]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
DBusAuthScript: Make USERNAME_HEX differ from USERID_HEX
authorSimon McVittie <smcv@collabora.com>
Fri, 12 Jan 2018 16:47:55 +0000 (16:47 +0000)
committerSimon McVittie <smcv@collabora.com>
Mon, 15 Jan 2018 14:05:15 +0000 (14:05 +0000)
Previously, USERID_HEX and USERNAME_HEX were both replaced by the hex
encoding of the numeric uid, something like 31303030 for "1000".
Now USERNAME_HEX is something like 736d6376 for "smcv". This is only
supported on Unix, but no authentication mechanisms use usernames on
Windows anyway.

This would require changing the tests that make use of USERNAME_HEX
if we had any, but we currently don't.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104588

dbus/dbus-auth-script.c

index 34c67f1d4860dd4528be57b40b25e48e96dc796e..63948422daac59b090d050a2b16d6350c0b554ae 100644 (file)
 #include "dbus-internals.h"
 #include <dbus/dbus-test-tap.h>
 
+#ifdef DBUS_UNIX
+# include "dbus/dbus-userdb.h"
+#endif
+
 /**
  * @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
  * @ingroup  DBusInternals
@@ -556,35 +560,33 @@ _dbus_auth_script_run (const DBusString *filename)
             else if (_dbus_string_find (&to_send, 0,
                                         "USERNAME_HEX", &where))
               {
-                DBusString username;
-                
-                if (!_dbus_string_init (&username))
-                  {
-                    _dbus_warn ("no memory for username");
-                    _dbus_string_free (&to_send);
-                    goto out;
-                  }
+#ifdef DBUS_UNIX
+                const DBusString *username;
 
-                if (!_dbus_append_user_from_current_process (&username))
+                if (!_dbus_username_from_current_process (&username))
                   {
                     _dbus_warn ("no memory for username");
-                    _dbus_string_free (&username);
                     _dbus_string_free (&to_send);
                     goto out;
                   }
 
                 _dbus_string_delete (&to_send, where, (int) strlen ("USERNAME_HEX"));
                 
-                if (!_dbus_string_hex_encode (&username, 0,
+                if (!_dbus_string_hex_encode (username, 0,
                                              &to_send, where))
                   {
                     _dbus_warn ("no memory to subst USERNAME_HEX");
-                    _dbus_string_free (&username);
                     _dbus_string_free (&to_send);
                     goto out;
                   }
-
-                _dbus_string_free (&username);
+#else
+                /* No authentication mechanism uses the login name on
+                 * Windows, so there's no point in it appearing in an
+                 * auth script that is not UNIX_ONLY. */
+                _dbus_warn ("USERNAME_HEX cannot be used on Windows");
+                _dbus_string_free (&to_send);
+                goto out;
+#endif
               }
           }