home *** CD-ROM | disk | FTP | other *** search
- /* This is doas, a system management utillity written in 1989
- * by Aaron Sherman (asherman@dino.ulowell.edu).
- *
- * Because of the nature of doas, the following precautions
- * are recommended:
- *
- * 1. Keep it in /usr/etc
- * 2. Keep the group ownership wheel.
- * 3. Keep the protection mode 4750.
- *
- * As an extra nifty you might want to make a group, doas, for
- * this program.
- *
- * Usage: doas [user [group]] [-e prog [args]]
- *
- * To install a password, grab a password entry from the password file,
- * most likely root's, then put it in the initialization for the
- * variable 'passwd'
- */
-
-
- /*
- * BUGS:
- * on a system where argv is not NULL terminated, the exec call
- * may seg-fault. I did not bother to write the fix for this, as
- * all of the machines that I use have this feature, and you
- * can danm well fix it yourself!
- * :-) -AJS
- */
-
- #include<pwd.h>
- #include<grp.h>
- #include<stdio.h>
-
- #define STDSHELL "csh"
- #ifdef PARANOID
- #ifndef LOG_FILE
- #define LOG_FILE "/usr/adm/doas.log"
- #endif /* LOG_FILE */
- #endif
-
- /* Please do not remove the next line */
- char author[]="\nDoas, by asherman@dino.ulowell.edu\n";
-
- char *std[]={ STDSHELL,NULL };
- #ifndef DES
- char passwd[] = "foobar";
- #else
- #ifdef NO_ETCPASSWD
- char passwd[] = "HkiH4rSeJlozo";
- #else
- char *passwd;
- #endif /*ALPO*/
- #endif /*DES*/
-
- main(argc,argv)
- char **argv;
- {
- struct passwd *pwd,*getpwnam();
- struct group *grp,*getgrnam();
- int user,group;
- int pos;
- char *shell,*getenv();
- #ifdef PARANOID
- #ifdef DES
- char salt[3];
- #endif
- char *pass,*getpass();
- struct passwd *getpwuid();
- char *myname,*getlogin();
-
- if ((myname=getlogin()) == NULL)
- {
- if ((pwd=getpwuid(getuid())) != NULL)
- {
- if ((myname=pwd->pw_name) == NULL)
- noname();
- }
- else
- noname();
- }
- #endif
-
- if (setuid(0) == -1)
- {
- fprintf(stderr,"doas: Unable to setuid.\n");
- exit(1);
- }
-
- #ifdef PARANOID
- log(myname);
-
- if ((pass=getpass("Password: ")) == NULL)
- {
- fprintf(stderr,"doas: Could not get password.\n");
- exit(1);
- }
- #ifdef DES
- #ifndef NO_ETCPASSWD
- if ((pwd = getpwnam("root")) == NULL)
- {
- fprintf(stderr,"doas: No root entry!\n");
- exit(1);
- }
- passwd=pwd->pw_passwd;
- #endif
- strncpy(salt,passwd,2);
- if (strcmp(passwd,crypt(pass,salt)))
- #else
- if (strcmp(pass,passwd))
- #endif
- {
- fprintf(stderr,"Sorry...\n");
- exit(1);
- }
- #endif
-
-
- if ((shell=getenv("SHELL")) != NULL)
- std[0]=shell;
-
- group=getgid();
- pos=1;
- if (argc == 1)
- {
- user=0;group=0;
- }
- else
- {
- if (strncmp(argv[1],"-e",2))
- {
- if ((pwd=getpwnam(argv[1])) == NULL)
- user=atoi(argv[1]);
- else
- user=pwd->pw_uid;
- pos++;
- if (argc > 2)
- {
- if (strncmp(argv[2],"-e",2))
- {
- if ((grp=getgrnam(argv[2])) == NULL)
- {
- group=atoi(argv[2]);
- }
- else
- {
- group=grp->gr_gid;
- }
- pos++;
- }
- }
- }
- }
-
- if (setgid(group) == -1)
- fprintf(stderr,"doas: Group id: %d not set\n",group);
- setuid(user);
-
- pos++;
- if (argc>pos)
- {
- execvp(argv[pos],argv+pos);
- fprintf(stderr,"doas: Was not able to execute %s.\n",argv[pos]);
- }
- else
- {
- execvp(std[0],std);
- fprintf(stderr,"doas: Was not able to execute %s.\n",std[0]);
- }
- exit(1);
- }
-
-
- #ifdef PARANOID
- log(name)
- char *name;
- {
- FILE *fp,*fopen();
- long the_time;
- int uid;
-
- the_time=time(NULL);
- if ((fp=fopen(LOG_FILE,"a")) == NULL)
- {
- fprintf(stderr,"doas: Could not open log file!\n");
- exit(1);
- }
- fprintf(fp,"%s using doas at %s",name,ctime(&the_time));
- fclose(fp);
- }
-
-
- noname()
- {
- fprintf(stderr,"doas: Cannot confirm user id.\n");
- exit(1);
- }
- #endif
-