Repository navigation
Expand file tree
/
Copy pathnss_exec-shadow.c
More file actions
146 lines (101 loc) · 3.69 KB
/
Copy pathnss_exec-shadow.c
File metadata and controls
146 lines (101 loc) · 3.69 KB
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
145
#include "nss_exec.h"
static long ent_index = 0;
static pthread_mutex_t NSS_EXEC_MUTEX = PTHREAD_MUTEX_INITIALIZER;
static int pack_shadow_struct(struct spwd *result, char *buffer, size_t buffer_length, char *output) {
field_parse_info info;
field_parse_init(&info, buffer, buffer_length, output);
result->sp_namp = field_parse_string(&info);
result->sp_pwdp = field_parse_string(&info);
result->sp_lstchg = field_parse_long(&info);
result->sp_min = field_parse_long(&info);
result->sp_max = field_parse_long(&info);
result->sp_warn = field_parse_long(&info);
// Set defaults for integers because they parse differently
result->sp_inact = -1;
result->sp_expire = -1;
result->sp_flag = ~0ul;
if (field_parse_more(&info)) {
result->sp_inact = field_parse_long(&info);
}
if (field_parse_more(&info)) {
result->sp_expire = field_parse_long(&info);
}
if (field_parse_more(&info)) {
result->sp_flag = field_parse_long(&info);
}
return info.return_code;
}
enum nss_status _nss_exec_setspent_locked(int stayopen) {
enum nss_status result_status;
result_status = nss_exec_script(NULL, "setspent", NULL);
if (result_status == NSS_STATUS_SUCCESS) {
ent_index = 0;
}
return result_status;
}
// Called to open the shadow file
enum nss_status _nss_exec_setspent(int stayopen) {
enum nss_status ret;
NSS_EXEC_LOCK();
ret = _nss_exec_setspent_locked(stayopen);
NSS_EXEC_UNLOCK();
return ret;
}
enum nss_status _nss_exec_endspent_locked(void) {
enum nss_status result_status;
result_status = nss_exec_script(NULL, "endspent", NULL);
if (result_status == NSS_STATUS_SUCCESS) {
ent_index = 0;
}
return result_status;
}
// Called to close the shadow file
enum nss_status _nss_exec_endspent(void) {
enum nss_status ret;
NSS_EXEC_LOCK();
ret = _nss_exec_endspent_locked();
NSS_EXEC_UNLOCK();
return ret;
}
enum nss_status _nss_exec_getspent_r_locked(struct spwd *result, char *buffer, size_t buffer_length, int *errnop) {
enum nss_status result_status;
char *output;
int pack_result;
result_status = nss_exec_script_long(&output, "getspent", ent_index);
if (result_status == NSS_STATUS_SUCCESS) {
ent_index += 1;
pack_result = pack_shadow_struct(result, buffer, buffer_length, output);
result_status = handle_pack_result(pack_result, errnop);
}
return result_status;
}
// Called to look up next entry in shadow file
enum nss_status _nss_exec_getspent_r(struct spwd *result, char *buffer, size_t buffer_length, int *errnop) {
enum nss_status ret;
NSS_EXEC_LOCK();
ret = _nss_exec_getspent_r_locked(result, buffer, buffer_length, errnop);
NSS_EXEC_UNLOCK();
return ret;
}
enum nss_status _nss_exec_getspnam_r_locked(const char *name, struct spwd *result, char *buffer, size_t buffer_length, int *errnop) {
enum nss_status result_status;
char *output;
int pack_result;
result_status = nss_exec_script(&output, "getspnam", name);
if (result_status == NSS_STATUS_SUCCESS) {
pack_result = pack_shadow_struct(result, buffer, buffer_length, output);
result_status = handle_pack_result(pack_result, errnop);
if (pack_result) {
result_status = NSS_STATUS_UNAVAIL;
}
}
return result_status;
}
// Find a shadow by name
enum nss_status _nss_exec_getspnam_r(const char *name, struct spwd *result, char *buffer, size_t buffer_length, int *errnop) {
enum nss_status ret;
NSS_EXEC_LOCK();
ret = _nss_exec_getspnam_r_locked(name, result, buffer, buffer_length, errnop);
NSS_EXEC_UNLOCK();
return ret;
}