]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/sys/ucred.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / sys / ucred.h
1 /*-
2  * Copyright (c) 1989, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *      @(#)ucred.h     8.4 (Berkeley) 1/9/95
30  * $FreeBSD$
31  */
32
33 #ifndef _SYS_UCRED_H_
34 #define _SYS_UCRED_H_
35
36 #include <bsm/audit.h>
37
38 /*
39  * Credentials.
40  *
41  * Please do not inspect cr_uid directly to determine superuserness.  The
42  * priv(9) interface should be used to check for privilege.
43  */
44 #if defined(_KERNEL) || defined(_WANT_UCRED)
45 struct ucred {
46         u_int   cr_ref;                 /* reference count */
47 #define cr_startcopy cr_uid
48         uid_t   cr_uid;                 /* effective user id */
49         uid_t   cr_ruid;                /* real user id */
50         uid_t   cr_svuid;               /* saved user id */
51         short   cr_ngroups;             /* number of groups */
52         gid_t   cr_groups[NGROUPS];     /* groups */
53         gid_t   cr_rgid;                /* real group id */
54         gid_t   cr_svgid;               /* saved group id */
55         struct uidinfo  *cr_uidinfo;    /* per euid resource consumption */
56         struct uidinfo  *cr_ruidinfo;   /* per ruid resource consumption */
57         struct prison   *cr_prison;     /* jail(2) */
58         void            *cr_pspare[3];  /* vimage 2; general use 1 */
59 #define cr_endcopy      cr_label
60         struct label    *cr_label;      /* MAC label */
61         struct auditinfo_addr   cr_audit;       /* Audit properties. */
62 };
63 #define NOCRED  ((struct ucred *)0)     /* no credential available */
64 #define FSCRED  ((struct ucred *)-1)    /* filesystem credential */
65 #endif /* _KERNEL || _WANT_UCRED */
66
67 /*
68  * This is the external representation of struct ucred.
69  */
70 struct xucred {
71         u_int   cr_version;             /* structure layout version */
72         uid_t   cr_uid;                 /* effective user id */
73         short   cr_ngroups;             /* number of groups */
74         gid_t   cr_groups[NGROUPS];     /* groups */
75         void    *_cr_unused1;           /* compatibility with old ucred */
76 };
77 #define XUCRED_VERSION  0
78
79 /* This can be used for both ucred and xucred structures. */
80 #define cr_gid cr_groups[0]
81
82 #ifdef _KERNEL
83 struct thread;
84
85 void    change_egid(struct ucred *newcred, gid_t egid);
86 void    change_euid(struct ucred *newcred, struct uidinfo *euip);
87 void    change_rgid(struct ucred *newcred, gid_t rgid);
88 void    change_ruid(struct ucred *newcred, struct uidinfo *ruip);
89 void    change_svgid(struct ucred *newcred, gid_t svgid);
90 void    change_svuid(struct ucred *newcred, uid_t svuid);
91 void    crcopy(struct ucred *dest, struct ucred *src);
92 struct ucred    *crdup(struct ucred *cr);
93 void    cred_update_thread(struct thread *td);
94 void    crfree(struct ucred *cr);
95 struct ucred    *crget(void);
96 struct ucred    *crhold(struct ucred *cr);
97 int     crshared(struct ucred *cr);
98 void    cru2x(struct ucred *cr, struct xucred *xcr);
99 int     groupmember(gid_t gid, struct ucred *cred);
100 #endif /* _KERNEL */
101
102 #endif /* !_SYS_UCRED_H_ */