From: pcl@foo.oucs.ox.ac.uk (Paul C Leyland)
Subject: npasswd, Ultrix and passwd locking -- bug and fix
Date: 18 Mar 1994 14:14:04 GMT [thread overview]
Message-ID: <PCL.94Mar18141404@foo.oucs.ox.ac.uk> (raw)
A problem has been found with my adaptation of Clyde Hoover's
"npasswd" program for Ultrix running at the UPGRADE and ENHANCED
security levels.
Under certain circumstances, the program could leave /etc/passwd
locked from other accesses, resulting in a denial of service. Since
/etc/passwd is not modified if the password is not stored there, there
is no reason to lock the file in the first place.
If you are running npasswd under Ultrix UPGRADE/ENHANCED security you
should either download a fresh copy of the code from
black.ox.ac.uk/src/security/npasswd_enhanced.shar.Z or you should
apply the patch below to the file pw_enhanced.c
My thanks to keppingm@ucs.orst.edu (Mark Keppinger) for identifying
this problem and for supplying the fix.
Paul
8<----------------------------------------------------------------->8
*** pw_enhanced.c~ Fri Mar 18 12:43:38 1994
--- pw_enhanced.c Fri Mar 18 13:06:49 1994
***************
*** 220,273 ****
randomstring (salt, sizeof (salt));
theUser.pw_passwd = "*"; /* Always '*' in /etc/passwd */
strcpy (theAuth.a_password, crypt16 (newpwd, salt)); /* Real one in auth DB */
! (void) umask (0);
! (void) stat (passwdfile, &oldstat);
! fd = open (passwdtemp, O_WRONLY | O_CREAT | O_EXCL, PASSWD_MODE);
! if (fd < 0)
{
! if (errno == EEXIST)
quit (0, "Password file busy - try again.\n");
! perror ("Tempfile create");
! quit (1, "Cannot create temp file.\n");
! }
! mytempfile = 1;
! if ((tf = fdopen (fd, "w")) == NULL)
quit (1, "Cannot fdopen temp file.");
! oldsigs = sigblock (blocksigs);
! setpwent ();
! while ((px = getpwent ()) != NULL)
! {
! if (px->pw_name == 0 || px->pw_name[0] == 0) /* Sanity check */
continue;
! if (strcmp (px->pw_name, theUser.pw_name) == 0)
px = &theUser;
! (void) putpwent (px, tf);
! }
! endpwent ();
! (void) fflush (tf);
! (void) fstat (fileno (tf), &newstat);
! (void) fclose (tf);
!
! /* Check if the new password file is complete. Since the encrypted password is of a fixed length,
! the new file should be roughly the same size as the old one. */
!
! if (newstat.st_size < (oldstat.st_size - SLOP))
quit (1, "New password file appears to be incomplete - aborting.\n");
!
! if (rename (passwdfile, savefile) < 0)
! {
! perror ("Password file save");
! unlink (passwdtemp);
! quit (1, "Can't save password file");
}
- if (rename (passwdtemp, passwdfile) < 0)
- {
- perror ("Password file replace");
- (void) unlink (passwdtemp);
- (void) link (savefile, passwdfile);
- quit (1, "Can't replace password file");
- }
- updatedbm ();
/* Ok, /etc/passwd in good shape -- update auth DB */
--- 220,276 ----
randomstring (salt, sizeof (salt));
theUser.pw_passwd = "*"; /* Always '*' in /etc/passwd */
strcpy (theAuth.a_password, crypt16 (newpwd, salt)); /* Real one in auth DB */
! if (strcmp ("*", theUser.pw_passwd))
{
! (void) umask (0);
! (void) stat (passwdfile, &oldstat);
! fd = open (passwdtemp, O_WRONLY | O_CREAT | O_EXCL, PASSWD_MODE);
! if (fd < 0)
! {
! if (errno == EEXIST)
quit (0, "Password file busy - try again.\n");
! perror ("Tempfile create");
! quit (1, "Cannot create temp file.\n");
! }
! mytempfile = 1;
! if ((tf = fdopen (fd, "w")) == NULL)
quit (1, "Cannot fdopen temp file.");
! oldsigs = sigblock (blocksigs);
! setpwent ();
! while ((px = getpwent ()) != NULL)
! {
! if (px->pw_name == 0 || px->pw_name[0] == 0) /* Sanity check */
continue;
! if (strcmp (px->pw_name, theUser.pw_name) == 0)
px = &theUser;
! (void) putpwent (px, tf);
! }
! endpwent ();
! (void) fflush (tf);
! (void) fstat (fileno (tf), &newstat);
! (void) fclose (tf);
!
! /* Check if the new password file is complete. Since the encrypted password is of a fixed length,
! the new file should be roughly the same size as the old one. */
!
! if (newstat.st_size < (oldstat.st_size - SLOP))
quit (1, "New password file appears to be incomplete - aborting.\n");
!
! if (rename (passwdfile, savefile) < 0)
! {
! perror ("Password file save");
! unlink (passwdtemp);
! quit (1, "Can't save password file");
! }
! if (rename (passwdtemp, passwdfile) < 0)
! {
! perror ("Password file replace");
! (void) unlink (passwdtemp);
! (void) link (savefile, passwdfile);
! quit (1, "Can't replace password file");
! }
! updatedbm ();
}
/* Ok, /etc/passwd in good shape -- update auth DB */
--
Paul Leyland <pcl@black.ox.ac.uk> | Hanging on in quiet desperation is
Oxford University Computing Services | the English way.
13 Banbury Road, Oxford, OX2 6NN, UK | The time is gone, the song is over.
Tel: +44-865-273200 Fax: +44-865-273275 | Thought I'd something more to say.
Finger pcl@black.ox.ac.uk for PGP key |
reply other threads:[~1994-03-18 14:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox