This is chsh.c in view mode; [Download] [Up]
// // This code written by Jason Fosback // Copyright (C) 1993 Jason Fosback, All Rights Reserved // // #include <stdio.h> #include <libc.h> #include <strings.h> #include <pwd.h> int main(int argc, char *argv[]) { int index = 0; int selectedIndex = 0; char answer[256]; char command[(MAXPATHLEN*2)+2]; char user[10]; char c; struct passwd *pass; char shells[128][MAXPATHLEN+1]; FILE *shellFile; while(1) { pass = (struct passwd *)getpwuid(getuid()); if (pass == (struct passwd *)EOF) { printf("You aren't a user! Intruder alert!\n"); exit(1); } strcpy(user,pass->pw_name); printf("Current shell for %s: %s\n",user,pass->pw_shell); endpwent(); shellFile = fopen("/etc/shells","r"); if (shellFile == NULL) { printf("Error accessing /etc/shells!\n"); exit(1); } printf("Available shells:\n"); while(fgets(shells[index], MAXPATHLEN, shellFile) != NULL) { c = shells[index][0]; if (c == '\n' || c == '#' || c == '\0') { continue; } printf(" %d) %s", index+1, shells[index]); index++; } fclose(shellFile); printf("Please select a shell: "); gets(answer); sscanf(answer, "%d", &selectedIndex); if (selectedIndex < 1 || selectedIndex > index) { printf("Error: invalid selection.\n"); index = 0; exit(1); } break; } sprintf(command,"niutil -createprop . /users/%s shell %s", user, shells[selectedIndex-1]); // printf("%s\n",command); if (system(command)) { printf("Error changing shell.\n"); exit(1); } printf("Shell changed to %s", shells[selectedIndex-1]); printf("This change will take effect the next time you log in.\n"); exit(0); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.