summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-auth-script.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-06-09 21:53:20 +0000
committerHavoc Pennington <hp@redhat.com>2007-06-09 21:53:20 +0000
commit23832672266bb4ff23b66247c0cfa1a2ed0cc97b (patch)
tree119e37411f14923780de3ca7a759707508f1ec63 /dbus/dbus-auth-script.c
parentb80a8fe6b364543aa4b32a02a5ad913faf97173b (diff)
2007-06-09 Havoc Pennington <hp@redhat.com>
* bus/dispatch.c (check_get_connection_unix_process_id): adapt since sysdeps-unix.h stuff isn't included anymore * bus/bus.c (bus_context_new): use more abstract functions to change user, so they can be no-ops on Windows * dbus/dbus-credentials.c, dbus/dbus-credentials.h, dbus/dbus-credentials-util.c: new files containing a fully opaque DBusCredentials data type to replace the old not opaque one. * configure.in (DBUS_UNIX): define DBUS_UNIX to match DBUS_WIN on windows * dbus/dbus-userdb.h: prohibit on Windows, next step is to clean up the uses of it in bus/*.c and factor out the parts of cookie auth that depend on it
Diffstat (limited to 'dbus/dbus-auth-script.c')
-rw-r--r--dbus/dbus-auth-script.c84
1 files changed, 69 insertions, 15 deletions
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index 3cb86d0f..5aa17d4b 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -28,8 +28,8 @@
#include "dbus-auth.h"
#include "dbus-string.h"
#include "dbus-hash.h"
+#include "dbus-credentials.h"
#include "dbus-internals.h"
-#include "dbus-userdb.h"
/**
* @defgroup DBusAuthScript code for running unit test scripts for DBusAuth
@@ -209,6 +209,29 @@ split_string (DBusString *str)
return array;
}
+static void
+auth_set_unix_credentials(DBusAuth *auth,
+ dbus_uid_t uid,
+ dbus_pid_t pid)
+{
+ DBusCredentials *credentials;
+
+ credentials = _dbus_credentials_new ();
+ if (credentials == NULL)
+ {
+ _dbus_warn ("no memory\n");
+ return;
+ }
+ if (uid != DBUS_UID_UNSET)
+ _dbus_credentials_add_unix_uid (credentials, uid);
+ if (pid != DBUS_PID_UNSET)
+ _dbus_credentials_add_unix_pid (credentials, pid);
+
+ _dbus_auth_set_credentials (auth, credentials);
+
+ _dbus_credentials_unref (credentials);
+}
+
/**
* Runs an "auth script" which is a script for testing the
* authentication protocol. Scripts send and receive data, and then
@@ -303,7 +326,7 @@ _dbus_auth_script_run (const DBusString *filename)
else if (_dbus_string_starts_with_c_str (&line,
"CLIENT"))
{
- DBusCredentials creds;
+ DBusCredentials *creds;
if (auth != NULL)
{
@@ -321,14 +344,31 @@ _dbus_auth_script_run (const DBusString *filename)
/* test ref/unref */
_dbus_auth_ref (auth);
_dbus_auth_unref (auth);
+
+ creds = _dbus_credentials_new_from_current_process ();
+ if (creds == NULL)
+ {
+ _dbus_warn ("no memory for credentials\n");
+ _dbus_auth_unref (auth);
+ auth = NULL;
+ goto out;
+ }
+
+ if (!_dbus_auth_set_credentials (auth, creds))
+ {
+ _dbus_warn ("no memory for setting credentials\n");
+ _dbus_auth_unref (auth);
+ auth = NULL;
+ _dbus_credentials_unref (creds);
+ goto out;
+ }
- _dbus_credentials_from_current_process (&creds);
- _dbus_auth_set_credentials (auth, &creds);
+ _dbus_credentials_unref (creds);
}
else if (_dbus_string_starts_with_c_str (&line,
"SERVER"))
{
- DBusCredentials creds;
+ DBusCredentials *creds;
if (auth != NULL)
{
@@ -346,9 +386,27 @@ _dbus_auth_script_run (const DBusString *filename)
/* test ref/unref */
_dbus_auth_ref (auth);
_dbus_auth_unref (auth);
+
+ creds = _dbus_credentials_new_from_current_process ();
+ if (creds == NULL)
+ {
+ _dbus_warn ("no memory for credentials\n");
+ _dbus_auth_unref (auth);
+ auth = NULL;
+ goto out;
+ }
+
+ if (!_dbus_auth_set_credentials (auth, creds))
+ {
+ _dbus_warn ("no memory for setting credentials\n");
+ _dbus_auth_unref (auth);
+ auth = NULL;
+ _dbus_credentials_unref (creds);
+ goto out;
+ }
- _dbus_credentials_from_current_process (&creds);
- _dbus_auth_set_credentials (auth, &creds);
+ _dbus_credentials_unref (creds);
+
_dbus_auth_set_context (auth, &context);
}
else if (auth == NULL)
@@ -360,20 +418,17 @@ _dbus_auth_script_run (const DBusString *filename)
else if (_dbus_string_starts_with_c_str (&line,
"NO_CREDENTIALS"))
{
- DBusCredentials creds = { -1, -1, -1 };
- _dbus_auth_set_credentials (auth, &creds);
+ auth_set_unix_credentials (auth, DBUS_UID_UNSET, DBUS_PID_UNSET);
}
else if (_dbus_string_starts_with_c_str (&line,
"ROOT_CREDENTIALS"))
{
- DBusCredentials creds = { -1, 0, 0 };
- _dbus_auth_set_credentials (auth, &creds);
+ auth_set_unix_credentials (auth, 0, DBUS_PID_UNSET);
}
else if (_dbus_string_starts_with_c_str (&line,
"SILLY_CREDENTIALS"))
{
- DBusCredentials creds = { -1, 4312, 1232 };
- _dbus_auth_set_credentials (auth, &creds);
+ auth_set_unix_credentials (auth, 4312, DBUS_PID_UNSET);
}
else if (_dbus_string_starts_with_c_str (&line,
"ALLOWED_MECHS"))
@@ -432,8 +487,7 @@ _dbus_auth_script_run (const DBusString *filename)
goto out;
}
- if (!_dbus_string_append_uint (&username,
- _dbus_getuid ()))
+ if (!_dbus_append_desired_identity (&username))
{
_dbus_warn ("no memory for userid\n");
_dbus_string_free (&username);