forked from tester1969/pam-validity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pam_validity_debug.c
68 lines (57 loc) · 1.64 KB
/
pam_validity_debug.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
/* expected hook */
PAM_EXTERN int pam_sm_setcred( pam_handle_t *pamh, int flags, int argc, const char **argv ) {
return PAM_SUCCESS;
}
PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) {
printf("Acct mgmt\n");
return PAM_SUCCESS;
}
/* expected hook, this is where custom stuff happens */
PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh, int flags,int argc, const char **argv ) {
int retval;
pid_t pid;
const char* pUsername;
char *const parmList[] = {"/bin/ls", "-l", "/u/userid/dirname", NULL};
char *const envParms[2] = {"STEPLIB=SASC.V6.LINKLIB", NULL};
int i = 1; int waitstatus;
fprintf(stderr,"Reached step 1");
// ubuntu, fedora
chdir("/usr/local/bin/python-validity");
// arch
chdir("/usr/share/python-validity/playground");
pid = fork();
if (pid < 0) {
fprintf(stderr, "Fork failed");
return 1;
}
else if (pid == 0) {
printf("Child PID is %d\n", pid);
// ubuntu, fedora
i = execv("/usr/local/bin/python-validity/pam_validity.sh", NULL);
// arch
i = execv("/usr/share/python-validity/playground/pam_validity.sh", NULL);
}
else {
wait(&waitstatus);
i = WEXITSTATUS(waitstatus);
}
retval = pam_get_user(pamh, &pUsername, "Username: ");
printf("Welcome %s\n", pUsername);
printf("ExitCode %i", i);
if (i == 0) {
fprintf(stderr,"Success");
return PAM_SUCCESS;
}
else {
fprintf(stderr,"Failure");
return PAM_AUTH_ERR;
}
}