pam-module.c revision 8c6db8336536916d0476ff8233e0abf40a2f6aab
/*-*- Mode: C; c-basic-offset: 8 -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <security/pam_modules.h>
#include <security/_pam_macros.h>
#include <security/pam_modutil.h>
#include <security/pam_misc.h>
#include <libcgroup.h>
#include "util.h"
#include "cgroup-util.h"
#include "macro.h"
#include "sd-daemon.h"
bool *create_session,
bool *kill_session,
bool *kill_user) {
unsigned i;
for (i = 0; i < (unsigned) argc; i++) {
int k;
return k;
}
if (create_session)
*create_session = k;
return k;
}
if (kill_session)
*kill_session = k;
return k;
}
if (kill_user)
*kill_user = k;
} else {
return -EINVAL;
}
}
*kill_user = true;
return 0;
}
static int open_file_and_lock(const char *fn) {
int fd;
return -errno;
return -errno;
return fd;
}
uint32_t r = 0;
unsigned i;
for (i = 0; i < sizeof(u)/4; i ++)
return r;
}
static char *generate_session_cookie(void) {
char *machine;
char *cookie;
unsigned long long r;
usec_t u;
int k;
if (getmachineid_malloc(&machine) < 0)
if (!(machine = gethostname_malloc()))
return NULL;
r = random_ull();
u = now(CLOCK_REALTIME);
(unsigned long) combine32(r),
(unsigned long) combine32((unsigned long long) u));
}
static int get_user_data(
const char **ret_username,
const char *username;
int r;
return r;
}
return PAM_AUTH_ERR;
}
return PAM_USER_UNKNOWN;
}
*ret_username = username;
return PAM_SUCCESS;
}
static int create_user_group(pam_handle_t *handle, const char *group, struct passwd *pw, bool attach) {
int r;
if (attach)
else
if (r < 0) {
return PAM_SESSION_ERR;
}
return PAM_SESSION_ERR;
}
return PAM_SUCCESS;
}
int flags,
int r;
int lock_fd = -1;
bool create_session = true;
return PAM_SESSION_ERR;
/* Make this a NOP on non-systemd systems */
if (sd_booted() <= 0)
return PAM_SUCCESS;
if ((r = cgroup_init()) != 0) {
r = PAM_SESSION_ERR;
goto finish;
}
goto finish;
r = PAM_SYSTEM_ERR;
goto finish;
}
r = PAM_SYSTEM_ERR;
goto finish;
}
r = PAM_BUF_ERR;
goto finish;
}
r = PAM_SYSTEM_ERR;
goto finish;
goto finish;
}
if (create_session) {
const char *cookie;
/* Reuse or create XDG session ID */
if (!(buf = generate_session_cookie())) {
r = PAM_BUF_ERR;
goto finish;
}
goto finish;
}
r = PAM_SESSION_ERR;
goto finish;
}
}
} else
if (r < 0) {
r = PAM_BUF_ERR;
goto finish;
}
goto finish;
r = PAM_SUCCESS;
if (lock_fd >= 0)
return r;
}
struct cgroup_file_info info;
int level = 0, r;
bool remains = false;
while (r == 0) {
goto next;
goto next;
goto next;
remains = true;
break;
next:
}
if (remains)
r = 1;
else if (r == 0 || r == ECGEOF)
r = 0;
else
r = cg_translate_error(r, errno);
return r;
}
int flags,
bool kill_session = false;
bool kill_user = false;
int lock_fd = -1, r;
const char *cookie;
return PAM_SESSION_ERR;
/* Make this a NOP on non-systemd systems */
if (sd_booted() <= 0)
return PAM_SUCCESS;
goto finish;
r = PAM_SYSTEM_ERR;
goto finish;
}
r = PAM_BUF_ERR;
goto finish;
}
r = PAM_BUF_ERR;
goto finish;
}
if (kill_session) {
/* Kill processes in session cgroup */
} else {
/* Migrate processes from session to
* no-session cgroup. First, try to create the
* no-session group in case it doesn't exist
* yet. */
}
/* Delete session cgroup */
if (r < 0)
else {
}
}
/* GC user tree */
/* Kill user processes not attached to any session */
if (kill_user && r == 0) {
/* Kill no-session cgroup */
} else {
/* If we managed to kill somebody, don't cleanup the cgroup. */
if (r == 0)
r = -EBUSY;
}
if (r >= 0) {
const char *runtime_dir;
/* Remove user cgroup */
/* This will migrate us to the /user cgroup. */
if ((r = rm_rf(runtime_dir, false, true)) < 0)
}
r = PAM_SUCCESS;
if (lock_fd >= 0)
return r;
}