|
|
1.1 root 1: static char *sccsid = "@(#)newgrp.c 4.1 (Berkeley) 10/1/80";
2: #include <stdio.h>
3: #include <grp.h>
4: #include <pwd.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: exit(13);
18: }
19: if((grp=getgrnam(argv[1])) == NULL) {
20: printf("%s: no such group\n", argv[1]);
21: exit(13);
22: }
23: if((pwd=getpwuid(getuid())) == NULL) {
24: printf("You do not exist!\n");
25: exit(13);
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: exit(13);
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: exit(13);
39: }
40: }
41: if(setgid(grp->gr_gid) < 0) {
42: perror("setgid");
43: exit(13);
44: }
45: setuid(getuid());
46: for (i=3; i<15; i++)
47: close(i);
48: execl((pwd->pw_shell[0]?pwd->pw_shell:"/bin/sh"), "-i", 0);
49: printf("No shell!\n");
50: exit(0);
51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.