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