6 |
|
|
7 |
|
#include "common.h" |
8 |
|
|
9 |
+ |
Shells shells[] = { |
10 |
+ |
{ "sh", "/bin/sh", "/bin/sh", "/bin/sh", "/usr/bin/sh" }, |
11 |
+ |
{ "csh", "/bin/csh", "/bin/csh", "/bin/csh", "/usr/bin/csh" }, |
12 |
+ |
{ "tcsh", "/bin/tcsh", "/bin/tcsh", "/bin/tcsh", "/usr/bin/tcsh" }, |
13 |
+ |
{ "bash", "/usr/local/bin/bash", "/bin/bash", "/bin/bash", "/usr/local/bin/bash" }, |
14 |
+ |
{ "ksh", "/usr/local/bin/ksh", "/bin/ksh", "/bin/ksh", "/usr/bin/ksh" }, |
15 |
+ |
{ "zsh", "/usr/local/bin/zsh", "/bin/zsh", "/bin/zsh", "/usr/bin/zsh" }, |
16 |
+ |
{ "3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh" }, |
17 |
+ |
{ "custom", NULL, NULL, NULL, NULL } |
18 |
+ |
}; |
19 |
+ |
|
20 |
|
int check(int value, jmp_buf environment) |
21 |
|
{ |
22 |
|
if (value == -1) |
87 |
|
{ |
88 |
|
check(dup2(pipe_[1], 1), environment); |
89 |
|
check(close(pipe_[0]), environment); |
90 |
< |
check(execl("/usr/local/bin/ldapwhoami", program, "-D", name, "-W", "-x", "-y", secret, NULL), environment); |
90 |
> |
check(execl(LDAPWHOAMI, program, "-D", name, "-W", "-x", "-y", secret, NULL), environment); |
91 |
|
} |
92 |
|
|
93 |
|
check(close(pipe_[1]), environment); |
132 |
|
check(write(file, password, strlen(password)), environment); |
133 |
|
check(close(file), environment); |
134 |
|
} |
135 |
+ |
|
136 |
+ |
void get(const char *prompt, regex_t *regex, char **string, jmp_buf environment) |
137 |
+ |
{ |
138 |
+ |
do |
139 |
+ |
{ |
140 |
+ |
printf("%s: ", prompt); |
141 |
+ |
|
142 |
+ |
size_t size; |
143 |
+ |
char *string_ = fcheck(fgetln(stdin, &size), stdin, environment); |
144 |
+ |
|
145 |
+ |
*string = *string ? realloc(*string, size) : malloc(size); |
146 |
+ |
|
147 |
+ |
strlcpy(*string, string_, size); |
148 |
+ |
} |
149 |
+ |
while (regcheck(regexec(regex, *string, 0, NULL, 0), regex, environment)); |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
void setshells(Shells *shells, jmp_buf environment) |
153 |
+ |
{ |
154 |
+ |
check(setenv("FREEBSD", shells->freebsd, 1), environment); |
155 |
+ |
check(setenv("LINUX", shells->linux, 1), environment); |
156 |
+ |
check(setenv("DARWIN", shells->darwin, 1), environment); |
157 |
+ |
check(setenv("SOLARIS", shells->solaris, 1), environment); |
158 |
+ |
} |
159 |
+ |
|
160 |
+ |
#if !defined(__FreeBSD__) && !defined(__sun__) |
161 |
+ |
size_t strlcpy(char *dst, const char *src, size_t size) |
162 |
+ |
{ |
163 |
+ |
dst[size - 1] = '\0'; |
164 |
+ |
|
165 |
+ |
return strlen(strncpy(dst, src, size - 1)); |
166 |
+ |
} |
167 |
+ |
|
168 |
+ |
size_t strlcat(char *dst, const char *src, size_t size) |
169 |
+ |
{ |
170 |
+ |
dst[size - 1] = '\0'; |
171 |
+ |
|
172 |
+ |
size_t size_ = strlen(dst); |
173 |
+ |
|
174 |
+ |
return strlen(strncpy(dst + size_, src, size - size_ - 1)); |
175 |
+ |
} |
176 |
+ |
|
177 |
+ |
char *fgetln(FILE * restrict stream, size_t * restrict len) |
178 |
+ |
{ |
179 |
+ |
static char *line = NULL; |
180 |
+ |
static size_t size; |
181 |
+ |
|
182 |
+ |
if ((*len = getline(&line, &size, stream)) == -1) |
183 |
+ |
return NULL; |
184 |
+ |
|
185 |
+ |
return line; |
186 |
+ |
} |
187 |
+ |
#elif defined(__sun__) |
188 |
+ |
char *fgetln(FILE * restrict stream, size_t * restrict len) |
189 |
+ |
{ |
190 |
+ |
static char *line = NULL; |
191 |
+ |
|
192 |
+ |
*len = 0; |
193 |
+ |
line = line ? realloc(line, 1) : malloc(1); |
194 |
+ |
|
195 |
+ |
while (line[*len] = getc(stream), line[(*len)++] != '\n') |
196 |
+ |
if (line[*len - 1] != EOF) |
197 |
+ |
line = realloc(line, *len + 1); |
198 |
+ |
else |
199 |
+ |
return NULL; |
200 |
+ |
|
201 |
+ |
return line; |
202 |
+ |
} |
203 |
+ |
|
204 |
+ |
int setenv(const char *name, const char *value, int overwrite) |
205 |
+ |
{ |
206 |
+ |
char *string = getenv(name); |
207 |
+ |
|
208 |
+ |
if (overwrite || !string) |
209 |
+ |
{ |
210 |
+ |
string = string ? realloc(string, strlen(name) + strlen(value) + 2) : malloc(strlen(name) + strlen(value) + 2); |
211 |
+ |
|
212 |
+ |
sprintf(string, "%s=%s", name, value); |
213 |
+ |
|
214 |
+ |
return putenv(string); |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
return 0; |
218 |
+ |
} |
219 |
+ |
#endif |