1*7e44d4f9Sad.\" $NetBSD: pw_lock.3,v 1.7 2001/08/18 19:31:48 ad 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. 18e42a9484Sjtc.\" 3. All advertising materials mentioning features or use of this software 19e42a9484Sjtc.\" must display the following acknowledgement: 20e42a9484Sjtc.\" This product includes software developed by the University of 21e42a9484Sjtc.\" California, Berkeley and its contributors. 22e42a9484Sjtc.\" 4. Neither the name of the University nor the names of its contributors 23e42a9484Sjtc.\" may be used to endorse or promote products derived from this software 24e42a9484Sjtc.\" without specific prior written permission. 25e42a9484Sjtc.\" 26e42a9484Sjtc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27e42a9484Sjtc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28e42a9484Sjtc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29e42a9484Sjtc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30e42a9484Sjtc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31e42a9484Sjtc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32e42a9484Sjtc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33e42a9484Sjtc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34e42a9484Sjtc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35e42a9484Sjtc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36e42a9484Sjtc.\" SUCH DAMAGE. 37e42a9484Sjtc.\" 38*7e44d4f9Sad.Dd August 18, 2001 39e42a9484Sjtc.Dt PW_LOCK 3 40e42a9484Sjtc.Os 41e42a9484Sjtc.Sh NAME 42e42a9484Sjtc.Nm pw_lock , 43e42a9484Sjtc.Nm pw_mkdb , 44a3a468eeStron.Nm pw_abort , 45a3a468eeStron.Nm pw_setprefix , 46a3a468eeStron.Nm pw_getprefix 47e42a9484Sjtc.Nd passwd file update functions 48312aca53Sperry.Sh LIBRARY 49312aca53Sperry.Lb libutil 50e42a9484Sjtc.Sh SYNOPSIS 51e42a9484Sjtc.Fd #include <util.h> 52e42a9484Sjtc.Ft int 53e42a9484Sjtc.Fn pw_lock "int retries" 54e42a9484Sjtc.Ft int 55*7e44d4f9Sad.Fn pw_mkdb "const char *username, int secureonly" 56e42a9484Sjtc.Ft void 57e8362050Sad.Fn pw_abort "void" 58a3a468eeStron.Ft void 59a3a468eeStron.Fn pw_error "const char *name" "int err" "int eval" 60a3a468eeStron.Ft int 61a3a468eeStron.Fn pw_setprefix "const char *new_prefix" 62a3a468eeStron.Ft "const char *" 63a3a468eeStron.Fn pw_getprefix "void" 64e42a9484Sjtc.Sh DESCRIPTION 65e42a9484SjtcThe 66e42a9484Sjtc.Fn pw_lock , 67e42a9484Sjtc.Fn pw_mkdb , 68e42a9484Sjtcand 69e42a9484Sjtc.Fn pw_abort 70e42a9484Sjtcfunctions allow a program to update the system passwd database. 71e42a9484Sjtc.Pp 72e42a9484SjtcThe 73e42a9484Sjtc.Fn pw_lock 74e42a9484Sjtcfunction attempts to lock the passwd database by creating the file 75e42a9484Sjtc.Pa /etc/ptmp , 76e42a9484Sjtcand returns the file descriptor of that file. If 77e42a9484Sjtc.Fa retries 78e42a9484Sjtcis greater than zero, 79e42a9484Sjtc.Fn pw_lock 80e42a9484Sjtcwill try multiple times to open 81e42a9484Sjtc.Pa /etc/ptmp , 82e42a9484Sjtcwaiting one second between tries. In addition to being a lock file, 83e42a9484Sjtc.Pa /etc/ptmp 84e42a9484Sjtcwill also hold the contents of the new passwd file. 85e42a9484Sjtc.Pp 86e42a9484SjtcThe 87e42a9484Sjtc.Fn pw_mkdb 88e42a9484Sjtcfunction updates the passwd file from the contents of 89e42a9484Sjtc.Pa /etc/ptmp . 90e42a9484SjtcYou should finish writing to and close the file descriptor returned by 91e42a9484Sjtc.Fn pw_lock 92e42a9484Sjtcbefore calling 93e42a9484Sjtc.Fn pw_mkdb . 9423beafabSghudsonIf 9523beafabSghudson.Fn pw_mkdb 9623beafabSghudsonfails and you do not wish to retry, you should make sure to call 9723beafabSghudson.Fn pw_abort 98*7e44d4f9Sadto clean up the lock file. If the 99*7e44d4f9Sad.Ar username 100*7e44d4f9Sadargument is not NULL, only database entries pertaining to the specified user 101*7e44d4f9Sadwill be modified. If the 102*7e44d4f9Sad.Ar secureonly 103*7e44d4f9Sadargument 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 113a3a468eeStronfunction defines the root directory used for passwd file updates. If 114a3a468eeStronthe prefix is set to 115a3a468eeStron.Pa /newroot 116a3a468eeStron.Fn pw_lock 117a3a468eeStronwill operate on 118a3a468eeStron.Pa /newroot/etc/ptmp 119a3a468eeStronafterwards. The default prefix is an empty string. 120a3a468eeStron.Pp 121a3a468eeStronThe 122a3a468eeStron.Fn pw_getprefix 123a3a468eeStronfunction returns the root directory which is currently used for passwd file 124a3a468eeStronupdates. 125e42a9484Sjtc.Sh RETURN VALUES 126e42a9484SjtcThe 127e42a9484Sjtc.Fn pw_lock 128e42a9484Sjtcand 129e42a9484Sjtc.Fn pw_mkdb 130e42a9484Sjtcfunctions return -1 if they are unable to complete properly. 131e42a9484Sjtc.Sh FILES 132e42a9484Sjtc.Bl -tag -width /etc/master.passwd -compact 133e42a9484Sjtc.It Pa /etc/master.passwd 134e42a9484Sjtc.It Pa /etc/ptmp 135e42a9484Sjtc.El 136e42a9484Sjtc.Sh SEE ALSO 137*7e44d4f9Sad.Xr pw_init 3 , 138*7e44d4f9Sad.Xr pwd_mkdb 8