Changeset 438
- Timestamp:
- 06/07/2009 01:39:17 (9 months ago)
- Location:
- admin
- Files:
-
- 11 modified
- 2 copied
-
GNUmakefile (modified) (6 diffs)
-
adduser.c (modified) (8 diffs)
-
chfn.c (modified) (3 diffs)
-
chsh.c (modified) (3 diffs)
-
common.c (modified) (7 diffs)
-
common.h (modified) (1 diff)
-
mysql.c (copied) (copied from admin/common.c) (1 diff)
-
mysql.h (copied) (copied from admin/common.h) (1 diff)
-
passwd.c (modified) (8 diffs)
-
secret.c (modified) (3 diffs)
-
shells.c (modified) (3 diffs)
-
turnin.c (modified) (2 diffs)
-
users.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
admin/GNUmakefile
r415 r438 11 11 COMMANDS := createuser date diff grep ldapmodify ldapsearch sed tail 12 12 CPPFLAGS := -DLDAPSEARCH=\"$(shell which ldapsearch)\" -DLDAPWHOAMI=\"$(shell which ldapwhoami)\" -DMASTER=\"$(MASTER)\" 13 CFLAGS := -std=c99 -Wall -pedantic -g -O2 13 14 UNAME :=$(shell uname) 14 15 HOSTNAME :=$(shell hostname -f 2> /dev/null || uname -n) … … 32 33 COMMANDS += ldapadd ldappasswd slappasswd smbpasswd 33 34 MASTERSLAVE :=Master 35 MYSQL_CFLAGS := $(shell mysql_config --include) 36 MYSQL_LDFLAGS := $(shell mysql_config --libs) 34 37 else 35 38 ifeq ($(HOSTNAME),$(SLAVE)) … … 62 65 endif 63 66 64 CFLAGS := -std=c99 -Wall -pedantic -g -O265 66 67 ifeq ($(shell sed --version </dev/null 2>/dev/null),) 67 68 E :=E … … 82 83 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ 83 84 85 ifdef ISMASTER 86 $(MACHINE)/adduser: adduser.c mysql.h users.h $(MACHINE)/common.o $(MACHINE)/mysql.o 87 @mkdir -p $(MACHINE) 88 $(CC) $(CPPFLAGS) $(CFLAGS) $(MYSQL_CFLAGS) $(LDFLAGS) $(MYSQL_LDFLAGS) $(filter-out %.h,$^) $(LOADLIBES) $(LDLIBS) -o $@ 89 90 $(MACHINE)/passwd: passwd.c mysql.h $(MACHINE)/common.o $(MACHINE)/mysql.o 91 @mkdir -p $(MACHINE) 92 $(CC) $(CPPFLAGS) $(CFLAGS) $(MYSQL_CFLAGS) $(LDFLAGS) $(MYSQL_LDFLAGS) $(filter-out %.h,$^) $(LOADLIBES) $(LDLIBS) -o $@ 93 else 84 94 $(MACHINE)/adduser: adduser.c users.h $(MACHINE)/common.o 85 95 86 96 $(MACHINE)/passwd: passwd.c $(MACHINE)/common.o 97 endif 87 98 88 99 $(MACHINE)/chsh: chsh.c $(MACHINE)/common.o … … 103 114 104 115 $(MACHINE)/common.o: common.c common.h 116 117 ifdef ISMASTER 118 $(MACHINE)/mysql.o: mysql.c mysql.h 119 @mkdir -p $(MACHINE) 120 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(MYSQL_CFLAGS) $< -o $@ 121 endif 105 122 106 123 $(MACHINE)/common.sh: GNUmakefile $(MACHINE)/shells … … 205 222 206 223 clean: 207 -rm - rf $(MACHINE)*.core224 -rm -f $(MACHINE)/* *.core -
admin/adduser.c
r264 r438 7 7 8 8 #include "common.h" 9 10 #ifdef _Master_ 11 #include "mysql.h" 12 #endif 9 13 10 14 #include <errno.h> … … 79 83 jmp_buf environment; 80 84 85 #ifdef _Master_ 86 MYSQL_BEGIN(); 87 #endif 88 81 89 switch (setjmp(environment)) 82 90 { 83 91 case 0: 84 92 break; 85 case 1:93 case POSIX_EXCEPTION: 86 94 perror(argv[0]); 87 95 88 return 1;89 default:96 goto end; 97 case STRING_EXCEPTION: 90 98 fprintf(stderr, "%s: %s\n", argv[0], exception); 91 99 #ifdef _Master_ 100 101 goto end; 102 case MYSQL_EXCEPTION: 103 fprintf(stderr, "%s: %s\n", argv[0], mysql_error(mysql)); 104 #endif 105 106 end: 107 #ifdef _Master_ 108 MYSQL_END(); 109 110 #endif 92 111 return 1; 93 112 } … … 113 132 printf("Usage: %s [-user=user] [-name=name]\n", argv[0]); 114 133 115 return 1;134 goto end; 116 135 } 117 136 } … … 139 158 } 140 159 else if (exists(argv[0], user, environment)) 141 longjmp(environment, (exception = "User exists", 3));160 longjmp(environment, (exception = "User exists", STRING_EXCEPTION)); 142 161 143 162 if (!name) … … 179 198 180 199 if (fprintf(smbpasswd, "%s\n%s\n", password, password) < 0) 181 longjmp(environment, 1);200 longjmp(environment, POSIX_EXCEPTION); 182 201 183 202 if (fclose(smbpasswd)) 184 longjmp(environment, 1);203 longjmp(environment, POSIX_EXCEPTION); 185 204 186 205 int status; … … 190 209 191 210 if (WEXITSTATUS(status)) 192 return 1; 211 goto end; 212 213 mysqlpassword(mysql, user, password, environment); 214 MYSQL_END(); 193 215 194 216 struct passwd *entry = getpwnam(user); 195 217 196 218 if (!entry) 197 longjmp(environment, 1);219 longjmp(environment, POSIX_EXCEPTION); 198 220 199 221 check(mkdir(entry->pw_dir, S_IRWXU | S_IRWXG | S_IRWXO), environment); … … 204 226 205 227 if (!traversal) 206 longjmp(environment, 1);228 longjmp(environment, POSIX_EXCEPTION); 207 229 208 230 FTSENT *entity; … … 243 265 244 266 if (errno) 245 longjmp(environment, 1);267 longjmp(environment, POSIX_EXCEPTION); 246 268 247 269 if (fts_close(traversal)) 248 longjmp(environment, 1);270 longjmp(environment, POSIX_EXCEPTION); 249 271 #else 250 longjmp(environment, (exception = "Log in to " MASTER " to add users", 3));272 longjmp(environment, (exception = "Log in to " MASTER " to add users", STRING_EXCEPTION)); 251 273 #endif 252 274 -
admin/chfn.c
r264 r438 21 21 case 0: 22 22 break; 23 case 1:23 case POSIX_EXCEPTION: 24 24 perror(argv[0]); 25 25 26 26 return 1; 27 default:27 case STRING_EXCEPTION: 28 28 fprintf(stderr, "%s: %s\n", argv[0], exception); 29 29 … … 64 64 goto on; 65 65 else 66 longjmp(environment, (exception = "Cannot change root full name", 3));66 longjmp(environment, (exception = "Cannot change root full name", STRING_EXCEPTION)); 67 67 } 68 68 else … … 84 84 85 85 if (!entry) 86 longjmp(environment, 1);86 longjmp(environment, POSIX_EXCEPTION); 87 87 88 88 strlcpy(user, entry->pw_name, sizeof (user)); -
admin/chsh.c
r264 r438 23 23 case 0: 24 24 break; 25 case 1:25 case POSIX_EXCEPTION: 26 26 perror(argv[0]); 27 27 28 28 return 1; 29 default:29 case STRING_EXCEPTION: 30 30 fprintf(stderr, "%s: %s\n", argv[0], exception); 31 31 … … 85 85 goto on; 86 86 else 87 longjmp(environment, (exception = "Cannot change root shell", 3));87 longjmp(environment, (exception = "Cannot change root shell", STRING_EXCEPTION)); 88 88 } 89 89 else … … 105 105 106 106 if (!entry) 107 longjmp(environment, 1);107 longjmp(environment, POSIX_EXCEPTION); 108 108 109 109 strlcpy(user, entry->pw_name, sizeof (user)); -
admin/common.c
r264 r438 30 30 { 31 31 if (value == -1) 32 longjmp(environment, 1);32 longjmp(environment, POSIX_EXCEPTION); 33 33 34 34 return value; … … 53 53 { 54 54 if (ferror(stream)) 55 longjmp(environment, 1);55 longjmp(environment, POSIX_EXCEPTION); 56 56 else 57 57 { … … 73 73 74 74 if (!entry) 75 longjmp(environment, 1);75 longjmp(environment, POSIX_EXCEPTION); 76 76 77 77 char name[strlen(entry->pw_name) + 36]; … … 83 83 84 84 if (!strlen(password)) 85 longjmp(environment, (exception = "Empty password", 3));85 longjmp(environment, (exception = "Empty password", STRING_EXCEPTION)); 86 86 87 87 char secret[] = "/tmp/secret.XXXXXX"; … … 113 113 114 114 if (WEXITSTATUS(status)) 115 longjmp(environment, (exception = "Sorry", 3));115 longjmp(environment, (exception = "Sorry", STRING_EXCEPTION)); 116 116 117 117 char whoami[size]; … … 124 124 125 125 if (strcmp(whoami, whoami_)) 126 longjmp(environment, (exception = "Sorry", 3));126 longjmp(environment, (exception = "Sorry", STRING_EXCEPTION)); 127 127 128 128 free(whoami_); … … 134 134 135 135 if (!strlen(password)) 136 longjmp(environment, (exception = "Empty password", 3));136 longjmp(environment, (exception = "Empty password", STRING_EXCEPTION)); 137 137 138 138 if (strcmp(password, getpass("Confirm Password: "))) 139 longjmp(environment, (exception = "Password and confirm password mismatched", 3));139 longjmp(environment, (exception = "Password and confirm password mismatched", STRING_EXCEPTION)); 140 140 } 141 141 -
admin/common.h
r264 r438 46 46 #endif 47 47 48 #define POSIX_EXCEPTION 1 49 #define STRING_EXCEPTION 2 50 #define SECRET "/ccs/etc/secret" 51 48 52 extern char *exception; 49 53 -
admin/mysql.c
r264 r438 6 6 // $Id$ 7 7 8 #include " common.h"8 #include "mysql.h" 9 9 10 #include <ctype.h> 10 #include <fcntl.h> 11 #include <stdbool.h> 11 12 12 #ifdef __sun__ 13 #define getpass getpassphrase 14 #endif 15 16 char *exception = NULL; 17 18 Shells shells[] = { 19 { "sh", "/bin/sh", "/bin/sh", "/bin/sh", "/usr/bin/sh", "/bin/sh", "/bin/sh" }, 20 { "csh", "/bin/csh", "/bin/csh", "/bin/csh", "/usr/bin/csh", "/bin/csh", "/bin/csh" }, 21 { "tcsh", "/bin/tcsh", "/bin/tcsh", "/bin/tcsh", "/usr/bin/tcsh", "/usr/local/bin/tcsh", "/usr/bin/tcsh" }, 22 { "bash", "/usr/local/bin/bash", "/bin/bash", "/opt/local/bin/bash", "/usr/local/bin/bash", "/usr/local/bin/bash", "/bin/bash" }, 23 { "ksh", "/usr/local/bin/ksh", "/bin/ksh", "/bin/ksh", "/usr/bin/ksh", "/bin/ksh", "/usr/bin/ksh" }, 24 { "zsh", "/usr/local/bin/zsh", "/bin/zsh", "/bin/zsh", "/usr/bin/zsh", "/usr/local/bin/zsh", "/usr/bin/zsh" }, 25 { "3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh", "/ccs/bin/3sh" }, 26 { "custom", NULL, NULL, NULL, NULL, NULL, NULL } 27 }; 28 29 int check(int value, jmp_buf environment) 13 void mysqlcheck(int value, jmp_buf environment) 30 14 { 31 if (value == -1) 32 longjmp(environment, 1); 33 34 return value; 15 if (value) 16 longjmp(environment, MYSQL_EXCEPTION); 35 17 } 36 18 37 int regcheck(int value, const regex_t *regex, jmp_buf environment)19 void mysqlpassword(MYSQL *mysql, char user[MAXLOGNAME], char password[_PASSWORD_LEN], jmp_buf environment) 38 20 { 39 if (value && value != REG_NOMATCH) 40 { 41 char error[regerror(value, regex, NULL, 0)]; 21 FILE *stream = fopen(SECRET, "r"); 42 22 43 regerror(value, regex, error, sizeof (error)); 44 longjmp(environment, (exception = error, 3)); 45 } 23 if (!stream) 24 longjmp(environment, POSIX_EXCEPTION); 46 25 47 return value; 48 } 26 char rootpassword[_PASSWORD_LEN] = ""; 49 27 50 char *fcheck(char *value, FILE *stream, jmp_buf environment) 51 { 28 fcheck(fgets(rootpassword, _PASSWORD_LEN, stream), stream, environment); 29 30 if (fclose(stream)) 31 longjmp(environment, POSIX_EXCEPTION); 32 33 if (!mysql_real_connect(mysql, NULL, "root", rootpassword, "mysql", 0, NULL, 0)) 34 longjmp(environment, MYSQL_EXCEPTION); 35 36 MYSQL_STMT *statement = mysql_stmt_init(mysql); 37 38 if (!statement) 39 longjmp(environment, MYSQL_EXCEPTION); 40 41 char *update = "update user set Password = PASSWORD(?) where User = ?"; 42 43 mysqlcheck(mysql_stmt_prepare(statement, update, strlen(update)), environment); 44 45 size_t userlength = strlen(user), passwordlength = strlen(password); 46 MYSQL_BIND parameters[2] = { { .buffer_type = MYSQL_TYPE_STRING, .buffer = password, .buffer_length = passwordlength, .length = &passwordlength, .is_null = NULL, .is_unsigned = false, .error = NULL, 0 }, { .buffer_type = MYSQL_TYPE_STRING, .buffer = user, .buffer_length = userlength, .length = &userlength, .is_null = NULL, .is_unsigned = false, .error = NULL, 0 } }; 47 48 mysqlcheck(mysql_stmt_bind_param(statement, parameters), environment); 49 mysqlcheck(mysql_stmt_execute(statement), environment); 50 51 my_ulonglong value = mysql_stmt_affected_rows(statement); 52 52 53 if (!value) 53 54 { 54 if (ferror(stream)) 55 longjmp(environment, 1); 56 else 55 char userescaped[userlength * 2 + 1], passwordescaped[passwordlength * 2 + 1]; 56 unsigned long userescapedlength = mysql_real_escape_string(mysql, userescaped, user, userlength), passwordescapedlength = mysql_real_escape_string(mysql, passwordescaped, password, passwordlength); 57 58 char *hosts[] = { "localhost", "%" }; 59 60 for (unsigned index = 0; index != sizeof (hosts) / sizeof (*hosts); ++index) 57 61 { 58 clearerr(stream); 62 char *host = hosts[index]; 63 size_t hostlength = strlen(host); 64 char create[userescapedlength + hostlength + passwordescapedlength + 35], grant[userescapedlength * 2 + hostlength + 31]; 59 65 60 if (stream == stdin)61 printf("\n");62 63 return "";66 sprintf(create, "create user '%s'@'%s' identified by '%s'", userescaped, host, passwordescaped); 67 mysqlcheck(mysql_query(mysql, create), environment); 68 sprintf(grant, "grant all on `%s\\_%%`.* to '%s'@'%s'", userescaped, userescaped, host); 69 mysqlcheck(mysql_query(mysql, grant), environment); 64 70 } 65 71 } 72 else if (value < 0) 73 longjmp(environment, MYSQL_EXCEPTION); 66 74 67 return value;75 mysqlcheck(mysql_stmt_close(statement), environment); 68 76 } 69 70 void authenticate(const char *program, jmp_buf environment)71 {72 struct passwd *entry = getpwuid(getuid());73 74 if (!entry)75 longjmp(environment, 1);76 77 char name[strlen(entry->pw_name) + 36];78 79 sprintf(name, "uid=%s,ou=People,dc=ccs,dc=ucsb,dc=edu", entry->pw_name);80 umask(022);81 82 char *password = getpass("Password: ");83 84 if (!strlen(password))85 longjmp(environment, (exception = "Empty password", 3));86 87 char secret[] = "/tmp/secret.XXXXXX";88 89 putpassword(password, secret, environment);90 91 int pipe_[2];92 93 check(pipe(pipe_), environment);94 95 pid_t ldapwhoami;96 97 if (!(ldapwhoami = check(fork(), environment)))98 {99 check(dup2(pipe_[1], 1), environment);100 check(close(pipe_[0]), environment);101 check(execl(LDAPWHOAMI, program, "-D", name, "-H", "ldaps://" MASTER, "-W", "-x", "-y", secret, NULL), environment);102 }103 104 check(close(pipe_[1]), environment);105 106 FILE *ldapwhoami_ = fdopen(pipe_[0], "r");107 size_t size;108 char *whoami_ = fcheck(fgetln(ldapwhoami_, &size), ldapwhoami_, environment);109 int status;110 111 check(waitpid(ldapwhoami, &status, 0), environment);112 check(unlink(secret), environment);113 114 if (WEXITSTATUS(status))115 longjmp(environment, (exception = "Sorry", 3));116 117 char whoami[size];118 119 strlcpy(whoami, whoami_, size);120 121 whoami_ = malloc(sizeof (name) + 3);122 123 sprintf(whoami_, "dn:%s", name);124 125 if (strcmp(whoami, whoami_))126 longjmp(environment, (exception = "Sorry", 3));127 128 free(whoami_);129 }130 131 void getpassword(char password[_PASSWORD_LEN], jmp_buf environment)132 {133 strcpy(password, getpass("New Password: "));134 135 if (!strlen(password))136 longjmp(environment, (exception = "Empty password", 3));137 138 if (strcmp(password, getpass("Confirm Password: ")))139 longjmp(environment, (exception = "Password and confirm password mismatched", 3));140 }141 142 void putpassword(char password[_PASSWORD_LEN], char *name, jmp_buf environment)143 {144 int file = check(mkstemp(name), environment);145 146 check(write(file, password, strlen(password)), environment);147 check(close(file), environment);148 }149 150 void get(const char *prompt, regex_t *regex, char **string, jmp_buf environment)151 {152 do153 {154 printf("%s: ", prompt);155 156 size_t size;157 char *string_ = fcheck(fgetln(stdin, &size), stdin, environment);158 159 *string = *string ? realloc(*string, size) : malloc(size);160 161 strlcpy(*string, string_, size);162 }163 while (regcheck(regexec(regex, *string, 0, NULL, 0), regex, environment));164 }165 166 void setshells(Shells *shells, jmp_buf environment)167 {168 # define setshell(os) \169 { \170 char bash[sizeof (#os)] = #os; \171 \172 for (unsigned index = 0; index != sizeof (#os) - 1; ++index) \173 bash[index] = toupper(bash[index]); \174 \175 check(setenv(bash, shells->os, 1), environment); \176 }177 178 setshell(shell);179 setshell(freebsd);180 setshell(linux);181 setshell(darwin);182 setshell(solaris);183 setshell(netbsd);184 setshell(debian);185 186 # undef setshell187 }188 189 #if !defined(__FreeBSD__) && !defined(__sun__) && !defined(__APPLE__)190 size_t strlcpy(char *dst, const char *src, size_t size)191 {192 dst[size - 1] = '\0';193 194 return strlen(strncpy(dst, src, size - 1));195 }196 197 size_t strlcat(char *dst, const char *src, size_t size)198 {199 dst[size - 1] = '\0';200 201 size_t size_ = strlen(dst);202 203 return strlen(strncpy(dst + size_, src, size - size_ - 1));204 }205 206 char *fgetln(FILE * restrict stream, size_t * restrict len)207 {208 static char *line = NULL;209 static size_t size;210 211 if ((*len = getline(&line, &size, stream)) == -1)212 return NULL;213 214 return line;215 }216 #elif defined(__sun__)217 char *fgetln(FILE * restrict stream, size_t * restrict len)218 {219 static char *line = NULL;220 221 *len = 0;222 line = line ? realloc(line, 1) : malloc(1);223 224 while (line[*len] = getc(stream), line[(*len)++] != '\n')225 if (line[*len - 1] != EOF)226 line = realloc(line, *len + 1);227 else228 return NULL;229 230 return line;231 }232 233 int setenv(const char *name, const char *value, int overwrite)234 {235 char *string_ = getenv(name);236 237 if (overwrite || !string_)238 {239 char *string = malloc(strlen(name) + strlen(value) + 2);240 241 sprintf(string, "%s=%s", name, value);242 243 int value_ = putenv(string);244 245 if (!string_)246 free(string_);247 248 return value_;249 }250 251 return 0;252 }253 #endif -
admin/mysql.h
r264 r438 6 6 // $Id$ 7 7 8 #ifndef _ common_h_9 #define _ common_h_8 #ifndef _mysql_h_ 9 #define _mysql_h_ 10 10 11 #ifdef linux 12 #undef linux 13 #endif 11 #include "common.h" 14 12 15 #if !defined(__FreeBSD__) && !defined(__sun__) && !defined(__APPLE__) 16 #ifndef _BSD_SOURCE 17 #define _BSD_SOURCE 18 #endif 19 #ifndef _POSIX_SOURCE 20 #define _POSIX_SOURCE 21 #endif 22 #ifndef _GNU_SOURCE 23 #define _GNU_SOURCE 24 #endif 25 #elif defined(__sun__) 26 #define __EXTENSIONS__ 27 #endif 13 #include <assert.h> 14 #include <mysql.h> 28 15 29 #include <pwd.h> 30 #include <regex.h> 31 #include <setjmp.h> 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <string.h> 35 #include <sys/param.h> 36 #include <sys/stat.h> 37 #include <sys/wait.h> 38 #include <unistd.h> 16 #define MYSQL_EXCEPTION 3 39 17 40 # ifndef _PASSWORD_LEN41 #define _PASSWORD_LEN BUFSIZ 42 #endif 18 #define MYSQL_BEGIN() MYSQL *mysql = mysql_init(NULL); \ 19 \ 20 assert(mysql != NULL) 43 21 44 #ifndef MAXLOGNAME 45 #define MAXLOGNAME 17 46 #endif 22 #define MYSQL_END() mysql_close(mysql); \ 23 mysql_library_end() 47 24 48 extern char *exception; 25 void mysqlcheck(int value, jmp_buf environment); 26 void mysqlpassword(MYSQL *mysql, char user[MAXLOGNAME], char password[_PASSWORD_LEN], jmp_buf environment); 49 27 50 typedef struct 51 { 52 const char *shell; 53 char *freebsd, *linux, *darwin, *solaris, *netbsd, *debian; 54 } 55 Shells; 56 57 typedef enum { sh, csh, tcsh, bash, ksh, zsh, _3sh, custom } Shell; 58 59 extern Shells shells[]; 60 61 int check(int value, jmp_buf environment); 62 int regcheck(int value, const regex_t *regex, jmp_buf environment); 63 char *fcheck(char *value, FILE *stream, jmp_buf environment); 64 void authenticate(const char *program, jmp_buf environment); 65 void getpassword(char password[_PASSWORD_LEN], jmp_buf environment); 66 void putpassword(char password[_PASSWORD_LEN], char *name, jmp_buf environment); 67 void get(const char *prompt, regex_t *regex, char **string, jmp_buf environment); 68 void setshells(Shells *shells, jmp_buf environment); 69 70 #if !defined(__FreeBSD__) && !defined(__sun__) && !defined(__APPLE__) 71 size_t strlcpy(char *dst, const char *src, size_t size); 72 size_t strlcat(char *dst, const char *src, size_t size); 73 char *fgetln(FILE * restrict stream, size_t * restrict len); 74 #elif defined(__sun__) 75 char *fgetln(FILE * restrict stream, size_t * restrict len); 76 int setenv(const char *name, const char *value, int overwrite); 77 #endif 78 79 #endif//_common_h_ 28 #endif//_mysql_h_ -
admin/passwd.c
r264 r438 7 7 8 8 #include "common.h" 9 10 #ifdef _Master_ 11 #include "mysql.h" 12 #endif 9 13 10 14 int main(int argc, char *argv[]) … … 17 21 jmp_buf environment; 18 22 23 #ifdef _Master_ 24 MYSQL_BEGIN(); 25 #endif 26 19 27 switch (setjmp(environment)) 20 28 { 21 29 case 0: 22 30 break; 23 case 1:31 case POSIX_EXCEPTION: 24 32 perror(argv[0]); 25 33 26 return 1;27 default:34 goto end; 35 case STRING_EXCEPTION: 28 36 fprintf(stderr, "%s: %s\n", argv[0], exception); 37 #ifdef _Master_ 29 38 39 goto end; 40 case MYSQL_EXCEPTION: 41 fprintf(stderr, "%s: %s\n", argv[0], mysql_error(mysql)); 42 #endif 43 44 end: 45 #ifdef _Master_ 46 MYSQL_END(); 47 48 #endif 30 49 return 1; 31 50 } … … 50 69 printf("Usage %s -user=user\n", argv[0]); 51 70 52 return 1;71 goto end; 53 72 } 54 73 } … … 59 78 goto on; 60 79 else 61 longjmp(environment, (exception = "Cannot change root password", 3));80 longjmp(environment, (exception = "Cannot change root password", STRING_EXCEPTION)); 62 81 } 63 82 else if (argc != 1) … … 65 84 printf("Usage: %s\n", argv[0]); 66 85 67 return 1;86 goto end; 68 87 } 69 88 … … 71 90 72 91 if (!entry) 73 longjmp(environment, 1);92 longjmp(environment, POSIX_EXCEPTION); 74 93 75 94 strlcpy(user, entry->pw_name, sizeof (user)); … … 105 124 106 125 if (fprintf(smbpasswd, "%s\n%s\n", password, password) < 0) 107 longjmp(environment, 1);126 longjmp(environment, POSIX_EXCEPTION); 108 127 109 128 if (fclose(smbpasswd)) 110 longjmp(environment, 1);129 longjmp(environment, POSIX_EXCEPTION); 111 130 112 131 int status; … … 116 135 117 136 if (WEXITSTATUS(status)) 118 return 1; 137 goto end; 138 139 mysqlpassword(mysql, user, password, environment); 140 MYSQL_END(); 119 141 #else 120 longjmp(environment, (exception = "Log in to " MASTER " to change password", 3));142 longjmp(environment, (exception = "Log in to " MASTER " to change password", STRING_EXCEPTION)); 121 143 #endif 122 144 -
admin/secret.c
r264 r438 6 6 // $Id$ 7 7 8 #include "common.h" 9 8 10 #include <fcntl.h> 9 10 #include "common.h"11 11 12 12 int main(int argc, char *argv[]) … … 18 18 case 0: 19 19 break; 20 case 1:20 case POSIX_EXCEPTION: 21 21 perror(argv[0]); 22 22 23 23 return 1; 24 default:24 case STRING_EXCEPTION: 25 25 fprintf(stderr, "%s: %s\n", argv[0], exception); 26 26 … … 32 32 getpassword(password, environment); 33 33 34 int file = check(open( "/ccs/etc/secret", O_WRONLY | O_TRUNC), environment);34 int file = check(open(SECRET, O_WRONLY | O_TRUNC), environment); 35 35 36 36 check(write(file, password, strlen(password)), environment); -
admin/shells.c
r264 r438 6 6 // $Id$ 7 7 8 #include <stdbool.h>9 10 8 #include "common.h" 11 9 12 10 #include <assert.h> 13 11 #include <ctype.h> 12 #include <stdbool.h> 14 13 15 14 int main(int argc, char *argv[]) … … 21 20 case 0: 22 21 break; 23 case 1:22 case POSIX_EXCEPTION: 24 23 perror(argv[0]); 25 24 26 25 return 1; 27 default:26 case STRING_EXCEPTION: 28 27 fprintf(stderr, "%s: %s\n", argv[0], exception); 29 28 … … 162 161 # undef checkshells 163 162 164 longjmp(environment, (exception = "Unknown shell layout", 3));163 longjmp(environment, (exception = "Unknown shell layout", STRING_EXCEPTION)); 165 164 166 165 on: for (Shell shell = sh; shell != _3sh; ++shell) -
admin/turnin.c
r264 r438 16 16 case 0: 17 17 break; 18 case 1:18 case POSIX_EXCEPTION: 19 19 perror(argv[0]); 20 20 21 21 return 1; 22 default:22 case STRING_EXCEPTION: 23 23 fprintf(stderr, "%s: %s\n", argv[0], exception); 24 24 … … 26 26 } 27 27 28 longjmp(environment, (exception = "Um, so, yeah, I'm guessing you want to be logged in to a CSIL box.", 3));28 longjmp(environment, (exception = "Um, so, yeah, I'm guessing you want to be logged in to a CSIL box.", STRING_EXCEPTION)); 29 29 30 30 return 0; -
admin/users.h
r415 r438 91 91 "plugdev", 92 92 "polkit", 93 "polkituser", 93 94 "pop", 94 95 "portage", … … 98 99 "postmaster", 99 100 "power", 101 "powerdev", 100 102 "proxy", 103 "pulse", 101 104 "qmail", 102 105 "qmaild", … … 110 113 "rpc", 111 114 "sambashare", 115 "saned", 112 116 "sashroot", 113 117 "sasl",
