1.\" $NetBSD: pw_lock.3,v 1.12 2003/08/07 16:45:00 agc 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 August 18, 2001 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 void 55.Fn pw_error "const char *name" "int err" "int eval" 56.Ft int 57.Fn pw_setprefix "const char *new_prefix" 58.Ft "const char *" 59.Fn pw_getprefix "void" 60.Sh DESCRIPTION 61The 62.Fn pw_lock , 63.Fn pw_mkdb , 64and 65.Fn pw_abort 66functions allow a program to update the system passwd database. 67.Pp 68The 69.Fn pw_lock 70function attempts to lock the passwd database by creating the file 71.Pa /etc/ptmp , 72and returns the file descriptor of that file. 73If 74.Fa retries 75is greater than zero, 76.Fn pw_lock 77will try multiple times to open 78.Pa /etc/ptmp , 79waiting one second between tries. 80In addition to being a lock file, 81.Pa /etc/ptmp 82will also hold the contents of the new passwd file. 83.Pp 84The 85.Fn pw_mkdb 86function updates the passwd file from the contents of 87.Pa /etc/ptmp . 88You should finish writing to and close the file descriptor returned by 89.Fn pw_lock 90before calling 91.Fn pw_mkdb . 92If 93.Fn pw_mkdb 94fails and you do not wish to retry, you should make sure to call 95.Fn pw_abort 96to clean up the lock file. 97If the 98.Ar username 99argument is not NULL, only 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