1*0d0949deSwiz.\" $NetBSD: pw_lock.3,v 1.14 2010/05/05 22:05:31 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.\" 34e7023c08Swiz.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 97*0d0949deSwizargument is not 98*0d0949deSwiz.Dv NULL , 99*0d0949deSwizonly database entries pertaining to the specified user 10027adb020Swizwill be modified. 10127adb020SwizIf the 1027e44d4f9Sad.Ar secureonly 1037e44d4f9Sadargument is non-zero, only the secure database will be updated. 104e42a9484Sjtc.Pp 105e42a9484SjtcThe 106e42a9484Sjtc.Fn pw_abort 107e42a9484Sjtcfunction aborts a passwd file update by deleting 108e42a9484Sjtc.Pa /etc/ptmp . 109e42a9484SjtcThe passwd database remains unchanged. 110a3a468eeStron.Pp 111a3a468eeStronThe 112a3a468eeStron.Fn pw_setprefix 11327adb020Swizfunction defines the root directory used for passwd file updates. 11427adb020SwizIf the prefix is set to 115a3a468eeStron.Pa /newroot 116a3a468eeStron.Fn pw_lock 117a3a468eeStronwill operate on 118a3a468eeStron.Pa /newroot/etc/ptmp 11927adb020Swizafterwards. 12027adb020SwizThe default prefix is an empty string. 121a3a468eeStron.Pp 122a3a468eeStronThe 123a3a468eeStron.Fn pw_getprefix 124a3a468eeStronfunction returns the root directory which is currently used for passwd file 125a3a468eeStronupdates. 126e42a9484Sjtc.Sh RETURN VALUES 127e42a9484SjtcThe 128e42a9484Sjtc.Fn pw_lock 129e42a9484Sjtcand 130e42a9484Sjtc.Fn pw_mkdb 131e42a9484Sjtcfunctions return -1 if they are unable to complete properly. 132e42a9484Sjtc.Sh FILES 133e42a9484Sjtc.Bl -tag -width /etc/master.passwd -compact 134e42a9484Sjtc.It Pa /etc/master.passwd 135e42a9484Sjtc.It Pa /etc/ptmp 136e42a9484Sjtc.El 137e42a9484Sjtc.Sh SEE ALSO 1387e44d4f9Sad.Xr pw_init 3 , 1397e44d4f9Sad.Xr pwd_mkdb 8 140