1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
1 |
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved |
2
by Francesco Paolo Lovergine
* Alligned to linux main manpages edition. |
2 |
.TH "GETPWUID" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual" |
1
by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages. |
3 |
.\" getpwuid |
4 |
.SH NAME |
|
5 |
getpwuid, getpwuid_r \- search user database for a user ID
|
|
6 |
.SH SYNOPSIS |
|
7 |
.LP
|
|
8 |
\fB#include <pwd.h>
|
|
9 |
.br
|
|
10 |
.sp
|
|
11 |
struct passwd *getpwuid(uid_t\fP \fIuid\fP\fB); |
|
12 |
.br
|
|
13 |
\fP
|
|
14 |
.LP
|
|
15 |
\fBint getpwuid_r(uid_t\fP \fIuid\fP\fB, struct passwd *\fP\fIpwd\fP\fB, |
|
16 |
char |
|
17 |
*\fP\fIbuffer\fP\fB, |
|
18 |
.br
|
|
19 |
\ \ \ \ \ \ size_t\fP \fIbufsize\fP\fB, struct passwd **\fP\fIresult\fP\fB); |
|
20 |
\fP
|
|
21 |
\fB
|
|
22 |
.br
|
|
23 |
\fP
|
|
24 |
.SH DESCRIPTION |
|
25 |
.LP
|
|
26 |
The \fIgetpwuid\fP() function shall search the user database for an |
|
27 |
entry with a matching \fIuid\fP. |
|
28 |
.LP
|
|
29 |
The \fIgetpwuid\fP() function need not be reentrant. A function that |
|
30 |
is not required to be reentrant is not required to be |
|
31 |
thread-safe. |
|
32 |
.LP
|
|
33 |
Applications wishing to check for error situations should set \fIerrno\fP |
|
34 |
to 0 before calling \fIgetpwuid\fP(). If |
|
35 |
\fIgetpwuid\fP() returns a null pointer and \fIerrno\fP is set to |
|
36 |
non-zero, an error occurred. |
|
37 |
.LP
|
|
38 |
The \fIgetpwuid_r\fP() function shall update the \fBpasswd\fP structure |
|
39 |
pointed to by \fIpwd\fP and store a pointer to that |
|
40 |
structure at the location pointed to by \fIresult\fP. The structure |
|
41 |
shall contain an entry from the user database with a matching |
|
42 |
\fIuid\fP. Storage referenced by the structure is allocated from the |
|
43 |
memory provided with the \fIbuffer\fP parameter, which is |
|
44 |
\fIbufsize\fP bytes in size. The maximum size needed for this buffer |
|
45 |
can be determined with the {_SC_GETPW_R_SIZE_MAX} \fIsysconf\fP() |
|
46 |
parameter. A NULL pointer shall be returned at the location pointed |
|
47 |
to by |
|
48 |
\fIresult\fP on error or if the requested entry is not found. |
|
49 |
.SH RETURN VALUE |
|
50 |
.LP
|
|
51 |
The \fIgetpwuid\fP() function shall return a pointer to a \fBstruct |
|
52 |
passwd\fP with the structure as defined in \fI<pwd.h>\fP with a matching |
|
53 |
entry if found. A null pointer shall be returned if the requested |
|
54 |
entry is not found, or an error occurs. On error, \fIerrno\fP shall |
|
55 |
be set to indicate the error. |
|
56 |
.LP
|
|
57 |
The return value may point to a static area which is overwritten by |
|
58 |
a subsequent call to \fIgetpwent\fP(), \fIgetpwnam\fP(), or |
|
59 |
\fIgetpwuid\fP(). |
|
60 |
.LP
|
|
61 |
If successful, the \fIgetpwuid_r\fP() function shall return zero; |
|
62 |
otherwise, an error number shall be returned to indicate the |
|
63 |
error. |
|
64 |
.SH ERRORS |
|
65 |
.LP
|
|
66 |
The \fIgetpwuid\fP() and \fIgetpwuid_r\fP() functions may fail if: |
|
67 |
.TP 7 |
|
68 |
.B EIO |
|
69 |
An I/O error has occurred. |
|
70 |
.TP 7 |
|
71 |
.B EINTR |
|
72 |
A signal was caught during \fIgetpwuid\fP(). |
|
73 |
.TP 7 |
|
74 |
.B EMFILE |
|
75 |
{OPEN_MAX} file descriptors are currently open in the calling process. |
|
76 |
.TP 7 |
|
77 |
.B ENFILE |
|
78 |
The maximum allowable number of files is currently open in the system. |
|
79 |
.sp
|
|
80 |
.LP
|
|
81 |
The \fIgetpwuid_r\fP() function may fail if: |
|
82 |
.TP 7 |
|
83 |
.B ERANGE |
|
84 |
Insufficient storage was supplied via \fIbuffer\fP and \fIbufsize\fP |
|
85 |
to contain the data to be referenced by the resulting |
|
86 |
\fBpasswd\fP structure. |
|
87 |
.sp
|
|
88 |
.LP
|
|
89 |
\fIThe following sections are informative.\fP |
|
90 |
.SH EXAMPLES |
|
91 |
.SS Getting an Entry for the Root User |
|
92 |
.LP
|
|
93 |
The following example gets the user database entry for the user with |
|
94 |
user ID 0 (root). |
|
95 |
.sp
|
|
96 |
.RS
|
|
97 |
.nf
|
|
98 |
||
99 |
\fB#include <sys/types.h>
|
|
100 |
#include <pwd.h> |
|
101 |
\&...
|
|
102 |
uid_t id = 0; |
|
103 |
struct passwd *pwd; |
|
104 |
.sp
|
|
105 |
||
106 |
pwd = getpwuid(id); |
|
107 |
\fP
|
|
108 |
.fi
|
|
109 |
.RE
|
|
110 |
.SS Finding the Name for the Effective User ID |
|
111 |
.LP
|
|
112 |
The following example defines \fIpws\fP as a pointer to a structure |
|
113 |
of type \fBpasswd\fP, which is used to store the structure |
|
114 |
pointer returned by the call to the \fIgetpwuid\fP() function. The |
|
115 |
\fIgeteuid\fP() |
|
116 |
function shall return the effective user ID of the calling process; |
|
117 |
this is used as the search criteria for the \fIgetpwuid\fP() |
|
118 |
function. The call to \fIgetpwuid\fP() shall return a pointer to the |
|
119 |
structure containing that user ID value. |
|
120 |
.sp
|
|
121 |
.RS
|
|
122 |
.nf
|
|
123 |
||
124 |
\fB#include <unistd.h>
|
|
125 |
#include <sys/types.h> |
|
126 |
#include <pwd.h> |
|
127 |
\&...
|
|
128 |
struct passwd *pws; |
|
129 |
pws = getpwuid(geteuid()); |
|
130 |
\fP
|
|
131 |
.fi
|
|
132 |
.RE
|
|
133 |
.SS Finding an Entry in the User Database |
|
134 |
.LP
|
|
135 |
The following example uses \fIgetpwuid\fP() to search the user database |
|
136 |
for a user ID that was previously stored in a |
|
137 |
\fBstat\fP structure, then prints out the user name if it is found. |
|
138 |
If the user is not found, the program prints the numeric value |
|
139 |
of the user ID for the entry. |
|
140 |
.sp
|
|
141 |
.RS
|
|
142 |
.nf
|
|
143 |
||
144 |
\fB#include <sys/types.h>
|
|
145 |
#include <pwd.h> |
|
146 |
#include <stdio.h> |
|
147 |
\&...
|
|
148 |
struct stat statbuf; |
|
149 |
struct passwd *pwd; |
|
150 |
\&...
|
|
151 |
if ((pwd = getpwuid(statbuf.st_uid)) != NULL) |
|
152 |
printf(" %-8.8s", pwd->pw_name); |
|
153 |
else |
|
154 |
printf(" %-8d", statbuf.st_uid); |
|
155 |
\fP
|
|
156 |
.fi
|
|
157 |
.RE
|
|
158 |
.SH APPLICATION USAGE |
|
159 |
.LP
|
|
160 |
Three names associated with the current process can be determined: |
|
161 |
\fIgetpwuid\fP( \fIgeteuid\fP()) returns the name associated with |
|
162 |
the effective user ID of the process; \fIgetlogin\fP() returns the |
|
163 |
name associated with the current login activity; and |
|
164 |
\fIgetpwuid\fP( \fIgetuid\fP()) returns the name associated with the |
|
165 |
real user ID of the |
|
166 |
process. |
|
167 |
.LP
|
|
168 |
The \fIgetpwuid_r\fP() function is thread-safe and returns values |
|
169 |
in a user-supplied buffer instead of possibly using a static |
|
170 |
data area that may be overwritten by each call. |
|
171 |
.SH RATIONALE |
|
172 |
.LP
|
|
173 |
None. |
|
174 |
.SH FUTURE DIRECTIONS |
|
175 |
.LP
|
|
176 |
None. |
|
177 |
.SH SEE ALSO |
|
178 |
.LP
|
|
179 |
\fIgetpwnam\fP() , \fIgeteuid\fP() , \fIgetuid\fP() , \fIgetlogin\fP() |
|
180 |
, the Base Definitions volume of |
|
181 |
IEEE\ Std\ 1003.1-2001, \fI<limits.h>\fP, \fI<pwd.h>\fP, \fI<sys/types.h>\fP |
|
182 |
.SH COPYRIGHT |
|
183 |
Portions of this text are reprinted and reproduced in electronic form |
|
184 |
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology |
|
185 |
-- Portable Operating System Interface (POSIX), The Open Group Base |
|
186 |
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of |
|
187 |
Electrical and Electronics Engineers, Inc and The Open Group. In the |
|
188 |
event of any discrepancy between this version and the original IEEE and |
|
189 |
The Open Group Standard, the original IEEE and The Open Group Standard |
|
190 |
is the referee document. The original Standard can be obtained online at |
|
191 |
http://www.opengroup.org/unix/online.html . |