forrie@morwyn.UUCP (Forrie Aldrich) (05/17/91)
I noticed that Boyd Ostroff posted the WLOGIN program again, so I thought I would again ask the net to look at this interesting bug that I find with it. I don't know which software is at fault really, but whenever I use the Wlogin program, other programs such as the Phone Manager don't work right. Another program that won't work right is the program by Lenny Tropiano called 'sudo'. The Phone Manager tells me that I have to log in to use the phone manager -- a way around THIS is to make sure that the window YOU log into is on /dev/w1, but that seems rather foolish (and possibly a bug with /etc/ph). With Sudo, it simply will not recognize me as an authorized user in su.allow. It apparently thinks my name is 'wlogin' and not 'forrie'. This is really weird, and I'd like to figure out why this computer acts as such. I have had similar problems with programs that attempt to act as a login interface on this machine (as per my previous postings). For experimentation, attached is a copy of 'sudo.c'. It isn't long and is fairly simple. I thought it to be a good tool for others to experiment with in conjunction with wlogin. I'd like to see what others have for results. Forrie ----------cut here-------------------------------------------------- /*********************************************************************** * Program Name: sudo * Author: Lenny Tropiano * (c)1986 ICUS Computer Group * Date: December 20, 1986 * * * Will check /usr/adm/su.allow for your logname and * will give you "root" permissions for a given command on line. * **********************************************************************/ #include <stdio.h> #include <time.h> extern char **environ; main(argc,argv,envp) int argc; char *argv[]; char *envp[]; { FILE *fp, *logfp; register int i, x; short rootid; struct tm *today; long *clock, tresult; char username[L_cuserid + 1], buffer[L_cuserid + 1], tty[L_ctermid + 1]; char runprog[25], program[25], *fgets(), *ttyname(), *getlogin(); tresult = time((long *) 0); clock = &tresult; today = localtime(clock); today->tm_mon++; if (argc < 2) { fprintf(stderr,"Usage: %s [-r] command\n",argv[0]); exit(1); } if (strncmp(argv[1],"-r",2) == 0) { if (argc < 3) { fprintf(stderr,"Usage: %s [-r] command\n",argv[0]); exit(1); } rootid = 1; } else rootid = 0; if ((logfp = fopen("/usr/adm/sulog","a")) == NULL) { fprintf(stderr,"error: cannot open /usr/adm/sulog file\n"); perror("sudo"); exit(1); } if ((fp = fopen("/usr/adm/su.allow","r")) == NULL) { fprintf(stderr,"error: cannot open /usr/adm/su.allow file\n"); perror("sudo"); exit(1); } x=0; for (i=(rootid + 1);i<argc+1;i++) argv[x++] = argv[i]; sscanf(ttyname(0),"%*c%*c%*c%*c%*c%s", tty); sprintf(username,"%s",getlogin()); while (fgets(buffer,L_cuserid,fp) != NULL) { if (strncmp(buffer,username,strlen(username)) == 0) { fprintf(logfp,"SUDO %.2d/%.2d %.2d:%.2d + %s %s %c(%s)\n", today->tm_mon, today->tm_mday, today->tm_hour, today->tm_min, tty, username, (!rootid) ? ' ' : '*', argv[0]); fclose(logfp); fclose(fp); sprintf(program,"(sudo) %s",argv[0]); sprintf(runprog,"%s",argv[0]); if (rootid) { setuid(0); setgid(1); } argv[0] = program; execvp(runprog,argv); perror("sudo"); exit(1); } /* End if */ } /* End while */ fprintf(logfp,"SUDO %.2d/%.2d %.2d:%.2d - %s %s %c(%s)\n", today->tm_mon, today->tm_mday, today->tm_hour, today->tm_min, tty, username, (!rootid) ? ' ' : '*', argv[0]); fclose(logfp); fprintf(stderr,"sudo: Sorry.\n"); fclose(fp); exit(0); } /* End main() */ ---------cut here------------------------------------------------------ -- --------------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-------------------- Forrest Aldrich, Jr.| ...uunet!eci!morwyn!forrie |forrie@morywn.UUCP | ...uunet!eci!zinn!morwyn!forrie | CREATIVE CONNECTIONS|...uunet!unhd!unhtel!morwyn!forrie |Graphic Illustration ------------------\-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-/------------------ \___ PO Box 1541 - Dover, NH 03820 ___/