Win32 port
Peter Kümmel
syntheticpp at gmx.net
Sun Jun 25 06:04:11 PDT 2006
Havoc Pennington wrote:
>
> I would do it like this:
>
> in .h:
>
> typedef struct DBusUID DBusUID;
> void dbus_uid_init_unix(DBusUID *uid, unsigned long value);
> void dbus_uid_init_win32(DBusUID *uid, const char *str);
> dbus_bool_t dbus_uid_equal(const DBusUID *uid1, const DBusUID *uid2);
> ... etc., include other operations on uid
>
I've done this, but a complete hiding of DBusUID is not
possible because DBusUID is used within other strucs.
> in .c:
>
> struct DBusUID
> {
> #ifdef _WIN32
> char *uid;
> #else
> unsigned long uid;
> #endif
> }
So I've also added the definition of DBusUID to the header, but
I use a long name for the member uid which could be changed by
a macro. This makes it very simple to detect the usage of the
variable (simulates a private declaration).
If this is the way to go I will also change the other files,
atm only dbus/dbus compiles.
Here the interesting part, for the rest see the attached diff:
#ifdef _WIN32
#else
#define DBUS_UID_IMPL unsigned long
#define DBUS_UID_FORMAT "%lu"
#define DBUS_UID_PRINT DBUS_UID_IMPL
/*#define DBUS_UID_UNSET ((DBusUID) {-1}) */
#define DBUS_UID_UNSET _dbus_uid_unset()
#endif
#define DBUS_UID_IMPL_VAR_NAME id_name_to_long_for_usage
typedef struct DBusUID
{
DBUS_UID_IMPL DBUS_UID_IMPL_VAR_NAME;
} DBusUID;
DBusUID _dbus_uid_unset(void);
DBusUID _dbus_uid_null(void);
DBusUID _dbus_uid_silly(void);
void _dbus_uid_set_id(DBusUID *uid, DBUS_UID_IMPL value);
DBUS_UID_IMPL _dbus_uid_get_id(DBusUID *uid);
dbus_bool_t _dbus_uid_equal(const DBusUID *uid1, const DBusUID *uid2);
dbus_bool_t _dbus_uid_is_unset(const DBusUID *uid);
dbus_bool_t _dbus_uid_is_null(const DBusUID *uid);
DBUS_UID_PRINT _dbus_uid_print(DBusUID *uid);
Regards,
Peter
-------------- next part --------------
Index: dbus-auth-script.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-auth-script.c,v
retrieving revision 1.17
diff -u -B -b -r1.17 dbus-auth-script.c
--- dbus-auth-script.c 26 Feb 2005 06:37:46 -0000 1.17
+++ dbus-auth-script.c 25 Jun 2006 12:45:02 -0000
@@ -360,19 +360,19 @@
else if (_dbus_string_starts_with_c_str (&line,
"NO_CREDENTIALS"))
{
- DBusCredentials creds = { -1, -1, -1 };
+ DBusCredentials creds = { -1, DBUS_UID_UNSET, -1 };
_dbus_auth_set_credentials (auth, &creds);
}
else if (_dbus_string_starts_with_c_str (&line,
"ROOT_CREDENTIALS"))
{
- DBusCredentials creds = { -1, 0, 0 };
+ DBusCredentials creds = { -1, _dbus_uid_null(), 0 };
_dbus_auth_set_credentials (auth, &creds);
}
else if (_dbus_string_starts_with_c_str (&line,
"SILLY_CREDENTIALS"))
{
- DBusCredentials creds = { -1, 4312, 1232 };
+ DBusCredentials creds = { -1, _dbus_uid_silly(), 1232 };
_dbus_auth_set_credentials (auth, &creds);
}
else if (_dbus_string_starts_with_c_str (&line,
@@ -432,7 +432,7 @@
goto out;
}
- if (!_dbus_string_append_uint (&username,
+ if (!_dbus_string_append_uid (&username,
_dbus_getuid ()))
{
_dbus_warn ("no memory for userid\n");
Index: dbus-auth.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-auth.c,v
retrieving revision 1.47
diff -u -B -b -r1.47 dbus-auth.c
--- dbus-auth.c 30 Nov 2005 19:32:26 -0000 1.47
+++ dbus-auth.c 25 Jun 2006 12:45:03 -0000
@@ -711,7 +711,7 @@
goto out_3;
_dbus_verbose ("%s: authenticated client with UID "DBUS_UID_FORMAT" using DBUS_COOKIE_SHA1\n",
- DBUS_AUTH_NAME (auth), auth->desired_identity.uid);
+ DBUS_AUTH_NAME (auth), _dbus_uid_print(&auth->desired_identity.uid));
auth->authorized_identity = auth->desired_identity;
retval = TRUE;
@@ -966,7 +966,7 @@
handle_server_data_external_mech (DBusAuth *auth,
const DBusString *data)
{
- if (auth->credentials.uid == DBUS_UID_UNSET)
+ if (_dbus_uid_is_unset(&auth->credentials.uid))
{
_dbus_verbose ("%s: no credentials, mechanism EXTERNAL can't authenticate\n",
DBUS_AUTH_NAME (auth));
@@ -1027,7 +1027,7 @@
}
}
- if (auth->desired_identity.uid == DBUS_UID_UNSET)
+ if (_dbus_uid_is_unset(&auth->desired_identity.uid))
{
_dbus_verbose ("%s: desired user %s is no good\n",
DBUS_AUTH_NAME (auth),
@@ -1045,8 +1045,8 @@
_dbus_verbose ("%s: authenticated client with UID "DBUS_UID_FORMAT
" matching socket credentials UID "DBUS_UID_FORMAT"\n",
DBUS_AUTH_NAME (auth),
- auth->desired_identity.uid,
- auth->credentials.uid);
+ _dbus_uid_print(&auth->desired_identity.uid),
+ _dbus_uid_print(&auth->credentials.uid));
auth->authorized_identity.pid = auth->credentials.pid;
auth->authorized_identity.uid = auth->desired_identity.uid;
@@ -1059,8 +1059,8 @@
" do not allow uid="DBUS_UID_FORMAT
" gid="DBUS_GID_FORMAT"\n",
DBUS_AUTH_NAME (auth),
- auth->credentials.uid, auth->credentials.gid,
- auth->desired_identity.uid, auth->desired_identity.gid);
+ _dbus_uid_print(&auth->credentials.uid), auth->credentials.gid,
+ _dbus_uid_print(&auth->desired_identity.uid), auth->desired_identity.gid);
return send_rejected (auth);
}
}
@@ -1085,7 +1085,7 @@
if (!_dbus_string_init (&plaintext))
return FALSE;
- if (!_dbus_string_append_uint (&plaintext,
+ if (!_dbus_string_append_uid (&plaintext,
_dbus_getuid ()))
goto failed;
Index: dbus-bus.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-bus.c,v
retrieving revision 1.50
diff -u -B -b -r1.50 dbus-bus.c
--- dbus-bus.c 3 May 2006 22:56:35 -0000 1.50
+++ dbus-bus.c 25 Jun 2006 12:45:04 -0000
@@ -582,7 +582,7 @@
* @param error location to store the error
* @returns a result code, -1 if error is set
*/
-unsigned long
+DBusUID
dbus_bus_get_unix_user (DBusConnection *connection,
const char *name,
DBusError *error)
@@ -644,7 +644,9 @@
dbus_message_unref (reply);
- return (unsigned long) uid;
+ DBusUID unix_uid;
+ _dbus_uid_set_id(&unix_uid, uid);
+ return unix_uid;
}
Index: dbus-bus.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-bus.h,v
retrieving revision 1.16
diff -u -B -b -r1.16 dbus-bus.h
--- dbus-bus.h 15 Nov 2005 17:19:19 -0000 1.16
+++ dbus-bus.h 25 Jun 2006 12:45:04 -0000
@@ -41,7 +41,7 @@
dbus_bool_t dbus_bus_set_unique_name (DBusConnection *connection,
const char *unique_name);
const char* dbus_bus_get_unique_name (DBusConnection *connection);
-unsigned long dbus_bus_get_unix_user (DBusConnection *connection,
+struct DBusUID dbus_bus_get_unix_user (DBusConnection *connection,
const char *name,
DBusError *error);
int dbus_bus_request_name (DBusConnection *connection,
Index: dbus-connection.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
retrieving revision 1.40
diff -u -B -b -r1.40 dbus-connection.h
--- dbus-connection.h 30 Nov 2005 20:30:02 -0000 1.40
+++ dbus-connection.h 25 Jun 2006 12:45:04 -0000
@@ -31,6 +31,7 @@
#include <dbus/dbus-memory.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-shared.h>
+#include <dbus/dbus-sysdeps.h>
DBUS_BEGIN_DECLS
@@ -76,7 +77,7 @@
void *data);
typedef void (* DBusWakeupMainFunction) (void *data);
typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,
- unsigned long uid,
+ struct DBusUID uid,
void *data);
typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
Index: dbus-string.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.c,v
retrieving revision 1.69
diff -u -B -b -r1.69 dbus-string.c
--- dbus-string.c 16 Feb 2006 00:43:41 -0000 1.69
+++ dbus-string.c 25 Jun 2006 12:45:05 -0000
@@ -1178,6 +1178,17 @@
return TRUE;
}
+dbus_bool_t _dbus_string_append_uid (DBusString *str,
+ DBusUID value)
+{
+#ifdef _WIN32
+
+#else
+ return _dbus_string_append_uint(str,_dbus_uid_get_id(&value));
+#endif
+}
+
+
/**
* Appends a printf-style formatted string
* to the #DBusString.
Index: dbus-string.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-string.h,v
retrieving revision 1.39
diff -u -B -b -r1.39 dbus-string.h
--- dbus-string.h 11 Feb 2005 03:37:03 -0000 1.39
+++ dbus-string.h 25 Jun 2006 12:45:05 -0000
@@ -156,6 +156,8 @@
dbus_bool_t _dbus_string_append_printf_valist (DBusString *str,
const char *format,
va_list args);
+dbus_bool_t _dbus_string_append_uid (DBusString *str,
+ DBusUID value);
dbus_bool_t _dbus_string_insert_2_aligned (DBusString *str,
int insert_at,
const unsigned char octets[2]);
Index: dbus-sysdeps-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-util.c,v
retrieving revision 1.6
diff -u -B -b -r1.6 dbus-sysdeps-util.c
--- dbus-sysdeps-util.c 24 Feb 2006 16:13:08 -0000 1.6
+++ dbus-sysdeps-util.c 25 Jun 2006 12:45:05 -0000
@@ -243,7 +243,7 @@
* @returns #FALSE on failure
*/
dbus_bool_t
-_dbus_change_identity (dbus_uid_t uid,
+_dbus_change_identity (DBusUID uid,
dbus_gid_t gid,
DBusError *error)
{
@@ -268,7 +268,7 @@
return FALSE;
}
- if (setuid (uid) < 0)
+ if (setuid (_dbus_uid_get_id(&uid)) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to set UID to %lu: %s", uid,
@@ -425,7 +425,7 @@
statbuf->mode = sb.st_mode;
statbuf->nlink = sb.st_nlink;
- statbuf->uid = sb.st_uid;
+ _dbus_uid_set_id(&statbuf->uid,sb.st_uid);
statbuf->gid = sb.st_gid;
statbuf->size = sb.st_size;
statbuf->atime = sb.st_atime;
Index: dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.102
diff -u -B -b -r1.102 dbus-sysdeps.c
--- dbus-sysdeps.c 30 May 2006 15:34:10 -0000 1.102
+++ dbus-sysdeps.c 25 Jun 2006 12:45:07 -0000
@@ -950,7 +950,7 @@
cr_len == sizeof (cr))
{
credentials->pid = cr.pid;
- credentials->uid = cr.uid;
+ _dbus_uid_set_id(&credentials->uid, cr.uid);
credentials->gid = cr.gid;
}
else
@@ -998,7 +998,7 @@
" uid "DBUS_UID_FORMAT
" gid "DBUS_GID_FORMAT"\n",
credentials->pid,
- credentials->uid,
+ _dbus_uid_print(&credentials->uid),
credentials->gid);
return TRUE;
@@ -1515,7 +1515,7 @@
_dbus_assert (p->pw_name != NULL);
_dbus_assert (p->pw_dir != NULL);
- info->uid = p->pw_uid;
+ _dbus_uid_set_id(&info->uid,p->pw_uid);
info->primary_gid = p->pw_gid;
info->username = _dbus_strdup (p->pw_name);
info->homedir = _dbus_strdup (p->pw_dir);
@@ -1532,15 +1532,15 @@
static dbus_bool_t
fill_user_info (DBusUserInfo *info,
- dbus_uid_t uid,
+ DBusUID uid,
const DBusString *username,
DBusError *error)
{
const char *username_c;
/* exactly one of username/uid provided */
- _dbus_assert (username != NULL || uid != DBUS_UID_UNSET);
- _dbus_assert (username == NULL || uid == DBUS_UID_UNSET);
+ _dbus_assert (username != NULL || !_dbus_uid_is_unset(&uid));
+ _dbus_assert (username == NULL || _dbus_uid_is_unset(&uid));
info->uid = DBUS_UID_UNSET;
info->primary_gid = DBUS_GID_UNSET;
@@ -1568,15 +1568,15 @@
p = NULL;
#ifdef HAVE_POSIX_GETPWNAM_R
- if (uid != DBUS_UID_UNSET)
- result = getpwuid_r (uid, &p_str, buf, sizeof (buf),
+ if (!_dbus_uid_is_unset(&uid))
+ result = getpwuid_r (_dbus_uid_get_id(&uid), &p_str, buf, sizeof (buf),
&p);
else
result = getpwnam_r (username_c, &p_str, buf, sizeof (buf),
&p);
#else
- if (uid != DBUS_UID_UNSET)
- p = getpwuid_r (uid, &p_str, buf, sizeof (buf));
+ if (!_dbus_uid_is_unset(&uid))
+ p = getpwuid_r (_dbus_uid_get_id(&uid), &p_str, buf, sizeof (buf));
else
p = getpwnam_r (username_c, &p_str, buf, sizeof (buf));
result = 0;
@@ -1600,7 +1600,7 @@
/* I guess we're screwed on thread safety here */
struct passwd *p;
- if (uid != DBUS_UID_UNSET)
+ if (!_dbus_uid_is_unset(&uid))
p = getpwuid (uid);
else
p = getpwnam (username_c);
@@ -1733,7 +1733,7 @@
*/
dbus_bool_t
_dbus_user_info_fill_uid (DBusUserInfo *info,
- dbus_uid_t uid,
+ DBusUID uid,
DBusError *error)
{
return fill_user_info (info, uid,
@@ -1795,7 +1795,7 @@
_dbus_assert (sizeof (gid_t) <= sizeof (credentials->gid));
credentials->pid = getpid ();
- credentials->uid = getuid ();
+ _dbus_uid_set_id(&credentials->uid, getuid ());
credentials->gid = getgid ();
}
@@ -1811,13 +1811,13 @@
_dbus_credentials_match (const DBusCredentials *expected_credentials,
const DBusCredentials *provided_credentials)
{
- if (provided_credentials->uid == DBUS_UID_UNSET)
+ if (_dbus_uid_is_unset(&provided_credentials->uid))
return FALSE;
- else if (expected_credentials->uid == DBUS_UID_UNSET)
+ else if (_dbus_uid_is_unset(&expected_credentials->uid))
return FALSE;
- else if (provided_credentials->uid == 0)
+ else if (_dbus_uid_is_null(&provided_credentials->uid))
return TRUE;
- else if (provided_credentials->uid == expected_credentials->uid)
+ else if (_dbus_uid_equal(&provided_credentials->uid, &expected_credentials->uid))
return TRUE;
else
return FALSE;
@@ -1836,10 +1836,12 @@
/** Gets our UID
* @returns process UID
*/
-dbus_uid_t
+DBusUID
_dbus_getuid (void)
{
- return getuid ();
+ DBusUID uid;
+ _dbus_uid_set_id(&uid,getuid());
+ return uid;
}
#ifdef DBUS_BUILD_TESTS
@@ -2891,7 +2893,7 @@
*/
dbus_bool_t
_dbus_parse_uid (const DBusString *uid_str,
- dbus_uid_t *uid)
+ DBusUID *uid)
{
int end;
long val;
@@ -2917,7 +2919,7 @@
return FALSE;
}
- *uid = val;
+ _dbus_uid_set_id(uid, val);
return TRUE;
}
@@ -2983,6 +2985,61 @@
#endif
}
+#ifdef _WIN32
+
+#else
+
+#define ID DBUS_UID_IMPL_VAR_NAME
+
+DBusUID _dbus_uid_unset(void)
+{
+ return (DBusUID){-1};
+}
+
+DBusUID _dbus_uid_null(void)
+{
+ return (DBusUID){0};
+}
+
+DBusUID _dbus_uid_silly(void)
+{
+ return (DBusUID){4312};
+}
+
+void _dbus_uid_set_id(DBusUID *uid, DBUS_UID_IMPL value)
+{
+ uid->ID = value;
+}
+
+DBUS_UID_IMPL _dbus_uid_get_id(DBusUID *uid)
+{
+ return uid->ID;
+}
+
+dbus_bool_t _dbus_uid_equal(const DBusUID *uid1, const DBusUID *uid2)
+{
+ return uid1->ID == uid2->ID;
+}
+
+dbus_bool_t _dbus_uid_is_unset(const DBusUID *uid)
+{
+
+ return uid->ID == (unsigned long) -1;
+}
+
+dbus_bool_t _dbus_uid_is_null(const DBusUID *uid)
+{
+ return uid->ID == 0;
+}
+
+DBUS_UID_PRINT _dbus_uid_print(DBusUID *uid)
+{
+ return uid->ID;
+}
+
+#undef ID
+#endif
+
/** @} end of sysdeps */
/* tests in dbus-sysdeps-util.c */
Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.49
diff -u -B -b -r1.49 dbus-sysdeps.h
--- dbus-sysdeps.h 8 Jul 2005 14:36:22 -0000 1.49
+++ dbus-sysdeps.h 25 Jun 2006 12:45:08 -0000
@@ -88,24 +88,53 @@
int len2);
typedef unsigned long dbus_pid_t;
-typedef unsigned long dbus_uid_t;
typedef unsigned long dbus_gid_t;
#define DBUS_PID_UNSET ((dbus_pid_t) -1)
-#define DBUS_UID_UNSET ((dbus_uid_t) -1)
#define DBUS_GID_UNSET ((dbus_gid_t) -1)
#define DBUS_PID_FORMAT "%lu"
-#define DBUS_UID_FORMAT "%lu"
#define DBUS_GID_FORMAT "%lu"
+
+#ifdef _WIN32
+
+#else
+#define DBUS_UID_IMPL unsigned long
+#define DBUS_UID_FORMAT "%lu"
+#define DBUS_UID_PRINT DBUS_UID_IMPL
+/*#define DBUS_UID_UNSET ((DBusUID) {-1}) */
+#define DBUS_UID_UNSET _dbus_uid_unset()
+#endif
+
+#define DBUS_UID_IMPL_VAR_NAME id_name_to_long_for_usage
+
+typedef struct DBusUID
+{
+ DBUS_UID_IMPL DBUS_UID_IMPL_VAR_NAME;
+} DBusUID;
+
+
+DBusUID _dbus_uid_unset(void);
+DBusUID _dbus_uid_null(void);
+DBusUID _dbus_uid_silly(void);
+
+void _dbus_uid_set_id(DBusUID *uid, DBUS_UID_IMPL value);
+DBUS_UID_IMPL _dbus_uid_get_id(DBusUID *uid);
+
+dbus_bool_t _dbus_uid_equal(const DBusUID *uid1, const DBusUID *uid2);
+dbus_bool_t _dbus_uid_is_unset(const DBusUID *uid);
+dbus_bool_t _dbus_uid_is_null(const DBusUID *uid);
+
+DBUS_UID_PRINT _dbus_uid_print(DBusUID *uid);
+
/**
* Struct representing socket credentials
*/
typedef struct
{
dbus_pid_t pid; /**< process ID or DBUS_PID_UNSET */
- dbus_uid_t uid; /**< user ID or DBUS_UID_UNSET */
+ DBusUID uid; /**< user ID or DBUS_UID_UNSET */
dbus_gid_t gid; /**< group ID or DBUS_GID_UNSET */
} DBusCredentials;
@@ -144,7 +173,7 @@
*/
struct DBusUserInfo
{
- dbus_uid_t uid; /**< UID */
+ DBusUID uid; /**< UID */
dbus_gid_t primary_gid; /**< GID */
dbus_gid_t *group_ids; /**< Groups IDs, *including* above primary group */
int n_group_ids; /**< Size of group IDs array */
@@ -165,7 +194,7 @@
const DBusString *username,
DBusError *error);
dbus_bool_t _dbus_user_info_fill_uid (DBusUserInfo *info,
- dbus_uid_t uid,
+ DBusUID uid,
DBusError *error);
void _dbus_user_info_free (DBusUserInfo *info);
@@ -179,7 +208,7 @@
unsigned long _dbus_getpid (void);
-dbus_uid_t _dbus_getuid (void);
+DBusUID _dbus_getuid (void);
dbus_gid_t _dbus_getgid (void);
typedef struct DBusAtomic DBusAtomic;
@@ -279,7 +308,7 @@
{
unsigned long mode; /**< File mode */
unsigned long nlink; /**< Number of hard links */
- dbus_uid_t uid; /**< User owning file */
+ DBusUID uid; /**< User owning file */
dbus_gid_t gid; /**< Group owning file */
unsigned long size; /**< Size of file */
unsigned long atime; /**< Access time */
@@ -305,7 +334,7 @@
dbus_bool_t _dbus_write_pid_file (const DBusString *filename,
unsigned long pid,
DBusError *error);
-dbus_bool_t _dbus_change_identity (unsigned long uid,
+dbus_bool_t _dbus_change_identity (DBusUID uid,
unsigned long gid,
DBusError *error);
@@ -348,7 +377,7 @@
_DBUS_BYTE_OF_PRIMITIVE (a, 7) == _DBUS_BYTE_OF_PRIMITIVE (b, 7))
dbus_bool_t _dbus_parse_uid (const DBusString *uid_str,
- dbus_uid_t *uid);
+ DBusUID *uid);
DBUS_END_DECLS
Index: dbus-transport.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
retrieving revision 1.46
diff -u -B -b -r1.46 dbus-transport.c
--- dbus-transport.c 5 May 2005 22:02:11 -0000 1.46
+++ dbus-transport.c 25 Jun 2006 12:45:08 -0000
@@ -162,7 +162,7 @@
transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
transport->credentials.pid = -1;
- transport->credentials.uid = -1;
+ transport->credentials.uid = DBUS_UID_UNSET;
transport->credentials.gid = -1;
_dbus_counter_set_notify (transport->live_messages_size,
@@ -533,13 +533,13 @@
if (allow)
{
- _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", auth_identity.uid);
+ _dbus_verbose ("Client UID "DBUS_UID_FORMAT" authorized\n", _dbus_uid_print(&auth_identity.uid));
}
else
{
_dbus_verbose ("Client UID "DBUS_UID_FORMAT
" was rejected, disconnecting\n",
- auth_identity.uid);
+ _dbus_uid_print(&auth_identity.uid));
_dbus_transport_disconnect (transport);
_dbus_connection_unref_unlocked (connection);
return FALSE;
@@ -556,7 +556,7 @@
{
_dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
" but our UID is "DBUS_UID_FORMAT", disconnecting\n",
- auth_identity.uid, our_identity.uid);
+ _dbus_uid_print(&auth_identity.uid), _dbus_uid_print(&our_identity.uid));
_dbus_transport_disconnect (transport);
_dbus_connection_unref_unlocked (transport->connection);
return FALSE;
@@ -565,7 +565,7 @@
{
_dbus_verbose ("Client authorized as UID "DBUS_UID_FORMAT
" matching our UID "DBUS_UID_FORMAT"\n",
- auth_identity.uid, our_identity.uid);
+ _dbus_uid_print(&auth_identity.uid), _dbus_uid_print(&our_identity.uid));
}
}
}
@@ -977,9 +977,9 @@
_dbus_auth_get_identity (transport->auth, &auth_identity);
- if (auth_identity.uid != DBUS_UID_UNSET)
+ if (!_dbus_uid_is_unset(&auth_identity.uid))
{
- *uid = auth_identity.uid;
+ *uid = _dbus_uid_get_id(&auth_identity.uid);
return TRUE;
}
else
Index: dbus-userdb-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb-util.c,v
retrieving revision 1.7
diff -u -B -b -r1.7 dbus-userdb-util.c
--- dbus-userdb-util.c 7 Jun 2006 19:59:11 -0000 1.7
+++ dbus-userdb-util.c 25 Jun 2006 12:45:08 -0000
@@ -40,7 +40,7 @@
* @returns #TRUE if the UID is the same as the console user and there are no errors
*/
dbus_bool_t
-_dbus_is_console_user (dbus_uid_t uid,
+_dbus_is_console_user (DBusUID uid,
DBusError *error)
{
@@ -110,7 +110,7 @@
* @returns #TRUE if the UID existed and we got some credentials
*/
dbus_bool_t
-_dbus_credentials_from_uid (dbus_uid_t uid,
+_dbus_credentials_from_uid (DBusUID uid,
DBusCredentials *credentials)
{
DBusUserDatabase *db;
@@ -131,7 +131,7 @@
return FALSE;
}
- _dbus_assert (info->uid == uid);
+ _dbus_assert (_dbus_uid_equal(&info->uid, &uid));
credentials->pid = DBUS_PID_UNSET;
credentials->uid = info->uid;
@@ -151,14 +151,14 @@
*/
dbus_bool_t
_dbus_get_user_id (const DBusString *username,
- dbus_uid_t *uid)
+ DBusUID *uid)
{
DBusCredentials creds;
if (!_dbus_credentials_from_username (username, &creds))
return FALSE;
- if (creds.uid == DBUS_UID_UNSET)
+ if (_dbus_uid_is_unset(&creds.uid))
return FALSE;
*uid = creds.uid;
@@ -224,7 +224,9 @@
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
/* See if the group is really a number */
- if (gid == DBUS_UID_UNSET)
+ DBusUID u_g_id;
+ _dbus_uid_set_id(&u_g_id, gid);
+ if (_dbus_uid_is_unset(&u_g_id))
{
unsigned long n;
@@ -361,7 +363,7 @@
*/
dbus_bool_t
_dbus_user_database_get_groups (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
dbus_gid_t **group_ids,
int *n_group_ids,
DBusError *error)
Index: dbus-userdb.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.c,v
retrieving revision 1.19
diff -u -B -b -r1.19 dbus-userdb.c
--- dbus-userdb.c 6 Mar 2006 19:06:45 -0000 1.19
+++ dbus-userdb.c 25 Jun 2006 12:45:08 -0000
@@ -100,40 +100,40 @@
*/
DBusUserInfo*
_dbus_user_database_lookup (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
const DBusString *username,
DBusError *error)
{
DBusUserInfo *info;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- _dbus_assert (uid != DBUS_UID_UNSET || username != NULL);
+ _dbus_assert (!_dbus_uid_is_unset(&uid) || username != NULL);
/* See if the username is really a number */
- if (uid == DBUS_UID_UNSET)
+ if (_dbus_uid_is_unset(&uid))
{
unsigned long n;
if (_dbus_is_a_number (username, &n))
- uid = n;
+ _dbus_uid_set_id(&uid, n);
}
- if (uid != DBUS_UID_UNSET)
- info = _dbus_hash_table_lookup_ulong (db->users, uid);
+ if (!_dbus_uid_is_unset(&uid))
+ info = _dbus_hash_table_lookup_ulong (db->users, _dbus_uid_get_id(&uid));
else
info = _dbus_hash_table_lookup_string (db->users_by_name, _dbus_string_get_const_data (username));
if (info)
{
_dbus_verbose ("Using cache for UID "DBUS_UID_FORMAT" information\n",
- info->uid);
+ _dbus_uid_print(&info->uid));
return info;
}
else
{
- if (uid != DBUS_UID_UNSET)
+ if (!_dbus_uid_is_unset(&uid))
_dbus_verbose ("No cache for UID "DBUS_UID_FORMAT"\n",
- uid);
+ _dbus_uid_print(&uid));
else
_dbus_verbose ("No cache for user \"%s\"\n",
_dbus_string_get_const_data (username));
@@ -145,7 +145,7 @@
return NULL;
}
- if (uid != DBUS_UID_UNSET)
+ if (!_dbus_uid_is_unset(&uid))
{
if (!_dbus_user_info_fill_uid (info, uid, error))
{
@@ -169,7 +169,7 @@
username = NULL;
/* insert into hash */
- if (!_dbus_hash_table_insert_ulong (db->users, info->uid, info))
+ if (!_dbus_hash_table_insert_ulong (db->users, _dbus_uid_get_id(&info->uid), info))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_user_info_free_allocated (info);
@@ -180,7 +180,7 @@
info->username,
info))
{
- _dbus_hash_table_remove_ulong (db->users, info->uid);
+ _dbus_hash_table_remove_ulong (db->users, _dbus_uid_get_id(&info->uid));
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
@@ -545,7 +545,7 @@
*/
dbus_bool_t
_dbus_user_database_get_uid (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
const DBusUserInfo **info,
DBusError *error)
{
Index: dbus-userdb.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-userdb.h,v
retrieving revision 1.11
diff -u -B -b -r1.11 dbus-userdb.h
--- dbus-userdb.h 6 Mar 2006 19:06:45 -0000 1.11
+++ dbus-userdb.h 25 Jun 2006 12:45:08 -0000
@@ -54,12 +54,12 @@
void _dbus_user_database_flush (DBusUserDatabase *db);
void _dbus_user_database_unref (DBusUserDatabase *db);
dbus_bool_t _dbus_user_database_get_groups (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
dbus_gid_t **group_ids,
int *n_group_ids,
DBusError *error);
dbus_bool_t _dbus_user_database_get_uid (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
const DBusUserInfo **info,
DBusError *error);
dbus_bool_t _dbus_user_database_get_gid (DBusUserDatabase *db,
@@ -77,7 +77,7 @@
#ifdef DBUS_USERDB_INCLUDES_PRIVATE
DBusUserInfo* _dbus_user_database_lookup (DBusUserDatabase *db,
- dbus_uid_t uid,
+ DBusUID uid,
const DBusString *username,
DBusError *error);
DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
@@ -97,14 +97,14 @@
dbus_bool_t _dbus_homedir_from_username (const DBusString *username,
DBusString *homedir);
dbus_bool_t _dbus_get_user_id (const DBusString *username,
- dbus_uid_t *uid);
+ DBusUID *uid);
dbus_bool_t _dbus_get_group_id (const DBusString *group_name,
dbus_gid_t *gid);
dbus_bool_t _dbus_credentials_from_username (const DBusString *username,
DBusCredentials *credentials);
-dbus_bool_t _dbus_credentials_from_uid (dbus_uid_t user_id,
+dbus_bool_t _dbus_credentials_from_uid (DBusUID user_id,
DBusCredentials *credentials);
-dbus_bool_t _dbus_is_console_user (dbus_uid_t uid,
+dbus_bool_t _dbus_is_console_user (DBusUID uid,
DBusError *error);
dbus_bool_t _dbus_is_a_number (const DBusString *str,
More information about the dbus
mailing list