[comp.sources.bugs] Patch for Gone2.0

stjohn@oswego.Oswego.EDU (Dave St. John) (04/11/89)

I experienced problems with selecting arguments for gone. I couldn't get any
of the arguments to work. I traced the problem to the signal code and the fact
that under Ultrix 3.0 it was skipping right over argument check. The reason why
I haven't discovered yet. I have moved the argument check above the signal code
and it now works under Ultrix. Since I wanted to have timeout enabled for some
users and not others I have added an EXEMPTGROUP which allows for some people
to be timed out and others not. Also when TIMEOUT is undef'd there were some
extra timeouttime that weren't ifdef'd that have been fixed.

Dave St. John

---------------------------------------------------------------------------
UUCP:		{your favorite backbone}!oswego!stjohn
INTERNET:	stjohn@oswego.oswego.edu 	(129.3.1.1)

US Mail:	Dave St. John				
    		Instructional Computing Center		
	    	SUNY College at Oswego			
		Oswego, N.Y. 13126

Armadillo: to provide weapons to Spanish pickles
---------------------------------------------------------------------------

-----cut here---------------------cut here----------------cut here---------

*** gone.c.orig	Mon Apr 10 21:23:06 1989
--- gone.c	Mon Apr 10 20:52:37 1989
***************
*** 82,94
  char *validate();		/** Is this password valid?	         **/
  
  struct unode {                  /** In here goes the encrypted passwords **/
    char name[81];                /**  of all the people in WIZGROUP.      **/
    char passwd[20];              /** Faster this way, instead of scanning **/
    struct unode *next;           /**  the whole password file each time   **/
! } *wizusers = NULL;             /**  a password is typed in.             **/
  
  #ifdef UENT			/** Local: We store names and ss#'s for  **/
  struct uent muent;		/**   each person.			 **/
  #endif
  
  #ifdef TIMEOUT

--- 82,94 -----
  char *validate();		/** Is this password valid?	         **/
  
  struct unode {                  /** In here goes the encrypted passwords **/
    char name[81];                /**  of all the people in WIZGROUP.      **/
    char passwd[20];              /** Faster this way, instead of scanning **/
    struct unode *next;           /**  the whole password file each time   **/
! } *wizusers, *exemptusers;       /**  a password is typed in.             **/
  
  #ifdef UENT			/** Local: We store names and ss#'s for  **/
  struct uent muent;		/**   each person.			 **/
  #endif
  
  #ifdef TIMEOUT
***************
*** 109,120
    register i = 1;
    int intprint();
    char *obuf = (char *) malloc (80L*25L);/** stdout buffer/one full screen**/
    char *term = getenv("TERM");		 /** Terminal type                **/
    char *liberator = NULL;		 /** Who liberated this terminal? **/
  
    for (i = SIGHUP; i <= SIGUSR2; i++)
      signal(i, intprint);
  
    (void) signal(SIGINT, SIG_IGN);
    (void) signal(SIGQUIT, SIG_IGN);
  #ifdef SIGTSTP	/** Some sysVers don't have job control. **/

--- 109,174 -----
    register i = 1;
    int intprint();
    char *obuf = (char *) malloc (80L*25L);/** stdout buffer/one full screen**/
    char *term = getenv("TERM");		 /** Terminal type                **/
    char *liberator = NULL;		 /** Who liberated this terminal? **/
  
+   if (exemptuser())
+     timeouttime = 0;
+ 
+   while ((i <= argc-1) && (argv[i++][0] == '-')) {
+     switch (argv[i-1][1]) {
+     case 'p': 
+       ++pflag;
+       break;
+ #ifdef TIMEOUT
+     case 't':
+       timeouttime = atoi(argv[i++]);
+       break;
+ #endif
+     case 'd': 
+       ++dflag;
+       break;
+     case 'c': { /** Change the password in the ~/.passwd file or create one **/
+       struct passwd *pwd;
+       FILE *pwdfile;
+       char path[80], *chpasswd();
+       char oldpw[12], newpw[12];
+       
+       if ((pwd = getpwuid(getuid())) == NULL) {
+         printf("Intruder alert!?\n");
+         printf("Your account appears to be GONE.\n");
+         exit(1);
+       }
+       sprintf(path, "%s/.passwd", pwd->pw_dir);
+       if ((pwdfile = fopen(path, "r")) == NULL) {
+         strcpy(oldpw, "");
+       } else {
+         fscanf(pwdfile, "%s", oldpw);
+         fclose(pwdfile);
+       }
+ 
+       strcpy(newpw, chpasswd(oldpw));
+       sprintf(path, "%s/.passwd", pwd->pw_dir);
+       if ((pwdfile = fopen(path, "w+")) == NULL) {
+         fprintf(stderr, 
+                 "cannot change passwd, open of .passwd file failed.\n");
+         perror(path);
+         exit(1);
+       }
+       fprintf(pwdfile, "%s\n", newpw);
+       fclose(pwdfile);
+       exit(1);
+     }
+     default: 
+       fprintf(stderr, "%s:  Can\'t grok a %c\n", argv[0], argv[i-1][1]);
+       sleep (1);
+       break;
+     }
+   }
+ 
    for (i = SIGHUP; i <= SIGUSR2; i++)
      signal(i, intprint);
  
    (void) signal(SIGINT, SIG_IGN);
    (void) signal(SIGQUIT, SIG_IGN);
  #ifdef SIGTSTP	/** Some sysVers don't have job control. **/
***************
*** 125,137
  #endif
    (void) signal(SIGTERM, die);
    (void) signal(SIGCHLD, SIG_DFL);
  #ifdef TIMEOUT
    (void) signal(SIGALRM, timeout);
  #endif
!   
    if (!isatty(0)) {  			 /** pipes?  ICK                   **/
       fprintf(stderr, 
         "%s: Without a terminal?  What\'s the point\?\n", argv[0]);
       exit(-1);
    } else if (!strcmp(term, "emacs")) { 	/** In emacs window 		   **/
       fprintf(stderr,			/** I guess we get all types       **/

--- 179,192 -----
  #endif
    (void) signal(SIGTERM, die);
    (void) signal(SIGCHLD, SIG_DFL);
  #ifdef TIMEOUT
    (void) signal(SIGALRM, timeout);
  #endif
! 
! 
    if (!isatty(0)) {  			 /** pipes?  ICK                   **/
       fprintf(stderr, 
         "%s: Without a terminal?  What\'s the point\?\n", argv[0]);
       exit(-1);
    } else if (!strcmp(term, "emacs")) { 	/** In emacs window 		   **/
       fprintf(stderr,			/** I guess we get all types       **/
***************
*** 168,184
  #endif
  
  #ifdef UENT
    muent = getuent(getuid());
  #endif
  
-   while ((i <= argc-1) && (argv[i++][0] == '-')) {
-     switch (argv[i-1][1]) {
-     case 'p': 
-       ++pflag;
-       break;
  #ifdef TIMEOUT
      case 't':
        timeouttime = atoi(argv[i++]);
        break;
  #endif
      case 'd': 

--- 223,234 -----
  #endif
  
  #ifdef UENT
    muent = getuent(getuid());
  #endif
  
  #ifdef TIMEOUT
    if (!wizuser())
      if (timeouttime > MAXTIMEOUT) {
        timeouttime = MAXTIMEOUT;
        fprintf(stderr, "Maximum time out is %d.\n", MAXTIMEOUT);
        fprintf(stderr, "You request has been degraded to that amount.\n");
***************
*** 174,230
    while ((i <= argc-1) && (argv[i++][0] == '-')) {
      switch (argv[i-1][1]) {
      case 'p': 
        ++pflag;
        break;
  #ifdef TIMEOUT
-     case 't':
-       timeouttime = atoi(argv[i++]);
-       break;
- #endif
-     case 'd': 
-       ++dflag;
-       break;
-     case 'c': { /** Change the password in the ~/.passwd file or create one **/
-       struct passwd *pwd;
-       FILE *pwdfile;
-       char path[80], *chpasswd();
-       char oldpw[12], newpw[12];
-       
-       if ((pwd = getpwuid(getuid())) == NULL) {
- 	printf("Intruder alert!?\n");
- 	printf("Your account appears to be GONE.\n");
- 	exit(1);
-       }
-       sprintf(path, "%s/.passwd", pwd->pw_dir);
-       if ((pwdfile = fopen(path, "r")) == NULL) {
- 	strcpy(oldpw, "");
-       } else {
- 	fscanf(pwdfile, "%s", oldpw);
- 	fclose(pwdfile);
-       }
- 
-       strcpy(newpw, chpasswd(oldpw));
-       sprintf(path, "%s/.passwd", pwd->pw_dir);
-       if ((pwdfile = fopen(path, "w+")) == NULL) {
- 	fprintf(stderr, 
- 		"cannot change passwd, open of .passwd file failed.\n");
- 	perror(path);
- 	exit(1);
-       }
-       fprintf(pwdfile, "%s\n", newpw);
-       fclose(pwdfile);
-       exit(1);
-       }
-     default: 
-       fprintf(stderr, "%s:  Can\'t grok a %c\n", argv[0], argv[i-1][1]);
-       sleep (1);
-       break;
-     }
-   }
- #ifdef TIMEOUT
    if (!wizuser())
      if (timeouttime > MAXTIMEOUT) {
        timeouttime = MAXTIMEOUT;
        fprintf(stderr, "Maximum time out is %d.\n", MAXTIMEOUT);
        fprintf(stderr, "You request has been degraded to that amount.\n");
      } else 

--- 224,235 -----
  
  #ifdef UENT
    muent = getuent(getuid());
  #endif
  
  #ifdef TIMEOUT
    if (!wizuser())
      if (timeouttime > MAXTIMEOUT) {
        timeouttime = MAXTIMEOUT;
        fprintf(stderr, "Maximum time out is %d.\n", MAXTIMEOUT);
        fprintf(stderr, "You request has been degraded to that amount.\n");
      } else 
***************
*** 346,358
      printf("\n");
    } else {
      printf("\nWelcome, %s, to this account%s.\n", liberator,
  	   foo ? ", Oh Mighty Wizard" : "");
      if (invalid)
        printf("There were %d invalid before this sucessful one.\n", invalid);
! }
  
  #ifndef dgux
    restore_utmp();
  #endif
    
    if (!dumb)

--- 351,363 -----
      printf("\n");
    } else {
      printf("\nWelcome, %s, to this account%s.\n", liberator,
  	   foo ? ", Oh Mighty Wizard" : "");
      if (invalid)
        printf("There were %d invalid before this sucessful one.\n", invalid);
!   }
  
  #ifndef dgux
    restore_utmp();
  #endif
    
    if (!dumb)
***************
*** 360,372
  
    fflush (stdout);
  }
  
  dodate () 
  {
- #ifdef TIMEOUT
    long foo[2];
  #endif
  #ifdef dgux
    char *obuf = (char *) malloc(80*5);
  #endif
    char *tty = ttyname(0);

--- 365,376 -----
  
    fflush (stdout);
  }
  
  dodate () 
  {
    long foo[2];
  #ifdef dgux
    char *obuf = (char *) malloc(80*5);
  #endif
    char *tty = ttyname(0);
    int count = 0, update();
***************
*** 362,374
  }
  
  dodate () 
  {
  #ifdef TIMEOUT
    long foo[2];
- #endif
  #ifdef dgux
    char *obuf = (char *) malloc(80*5);
  #endif
    char *tty = ttyname(0);
    int count = 0, update();
  

--- 366,377 -----
    fflush (stdout);
  }
  
  dodate () 
  {
    long foo[2];
  #ifdef dgux
    char *obuf = (char *) malloc(80*5);
  #endif
    char *tty = ttyname(0);
    int count = 0, update();
  
***************
*** 383,394
  #endif
  
  #ifdef dgux
    setbuf(stdout, obuf);
  #endif
  
    if (timeouttime)
      --timeouttime;
  
    nice(10);
    signal (SIGTERM, die);
    for (;;) {

--- 386,398 -----
  #endif
  
  #ifdef dgux
    setbuf(stdout, obuf);
  #endif
  
+ #ifdef TIMEOUT
    if (timeouttime)
      --timeouttime;
  #endif
  
    nice(10);
    signal (SIGTERM, die);
***************
*** 385,396
  #ifdef dgux
    setbuf(stdout, obuf);
  #endif
  
    if (timeouttime)
      --timeouttime;
  
    nice(10);
    signal (SIGTERM, die);
    for (;;) {
      if (pflag) {                  /* Touch the terminal every soo often */
        foo[0] = foo[1] = time(0);

--- 389,401 -----
    setbuf(stdout, obuf);
  #endif
  
  #ifdef TIMEOUT
    if (timeouttime)
      --timeouttime;
+ #endif
  
    nice(10);
    signal (SIGTERM, die);
    for (;;) {
      if (pflag) {                  /* Touch the terminal every soo often */
        foo[0] = foo[1] = time(0);
***************
*** 397,409
        utime(tty, foo);
      }
      if (++count > 5) {
        count = 0;
        do_screen();
      }
!     
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  

--- 402,415 -----
        utime(tty, foo);
      }
      if (++count > 5) {
        count = 0;
        do_screen();
      }
! 
! #ifdef TIMEOUT    
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  #endif
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
***************
*** 400,411
        count = 0;
        do_screen();
      }
      
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);

--- 406,418 -----
        do_screen();
      }
  
  #ifdef TIMEOUT    
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
+ #endif
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);
***************
*** 406,417
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);
      if (timeouttime)
        --timeouttime;
    }
  }
  die () {
    exit (1);

--- 413,425 -----
  
  	/** Have to put all this in one printf for DG/UX **/
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);
+ #ifdef TIMEOUT
      if (timeouttime)
        --timeouttime;
  #endif
    }
  }
  die () {
***************
*** 408,419
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);
      if (timeouttime)
        --timeouttime;
    }
  }
  die () {
    exit (1);
  }
  update () {

--- 416,428 -----
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      sleep (60);
  #ifdef TIMEOUT
      if (timeouttime)
        --timeouttime;
+ #endif
    }
  }
  die () {
    exit (1);
  }
  update () {
***************
*** 414,425
    }
  }
  die () {
    exit (1);
  }
  update () {
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/

--- 423,435 -----
    }
  }
  die () {
    exit (1);
  }
  update () {
+ #ifdef TIMEOUT
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  #endif
  
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
***************
*** 416,427
  die () {
    exit (1);
  }
  update () {
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
  
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      signal(SIGHUP, update);
  }

--- 426,438 -----
    exit (1);
  }
  update () {
  #ifdef TIMEOUT
      if (timeouttime)
        printf("\033[17;25HTimeout in \033[1m%d\033[0m minutes.", timeouttime);
+ #endif
  
      printf ("\033[22;24Hload: %.2f, and %d users.\033[K\033[23;18HStarted up at %26s\033[20;37H", load(), users(), ctime(&startup_time));
  
      fflush (stdout);      /** Moves cursor to Password: prompt **/
      signal(SIGHUP, update);
  }
***************
*** 744,758
    if (gr == NULL) return(0);             /* groups does not exist      */
  
    for (i = 0; gr->gr_mem[i] != NULL; i++)/* loop through each member   */
      if (!strcmp(gr->gr_mem[i], logname)) /* is he a valid member?      */
        return(1);                         /* user looks okay to me      */
  #endif
!   /** Or if we are the author, then we are a wiz user **/
!   if (!strcmp(logname, "lavallee")) 
!     return(1);
  
    return(0);                             /* Not found                  */
  }
  
  /** Change the guys passwd from the ~/.passwd file...  We return the new
   ** crypted password if successful... NULL elsewise...  old is the

--- 755,785 -----
    if (gr == NULL) return(0);             /* groups does not exist      */
  
    for (i = 0; gr->gr_mem[i] != NULL; i++)/* loop through each member   */
      if (!strcmp(gr->gr_mem[i], logname)) /* is he a valid member?      */
        return(1);                         /* user looks okay to me      */
  #endif
! 
!   return(0);                             /* Not found                  */
! }
! 
! int exemptuser() 
! {
! #ifdef EXEMPTGROUP
!   register i;			         /* index                      */
!   char *group = EXEMPTGROUP;	 /* The name of the group      */
!   struct group *gr;		         /* group file entry           */
!   char *logname = (char *) getlogin ();  /* login name of caller       */
!   gr = getgrnam(group);                  /* get id of authorized group */
! 
!   if (gr == NULL) return(0);             /* groups does not exist      */
! 
!   for (i = 0; gr->gr_mem[i] != NULL; i++)/* loop through each member   */
!     if (!strcmp(gr->gr_mem[i], logname)) /* is he a valid member?      */
!       return(1);                         /* user looks okay to me      */
! #endif
  
    return(0);                             /* Not found                  */
  }
  
  /** Change the guys passwd from the ~/.passwd file...  We return the new
   ** crypted password if successful... NULL elsewise...  old is the
*** conf.h.orig	Mon Apr 10 17:08:14 1989
--- conf.h	Mon Apr 10 20:45:47 1989
***************
*** 14,26
  #undef HOSTNAME			/** define this to you hostname if
  				 **  you don't have gethostname(2)
  				 **/
  
  /**         You may undefine this if you don't want it                 **/
  
! #define WIZGROUP "wheel"    /** Magic group:
                                * If you type in the password of someone
  			      * in this group, you will get out.
  			      *
  			      * I think this is better than having a
  			      * global password like "hasta la vista"
  			      * like some locks have.

--- 14,26 -----
  #undef HOSTNAME			/** define this to you hostname if
  				 **  you don't have gethostname(2)
  				 **/
  
  /**         You may undefine this if you don't want it                 **/
  
! #define WIZGROUP "sys"    /** Magic group:
                                * If you type in the password of someone
  			      * in this group, you will get out.
  			      *
  			      * I think this is better than having a
  			      * global password like "hasta la vista"
  			      * like some locks have.
***************
*** 22,32
  			      * in this group, you will get out.
  			      *
  			      * I think this is better than having a
  			      * global password like "hasta la vista"
  			      * like some locks have.
  			     **/
  
  /** #define FCRYPT **/	     /** define if you are useing fcrypt **/
  
  #define __CONF__
  #endif

--- 22,35 -----
  			      * in this group, you will get out.
  			      *
  			      * I think this is better than having a
  			      * global password like "hasta la vista"
  			      * like some locks have.
  			     **/
+ 
+ #define EXEMPTGROUP "staff"   /** Exempt group:
+                                 * if in this group TIMEOUT is not used **/
  
  /** #define FCRYPT **/	     /** define if you are useing fcrypt **/
  
  #define __CONF__
  #endif