summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolger Macht <holger@homac.de>2006-10-26 19:28:47 +0200
committerHolger Macht <holger@homac.de>2006-10-26 19:28:47 +0200
commita60d22e3677c2bc328fdf26acf1b9987efe072ad (patch)
tree120534fa775a45fb9107d0a633b5ce6b9fee8659
parent07b91679dd5d69db855c2d228154ad56b45d0a2d (diff)
add function to query if the _current_ user possesses a privilege
-rw-r--r--liblazy/liblazy.h14
-rw-r--r--liblazy/liblazy_polkit.c18
2 files changed, 32 insertions, 0 deletions
diff --git a/liblazy/liblazy.h b/liblazy/liblazy.h
index fd8a721..59bc82f 100644
--- a/liblazy/liblazy.h
+++ b/liblazy/liblazy.h
@@ -252,6 +252,20 @@ int liblazy_polkit_is_user_allowed_by_name(char *user, char *privilege,
/** @brief check if a user possesses a privilege
*
+ * Functions asks the PolicyKit daemon if the user with the given uid
+ * possesses a given privilege on a optional given ressource
+ *
+ * @param uid the uid to check against
+ * @param privilege the privilege to check for
+ * @param ressource the ressource to check for or NULL
+ *
+ * @return 0 on success, LIBLAZY_ERROR_* on failure
+ */
+int liblazy_polkit_is_user_allowed_by_uid(int uid, char *privilege,
+ char *ressource);
+
+/** @brief check if a user possesses a privilege
+ *
* Functions asks the PolicyKit daemon if the current user possesses a
* given privilege on a optional given ressource
*
diff --git a/liblazy/liblazy_polkit.c b/liblazy/liblazy_polkit.c
index e33cf2e..0a2db2f 100644
--- a/liblazy/liblazy_polkit.c
+++ b/liblazy/liblazy_polkit.c
@@ -28,6 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
+#include <pwd.h>
+#include <string.h>
+#include <errno.h>
#define DBUS_POLKIT_SERVICE "org.freedesktop.PolicyKit"
#define DBUS_POLKIT_PATH "/org/freedesktop/PolicyKit/Manager"
@@ -82,9 +85,24 @@ int liblazy_polkit_is_user_allowed_by_name(char *user,
return is_allowed;
}
+int liblazy_polkit_is_user_allowed_by_uid(int uid, char *privilege,
+ char *ressource)
+{
+ struct passwd *pw = getpwuid(uid);
+
+ if (pw == NULL) {
+ ERROR("Could not get current username: %s", strerror(errno));
+ return LIBLAZY_ERROR_GENERAL;
+ }
+
+ return liblazy_polkit_is_user_allowed_by_name(pw->pw_name, privilege,
+ ressource);
+}
+
int liblazy_polkit_is_user_allowed(char *privilege, char *ressource)
{
char *user = getenv("USER");
return liblazy_polkit_is_user_allowed_by_name(user, privilege,
ressource);
}
+