forked from mricon/pam_url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpam_url_authenticate.c
71 lines (59 loc) · 1.39 KB
/
pam_url_authenticate.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
// pam_url - GPLv2, Sascha Thomas Spreitzer, https://fedorahosted.org/pam_url
#include "pam_url.h"
PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
{ // by now, a dummy
return PAM_SUCCESS;
}
PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags,
int argc, const char **argv)
{
pam_url_opts opts;
int ret = 0;
int len = 0;
if ( PAM_SUCCESS != pam_get_item(pamh, PAM_USER, &opts.user) )
{
ret++;
debug(pamh, "Could not get user item from pam.");
}
if( PAM_SUCCESS != pam_get_item(pamh, PAM_AUTHTOK, &opts.passwd) )
{
ret++;
debug(pamh, "Could not get password item from pam.");
}
if( PAM_SUCCESS != parse_opts(&opts, argc, argv, PAM_SM_AUTH) )
{
ret++;
debug(pamh, "Could not parse module options.");
}
if( !opts.use_first_pass || NULL == opts.passwd )
{
if( NULL != opts.passwd ) {
opts.first_pass = strdup(opts.passwd);
}
if( PAM_SUCCESS != get_password(pamh, &opts) )
{
debug(pamh, "Could not get password from user. No TTY?");
return PAM_AUTH_ERR;
}
}
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.");
}
cleanup(&opts);
if( 0 == ret )
{
return PAM_SUCCESS;
}
else
{
debug(pamh, "Authentication failed.");
return PAM_AUTH_ERR;
}
}