xref: /netbsd-src/lib/libutil/pw_lock.3 (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1.\" Copyright (c) 1995
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software developed by the Computer Systems
5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
6.\" BG 91-66 and contributed to Berkeley.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed by the University of
19.\"	California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\"    may be used to endorse or promote products derived from this software
22.\"    without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.Dd December 15, 1995
37.Dt PW_LOCK 3
38.Os
39.Sh NAME
40.Nm pw_lock ,
41.Nm pw_mkdb ,
42.Nm pw_abort
43.Nd passwd file update functions
44.Sh SYNOPSIS
45.Fd #include <util.h>
46.Ft int
47.Fn pw_lock "int retries"
48.Ft int
49.Fn pw_mkdb
50.Ft void
51.Fn pw_abort
52.Sh DESCRIPTION
53The
54.Fn pw_lock ,
55.Fn pw_mkdb ,
56and
57.Fn pw_abort
58functions allow a program to update the system passwd database.
59.Pp
60The
61.Fn pw_lock
62function attempts to lock the passwd database by creating the file
63.Pa /etc/ptmp ,
64and returns the file descriptor of that file.  If
65.Fa retries
66is greater than zero,
67.Fn pw_lock
68will try multiple times to open
69.Pa /etc/ptmp ,
70waiting one second between tries.  In addition to being a lock file,
71.Pa /etc/ptmp
72will also hold the contents of the new passwd file.
73.Pp
74The
75.Fn pw_mkdb
76function updates the passwd file from the contents of
77.Pa /etc/ptmp .
78You should finish writing to and close the file descriptor returned by
79.Fn pw_lock
80before calling
81.Fn pw_mkdb .
82If
83.Fn pw_mkdb
84fails and you do not wish to retry, you should make sure to call
85.Fn pw_abort
86to clean up the lock file.
87.Pp
88The
89.Fn pw_abort
90function aborts a passwd file update by deleting
91.Pa /etc/ptmp .
92The passwd database remains unchanged.
93.Sh RETURN VALUES
94The
95.Fn pw_lock
96and
97.Fn pw_mkdb
98functions return -1 if they are unable to complete properly.
99.Sh FILES
100.Bl -tag -width /etc/master.passwd -compact
101.It Pa /etc/master.passwd
102.It Pa /etc/ptmp
103.El
104.Sh SEE ALSO
105.Xr pw_init 3
106