This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpam_cernvm.c
98 lines (78 loc) · 2.41 KB
/
pam_cernvm.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* This PAM module is used to contextualize a CernVM using the PIN pairing
* mechanism. A login name of the form #<PIN> is interpreted as
* contextualization request, all other login names are passed through.
*
* The actual contextualization request is forwarded to
* /etc/cernvm/pam_action.sh, having the login name as first argument.
*
* This module should be high in the auth PAM stack as "sufficient" and
* high in the account PAM stack as "requisite" (see /etc/pam.d).
* The shared library itself should be installed under /lib64/security/
*
* Mar 2013, [email protected]
*/
#define PAM_SM_AUTH
#include <security/pam_modules.h>
#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#define ACTION_FILE "/etc/cernvm/pam_action.sh"
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
const char *user;
int retval = pam_get_user(pamh, &user, NULL);
if (retval != PAM_SUCCESS)
return retval;
if (user && (user[0] == '#')) {
pam_syslog(pamh, LOG_NOTICE, "running CernVM contextualization...");
int cmd_line_length = strlen(ACTION_FILE) + 1 + strlen(user) + 1;
char *cmd_line = (char *)malloc(cmd_line_length);
strcpy(cmd_line, ACTION_FILE);
strcat(cmd_line, " ");
strcat(cmd_line, &user[1]); // strip #
retval = system(cmd_line);
free(cmd_line);
if (retval != 0) {
pam_syslog(pamh, LOG_NOTICE, "contextualization failed (%d)", retval);
return PAM_AUTH_ERR;
}
return PAM_SUCCESS;
}
return PAM_IGNORE;
}
PAM_EXTERN int
pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
return PAM_IGNORE;
}
PAM_EXTERN int
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc ,const char **argv)
{
const char *user;
int retval = pam_get_user(pamh, &user, NULL);
if (retval != PAM_SUCCESS)
return retval;
if (user && (user[0] == '#')) {
pam_syslog(pamh, LOG_NOTICE,
"contextualization does not have an account, stopping login.");
return PAM_USER_UNKNOWN;
}
return PAM_IGNORE;
}
PAM_EXTERN int
pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
return PAM_IGNORE;
}
PAM_EXTERN int
pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
return PAM_IGNORE;
}
PAM_EXTERN int
pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
return PAM_IGNORE;
}