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