summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <kuri@friloux.me>2014-04-19 23:09:22 +0200
committerGuillaume Friloux <kuri@friloux.me>2014-04-19 23:09:22 +0200
commitb7d72f9d68d04fb76366f1aa68e56317e3779609 (patch)
tree32e3901911a11ed1cf48cdc9c89992f07c182bb5
parentab010e15dbe4f593f180a2b62de54f81d637939b (diff)
Add support for file execution with dropping of privs. UNTESTED!
-rw-r--r--src/bin/main.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 7a35246..93c3d67 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -22,12 +22,89 @@ typedef struct _User
22 char *dir; 22 char *dir;
23} User; 23} User;
24 24
25typedef struct _User_Execute
26{
27 Fingered_User *fu;
28 Ecore_Exe *exe;
29
30 struct
31 {
32 Ecore_Event_Handler *data,
33 *del;
34 } ev;
35} User_Execute;
36
37Eina_Bool
38_user_execute_data(void *data,
39 int type EINA_UNUSED,
40 void *ev)
41{
42 Ecore_Exe_Event_Data *event = ev;
43 User_Execute *ue = data;
44
45 DBG("data[%p] ev[%p]", data, ev);
46
47 fingered_user_send(ue->fu, event->data, event->size);
48 return EINA_TRUE;
49}
50
51Eina_Bool
52_user_execute_del(void *data,
53 int type EINA_UNUSED,
54 void *ev)
55{
56 Ecore_Exe_Event_Del *event = ev;
57 User_Execute *ue = data;
58
59 DBG("data[%p] ev[%p]", data, ev);
60
61 fingered_user_free(ue->fu);
62 ecore_exe_free(ue->exe);
63 ecore_event_handler_del(ue->ev.data);
64 ecore_event_handler_del(ue->ev.del);
65 free(ue);
66 return EINA_TRUE;
67}
25 68
26void 69void
27_user_execute(User *u, 70_user_execute(User *u,
28 const char *s) 71 const char *s)
29{ 72{
73 uid_t uid_orig;
74 gid_t gid_orig;
75 User_Execute *ue;
76
30 DBG("u[%p] s[%s]", u, s); 77 DBG("u[%p] s[%s]", u, s);
78
79 uid_orig = geteuid();
80 gid_orig = getegid();
81
82 seteuid(u->uid);
83 setegid(u->gid);
84
85 ue = calloc(1, sizeof(User_Execute));
86 if (!ue)
87 {
88 ERR("Failed to allocate User_Execute structure.");
89 goto execute_end;
90 }
91
92 ue->fu = u->fu;
93
94#define _EV(_a, _b, _c, _d) \
95 _a = ecore_event_handler_add(ECORE_EXE_EVENT_##_b, \
96 _user_execute_##_c, _d)
97 _EV(ue->ev.data, DATA, data, ue);
98 _EV(ue->ev.del, DEL, del, ue);
99#undef _EV
100
101 DBG("Executing %s", s);
102 ue->exe = ecore_exe_pipe_run(s,
103 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
104 ECORE_EXE_PIPE_READ, ue);
105execute_end:
106 seteuid(uid_orig);
107 setegid(gid_orig);
31} 108}
32 109
33void 110void
@@ -94,7 +171,6 @@ _user_check(User *u)
94 171
95free_s: 172free_s:
96 free(s); 173 free(s);
97 fingered_user_free(u->fu);
98 free(u->dir); 174 free(u->dir);
99 free(u); 175 free(u);
100} 176}