X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fudev-acl%2Fudev-acl.c;h=35bad76034972e23ff0e6295891b7b2e5518cdc4;hb=eb042a2c92fb857294e1380ff232a7633a2d3725;hp=f2b50051c1121fa4bf80932f0f1a3553d1533f05;hpb=939cc18afc49ee8479572c14c7fa777646fd4add;p=elogind.git diff --git a/extras/udev-acl/udev-acl.c b/extras/udev-acl/udev-acl.c index f2b50051c..35bad7603 100644 --- a/extras/udev-acl/udev-acl.c +++ b/extras/udev-acl/udev-acl.c @@ -12,20 +12,18 @@ * General Public License for more details: */ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include -#include #include -#include +#include #include +#include +#include +#include +#include +#include static int debug; @@ -45,6 +43,10 @@ static int set_facl(const char* filename, uid_t uid, int add) acl_permset_t permset; int ret; + /* don't touch ACLs for root */ + if (uid == 0) + return 0; + /* read current record */ acl = acl_get_file(filename, ACL_TYPE_ACCESS); if (!acl) @@ -190,8 +192,6 @@ static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, con if (s == NULL) return -1; u = strtoul(s, NULL, 10); - if (u == 0) - return 0; s = getenv("CK_SEAT_SESSION_IS_LOCAL"); if (s == NULL) @@ -205,8 +205,6 @@ static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, con if (s == NULL) return -1; u = strtoul(s, NULL, 10); - if (u == 0) - return 0; s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL"); if (s == NULL) @@ -260,11 +258,6 @@ static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, con u = u2; } break; - case ACTION_NONE: - break; - default: - g_assert_not_reached(); - break; } *remove_session_id = old_session; @@ -331,6 +324,7 @@ int main (int argc, char* argv[]) }; int action = -1; const char *device = NULL; + bool uid_given = false; uid_t uid = 0; uid_t uid2 = 0; const char* remove_session_id = NULL; @@ -357,6 +351,7 @@ int main (int argc, char* argv[]) device = optarg; break; case 'u': + uid_given = true; uid = strtoul(optarg, NULL, 10); break; case 'd': @@ -364,13 +359,13 @@ int main (int argc, char* argv[]) break; case 'h': printf("Usage: udev-acl --action=ACTION [--device=DEVICEFILE] [--user=UID]\n\n"); - default: goto out; } } - if (action < 0 && device == NULL && uid == 0) - consolekit_called(argv[optind], &uid, &uid2, &remove_session_id, &action); + if (action < 0 && device == NULL && !uid_given) + if (!consolekit_called(argv[optind], &uid, &uid2, &remove_session_id, &action)) + uid_given = true; if (action < 0) { fprintf(stderr, "missing action\n\n"); @@ -378,13 +373,13 @@ int main (int argc, char* argv[]) goto out; } - if (device != NULL && uid != 0) { + if (device != NULL && uid_given) { fprintf(stderr, "only one option, --device=DEVICEFILE or --user=UID expected\n\n"); rc = 3; goto out; } - if (uid != 0) { + if (uid_given) { switch (action) { case ACTION_ADD: /* Add ACL for given uid to all matching devices. */