Actually use DBusAuthorization in DBusAuth EXTERNAL mech
authorCosimo Alfarano <cosimo.alfarano@collabora.com>
Thu, 22 Aug 2013 23:30:55 +0000 (01:30 +0200)
committerRalf Habacker <ralf.habacker@freenet.de>
Thu, 22 Aug 2013 23:31:47 +0000 (01:31 +0200)
Also update the authentication script so that DBusAuthorization default
rules are used during testing.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39720
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
dbus/dbus-auth-script.c
dbus/dbus-auth.c
dbus/dbus-auth.h
dbus/dbus-transport.c

index c1f0c88..445452c 100644 (file)
@@ -30,6 +30,7 @@
 #include "dbus-hash.h"
 #include "dbus-credentials.h"
 #include "dbus-internals.h"
 #include "dbus-hash.h"
 #include "dbus-credentials.h"
 #include "dbus-internals.h"
+#include "dbus-authorization.h"
 
 /**
  * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
 
 /**
  * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
@@ -401,6 +402,7 @@ _dbus_auth_script_run (const DBusString *filename)
                                                "SERVER"))
         {
           DBusCredentials *creds;
                                                "SERVER"))
         {
           DBusCredentials *creds;
+          DBusAuthorization *authorization;
           
           if (auth != NULL)
             {
           
           if (auth != NULL)
             {
@@ -408,7 +410,16 @@ _dbus_auth_script_run (const DBusString *filename)
               goto out;
             }
 
               goto out;
             }
 
-          auth = _dbus_auth_server_new (&guid);
+          /* empty authorization, it will use default rules */
+          authorization = _dbus_authorization_new ();
+          if (authorization == NULL)
+            {
+              _dbus_warn ("no memory to create DBusAuthorization\n");
+              goto out;
+            }
+          auth = _dbus_auth_server_new (&guid, authorization);
+          /* DBusAuth owns it, or finalized on OOM */
+          _dbus_authorization_unref (authorization);
           if (auth == NULL)
             {
               _dbus_warn ("no memory to create DBusAuth\n");
           if (auth == NULL)
             {
               _dbus_warn ("no memory to create DBusAuth\n");
index a0f7277..35efa3a 100644 (file)
@@ -30,6 +30,7 @@
 #include "dbus-sha.h"
 #include "dbus-protocol.h"
 #include "dbus-credentials.h"
 #include "dbus-sha.h"
 #include "dbus-protocol.h"
 #include "dbus-credentials.h"
+#include "dbus-authorization.h"
 
 /**
  * @defgroup DBusAuth Authentication
 
 /**
  * @defgroup DBusAuth Authentication
@@ -213,6 +214,8 @@ typedef struct
 {
   DBusAuth base;    /**< Parent class */
 
 {
   DBusAuth base;    /**< Parent class */
 
+  DBusAuthorization *authorization;             /* DBus Authorization callbacks */
+
   int failures;     /**< Number of times client has been rejected */
   int max_failures; /**< Number of times we reject before disconnect */
 
   int failures;     /**< Number of times client has been rejected */
   int max_failures; /**< Number of times we reject before disconnect */
 
@@ -1115,12 +1118,26 @@ handle_server_data_external_mech (DBusAuth         *auth,
                                              DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID,
                                              auth->credentials))
         return FALSE;
                                              DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID,
                                              auth->credentials))
         return FALSE;
-      
-      if (!send_ok (auth))
-        return FALSE;
 
 
-      _dbus_verbose ("%s: authenticated client based on socket credentials\n",
-                     DBUS_AUTH_NAME (auth));
+      /* Do a first authorization of the transport, in order to REJECT
+       * immediately connection if needed (FDO#39720), transport will
+       * re-authorize later, but it will close the connection on fail,
+       * we want to REJECT now if possible */
+      if (_dbus_authorization_do_authorization (DBUS_AUTH_SERVER (auth)->authorization,
+            auth->authorized_identity))
+        {
+          if (!send_ok (auth))
+            return FALSE;
+        }
+      else
+        {
+          _dbus_verbose ("%s: desired identity does not match server identity: "
+              "not authorized\n", DBUS_AUTH_NAME (auth));
+          return send_rejected (auth);
+        }
+
+      _dbus_verbose ("%s: authenticated and authorized client based on "
+          "socket credentials\n", DBUS_AUTH_NAME (auth));
 
       return TRUE;
     }
 
       return TRUE;
     }
@@ -2244,7 +2261,8 @@ process_command (DBusAuth *auth)
  * @returns the new object or #NULL if no memory
  */
 DBusAuth*
  * @returns the new object or #NULL if no memory
  */
 DBusAuth*
-_dbus_auth_server_new (const DBusString *guid)
+_dbus_auth_server_new (const DBusString *guid,
+    DBusAuthorization *authorization)
 {
   DBusAuth *auth;
   DBusAuthServer *server_auth;
 {
   DBusAuth *auth;
   DBusAuthServer *server_auth;
@@ -2272,7 +2290,8 @@ _dbus_auth_server_new (const DBusString *guid)
   server_auth = DBUS_AUTH_SERVER (auth);
 
   server_auth->guid = guid_copy;
   server_auth = DBUS_AUTH_SERVER (auth);
 
   server_auth->guid = guid_copy;
-  
+  server_auth->authorization = _dbus_authorization_ref (authorization);
+
   /* perhaps this should be per-mechanism with a lower
    * max
    */
   /* perhaps this should be per-mechanism with a lower
    * max
    */
@@ -2363,6 +2382,7 @@ _dbus_auth_unref (DBusAuth *auth)
           _dbus_assert (DBUS_AUTH_IS_SERVER (auth));
 
           _dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid);
           _dbus_assert (DBUS_AUTH_IS_SERVER (auth));
 
           _dbus_string_free (& DBUS_AUTH_SERVER (auth)->guid);
+          _dbus_authorization_unref (DBUS_AUTH_SERVER (auth)->authorization);
         }
 
       if (auth->keyring)
         }
 
       if (auth->keyring)
index ae3f364..3f178a2 100644 (file)
@@ -27,6 +27,7 @@
 #include <dbus/dbus-errors.h>
 #include <dbus/dbus-string.h>
 #include <dbus/dbus-sysdeps.h>
 #include <dbus/dbus-errors.h>
 #include <dbus/dbus-string.h>
 #include <dbus/dbus-sysdeps.h>
+#include <dbus/dbus-authorization.h>
 
 DBUS_BEGIN_DECLS
 
 
 DBUS_BEGIN_DECLS
 
@@ -41,7 +42,8 @@ typedef enum
   DBUS_AUTH_STATE_AUTHENTICATED
 } DBusAuthState;
 
   DBUS_AUTH_STATE_AUTHENTICATED
 } DBusAuthState;
 
-DBusAuth*     _dbus_auth_server_new          (const DBusString       *guid);
+DBusAuth*     _dbus_auth_server_new          (const DBusString       *guid,
+                                              DBusAuthorization      *authorization);
 DBusAuth*     _dbus_auth_client_new          (void);
 DBusAuth*     _dbus_auth_ref                 (DBusAuth               *auth);
 void          _dbus_auth_unref               (DBusAuth               *auth);
 DBusAuth*     _dbus_auth_client_new          (void);
 DBusAuth*     _dbus_auth_ref                 (DBusAuth               *auth);
 void          _dbus_auth_unref               (DBusAuth               *auth);
index 661b54f..3a9cf84 100644 (file)
@@ -125,7 +125,7 @@ _dbus_transport_init_base (DBusTransport             *transport,
           return FALSE; /* OOM */
         }
 
           return FALSE; /* OOM */
         }
 
-      auth = _dbus_auth_server_new (server_guid);
+      auth = _dbus_auth_server_new (server_guid, authorization);
     }
   else
     {
     }
   else
     {