chiark / gitweb /
bf5fcf4d400d7e501d0cb7dde3356f82ab3f88fd
[elogind.git] / src / login / pam_elogind.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3   This file is part of systemd.
4
5   Copyright 2010 Lennart Poettering
6 ***/
7
8 #include <endian.h>
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <pwd.h>
12 #include <security/_pam_macros.h>
13 #include <security/pam_ext.h>
14 #include <security/pam_misc.h>
15 #include <security/pam_modules.h>
16 #include <security/pam_modutil.h>
17 #include <sys/file.h>
18
19 #include "alloc-util.h"
20 #include "audit-util.h"
21 #include "bus-common-errors.h"
22 #include "bus-error.h"
23 #include "bus-util.h"
24 #include "def.h"
25 #include "fd-util.h"
26 #include "fileio.h"
27 #include "format-util.h"
28 #include "hostname-util.h"
29 #include "login-util.h"
30 #include "macro.h"
31 #include "parse-util.h"
32 #include "process-util.h"
33 #include "socket-util.h"
34 #include "strv.h"
35 #include "terminal-util.h"
36 #include "util.h"
37 #include "path-util.h"
38 //#include "cgroup-util.h"
39
40 static int parse_argv(
41                 pam_handle_t *handle,
42                 int argc, const char **argv,
43                 const char **class,
44                 const char **type,
45                 bool *debug) {
46
47         unsigned i;
48
49         assert(argc >= 0);
50         assert(argc == 0 || argv);
51
52         for (i = 0; i < (unsigned) argc; i++) {
53                 if (startswith(argv[i], "class=")) {
54                         if (class)
55                                 *class = argv[i] + 6;
56
57                 } else if (startswith(argv[i], "type=")) {
58                         if (type)
59                                 *type = argv[i] + 5;
60
61                 } else if (streq(argv[i], "debug")) {
62                         if (debug)
63                                 *debug = true;
64
65                 } else if (startswith(argv[i], "debug=")) {
66                         int k;
67
68                         k = parse_boolean(argv[i] + 6);
69                         if (k < 0)
70                                 pam_syslog(handle, LOG_WARNING, "Failed to parse debug= argument, ignoring.");
71                         else if (debug)
72                                 *debug = k;
73
74                 } else
75                         pam_syslog(handle, LOG_WARNING, "Unknown parameter '%s', ignoring", argv[i]);
76         }
77
78         return 0;
79 }
80
81 static int get_user_data(
82                 pam_handle_t *handle,
83                 const char **ret_username,
84                 struct passwd **ret_pw) {
85
86         const char *username = NULL;
87         struct passwd *pw = NULL;
88         int r;
89
90         assert(handle);
91         assert(ret_username);
92         assert(ret_pw);
93
94         r = pam_get_user(handle, &username, NULL);
95         if (r != PAM_SUCCESS) {
96                 pam_syslog(handle, LOG_ERR, "Failed to get user name.");
97                 return r;
98         }
99
100         if (isempty(username)) {
101                 pam_syslog(handle, LOG_ERR, "User name not valid.");
102                 return PAM_AUTH_ERR;
103         }
104
105         pw = pam_modutil_getpwnam(handle, username);
106         if (!pw) {
107                 pam_syslog(handle, LOG_ERR, "Failed to get user data.");
108                 return PAM_USER_UNKNOWN;
109         }
110
111         *ret_pw = pw;
112         *ret_username = username;
113
114         return PAM_SUCCESS;
115 }
116
117 static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
118         union sockaddr_union sa = {
119                 .un.sun_family = AF_UNIX,
120         };
121         _cleanup_free_ char *p = NULL, *tty = NULL;
122         _cleanup_close_ int fd = -1;
123         struct ucred ucred;
124         int v, r;
125
126         assert(display);
127         assert(vtnr);
128
129         /* We deduce the X11 socket from the display name, then use
130          * SO_PEERCRED to determine the X11 server process, ask for
131          * the controlling tty of that and if it's a VC then we know
132          * the seat and the virtual terminal. Sounds ugly, is only
133          * semi-ugly. */
134
135         r = socket_from_display(display, &p);
136         if (r < 0)
137                 return r;
138         strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1);
139
140         fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
141         if (fd < 0)
142                 return -errno;
143
144         if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
145                 return -errno;
146
147         r = getpeercred(fd, &ucred);
148         if (r < 0)
149                 return r;
150
151         r = get_ctty(ucred.pid, NULL, &tty);
152         if (r < 0)
153                 return r;
154
155         v = vtnr_from_tty(tty);
156         if (v < 0)
157                 return v;
158         else if (v == 0)
159                 return -ENOENT;
160
161         if (seat)
162                 *seat = "seat0";
163         *vtnr = (uint32_t) v;
164
165         return 0;
166 }
167
168 static int export_legacy_dbus_address(
169                 pam_handle_t *handle,
170                 uid_t uid,
171                 const char *runtime) {
172
173         _cleanup_free_ char *s = NULL;
174         int r = PAM_BUF_ERR;
175
176         /* FIXME: We *really* should move the access() check into the
177          * daemons that spawn dbus-daemon, instead of forcing
178          * DBUS_SESSION_BUS_ADDRESS= here. */
179
180         s = strjoin(runtime, "/bus");
181         if (!s)
182                 goto error;
183
184         if (access(s, F_OK) < 0)
185                 return PAM_SUCCESS;
186
187         s = mfree(s);
188         if (asprintf(&s, DEFAULT_USER_BUS_ADDRESS_FMT, runtime) < 0)
189                 goto error;
190
191         r = pam_misc_setenv(handle, "DBUS_SESSION_BUS_ADDRESS", s, 0);
192         if (r != PAM_SUCCESS)
193                 goto error;
194
195         return PAM_SUCCESS;
196
197 error:
198         pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
199         return r;
200 }
201
202 static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, const char *limit) {
203         uint64_t val;
204         int r;
205
206         if (isempty(limit))
207                 return 0;
208
209         if (streq(limit, "infinity")) {
210                 r = sd_bus_message_append(m, "(sv)", "MemoryMax", "t", (uint64_t)-1);
211                 if (r < 0) {
212                         pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
213                         return r;
214                 }
215         } else {
216                 r = parse_percent(limit);
217                 if (r >= 0) {
218                         r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) (((uint64_t) UINT32_MAX * r) / 100U));
219                         if (r < 0) {
220                                 pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
221                                 return r;
222                         }
223                 } else {
224                         r = parse_size(limit, 1024, &val);
225                         if (r >= 0) {
226                                 r = sd_bus_message_append(m, "(sv)", "MemoryMax", "t", val);
227                                 if (r < 0) {
228                                         pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
229                                         return r;
230                                 }
231                         } else
232                                 pam_syslog(handle, LOG_WARNING, "Failed to parse elogind.limit: %s, ignoring.", limit);
233                 }
234         }
235
236         return 0;
237 }
238
239 static int append_session_tasks_max(pam_handle_t *handle, sd_bus_message *m, const char *limit)
240 {
241         uint64_t val;
242         int r;
243
244         /* No need to parse "infinity" here, it will be set unconditionally later in manager_start_scope() */
245         if (isempty(limit) || streq(limit, "infinity"))
246                 return 0;
247
248         r = safe_atou64(limit, &val);
249         if (r >= 0) {
250                 r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", val);
251                 if (r < 0) {
252                         pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
253                         return r;
254                 }
255         } else
256                 pam_syslog(handle, LOG_WARNING, "Failed to parse elogind.limit: %s, ignoring.", limit);
257
258         return 0;
259 }
260
261 static int append_session_cg_weight(pam_handle_t *handle, sd_bus_message *m, const char *limit, const char *field) {
262         uint64_t val;
263         int r;
264
265         if (!isempty(limit)) {
266                 r = cg_weight_parse(limit, &val);
267                 if (r >= 0) {
268                         r = sd_bus_message_append(m, "(sv)", field, "t", val);
269                         if (r < 0) {
270                                 pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
271                                 return r;
272                         }
273                 } else if (streq(field, "CPUWeight"))
274                         pam_syslog(handle, LOG_WARNING, "Failed to parse elogind.cpu_weight: %s, ignoring.", limit);
275                 else
276                         pam_syslog(handle, LOG_WARNING, "Failed to parse elogind.io_weight: %s, ignoring.", limit);
277         }
278
279         return 0;
280 }
281
282 _public_ PAM_EXTERN int pam_sm_open_session(
283                 pam_handle_t *handle,
284                 int flags,
285                 int argc, const char **argv) {
286
287         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
288         _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
289         const char
290                 *username, *id, *object_path, *runtime_path,
291                 *service = NULL,
292                 *tty = NULL, *display = NULL,
293                 *remote_user = NULL, *remote_host = NULL,
294                 *seat = NULL,
295                 *type = NULL, *class = NULL,
296                 *class_pam = NULL, *type_pam = NULL, *cvtnr = NULL, *desktop = NULL,
297                 *memory_max = NULL, *tasks_max = NULL, *cpu_weight = NULL, *io_weight = NULL;
298         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
299         int session_fd = -1, existing, r;
300         bool debug = false, remote;
301         struct passwd *pw;
302         uint32_t vtnr = 0;
303         uid_t original_uid;
304
305         assert(handle);
306
307 #if 0 /// with elogind, it is always a "logind system".
308         /* Make this a NOP on non-logind systems */
309         if (!logind_running())
310                 return PAM_SUCCESS;
311 #endif // 0
312
313         if (parse_argv(handle,
314                        argc, argv,
315                        &class_pam,
316                        &type_pam,
317                        &debug) < 0)
318                 return PAM_SESSION_ERR;
319
320         if (debug)
321                 pam_syslog(handle, LOG_DEBUG, "pam-elogind initializing");
322
323         r = get_user_data(handle, &username, &pw);
324         if (r != PAM_SUCCESS) {
325                 pam_syslog(handle, LOG_ERR, "Failed to get user data.");
326                 return r;
327         }
328
329         /* Make sure we don't enter a loop by talking to
330          * elogind when it is actually waiting for the
331          * background to finish start-up. If the service is
332          * "elogind-user" we simply set XDG_RUNTIME_DIR and
333          * leave. */
334
335         pam_get_item(handle, PAM_SERVICE, (const void**) &service);
336         if (streq_ptr(service, "elogind-user")) {
337                 _cleanup_free_ char *rt = NULL;
338
339                 if (asprintf(&rt, "/run/user/"UID_FMT, pw->pw_uid) < 0)
340                         return PAM_BUF_ERR;
341
342                 r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", rt, 0);
343                 if (r != PAM_SUCCESS) {
344                         pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
345                         return r;
346                 }
347
348                 r = export_legacy_dbus_address(handle, pw->pw_uid, rt);
349                 if (r != PAM_SUCCESS)
350                         return r;
351
352                 return PAM_SUCCESS;
353         }
354
355         /* Otherwise, we ask logind to create a session for us */
356
357         pam_get_item(handle, PAM_XDISPLAY, (const void**) &display);
358         pam_get_item(handle, PAM_TTY, (const void**) &tty);
359         pam_get_item(handle, PAM_RUSER, (const void**) &remote_user);
360         pam_get_item(handle, PAM_RHOST, (const void**) &remote_host);
361
362         seat = pam_getenv(handle, "XDG_SEAT");
363         if (isempty(seat))
364                 seat = getenv("XDG_SEAT");
365
366         cvtnr = pam_getenv(handle, "XDG_VTNR");
367         if (isempty(cvtnr))
368                 cvtnr = getenv("XDG_VTNR");
369
370         type = pam_getenv(handle, "XDG_SESSION_TYPE");
371         if (isempty(type))
372                 type = getenv("XDG_SESSION_TYPE");
373         if (isempty(type))
374                 type = type_pam;
375
376         class = pam_getenv(handle, "XDG_SESSION_CLASS");
377         if (isempty(class))
378                 class = getenv("XDG_SESSION_CLASS");
379         if (isempty(class))
380                 class = class_pam;
381
382         desktop = pam_getenv(handle, "XDG_SESSION_DESKTOP");
383         if (isempty(desktop))
384                 desktop = getenv("XDG_SESSION_DESKTOP");
385
386         tty = strempty(tty);
387
388         if (strchr(tty, ':')) {
389                 /* A tty with a colon is usually an X11 display,
390                  * placed there to show up in utmp. We rearrange
391                  * things and don't pretend that an X display was a
392                  * tty. */
393
394                 if (isempty(display))
395                         display = tty;
396                 tty = NULL;
397         } else if (streq(tty, "cron")) {
398                 /* cron has been setting PAM_TTY to "cron" for a very
399                  * long time and it probably shouldn't stop doing that
400                  * for compatibility reasons. */
401                 type = "unspecified";
402                 class = "background";
403                 tty = NULL;
404         } else if (streq(tty, "ssh")) {
405                 /* ssh has been setting PAM_TTY to "ssh" for a very
406                  * long time and probably shouldn't stop doing that
407                  * for compatibility reasons. */
408                 type ="tty";
409                 class = "user";
410                 tty = NULL;
411         } else
412                 /* Chop off leading /dev prefix that some clients specify, but others do not. */
413                 tty = skip_dev_prefix(tty);
414
415         /* If this fails vtnr will be 0, that's intended */
416         if (!isempty(cvtnr))
417                 (void) safe_atou32(cvtnr, &vtnr);
418
419         if (!isempty(display) && !vtnr) {
420                 if (isempty(seat))
421                         get_seat_from_display(display, &seat, &vtnr);
422                 else if (streq(seat, "seat0"))
423                         get_seat_from_display(display, NULL, &vtnr);
424         }
425
426         if (seat && !streq(seat, "seat0") && vtnr != 0) {
427                 pam_syslog(handle, LOG_DEBUG, "Ignoring vtnr %"PRIu32" for %s which is not seat0", vtnr, seat);
428                 vtnr = 0;
429         }
430
431         if (isempty(type))
432                 type = !isempty(display) ? "x11" :
433                            !isempty(tty) ? "tty" : "unspecified";
434
435         if (isempty(class))
436                 class = streq(type, "unspecified") ? "background" : "user";
437
438         remote = !isempty(remote_host) && !is_localhost(remote_host);
439
440         (void) pam_get_data(handle, "elogind.memory_max", (const void **)&memory_max);
441         (void) pam_get_data(handle, "elogind.tasks_max",  (const void **)&tasks_max);
442         (void) pam_get_data(handle, "elogind.cpu_weight", (const void **)&cpu_weight);
443         (void) pam_get_data(handle, "elogind.io_weight",  (const void **)&io_weight);
444
445         /* Talk to logind over the message bus */
446
447         r = sd_bus_open_system(&bus);
448         if (r < 0) {
449                 pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", strerror(-r));
450                 return PAM_SESSION_ERR;
451         }
452
453         if (debug) {
454                 pam_syslog(handle, LOG_DEBUG, "Asking logind to create session: "
455                            "uid="UID_FMT" pid="PID_FMT" service=%s type=%s class=%s desktop=%s seat=%s vtnr=%"PRIu32" tty=%s display=%s remote=%s remote_user=%s remote_host=%s",
456                            pw->pw_uid, getpid_cached(),
457                            strempty(service),
458                            type, class, strempty(desktop),
459                            strempty(seat), vtnr, strempty(tty), strempty(display),
460                            yes_no(remote), strempty(remote_user), strempty(remote_host));
461                 pam_syslog(handle, LOG_DEBUG, "Session limits: "
462                            "memory_max=%s tasks_max=%s cpu_weight=%s io_weight=%s",
463                            strna(memory_max), strna(tasks_max), strna(cpu_weight), strna(io_weight));
464         }
465
466         r = sd_bus_message_new_method_call(
467                         bus,
468                         &m,
469                         "org.freedesktop.login1",
470                         "/org/freedesktop/login1",
471                         "org.freedesktop.login1.Manager",
472                         "CreateSession");
473         if (r < 0) {
474                 pam_syslog(handle, LOG_ERR, "Failed to create CreateSession method call: %s", strerror(-r));
475                 return PAM_SESSION_ERR;
476         }
477
478         r = sd_bus_message_append(m, "uusssssussbss",
479                         (uint32_t) pw->pw_uid,
480                         (uint32_t) getpid_cached(),
481                         service,
482                         type,
483                         class,
484                         desktop,
485                         seat,
486                         vtnr,
487                         tty,
488                         display,
489                         remote,
490                         remote_user,
491                         remote_host);
492         if (r < 0) {
493                 pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror(-r));
494                 return PAM_SESSION_ERR;
495         }
496
497         r = sd_bus_message_open_container(m, 'a', "(sv)");
498         if (r < 0) {
499                 pam_syslog(handle, LOG_ERR, "Failed to open message container: %s", strerror(-r));
500                 return PAM_SYSTEM_ERR;
501         }
502
503         r = append_session_memory_max(handle, m, memory_max);
504         if (r < 0)
505                 return PAM_SESSION_ERR;
506
507         r = append_session_tasks_max(handle, m, tasks_max);
508         if (r < 0)
509                 return PAM_SESSION_ERR;
510
511         r = append_session_cg_weight(handle, m, cpu_weight, "CPUWeight");
512         if (r < 0)
513                 return PAM_SESSION_ERR;
514
515         r = append_session_cg_weight(handle, m, io_weight, "IOWeight");
516         if (r < 0)
517                 return PAM_SESSION_ERR;
518
519         r = sd_bus_message_close_container(m);
520         if (r < 0) {
521                 pam_syslog(handle, LOG_ERR, "Failed to close message container: %s", strerror(-r));
522                 return PAM_SYSTEM_ERR;
523         }
524
525         r = sd_bus_call(bus, m, 0, &error, &reply);
526         if (r < 0) {
527                 if (sd_bus_error_has_name(&error, BUS_ERROR_SESSION_BUSY)) {
528                         pam_syslog(handle, LOG_DEBUG, "Cannot create session: %s", bus_error_message(&error, r));
529                         return PAM_SUCCESS;
530                 } else {
531                         pam_syslog(handle, LOG_ERR, "Failed to create session: %s", bus_error_message(&error, r));
532                         return PAM_SYSTEM_ERR;
533                 }
534         }
535
536         r = sd_bus_message_read(reply,
537                                 "soshusub",
538                                 &id,
539                                 &object_path,
540                                 &runtime_path,
541                                 &session_fd,
542                                 &original_uid,
543                                 &seat,
544                                 &vtnr,
545                                 &existing);
546         if (r < 0) {
547                 pam_syslog(handle, LOG_ERR, "Failed to parse message: %s", strerror(-r));
548                 return PAM_SESSION_ERR;
549         }
550
551         if (debug)
552                 pam_syslog(handle, LOG_DEBUG, "Reply from logind: "
553                            "id=%s object_path=%s runtime_path=%s session_fd=%d seat=%s vtnr=%u original_uid=%u",
554                            id, object_path, runtime_path, session_fd, seat, vtnr, original_uid);
555
556         r = pam_misc_setenv(handle, "XDG_SESSION_ID", id, 0);
557         if (r != PAM_SUCCESS) {
558                 pam_syslog(handle, LOG_ERR, "Failed to set session id.");
559                 return r;
560         }
561
562         if (original_uid == pw->pw_uid) {
563                 /* Don't set $XDG_RUNTIME_DIR if the user we now
564                  * authenticated for does not match the original user
565                  * of the session. We do this in order not to result
566                  * in privileged apps clobbering the runtime directory
567                  * unnecessarily. */
568
569                 r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", runtime_path, 0);
570                 if (r != PAM_SUCCESS) {
571                         pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
572                         return r;
573                 }
574
575                 r = export_legacy_dbus_address(handle, pw->pw_uid, runtime_path);
576                 if (r != PAM_SUCCESS)
577                         return r;
578         }
579
580         if (!isempty(seat)) {
581                 r = pam_misc_setenv(handle, "XDG_SEAT", seat, 0);
582                 if (r != PAM_SUCCESS) {
583                         pam_syslog(handle, LOG_ERR, "Failed to set seat.");
584                         return r;
585                 }
586         }
587
588         if (vtnr > 0) {
589                 char buf[DECIMAL_STR_MAX(vtnr)];
590                 sprintf(buf, "%u", vtnr);
591
592                 r = pam_misc_setenv(handle, "XDG_VTNR", buf, 0);
593                 if (r != PAM_SUCCESS) {
594                         pam_syslog(handle, LOG_ERR, "Failed to set virtual terminal number.");
595                         return r;
596                 }
597         }
598
599         r = pam_set_data(handle, "systemd.existing", INT_TO_PTR(!!existing), NULL);
600         if (r != PAM_SUCCESS) {
601                 pam_syslog(handle, LOG_ERR, "Failed to install existing flag.");
602                 return r;
603         }
604
605         if (session_fd >= 0) {
606                 session_fd = fcntl(session_fd, F_DUPFD_CLOEXEC, 3);
607                 if (session_fd < 0) {
608                         pam_syslog(handle, LOG_ERR, "Failed to dup session fd: %m");
609                         return PAM_SESSION_ERR;
610                 }
611
612                 r = pam_set_data(handle, "systemd.session-fd", FD_TO_PTR(session_fd), NULL);
613                 if (r != PAM_SUCCESS) {
614                         pam_syslog(handle, LOG_ERR, "Failed to install session fd.");
615                         safe_close(session_fd);
616                         return r;
617                 }
618         }
619
620         return PAM_SUCCESS;
621 }
622
623 _public_ PAM_EXTERN int pam_sm_close_session(
624                 pam_handle_t *handle,
625                 int flags,
626                 int argc, const char **argv) {
627
628         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
629         _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
630         const void *existing = NULL;
631         const char *id;
632         int r;
633
634         assert(handle);
635
636         /* Only release session if it wasn't pre-existing when we
637          * tried to create it */
638         pam_get_data(handle, "systemd.existing", &existing);
639
640         id = pam_getenv(handle, "XDG_SESSION_ID");
641         if (id && !existing) {
642
643                 /* Before we go and close the FIFO we need to tell
644                  * logind that this is a clean session shutdown, so
645                  * that it doesn't just go and slaughter us
646                  * immediately after closing the fd */
647
648                 r = sd_bus_open_system(&bus);
649                 if (r < 0) {
650                         pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", strerror(-r));
651                         return PAM_SESSION_ERR;
652                 }
653
654                 r = sd_bus_call_method(bus,
655                                        "org.freedesktop.login1",
656                                        "/org/freedesktop/login1",
657                                        "org.freedesktop.login1.Manager",
658                                        "ReleaseSession",
659                                        &error,
660                                        NULL,
661                                        "s",
662                                        id);
663                 if (r < 0) {
664                         pam_syslog(handle, LOG_ERR, "Failed to release session: %s", bus_error_message(&error, r));
665                         return PAM_SESSION_ERR;
666                 }
667         }
668
669         /* Note that we are knowingly leaking the FIFO fd here. This
670          * way, logind can watch us die. If we closed it here it would
671          * not have any clue when that is completed. Given that one
672          * cannot really have multiple PAM sessions open from the same
673          * process this means we will leak one FD at max. */
674
675         return PAM_SUCCESS;
676 }