chiark / gitweb /
logind: properly handle if two session with identical loginuids are attempted to...
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 20:55:39 +0000 (22:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 20:55:39 +0000 (22:55 +0200)
src/logind-dbus.c
src/logind.h
src/pam-module.c

index 2bad549fc528a60e49eda77ec1027cfda8d4e32e..d48d68c2bb70b4b64d5bdd3fc63c7a54dc43e134 100644 (file)
@@ -314,9 +314,53 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
                         goto fail;
                 }
 
-                if (hashmap_get(m->sessions, id)) {
-                        r = -EEXIST;
-                        goto fail;
+                session = hashmap_get(m->sessions, id);
+
+                if (session) {
+
+                        /* Session already exists, client is probably
+                         * something like "su" which changes uid but
+                         * is still the same audit session */
+
+                        reply = dbus_message_new_method_return(message);
+                        if (!reply) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+
+                        /* Create a throw-away fd */
+                        if (pipe(pipe_fds) < 0) {
+                                r = -errno;
+                                goto fail;
+                        }
+
+                        close_nointr_nofail(pipe_fds[0]);
+                        pipe_fds[0] = -1;
+
+                        p = session_bus_path(session);
+                        if (!p) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+
+                        b = dbus_message_append_args(
+                                        reply,
+                                        DBUS_TYPE_STRING, &session->id,
+                                        DBUS_TYPE_OBJECT_PATH, &p,
+                                        DBUS_TYPE_STRING, &session->user->runtime_path,
+                                        DBUS_TYPE_UNIX_FD, &pipe_fds[1],
+                                        DBUS_TYPE_INVALID);
+                        free(p);
+
+                        if (!b) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+
+                        close_nointr_nofail(pipe_fds[1]);
+                        *_reply = reply;
+
+                        return 0;
                 }
 
         } else {
index 2b9b702f3d9591d3154ab936e2232525b2fb9acc..d8674e75116a5fed8d77bba1e9c06eb8f678bb30 100644 (file)
@@ -40,7 +40,6 @@
  * subscribe to fd HUP
  * D-Bus method: AttachDevice(seat, device);
  * D-Bus method: PermitLinger(user, bool b);
- * properly handle if two sessions with the same loginuid are attempted to be created
  *
  * non-local X11 server
  * reboot/shutdown halt management
index dc7c00166e6ca35f1f313de3df236a9c57d93a9b..eba59f65f25837c64e146e43c1ba86b80f4725a6 100644 (file)
@@ -457,10 +457,12 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 goto finish;
         }
 
-        r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL);
-        if (r != PAM_SUCCESS) {
-                pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
-                return r;
+        if (session_fd >= 0) {
+                r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL);
+                if (r != PAM_SUCCESS) {
+                        pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
+                        return r;
+                }
         }
 
         session_fd = -1;