summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c/ucred.3c
blob: 9333e8b0e6cdab5ff3264742e15ee69f32667e9a (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
'\" te
.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
.\" 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.  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 the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH UCRED 3C "Nov 6, 2014"
.SH NAME
ucred, ucred_get, ucred_free, ucred_geteuid, ucred_getruid, ucred_getsuid,
ucred_getegid, ucred_getrgid, ucred_getsgid, ucred_getgroups, ucred_getprivset,
ucred_getpid, ucred_getprojid, ucred_getzoneid, ucred_getpflags,
ucred_getlabel, ucred_size \- user credential functions
.SH SYNOPSIS
.LP
.nf
#include <ucred.h>

\fBucred_t *\fR\fBucred_get\fR(\fBpid_t\fR \fIpid\fR);
.fi

.LP
.nf
\fBvoid\fR \fBucred_free\fR(\fBucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBuid_t\fR \fBucred_geteuid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBuid_t\fR \fBucred_getruid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBuid_t\fR \fBucred_getsuid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBgid_t\fR \fBucred_getegid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBgid_t\fR \fBucred_getrgid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBgid_t\fR \fBucred_getsgid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBint\fR \fBucred_getgroups\fR(\fBconst ucred_t *\fR\fIuc\fR, \fBconst gid_t **\fR\fIgroups\fR);
.fi

.LP
.nf
\fBconst priv_set_t *\fR\fBucred_getprivset\fR(\fBconst ucred_t *\fR\fIuc\fR,
     \fBpriv_ptype_t\fR \fIset\fR);
.fi

.LP
.nf
\fBpid_t\fR \fBucred_getpid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBprojid_t\fR \fBucred_getprojid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBzoneid_t\fR \fBucred_getzoneid\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBuint_t\fR \fBucred_getpflags\fR(\fBconst ucred_t *\fR\fIuc\fR, \fBuint_t\fR \fIflags\fR);
.fi

.LP
.nf
\fBm_label_t *\fR\fBucred_getlabel\fR(\fBconst ucred_t *\fR\fIuc\fR);
.fi

.LP
.nf
\fBsize_t\fR \fBucred_size\fR(\fBvoid\fR);
.fi

.SH DESCRIPTION
.LP
These functions return or act on a user credential, \fBucred_t\fR. User
credentials are returned by various functions and describe the credentials of a
process. Information about the process can then be obtained by calling the
access functions. Access functions can fail if the underlying mechanism did not
return sufficient information.
.sp
.LP
The \fBucred_get()\fR function returns the user credential of the specified
\fIpid\fR or \fINULL\fR if none can be obtained. A \fIpid\fR value of
\fBP_MYID\fR returns information about the calling process. The return value is
dynamically allocated and must be freed using \fBucred_free()\fR.
.sp
.LP
The \fBucred_geteuid()\fR, \fBucred_getruid()\fR, \fBucred_getsuid()\fR,
\fBucred_getegid()\fR, \fBucred_getrgid()\fR, and \fBucred_getsgid()\fR
functions return the effective UID, real UID, saved UID, effective GID, real
GID, saved GID, respectively, or -1 if the user credential does not contain
sufficient information.
.sp
.LP
The \fBucred_getgroups()\fR function stores a pointer to the group list in the
\fBgid_t *\fR pointed to by the second argument and returns the number of
groups in the list. It returns -1 if the information is not available. The
returned group list is valid until \fBucred_free()\fR is called on the user
credential given as argument.
.sp
.LP
The \fBucred_getpid()\fR function returns the process ID of the process or -1
if the process ID is not available. The process ID returned in a user
credential is only guaranteed to be correct in a very limited number of cases
when returned by \fBdoor_ucred\fR(3C) and \fBucred_get()\fR. In all other
cases, the process in question might have handed of the file descriptor, the
process might have exited or executed another program, or the process ID might
have been reused by a completely unrelated process after the original program
exited.
.sp
.LP
The \fBucred_getprojid()\fR function returns the project ID of the process or
-1 if the project ID is not available.
.sp
.LP
The \fBucred_getzoneid()\fR function returns the zone ID of the process or
\(mi1 if the zone ID is not available.
.sp
.LP
The \fBucred_getprivset()\fR function returns the specified privilege set
specified as second argument, or \fINULL\fR if either the requested information
is not available or the privilege set name is invalid. The returned privilege
set is valid until \fBucred_free()\fR is called on the specified user
credential.
.sp
.LP
The \fBucred_getpflags()\fR function returns the value of the specified
privilege flags from the \fBucred\fR structure, or (\fBuint_t\fR)-1 if none was
present.
.sp
.LP
The \fBucred_getlabel()\fR function returns the value of the label, or
\fINULL\fR if the label is not available. The returned label is valid until
\fBucred_free()\fR is called on the specified user credential. This function is
available only if the system is configured with Trusted Extensions.
.sp
.LP
The \fBucred_free()\fR function frees the memory allocated for the specified
user credential.
.sp
.LP
The \fBucred_size()\fR function returns \fBsizeof\fR(\fBucred_t\fR). This value
is constant only until the next boot, at which time it could change. The
\fBucred_size()\fR function can be used to determine the size of the buffer
needed to receive a credential option with \fBSO_RECVUCRED\fR. See
\fBsocket.h\fR(3HEAD).
.SH RETURN VALUES
.LP
See DESCRIPTION.
.SH ERRORS
.LP
The \fBucred_get()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEAGAIN\fR\fR
.ad
.RS 10n
There is not enough memory available to allocate sufficient memory to hold a
user credential. The application can try again later.
.RE

.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 10n
The caller does not have sufficient privileges to examine the target process.
.RE

.sp
.ne 2
.na
\fB\fBEMFILE\fR\fR
.ad
.br
.na
\fB\fBENFILE\fR\fR
.ad
.RS 10n
The calling process cannot open any more files.
.RE

.sp
.ne 2
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 10n
The physical limits of the system are exceeded by the memory allocation needed
to hold a user credential.
.RE

.sp
.ne 2
.na
\fB\fBESRCH\fR\fR
.ad
.RS 10n
The target process does not exist.
.RE

.sp
.LP
The \fBucred_getprivset()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The privilege set argument is invalid.
.RE

.sp
.LP
The \fBucred_getlabel()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The label is not present.
.RE

.sp
.LP
The \fBucred_geteuid()\fR, \fBucred_getruid()\fR, \fBucred_getsuid()\fR,
\fBucred_getegid()\fR, \fBucred_getrgid()\fR, \fBucred_getsgid()\fR,
\fBucred_getgroups()\fR, \fBucred_getpflags()\fR, \fBucred_getprivset()\fR,
\fBucred_getprojid()\fR, \fBucred_getpid()\fR, and \fBucred_getlabel()\fR
functions will fail if:
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The requested user credential attribute is not available in the specified user
credential.
.RE

.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
MT-Level	MT-Safe
.TE

.SH SEE ALSO
.LP
\fBgetpflags\fR(2), \fBgetppriv\fR(2), \fBdoor_ucred\fR(3C),
\fBgetpeerucred\fR(3C), \fBpriv_set\fR(3C), \fBsocket.h\fR(3HEAD),
\fBattributes\fR(5), \fBlabels\fR(5), \fBprivileges\fR(5)