Browse Source

Always write errno on pw_lock failure so it can be relied on.

Mention errno, pw_file, and pw_init in pw_lock man page.
OK jmc@, otto@, millert@, and deraadt@.
OPENBSD_4_1
ray 18 years ago
parent
commit
42bf021fff
2 changed files with 29 additions and 5 deletions
  1. +4
    -2
      src/lib/libutil/passwd.c
  2. +25
    -3
      src/lib/libutil/pw_lock.3

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

@ -1,4 +1,4 @@
/* $OpenBSD: passwd.c,v 1.47 2006/04/02 02:10:35 deraadt Exp $ */
/* $OpenBSD: passwd.c,v 1.48 2006/12/17 20:50:51 ray Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@ -95,8 +95,10 @@ pw_lock(int retries)
mode_t old_mode;
int save_errno;
if (!pw_lck)
if (!pw_lck) {
errno = EINVAL;
return (-1);
}
/* Acquire the lock file. */
old_mode = umask(0);
fd = open(pw_lck, O_WRONLY|O_CREAT|O_EXCL, 0600);


+ 25
- 3
src/lib/libutil/pw_lock.3 View File

@ -1,4 +1,4 @@
.\" $OpenBSD: pw_lock.3,v 1.12 2005/07/29 09:08:34 jmc Exp $
.\" $OpenBSD: pw_lock.3,v 1.13 2006/12/17 20:50:51 ray Exp $
.\"
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
@ -70,6 +70,12 @@ waiting one second between tries.
In addition to being a lock file,
.Pa /etc/ptmp
will also hold the contents of the new passwd file.
A different lock file can be specified with
.Xr pw_file 3 .
.Pp
.Xr pw_init 3
must be called before
.Fn pw_lock .
.Pp
The
.Fn pw_mkdb
@ -115,9 +121,11 @@ The passwd database remains unchanged.
.Sh RETURN VALUES
The
.Fn pw_lock
and
function returns \-1 on error and sets
.Va errno .
The
.Fn pw_mkdb
functions return \-1 if they are unable to complete properly.
function returns \-1 if it is unable to complete properly.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/master.passwd
@ -131,7 +139,21 @@ insecure password database file
.It Pa /etc/spwd.db
secure password database file
.El
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er EINVAL
.Fn pw_lock
was called before
.Xr pw_init 3 .
.El
.Pp
.Fn pw_lock
may also fail and set
.Va errno
for any of the errors specified for the routine
.Xr open 2 .
.Sh SEE ALSO
.Xr flock 2 ,
.Xr pw_file 3 ,
.Xr pw_init 3 ,
.Xr pwd_mkdb 8

Loading…
Cancel
Save