From b3bd9b934345e39586360bb19169a2c9bf49edd2 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 31 Oct 2015 21:00:00 +0100 Subject: [PATCH] Fix bus-test error 'Unknown username "root" on element '. --- bus/config-parser.c | 58 ++++++++++++++++++++++++++++++++++++++++---- bus/policy.c | 6 +++++ bus/policy.h | 2 ++ dbus/dbus-sysdeps-util-win.c | 36 +++++++++++++++++++++++++++ dbus/dbus-sysdeps.h | 5 ++++ 5 files changed, 102 insertions(+), 5 deletions(-) diff --git a/bus/config-parser.c b/bus/config-parser.c index a7d8f96..7cdcab1 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -66,7 +66,10 @@ typedef struct struct { PolicyType type; - unsigned long gid_uid_or_at_console; + unsigned long gid_uid_or_at_console; +#ifdef DBUS_WIN + char *group_user_sid; +#endif } policy; struct @@ -152,7 +155,11 @@ element_free (Element *e) { if (e->type == ELEMENT_LIMIT) dbus_free (e->d.limit.name); - +#ifdef DBUS_WIN + else if (e->type == ELEMENT_POLICY) + dbus_free (e->d.policy.group_user_sid); +#endif + dbus_free (e); } @@ -1044,9 +1051,14 @@ start_busconfig_child (BusConfigParser *parser, { DBusString username; _dbus_string_init_const (&username, user); +#ifdef DBUS_WIN + if (_dbus_parse_windows_user_from_config (&username, + &e->d.policy.group_user_sid)) +#else if (_dbus_parse_unix_user_from_config (&username, &e->d.policy.gid_uid_or_at_console)) +#endif e->d.policy.type = POLICY_USER; else _dbus_warn ("Unknown username \"%s\" in message bus configuration file\n", @@ -1056,9 +1068,14 @@ start_busconfig_child (BusConfigParser *parser, { DBusString group_name; _dbus_string_init_const (&group_name, group); +#ifdef DBUS_WIN + if (_dbus_parse_windows_group_from_config (&group_name, + &e->d.policy.group_user_sid)) +#else if (_dbus_parse_unix_group_from_config (&group_name, &e->d.policy.gid_uid_or_at_console)) +#endif e->d.policy.type = POLICY_GROUP; else _dbus_warn ("Unknown group \"%s\" in message bus configuration file\n", @@ -1562,22 +1579,37 @@ append_rule_from_element (BusConfigParser *parser, if (rule == NULL) goto nomem; +#ifdef DBUS_WIN + rule->d.user.sid = 0; +#else rule->d.user.uid = DBUS_UID_UNSET; +#endif } else { DBusString username; +#ifdef DBUS_WIN + char *sid; +#else dbus_uid_t uid; - +#endif + _dbus_string_init_const (&username, user); - +#ifdef DBUS_WIN + if (_dbus_parse_windows_user_from_config (&username, &sid)) +#else if (_dbus_parse_unix_user_from_config (&username, &uid)) +#endif { rule = bus_policy_rule_new (BUS_POLICY_RULE_USER, allow); if (rule == NULL) goto nomem; +#ifdef DBUS_WIN + rule->d.user.sid = sid; +#else rule->d.user.uid = uid; +#endif } else { @@ -1594,22 +1626,38 @@ append_rule_from_element (BusConfigParser *parser, if (rule == NULL) goto nomem; +#ifdef DBUS_WIN + rule->d.user.sid = 0; +#else rule->d.group.gid = DBUS_GID_UNSET; +#endif } else { DBusString groupname; +#ifdef DBUS_WIN + char *sid; +#else dbus_gid_t gid; - +#endif + _dbus_string_init_const (&groupname, group); +#ifdef DBUS_WIN + if (_dbus_parse_windows_group_from_config (&groupname, &sid)) +#else if (_dbus_parse_unix_group_from_config (&groupname, &gid)) +#endif { rule = bus_policy_rule_new (BUS_POLICY_RULE_GROUP, allow); if (rule == NULL) goto nomem; +#ifdef DBUS_WIN + rule->d.group.sid = sid; +#else rule->d.group.gid = gid; +#endif } else { diff --git a/bus/policy.c b/bus/policy.c index 082f385..de02b8a 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -113,8 +113,14 @@ bus_policy_rule_unref (BusPolicyRule *rule) dbus_free (rule->d.own.service_name); break; case BUS_POLICY_RULE_USER: +#ifdef DBUS_WIN + dbus_free (rule->d.user.sid); +#endif break; case BUS_POLICY_RULE_GROUP: +#ifdef DBUS_WIN + dbus_free (rule->d.group.sid); +#endif break; } diff --git a/bus/policy.h b/bus/policy.h index d1d3e72..99fb07a 100644 --- a/bus/policy.h +++ b/bus/policy.h @@ -94,12 +94,14 @@ struct BusPolicyRule { /* can be DBUS_UID_UNSET meaning "any" */ dbus_uid_t uid; + char *sid; } user; struct { /* can be DBUS_GID_UNSET meaning "any" */ dbus_gid_t gid; + char *sid; } group; } d; diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index da0abe1..6e754c0 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -785,7 +785,43 @@ _dbus_unix_groups_from_uid (dbus_uid_t uid, return FALSE; } +/** + * Parse a windows group from the bus config file. On Unix, this should + * simply always fail (just return #FALSE). + * + * @param groupname the groupname text + * @param gid_p place to return the gid (need to be freed) + * @returns #TRUE on success + */ +dbus_bool_t +_dbus_parse_windows_group_from_config (const DBusString *groupname, + char **gid_p) +{ + char *s = _dbus_strdup(_dbus_string_get_const_data (groupname)); + if (!s) + return FALSE; + *gid_p = s; + return TRUE; +} +/** + * Parse a windows user from the bus config file. On UNIX, this should + * simply always fail (just return #FALSE). + * + * @param username the username text + * @param uid_p place to return the uid (need to be freed) + * @returns #TRUE on success + */ +dbus_bool_t +_dbus_parse_windows_user_from_config (const DBusString *username, + char **uid_p) +{ + char *s = _dbus_strdup(_dbus_string_get_const_data (username)); + if (!s) + return FALSE; + *uid_p = s; + return TRUE; +} /** @} */ /* DBusString stuff */ diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 79a6cc7..1e86f38 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -255,6 +255,11 @@ dbus_bool_t _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_bool_t _dbus_unix_user_is_at_console (dbus_uid_t uid, DBusError *error); dbus_bool_t _dbus_unix_user_is_process_owner (dbus_uid_t uid); + +dbus_bool_t _dbus_parse_windows_user_from_config (const DBusString *username, + char **uid_p); +dbus_bool_t _dbus_parse_windows_group_from_config (const DBusString *username, + char **gid_p); dbus_bool_t _dbus_windows_user_is_process_owner (const char *windows_sid); dbus_bool_t _dbus_append_keyring_directory_for_credentials (DBusString *directory, -- 1.8.4.5