chiark / gitweb /
e1a1a5001cedc9b438a31546906511949716c703
[elogind.git] / src / pam-module.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <sys/file.h>
25 #include <pwd.h>
26 #include <endian.h>
27
28 #include <security/pam_modules.h>
29 #include <security/_pam_macros.h>
30 #include <security/pam_modutil.h>
31 #include <security/pam_ext.h>
32 #include <security/pam_misc.h>
33
34 #include "util.h"
35 #include "cgroup-util.h"
36 #include "macro.h"
37 #include "sd-daemon.h"
38 #include "strv.h"
39
40 static int parse_argv(pam_handle_t *handle,
41                       int argc, const char **argv,
42                       bool *create_session,
43                       bool *kill_session,
44                       bool *kill_user,
45                       char ***controllers,
46                       char ***reset_controllers,
47                       char ***kill_only_users,
48                       char ***kill_exclude_users) {
49
50         unsigned i;
51         bool reset_controller_set = false;
52         bool kill_exclude_users_set = false;
53
54         assert(argc >= 0);
55         assert(argc == 0 || argv);
56
57         for (i = 0; i < (unsigned) argc; i++) {
58                 int k;
59
60                 if (startswith(argv[i], "create-session=")) {
61                         if ((k = parse_boolean(argv[i] + 15)) < 0) {
62                                 pam_syslog(handle, LOG_ERR, "Failed to parse create-session= argument.");
63                                 return k;
64                         }
65
66                         if (create_session)
67                                 *create_session = k;
68
69                 } else if (startswith(argv[i], "kill-session=")) {
70                         if ((k = parse_boolean(argv[i] + 13)) < 0) {
71                                 pam_syslog(handle, LOG_ERR, "Failed to parse kill-session= argument.");
72                                 return k;
73                         }
74
75                         if (kill_session)
76                                 *kill_session = k;
77
78                 } else if (startswith(argv[i], "kill-user=")) {
79                         if ((k = parse_boolean(argv[i] + 10)) < 0) {
80                                 pam_syslog(handle, LOG_ERR, "Failed to parse kill-user= argument.");
81                                 return k;
82                         }
83
84                         if (kill_user)
85                                 *kill_user = k;
86
87                 } else if (startswith(argv[i], "controllers=")) {
88
89                         if (controllers) {
90                                 char **l;
91
92                                 if (!(l = strv_split(argv[i] + 12, ","))) {
93                                         pam_syslog(handle, LOG_ERR, "Out of memory.");
94                                         return -ENOMEM;
95                                 }
96
97                                 strv_free(*controllers);
98                                 *controllers = l;
99                         }
100
101                 } else if (startswith(argv[i], "reset-controllers=")) {
102
103                         if (reset_controllers) {
104                                 char **l;
105
106                                 if (!(l = strv_split(argv[i] + 18, ","))) {
107                                         pam_syslog(handle, LOG_ERR, "Out of memory.");
108                                         return -ENOMEM;
109                                 }
110
111                                 strv_free(*reset_controllers);
112                                 *reset_controllers = l;
113                         }
114
115                         reset_controller_set = true;
116
117                 } else if (startswith(argv[i], "kill-only-users=")) {
118
119                         if (kill_only_users) {
120                                 char **l;
121
122                                 if (!(l = strv_split(argv[i] + 16, ","))) {
123                                         pam_syslog(handle, LOG_ERR, "Out of memory.");
124                                         return -ENOMEM;
125                                 }
126
127                                 strv_free(*kill_only_users);
128                                 *kill_only_users = l;
129                         }
130
131                 } else if (startswith(argv[i], "kill-exclude-users=")) {
132
133                         if (kill_exclude_users) {
134                                 char **l;
135
136                                 if (!(l = strv_split(argv[i] + 19, ","))) {
137                                         pam_syslog(handle, LOG_ERR, "Out of memory.");
138                                         return -ENOMEM;
139                                 }
140
141                                 strv_free(*kill_exclude_users);
142                                 *kill_exclude_users = l;
143                         }
144
145                         kill_exclude_users_set = true;
146
147                 } else {
148                         pam_syslog(handle, LOG_ERR, "Unknown parameter '%s'.", argv[i]);
149                         return -EINVAL;
150                 }
151         }
152
153         if (!reset_controller_set && reset_controllers) {
154                 char **l;
155
156                 if (!(l = strv_new("cpu", NULL))) {
157                         pam_syslog(handle, LOG_ERR, "Out of memory");
158                         return -ENOMEM;
159                 }
160
161                 *reset_controllers = l;
162         }
163
164         if (controllers)
165                 strv_remove(*controllers, "name=systemd");
166
167         if (reset_controllers)
168                 strv_remove(*reset_controllers, "name=systemd");
169
170         if (kill_session && *kill_session && kill_user)
171                 *kill_user = true;
172
173         if (!kill_exclude_users_set && kill_exclude_users) {
174                 char **l;
175
176                 if (!(l = strv_new("root", NULL))) {
177                         pam_syslog(handle, LOG_ERR, "Out of memory");
178                         return -ENOMEM;
179                 }
180
181                 *kill_exclude_users = l;
182         }
183
184         return 0;
185 }
186
187 static int open_file_and_lock(const char *fn) {
188         int fd;
189
190         assert(fn);
191
192         if ((fd = open(fn, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW|O_CREAT, 0600)) < 0)
193                 return -errno;
194
195         /* The BSD socket semantics are a lot nicer than those of
196          * POSIX locks. Which is why we use flock() here. BSD locking
197          * does not work across NFS which however is not needed here
198          * as the filesystems in question should be local, and only
199          * locally accessible, and most likely even tmpfs. */
200
201         if (flock(fd, LOCK_EX) < 0) {
202                 int r = -errno;
203
204                 close_nointr_nofail(fd);
205                 return r;
206         }
207
208         return fd;
209 }
210
211 enum {
212         SESSION_ID_AUDIT = 'a',
213         SESSION_ID_COUNTER = 'c',
214         SESSION_ID_RANDOM = 'r'
215 };
216
217 static uint64_t get_session_id(int *mode) {
218         char *s;
219         int fd;
220
221         assert(mode);
222
223         /* First attempt: let's use the session ID of the audit
224          * system, if it is available. */
225         if (read_one_line_file("/proc/self/sessionid", &s) >= 0) {
226                 uint32_t u;
227                 int r;
228
229                 r = safe_atou32(s, &u);
230                 free(s);
231
232                 if (r >= 0 && u != (uint32_t) -1 && u > 0) {
233                         *mode = SESSION_ID_AUDIT;
234                         return (uint64_t) u;
235                 }
236         }
237
238         /* Second attempt, use our own counter. */
239         if ((fd = open_file_and_lock(RUNTIME_DIR "/user/.pam-systemd-session")) >= 0) {
240                 uint64_t counter;
241                 ssize_t r;
242
243                 /* We do a bit of endianess swapping here, just to be
244                  * sure. /var should be machine specific anyway, and
245                  * /var/run even mounted from tmpfs, so this
246                  * byteswapping should really not be necessary. But
247                  * then again, you never know, so let's avoid any
248                  * risk. */
249
250                 if (loop_read(fd, &counter, sizeof(counter), false) != sizeof(counter))
251                         counter = 1;
252                 else
253                         counter = le64toh(counter) + 1;
254
255                 if (lseek(fd, 0, SEEK_SET) == 0) {
256                         uint64_t swapped = htole64(counter);
257
258                         r = loop_write(fd, &swapped, sizeof(swapped), false);
259
260                         if (r != sizeof(swapped))
261                                 r = -EIO;
262                 } else
263                         r = -errno;
264
265                 close_nointr_nofail(fd);
266
267                 if (r >= 0) {
268                         *mode = SESSION_ID_COUNTER;
269                         return counter;
270                 }
271         }
272
273         *mode = SESSION_ID_RANDOM;
274
275         /* Last attempt, pick a random value */
276         return (uint64_t) random_ull();
277 }
278 static int get_user_data(
279                 pam_handle_t *handle,
280                 const char **ret_username,
281                 struct passwd **ret_pw) {
282
283         const char *username = NULL;
284         struct passwd *pw = NULL;
285         int r;
286         bool have_loginuid = false;
287         char *s;
288
289         assert(handle);
290         assert(ret_username);
291         assert(ret_pw);
292
293         if (read_one_line_file("/proc/self/loginuid", &s) >= 0) {
294                 uint32_t u;
295
296                 r = safe_atou32(s, &u);
297                 free(s);
298
299                 if (r >= 0 && u != (uint32_t) -1 && u > 0) {
300                         have_loginuid = true;
301                         pw = pam_modutil_getpwuid(handle, u);
302                 }
303         }
304
305         if (!have_loginuid) {
306                 if ((r = pam_get_user(handle, &username, NULL)) != PAM_SUCCESS) {
307                         pam_syslog(handle, LOG_ERR, "Failed to get user name.");
308                         return r;
309                 }
310
311                 if (!username || !*username) {
312                         pam_syslog(handle, LOG_ERR, "User name not valid.");
313                         return PAM_AUTH_ERR;
314                 }
315
316                 pw = pam_modutil_getpwnam(handle, username);
317         }
318
319         if (!pw) {
320                 pam_syslog(handle, LOG_ERR, "Failed to get user data.");
321                 return PAM_USER_UNKNOWN;
322         }
323
324         *ret_pw = pw;
325         *ret_username = username ? username : pw->pw_name;
326
327         return PAM_SUCCESS;
328 }
329
330 static int create_user_group(
331                 pam_handle_t *handle,
332                 const char *controller,
333                 const char *group,
334                 struct passwd *pw,
335                 bool attach,
336                 bool remember) {
337
338         int r;
339
340         assert(handle);
341         assert(group);
342
343         if (attach)
344                 r = cg_create_and_attach(controller, group, 0);
345         else
346                 r = cg_create(controller, group);
347
348         if (r < 0) {
349                 pam_syslog(handle, LOG_ERR, "Failed to create cgroup: %s", strerror(-r));
350                 return PAM_SESSION_ERR;
351         }
352
353         if (r > 0 && remember) {
354                 /* Remember that it was us who created this group, and
355                  * that hence we need to remove it too. This is a
356                  * protection against removing the cgroup when run
357                  * recursively. */
358                 if ((r = pam_set_data(handle, "systemd.created", INT_TO_PTR(1), NULL)) != PAM_SUCCESS) {
359                         pam_syslog(handle, LOG_ERR, "Failed to install created variable.");
360                         return r;
361                 }
362         }
363
364         if ((r = cg_set_task_access(controller, group, 0644, pw->pw_uid, pw->pw_gid)) < 0 ||
365             (r = cg_set_group_access(controller, group, 0755, pw->pw_uid, pw->pw_gid)) < 0) {
366                 pam_syslog(handle, LOG_ERR, "Failed to change access modes: %s", strerror(-r));
367                 return PAM_SESSION_ERR;
368         }
369
370         return PAM_SUCCESS;
371 }
372
373 static int reset_group(
374                 pam_handle_t *handle,
375                 const char *controller) {
376
377         int r;
378
379         assert(handle);
380
381         if ((r = cg_attach(controller, "/", 0)) < 0) {
382                 pam_syslog(handle, LOG_ERR, "Failed to reset cgroup for controller %s: %s", controller, strerror(-r));
383                 return PAM_SESSION_ERR;
384         }
385
386         return PAM_SUCCESS;
387 }
388
389 _public_ PAM_EXTERN int pam_sm_open_session(
390                 pam_handle_t *handle,
391                 int flags,
392                 int argc, const char **argv) {
393
394         const char *username = NULL;
395         struct passwd *pw;
396         int r;
397         char *buf = NULL;
398         int lock_fd = -1;
399         bool create_session = true;
400         char **controllers = NULL, **reset_controllers = NULL, **c;
401
402         assert(handle);
403
404         /* pam_syslog(handle, LOG_DEBUG, "pam-systemd initializing"); */
405
406         /* Make this a NOP on non-systemd systems */
407         if (sd_booted() <= 0)
408                 return PAM_SUCCESS;
409
410         if (parse_argv(handle,
411                        argc, argv,
412                        &create_session, NULL, NULL,
413                        &controllers, &reset_controllers,
414                        NULL, NULL) < 0)
415                 return PAM_SESSION_ERR;
416
417         if ((r = get_user_data(handle, &username, &pw)) != PAM_SUCCESS)
418                 goto finish;
419
420         if (safe_mkdir(RUNTIME_DIR "/user", 0755, 0, 0) < 0) {
421                 pam_syslog(handle, LOG_ERR, "Failed to create runtime directory: %m");
422                 r = PAM_SYSTEM_ERR;
423                 goto finish;
424         }
425
426         if ((lock_fd = open_file_and_lock(RUNTIME_DIR "/user/.pam-systemd-lock")) < 0) {
427                 pam_syslog(handle, LOG_ERR, "Failed to lock runtime directory: %m");
428                 r = PAM_SYSTEM_ERR;
429                 goto finish;
430         }
431
432         /* Create /var/run/$USER */
433         free(buf);
434         if (asprintf(&buf, RUNTIME_DIR "/user/%s", username) < 0) {
435                 r = PAM_BUF_ERR;
436                 goto finish;
437         }
438
439         if (safe_mkdir(buf, 0700, pw->pw_uid, pw->pw_gid) < 0) {
440                 pam_syslog(handle, LOG_WARNING, "Failed to create runtime directory: %m");
441                 r = PAM_SYSTEM_ERR;
442                 goto finish;
443         } else if ((r = pam_misc_setenv(handle, "XDG_RUNTIME_DIR", buf, 0)) != PAM_SUCCESS) {
444                 pam_syslog(handle, LOG_ERR, "Failed to set runtime dir.");
445                 goto finish;
446         }
447
448         free(buf);
449         buf = NULL;
450
451         if (create_session) {
452                 const char *id;
453
454                 /* Reuse or create XDG session ID */
455                 if (!(id = pam_getenv(handle, "XDG_SESSION_ID"))) {
456                         int mode;
457
458                         if (asprintf(&buf, "%llux", (unsigned long long) get_session_id(&mode)) < 0) {
459                                 r = PAM_BUF_ERR;
460                                 goto finish;
461                         }
462
463                         /* To avoid id clashes we add the session id
464                          * source to our session ids. Note that the
465                          * session id source might change during
466                          * runtime, because a filesystem became
467                          * writable or the system reconfigured. */
468                         buf[strlen(buf)-1] =
469                                 mode != SESSION_ID_AUDIT ? (char) mode : 0;
470
471                         if ((r = pam_misc_setenv(handle, "XDG_SESSION_ID", buf, 0)) != PAM_SUCCESS) {
472                                 pam_syslog(handle, LOG_ERR, "Failed to set session id.");
473                                 goto finish;
474                         }
475
476                         if (!(id = pam_getenv(handle, "XDG_SESSION_ID"))) {
477                                 pam_syslog(handle, LOG_ERR, "Failed to get session id.");
478                                 r = PAM_SESSION_ERR;
479                                 goto finish;
480                         }
481                 }
482
483                 r = asprintf(&buf, "/user/%s/%s", username, id);
484         } else
485                 r = asprintf(&buf, "/user/%s/master", username);
486
487         if (r < 0) {
488                 r = PAM_BUF_ERR;
489                 goto finish;
490         }
491
492         pam_syslog(handle, LOG_INFO, "Moving new user session for %s into control group %s.", username, buf);
493
494         if ((r = create_user_group(handle, SYSTEMD_CGROUP_CONTROLLER, buf, pw, true, true)) != PAM_SUCCESS)
495                 goto finish;
496
497         /* The additional controllers don't really matter, so we
498          * ignore the return value */
499         STRV_FOREACH(c, controllers)
500                 create_user_group(handle, *c, buf, pw, true, false);
501
502         STRV_FOREACH(c, reset_controllers)
503                 reset_group(handle, *c);
504
505         r = PAM_SUCCESS;
506
507 finish:
508         free(buf);
509
510         if (lock_fd >= 0)
511                 close_nointr_nofail(lock_fd);
512
513         strv_free(controllers);
514         strv_free(reset_controllers);
515
516         return r;
517 }
518
519 static int session_remains(pam_handle_t *handle, const char *user_path) {
520         int r;
521         bool remains = false;
522         DIR *d;
523         char *subgroup;
524
525         if ((r = cg_enumerate_subgroups(SYSTEMD_CGROUP_CONTROLLER, user_path, &d)) < 0)
526                 return r;
527
528         while ((r = cg_read_subgroup(d, &subgroup)) > 0) {
529
530                 remains = !streq(subgroup, "master");
531                 free(subgroup);
532
533                 if (remains)
534                         break;
535         }
536
537         closedir(d);
538
539         if (r < 0)
540                 return r;
541
542         return !!remains;
543 }
544
545 static bool check_user_lists(
546                 pam_handle_t *handle,
547                 uid_t uid,
548                 char **kill_only_users,
549                 char **kill_exclude_users) {
550
551         const char *name = NULL;
552         char **l;
553
554         assert(handle);
555
556         if (uid == 0)
557                 name = "root"; /* Avoid obvious NSS requests, to suppress network traffic */
558         else {
559                 struct passwd *pw;
560
561                 if ((pw = pam_modutil_getpwuid(handle, uid)))
562                         name = pw->pw_name;
563         }
564
565         STRV_FOREACH(l, kill_exclude_users) {
566                 uint32_t id;
567
568                 if (safe_atou32(*l, &id) >= 0)
569                         if ((uid_t) id == uid)
570                                 return false;
571
572                 if (name && streq(name, *l))
573                         return false;
574         }
575
576         if (strv_isempty(kill_only_users))
577                 return true;
578
579         STRV_FOREACH(l, kill_only_users) {
580                 uint32_t id;
581
582                 if (safe_atou32(*l, &id) >= 0)
583                         if ((uid_t) id == uid)
584                                 return true;
585
586                 if (name && streq(name, *l))
587                         return true;
588         }
589
590         return false;
591 }
592
593 _public_ PAM_EXTERN int pam_sm_close_session(
594                 pam_handle_t *handle,
595                 int flags,
596                 int argc, const char **argv) {
597
598         const char *username = NULL;
599         bool kill_session = false;
600         bool kill_user = false;
601         int lock_fd = -1, r;
602         char *session_path = NULL, *nosession_path = NULL, *user_path = NULL;
603         const char *id;
604         struct passwd *pw;
605         const void *created = NULL;
606         char **controllers = NULL, **c, **kill_only_users = NULL, **kill_exclude_users = NULL;
607
608         assert(handle);
609
610         /* Make this a NOP on non-systemd systems */
611         if (sd_booted() <= 0)
612                 return PAM_SUCCESS;
613
614         if (parse_argv(handle,
615                        argc, argv,
616                        NULL, &kill_session, &kill_user,
617                        &controllers, NULL,
618                        &kill_only_users, &kill_exclude_users) < 0)
619                 return PAM_SESSION_ERR;
620
621         if ((r = get_user_data(handle, &username, &pw)) != PAM_SUCCESS)
622                 goto finish;
623
624         if ((lock_fd = open_file_and_lock(RUNTIME_DIR "/user/.pam-systemd-lock")) < 0) {
625                 pam_syslog(handle, LOG_ERR, "Failed to lock runtime directory: %m");
626                 r = PAM_SYSTEM_ERR;
627                 goto finish;
628         }
629
630         /* We are probably still in some session/user dir. Move ourselves out of the way as first step */
631         if ((r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, "/user", 0)) < 0)
632                 pam_syslog(handle, LOG_ERR, "Failed to move us away: %s", strerror(-r));
633
634         STRV_FOREACH(c, controllers)
635                 if ((r = cg_attach(*c, "/user", 0)) < 0)
636                         pam_syslog(handle, LOG_ERR, "Failed to move us away in %s hierarchy: %s", *c, strerror(-r));
637
638         if (asprintf(&user_path, "/user/%s", username) < 0) {
639                 r = PAM_BUF_ERR;
640                 goto finish;
641         }
642
643         pam_get_data(handle, "systemd.created", &created);
644
645         if ((id = pam_getenv(handle, "XDG_SESSION_ID")) && created) {
646
647                 if (asprintf(&session_path, "/user/%s/%s", username, id) < 0 ||
648                     asprintf(&nosession_path, "/user/%s/master", username) < 0) {
649                         r = PAM_BUF_ERR;
650                         goto finish;
651                 }
652
653                 if (kill_session && check_user_lists(handle, pw->pw_uid, kill_only_users, kill_exclude_users))  {
654                         pam_syslog(handle, LOG_INFO, "Killing remaining processes of user session %s of %s.", id, username);
655
656                         /* Kill processes in session cgroup, and delete it */
657                         if ((r = cg_kill_recursive_and_wait(SYSTEMD_CGROUP_CONTROLLER, session_path, true)) < 0)
658                                 pam_syslog(handle, LOG_ERR, "Failed to kill session cgroup: %s", strerror(-r));
659                 } else {
660                         pam_syslog(handle, LOG_INFO, "Moving remaining processes of user session %s of %s into control group %s.", id, username, nosession_path);
661
662                         /* Migrate processes from session to user
663                          * cgroup. First, try to create the user group
664                          * in case it doesn't exist yet. Also, delete
665                          * the session group. */
666                         create_user_group(handle, SYSTEMD_CGROUP_CONTROLLER, nosession_path, pw, false, false);
667
668                         if ((r = cg_migrate_recursive(SYSTEMD_CGROUP_CONTROLLER, session_path, nosession_path, false, true)) < 0)
669                                 pam_syslog(handle, LOG_ERR, "Failed to migrate session cgroup: %s", strerror(-r));
670                 }
671
672                 STRV_FOREACH(c, controllers) {
673                         create_user_group(handle, *c, nosession_path, pw, false, false);
674
675                         if ((r = cg_migrate_recursive(*c, session_path, nosession_path, false, true)) < 0)
676                                 pam_syslog(handle, LOG_ERR, "Failed to migrate session cgroup in hierarchy %s: %s", *c, strerror(-r));
677                 }
678         }
679
680         /* GC user tree */
681         cg_trim(SYSTEMD_CGROUP_CONTROLLER, user_path, false);
682
683         if ((r = session_remains(handle, user_path)) < 0)
684                 pam_syslog(handle, LOG_ERR, "Failed to determine whether a session remains: %s", strerror(-r));
685
686         /* Kill user processes not attached to any session */
687         if (kill_user && r == 0 && check_user_lists(handle, pw->pw_uid, kill_only_users, kill_exclude_users)) {
688
689                 /* Kill user cgroup */
690                 if ((r = cg_kill_recursive_and_wait(SYSTEMD_CGROUP_CONTROLLER, user_path, true)) < 0)
691                         pam_syslog(handle, LOG_ERR, "Failed to kill user cgroup: %s", strerror(-r));
692         } else {
693
694                 if ((r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, user_path, true)) < 0)
695                         pam_syslog(handle, LOG_ERR, "Failed to check user cgroup: %s", strerror(-r));
696
697                 /* Remove user cgroup */
698                 if (r > 0) {
699                         if ((r = cg_delete(SYSTEMD_CGROUP_CONTROLLER, user_path)) < 0)
700                                 pam_syslog(handle, LOG_ERR, "Failed to delete user cgroup: %s", strerror(-r));
701
702                 /* If we managed to find somebody, don't cleanup the cgroup. */
703                 } else if (r == 0)
704                         r = -EBUSY;
705         }
706
707         STRV_FOREACH(c, controllers)
708                 cg_trim(*c, user_path, true);
709
710         if (r >= 0) {
711                 const char *runtime_dir;
712
713                 if ((runtime_dir = pam_getenv(handle, "XDG_RUNTIME_DIR")))
714                         if ((r = rm_rf(runtime_dir, false, true)) < 0)
715                                 pam_syslog(handle, LOG_ERR, "Failed to remove runtime directory: %s", strerror(-r));
716         }
717
718         /* pam_syslog(handle, LOG_DEBUG, "pam-systemd done"); */
719
720         r = PAM_SUCCESS;
721
722 finish:
723         if (lock_fd >= 0)
724                 close_nointr_nofail(lock_fd);
725
726         free(session_path);
727         free(nosession_path);
728         free(user_path);
729
730         strv_free(controllers);
731         strv_free(kill_exclude_users);
732         strv_free(kill_only_users);
733
734         return r;
735 }