1*e7023c08Swiz.\" $NetBSD: pw_lock.3,v 1.13 2007/02/17 09:37:55 wiz Exp $ 2b51ed80fSperry.\" 3e42a9484Sjtc.\" Copyright (c) 1995 4e42a9484Sjtc.\" The Regents of the University of California. All rights reserved. 5e42a9484Sjtc.\" 6e42a9484Sjtc.\" This code is derived from software developed by the Computer Systems 7e42a9484Sjtc.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 8e42a9484Sjtc.\" BG 91-66 and contributed to Berkeley. 9e42a9484Sjtc.\" 10e42a9484Sjtc.\" Redistribution and use in source and binary forms, with or without 11e42a9484Sjtc.\" modification, are permitted provided that the following conditions 12e42a9484Sjtc.\" are met: 13e42a9484Sjtc.\" 1. Redistributions of source code must retain the above copyright 14e42a9484Sjtc.\" notice, this list of conditions and the following disclaimer. 15e42a9484Sjtc.\" 2. Redistributions in binary form must reproduce the above copyright 16e42a9484Sjtc.\" notice, this list of conditions and the following disclaimer in the 17e42a9484Sjtc.\" documentation and/or other materials provided with the distribution. 18eb7c1594Sagc.\" 3. Neither the name of the University nor the names of its contributors 19e42a9484Sjtc.\" may be used to endorse or promote products derived from this software 20e42a9484Sjtc.\" without specific prior written permission. 21e42a9484Sjtc.\" 22e42a9484Sjtc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23e42a9484Sjtc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24e42a9484Sjtc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25e42a9484Sjtc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26e42a9484Sjtc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27e42a9484Sjtc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28e42a9484Sjtc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29e42a9484Sjtc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30e42a9484Sjtc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31e42a9484Sjtc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32e42a9484Sjtc.\" SUCH DAMAGE. 33e42a9484Sjtc.\" 34*e7023c08Swiz.Dd February 17, 2007 35e42a9484Sjtc.Dt PW_LOCK 3 36e42a9484Sjtc.Os 37e42a9484Sjtc.Sh NAME 38e42a9484Sjtc.Nm pw_lock , 39e42a9484Sjtc.Nm pw_mkdb , 40a3a468eeStron.Nm pw_abort , 41a3a468eeStron.Nm pw_setprefix , 42a3a468eeStron.Nm pw_getprefix 43e42a9484Sjtc.Nd passwd file update functions 44312aca53Sperry.Sh LIBRARY 45312aca53Sperry.Lb libutil 46e42a9484Sjtc.Sh SYNOPSIS 47472351e1Swiz.In util.h 48e42a9484Sjtc.Ft int 49e42a9484Sjtc.Fn pw_lock "int retries" 50e42a9484Sjtc.Ft int 514068c808Swiz.Fn pw_mkdb "const char *username" "int secureonly" 52e42a9484Sjtc.Ft void 53e8362050Sad.Fn pw_abort "void" 54a3a468eeStron.Ft int 55a3a468eeStron.Fn pw_setprefix "const char *new_prefix" 56a3a468eeStron.Ft "const char *" 57a3a468eeStron.Fn pw_getprefix "void" 58e42a9484Sjtc.Sh DESCRIPTION 59e42a9484SjtcThe 60e42a9484Sjtc.Fn pw_lock , 61e42a9484Sjtc.Fn pw_mkdb , 62e42a9484Sjtcand 63e42a9484Sjtc.Fn pw_abort 64e42a9484Sjtcfunctions allow a program to update the system passwd database. 65e42a9484Sjtc.Pp 66e42a9484SjtcThe 67e42a9484Sjtc.Fn pw_lock 68e42a9484Sjtcfunction attempts to lock the passwd database by creating the file 69e42a9484Sjtc.Pa /etc/ptmp , 7027adb020Swizand returns the file descriptor of that file. 7127adb020SwizIf 72e42a9484Sjtc.Fa retries 73e42a9484Sjtcis greater than zero, 74e42a9484Sjtc.Fn pw_lock 75e42a9484Sjtcwill try multiple times to open 76e42a9484Sjtc.Pa /etc/ptmp , 7727adb020Swizwaiting one second between tries. 7827adb020SwizIn addition to being a lock file, 79e42a9484Sjtc.Pa /etc/ptmp 80e42a9484Sjtcwill also hold the contents of the new passwd file. 81e42a9484Sjtc.Pp 82e42a9484SjtcThe 83e42a9484Sjtc.Fn pw_mkdb 84e42a9484Sjtcfunction updates the passwd file from the contents of 85e42a9484Sjtc.Pa /etc/ptmp . 86e42a9484SjtcYou should finish writing to and close the file descriptor returned by 87e42a9484Sjtc.Fn pw_lock 88e42a9484Sjtcbefore calling 89e42a9484Sjtc.Fn pw_mkdb . 9023beafabSghudsonIf 9123beafabSghudson.Fn pw_mkdb 9223beafabSghudsonfails and you do not wish to retry, you should make sure to call 9323beafabSghudson.Fn pw_abort 9427adb020Swizto clean up the lock file. 9527adb020SwizIf the 967e44d4f9Sad.Ar username 977e44d4f9Sadargument is not NULL, only database entries pertaining to the specified user 9827adb020Swizwill be modified. 9927adb020SwizIf the 1007e44d4f9Sad.Ar secureonly 1017e44d4f9Sadargument is non-zero, only the secure database will be updated. 102e42a9484Sjtc.Pp 103e42a9484SjtcThe 104e42a9484Sjtc.Fn pw_abort 105e42a9484Sjtcfunction aborts a passwd file update by deleting 106e42a9484Sjtc.Pa /etc/ptmp . 107e42a9484SjtcThe passwd database remains unchanged. 108a3a468eeStron.Pp 109a3a468eeStronThe 110a3a468eeStron.Fn pw_setprefix 11127adb020Swizfunction defines the root directory used for passwd file updates. 11227adb020SwizIf the prefix is set to 113a3a468eeStron.Pa /newroot 114a3a468eeStron.Fn pw_lock 115a3a468eeStronwill operate on 116a3a468eeStron.Pa /newroot/etc/ptmp 11727adb020Swizafterwards. 11827adb020SwizThe default prefix is an empty string. 119a3a468eeStron.Pp 120a3a468eeStronThe 121a3a468eeStron.Fn pw_getprefix 122a3a468eeStronfunction returns the root directory which is currently used for passwd file 123a3a468eeStronupdates. 124e42a9484Sjtc.Sh RETURN VALUES 125e42a9484SjtcThe 126e42a9484Sjtc.Fn pw_lock 127e42a9484Sjtcand 128e42a9484Sjtc.Fn pw_mkdb 129e42a9484Sjtcfunctions return -1 if they are unable to complete properly. 130e42a9484Sjtc.Sh FILES 131e42a9484Sjtc.Bl -tag -width /etc/master.passwd -compact 132e42a9484Sjtc.It Pa /etc/master.passwd 133e42a9484Sjtc.It Pa /etc/ptmp 134e42a9484Sjtc.El 135e42a9484Sjtc.Sh SEE ALSO 1367e44d4f9Sad.Xr pw_init 3 , 1377e44d4f9Sad.Xr pwd_mkdb 8 138