8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / getpwnam.3c
blob1af5c7aa44ac34ac466674c1e81ef16fbe625b39
1 '\" te
2 .\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at  http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
7 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
8 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
9 .\"  This notice shall appear on any product containing this material.
10 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
11 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
12 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
13 .TH GETPWNAM 3C "Feb 25, 2017"
14 .SH NAME
15 getpwnam, getpwnam_r, getpwent, getpwent_r, getpwuid, getpwuid_r, setpwent,
16 endpwent, fgetpwent, fgetpwent_r \- get password entry
17 .SH SYNOPSIS
18 .LP
19 .nf
20 #include <pwd.h>
22 \fBstruct passwd *\fR\fBgetpwnam\fR(\fBconst char *\fR\fIname\fR);
23 .fi
25 .LP
26 .nf
27 \fBstruct passwd *\fR\fBgetpwnam_r\fR(\fBconst char *\fR\fIname\fR, \fBstruct passwd *\fR\fIpwd\fR,
28      \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbuflen\fR);
29 .fi
31 .LP
32 .nf
33 \fBstruct passwd *\fR\fBgetpwent\fR(\fBvoid\fR);
34 .fi
36 .LP
37 .nf
38 \fBstruct passwd *\fR\fBgetpwent_r\fR(\fBstruct passwd *\fR\fIpwd\fR, \fBchar *\fR\fIbuffer\fR,
39      \fBint\fR \fIbuflen\fR);
40 .fi
42 .LP
43 .nf
44 \fBstruct passwd *\fR\fBgetpwuid\fR(\fBuid_t\fR \fIuid\fR);
45 .fi
47 .LP
48 .nf
49 \fBstruct passwd *\fR\fBgetpwuid_r\fR(\fBuid_t\fR \fIuid\fR, \fBstruct passwd *\fR\fIpwd\fR,
50     \fBchar *\fR\fIbuffer\fR, \fBint\fR  \fIbuflen\fR);
51 .fi
53 .LP
54 .nf
55 \fBvoid\fR \fBsetpwent\fR(\fBvoid\fR);
56 .fi
58 .LP
59 .nf
60 \fBvoid\fR \fBendpwent\fR(\fBvoid\fR);
61 .fi
63 .LP
64 .nf
65 \fBstruct passwd *\fR\fBfgetpwent\fR(\fBFILE *\fR\fIf\fR);
66 .fi
68 .LP
69 .nf
70 \fBstruct passwd *\fR\fBfgetpwent_r\fR(\fBFILE *\fR\fIf\fR, \fBstruct passwd *\fR\fIpwd\fR,
71      \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbuflen\fR);
72 .fi
74 .SS "Standard conforming"
75 .LP
76 .nf
77 cc [ \fIflag\fR...] \fIfile\fR... \fB-D_POSIX_PTHREAD_SEMANTICS\fR [ \fIlibrary\fR... ]
79 \fBint\fR \fBgetpwnam_r\fR(\fBconst char *\fR\fIname\fR, \fBstruct passwd *\fR\fIpwd\fR, \fBchar *\fR\fIbuffer\fR,
80      \fBsize_t\fR \fIbufsize\fR, \fBstruct passwd **\fR\fIresult\fR);
81 .fi
83 .LP
84 .nf
85 \fBint\fR \fBgetpwuid_r\fR(\fBuid_t\fR \fIuid\fR, \fBstruct passwd *\fR\fIpwd\fR, \fBchar *\fR\fIbuffer\fR,
86      \fBsize_t\fR \fIbufsize\fR, \fBstruct passwd **\fR\fIresult\fR);
87 .fi
89 .SH DESCRIPTION
90 .LP
91 These functions are used to obtain password entries. Entries can come from any
92 of the sources for \fBpasswd\fR specified in the \fB/etc/nsswitch.conf\fR file
93 (see \fBnsswitch.conf\fR(4)).
94 .sp
95 .LP
96 The \fBgetpwnam()\fR function searches for a password entry with the login name
97 specified by the character string parameter \fIname\fR.
98 .sp
99 .LP
100 The \fBgetpwuid()\fR function searches for a password entry with the (numeric)
101 user \fBID\fR specified by the \fIuid\fR parameter.
104 The \fBsetpwent()\fR, \fBgetpwent()\fR, and \fBendpwent()\fR functions are used
105 to enumerate password entries from the database. The \fBsetpwent()\fR function
106 sets (or resets) the enumeration to the beginning of the set of password
107 entries. This function should be called before the first call to
108 \fBgetpwent()\fR. Calls to \fBgetpwnam()\fR and \fBgetpwuid()\fR leave the
109 enumeration position in an indeterminate state. Successive calls to
110 \fBgetpwent()\fR return either successive entries or a null pointer, indicating
111 the end of the enumeration.
114 The \fBendpwent()\fR function may be called to indicate that the caller expects
115 to do no further password retrieval operations; the system may then  close the
116 password file, deallocate resources it was using, and so forth.  It is still
117 allowed, but possibly less efficient, for the process to call more password
118 functions after calling \fBendpwent()\fR.
121 The \fBfgetpwent()\fR function, unlike the other functions above, does not use
122 \fBnsswitch.conf\fR but reads and parses the next line from the stream \fIf\fR,
123 which is assumed to have the format of the \fBpasswd\fR file.  See
124 \fBpasswd\fR(4).
125 .SS "Reentrant Interfaces"
127 The \fBgetpwnam()\fR, \fBgetpwuid()\fR, \fBgetpwent()\fR, and \fBfgetpwent()\fR
128 functions use thread-specific data storage that is reused in each call to one
129 of these functions by the same thread, making them safe to use but not
130 recommended for multithreaded applications.
133 The parallel functions \fBgetpwnam_r()\fR, \fBgetpwuid_r()\fR,
134 \fBgetpwent_r()\fR, and \fBfgetpwent_r()\fR provide reentrant interfaces for
135 these operations.
138 Each reentrant interface performs the same operation as its non-reentrant
139 counterpart, named by removing the "\|_r\|" suffix. The reentrant interfaces,
140 however, use buffers supplied by the caller to store returned results instead
141 of using thread-specific data that can be overwritten by each call. They are
142 safe for use in both single-threaded and multithreaded applications.
145 Each reentrant interface takes the same parameters as its non-reentrant
146 counterpart, as well as the following additional parameters. The \fIpwd\fR
147 parameter must be a pointer to a \fBstruct passwd\fR structure allocated by the
148 caller. On successful completion, the function returns the password entry in
149 this structure. The parameter \fIbuffer\fR is a pointer to a buffer supplied by
150 the caller, used as storage space for the password data. All pointers within
151 the returned \fBstruct passwd\fR \fIpwd\fR point to data stored within this
152 buffer; see \fBpasswd Structure\fR below. The buffer must be large enough to
153 hold all the data associated with the password entry. The parameter
154 \fIbuflen\fR (or \fIbufsize\fR for the standard-conforming versions; see
155 \fBstandards\fR(5)) should give the size in bytes of \fIbuffer\fR. The maximum
156 size needed for this buffer can be determined with the
157 {\fB_SC_GETPW_R_SIZE_MAX\fR} \fBsysconf\fR(3C) parameter. The
158 standard-conforming versions place a pointer to the modified \fIpwd\fR
159 structure in the \fIresult\fR parameter, instead of returning a pointer to this
160 structure. A null pointer is returned at the location pointed to by
161 \fIresult\fR on error or if the requested entry is not found.
164 For enumeration in multithreaded applications, the position within the
165 enumeration is a process-wide property shared by all threads. The
166 \fBsetpwent()\fR function can be used in a multithreaded application but resets
167 the enumeration position for all threads.  If multiple threads interleave calls
168 to \fBgetpwent_r()\fR, the threads will enumerate disjoint subsets of the
169 password database.
172 Like their non-reentrant counterparts, \fBgetpwnam_r()\fR and
173 \fBgetpwuid_r()\fR leave the enumeration position in an indeterminate state.
174 .SS "passwd Structure"
176 Password entries are represented by the \fBstruct passwd\fR structure defined
177 in <\fBpwd.h\fR>:
179 .in +2
181 struct passwd {
182     char *pw_name;      /* user's login name */
183     char *pw_passwd;    /* no longer used */
184     uid_t pw_uid;       /* user's uid */
185     gid_t pw_gid;       /* user's gid */
186     char *pw_age;       /* not used */
187     char *pw_comment;   /* not used */
188     char *pw_gecos;     /* typically user's full name */
189     char *pw_dir;       /* user's home dir */
190     char *pw_shell;     /* user's login shell */
193 .in -2
197 The \fBpw_passwd\fR member should not be used as the encrypted password for the
198 user; use \fBgetspnam()\fR or \fBgetspnam_r()\fR instead. See
199 \fBgetspnam\fR(3C).
200 .SH RETURN VALUES
202 The \fBgetpwnam()\fR, \fBgetpwnam_r()\fR, \fBgetpwuid()\fR, and
203 \fBgetpwuid_r()\fR functions each return a pointer to a \fBstruct passwd\fR if
204 they successfully locate the requested entry. A null pointer is returned if the
205 requested entry is not found, or an error occurs. On error, \fBerrno\fR is set
206 to indicate the error.
209 Applications wishing to check for error situations should set \fBerrno\fR to 0
210 before calling \fBgetpwnam()\fR, \fBgetpwnam_r()\fR, \fBgetpwuid()\fR,
211 \fBgetpwuid_r()\fR, \fBgetpwent()\fR, \fBgetpwent_r()\fR, \fBfgetpwent()\fR,
212 and \fBfgetpwent_r()\fR. If these non-reentrant functions return a null pointer
213 and \fBerrno\fR is non-zero, an error occurred.
216 The standard-conforming functions \fBgetpwnam_r()\fR and \fBgetpwuid_r()\fR can
217 return \fB0\fR even on an error, particularly in the case where the requested
218 entry is not found. The application needs to check the return value and that
219 the \fIpwd\fR pointer is non-null. Otherwise, an error value is returned to
220 indicate the error.
223 The \fBgetpwent()\fR, \fBgetpwent_r()\fR, \fBfgetpwent()\fR, and
224 \fBfgetpwent_r()\fR functions each return a pointer to a \fBstruct passwd\fR if
225 they successfully enumerate an entry; otherwise they return a null pointer on
226 end-of-file or error. On error, \fBerrno\fR is set to indicate the error.
229 See \fBIntro\fR(2) for the proper usage and interpretation of \fBerrno\fR in
230 multithreaded applications.
233 The \fBgetpwnam()\fR, \fBgetpwuid()\fR, \fBgetpwent()\fR, and \fBfgetpwent()\fR
234 functions use thread-specific data storage, so returned data must be copied
235 before a subsequent call to any of these functions if the data is to be saved.
238 When the pointer returned by the reentrant functions \fBgetpwnam_r()\fR,
239 \fBgetpwuid_r()\fR, \fBgetpwent_r()\fR, and \fBfgetpwent_r()\fR is non-null, it
240 is always equal to the \fIpwd\fR pointer that was supplied by the caller.
241 .SH ERRORS
243 The \fBgetpwent_r()\fR, \fBfgetpwent()\fR, and \fBfgetpwent_r()\fR functions
244 will fail if:
246 .ne 2
248 \fB\fBEIO\fR\fR
250 .RS 10n
251 An I/O error has occurred.
255 .ne 2
257 \fB\fBERANGE\fR\fR
259 .RS 10n
260 Insufficient storage was supplied by \fIbuffer\fR and \fIbufsize\fR to contain
261 the data to be referenced by the resulting \fBpasswd\fR structure.
266 The \fBgetpwent_r()\fR function will fail if:
268 .ne 2
270 \fB\fBEMFILE\fR\fR
272 .RS 10n
273 There are {\fBOPEN_MAX\fR} file descriptors currently open in the calling
274 process.
278 .ne 2
280 \fB\fBENFILE\fR\fR
282 .RS 10n
283 The maximum allowable number of files is currently open in the system.
288 The \fBgetpwnam()\fR, \fBgetpwnam_r()\fR, \fBgetpwuid()\fR, \fBgetpwuid_r()\fR,
289 \fBgetpwent()\fR, \fBsetpwent()\fR, and \fBendpwent()\fR functions may fail if:
291 .ne 2
293 \fB\fBEIO\fR\fR
295 .RS 7n
296 An I/O error has occurred.
301 The \fBgetpwnam()\fR, \fBgetpwnam_r()\fR, \fBgetpwuid()\fR, \fBgetpwuid_r()\fR,
302 \fBgetpwent()\fR, and \fBsetpwent()\fR functions may fail if:
304 .ne 2
306 \fB\fBEMFILE\fR\fR
308 .RS 10n
309 There are {\fBOPEN_MAX\fR} file descriptors currently open in the calling
310 process.
314 .ne 2
316 \fB\fBENFILE\fR\fR
318 .RS 10n
319 The maximum allowable number of files is currently open in the system.
324 The \fBgetpwnam()\fR, \fBgetpwnam_r()\fR, \fBgetpwuid()\fR, and
325 \fBgetpwuid_r()\fR functions may fail if:
327 .ne 2
329 \fB\fBEINTR\fR\fR
331 .RS 9n
332 A signal was caught during the execution of the function call.
337 The \fBgetpwnam_r()\fR and \fBgetpwuid_r()\fR functions may fail if:
339 .ne 2
341 \fB\fBERANGE\fR\fR
343 .RS 10n
344 Insufficient storage was supplied by \fIbuffer\fR and \fIbufsize\fR to contain
345 the data to be referenced by the resulting \fBpasswd\fR structure.
348 .SH USAGE
350 Three names associated with the current process can be determined:
351 \fBgetpwuid\fR(\fBgeteuid()\fR) returns the name associated with the effective
352 user ID of the process; \fBgetlogin()\fR returns the name associated with the
353 current login activity; and \fBgetpwuid\fR(\fBgetuid()\fR) returns the name
354 associated with the real user ID of the process.
355 .SH ATTRIBUTES
357 See \fBattributes\fR(5) for descriptions of the following attributes:
362 box;
363 c | c
364 l | l .
365 ATTRIBUTE TYPE  ATTRIBUTE VALUE
367 Interface Stability     Committed
369 MT-Level        See \fBReentrant Interfaces\fR in \fBDESCRIPTION\fR.
371 Standard        See below.
376 For \fBendpwent()\fR,  \fBgetpwent()\fR,  \fBgetpwnam()\fR,
377 \fBgetpwnam_r()\fR, \fBgetpwuid()\fR, \fBgetpwuid_r()\fR, and \fBsetpwent()\fR,
378 see \fBstandards\fR(5).
379 .SH SEE ALSO
381 \fBpasswd\fR(1), \fByppasswd\fR(1), \fBIntro\fR(2),
382 \fBIntro\fR(3), \fBcuserid\fR(3C), \fBgetgrnam\fR(3C), \fBgetlogin\fR(3C),
383 \fBgetspnam\fR(3C), \fBnsswitch.conf\fR(4), \fBpasswd\fR(4), \fBshadow\fR(4),
384 \fBattributes\fR(5), \fBstandards\fR(5)
385 .SH NOTES
387 When compiling multithreaded programs, see \fBIntro\fR(3).
390 Use of the enumeration interfaces \fBgetpwent()\fR and \fBgetpwent_r()\fR is
391 discouraged; enumeration is supported for the \fBpasswd\fR file and \fBNIS\fR
392 but in general is not efficient and might not be supported for all
393 database sources.  The semantics of enumeration are discussed further in
394 \fBnsswitch.conf\fR(4).
397 Previous releases allowed the use of `+' and `-' entries in \fB/etc/passwd\fR
398 to selectively include and exclude \fBNIS\fR entries. The primary usage of
399 these `+/-' entries is superseded by the name service switch, so the `+/-' form
400 might not be supported in future releases.
403 If required, the `+/-' functionality can still be obtained for \fBNIS\fR by
404 specifying \fBcompat\fR as the source for \fBpasswd\fR. See
405 \fBnsswitch.conf\fR(4).
408 If the `+/-' is used, both \fB/etc/shadow\fR and \fB/etc/passwd\fR should have
409 the same `+' and `-' entries to ensure consistency between the password and
410 shadow databases.
413 If a password entry from any of the sources contains an empty \fIuid\fR or
414 \fIgid\fR field, that entry will be ignored by the files and \fBNIS\fR
415 name service switch backends, causing the user to appear unknown to
416 the system.
419 If a password entry contains an empty \fIgecos\fR, \fIhome directory\fR, or
420 \fIshell\fR field, \fBgetpwnam()\fR and \fBgetpwnam_r()\fR return a pointer to
421 a null string in the respective field of the \fBpasswd\fR structure.
424 If the shell field is empty, \fBlogin\fR(1) automatically assigns the default
425 shell.  See \fBlogin\fR(1).
428 Solaris 2.4 and earlier releases provided definitions of the \fBgetpwnam_r()\fR
429 and \fBgetpwuid_r()\fR functions as specified in POSIX.1c Draft 6. The final
430 POSIX.1c standard changed the interface for these functions. Support for the
431 Draft 6 interface is provided for compatibility only and might not be supported
432 in future releases. New applications and libraries should use the
433 standard-conforming interface.
436 For POSIX.1c-conforming applications, the \fB_POSIX_PTHREAD_SEMANTICS\fR and
437 \fB_REENTRANT\fR flags are automatically turned on by defining the
438 \fB_POSIX_C_SOURCE\fR flag with a value \(>=199506L.