xref: /netbsd-src/lib/libutil/pw_init.3 (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1.\"	$NetBSD: pw_init.3,v 1.3 1998/01/09 04:12:22 perry 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 SYNOPSIS
50.Fd #indlude <pwd.h>
51.Fd #include <util.h>
52.Ft void
53.Fn pw_init
54.Ft void
55.Fn pw_edit "int notsetuid" "const char *filename"
56.Ft void
57.Fn pw_prompt
58.Ft void
59.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw" "struct passwd *old_pw"
60.Ft int
61.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags"
62.Ft void
63.Fn pw_error "const char *name" "int err" "int eval"
64.Sh DESCRIPTION
65These functions are designed as conveniences for interactive programs
66which update the passwd file and do nothing else.  They generally
67handle errors by printing out a message to the standard error stream
68and possibly aborting the process.
69.Pp
70The
71.Fn pw_init
72function prepares for a passwd update by unlimiting all resource
73constraints, disabling core dumps (thus preventing dumping the
74contents of the passwd database into a world-readable file), and
75disabling most signals.
76.Pp
77The
78.Fn pw_edit
79function runs an editor (named by the environment variable EDITOR, or
80.Pa /usr/bin/vi
81if EDITOR is not set) on the file
82.Fa filename
83(or
84.Pa /etc/ptmp
85if
86.Fa filename
87is NULL).  If
88.Fa notsetuid
89is nonzero,
90.Fn pw_edit
91will set the effective user and group ID to the real user and group ID
92before running the editor.
93.Pp
94The
95.Fn pw_prompt
96function asks the user whether he or she wants to re-edit the password
97file; if the answer is no,
98.Fn pw_prompt
99deletes the lock file and exits the process.
100.Pp
101The
102.Fn pw_copy
103function reads a passwd file from
104.Fa ffd
105and writes it to
106.Fa tfd ,
107updating the entry corresponding to pw->pw_name with the information
108in
109.Fa pw .
110If
111.Fa old_pw
112is not NULL, it checks to make sure the old entry is the same as
113the one described in
114.Fa old_pw
115or the process is aborted.  If an entry is not found to match
116.Fa pw ,
117a new entry is appended to the passwd file only if the real user
118ID is 0.
119.Pp
120The
121.Fn pw_scan
122function accepts in
123.Fa bp
124a passwd entry as it would be represented in
125.Pa /etc/master.passwd
126and fills in
127.Fa pw
128with corresponding values; string fields in
129.Fa pw
130will be pointers into
131.Fa bp .
132Some characters in
133.Fa bp
134will be overwritten with 0s in order to terminate the strings pointed
135to by
136.Fa pw .
137If
138.Fa flags
139is non-null, it is filled in with the following flags:
140.Bl -tag -width _PASSWORD_NOGIDxxx
141.It Dv _PASSWORD_NOUID
142The uid field of
143.Fa bp
144is empty.
145.It Dv _PASSWORD_NOGID
146The gid field of
147.Fa bp
148is empty.
149.It Dv _PASSWD_NOCHG
150The change field of
151.Fa bp
152is empty.
153.It Dv _PASSWD_NOEXP
154The expire field of
155.Fa bp
156is empty.
157.El
158.Pp
159The
160.Fn pw_error
161function displays an error message, aborts the current passwd update,
162and exits the current process.  If
163.Fa err
164is non-zero, a warning message beginning with
165.Fa name
166is printed for the current value of
167.Va errno .
168The process exits with status
169.Fa eval .
170.Sh RETURN VALUES
171The
172.Fn pw_scan
173function prints a warning message and returns 0 if the string in the
174.Fa bp
175argument is not a valid passwd string.  Otherwise,
176.Fn pw_scan
177returns 1.
178.Sh FILES
179.Bl -tag -width /etc/master.passwd -compact
180.It Pa /etc/master.passwd
181.It Pa /etc/ptmp
182.El
183.Sh SEE ALSO
184.Xr pw_lock 3 ,
185.Xr passwd 5
186