summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-12-17 20:50:52 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-12-17 20:50:52 +0000
commita1ff8a914da85448d7278b5679a2e6d88f8856a6 (patch)
treef917f86ec77bfb391367c3b08b2edb4ab3e9a33b /lib
parent5fc9be94a0cbfe07bf5b8fbbef13e79c5ce9714c (diff)
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@.
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/passwd.c6
-rw-r--r--lib/libutil/pw_lock.328
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
index c3dc4ece8bf..94703156aed 100644
--- a/lib/libutil/passwd.c
+++ b/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/lib/libutil/pw_lock.3 b/lib/libutil/pw_lock.3
index fca11013cee..b5edfb37de2 100644
--- a/lib/libutil/pw_lock.3
+++ b/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