xref: /netbsd/lib/libutil/pw_lock.3 (revision c4a72b64)
1.\"	$NetBSD: pw_lock.3,v 1.10 2002/10/01 19:36:30 wiz Exp $
2.\"
3.\" Copyright (c) 1995
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software developed by the Computer Systems
7.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
8.\" BG 91-66 and contributed to Berkeley.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.Dd August 18, 2001
39.Dt PW_LOCK 3
40.Os
41.Sh NAME
42.Nm pw_lock ,
43.Nm pw_mkdb ,
44.Nm pw_abort ,
45.Nm pw_setprefix ,
46.Nm pw_getprefix
47.Nd passwd file update functions
48.Sh LIBRARY
49.Lb libutil
50.Sh SYNOPSIS
51.Fd #include \*[Lt]util.h\*[Gt]
52.Ft int
53.Fn pw_lock "int retries"
54.Ft int
55.Fn pw_mkdb "const char *username" "int secureonly"
56.Ft void
57.Fn pw_abort "void"
58.Ft void
59.Fn pw_error "const char *name" "int err" "int eval"
60.Ft int
61.Fn pw_setprefix "const char *new_prefix"
62.Ft "const char *"
63.Fn pw_getprefix "void"
64.Sh DESCRIPTION
65The
66.Fn pw_lock ,
67.Fn pw_mkdb ,
68and
69.Fn pw_abort
70functions allow a program to update the system passwd database.
71.Pp
72The
73.Fn pw_lock
74function attempts to lock the passwd database by creating the file
75.Pa /etc/ptmp ,
76and returns the file descriptor of that file.
77If
78.Fa retries
79is greater than zero,
80.Fn pw_lock
81will try multiple times to open
82.Pa /etc/ptmp ,
83waiting one second between tries.
84In addition to being a lock file,
85.Pa /etc/ptmp
86will also hold the contents of the new passwd file.
87.Pp
88The
89.Fn pw_mkdb
90function updates the passwd file from the contents of
91.Pa /etc/ptmp .
92You should finish writing to and close the file descriptor returned by
93.Fn pw_lock
94before calling
95.Fn pw_mkdb .
96If
97.Fn pw_mkdb
98fails and you do not wish to retry, you should make sure to call
99.Fn pw_abort
100to clean up the lock file.
101If the
102.Ar username
103argument is not NULL, only database entries pertaining to the specified user
104will be modified.
105If the
106.Ar secureonly
107argument is non-zero, only the secure database will be updated.
108.Pp
109The
110.Fn pw_abort
111function aborts a passwd file update by deleting
112.Pa /etc/ptmp .
113The passwd database remains unchanged.
114.Pp
115The
116.Fn pw_setprefix
117function defines the root directory used for passwd file updates.
118If the prefix is set to
119.Pa /newroot
120.Fn pw_lock
121will operate on
122.Pa /newroot/etc/ptmp
123afterwards.
124The default prefix is an empty string.
125.Pp
126The
127.Fn pw_getprefix
128function returns the root directory which is currently used for passwd file
129updates.
130.Sh RETURN VALUES
131The
132.Fn pw_lock
133and
134.Fn pw_mkdb
135functions return -1 if they are unable to complete properly.
136.Sh FILES
137.Bl -tag -width /etc/master.passwd -compact
138.It Pa /etc/master.passwd
139.It Pa /etc/ptmp
140.El
141.Sh SEE ALSO
142.Xr pw_init 3 ,
143.Xr pwd_mkdb 8
144