Commit a2932ccc authored by Simon McVittie's avatar Simon McVittie

_dbus_credentials_add_from_user: Add proper error reporting

While I'm changing its signature anyway, I might as well fix a
long-standing FIXME.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104588
parent 5634b2fe
......@@ -549,10 +549,18 @@ sha1_handle_first_client_response (DBusAuth *auth,
}
}
if (!_dbus_credentials_add_from_user (auth->desired_identity, data))
if (!_dbus_credentials_add_from_user (auth->desired_identity, data,
&error))
{
_dbus_verbose ("%s: Did not get a valid username from client\n",
DBUS_AUTH_NAME (auth));
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_error_free (&error);
goto out;
}
_dbus_verbose ("%s: Did not get a valid username from client: %s\n",
DBUS_AUTH_NAME (auth), error.message);
dbus_error_free (&error);
return send_rejected (auth);
}
......@@ -1108,11 +1116,21 @@ handle_server_data_external_mech (DBusAuth *auth,
}
else
{
DBusError error = DBUS_ERROR_INIT;
if (!_dbus_credentials_add_from_user (auth->desired_identity,
&auth->identity))
&auth->identity,
&error))
{
_dbus_verbose ("%s: could not get credentials from uid string\n",
DBUS_AUTH_NAME (auth));
if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
dbus_error_free (&error);
return FALSE;
}
_dbus_verbose ("%s: could not get credentials from uid string: %s\n",
DBUS_AUTH_NAME (auth), error.message);
dbus_error_free (&error);
return send_rejected (auth);
}
}
......
......@@ -2064,11 +2064,18 @@ _dbus_concat_dir_and_file (DBusString *dir,
* @returns #TRUE if the username existed and we got some credentials
*/
dbus_bool_t
_dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username)
_dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username,
DBusError *error)
{
return _dbus_credentials_add_windows_sid (credentials,
_dbus_string_get_const_data(username));
if (!_dbus_credentials_add_windows_sid (credentials,
_dbus_string_get_const_data (username)))
{
_DBUS_SET_OOM (error);
return FALSE;
}
return TRUE;
}
/**
......
......@@ -240,8 +240,10 @@ dbus_bool_t _dbus_read_credentials_socket (DBusSocket client_fd,
dbus_bool_t _dbus_send_credentials_socket (DBusSocket server_fd,
DBusError *error);
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username);
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username,
DBusError *error);
dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_append_user_from_current_process (DBusString *str);
......
......@@ -517,8 +517,9 @@ _dbus_homedir_from_uid (dbus_uid_t uid,
* @returns #TRUE if the username existed and we got some credentials
*/
dbus_bool_t
_dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username)
_dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username,
DBusError *error)
{
DBusUserDatabase *db;
const DBusUserInfo *info;
......@@ -535,19 +536,22 @@ _dbus_credentials_add_from_user (DBusCredentials *credentials,
return TRUE;
}
/* FIXME: this can't distinguish ENOMEM from other errors */
if (!_dbus_user_database_lock_system ())
return FALSE;
{
_DBUS_SET_OOM (error);
return FALSE;
}
db = _dbus_user_database_get_system ();
if (db == NULL)
{
_dbus_user_database_unlock_system ();
_DBUS_SET_OOM (error);
return FALSE;
}
if (!_dbus_user_database_get_username (db, username,
&info, NULL))
&info, error))
{
_dbus_user_database_unlock_system ();
return FALSE;
......@@ -556,6 +560,7 @@ _dbus_credentials_add_from_user (DBusCredentials *credentials,
if (!_dbus_credentials_add_unix_uid(credentials, info->uid))
{
_dbus_user_database_unlock_system ();
_DBUS_SET_OOM (error);
return FALSE;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment