xref: /netbsd/lib/libutil/pw_lock.3 (revision 6550d01e)
1.\"	$NetBSD: pw_lock.3,v 1.14 2010/05/05 22:05:31 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. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd February 17, 2007
35.Dt PW_LOCK 3
36.Os
37.Sh NAME
38.Nm pw_lock ,
39.Nm pw_mkdb ,
40.Nm pw_abort ,
41.Nm pw_setprefix ,
42.Nm pw_getprefix
43.Nd passwd file update functions
44.Sh LIBRARY
45.Lb libutil
46.Sh SYNOPSIS
47.In util.h
48.Ft int
49.Fn pw_lock "int retries"
50.Ft int
51.Fn pw_mkdb "const char *username" "int secureonly"
52.Ft void
53.Fn pw_abort "void"
54.Ft int
55.Fn pw_setprefix "const char *new_prefix"
56.Ft "const char *"
57.Fn pw_getprefix "void"
58.Sh DESCRIPTION
59The
60.Fn pw_lock ,
61.Fn pw_mkdb ,
62and
63.Fn pw_abort
64functions allow a program to update the system passwd database.
65.Pp
66The
67.Fn pw_lock
68function attempts to lock the passwd database by creating the file
69.Pa /etc/ptmp ,
70and returns the file descriptor of that file.
71If
72.Fa retries
73is greater than zero,
74.Fn pw_lock
75will try multiple times to open
76.Pa /etc/ptmp ,
77waiting one second between tries.
78In addition to being a lock file,
79.Pa /etc/ptmp
80will also hold the contents of the new passwd file.
81.Pp
82The
83.Fn pw_mkdb
84function updates the passwd file from the contents of
85.Pa /etc/ptmp .
86You should finish writing to and close the file descriptor returned by
87.Fn pw_lock
88before calling
89.Fn pw_mkdb .
90If
91.Fn pw_mkdb
92fails and you do not wish to retry, you should make sure to call
93.Fn pw_abort
94to clean up the lock file.
95If the
96.Ar username
97argument is not
98.Dv NULL ,
99only database entries pertaining to the specified user
100will be modified.
101If the
102.Ar secureonly
103argument is non-zero, only the secure database will be updated.
104.Pp
105The
106.Fn pw_abort
107function aborts a passwd file update by deleting
108.Pa /etc/ptmp .
109The passwd database remains unchanged.
110.Pp
111The
112.Fn pw_setprefix
113function defines the root directory used for passwd file updates.
114If the prefix is set to
115.Pa /newroot
116.Fn pw_lock
117will operate on
118.Pa /newroot/etc/ptmp
119afterwards.
120The default prefix is an empty string.
121.Pp
122The
123.Fn pw_getprefix
124function returns the root directory which is currently used for passwd file
125updates.
126.Sh RETURN VALUES
127The
128.Fn pw_lock
129and
130.Fn pw_mkdb
131functions return -1 if they are unable to complete properly.
132.Sh FILES
133.Bl -tag -width /etc/master.passwd -compact
134.It Pa /etc/master.passwd
135.It Pa /etc/ptmp
136.El
137.Sh SEE ALSO
138.Xr pw_init 3 ,
139.Xr pwd_mkdb 8
140