ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSAdmin/chsh.c
(Generate patch)

Comparing CCSAdmin/chsh.c (file contents):
Revision 565 by douglas, 2005-08-28T03:37:15-07:00 vs.
Revision 569 by douglas, 2005-08-28T23:50:17-07:00

# Line 4 | Line 4
4   //
5   // Change Shell
6  
7 #include <sys/utsname.h>
8
7   #include "common.h"
8  
9   int main(int argc, char *argv[])
# Line 13 | Line 11 | 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  
# Line 30 | Line 30 | int main(int argc, char *argv[])
30                  return 1;
31          }
32  
33        char user[MAXLOGNAME] = "", *shell = NULL;
34        regex_t shell_;
35
33          typedef struct
34          {
35                  const char *name;
# Line 71 | Line 68 | int main(int argc, char *argv[])
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_;
# Line 130 | Line 132 | on:    regfree(&shell_);
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 (");
# Line 171 | Line 174 | on:    regfree(&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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines