forked from mricon/pam_url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pam_url_session.c
121 lines (100 loc) · 2.43 KB
/
pam_url_session.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// pam_url - GPLv2, Sascha Thomas Spreitzer, https://fedorahosted.org/pam_url
#include "pam_url.h"
PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
pam_url_opts opts;
int ret=0;
int len = 0;
char* addextra = "&PAM_SM_SESSION=open";
char* tmp = NULL;
if ( PAM_SUCCESS != pam_get_item(pamh, PAM_USER, &opts.user) )
{
ret++;
debug(pamh, "Could not get user item from pam.");
}
if( PAM_SUCCESS != parse_opts(&opts, argc, argv, PAM_SM_SESSION) )
{
ret++;
debug(pamh, "Could not parse module options.");
}
len = strlen(opts.extra_field) + strlen(addextra) + 1;
opts.extra_field = realloc(opts.extra_field, len);
if (opts.extra_field == NULL)
goto done;
tmp = calloc(1, strlen(opts.extra_field) + 1);
if (tmp == NULL)
goto done;
snprintf(tmp, strlen(opts.extra_field) + 1, "%s", opts.extra_field);
snprintf(opts.extra_field, len, "%s%s", addextra, tmp);
free(tmp);
if( PAM_SUCCESS != fetch_url(pamh, opts) )
{
ret++;
debug(pamh, "Could not fetch URL.");
}
if( PAM_SUCCESS != check_rc(opts) )
{
ret++;
debug(pamh, "Wrong Return Code");
}
done:
cleanup(&opts);
if( 0 == ret )
{
return PAM_SUCCESS;
}
else
{
debug(pamh, "Session not registering. Failing.");
return PAM_SESSION_ERR;
}
}
PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
pam_url_opts opts;
int ret=0;
int len = 0;
char* addextra = "&PAM_SM_SESSION=close";
char* tmp = NULL;
if ( PAM_SUCCESS != pam_get_item(pamh, PAM_USER, &opts.user) )
{
ret++;
debug(pamh, "Could not get user item from pam.");
}
if( PAM_SUCCESS != parse_opts(&opts, argc, argv, PAM_SM_SESSION) )
{
ret++;
debug(pamh, "Could not parse module options.");
}
len = strlen(opts.extra_field) + strlen(addextra) + 1;
opts.extra_field = realloc(opts.extra_field, len);
if (opts.extra_field == NULL)
goto done;
tmp = calloc(1, strlen(opts.extra_field) + 1);
if (tmp == NULL)
goto done;
snprintf(tmp, strlen(opts.extra_field) + 1, "%s", opts.extra_field );
snprintf(opts.extra_field, len, "%s%s", addextra, tmp);
free(tmp);
if( PAM_SUCCESS != fetch_url(pamh, opts) )
{
ret++;
debug(pamh, "Could not fetch URL.");
}
if( PAM_SUCCESS != check_rc(opts) )
{
ret++;
debug(pamh, "Wrong Return Code.");
}
done:
cleanup(&opts);
if( 0 == ret )
{
return PAM_SUCCESS;
}
else
{
debug(pamh, "Session not releasing. Failing.");
return PAM_SESSION_ERR;
}
}