2 .\" Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice(s), this list of conditions and the following disclaimer as
9 .\" the first lines of this file unmodified other than the possible
10 .\" addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice(s), this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 .\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 .\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
40 .Nd "functions related to user credentials"
47 .Fn crhold "struct ucred *cr"
49 .Fn crfree "struct ucred *cr"
51 .Fn crcopy "struct ucred *dest" "struct ucred *src"
53 .Fn crcopysafe "struct proc *p" "struct ucred *cr"
55 .Fn crdup "struct ucred *cr"
57 .Fn crsetgroups "struct ucred *cr" "int ngrp" "gid_t *groups"
59 .Fn cru2x "struct ucred *cr" "struct xucred *xcr"
63 family of functions is used to manage user credential structures
69 function allocates memory
70 for a new structure, sets its reference count to 1, and
75 function increases the reference count on the credential.
79 function decreases the reference count on the credential.
80 If the count drops to 0, the storage for the structure is freed.
84 function copies the contents of the source (template)
85 credential into the destination template.
88 structure within the destination is referenced
94 function copies the current credential associated with the process
96 into the newly allocated credential
100 must be held and will be dropped and reacquired as needed to allocate
101 group storage space in
106 function allocates memory for a new structure and copies the
110 The actual copying is performed by
119 variables and allocates space as needed.
120 It also truncates the group list to the current maximum number of
122 No other mechanism should be used to modify the
124 array except for updating the primary group via assignment to
139 it ignores fields in the former that are not present in the latter
142 and appropriately sets fields in the latter that are not present in
153 all return a pointer to a
161 structure contains extensible fields.
162 This means that the correct protocol must always be followed to create
163 a fresh and writable credential structure: new credentials must always
164 be derived from existing credentials using
170 In the common case, credentials required for access control decisions are
171 used in a read-only manner.
172 In these circumstances, the thread credential
174 should be used, as it requires no locking to access safely, and remains stable
175 for the duration of the call even in the face of a multi-threaded
176 application changing the process credentials from another thread.
178 During a process credential update, the process lock must be held across
179 check and update, to prevent race conditions.
180 The process credential,
181 .Va td->td_proc->p_ucred ,
182 must be used both for check and update.
183 If a process credential is updated during a system call and checks against
184 the thread credential are to be made later during the same system call,
185 the thread credential must also be refreshed from the process credential
186 so as to prevent use of a stale value.
187 To avoid this scenario, it is recommended that system calls updating the
188 process credential be designed to avoid other authorization functions.
190 If temporarily elevated privileges are required for a thread, the thread
191 credential can by replaced for the duration of an activity, or for
192 the remainder of the system call.
193 However, as a thread credential is often shared, appropriate care should be
194 taken to make sure modifications are made to a writable credential
200 Caution should be exercised when checking authorization for a thread or
201 process perform an operation on another thread or process.
202 As a result of temporary elevation, the target thread credential should
204 be used as the target credential in an access control decision: the process
205 credential associated with the thread,
206 .Va td->td_proc->p_ucred ,
207 should be used instead.
210 accepts a target process, not a target thread, for access control purposes.
214 This manual page was written by
215 .An Chad David Aq Mt davidc@acns.ab.ca .