summaryrefslogtreecommitdiff
path: root/lib/libutil/pw_init.3
blob: 0de0b1a16c2e87182d546e5cb01b350589fc4605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.\" Copyright (c) 1995
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software developed by the Computer Systems
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
.\" BG 91-66 and contributed to Berkeley.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 15, 1995
.Dt PW_INIT 3
.Os
.Sh NAME
.Nm pw_init ,
.Nm pw_edit ,
.Nm pw_prompt ,
.Nm pw_copy ,
.Nm pw_scan ,
.Nm pw_error
.Nd utility functions for interactive passwd file updates
.Sh SYNOPSIS
.Fd #indlude <pwd.h>
.Fd #include <util.h>
.Ft void
.Fn pw_init
.Ft void
.Fn pw_edit "int notsetuid" "const char *filename"
.Ft void
.Fn pw_prompt
.Ft void
.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw"
.Ft int
.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags"
.Ft void
.Fn pw_error "const char *name" "int err" "int eval"
.Sh DESCRIPTION
These functions are designed as conveniences for interactive programs
which update the passwd file and do nothing else.  They generally
handle errors by printing out a message to the standard error stream
and possibly aborting the process.
.Pp
The
.Fn pw_init
function prepares for a passwd update by unlimiting all resource
constraints, disabling core dumps (thus preventing dumping the
contents of the passwd database into a world-readable file), and
disabling most signals.
.Pp
The
.Fn pw_edit
function runs an editor (named by the environment variable EDITOR, or
.Pa /usr/bin/vi
if EDITOR is not set) on the file
.Fa filename
(or
.Pa /etc/ptmp
if
.Fa filename
is NULL).  If
.Fa notsetuid
is nonzero,
.Fn pw_edit
will set the effective user and group ID to the real user and group ID
before running the editor.
.Pp
The
.Fn pw_prompt
function asks the user whether he or she wants to re-edit the password
file; if the answer is no,
.Fn pw_prompt
deletes the lock file and exits the process.
.Pp
The
.Fn pw_copy
function reads a passwd file from
.Fa ffd
and writes it to
.Fa tfd ,
updating the entry corresponding to pw->pw_name with the information
in
.Fa pw .
.Pp
The
.Fn pw_scan
function accepts in
.Fa bp
a passwd entry as it would be represented in
.Pa /etc/master.passwd
and fills in
.Fa pw
with corresponding values; string fields in
.Fa pw
will be pointers into
.Fa bp .
Some characters in
.Fa bp
will be overwritten with 0s in order to terminate the strings pointed
to by
.Fa pw .
If
.Fa flags
is non-null, it is filled in with the following flags:
.Bl -tag -width _PASSWORD_NOGIDxxx
.It Dv _PASSWORD_NOUID
The uid field of
.Fa bp
is empty.
.It Dv _PASSWORD_NOGID
The gid field of
.Fa bp
is empty.
.It Dv _PASSWD_NOCHG
The change field of
.Fa bp
is empty.
.It Dv _PASSWD_NOEXP
The expire field of
.Fa bp
is empty.
.El
.Pp
The
.Fn pw_error
function displays an error message, aborts the current passwd update,
and exits the current process.  If
.Fa err
is non-zero, a warning message beginning with
.Fa name
is printed for the current value of
.Va errno .
The process exits with status
.Fa eval .
.Sh RETURN VALUES
The
.Fn pw_scan
function prints a warning message and returns 0 if the string in the
.Fa bp
argument is not a valid passwd string.  Otherwise,
.Fn pw_scan
returns 1.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/master.passwd
.It Pa /etc/ptmp
.El
.Sh SEE ALSO
.Xr pw_lock 3 ,
.Xr passwd 5