[pulseaudio-commits] r2131 - in /trunk: configure.ac src/daemon/polkit.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Mar 27 13:34:05 PDT 2008


Author: lennart
Date: Thu Mar 27 21:34:04 2008
New Revision: 2131

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2131&root=pulseaudio&view=rev
Log:
modernize polkit code a bit, use new functions from pk 0.7 instead of our home-grown ones

Modified:
    trunk/configure.ac
    trunk/src/daemon/polkit.c

Modified: trunk/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/configure.ac?rev=2131&root=pulseaudio&r1=2130&r2=2131&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Thu Mar 27 21:34:04 2008
@@ -150,11 +150,11 @@
 AC_MSG_CHECKING([target operating system])
 case $host in
     	*-*-linux*)
-	    AC_MSG_RESULT([linux]) 
+	    AC_MSG_RESULT([linux])
 	    pulse_target_os=linux
     	;;
 	*)
-	    AC_MSG_RESULT([unknown]) 	   
+	    AC_MSG_RESULT([unknown])
 	    pulse_target_os=unknown
 	;;
 esac
@@ -173,14 +173,14 @@
     need_libatomic_ops=no
 else
     AC_MSG_RESULT([no])
-    # HW specific atomic ops stuff 
+    # HW specific atomic ops stuff
     AC_MSG_CHECKING([architecture for native atomic operations])
-    case $host_cpu in	
+    case $host_cpu in
         arm*)
 	    AC_MSG_RESULT([arm])
 	    AC_MSG_CHECKING([whether we can use Linux kernel helpers])
 	    # The Linux kernel helper functions have been there since 2.6.16. However
-  	    # compile time checking for kernel version in cross compile environment 
+  	    # compile time checking for kernel version in cross compile environment
 	    # (which is usually the case for arm cpu) is tricky (or impossible).
 	    if test "x$pulse_target_os" = "xlinux" && test "x$atomic_arm_linux_helpers" != "xno"; then
 	        AC_MSG_RESULT([yes])
@@ -189,8 +189,8 @@
 	    else
 	       AC_MSG_RESULT([no])
 	       AC_MSG_CHECKING([compiler support for arm inline asm atomic operations])
-	       AC_LANG_CONFTEST([[int main() 
-	       { 
+	       AC_LANG_CONFTEST([[int main()
+	       {
                    volatile int a=0;
 	           int o=0, n=1, r;
 	           asm volatile ("ldrex	%0, [%1]\n"
@@ -201,7 +201,7 @@
 			 	 : "cc");
                    return (a==1 ? 0 : -1);
 	       }]])
-	       $CC conftest.c $CFLAGS -o conftest > /dev/null 2>&1 
+	       $CC conftest.c $CFLAGS -o conftest > /dev/null 2>&1
 	       ret=$?
 	       rm -f conftest.o conftest
 	       if test $ret -eq 0 ; then
@@ -209,7 +209,7 @@
 	    	   AC_MSG_RESULT([yes])
 		   need_libatomic_ops=no
 	       else
-	    	   AC_MSG_RESULT([no])	       
+	    	   AC_MSG_RESULT([no])
                fi
 	   fi
       	;;
@@ -494,7 +494,7 @@
 
 #### atomic-ops ###
 
-AC_MSG_CHECKING([whether we need libatomic_ops])		
+AC_MSG_CHECKING([whether we need libatomic_ops])
 if test "x$need_libatomic_ops" = "xyes"; then
    AC_MSG_RESULT([yes])
    AC_CHECK_HEADERS([atomic_ops.h], [], [
@@ -976,13 +976,9 @@
 
 if test "x${polkit}" != xno ; then
 
-    PKG_CHECK_MODULES(POLKIT, [ polkit-dbus ],
+    PKG_CHECK_MODULES(POLKIT, [ polkit-dbus >= 0.7 ],
         [
             HAVE_POLKIT=1
-            saved_LIBS="$LIBS"
-            LIBS="$LIBS $POLKIT_LIBS"
-            AC_CHECK_FUNCS(polkit_context_is_caller_authorized)
-            LIBS="$saved_LIBS"
             AC_DEFINE([HAVE_POLKIT], 1, [Have PolicyKit])
             policydir=`pkg-config polkit-dbus --variable prefix`/share/PolicyKit/policy/
             AC_SUBST(policydir)

Modified: trunk/src/daemon/polkit.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/polkit.c?rev=2131&root=pulseaudio&r1=2130&r2=2131&view=diff
==============================================================================
--- trunk/src/daemon/polkit.c (original)
+++ trunk/src/daemon/polkit.c Thu Mar 27 21:34:04 2008
@@ -37,59 +37,6 @@
 #include <pulsecore/macro.h>
 
 #include "polkit.h"
-
-static pa_bool_t show_grant_dialog(const char *action_id) {
-    DBusError dbus_error;
-    DBusConnection *bus = NULL;
-    DBusMessage *m = NULL, *reply = NULL;
-    pa_bool_t r = FALSE;
-    uint32_t xid = 0;
-    int verdict;
-
-    dbus_error_init(&dbus_error);
-
-    if (!(bus = dbus_bus_get(DBUS_BUS_SESSION, &dbus_error))) {
-        pa_log_error("Cannot connect to session bus: %s", dbus_error.message);
-        goto finish;
-    }
-
-    if (!(m = dbus_message_new_method_call("org.gnome.PolicyKit", "/org/gnome/PolicyKit/Manager", "org.gnome.PolicyKit.Manager", "ShowDialog"))) {
-        pa_log_error("Failed to allocate D-Bus message.");
-        goto finish;
-    }
-
-    if (!(dbus_message_append_args(m, DBUS_TYPE_STRING, &action_id, DBUS_TYPE_UINT32, &xid, DBUS_TYPE_INVALID))) {
-        pa_log_error("Failed to append arguments to D-Bus message.");
-        goto finish;
-    }
-
-    if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &dbus_error))) {
-        pa_log_warn("Failed to show grant dialog: %s", dbus_error.message);
-        goto finish;
-    }
-
-    if (!(dbus_message_get_args(reply, &dbus_error, DBUS_TYPE_BOOLEAN, &verdict, DBUS_TYPE_INVALID))) {
-        pa_log_warn("Malformed response from grant manager: %s", dbus_error.message);
-        goto finish;
-    }
-
-    r = !!verdict;
-
-finish:
-
-    if (bus)
-        dbus_connection_unref(bus);
-
-    dbus_error_free(&dbus_error);
-
-    if (m)
-        dbus_message_unref(m);
-
-    if (reply)
-        dbus_message_unref(reply);
-
-    return r;
-}
 
 int pa_polkit_check(const char *action_id) {
     int ret = -1;
@@ -161,35 +108,32 @@
 
     for (;;) {
 
-#ifdef HAVE_POLKIT_CONTEXT_IS_CALLER_AUTHORIZED
         polkit_result = polkit_context_is_caller_authorized(context, action, caller, TRUE, &polkit_error);
 
         if (polkit_error_is_set(polkit_error)) {
             pa_log_error("Could not determine whether caller is authorized: %s", polkit_error_get_error_message(polkit_error));
             goto finish;
         }
-#else
-
-        polkit_result = polkit_context_can_caller_do_action(context, action, caller);
-
-#endif
 
         if (polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH ||
             polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_SESSION ||
             polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_KEEP_ALWAYS ||
-#ifdef POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT
             polkit_result == POLKIT_RESULT_ONLY_VIA_ADMIN_AUTH_ONE_SHOT ||
-#endif
             polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH ||
             polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION ||
-            polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS
-#ifdef POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT
-            || polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT
-#endif
+            polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS ||
+            polkit_result == POLKIT_RESULT_ONLY_VIA_SELF_AUTH_ONE_SHOT
         ) {
 
-            if (show_grant_dialog(action_id))
-                continue;
+            if (polkit_auth_obtain(action_id, 0, getpid(), &dbus_error)) {
+                polkit_result = POLKIT_RESULT_YES;
+                break;
+            }
+
+            if (dbus_error_is_set(&dbus_error)) {
+                pa_log_error("Cannot obtain auth: %s", dbus_error.message);
+                goto finish;
+            }
         }
 
         break;




More information about the pulseaudio-commits mailing list