Annotation of coherent/d/bin/newgrp.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * newgrp groupname
                      3:  * this is exec'd by the shell
                      4:  * to make it work:
                      5:  *                     chmod u+s /bin/newgrp
                      6:  */
                      7: #include <stdio.h>
                      8: #include <grp.h>
                      9: 
                     10: extern char **environ;
                     11: 
                     12: main(argc,argv,envp)
                     13: char **argv,**envp;
                     14: {
                     15:        register char *unam;
                     16:        register int *flag;
                     17:        register struct group *grp;
                     18:        char *cp;
                     19:        char *crypt(),*getpass(),*getlogin();
                     20:        int namect=0,inflg=0,outflg=0;
                     21: 
                     22:        environ=envp;
                     23:        if (argc<2)
                     24:                perrx("Usage: newgrp groupname");
                     25:        if ((grp=getgrnam(argv[1]))==NULL)
                     26:                perrx("non-existent group");
                     27:        unam=getlogin();
                     28:        while (*grp->gr_mem!=NULL) {
                     29:                if (**grp->gr_mem=='!') {
                     30:                        ++*grp->gr_mem;
                     31:                        flag=&outflg;
                     32:                } else {
                     33:                        flag=&inflg;
                     34:                        ++namect;
                     35:                }
                     36:                if (strcmp(*grp->gr_mem,unam)==0)
                     37:                        ++*flag;
                     38:                ++grp->gr_mem;
                     39:        }
                     40:        if (outflg)
                     41:                perrx("access explicitly denied");
                     42:        if (!inflg && *grp->gr_passwd=='\0' && namect)
                     43:                perrx("not in access list");
                     44:        if (!inflg && *grp->gr_passwd!='\0') {
                     45:                if ((cp=getpass("Password:"))==NULL || *cp=='\0')
                     46:                        perrx("no");
                     47:                cp=crypt(cp,grp->gr_passwd);
                     48:                if (strcmp(cp,grp->gr_passwd)!=0)
                     49:                        perrx("no");
                     50:        }
                     51:        setgid(grp->gr_gid);
                     52:        setuid(getuid());
                     53:        execle("/bin/sh","-",NULL,environ);
                     54: }
                     55: 
                     56: perrx(s)
                     57: char *s;
                     58: {
                     59:        fprintf(stderr,"%s\n",s);
                     60:        setuid(getuid());
                     61:        execle("/bin/sh","-",NULL,environ);
                     62: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.