diff options
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-auth.c | 4 | ||||
-rw-r--r-- | dbus/dbus-connection.c | 31 | ||||
-rw-r--r-- | dbus/dbus-connection.h | 2 | ||||
-rw-r--r-- | dbus/dbus-protocol.h | 1 | ||||
-rw-r--r-- | dbus/dbus-transport.c | 32 | ||||
-rw-r--r-- | dbus/dbus-transport.h | 2 |
6 files changed, 70 insertions, 2 deletions
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c index 83dfc8a7..ee3b878d 100644 --- a/dbus/dbus-auth.c +++ b/dbus/dbus-auth.c @@ -1048,9 +1048,9 @@ handle_server_data_external_mech (DBusAuth *auth, DBUS_AUTH_NAME (auth), auth->desired_identity.uid, auth->credentials.uid); - + + auth->authorized_identity.pid = auth->credentials.pid; auth->authorized_identity.uid = auth->desired_identity.uid; - return TRUE; } else diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index d68c3958..58ab7900 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -2985,6 +2985,37 @@ dbus_connection_get_unix_user (DBusConnection *connection, } /** + * Gets the process ID of the connection if any. + * Returns #TRUE if the uid is filled in. + * Always returns #FALSE prior to authenticating the + * connection. + * + * @param connection the connection + * @param pid return location for the process ID + * @returns #TRUE if uid is filled in with a valid process ID + */ +dbus_bool_t +dbus_connection_get_unix_process_id (DBusConnection *connection, + unsigned long *pid) +{ + dbus_bool_t result; + + _dbus_return_val_if_fail (connection != NULL, FALSE); + _dbus_return_val_if_fail (pid != NULL, FALSE); + + CONNECTION_LOCK (connection); + + if (!_dbus_transport_get_is_authenticated (connection->transport)) + result = FALSE; + else + result = _dbus_transport_get_unix_process_id (connection->transport, + pid); + CONNECTION_UNLOCK (connection); + + return result; +} + +/** * Sets a predicate function used to determine whether a given user ID * is allowed to connect. When an incoming connection has * authenticated with a particular user ID, this function is called; diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h index fb6dfbcd..12de0c05 100644 --- a/dbus/dbus-connection.h +++ b/dbus/dbus-connection.h @@ -138,6 +138,8 @@ void dbus_connection_set_dispatch_status_function (DBusConnection DBusFreeFunction free_data_function); dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection, unsigned long *uid); +dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection, + unsigned long *pid); void dbus_connection_set_unix_user_function (DBusConnection *connection, DBusAllowUnixUserFunction function, void *data, diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h index c30339c9..00c3ba7d 100644 --- a/dbus/dbus-protocol.h +++ b/dbus/dbus-protocol.h @@ -154,6 +154,7 @@ extern "C" { #define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited" #define DBUS_ERROR_SPAWN_CHILD_SIGNALED "org.freedesktop.DBus.Error.Spawn.ChildSignaled" #define DBUS_ERROR_SPAWN_FAILED "org.freedesktop.DBus.Error.Spawn.Failed" +#define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN "org.freedesktop.DBus.Error.UnixProcessIdUnknown" #ifdef __cplusplus } diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index 371ecbfb..ada960d4 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -938,6 +938,38 @@ _dbus_transport_get_unix_user (DBusTransport *transport, } /** + * See dbus_connection_get_unix_process_id(). + * + * @param transport the transport + * @param pid return location for the process ID + * @returns #TRUE if uid is filled in with a valid process ID + */ +dbus_bool_t +_dbus_transport_get_unix_process_id (DBusTransport *transport, + unsigned long *pid) +{ + DBusCredentials auth_identity; + + *pid = DBUS_PID_UNSET; /* Caller should never use this value on purpose, + * but we set it to a safe number, INT_MAX, + * just to root out possible bugs in bad callers. + */ + + if (!transport->authenticated) + return FALSE; + + _dbus_auth_get_identity (transport->auth, &auth_identity); + + if (auth_identity.pid != DBUS_PID_UNSET) + { + *pid = auth_identity.pid; + return TRUE; + } + else + return FALSE; +} + +/** * See dbus_connection_set_unix_user_function(). * * @param transport the transport diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h index 2c17c2a1..b6c7a4ec 100644 --- a/dbus/dbus-transport.h +++ b/dbus/dbus-transport.h @@ -59,6 +59,8 @@ void _dbus_transport_set_max_received_size (DBusTransport long _dbus_transport_get_max_received_size (DBusTransport *transport); dbus_bool_t _dbus_transport_get_unix_user (DBusTransport *transport, unsigned long *uid); +dbus_bool_t _dbus_transport_get_unix_process_id (DBusTransport *transport, + unsigned long *pid); void _dbus_transport_set_unix_user_function (DBusTransport *transport, DBusAllowUnixUserFunction function, void *data, |