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
|
/* Source code from http://www.rkeene.org/projects/info/wiki/222, adapted by Camil Staps */
/* Define which PAM interfaces we provide */
#define PAM_SM_ACCOUNT
#define PAM_SM_AUTH
#define PAM_SM_PASSWORD
#define PAM_SM_SESSION
/* Include PAM headers */
#include <security/pam_appl.h>
#include <security/pam_modules.h>
/* Other headers */
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
/* Our questions and answers */
const char * const q[5] = {
"6*7",
"the answer to life the universe and everything",
"'forty two' in numbers",
"the meaning of 'efa-polo roa' in Malagasi",
"not 54" };
const char a[5] = {42, 42, 42, 42, 42};
/* PAM entry point for session creation */
int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return(PAM_IGNORE);
}
/* PAM entry point for session cleanup */
int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return(PAM_IGNORE);
}
/* PAM entry point for accounting */
int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return(PAM_IGNORE);
}
/* PAM entry point for authentication verification */
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) {
const char* username;
pam_get_user(pamh, &username, NULL);
srand(time(NULL));
int r = rand() % 5;
printf("What is %s? ", q[r]);
int resp;
scanf("%d", &resp);
if (resp == a[r]) {
return(PAM_SUCCESS);
} else {
return(PAM_AUTH_ERR);
}
}
/*
PAM entry point for setting user credentials (that is, to actually
establish the authenticated user's credentials to the service provider)
*/
int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return(PAM_IGNORE);
}
/* PAM entry point for authentication token (password) changes */
int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return(PAM_IGNORE);
}
|