diff options
author | Colin Walters <walters@verbum.org> | 2010-03-16 09:00:23 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2010-03-16 15:57:27 -0400 |
commit | e48b0928490e175d08a5a33b29b56314c806305c (patch) | |
tree | 8aacacbeab92281ba502803e6d3aeaf0d17e273c | |
parent | 00e031a543bbc388b667e0c79b947f854b4e7e71 (diff) | |
download | dbus-e48b0928490e175d08a5a33b29b56314c806305c.tar.gz |
Add _dbus_credentials_to_string_append
Convert the credentials to a string; useful for logging.
-rw-r--r-- | dbus/dbus-credentials.c | 43 | ||||
-rw-r--r-- | dbus/dbus-credentials.h | 3 |
2 files changed, 45 insertions, 1 deletions
diff --git a/dbus/dbus-credentials.c b/dbus/dbus-credentials.c index f06d5c00..889166ba 100644 --- a/dbus/dbus-credentials.c +++ b/dbus/dbus-credentials.c @@ -502,6 +502,49 @@ _dbus_credentials_same_user (DBusCredentials *credentials, strcmp (credentials->windows_sid, other_credentials->windows_sid) == 0)); } +/** + * Convert the credentials in this object to a human-readable + * string format, and append to the given string. + * + * @param credentials the object + * @param string append to this string + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_credentials_to_string_append (DBusCredentials *credentials, + DBusString *string) +{ + dbus_bool_t join; + + join = FALSE; + if (credentials->unix_uid != DBUS_UID_UNSET) + { + if (!_dbus_string_append_printf (string, "uid=%d", credentials->unix_uid)) + goto oom; + join = TRUE; + } + if (credentials->unix_pid != DBUS_PID_UNSET) + { + if (!_dbus_string_append_printf (string, "%spid=%d", join ? " " : "", credentials->unix_pid)) + goto oom; + join = TRUE; + } + else + join = FALSE; + if (credentials->windows_sid != NULL) + { + if (!_dbus_string_append_printf (string, "%ssid=%s", join ? " " : "", credentials->windows_sid)) + goto oom; + join = TRUE; + } + else + join = FALSE; + + return TRUE; +oom: + return FALSE; +} + /** @} */ /* tests in dbus-credentials-util.c */ diff --git a/dbus/dbus-credentials.h b/dbus/dbus-credentials.h index 25f31b79..ef6124fd 100644 --- a/dbus/dbus-credentials.h +++ b/dbus/dbus-credentials.h @@ -71,7 +71,8 @@ void _dbus_credentials_clear (DBusCredentials DBusCredentials* _dbus_credentials_copy (DBusCredentials *credentials); dbus_bool_t _dbus_credentials_same_user (DBusCredentials *credentials, DBusCredentials *other_credentials); - +dbus_bool_t _dbus_credentials_to_string_append (DBusCredentials *credentials, + DBusString *string); DBUS_END_DECLS |