xref: /minix3/lib/libutil/pw_init.3 (revision 0c3983b25a88161cf074524e5c94585a2582ae82)
1.\"	$NetBSD: pw_init.3,v 1.15 2010/05/05 22:05:31 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. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd August 1, 2004
35.Dt PW_INIT 3
36.Os
37.Sh NAME
38.Nm pw_init ,
39.Nm pw_edit ,
40.Nm pw_prompt ,
41.Nm pw_copy ,
42.Nm pw_copyx ,
43.Nm pw_scan ,
44.Nm pw_error
45.Nd utility functions for interactive passwd file updates
46.Sh LIBRARY
47.Lb libutil
48.Sh SYNOPSIS
49.In pwd.h
50.In util.h
51.Ft void
52.Fn pw_init "void"
53.Ft void
54.Fn pw_edit "int notsetuid" "const char *filename"
55.Ft void
56.Fn pw_prompt "void"
57.Ft void
58.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw"
59.Ft int
60.Fn pw_copyx "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw" \
61    "char *errbuf" "size_t errbufsz"
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
90.Dv NULL ) .
91If
92.Fa notsetuid
93is nonzero,
94.Fn pw_edit
95will set the effective user and group ID to the real user and group ID
96before running the editor.
97.Pp
98The
99.Fn pw_prompt
100function asks the user whether he or she wants to re-edit the password
101file; if the answer is no,
102.Fn pw_prompt
103deletes the lock file and exits the process.
104.Pp
105The
106.Fn pw_copy
107function reads a passwd file from
108.Fa ffd
109and writes it to
110.Fa tfd ,
111updating the entry corresponding to pw-\*[Gt]pw_name with the information
112in
113.Fa pw .
114If
115.Fa old_pw
116is not
117.Dv NULL ,
118it checks to make sure the old entry is the same as
119the one described in
120.Fa old_pw
121or the process is aborted.
122If an entry is not found to match
123.Fa pw ,
124a new entry is appended to the passwd file only if the real user
125ID is 0.
126If an error occurs,
127.Fn pw_copy
128will display a message on
129.Dv stderr
130and call
131.Fn pw_error .
132.Pp
133The
134.Fn pw_copyx
135function performs the same operation as
136.Fn pw_copy
137with the exception of error handling.
138Upon an error,
139.Fn pw_copyx
140will write an error message into the buffer pointed to by
141.Fa errbuf
142which has the size
143.Fa errbufsz .
144.Pp
145The
146.Fn pw_scan
147function accepts in
148.Fa bp
149a passwd entry as it would be represented in
150.Pa /etc/master.passwd
151and fills in
152.Fa pw
153with corresponding values; string fields in
154.Fa pw
155will be pointers into
156.Fa bp .
157Some characters in
158.Fa bp
159will be overwritten with 0s in order to terminate the strings pointed
160to by
161.Fa pw .
162If
163.Fa flags
164is non-null, it should be cleared and the following options
165enabled if required:
166.Bl -tag -offset indent -width _PASSWORD_OLDFMT
167.It Dv _PASSWORD_NOWARN
168Don't print warnings.
169.It Dv _PASSWORD_OLDFMT
170Parse
171.Fa bp
172as an old format entry as found in
173.Pa /etc/passwd .
174.El
175.Pp
176Upon return it is cleared, and filled in with the following flags:
177.Bl -tag -offset indent -width _PASSWORD_NOGID
178.It Dv _PASSWORD_NOUID
179The uid field of
180.Fa bp
181is empty.
182.It Dv _PASSWORD_NOGID
183The gid field of
184.Fa bp
185is empty.
186.It Dv _PASSWORD_NOCHG
187The change field of
188.Fa bp
189is empty.
190.It Dv _PASSWORD_NOEXP
191The expire field of
192.Fa bp
193is empty.
194.El
195.Pp
196The
197.Fn pw_error
198function displays an error message, aborts the current passwd update,
199and exits the current process.
200If
201.Fa err
202is non-zero, a warning message beginning with
203.Fa name
204is printed for the current value of
205.Va errno .
206The process exits with status
207.Fa eval .
208.Sh RETURN VALUES
209The
210.Fn pw_copyx
211function returns 1 if the new password entry was successfully written
212to the destination file, and 0 otherwise.
213.Pp
214The
215.Fn pw_scan
216function prints a warning message and returns 0 if the string in the
217.Fa bp
218argument is not a valid passwd string.
219Otherwise,
220.Fn pw_scan
221returns 1.
222.Sh FILES
223.Bl -tag -width /etc/master.passwd -compact
224.It Pa /etc/master.passwd
225.It Pa /etc/ptmp
226.El
227.Sh SEE ALSO
228.Xr pw_lock 3 ,
229.Xr passwd 5
230