Browse Source

Merge in 1.12 to 1.14 from the trunk;

Work around bug in open(2) wrt O_TRUNC and O_SHLOCK|O_EXLOCK.
pw_mkdb() now returns -1 if ptmp is size 0.
OPENBSD_2_2
millert 27 years ago
parent
commit
c06f8648ba
1 changed files with 16 additions and 4 deletions
  1. +16
    -4
      src/lib/libutil/passwd.c

+ 16
- 4
src/lib/libutil/passwd.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: passwd.c,v 1.12 1997/09/29 19:18:21 deraadt Exp $ */
/* $OpenBSD: passwd.c,v 1.12.2.1 1997/11/17 21:15:14 millert Exp $ */
/* /*
* Copyright (c) 1987, 1993, 1994, 1995 * Copyright (c) 1987, 1993, 1994, 1995
@ -34,7 +34,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: passwd.c,v 1.12 1997/09/29 19:18:21 deraadt Exp $";
static char rcsid[] = "$OpenBSD: passwd.c,v 1.12.2.1 1997/11/17 21:15:14 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #include <sys/types.h>
@ -252,11 +252,14 @@ pw_lock(retries)
return (-1); return (-1);
/* Acquire the lock file. */ /* Acquire the lock file. */
old_mode = umask(0); old_mode = umask(0);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK|O_EXLOCK, 0600);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 0600);
for (i = 0; i < retries && fd < 0 && errno == EAGAIN; i++) { for (i = 0; i < retries && fd < 0 && errno == EAGAIN; i++) {
sleep(1); sleep(1);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_TRUNC|O_NONBLOCK|O_EXLOCK, 0600);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_NONBLOCK|O_EXLOCK, 0600);
} }
/* Really want to use O_TRUNC above but there is a bug in open(2) */
if (fd != -1)
ftruncate(fd, 0);
umask(old_mode); umask(old_mode);
return (fd); return (fd);
} }
@ -267,6 +270,15 @@ pw_mkdb()
int pstat; int pstat;
pid_t pid; pid_t pid;
char *lock; char *lock;
struct stat sb;
/* A zero length passwd file is never ok */
if (pw_lck && stat(pw_lck, &sb) == 0) {
if (sb.st_size == 0) {
warnx("%s is zero length", pw_lck);
return (-1);
}
}
pid = vfork(); pid = vfork();
if (pid == 0) { if (pid == 0) {


Loading…
Cancel
Save