|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <grp.h> ! 3: #include <pwd.h> ! 4: #include <sys/param.h> ! 5: ! 6: struct group *getgrnam(), *grp; ! 7: struct passwd *getpwuid(), *pwd; ! 8: char *getpass(), *crypt(); ! 9: ! 10: main(argc,argv) ! 11: int argc; ! 12: char **argv; ! 13: { ! 14: register i; ! 15: if(argc != 2) { ! 16: printf("usage: newgrp groupname\n"); ! 17: done(); ! 18: } ! 19: if((grp=getgrnam(argv[1])) == NULL) { ! 20: printf("%s: no such group\n", argv[1]); ! 21: done(); ! 22: } ! 23: if((pwd=getpwuid(getuid())) == NULL) { ! 24: printf("You do not exist!\n"); ! 25: done(); ! 26: } ! 27: for(i=0;grp->gr_mem[i];i++) ! 28: if(strcmp(grp->gr_mem[i], pwd->pw_name) == 0) ! 29: break; ! 30: if(grp->gr_mem[i] == 0 && strcmp(grp->gr_name,"other")) { ! 31: printf("Sorry\n"); ! 32: done(); ! 33: } ! 34: ! 35: if(grp->gr_passwd[0] != '\0' && pwd->pw_passwd[0] == '\0') { ! 36: if(strcmp(grp->gr_passwd, crypt(getpass("Password:"),grp->gr_passwd)) != 0) { ! 37: printf("Sorry\n"); ! 38: done(); ! 39: } ! 40: } ! 41: if(setgid(grp->gr_gid) < 0) ! 42: perror("setgid"); ! 43: done(); ! 44: } ! 45: ! 46: done() ! 47: { ! 48: register i; ! 49: ! 50: setuid(getuid()); ! 51: for (i=NSYSFILE; i<NOFILE; i++) ! 52: close(i); ! 53: execl(((pwd && pwd->pw_shell[0])? pwd->pw_shell: "/bin/sh"), "sh", 0); ! 54: printf("No shell!\n"); ! 55: exit(0); ! 56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.