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