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