1.\" Copyright (c) 1995 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software developed by the Computer Systems 5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 6.\" BG 91-66 and contributed to Berkeley. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.Dd December 15, 1995 37.Dt PW_INIT 3 38.Os 39.Sh NAME 40.Nm pw_init , 41.Nm pw_edit , 42.Nm pw_prompt , 43.Nm pw_copy , 44.Nm pw_scan , 45.Nm pw_error 46.Nd utility functions for interactive passwd file updates 47.Sh SYNOPSIS 48.Fd #indlude <pwd.h> 49.Fd #include <util.h> 50.Ft void 51.Fn pw_init 52.Ft void 53.Fn pw_edit "int notsetuid" "const char *filename" 54.Ft void 55.Fn pw_prompt 56.Ft void 57.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw" 58.Ft int 59.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags" 60.Ft void 61.Fn pw_error "const char *name" "int err" "int eval" 62.Sh DESCRIPTION 63These functions are designed as conveniences for interactive programs 64which update the passwd file and do nothing else. They generally 65handle errors by printing out a message to the standard error stream 66and possibly aborting the process. 67.Pp 68The 69.Fn pw_init 70function prepares for a passwd update by unlimiting all resource 71constraints, disabling core dumps (thus preventing dumping the 72contents of the passwd database into a world-readable file), and 73disabling most signals. 74.Pp 75The 76.Fn pw_edit 77function runs an editor (named by the environment variable EDITOR, or 78.Pa /usr/bin/vi 79if EDITOR is not set) on the file 80.Fa filename 81(or 82.Pa /etc/ptmp 83if 84.Fa filename 85is NULL). If 86.Fa notsetuid 87is nonzero, 88.Fn pw_edit 89will set the effective user and group ID to the real user and group ID 90before running the editor. 91.Pp 92The 93.Fn pw_prompt 94function asks the user whether he or she wants to re-edit the password 95file; if the answer is no, 96.Fn pw_prompt 97deletes the lock file and exits the process. 98.Pp 99The 100.Fn pw_copy 101function reads a passwd file from 102.Fa ffd 103and writes it to 104.Fa tfd , 105updating the entry corresponding to pw->pw_name with the information 106in 107.Fa pw . 108If 109.Fa old_pw 110is not NULL, it checks to make sure the old entry is the same as 111the one described in 112.Fa old_pw 113or the process is aborted. If an entry is not found to match 114.Fa pw , 115a new entry is appended to the passwd file only if the real user 116ID is 0. 117.Pp 118The 119.Fn pw_scan 120function accepts in 121.Fa bp 122a passwd entry as it would be represented in 123.Pa /etc/master.passwd 124and fills in 125.Fa pw 126with corresponding values; string fields in 127.Fa pw 128will be pointers into 129.Fa bp . 130Some characters in 131.Fa bp 132will be overwritten with 0s in order to terminate the strings pointed 133to by 134.Fa pw . 135If 136.Fa flags 137is non-null, it is filled in with the following flags: 138.Bl -tag -width _PASSWORD_NOGIDxxx 139.It Dv _PASSWORD_NOUID 140The uid field of 141.Fa bp 142is empty. 143.It Dv _PASSWORD_NOGID 144The gid field of 145.Fa bp 146is empty. 147.It Dv _PASSWD_NOCHG 148The change field of 149.Fa bp 150is empty. 151.It Dv _PASSWD_NOEXP 152The expire field of 153.Fa bp 154is empty. 155.El 156.Pp 157The 158.Fn pw_error 159function displays an error message, aborts the current passwd update, 160and exits the current process. If 161.Fa err 162is non-zero, a warning message beginning with 163.Fa name 164is printed for the current value of 165.Va errno . 166The process exits with status 167.Fa eval . 168.Sh RETURN VALUES 169The 170.Fn pw_scan 171function prints a warning message and returns 0 if the string in the 172.Fa bp 173argument is not a valid passwd string. Otherwise, 174.Fn pw_scan 175returns 1. 176.Sh FILES 177.Bl -tag -width /etc/master.passwd -compact 178.It Pa /etc/master.passwd 179.It Pa /etc/ptmp 180.El 181.Sh SEE ALSO 182.Xr pw_lock 3 , 183.Xr passwd 5 184