[net.bugs.4bsd] 4.3 vipw does not allow root to have a shell in /etc/shells

arnold@emory.UUCP (Arnold D. Robbins {EUCC}) (10/23/86)

Subject: 4.3 vipw does not allow root to have a shell in /etc/shells
Index:	/usr/src/etc/vipw.c 4.3BSD

Description:
	/* fall through ... */
Repeat-By:
	Edit the password file with vipw, and try to change root's shell
	to a shell listed in /etc/shells, but not /bin/sh or /bin/csh,
	(e.g., /bin/ksh). Watch vipw complain about mangling the password
	file.
Fix:

RCS file: RCS/vipw.c,v
retrieving revision 1.1
diff -c -r1.1 vipw.c
*** /tmp/,RCSt1007105	Wed Oct 22 18:02:04 1986
--- vipw.c	Thu Aug  7 15:01:37 1986
***************
*** 1,9 ****
  #ifndef lint
! static char *RCSid = "$Header: vipw.c,v 1.1 86/08/06 17:47:40 root Exp $";
  #endif
  
  /*
   * $Log:	vipw.c,v $
   * Revision 1.1  86/08/06  17:47:40  root
   * Initial revision
   * 
--- 1,15 ----
  #ifndef lint
! static char *RCSid = "$Header: vipw.c,v 1.3 86/08/07 15:01:19 root Locked $";
  #endif
  
  /*
   * $Log:	vipw.c,v $
+  * Revision 1.3  86/08/07  15:01:19  root
+  * Made error message more descriptive for invalid root entry. ADR.
+  * 
+  * Revision 1.2  86/08/06  17:56:44  root
+  * fixed to check root's shell against list of valid shells.
+  * 
   * Revision 1.1  86/08/06  17:47:40  root
   * Initial revision
   * 
***************
*** 140,147 ****
  			if (strncmp(++cp, "/:", 2))
  				break;
  			cp += 2;
! 			if (*cp && strcmp(cp, "/bin/sh") &&
! 			    strcmp(cp, "/bin/csh"))
  				break;
  			ok++;
  		}
--- 146,152 ----
  			if (strncmp(++cp, "/:", 2))
  				break;
  			cp += 2;
! 			if (*cp && ! validsh (cp))
  				break;
  			ok++;
  		}
***************
*** 153,162 ****
  				exit(0);
  		} else
  			fprintf(stderr,
! 			    "vipw: you mangled the temp file, %s unchanged\n",
  			    passwd);
  	}
  bad:
  	unlink(temp);
  	exit(1);
  }
--- 158,186 ----
  				exit(0);
  		} else
  			fprintf(stderr,
! 		"vipw: there are problems with root's entry, %s unchanged\n",
  			    passwd);
  	}
  bad:
  	unlink(temp);
  	exit(1);
+ }
+ 
+ int validsh (rootsh)
+ char *rootsh;
+ {
+ 	char *sh, *getusershell ();
+ 	int ret = 0;
+ 
+ 	while ((sh = getusershell ()) != NULL)
+ 	{
+ 		if (strcmp (sh, rootsh) == 0)
+ 		{
+ 			ret = 1;
+ 			break;
+ 		}
+ 	}
+ 
+ 	endusershell ();
+ 	return (ret);
  }
-- 
Arnold Robbins
CSNET:	arnold@emory	BITNET:	arnold@emoryu1
ARPA:	arnold%emory.csnet@csnet-relay.arpa
UUCP:	{ akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold