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