18 /* local subsystem functions */
19 static int auth_action_ok(char *a,
25 static int auth_etc_enlightenment_sysactions(char *a,
28 static char *get_word(char *s,
31 /* local subsystem globals */
32 static Eina_Hash *actions = NULL;
34 /* externally accessible functions */
41 Eina_Bool mnt = EINA_FALSE;
44 gid_t gid, gl[65536], egid;
46 for (i = 1; i < argc; i++)
48 if ((!strcmp(argv[i], "-h")) ||
49 (!strcmp(argv[i], "-help")) ||
50 (!strcmp(argv[i], "--help")))
53 "This is an internal tool for Enlightenment.\n"
61 if ((argc == 3) && (!strcmp(argv[1], "-t")))
70 s = strrchr(argv[1], '/');
71 if ((!s) || (!(++s))) exit(1); /* eeze always uses complete path */
72 if (strcmp(s, "mount") && strcmp(s, "umount") && strcmp(s, "eject")) exit(1);
89 gn = getgroups(65536, gl);
92 printf("ERROR: MEMBER OF MORE THAN 65536 GROUPS\n");
97 printf("ERROR: UNABLE TO ASSUME ROOT PRIVILEGES\n");
102 printf("ERROR: UNABLE TO ASSUME ROOT GROUP PRIVILEGES\n");
108 if (!auth_action_ok(action, uid, gid, gl, gn, egid))
110 printf("ERROR: ACTION NOT ALLOWED: %s\n", action);
113 /* we can add more levels of auth here */
115 /* when mounting, this will match the exact path to the exe,
116 * as required in sysactions.conf
117 * this is intentionally pedantic for security
119 cmd = eina_hash_find(actions, action);
122 printf("ERROR: UNDEFINED ACTION: %s\n", action);
125 if ((!test) && (!mnt)) return system(cmd);
130 const char *mp = NULL;
132 buf = eina_strbuf_new();
134 for (i = 1; i < argc; i++)
136 if (!strncmp(argv[i], "/media/", 7))
139 if (!strcmp(action, "mount"))
143 if (stat("/media", &s))
148 if (mkdir("/media", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
150 printf("ERROR: COULD NOT CREATE DIRECTORY /media\n");
155 else if (!S_ISDIR(s.st_mode))
157 printf("ERROR: NOT A DIRECTORY: /media\n");
161 if (stat(argv[i], &s))
166 if (mkdir(argv[i], S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
168 printf("ERROR: COULD NOT CREATE DIRECTORY %s\n", argv[i]);
173 else if (!S_ISDIR(s.st_mode))
175 printf("ERROR: NOT A DIRECTORY: %s\n", argv[i]);
180 eina_strbuf_append_printf(buf, "%s ", argv[i]);
182 ret = system(eina_strbuf_string_get(buf));
183 if (mp && (!strcmp(action, "umount")) && (!ret))
186 printf("ERROR: COULD NOT UNLINK MOUNT POINT %s\n", mp);
196 printf("ERROR: MEMORY CRISIS\n");
201 /* local subsystem functions */
203 auth_action_ok(char *a,
212 char *usr = NULL, **grp, *g;
219 grp = alloca(sizeof(char *) * (gn + 1 + 1));
224 grp[j] = gp->gr_name;
227 for (i = 0; i < gn; i++)
231 gp = getgrgid(gl[i]);
234 g = alloca(strlen(gp->gr_name) + 1);
235 strcpy(g, gp->gr_name);
242 /* first stage - check:
243 * PREFIX/etc/enlightenment/sysactions.conf
245 ret = auth_etc_enlightenment_sysactions(a, usr, grp);
246 if (ret == 1) return 1;
249 /* the DEFAULT - allow */
254 auth_etc_enlightenment_sysactions(char *a,
259 char file[4096], buf[4096], id[4096], ugname[4096], perm[4096], act[4096];
260 char *p, *pp, *s, **gp;
261 int len, line = 0, ok = 0;
265 snprintf(file, sizeof(file), "/etc/enlightenment/sysactions.conf");
266 f = fopen(file, "r");
269 snprintf(file, sizeof(file), PACKAGE_SYSCONF_DIR "/enlightenment/sysactions.conf");
270 f = fopen(file, "r");
273 while (fgets(buf, sizeof(buf), f))
277 if (len < 1) continue;
278 if (buf[len - 1] == '\n') buf[len - 1] = 0;
282 * user: username [allow:|deny:] halt reboot ...
283 * group: groupname [allow:|deny:] suspend ...
285 if (buf[0] == '#') continue;
288 p = get_word(p, ugname);
290 p = get_word(p, perm);
293 if (!strcmp(id, "user:"))
295 if (!fnmatch(ugname, u, 0))
297 if (!strcmp(perm, "allow:")) allow = 1;
298 else if (!strcmp(perm, "deny:"))
306 else if (!strcmp(id, "group:"))
311 for (gp = g; *gp; gp++)
313 if (!fnmatch(ugname, *gp, 0))
316 if (!strcmp(perm, "allow:")) allow = 1;
317 else if (!strcmp(perm, "deny:"))
323 if (!matched) continue;
325 else if (!strcmp(id, "action:"))
327 while ((*pp) && (isspace(*pp))) pp++;
328 s = eina_hash_find(actions, ugname);
329 if (s) eina_hash_del(actions, ugname, s);
330 if (!actions) actions = eina_hash_string_superfast_new(free);
331 eina_hash_add(actions, ugname, strdup(pp));
341 p = get_word(p, act);
342 if (act[0] == 0) break;
343 if (!fnmatch(act, a, 0))
354 printf("WARNING: %s:%i\n"
356 "MALFORMED LINE. SKIPPED.\n",
382 if (isspace(*p1)) break;