1*0c3983b2SBen Gras.\" $NetBSD: pw_init.3,v 1.15 2010/05/05 22:05:31 wiz Exp $ 2*0c3983b2SBen Gras.\" 3*0c3983b2SBen Gras.\" Copyright (c) 1995 4*0c3983b2SBen Gras.\" The Regents of the University of California. All rights reserved. 5*0c3983b2SBen Gras.\" 6*0c3983b2SBen Gras.\" This code is derived from software developed by the Computer Systems 7*0c3983b2SBen Gras.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 8*0c3983b2SBen Gras.\" BG 91-66 and contributed to Berkeley. 9*0c3983b2SBen Gras.\" 10*0c3983b2SBen Gras.\" Redistribution and use in source and binary forms, with or without 11*0c3983b2SBen Gras.\" modification, are permitted provided that the following conditions 12*0c3983b2SBen Gras.\" are met: 13*0c3983b2SBen Gras.\" 1. Redistributions of source code must retain the above copyright 14*0c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer. 15*0c3983b2SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 16*0c3983b2SBen Gras.\" notice, this list of conditions and the following disclaimer in the 17*0c3983b2SBen Gras.\" documentation and/or other materials provided with the distribution. 18*0c3983b2SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 19*0c3983b2SBen Gras.\" may be used to endorse or promote products derived from this software 20*0c3983b2SBen Gras.\" without specific prior written permission. 21*0c3983b2SBen Gras.\" 22*0c3983b2SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*0c3983b2SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*0c3983b2SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*0c3983b2SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*0c3983b2SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*0c3983b2SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*0c3983b2SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*0c3983b2SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*0c3983b2SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*0c3983b2SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*0c3983b2SBen Gras.\" SUCH DAMAGE. 33*0c3983b2SBen Gras.\" 34*0c3983b2SBen Gras.Dd August 1, 2004 35*0c3983b2SBen Gras.Dt PW_INIT 3 36*0c3983b2SBen Gras.Os 37*0c3983b2SBen Gras.Sh NAME 38*0c3983b2SBen Gras.Nm pw_init , 39*0c3983b2SBen Gras.Nm pw_edit , 40*0c3983b2SBen Gras.Nm pw_prompt , 41*0c3983b2SBen Gras.Nm pw_copy , 42*0c3983b2SBen Gras.Nm pw_copyx , 43*0c3983b2SBen Gras.Nm pw_scan , 44*0c3983b2SBen Gras.Nm pw_error 45*0c3983b2SBen Gras.Nd utility functions for interactive passwd file updates 46*0c3983b2SBen Gras.Sh LIBRARY 47*0c3983b2SBen Gras.Lb libutil 48*0c3983b2SBen Gras.Sh SYNOPSIS 49*0c3983b2SBen Gras.In pwd.h 50*0c3983b2SBen Gras.In util.h 51*0c3983b2SBen Gras.Ft void 52*0c3983b2SBen Gras.Fn pw_init "void" 53*0c3983b2SBen Gras.Ft void 54*0c3983b2SBen Gras.Fn pw_edit "int notsetuid" "const char *filename" 55*0c3983b2SBen Gras.Ft void 56*0c3983b2SBen Gras.Fn pw_prompt "void" 57*0c3983b2SBen Gras.Ft void 58*0c3983b2SBen Gras.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw" 59*0c3983b2SBen Gras.Ft int 60*0c3983b2SBen Gras.Fn pw_copyx "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw" \ 61*0c3983b2SBen Gras "char *errbuf" "size_t errbufsz" 62*0c3983b2SBen Gras.Ft int 63*0c3983b2SBen Gras.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags" 64*0c3983b2SBen Gras.Ft void 65*0c3983b2SBen Gras.Fn pw_error "const char *name" "int err" "int eval" 66*0c3983b2SBen Gras.Sh DESCRIPTION 67*0c3983b2SBen GrasThese functions are designed as conveniences for interactive programs 68*0c3983b2SBen Graswhich update the passwd file and do nothing else. 69*0c3983b2SBen GrasThey generally handle errors by printing out a message to the standard error 70*0c3983b2SBen Grasstream and possibly aborting the process. 71*0c3983b2SBen Gras.Pp 72*0c3983b2SBen GrasThe 73*0c3983b2SBen Gras.Fn pw_init 74*0c3983b2SBen Grasfunction prepares for a passwd update by unlimiting all resource 75*0c3983b2SBen Grasconstraints, disabling core dumps (thus preventing dumping the 76*0c3983b2SBen Grascontents of the passwd database into a world-readable file), and 77*0c3983b2SBen Grasdisabling most signals. 78*0c3983b2SBen Gras.Pp 79*0c3983b2SBen GrasThe 80*0c3983b2SBen Gras.Fn pw_edit 81*0c3983b2SBen Grasfunction runs an editor (named by the environment variable EDITOR, or 82*0c3983b2SBen Gras.Pa /usr/bin/vi 83*0c3983b2SBen Grasif EDITOR is not set) on the file 84*0c3983b2SBen Gras.Fa filename 85*0c3983b2SBen Gras(or 86*0c3983b2SBen Gras.Pa /etc/ptmp 87*0c3983b2SBen Grasif 88*0c3983b2SBen Gras.Fa filename 89*0c3983b2SBen Grasis 90*0c3983b2SBen Gras.Dv NULL ) . 91*0c3983b2SBen GrasIf 92*0c3983b2SBen Gras.Fa notsetuid 93*0c3983b2SBen Grasis nonzero, 94*0c3983b2SBen Gras.Fn pw_edit 95*0c3983b2SBen Graswill set the effective user and group ID to the real user and group ID 96*0c3983b2SBen Grasbefore running the editor. 97*0c3983b2SBen Gras.Pp 98*0c3983b2SBen GrasThe 99*0c3983b2SBen Gras.Fn pw_prompt 100*0c3983b2SBen Grasfunction asks the user whether he or she wants to re-edit the password 101*0c3983b2SBen Grasfile; if the answer is no, 102*0c3983b2SBen Gras.Fn pw_prompt 103*0c3983b2SBen Grasdeletes the lock file and exits the process. 104*0c3983b2SBen Gras.Pp 105*0c3983b2SBen GrasThe 106*0c3983b2SBen Gras.Fn pw_copy 107*0c3983b2SBen Grasfunction reads a passwd file from 108*0c3983b2SBen Gras.Fa ffd 109*0c3983b2SBen Grasand writes it to 110*0c3983b2SBen Gras.Fa tfd , 111*0c3983b2SBen Grasupdating the entry corresponding to pw-\*[Gt]pw_name with the information 112*0c3983b2SBen Grasin 113*0c3983b2SBen Gras.Fa pw . 114*0c3983b2SBen GrasIf 115*0c3983b2SBen Gras.Fa old_pw 116*0c3983b2SBen Grasis not 117*0c3983b2SBen Gras.Dv NULL , 118*0c3983b2SBen Grasit checks to make sure the old entry is the same as 119*0c3983b2SBen Grasthe one described in 120*0c3983b2SBen Gras.Fa old_pw 121*0c3983b2SBen Grasor the process is aborted. 122*0c3983b2SBen GrasIf an entry is not found to match 123*0c3983b2SBen Gras.Fa pw , 124*0c3983b2SBen Grasa new entry is appended to the passwd file only if the real user 125*0c3983b2SBen GrasID is 0. 126*0c3983b2SBen GrasIf an error occurs, 127*0c3983b2SBen Gras.Fn pw_copy 128*0c3983b2SBen Graswill display a message on 129*0c3983b2SBen Gras.Dv stderr 130*0c3983b2SBen Grasand call 131*0c3983b2SBen Gras.Fn pw_error . 132*0c3983b2SBen Gras.Pp 133*0c3983b2SBen GrasThe 134*0c3983b2SBen Gras.Fn pw_copyx 135*0c3983b2SBen Grasfunction performs the same operation as 136*0c3983b2SBen Gras.Fn pw_copy 137*0c3983b2SBen Graswith the exception of error handling. 138*0c3983b2SBen GrasUpon an error, 139*0c3983b2SBen Gras.Fn pw_copyx 140*0c3983b2SBen Graswill write an error message into the buffer pointed to by 141*0c3983b2SBen Gras.Fa errbuf 142*0c3983b2SBen Graswhich has the size 143*0c3983b2SBen Gras.Fa errbufsz . 144*0c3983b2SBen Gras.Pp 145*0c3983b2SBen GrasThe 146*0c3983b2SBen Gras.Fn pw_scan 147*0c3983b2SBen Grasfunction accepts in 148*0c3983b2SBen Gras.Fa bp 149*0c3983b2SBen Grasa passwd entry as it would be represented in 150*0c3983b2SBen Gras.Pa /etc/master.passwd 151*0c3983b2SBen Grasand fills in 152*0c3983b2SBen Gras.Fa pw 153*0c3983b2SBen Graswith corresponding values; string fields in 154*0c3983b2SBen Gras.Fa pw 155*0c3983b2SBen Graswill be pointers into 156*0c3983b2SBen Gras.Fa bp . 157*0c3983b2SBen GrasSome characters in 158*0c3983b2SBen Gras.Fa bp 159*0c3983b2SBen Graswill be overwritten with 0s in order to terminate the strings pointed 160*0c3983b2SBen Grasto by 161*0c3983b2SBen Gras.Fa pw . 162*0c3983b2SBen GrasIf 163*0c3983b2SBen Gras.Fa flags 164*0c3983b2SBen Grasis non-null, it should be cleared and the following options 165*0c3983b2SBen Grasenabled if required: 166*0c3983b2SBen Gras.Bl -tag -offset indent -width _PASSWORD_OLDFMT 167*0c3983b2SBen Gras.It Dv _PASSWORD_NOWARN 168*0c3983b2SBen GrasDon't print warnings. 169*0c3983b2SBen Gras.It Dv _PASSWORD_OLDFMT 170*0c3983b2SBen GrasParse 171*0c3983b2SBen Gras.Fa bp 172*0c3983b2SBen Grasas an old format entry as found in 173*0c3983b2SBen Gras.Pa /etc/passwd . 174*0c3983b2SBen Gras.El 175*0c3983b2SBen Gras.Pp 176*0c3983b2SBen GrasUpon return it is cleared, and filled in with the following flags: 177*0c3983b2SBen Gras.Bl -tag -offset indent -width _PASSWORD_NOGID 178*0c3983b2SBen Gras.It Dv _PASSWORD_NOUID 179*0c3983b2SBen GrasThe uid field of 180*0c3983b2SBen Gras.Fa bp 181*0c3983b2SBen Grasis empty. 182*0c3983b2SBen Gras.It Dv _PASSWORD_NOGID 183*0c3983b2SBen GrasThe gid field of 184*0c3983b2SBen Gras.Fa bp 185*0c3983b2SBen Grasis empty. 186*0c3983b2SBen Gras.It Dv _PASSWORD_NOCHG 187*0c3983b2SBen GrasThe change field of 188*0c3983b2SBen Gras.Fa bp 189*0c3983b2SBen Grasis empty. 190*0c3983b2SBen Gras.It Dv _PASSWORD_NOEXP 191*0c3983b2SBen GrasThe expire field of 192*0c3983b2SBen Gras.Fa bp 193*0c3983b2SBen Grasis empty. 194*0c3983b2SBen Gras.El 195*0c3983b2SBen Gras.Pp 196*0c3983b2SBen GrasThe 197*0c3983b2SBen Gras.Fn pw_error 198*0c3983b2SBen Grasfunction displays an error message, aborts the current passwd update, 199*0c3983b2SBen Grasand exits the current process. 200*0c3983b2SBen GrasIf 201*0c3983b2SBen Gras.Fa err 202*0c3983b2SBen Grasis non-zero, a warning message beginning with 203*0c3983b2SBen Gras.Fa name 204*0c3983b2SBen Grasis printed for the current value of 205*0c3983b2SBen Gras.Va errno . 206*0c3983b2SBen GrasThe process exits with status 207*0c3983b2SBen Gras.Fa eval . 208*0c3983b2SBen Gras.Sh RETURN VALUES 209*0c3983b2SBen GrasThe 210*0c3983b2SBen Gras.Fn pw_copyx 211*0c3983b2SBen Grasfunction returns 1 if the new password entry was successfully written 212*0c3983b2SBen Grasto the destination file, and 0 otherwise. 213*0c3983b2SBen Gras.Pp 214*0c3983b2SBen GrasThe 215*0c3983b2SBen Gras.Fn pw_scan 216*0c3983b2SBen Grasfunction prints a warning message and returns 0 if the string in the 217*0c3983b2SBen Gras.Fa bp 218*0c3983b2SBen Grasargument is not a valid passwd string. 219*0c3983b2SBen GrasOtherwise, 220*0c3983b2SBen Gras.Fn pw_scan 221*0c3983b2SBen Grasreturns 1. 222*0c3983b2SBen Gras.Sh FILES 223*0c3983b2SBen Gras.Bl -tag -width /etc/master.passwd -compact 224*0c3983b2SBen Gras.It Pa /etc/master.passwd 225*0c3983b2SBen Gras.It Pa /etc/ptmp 226*0c3983b2SBen Gras.El 227*0c3983b2SBen Gras.Sh SEE ALSO 228*0c3983b2SBen Gras.Xr pw_lock 3 , 229*0c3983b2SBen Gras.Xr passwd 5 230