From 42bf021fff9c11b366ab669a431902968ce2027f Mon Sep 17 00:00:00 2001 From: ray <> Date: Sun, 17 Dec 2006 20:50:51 +0000 Subject: [PATCH] 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@. --- src/lib/libutil/passwd.c | 6 ++++-- src/lib/libutil/pw_lock.3 | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/lib/libutil/passwd.c b/src/lib/libutil/passwd.c index c3dc4ece..94703156 100644 --- a/src/lib/libutil/passwd.c +++ b/src/lib/libutil/passwd.c @@ -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); diff --git a/src/lib/libutil/pw_lock.3 b/src/lib/libutil/pw_lock.3 index fca11013..b5edfb37 100644 --- a/src/lib/libutil/pw_lock.3 +++ b/src/lib/libutil/pw_lock.3 @@ -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