commit 1748f9e0cdb8553c8986164d8af41f7c7ca07112 Author: Christian Dywan Date: Tue Jun 8 17:15:18 2010 +0200 Rework NEGOTIATE_UNIX_FD as NEGOTIATE_CAPABILITIES Individual capabilities are passed, comma separated. diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c index 3173f34..5e16731 100644 --- a/dbus/dbus-auth.c +++ b/dbus/dbus-auth.c @@ -125,8 +125,8 @@ typedef enum { DBUS_AUTH_COMMAND_OK, DBUS_AUTH_COMMAND_ERROR, DBUS_AUTH_COMMAND_UNKNOWN, - DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD, - DBUS_AUTH_COMMAND_AGREE_UNIX_FD + DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES, + DBUS_AUTH_COMMAND_AGREE_CAPABILITIES } DBusAuthCommand; /** @@ -232,8 +232,8 @@ static dbus_bool_t send_error (DBusAuth *auth, static dbus_bool_t send_ok (DBusAuth *auth); static dbus_bool_t send_begin (DBusAuth *auth); static dbus_bool_t send_cancel (DBusAuth *auth); -static dbus_bool_t send_negotiate_unix_fd (DBusAuth *auth); -static dbus_bool_t send_agree_unix_fd (DBusAuth *auth); +static dbus_bool_t send_negotiate_capabilities (DBusAuth *auth); +static dbus_bool_t send_agree_capabilities (DBusAuth *auth); /** * Client states @@ -272,9 +272,9 @@ static dbus_bool_t handle_client_state_waiting_for_ok (DBusAuth *aut static dbus_bool_t handle_client_state_waiting_for_reject (DBusAuth *auth, DBusAuthCommand command, const DBusString *args); -static dbus_bool_t handle_client_state_waiting_for_agree_unix_fd (DBusAuth *auth, - DBusAuthCommand command, - const DBusString *args); +static dbus_bool_t handle_client_state_waiting_for_agree_capabilities (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args); static const DBusAuthStateData client_state_need_send_auth = { "NeedSendAuth", NULL @@ -288,8 +288,8 @@ static const DBusAuthStateData client_state_waiting_for_ok = { static const DBusAuthStateData client_state_waiting_for_reject = { "WaitingForReject", handle_client_state_waiting_for_reject }; -static const DBusAuthStateData client_state_waiting_for_agree_unix_fd = { - "WaitingForAgreeUnixFD", handle_client_state_waiting_for_agree_unix_fd +static const DBusAuthStateData client_state_waiting_for_agree_capabilities = { + "WaitingForAgreeCapabilities", handle_client_state_waiting_for_agree_capabilities }; /** @@ -1584,9 +1584,9 @@ process_ok(DBusAuth *auth, _dbus_string_get_const_data (& DBUS_AUTH_CLIENT (auth)->guid_from_server)); if (auth->unix_fd_possible) - return send_negotiate_unix_fd(auth); + return send_negotiate_capabilities (auth); - _dbus_verbose("Not negotiating unix fd passing, since not possible\n"); + _dbus_verbose ("Not negotiating capabilities, none were requested\n"); return send_begin (auth); } @@ -1647,26 +1647,47 @@ process_data (DBusAuth *auth, } static dbus_bool_t -send_negotiate_unix_fd (DBusAuth *auth) +send_negotiate_capabilities (DBusAuth *auth) { if (!_dbus_string_append (&auth->outgoing, - "NEGOTIATE_UNIX_FD\r\n")) + "NEGOTIATE_CAPABILITIES")) return FALSE; - goto_state (auth, &client_state_waiting_for_agree_unix_fd); +#ifdef HAVE_UNIX_FD_PASSING + if (auth->unix_fd_possible) + { + if (!_dbus_string_append (&auth->outgoing, " CAP_UNIXFD")) + return FALSE; + } +#endif + + if (!_dbus_string_append (&auth->outgoing, "\r\n")) + return FALSE; + + goto_state (auth, &client_state_waiting_for_agree_capabilities); return TRUE; } static dbus_bool_t -send_agree_unix_fd (DBusAuth *auth) +send_agree_capabilities (DBusAuth *auth) { _dbus_assert(auth->unix_fd_possible); - auth->unix_fd_negotiated = TRUE; - _dbus_verbose("Agreed to UNIX FD passing\n"); + if (!_dbus_string_append (&auth->outgoing, "AGREE_CAPABILITIES")) + return FALSE; + +#ifdef HAVE_UNIX_FD_PASSING + if (auth->unix_fd_possible) + { + if (!_dbus_string_append (&auth->outgoing, " CAP_UNIXFD")) + return FALSE; - if (!_dbus_string_append (&auth->outgoing, - "AGREE_UNIX_FD\r\n")) + auth->unix_fd_negotiated = TRUE; + _dbus_verbose ("Agreed to UNIX FD passing\n"); + } +#endif + + if (!_dbus_string_append (&auth->outgoing, "\r\n")) return FALSE; goto_state (auth, &server_state_waiting_for_begin); @@ -1764,13 +1785,13 @@ handle_server_state_waiting_for_auth (DBusAuth *auth, case DBUS_AUTH_COMMAND_ERROR: return send_rejected (auth); - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: return send_error (auth, "Need to authenticate first"); case DBUS_AUTH_COMMAND_REJECTED: case DBUS_AUTH_COMMAND_OK: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: return send_error (auth, "Unknown command"); } @@ -1797,13 +1818,13 @@ handle_server_state_waiting_for_data (DBusAuth *auth, goto_state (auth, &common_state_need_disconnect); return TRUE; - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: return send_error (auth, "Need to authenticate first"); case DBUS_AUTH_COMMAND_REJECTED: case DBUS_AUTH_COMMAND_OK: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: return send_error (auth, "Unknown command"); } @@ -1826,16 +1847,16 @@ handle_server_state_waiting_for_begin (DBusAuth *auth, goto_state (auth, &common_state_authenticated); return TRUE; - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: if (auth->unix_fd_possible) - return send_agree_unix_fd(auth); + return send_agree_capabilities (auth); else - return send_error(auth, "Unix FD passing not supported, not authenticated or otherwise not possible"); + return send_error (auth, "Capabilities not supported, not authenticated or otherwise not possible"); case DBUS_AUTH_COMMAND_REJECTED: case DBUS_AUTH_COMMAND_OK: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: return send_error (auth, "Unknown command"); @@ -2009,8 +2030,8 @@ handle_client_state_waiting_for_data (DBusAuth *auth, case DBUS_AUTH_COMMAND_CANCEL: case DBUS_AUTH_COMMAND_BEGIN: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: return send_error (auth, "Unknown command"); } @@ -2037,8 +2058,8 @@ handle_client_state_waiting_for_ok (DBusAuth *auth, case DBUS_AUTH_COMMAND_CANCEL: case DBUS_AUTH_COMMAND_BEGIN: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: return send_error (auth, "Unknown command"); } @@ -2061,8 +2082,8 @@ handle_client_state_waiting_for_reject (DBusAuth *auth, case DBUS_AUTH_COMMAND_OK: case DBUS_AUTH_COMMAND_ERROR: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: default: goto_state (auth, &common_state_need_disconnect); return TRUE; @@ -2070,22 +2091,22 @@ handle_client_state_waiting_for_reject (DBusAuth *auth, } static dbus_bool_t -handle_client_state_waiting_for_agree_unix_fd(DBusAuth *auth, - DBusAuthCommand command, - const DBusString *args) +handle_client_state_waiting_for_agree_capabilities (DBusAuth *auth, + DBusAuthCommand command, + const DBusString *args) { switch (command) { - case DBUS_AUTH_COMMAND_AGREE_UNIX_FD: + case DBUS_AUTH_COMMAND_AGREE_CAPABILITIES: _dbus_assert(auth->unix_fd_possible); auth->unix_fd_negotiated = TRUE; - _dbus_verbose("Sucessfully negotiated UNIX FD passing\n"); + _dbus_verbose ("Sucessfully negotiated capabilities\n"); return send_begin (auth); case DBUS_AUTH_COMMAND_ERROR: _dbus_assert(auth->unix_fd_possible); auth->unix_fd_negotiated = FALSE; - _dbus_verbose("Failed to negotiate UNIX FD passing\n"); + _dbus_verbose ("Failed to negotiate capabilities\n"); return send_begin (auth); case DBUS_AUTH_COMMAND_OK: @@ -2095,7 +2116,7 @@ handle_client_state_waiting_for_agree_unix_fd(DBusAuth *auth, case DBUS_AUTH_COMMAND_CANCEL: case DBUS_AUTH_COMMAND_BEGIN: case DBUS_AUTH_COMMAND_UNKNOWN: - case DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD: + case DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES: default: return send_error (auth, "Unknown command"); } @@ -2117,8 +2138,8 @@ static const DBusAuthCommandName auth_command_names[] = { { "REJECTED", DBUS_AUTH_COMMAND_REJECTED }, { "OK", DBUS_AUTH_COMMAND_OK }, { "ERROR", DBUS_AUTH_COMMAND_ERROR }, - { "NEGOTIATE_UNIX_FD", DBUS_AUTH_COMMAND_NEGOTIATE_UNIX_FD }, - { "AGREE_UNIX_FD", DBUS_AUTH_COMMAND_AGREE_UNIX_FD } + { "NEGOTIATE_CAPABILITIES", DBUS_AUTH_COMMAND_NEGOTIATE_CAPABILITIES }, + { "AGREE_CAPABILITIES", DBUS_AUTH_COMMAND_AGREE_CAPABILITIES } }; static DBusAuthCommand @@ -2290,6 +2311,10 @@ _dbus_auth_server_new (const DBusString *guid) */ server_auth->failures = 0; server_auth->max_failures = 6; + +#ifdef HAVE_UNIX_FD_PASSING + _dbus_auth_set_unix_fd_possible (auth, TRUE); +#endif return auth; } @@ -2329,6 +2354,9 @@ _dbus_auth_client_new (void) _dbus_auth_unref (auth); return NULL; } +#ifdef HAVE_UNIX_FD_PASSING + _dbus_auth_set_unix_fd_possible (auth, TRUE); +#endif return auth; }