From: David Zeuthen Date: Tue, 20 Jan 2009 00:00:08 +0000 (-0500) Subject: make it possible to grant/revoke/use authorizations from groups X-Git-Tag: 0.91~48^2~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0faf5619bfb0c6c78ed7f4109c562959ce8611a;p=platform%2Fupstream%2Fpolkit.git make it possible to grant/revoke/use authorizations from groups --- diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c index febbf0b..c9e7b93 100644 --- a/src/polkitbackend/polkitbackendlocalauthority.c +++ b/src/polkitbackend/polkitbackendlocalauthority.c @@ -24,6 +24,8 @@ #include #include #include +#include + #include #include "polkitbackendlocalauthority.h" #include "polkitbackendactionpool.h" @@ -825,6 +827,24 @@ authorization_store_save_permanent_authorizations (AuthorizationStore *store, gboolean ret; ret = FALSE; + str = NULL; + + /* simply unlink the file if there are no authorizations */ + if (store->authorizations == NULL) + { + if (g_unlink (store->path) != 0) + { + g_set_error (error, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "Cannot remove authorization. Error unlinking file %s: %m", + store->path); + goto out; + } + + ret = TRUE; + goto out; + } s = g_string_new ("# polkit-1 " PACKAGE_VERSION " authorizations file\n" "#\n" @@ -1151,8 +1171,42 @@ static GList * get_groups_for_user (PolkitBackendLocalAuthority *authority, PolkitIdentity *user) { - /* TODO */ - return NULL; + uid_t uid; + struct passwd *passwd; + GList *result; + gid_t groups[512]; + int num_groups = 512; + int n; + + result = NULL; + + /* TODO: it would be, uhm, good to cache this information */ + + uid = polkit_unix_user_get_uid (POLKIT_UNIX_USER (user)); + passwd = getpwuid (uid); + if (passwd == NULL) + { + g_warning ("No user with uid %d", uid); + goto out; + } + + /* TODO: should resize etc etc etc */ + + if (getgrouplist (passwd->pw_name, + passwd->pw_gid, + groups, + &num_groups) < 0) + { + g_warning ("Error looking up groups for uid %d: %m", uid); + goto out; + } + + for (n = 0; n < num_groups; n++) + result = g_list_prepend (result, polkit_unix_group_new (groups[n])); + + out: + + return result; } static GList *