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 583 by douglas, 2005-11-21T12:56:05-08: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
36        typedef struct
37        {
38                const char *name;
39                char *freebsd, *linux, *darwin;
40        }
41        Shells;
42
43        typedef enum { sh, csh, tcsh, bash, ksh, zsh, _3sh, custom } Shell;
44
45        Shells shells[] = {
46                { "sh", "/bin/sh", "/bin/sh", "/bin/sh" },
47                { "csh", "/bin/csh", "/bin/csh", "/bin/csh" },
48                { "tcsh", "/bin/tcsh", "/bin/tcsh", "/bin/tcsh" },
49                { "bash", "/usr/local/bin/bash", "/bin/bash", "/bin/bash" },
50                { "ksh", "/usr/local/bin/ksh", "/bin/ksh", "/bin/ksh" },
51                { "zsh", "/usr/local/bin/zsh", "/bin/zsh", "/bin/zsh" },
52                { "3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh" },
53                { "custom", NULL, NULL, NULL }
54        };
55
33          char *shell_regex = NULL;
34  
35          {
# Line 71 | Line 48 | int main(int argc, char *argv[])
48          char shell_regex_[strlen(shell_regex) + 12];
49  
50          sprintf(shell_regex_, "^-shell=(%s)$", shell_regex);
51 +
52 +        regex_t shell_;
53 +
54          regcheck(regcomp(&shell_, shell_regex_, REG_EXTENDED), &shell_, environment);
55  
56 +        char user[MAXLOGNAME] = "", *shell = NULL;
57 +
58          if (!getuid())
59          {
60                  regex_t user_;
# Line 130 | Line 112 | on:    regfree(&shell_);
112          {
113                  sprintf(shell_regex_, "^%s$", shell_regex);
114                  regcheck(regcomp(&shell_, shell_regex_, REG_EXTENDED), &shell_, environment);
115 +
116                  do
117                  {
118                          printf("Shell (");
# Line 167 | Line 150 | on:    regfree(&shell_);
150          get("FreeBSD", &path, &shells_->freebsd, environment);
151          get("Linux", &path, &shells_->linux, environment);
152          get("Darwin", &path, &shells_->darwin, environment);
153 +        get("Solaris", &path, &shells_->solaris, environment);
154          regfree(&path);
155  
156   no:     check(setuid(geteuid()), environment);
157  
174        int pipe_[2];
175
176        check(pipe(pipe_), environment);
177
158          pid_t bash_;
159  
160          if (!(bash_ = check(fork(), environment)))
161          {
182                check(dup2(pipe_[0], 0), environment);
183                check(close(pipe_[1]), environment);
162                  check(setenv("USER", user, 1), environment);
163 +                setshells(shells_, environment);
164                  check(execl("/ccs/bin/chsh.sh", argv[0], NULL), environment);
165          }
166  
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
167          int status;
168  
169          check(waitpid(bash_, &status, 0), environment);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines