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 * 3. 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: src/sys/sys/ucred.h,v 1.14.2.5 2002/03/09 05:20:25 dd Exp $ 31 * $DragonFly: src/sys/sys/ucred.h,v 1.9 2007/01/08 21:32:57 corecode Exp $ 32 */ 33 34 #ifndef _SYS_UCRED_H_ 35 #define _SYS_UCRED_H_ 36 37 #ifndef _SYS_TYPES_H_ 38 #include <sys/types.h> 39 #endif 40 #ifndef _SYS_PARAM_H_ 41 #include <sys/param.h> 42 #endif 43 #ifndef _SYS_SPINLOCK_H_ 44 #include <sys/spinlock.h> 45 #endif 46 47 struct prison; 48 49 /* 50 * Credentials. 51 * 52 * Please do not inspect cr_uid directly to determine superuserness. 53 * Only the priv(9) functions should be used for this. 54 */ 55 struct ucred { 56 int cr_ref; /* reference count */ 57 uid_t cr_uid; /* effective user id */ 58 short cr_ngroups; /* number of groups */ 59 gid_t cr_groups[NGROUPS]; /* groups */ 60 struct uidinfo *cr_uidinfo; /* per uid resource consumption */ 61 struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */ 62 struct prison *cr_prison; /* prison info */ 63 uid_t cr_ruid; /* Real user id. */ 64 uid_t cr_svuid; /* Saved effective user id. */ 65 gid_t cr_rgid; /* Real group id. */ 66 gid_t cr_svgid; /* Saved effective group id. */ 67 }; 68 #define cr_gid cr_groups[0] 69 #define NOCRED ((struct ucred *)0) /* no credential available */ 70 #define FSCRED ((struct ucred *)-1) /* filesystem credential */ 71 72 /* 73 * This is the external representation of struct ucred, based upon the 74 * size of a 4.2-RELEASE struct ucred. There will probably never be 75 * any need to change the size of this or layout of its used fields. 76 */ 77 struct xucred { 78 u_int cr_version; /* structure layout version */ 79 uid_t cr_uid; /* effective user id */ 80 short cr_ngroups; /* number of groups */ 81 gid_t cr_groups[NGROUPS]; /* groups */ 82 void *_cr_unused1; /* compatibility with old ucred */ 83 }; 84 #define XUCRED_VERSION 0 85 86 #ifdef _KERNEL 87 88 struct proc; 89 90 struct ucred *change_euid (uid_t euid); 91 struct ucred *change_ruid (uid_t ruid); 92 struct ucred *cratom (struct ucred **pcr); 93 struct ucred *cratom_proc (struct proc *p); 94 struct ucred *crcopy (struct ucred *cr); 95 struct ucred *crdup (struct ucred *cr); 96 void crfree (struct ucred *cr); 97 void crinit (struct ucred *cr); 98 struct ucred *crget (void); 99 struct ucred *crhold (struct ucred *cr); 100 void cru2x (struct ucred *cr, struct xucred *xcr); 101 int groupmember (gid_t gid, struct ucred *cred); 102 #endif /* _KERNEL */ 103 104 #endif /* !_SYS_UCRED_H_ */ 105