|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 1228 (0x4cc) Types: TextFile Notes: UNIX file Names: »newgrp.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─ ⟦this⟧ »cmd/newgrp.c«
/* * newgrp groupname * this is exec'd by the shell * to make it work: * chmod u+s /bin/newgrp */ #include <stdio.h> #include <grp.h> extern char **environ; main(argc,argv,envp) char **argv,**envp; { register char *unam; register int *flag; register struct group *grp; char *cp; char *crypt(),*getpass(),*getlogin(); int namect=0,inflg=0,outflg=0; environ=envp; if (argc<2) perrx("Usage: newgrp groupname"); if ((grp=getgrnam(argv[1]))==NULL) perrx("non-existent group"); unam=getlogin(); while (*grp->gr_mem!=NULL) { if (**grp->gr_mem=='!') { ++*grp->gr_mem; flag=&outflg; } else { flag=&inflg; ++namect; } if (strcmp(*grp->gr_mem,unam)==0) ++*flag; ++grp->gr_mem; } if (outflg) perrx("access explicitly denied"); if (!inflg && *grp->gr_passwd=='\0' && namect) perrx("not in access list"); if (!inflg && *grp->gr_passwd!='\0') { if ((cp=getpass("Password:"))==NULL || *cp=='\0') perrx("no"); cp=crypt(cp,grp->gr_passwd); if (strcmp(cp,grp->gr_passwd)!=0) perrx("no"); } setgid(grp->gr_gid); setuid(getuid()); execle("/bin/sh","-",NULL,environ); } perrx(s) char *s; { fprintf(stderr,"%s\n",s); setuid(getuid()); execle("/bin/sh","-",NULL,environ); }