Shadow Login Suite, patch 3

John F Haugh II jfh at rpp386.cactus.org
Fri Jun 7 01:06:34 AEST 1991


Chip Rosenthal has provided me with a large collection of fixes for the
code, and many of them are included here.  I've been working on implementing
the SVR4 "useradd" and "userdel" command, and some of these changes were
required to support those commands.  Patch 4 will include useradd, usermod
and userdel, as well as the documentation for those three commands.  I will
probably do groupadd, groupmod and groupdel for Patch 5 or 6.

There is someone down under working on a port to SunOS and I expect those
changes to show up in the next patch or two.
--
Changes -

dialup.c 3.4
made code more robust, added support for shell name default to "*"

utmp.c 3.7
fixed strncmp and strncpy calls in BSD part of an ifdef

README 3.3
added DBM and SYSLOG comments

Makefile 3.10
fixed lint flags to get around command bug

config.h 3.7
removed NOBLANK option.

passwd.c 3.3
don't need to print CHANGING message with -S flag

sgroupio.c 3.3
fixed misspelt function calls

gshadow.c 3.4
fixed bugs with variable names

pwdbm.c 3.5
added pw_dbm_remove function

spdbm.c 3.2
added sp_dbm_remove function

gpmain.c 3.6
list addition/deletion had bugs

*** rel3/dialup.c	Thu May 30 07:02:56 1991
--- dialup.c	Tue Jun  4 08:15:10 1991
***************
*** 1,5 ****
  /*
!  * Copyright 1989, 1990, John F. Haugh II
   * All rights reserved.
   *
   * Permission is granted to copy and create derivative works for any
--- 1,5 ----
  /*
!  * Copyright 1989, 1990, 1991, John F. Haugh II
   * All rights reserved.
   *
   * Permission is granted to copy and create derivative works for any
***************
*** 20,26 ****
  #include "dialup.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)dialup.c	3.3	19:44:20	12/10/90";
  #endif
  
  static	FILE	*dialpwd;
--- 20,26 ----
  #include "dialup.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)dialup.c	3.4	07:58:44	5/30/91";
  #endif
  
  static	FILE	*dialpwd;
***************
*** 48,57 ****
  FILE	*fp;
  {
  	static	struct	dialup	dialup;	/* static structure to point to */
! 	static	char	shell[64];	/* some space for a login shell */
! 	static	char	passwd[16];	/* some space for dialup password */
  	char	buf[BUFSIZ];
  	char	*cp;
  
  	if (! fp)
  		return 0;
--- 48,58 ----
  FILE	*fp;
  {
  	static	struct	dialup	dialup;	/* static structure to point to */
! 	static	char	shell[128];	/* some space for a login shell */
! 	static	char	passwd[128];	/* some space for dialup password */
  	char	buf[BUFSIZ];
  	char	*cp;
+ 	char	*cp2;
  
  	if (! fp)
  		return 0;
***************
*** 65,84 ****
  	if (feof (fp))
  		return ((struct dialup *) 0);
  
! 	cp = strchr (buf, ':');
  	if (cp - buf > sizeof shell)	/* something is fishy ... */
  		return ((struct dialup *) 0);
  
! 	(void) strncpy (shell, buf, cp - buf);
  	shell[cp - buf] = '\0';
  
! 	if (strlen (cp + 1) > sizeof passwd) /* something is REALLY fishy */
  		return ((struct dialup *) 0);
  
! 	(void) strcpy (passwd, cp + 1);
! 	passwd[strlen (passwd) - 1] = '\0';
! 	if (cp = strchr (passwd, ':'))
! 		*cp = '\0';
  
  	dialup.du_shell = shell;
  	dialup.du_passwd = passwd;
--- 66,88 ----
  	if (feof (fp))
  		return ((struct dialup *) 0);
  
! 	if (! (cp = strchr (buf, ':')))
! 		return ((struct dialup *) 0);
! 
  	if (cp - buf > sizeof shell)	/* something is fishy ... */
  		return ((struct dialup *) 0);
  
! 	*cp++ = '\0';
! 	(void) strcpy (shell, buf);
  	shell[cp - buf] = '\0';
  
! 	if (cp2 = strchr (cp, ':'))
! 		*cp2 = '\0';
! 
! 	if (strlen (cp) + 1 > sizeof passwd) /* something is REALLY fishy */
  		return ((struct dialup *) 0);
  
! 	(void) strcpy (passwd, cp);
  
  	dialup.du_shell = shell;
  	dialup.du_passwd = passwd;
*** rel3/utmp.c	Thu May 30 07:04:51 1991
--- utmp.c	Thu Jun  6 09:32:47 1991
***************
*** 25,44 ****
  #include "config.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)utmp.c	3.4	09:08:23	5/28/91";
  #endif
  
  extern	struct	utmp	utent;
- extern	char	name[];
  
  extern	struct	utmp	*getutent();
  extern	void	setutent();
  extern	void	endutent();
  extern	time_t	time();
  extern	char	*ttyname();
  
  #define	NO_UTENT \
  	"No utmp entry.  You must exec \"login\" from the lowest level \"sh\""
  
  /*
   * checkutmp - see if utmp file is correct for this process
--- 25,47 ----
  #include "config.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)utmp.c	3.7	09:49:56	6/5/91";
  #endif
  
  extern	struct	utmp	utent;
  
  extern	struct	utmp	*getutent();
+ extern	struct	utmp	*getutline();
  extern	void	setutent();
  extern	void	endutent();
  extern	time_t	time();
  extern	char	*ttyname();
+ extern	long	lseek();
  
  #define	NO_UTENT \
  	"No utmp entry.  You must exec \"login\" from the lowest level \"sh\""
+ #define	NO_TTY \
+ 	"Unable to determine your tty name."
  
  /*
   * checkutmp - see if utmp file is correct for this process
***************
*** 47,52 ****
--- 50,60 ----
   *	and requires that a slot for the current process exist.
   *	The utmp file is scanned for an entry with the same process
   *	ID.  If no entry exists the process exits with a message.
+  *
+  *	The "picky" flag is for network and other logins that may
+  *	use special flags.  It allows the pid checks to be overridden.
+  *	This means that getty should never invoke login with any
+  *	command line flags.
   */
  
  void
***************
*** 53,65 ****
  checkutmp (picky)
  int	picky;
  {
- 	struct	utmp	*ut;
  	char	*line;
  #ifndef	NDEBUG
  	int	pid = getppid ();
  #else
  	int	pid = getpid ();
  #endif
  	setutent ();
  
  #ifndef	BSD
--- 61,75 ----
  checkutmp (picky)
  int	picky;
  {
  	char	*line;
+ #ifdef	USG
+ 	struct	utmp	*ut;
  #ifndef	NDEBUG
  	int	pid = getppid ();
  #else
  	int	pid = getpid ();
  #endif
+ #endif
  	setutent ();
  
  #ifndef	BSD
***************
*** 76,98 ****
  		if (ut && utent.ut_pid == pid)
  			return;
  
! 		puts (NO_UTENT);
  		exit (1);
  	} else {
! 		line = ttyname (0);
  		if (strncmp (line, "/dev/", 5) == 0)
  			line += 5;
  
! 		strncpy (utent.ut_line, line, sizeof utent.ut_line);
  		if (ut = getutline (&utent))
! 			strncpy (utent.ut_id, ut->ut_id, sizeof ut->ut_id);
  
! 		strcpy (utent.ut_user, "LOGIN");
  		utent.ut_pid = getpid ();
  		utent.ut_type = LOGIN_PROCESS;
! 		time (&utent.ut_time);
  	}
  #endif
  }
  
  /*
--- 86,126 ----
  		if (ut && utent.ut_pid == pid)
  			return;
  
! 		(void) puts (NO_UTENT);
  		exit (1);
  	} else {
! 		if (! (line = ttyname (0))) {
! 			(void) puts (NO_TTY);
! 			exit (1);
! 		}
  		if (strncmp (line, "/dev/", 5) == 0)
  			line += 5;
  
! 		(void) strncpy (utent.ut_line, line,
! 				(int) sizeof utent.ut_line);
  		if (ut = getutline (&utent))
! 			(void) strncpy (utent.ut_id, ut->ut_id,
! 					(int) sizeof ut->ut_id);
  
! 		(void) strcpy (utent.ut_user, "LOGIN");
  		utent.ut_pid = getpid ();
  		utent.ut_type = LOGIN_PROCESS;
! 		(void) time (&utent.ut_time);
! 		return;
! 	}
! #else
! 	bzero (&utent, sizeof utent);
! 	if (line = ttyname (0)) {
! 		if (strncmp (line, "/dev/", 5) == 0)
! 			line += 5;
! 
! 		(void) strncpy (utent.ut_line, line, (int) sizeof utent.ut_line);
! 		(void) time (&utent.ut_time);
! 		return;
  	}
  #endif
+ 	(void) puts (NO_TTY);
+ 	exit (1);
  }
  
  /*
***************
*** 107,144 ****
  char	*name;
  char	*line;
  {
! 	FILE	*wtmp;
! 	struct	utmp	utent;
  	int	fd;
- 	int	i;
  	int	found = 0;
  
  	if (! (fd = open ("/etc/utmp", O_RDWR)))
  		return;
  
! 	while (! found && read (fd, &utent, sizeof utent) == sizeof utent) {
! 		if (! strncmp (line, utent.ut_line, sizeof utent.ut_line))
  			found++;
  	}
  	if (! found) {
! 		bzero (&utent, sizeof utent);
! 		strncpy (utent.ut_line, line, sizeof utent.ut_line);
  	}
- 	(void) strncpy (utent.ut_user, name, sizeof utent.ut_user);
  #ifndef	BSD
! 	utent.ut_type = USER_PROCESS;
! 	utent.ut_pid = getpid ();
  #endif
! 	(void) time (&utent.ut_time);
  
  	if (found)
! 		lseek (fd, (long) - sizeof utent, 1);
  
! 	write (fd, &utent, sizeof utent);
! 	close (fd);
  
! 	if ((wtmp = fopen (WTMP_FILE, "a+"))) {
! 		fwrite ((char *) &utent, sizeof utent, 1, wtmp);
! 		fclose (wtmp);
  	}
  }
--- 135,173 ----
  char	*name;
  char	*line;
  {
! 	struct	utmp	utmp;
  	int	fd;
  	int	found = 0;
  
  	if (! (fd = open ("/etc/utmp", O_RDWR)))
  		return;
  
! 	while (! found && read (fd, &utmp, sizeof utmp) == sizeof utmp) {
! 		if (! strncmp (line, utmp.ut_line, (int) sizeof utmp.ut_line))
  			found++;
  	}
  	if (! found) {
! 		(void) bzero (&utmp, sizeof utmp);
! 		(void) strncpy (utmp.ut_line, line, (int) sizeof utmp.ut_line);
  	}
  #ifndef	BSD
! 	(void) strncpy (utmp.ut_user, name, (int) sizeof utmp.ut_user);
! 	utmp.ut_type = USER_PROCESS;
! 	utmp.ut_pid = getpid ();
! #else
! 	(void) strncpy (utmp.ut_name, name, (int) sizeof utmp.ut_name);
  #endif
! 	(void) time (&utmp.ut_time);
  
  	if (found)
! 		(void) lseek (fd, (long) - sizeof utmp, 1);
  
! 	(void) write (fd, &utmp, sizeof utmp);
! 	(void) close (fd);
  
! 	if ((fd = open (WTMP_FILE, O_WRONLY|O_APPEND)) >= 0) {
! 		(void) write (fd, &utmp, sizeof utmp);
! 		(void) close (fd);
  	}
+ 	utent = utmp;
  }
*** rel3/README	Thu May 30 07:02:41 1991
--- README	Thu Jun  6 09:32:49 1991
***************
*** 1,9 ****
  This is the explanatory document for John F. Haugh II's login replacement,
! release 3.  This document was last updated 11/21/90.
  
! This software is copyright 1988, 1989, 1990, John F. Haugh II.  All rights
! reserved.  Use, duplication and disclosure is permitted according to the
! guidelines listed below.
  
  This software is being provided as a freely redistributable login clone.
  You may distribute this software provided you do not charge for other than
--- 1,11 ----
+ [	@(#)README	3.3	08:56:06	5/30/91	]
+ 
  This is the explanatory document for John F. Haugh II's login replacement,
! release 3.  This document was last updated 5/30/91.
  
! This software is copyright 1988, 1989, 1990, 1991, John F. Haugh II.  All
! rights reserved.  Use, duplication and disclosure is permitted according
! to the guidelines listed below.
  
  This software is being provided as a freely redistributable login clone.
  You may distribute this software provided you do not charge for other than
***************
*** 27,35 ****
  New for Release 3:
  	The objects are being combined into libraries to make maintenance
  	easier and to encourage developers to use the modules as the
! 	basis for new tools.
  
  	New lint rules have been added to make the code easier to lint.
  
  Begin by reading and editing the config.h file.  All options are selected
  by using #define's.  A brief description for each available option appears
--- 29,43 ----
  New for Release 3:
  	The objects are being combined into libraries to make maintenance
  	easier and to encourage developers to use the modules as the
! 	basis for new tools.  New tools are planned based on SVR4 commands.
  
  	New lint rules have been added to make the code easier to lint.
+ 	Files will gradually be fixed so that they lint cleanly.
+ 
+ 	DBM file access has been added to everything that would tolerate
+ 	it.  The files /etc/passwd, /etc/group, and /etc/shadow all have
+ 	DBM interfaces.  The new file, /etc/gshadow, has been added to
+ 	support shadowed group information and it too has a DBM interface.
  
  Begin by reading and editing the config.h file.  All options are selected
  by using #define's.  A brief description for each available option appears
***************
*** 70,76 ****
  DBM Password Files -
  	This option utilizes the DBM database access routines to
  	increase the performance of user name and ID lookups in the
! 	password file.
  
  	Select this option by defining both the DBM and GETPWENT
  	macros.  The FGETPWENT macro must also be defined or the
--- 78,85 ----
  DBM Password Files -
  	This option utilizes the DBM database access routines to
  	increase the performance of user name and ID lookups in the
! 	password file.  You may select the NDBM database instead
! 	and have DBM-style access to all user information files.
  
  	Select this option by defining both the DBM and GETPWENT
  	macros.  The FGETPWENT macro must also be defined or the
***************
*** 94,108 ****
  	Additionally, the PASSLENGTH macro must be defined to
  	control the minimum length for a legal password.
  
- Mandatory Password Prompting -
- 	This option requires all passwords, including null ones,
- 	to be prompted for.  Traditionally an account with a
- 	password field of '::' does not require prompting for.
- 	This option modifies this behavior to require even
- 	null passwords be prompted for.
- 
- 	Select this option by defining the NOBLANK macro.
- 
  Password Aging Defaults -
  	You may select the default number of days during which a
  	password is valid.  The pwconv command adds aging
--- 103,108 ----
***************
*** 169,175 ****
  	This option permits you to specify a file which disables
  	user logins.  This options permits you to keep normal
  	users off of the system while performing maintenance
! 	functions.
  
  	Select this option by defining NOLOGINS to be the name
  	of the file to use.
--- 169,176 ----
  	This option permits you to specify a file which disables
  	user logins.  This options permits you to keep normal
  	users off of the system while performing maintenance
! 	functions.  The contents of the file will be displayed if
! 	the file exists at login time.
  
  	Select this option by defining NOLOGINS to be the name
  	of the file to use.
***************
*** 261,267 ****
  
  	Select this option by defining the SULOG macro to
  	have the value of the name of the file you want
! 	attempts logged to.
  
  Configurable Editing Keys -
  	This options allows the erase and kill characters to
--- 262,270 ----
  
  	Select this option by defining the SULOG macro to
  	have the value of the name of the file you want
! 	attempts logged to.  If you enable syslog processing,
! 	you may want to define SULOGONLY to prevent multiple
! 	records of su(1) usage.  See config.h for more details.
  
  Configurable Editing Keys -
  	This options allows the erase and kill characters to
***************
*** 284,289 ****
--- 287,301 ----
  	
  	Warning: These values will not apply to processes
  	executed by /etc/cron or any of their children.
+ 
+ Syslog -
+ 	This option causes the code to log various errors or
+ 	special conditions to the syslog daemon.  The types of
+ 	information that are logged security violations, changes
+ 	to the user database, and program errors.
+ 
+ 	Select syslog processing by defining the USE_SYSLOG
+ 	macro.
  
  BSD Notes:	Steve Simmons	scs at iti.org
  
*** rel3/Makefile	Thu May 30 07:04:20 1991
--- Makefile	Thu Jun  6 09:32:51 1991
***************
*** 8,16 ****
  # and conspicuously displayed on all copies of object code or
  # distribution media.
  #
! #	@(#)Makefile	3.9	09:06:23  - Shadow password system
  #
! #	@(#)Makefile	3.9	09:06:23	5/28/91
  #
  SHELL = /bin/sh
  
--- 8,16 ----
  # and conspicuously displayed on all copies of object code or
  # distribution media.
  #
! #	@(#)Makefile	3.10	09:05:50  - Shadow password system
  #
! #	@(#)Makefile	3.10	09:05:50	5/30/91
  #
  SHELL = /bin/sh
  
***************
*** 67,73 ****
  LINTFLAGS = $(OS) -Dlint
  
  .c.L:
! 	$(LINT) -u $(LINTFLAGS) $*.c > $*.L
  
  LOBJS = lmain.o login.o env.o valid.o setup.o shell.o age.o \
  	utmp.o sub.o mail.o motd.o log.o ttytype.o failure.o
--- 67,73 ----
  LINTFLAGS = $(OS) -Dlint
  
  .c.L:
! 	$(LINT) -pxu $(LINTFLAGS) $*.c > $*.L
  
  LOBJS = lmain.o login.o env.o valid.o setup.o shell.o age.o \
  	utmp.o sub.o mail.o motd.o log.o ttytype.o failure.o
*** rel3/config.h	Thu May 30 07:04:21 1991
--- config.h	Sun Jun  2 16:03:33 1991
***************
*** 12,18 ****
  /*
   * Configuration file for login.
   *
!  *	@(#)config.h	3.6	09:18:23	5/28/91
   */
  
  /*
--- 12,18 ----
  /*
   * Configuration file for login.
   *
!  *	@(#)config.h	3.7	08:57:09	5/30/91
   */
  
  /*
***************
*** 53,64 ****
   */
  
  #define	PASSLENGTH	5
- 
- /*
-  * Define NOBLANK if you want all passwords prompted for, including
-  * empty ones.
- 
- #undef	NOBLANK
  
  /*
   * Define MAXDAYS to be the default maximum number of days a password
--- 53,58 ----
*** rel3/passwd.c	Thu May 30 07:04:21 1991
--- passwd.c	Tue Jun  4 09:11:10 1991
***************
*** 16,22 ****
  #include <signal.h>
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)passwd.c	3.2	09:06:29	5/28/91";
  #endif
  
  /*
--- 16,22 ----
  #include <signal.h>
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)passwd.c	3.3	08:50:26	6/4/91";
  #endif
  
  /*
***************
*** 605,611 ****
  	 * Let the user know whose password is being changed.
  	 */
  
! 	printf (CHANGING, name);
  
  	/*
  	 * The user name is valid, so let's get the shadow file
--- 605,612 ----
  	 * Let the user know whose password is being changed.
  	 */
  
! 	if (! Sflg)
! 		printf (CHANGING, name);
  
  	/*
  	 * The user name is valid, so let's get the shadow file
*** rel3/sgroupio.c	Thu May 30 07:04:49 1991
--- sgroupio.c	Thu Jun  6 07:23:39 1991
***************
*** 38,44 ****
  #include "shadow.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)sgroupio.c	3.2	09:08:11	5/28/91";
  #endif
  
  static	int	islocked;
--- 38,44 ----
  #include "shadow.h"
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)sgroupio.c	3.3	07:06:36	6/6/91";
  #endif
  
  static	int	islocked;
***************
*** 66,72 ****
  static	char	sg_filename[BUFSIZ] = SGROUP;
  
  extern	char	*strdup();
! extern	struct	sgrp	*sgetgsent();
  extern	char	*fgetsx();
  extern	char	*malloc();
  
--- 66,72 ----
  static	char	sg_filename[BUFSIZ] = SGROUP;
  
  extern	char	*strdup();
! extern	struct	sgrp	*sgetsgent();
  extern	char	*fgetsx();
  extern	char	*malloc();
  
***************
*** 338,344 ****
  
  		sgrf->sgr_changed = 0;
  		sgrf->sgr_line = strdup (buf);
! 		if ((sgrent = sgetgsent (buf)) && ! (sgrent = sgr_dup (sgrent)))
  			return 0;
  
  		sgrf->sgr_entry = sgrent;
--- 338,344 ----
  
  		sgrf->sgr_changed = 0;
  		sgrf->sgr_line = strdup (buf);
! 		if ((sgrent = sgetsgent (buf)) && ! (sgrent = sgr_dup (sgrent)))
  			return 0;
  
  		sgrf->sgr_entry = sgrent;
***************
*** 421,427 ****
  
  		for (sgrf = sgr_head;! errors && sgrf;sgrf = sgrf->sgr_next) {
  			if (sgrf->sgr_changed) {
! 				if (putgsent (sgrf->sgr_entry, sgrfp))
  					errors++;
  			} else {
  				if (fputsx (sgrf->sgr_line, sgrfp))
--- 421,427 ----
  
  		for (sgrf = sgr_head;! errors && sgrf;sgrf = sgrf->sgr_next) {
  			if (sgrf->sgr_changed) {
! 				if (putsgent (sgrf->sgr_entry, sgrfp))
  					errors++;
  			} else {
  				if (fputsx (sgrf->sgr_line, sgrfp))
*** rel3/gshadow.c	Thu May 30 07:03:27 1991
--- gshadow.c	Thu Jun  6 08:08:00 1991
***************
*** 1,5 ****
  /*
!  * Copyright 1990, John F. Haugh II
   * All rights reserved.
   *
   * Permission is granted to copy and create derivative works for any
--- 1,5 ----
  /*
!  * Copyright 1990, 1991, John F. Haugh II
   * All rights reserved.
   *
   * Permission is granted to copy and create derivative works for any
***************
*** 24,31 ****
  #ifdef	NDBM
  #include <ndbm.h>
  #include <fcntl.h>
! DBM	*sg_dbm;
! int	sg_dbm_mode;
  static	int	dbmopened;
  static	int	dbmerror;
  #endif
--- 24,31 ----
  #ifdef	NDBM
  #include <ndbm.h>
  #include <fcntl.h>
! DBM	*sgr_dbm;
! int	sg_dbm_mode = -1;
  static	int	dbmopened;
  static	int	dbmerror;
  #endif
***************
*** 32,38 ****
  
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)gshadow.c	3.3	11:25:55	12/19/90";
  #endif
  
  #define	MAXMEM	1024
--- 32,38 ----
  
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)gshadow.c	3.4	07:31:22	6/6/91";
  #endif
  
  #define	MAXMEM	1024
***************
*** 88,101 ****
  
  		strcpy (dbmfiles, sgrpfile);
  		strcat (dbmfiles, ".pag");
! 		if (sg_dbm_mode != -1)
! 			mode = O_RDONLY;
  		else
! 			mode = (sg_dbm_mode == O_RDONLY ||
! 				sg_dbm_mode == O_RDWR) ? sg_dbm_mode:O_RDONLY;
  
  		if (access (dbmfiles, 0) ||
! 			(! (sg_dbm = dbm_open (sgrpfile, mode, 0))))
  			dbmerror = 1;
  		else
  			dbmopened = 1;
--- 88,101 ----
  
  		strcpy (dbmfiles, sgrpfile);
  		strcat (dbmfiles, ".pag");
! 
! 		if (sg_dbm_mode == -1)
! 			mode = O_RDWR;
  		else
! 			mode = (sg_dbm_mode == O_RDWR) ? O_RDWR:O_RDONLY;
  
  		if (access (dbmfiles, 0) ||
! 			(! (sgr_dbm = dbm_open (sgrpfile, mode, 0))))
  			dbmerror = 1;
  		else
  			dbmopened = 1;
***************
*** 111,120 ****
  
  	shadow = (FILE *) 0;
  #ifdef	NDBM
! 	if (dbmopened && sg_dbm) {
! 		dbm_close (sg_dbm);
  		dbmopened = 0;
! 		sg_dbm = 0;
  	}
  #endif
  }
--- 111,120 ----
  
  	shadow = (FILE *) 0;
  #ifdef	NDBM
! 	if (dbmopened && sgr_dbm) {
! 		dbm_close (sgr_dbm);
  		dbmopened = 0;
! 		sgr_dbm = 0;
  	}
  #endif
  }
***************
*** 204,210 ****
  		key.dsize = strlen (name);
  		key.dptr = name;
  
! 		content = dbm_fetch (sg_dbm, key);
  		if (content.dptr != 0) {
  			memcpy (sgrbuf, content.dptr, content.dsize);
  			sgroup.sg_mem = members;
--- 204,210 ----
  		key.dsize = strlen (name);
  		key.dptr = name;
  
! 		content = dbm_fetch (sgr_dbm, key);
  		if (content.dptr != 0) {
  			memcpy (sgrbuf, content.dptr, content.dsize);
  			sgroup.sg_mem = members;
*** rel3/pwdbm.c	Thu May 30 07:04:47 1991
--- pwdbm.c	Thu Jun  6 09:32:51 1991
***************
*** 10,16 ****
   */
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)pwdbm.c	3.4	09:08:00	5/28/91";
  #endif
  
  #ifdef	BSD
--- 10,16 ----
   */
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)pwdbm.c	3.5	09:29:30	6/6/91";
  #endif
  
  #ifdef	BSD
***************
*** 92,97 ****
--- 92,152 ----
  #endif
  #ifdef	NDBM
  	if (dbm_store (pw_dbm, key, content, DBM_REPLACE))
+ 		return 0;
+ #endif
+ 	return 1;
+ }
+ 
+ /*
+  * pw_dbm_remove
+  *
+  * Removes the DBM password entry, if it exists.
+  */
+ 
+ int
+ pw_dbm_remove (pw)
+ struct	passwd	*pw;
+ {
+ 	datum	key;
+ 	static	int	once;
+ 
+ 	if (! once) {
+ #ifdef	NDBM
+ 		if (! pw_dbm)
+ 			setpwent ();
+ #else
+ 		setpwent ();
+ #endif
+ 		once++;
+ 	}
+ #ifdef	DBM
+ 	strcpy (data, PWDFILE);
+ 	strcat (data, ".pag");
+ 	if (access (data, 0))
+ 		return 0;
+ #endif
+ #ifdef	NDBM
+ 	if (! pw_dbm)
+ 		return 0;
+ #endif
+ 	key.dsize = strlen (pw->pw_name);
+ 	key.dptr = pw->pw_name;
+ #ifdef	DBM
+ 	if (delete (key))
+ 		return 0;
+ #endif
+ #ifdef	NDBM
+ 	if (dbm_delete (pw_dbm, key))
+ 		return 0;
+ #endif
+ 	key.dsize = sizeof pw->pw_uid;
+ 	key.dptr = (char *) &pw->pw_uid;
+ #ifdef	DBM
+ 	if (delete (key))
+ 		return 0;
+ #endif
+ #ifdef	NDBM
+ 	if (dbm_delete (pw_dbm, key))
  		return 0;
  #endif
  	return 1;
*** rel3/spdbm.c	Thu May 30 07:03:30 1991
--- spdbm.c	Thu Jun  6 09:32:52 1991
***************
*** 1,5 ****
  /*
!  * Copyright 1990, John F. Haugh II
   * All rights reserved.
   *
   * Use, duplication, and disclosure prohibited without
--- 1,5 ----
  /*
!  * Copyright 1990, 1991, John F. Haugh II
   * All rights reserved.
   *
   * Use, duplication, and disclosure prohibited without
***************
*** 7,13 ****
   */
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)spdbm.c	3.1	08:16:16	11/21/90";
  #endif
  
  #include <string.h>
--- 7,13 ----
   */
  
  #ifndef	lint
! static	char	sccsid[] = "@(#)spdbm.c	3.2	09:29:53	6/6/91";
  #endif
  
  #include <string.h>
***************
*** 56,61 ****
--- 56,91 ----
  	key.dsize = strlen (sp->sp_namp);
  	key.dptr = sp->sp_namp;
  	if (dbm_store (sp_dbm, key, content, DBM_REPLACE))
+ 		return 0;
+ 
+ 	return 1;
+ }
+ 
+ /*
+  * sp_dbm_remove
+  *
+  * Updates the DBM password files, if they exist.
+  */
+ 
+ int
+ sp_dbm_remove (user)
+ char	*user;
+ {
+ 	datum	key;
+ 	static	int	once;
+ 
+ 	if (! once) {
+ 		if (! sp_dbm)
+ 			setspent ();
+ 
+ 		once++;
+ 	}
+ 	if (! sp_dbm)
+ 		return 0;
+ 
+ 	key.dsize = strlen (user);
+ 	key.dptr = user;
+ 	if (dbm_delete (sp_dbm, key))
  		return 0;
  
  	return 1;
*** rel3/gpmain.c	Thu May 30 07:04:33 1991
--- gpmain.c	Thu Jun  6 09:32:53 1991
***************
*** 38,44 ****
  #endif
  
  #ifndef	lint
! static	char	_sccsid[] = "@(#)gpmain.c	3.5	09:07:24	5/28/91";
  #endif
  
  char	name[BUFSIZ];
--- 38,44 ----
  #endif
  
  #ifndef	lint
! static	char	_sccsid[] = "@(#)gpmain.c	3.6	09:28:18	6/6/91";
  #endif
  
  char	name[BUFSIZ];
***************
*** 95,116 ****
  char	*member;
  {
  	int	i;
- 	int	found = 0;
  	char	**tmp;
  
! 	for (i = 0;!found && list[i] != (char *) 0;i++)
  		if (strcmp (list[i], member) == 0)
! 			found++;
  
! 	tmp = (char **) malloc ((i + 2) * sizeof member);
  
  	for (i = 0;list[i] != (char *) 0;i++)
  		tmp[i] = list[i];
  
! 	if (! found)
! 		tmp[i++] = strdup (member);
! 
  	tmp[i] = (char *) 0;
  	return tmp;
  }
  
--- 95,115 ----
  char	*member;
  {
  	int	i;
  	char	**tmp;
  
! 	for (i = 0;list[i] != (char *) 0;i++)
  		if (strcmp (list[i], member) == 0)
! 			return list;
  
! 	if (! (tmp = (char **) malloc ((i + 2) * sizeof member)))
! 		return 0;
  
  	for (i = 0;list[i] != (char *) 0;i++)
  		tmp[i] = list[i];
  
! 	tmp[i++] = strdup (member);
  	tmp[i] = (char *) 0;
+ 
  	return tmp;
  }
  
-- 
John F. Haugh II        | Distribution to  | UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 255-8251 | GEnie PROHIBITED :-) |  Domain: jfh at rpp386.cactus.org
"If liberals interpreted the 2nd Amendment the same way they interpret the
 rest of the Constitution, gun ownership would be mandatory."



More information about the Alt.sources mailing list