9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / getspnam.3c
blob50c169d9e17f67fd7e177ba438d019e1c24536ef
1 '\" te
2 .\" Copyright (c) 2008 Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T.
4 .\" 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.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" 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 the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH GETSPNAM 3C "Feb 25, 2017"
8 .SH NAME
9 getspnam, getspnam_r, getspent, getspent_r, setspent, endspent, fgetspent,
10 fgetspent_r \- get password entry
11 .SH SYNOPSIS
12 .LP
13 .nf
14 #include <shadow.h>
16 \fBstruct spwd *\fR\fBgetspnam\fR(\fBconst char *\fR\fIname\fR);
17 .fi
19 .LP
20 .nf
21 \fBstruct spwd *\fR\fBgetspnam_r\fR(\fBconst char *\fR\fIname\fR, \fBstruct spwd *\fR\fIresult\fR,
22      \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbuflen\fR);
23 .fi
25 .LP
26 .nf
27 \fBstruct spwd *\fR\fBgetspent\fR(\fBvoid\fR);
28 .fi
30 .LP
31 .nf
32 \fBstruct spwd *\fR\fBgetspent_r\fR(\fBstruct spwd *\fR\fIresult\fR, \fBchar *\fR\fIbuffer\fR,
33      \fBint\fR \fIbuflen\fR);
34 .fi
36 .LP
37 .nf
38 \fBvoid\fR \fBsetspent\fR(\fBvoid\fR);
39 .fi
41 .LP
42 .nf
43 \fBvoid\fR \fBendspent\fR(\fBvoid\fR);
44 .fi
46 .LP
47 .nf
48 \fBstruct spwd *\fR\fBfgetspent\fR(\fBFILE *\fR\fIfp\fR);
49 .fi
51 .LP
52 .nf
53 \fBstruct spwd *\fR\fBfgetspent_r\fR(\fBFILE *\fR\fIfp\fR, \fBstruct spwd *\fR\fIresult\fR,
54      \fBchar *\fR\fIbuffer\fR, \fBint\fR \fIbuflen\fR);
55 .fi
57 .SH DESCRIPTION
58 .LP
59 These functions are used to obtain shadow password entries.  An entry may come
60 from any of the sources for \fBshadow\fR specified in the
61 \fB/etc/nsswitch.conf\fR file (see \fBnsswitch.conf\fR(4)).
62 .sp
63 .LP
64 The \fBgetspnam()\fR function searches for a shadow password entry with the
65 login name specified by the character string argument \fIname\fR.
66 .sp
67 .LP
68 The  \fBsetspent()\fR, \fBgetspent()\fR, and \fBendspent()\fR functions are
69 used to enumerate shadow password entries from the database.
70 .sp
71 .LP
72 The \fBsetspent()\fR function sets (or resets) the enumeration to the beginning
73 of the set of shadow password entries.  This function should be called before
74 the first call to \fBgetspent()\fR. Calls to \fBgetspnam()\fR leave the
75 enumeration position in an indeterminate state.
76 .sp
77 .LP
78 Successive calls to \fBgetspent()\fR return either successive entries or
79 \fINULL\fR, indicating the end of the enumeration.
80 .sp
81 .LP
82 The \fBendspent()\fR function may be called to indicate that the caller expects
83 to do no further shadow password retrieval operations; the system may then
84 close the shadow password file, deallocate resources it was using, and so
85 forth.  It is still allowed, but possibly less efficient, for the process to
86 call more shadow password functions after calling \fBendspent()\fR.
87 .sp
88 .LP
89 The \fBfgetspent()\fR function, unlike the other functions above, does not use
90 \fBnsswitch.conf\fR; it reads and parses the next line from the stream
91 \fIfp\fR, which is assumed to have the format of the \fBshadow\fR file (see
92 \fBshadow\fR(4)).
93 .SS "Reentrant Interfaces"
94 .LP
95 The  \fBgetspnam()\fR, \fBgetspent()\fR, and \fBfgetspent()\fR functions use
96 thread-specific data storage that is reused in each call to one of these
97 functions by the same thread, making them safe to use but not recommended for
98 multithreaded applications.
99 .sp
101 The  \fBgetspnam_r()\fR, \fBgetspent_r()\fR, and \fBfgetspent_r()\fR functions
102 provide reentrant interfaces for these operations.
105 Each reentrant interface performs the same operation as its non-reentrant
106 counterpart, named by removing the  \fB_r\fR suffix.  The reentrant interfaces,
107 however, use buffers supplied by the caller to store returned results, and  are
108 safe for use in both single-threaded and multithreaded applications.
111 Each reentrant interface takes the same argument as its non-reentrant
112 counterpart, as well as the following additional arguments.  The \fIresult\fR
113 argument must be a pointer to a \fBstruct spwd\fR structure allocated by the
114 caller.  On successful completion, the function returns the shadow password
115 entry in this structure. The  \fIbuffer\fR argument must be a pointer to a
116 buffer supplied by the caller.  This buffer is used as storage space for the
117 shadow password data.  All of the pointers within the returned \fBstruct
118 spwd\fR \fIresult\fR point to data stored within this buffer (see \fBRETURN
119 VALUES\fR). The buffer must be large enough to hold all of the data associated
120 with the shadow password entry. The \fIbuflen\fR argument should give the size
121 in bytes of the buffer indicated by \fIbuffer.\fR
124 For enumeration in multithreaded applications, the position within the
125 enumeration is a process-wide property shared by all threads. The
126 \fBsetspent()\fR function may be used in a multithreaded application but resets
127 the enumeration position for all threads.  If multiple threads interleave calls
128 to \fBgetspent_r()\fR, the threads will enumerate disjoint subsets of the
129 shadow password database.
132 Like its non-reentrant counterpart, \fBgetspnam_r()\fR leaves the enumeration
133 position in an indeterminate state.
134 .SH RETURN VALUES
136 Password entries are represented by the \fBstruct spwd\fR structure defined in
137 \fB<shadow.h>\fR:
139 .in +2
141 \fBstruct spwd{
142     char           *sp_namp;     /* login name */
143     char           *sp_pwdp;     /* encrypted passwd */
144     int            sp_lstchg;    /* date of last change */
145     int            sp_min;       /* min days to passwd change */
146     int            sp_max;       /* max days to passwd change*/
147     int            sp_warn;      /* warning period */
148     int            sp_inact;     /* max days inactive */
149     int            sp_expire;    /* account expiry date */
150     unsigned int   sp_flag;      /* not used */
151 };\fR
153 .in -2
157 See \fBshadow\fR(4) for more information on the interpretation of this data.
160 The  \fBgetspnam()\fRand \fBgetspnam_r()\fR functions each return a pointer to
161 a \fBstruct spwd\fR if they successfully locate the requested entry; otherwise
162 they return \fINULL\fR.
165 The  \fBgetspent()\fR, \fBgetspent_r()\fR, \fBfgetspent()\fR, and
166 \fBfgetspent()\fR functions each return a pointer to a \fBstruct spwd\fR if
167 they successfully enumerate an entry; otherwise they return \fINULL\fR,
168 indicating the end of the enumeration.
171 The  \fBgetspnam()\fR, \fBgetspent()\fR, and \fBfgetspent()\fR functions use
172 thread-specific data storage, so returned data must be copied before a
173 subsequent call to any of these functions if the data is to be saved.
176 When the pointer returned by the reentrant functions \fBgetspnam_r()\fR,
177 \fBgetspent_r()\fR, and \fBfgetspent_r()\fR is non-null, it is always equal to
178 the \fIresult\fR pointer that was supplied by the caller.
179 .SH ERRORS
181 The reentrant functions  \fBgetspnam_r()\fR, \fBgetspent_r()\fR, and
182 \fBfgetspent_r()\fR will return \fBNULL\fR and set \fBerrno\fR to \fBERANGE\fR
183 if the length of the buffer supplied by caller is not large enough to store the
184 result.  See \fBIntro\fR(2) for the proper usage and interpretation of
185 \fBerrno\fR in multithreaded applications.
186 .SH ATTRIBUTES
188 See \fBattributes\fR(5) for descriptions of the following attributes:
193 box;
194 c | c
195 l | l .
196 ATTRIBUTE TYPE  ATTRIBUTE VALUE
198 MT-Level        T{
199 See "Reentrant Interfaces" in \fBDESCRIPTION\fR.
203 .SH SEE ALSO
205 \fBpasswd\fR(1), \fByppasswd\fR(1), \fBIntro\fR(3),
206 \fBgetlogin\fR(3C), \fBgetpwnam\fR(3C), \fBnsswitch.conf\fR(4),
207 \fBpasswd\fR(4), \fBshadow\fR(4), \fBattributes\fR(5)
208 .SH WARNINGS
210 The reentrant interfaces \fBgetspnam_r()\fR, \fBgetspent_r()\fR, and
211 \fBfgetspent_r()\fR are included in this release on an uncommitted basis only,
212 and are subject to change or removal in future minor releases.
213 .SH NOTES
215 When compiling multithreaded applications, see \fBIntro\fR(3), \fINotes On
216 Multithreaded Applications\fR, for information about the use of the
217 \fB_REENTRANT\fR flag.
220 Use of the enumeration interfaces \fBgetspent()\fR and \fBgetspent_r()\fR is
221 not recommended; enumeration is supported for the shadow file and \fBNIS\fR
222 but in general is not efficient and may not be supported for all
223 database sources.  The semantics of enumeration are discussed further in
224 \fBnsswitch.conf\fR(4).
227 Access to shadow password information may be restricted in a manner depending
228 on the database source being used.  Access to the \fB/etc/shadow\fR file is
229 generally restricted to processes running with the effective uid of the file
230 owner or the {\fBPRIV_FILE_DAC_READ\fR} privilege.  Other database sources may
231 impose stronger or less stringent restrictions.
234 Empty fields in the database source return -1 values for all fields except
235 \fBsp_pwdp\fR and \fBsp_flag\fR, where the value returned is 0.
238 When \fBNIS\fR is used as the database source,  the information for the shadow
239 password entries is obtained from the ``passwd.byname'' map. This map stores
240 only the information for the \fBsp_namp\fR and \fBsp_pwdp\fR fields of the
241 \fBstruct spwd\fR structure. Shadow password entries obtained from \fBNIS\fR
242 will contain the value \fB-1\fR in the remainder of the fields.