PolicyKit/libpolkit libpolkit.c,1.2,1.3 libpolkit.h,1.2,1.3

David Zeuthen david at kemper.freedesktop.org
Sat Apr 22 16:27:16 PDT 2006


Update of /cvs/hal/PolicyKit/libpolkit
In directory kemper:/tmp/cvs-serv6540/libpolkit

Modified Files:
	libpolkit.c libpolkit.h 
Log Message:
2006-04-22  David Zeuthen  <davidz at redhat.com>

        * tools/polkit-list-privileges.c (main): Update to new D-BUS API;
        print " (temporary)" for privilege if appropriate.

        * tools/polkit-is-privileged.c (main): Update to new D-BUS API

        * tools/polkit-grant-privilege.c:
        (do_grant_privilege): Update to new D-BUS API
        (main): --do--

        * tools/polkit-revoke-privilege.c: New file

        * tools/Makefile.am: Add build rules for polkit-revoke-privilege

        * polkitd/polkit-manager.h: Fix up prototypes

        * polkitd/polkit-manager.c:
        (polkit_manager_initiate_temporary_privilege_grant): Update to new
        D-BUS API
        (polkit_manager_get_allowed_resources_for_privilege): --do--
        (polkit_manager_revoke_temporary_privilege): New function
        (polkit_manager_remove_temporary_privilege): Fix up resource handling
        (polkit_manager_add_temporary_privilege): --do--

        * libpolkit/libpolkit.h:
        (libpolkit_get_allowed_resources_for_privilege_for_uid): Update to
        new D-BUS API and export libpolkit_revoke_temporary_privilege()

        * libpolkit/libpolkit.c:
        (libpolkit_is_uid_allowed_for_privilege): Update to new D-BUS API
        (libpolkit_get_allowed_resources_for_privilege_for_uid): --do--
        (libpolkit_revoke_temporary_privilege): New function

        * polkit-interface-manager.xml: Rename InitiatePrivilegeGrant() to
        InitiateTemporaryPrivilegeGrant(). Add new function
        RevokeTemporaryPrivilege(). Make IsUserPrivileged() output a
        boolean is_temporary. GetAllowedResourcesForPrivilege() now also
        outputs an integer num_non_temp.



Index: libpolkit.c
===================================================================
RCS file: /cvs/hal/PolicyKit/libpolkit/libpolkit.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- libpolkit.c	14 Mar 2006 06:14:33 -0000	1.2
+++ libpolkit.c	22 Apr 2006 23:27:14 -0000	1.3
@@ -102,7 +102,8 @@
 libpolkit_get_allowed_resources_for_privilege_for_uid (LibPolKitContext    *ctx,
 						       const char          *user, 
 						       const char          *privilege, 
-						       GList              **result)
+						       GList              **result,
+						       int                 *num_non_temporary)
 {
 	LibPolKitResult res;
 	DBusMessage *message = NULL;
@@ -148,6 +149,7 @@
 
 	if (!dbus_message_get_args (reply, &error,
 				    DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &resource_list, &num_resources,
+				    DBUS_TYPE_INT32, num_non_temporary,
 				    DBUS_TYPE_INVALID)) {
 		g_warning ("Could not extract args from D-BUS message: %s : %s", error.name, error.message);
 		dbus_error_free (&error);
@@ -175,7 +177,8 @@
 					const char          *user, 
 					const char          *privilege, 
 					const char          *resource,
-					gboolean            *result)
+					gboolean            *is_allowed,
+					gboolean            *is_temporary)
 {
 	LibPolKitResult res;
 	DBusMessage *message = NULL;
@@ -186,7 +189,8 @@
 	LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
 
 	res = LIBPOLKIT_RESULT_ERROR;
-	*result = FALSE;
+	*is_allowed = FALSE;
+	*is_temporary = FALSE;
 
 	message = dbus_message_new_method_call ("org.freedesktop.PolicyKit",
 						"/org/freedesktop/PolicyKit/Manager",
@@ -228,7 +232,8 @@
 
 
 	if (!dbus_message_get_args (reply, &error,
-				    DBUS_TYPE_BOOLEAN, result,
+				    DBUS_TYPE_BOOLEAN, is_allowed,
+				    DBUS_TYPE_BOOLEAN, is_temporary,
 				    DBUS_TYPE_INVALID)) {
 		g_warning ("Could not extract args from D-BUS message: %s : %s", error.name, error.message);
 		dbus_error_free (&error);
@@ -246,6 +251,80 @@
 }
 
 LibPolKitResult
+libpolkit_revoke_temporary_privilege (LibPolKitContext      *ctx,
+				      const char            *user, 
+				      const char            *privilege, 
+				      const char            *resource,
+				      gboolean              *result)
+{
+	LibPolKitResult res;
+	DBusMessage *message = NULL;
+	DBusMessage *reply = NULL;
+	DBusError error;
+	const char *myresource = "";
+
+	LIBPOLKIT_CHECK_CONTEXT (ctx, LIBPOLKIT_RESULT_INVALID_CONTEXT);
+
+	res = LIBPOLKIT_RESULT_ERROR;
+	*result = FALSE;
+
+	message = dbus_message_new_method_call ("org.freedesktop.PolicyKit",
+						"/org/freedesktop/PolicyKit/Manager",
+						"org.freedesktop.PolicyKit.Manager",
+						"RevokeTemporaryPrivilege");
+	if (message == NULL) {
+		g_warning ("Could not allocate D-BUS message");
+		goto out;
+	}
+
+	if (resource != NULL)
+		myresource = resource;
+
+	if (!dbus_message_append_args (message, 
+				       DBUS_TYPE_STRING, &user, 
+				       DBUS_TYPE_STRING, &privilege,
+				       DBUS_TYPE_STRING, &myresource,
+				       DBUS_TYPE_INVALID)) {
+		g_warning ("Could not append args to D-BUS message");
+		goto out;
+	}
+
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (ctx->connection, message, -1, &error);
+	if (dbus_error_is_set (&error)) {
+		if (strcmp (error.name, "org.freedesktop.PolicyKit.Manager.NoSuchUser") == 0) {
+			res = LIBPOLKIT_RESULT_NO_SUCH_USER;
+		} else if (strcmp (error.name, "org.freedesktop.PolicyKit.Manager.NoSuchPrivilege") == 0) {
+			res = LIBPOLKIT_RESULT_NO_SUCH_PRIVILEGE;
+		} else if (strcmp (error.name, "org.freedesktop.PolicyKit.Manager.NotPrivileged") == 0) {
+			res = LIBPOLKIT_RESULT_NOT_PRIVILEGED;
+		} else if (strcmp (error.name, "org.freedesktop.PolicyKit.Manager.Error") == 0) {
+			res = LIBPOLKIT_RESULT_ERROR;
+		}
+		dbus_error_free (&error);
+		goto out;
+	}
+
+
+	if (!dbus_message_get_args (reply, &error,
+				    DBUS_TYPE_BOOLEAN, result,
+				    DBUS_TYPE_INVALID)) {
+		g_warning ("Could not extract args from D-BUS message: %s : %s", error.name, error.message);
+		dbus_error_free (&error);
+		goto out;
+	}
+
+	res = LIBPOLKIT_RESULT_OK;
+
+out:
+	if (reply != NULL)
+		dbus_message_unref (reply);
+	if (message != NULL)
+		dbus_message_unref (message);
+	return res;	
+}
+
+LibPolKitResult
 libpolkit_get_privilege_list (LibPolKitContext      *ctx,
 			      GList                **result)
 {

Index: libpolkit.h
===================================================================
RCS file: /cvs/hal/PolicyKit/libpolkit/libpolkit.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- libpolkit.h	14 Mar 2006 06:14:33 -0000	1.2
+++ libpolkit.h	22 Apr 2006 23:27:14 -0000	1.3
@@ -55,12 +55,20 @@
 								       const char            *user, 
 								       const char            *privilege, 
 								       const char            *resource,
+								       gboolean              *is_allowed,
+								       gboolean              *is_temporary);
+
+LibPolKitResult    libpolkit_revoke_temporary_privilege               (LibPolKitContext      *ctx,
+								       const char            *user, 
+								       const char            *privilege, 
+								       const char            *resource,
 								       gboolean              *result);
 
 LibPolKitResult    libpolkit_get_allowed_resources_for_privilege_for_uid (LibPolKitContext      *ctx,
 									  const char            *user, 
 									  const char            *privilege, 
-									  GList                **result);
+									  GList                **result,
+									  int                   *num_non_temporary);
 
 #endif /* LIBPOLKIT_H */
 




More information about the hal-commit mailing list