25 #include "dbus-internals.h" 26 #include "dbus-test.h" 27 #include "dbus-credentials.h" 28 #include <dbus/dbus-test-tap.h> 37 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 45 const char *windows_sid)
55 { 4, { 1000, 42, 123, 5678 } },
57 { 4, { 5678, 123, 42, 1000 } }
99 memcpy (copy, group_vectors[group_vector - 1].gids,
100 sizeof (
dbus_gid_t) * group_vectors[group_vector - 1].n);
103 group_vectors[group_vector - 1].n);
106 if (windows_sid !=
NULL)
118 #define SAMPLE_SID "whatever a windows sid looks like" 119 #define OTHER_SAMPLE_SID "whatever else" 122 _dbus_credentials_test (
const char *test_data_dir)
130 if (test_data_dir ==
NULL)
133 creds = make_credentials (12, 511, 1, SAMPLE_SID);
135 _dbus_test_fatal (
"oom");
162 _dbus_test_fatal (
"oom");
186 _dbus_test_fatal (
"oom");
195 _dbus_test_fatal (
"oom");
203 creds2 = make_credentials (12,
DBUS_PID_UNSET, 0, OTHER_SAMPLE_SID);
205 _dbus_test_fatal (
"oom");
215 _dbus_test_fatal (
"oom");
225 _dbus_test_fatal (
"oom");
235 _dbus_test_fatal (
"oom");
243 creds2 = make_credentials (12, 511, 2, SAMPLE_SID);
245 _dbus_test_fatal (
"oom");
253 creds2 = make_credentials (12, 511, 3, SAMPLE_SID);
255 _dbus_test_fatal (
"oom");
281 _dbus_test_fatal (
"oom");
285 _dbus_test_fatal (
"oom");
288 _dbus_test_fatal (
"oom");
290 _dbus_test_diag (
"Unix uid only: %s", _dbus_string_get_const_data (&str));
291 _dbus_assert (strcmp (_dbus_string_get_const_data (&str),
296 creds = make_credentials (12, 511, 1,
NULL);
298 _dbus_test_fatal (
"oom");
301 _dbus_test_fatal (
"oom");
304 _dbus_test_fatal (
"oom");
306 _dbus_test_diag (
"Unix complete set: %s", _dbus_string_get_const_data (&str));
307 _dbus_assert (strcmp (_dbus_string_get_const_data (&str),
308 "uid=12 pid=511 gid=42 gid=123 gid=1000 gid=5678") == 0);
314 _dbus_test_fatal (
"oom");
317 _dbus_test_fatal (
"oom");
320 _dbus_test_fatal (
"oom");
322 _dbus_test_diag (
"Windows sid only: %s", _dbus_string_get_const_data (&str));
323 _dbus_assert (strcmp (_dbus_string_get_const_data (&str),
324 "sid=" SAMPLE_SID) == 0);
330 _dbus_test_fatal (
"oom");
333 _dbus_test_fatal (
"oom");
336 _dbus_test_fatal (
"oom");
338 _dbus_test_diag (
"Windows complete set: %s", _dbus_string_get_const_data (&str));
339 _dbus_assert (strcmp (_dbus_string_get_const_data (&str),
340 "pid=511 sid=" SAMPLE_SID) == 0);
dbus_uid_t _dbus_credentials_get_unix_uid(DBusCredentials *credentials)
Gets the UNIX user ID in the credentials, or DBUS_UID_UNSET if the credentials object doesn't contain...
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_credentials_include(DBusCredentials *credentials, DBusCredentialType type)
Checks whether the given credential is present.
DBusCredentials * _dbus_credentials_copy(DBusCredentials *credentials)
Copy a credentials object.
dbus_bool_t _dbus_credentials_are_superset(DBusCredentials *credentials, DBusCredentials *possible_subset)
Checks whether the first credentials object contains all the credentials found in the second credenti...
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
dbus_bool_t _dbus_credentials_add_windows_sid(DBusCredentials *credentials, const char *windows_sid)
Add a Windows user SID to the credentials.
#define DBUS_PID_UNSET
an invalid PID used to represent an uninitialized dbus_pid_t field
void _dbus_credentials_clear(DBusCredentials *credentials)
Clear all credentials in the object.
#define DBUS_UID_UNSET
an invalid UID used to represent an uninitialized dbus_uid_t field
unsigned long dbus_pid_t
A process ID.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_bool_t _dbus_credentials_are_anonymous(DBusCredentials *credentials)
Checks whether a credentials object contains a user identity.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_credentials_take_unix_gids(DBusCredentials *credentials, dbus_gid_t *gids, size_t n_gids)
Add UNIX group IDs to the credentials, replacing any group IDs that might already have been present...
void _dbus_credentials_ref(DBusCredentials *credentials)
Increment refcount on credentials.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(), and fills it with the same contents as #_DBUS_STRING_I...
#define TRUE
Expands to "1".
dbus_bool_t _dbus_credentials_add_pid(DBusCredentials *credentials, dbus_pid_t pid)
Add a UNIX process ID to the credentials.
DBusCredentials * _dbus_credentials_new(void)
Creates a new credentials object.
dbus_pid_t _dbus_credentials_get_pid(DBusCredentials *credentials)
Gets the UNIX process ID in the credentials, or DBUS_PID_UNSET if the credentials object doesn't cont...
dbus_bool_t _dbus_credentials_get_unix_gids(DBusCredentials *credentials, const dbus_gid_t **gids, size_t *n_gids)
Get the Unix group IDs.
void _dbus_credentials_unref(DBusCredentials *credentials)
Decrement refcount on credentials.
dbus_bool_t _dbus_credentials_same_user(DBusCredentials *credentials, DBusCredentials *other_credentials)
Check whether the user-identifying credentials in two credentials objects are identical.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
dbus_bool_t _dbus_credentials_to_string_append(DBusCredentials *credentials, DBusString *string)
Convert the credentials in this object to a human-readable string format, and append to the given str...
const char * _dbus_credentials_get_windows_sid(DBusCredentials *credentials)
Gets the Windows user SID in the credentials, or NULL if the credentials object doesn't contain a Win...
unsigned long dbus_gid_t
A group ID.
dbus_bool_t _dbus_credentials_add_unix_uid(DBusCredentials *credentials, dbus_uid_t uid)
Add a UNIX user ID to the credentials.
unsigned long dbus_uid_t
A user ID.
dbus_bool_t _dbus_credentials_are_empty(DBusCredentials *credentials)
Checks whether a credentials object contains anything.