4 |
|
// |
5 |
|
// Change Shell |
6 |
|
|
7 |
– |
#include <sys/utsname.h> |
8 |
– |
|
7 |
|
#include "common.h" |
8 |
|
|
9 |
|
int main(int argc, char *argv[]) |
11 |
|
if (argc < 1) |
12 |
|
return 1; |
13 |
|
|
14 |
+ |
umask(S_IWGRP | S_IWOTH); |
15 |
+ |
|
16 |
|
int exception; |
17 |
|
jmp_buf environment; |
18 |
|
|
30 |
|
return 1; |
31 |
|
} |
32 |
|
|
33 |
– |
char user[MAXLOGNAME] = "", *shell = NULL; |
34 |
– |
regex_t shell_; |
35 |
– |
|
33 |
|
typedef struct |
34 |
|
{ |
35 |
|
const char *name; |
68 |
|
char shell_regex_[strlen(shell_regex) + 12]; |
69 |
|
|
70 |
|
sprintf(shell_regex_, "^-shell=(%s)$", shell_regex); |
71 |
+ |
|
72 |
+ |
regex_t shell_; |
73 |
+ |
|
74 |
|
regcheck(regcomp(&shell_, shell_regex_, REG_EXTENDED), &shell_, environment); |
75 |
|
|
76 |
+ |
char user[MAXLOGNAME] = "", *shell = NULL; |
77 |
+ |
|
78 |
|
if (!getuid()) |
79 |
|
{ |
80 |
|
regex_t user_; |
132 |
|
{ |
133 |
|
sprintf(shell_regex_, "^%s$", shell_regex); |
134 |
|
regcheck(regcomp(&shell_, shell_regex_, REG_EXTENDED), &shell_, environment); |
135 |
+ |
|
136 |
|
do |
137 |
|
{ |
138 |
|
printf("Shell ("); |
174 |
|
|
175 |
|
no: check(setuid(geteuid()), environment); |
176 |
|
|
174 |
– |
int pipe_[2]; |
175 |
– |
|
176 |
– |
check(pipe(pipe_), environment); |
177 |
– |
|
177 |
|
pid_t bash_; |
178 |
|
|
179 |
|
if (!(bash_ = check(fork(), environment))) |
180 |
|
{ |
182 |
– |
check(dup2(pipe_[0], 0), environment); |
183 |
– |
check(close(pipe_[1]), environment); |
181 |
|
check(setenv("USER", user, 1), environment); |
182 |
+ |
check(setenv("FREEBSD", shells_->freebsd, 1), environment); |
183 |
+ |
check(setenv("LINUX", shells_->linux, 1), environment); |
184 |
+ |
check(setenv("DARWIN", shells_->darwin, 1), environment); |
185 |
|
check(execl("/ccs/bin/chsh.sh", argv[0], NULL), environment); |
186 |
|
} |
187 |
|
|
188 |
– |
check(close(pipe_[0]), environment); |
189 |
– |
|
190 |
– |
FILE *sed = fdopen(pipe_[1], "w"); |
191 |
– |
|
192 |
– |
if (fprintf(sed, "%s\n%s\n%s\n", shells_->freebsd, shells_->linux, shells_->darwin) < 0) |
193 |
– |
longjmp(environment, 1); |
194 |
– |
|
195 |
– |
if (fclose(sed)) |
196 |
– |
longjmp(environment, 1); |
197 |
– |
|
188 |
|
int status; |
189 |
|
|
190 |
|
check(waitpid(bash_, &status, 0), environment); |