1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
const char *PAM_user = NULL;
char fnam[400];
int ret, err, count, i;
struct mount_entries *entries;
struct stat statbuf;
ret = pam_get_user(pamh, &PAM_user, NULL);
if (ret != PAM_SUCCESS) {
mysyslog(LOG_ERR, "PAM-MOUNT: couldn't get user\n");
return PAM_SESSION_ERR;
}
/* check whether /share/$pam_user/root exists. If so, chroot to it */
sprintf(fnam, "/share/%s/root", PAM_user);
ret = stat(fnam, &statbuf);
if (ret == 0 && S_ISDIR(statbuf.st_mode)) {
ret = chroot(fnam);
if (ret) {
mysyslog(LOG_ERR, "PAM-MOUNT: unable to chroot to %s\n", fnam);
return PAM_SESSION_ERR;
}
}
return PAM_SUCCESS;
}
|