1139825Simp/*- 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914488Shsu * @(#)ucred.h 8.4 (Berkeley) 1/9/95 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 331541Srgrimes#ifndef _SYS_UCRED_H_ 341541Srgrimes#define _SYS_UCRED_H_ 351541Srgrimes 36170407Srwatson#include <bsm/audit.h> 37170407Srwatson 38219304Straszstruct loginclass; 39219304Strasz 401541Srgrimes/* 411541Srgrimes * Credentials. 4243429Sphk * 43167572Srwatson * Please do not inspect cr_uid directly to determine superuserness. The 44167572Srwatson * priv(9) interface should be used to check for privilege. 451541Srgrimes */ 46102538Salfred#if defined(_KERNEL) || defined(_WANT_UCRED) 471541Srgrimesstruct ucred { 4899092Sbde u_int cr_ref; /* reference count */ 4984827Sjhb#define cr_startcopy cr_uid 5099092Sbde uid_t cr_uid; /* effective user id */ 5199092Sbde uid_t cr_ruid; /* real user id */ 5299092Sbde uid_t cr_svuid; /* saved user id */ 53194498Sbrooks int cr_ngroups; /* number of groups */ 5499092Sbde gid_t cr_rgid; /* real group id */ 55147641Sdelphij gid_t cr_svgid; /* saved group id */ 5690757Sjulian struct uidinfo *cr_uidinfo; /* per euid resource consumption */ 5790757Sjulian struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */ 58112704Smaxim struct prison *cr_prison; /* jail(2) */ 59219304Strasz struct loginclass *cr_loginclass; /* login class */ 60193255Srwatson u_int cr_flags; /* credential flags */ 61195741Sjamie void *cr_pspare2[2]; /* general use 2 */ 62100986Srwatson#define cr_endcopy cr_label 63122524Srwatson struct label *cr_label; /* MAC label */ 64170407Srwatson struct auditinfo_addr cr_audit; /* Audit properties. */ 65194498Sbrooks gid_t *cr_groups; /* groups */ 66194498Sbrooks int cr_agroups; /* Available groups */ 671541Srgrimes}; 6898745Sbde#define NOCRED ((struct ucred *)0) /* no credential available */ 6998745Sbde#define FSCRED ((struct ucred *)-1) /* filesystem credential */ 70102538Salfred#endif /* _KERNEL || _WANT_UCRED */ 711541Srgrimes 72194498Sbrooks#define XU_NGROUPS 16 73194498Sbrooks 7472650Sgreen/* 75219129Srwatson * Flags for cr_flags. 76219129Srwatson */ 77219129Srwatson#define CRED_FLAG_CAPMODE 0x00000001 /* In capability mode. */ 78219129Srwatson 79219129Srwatson/* 8094020Sdd * This is the external representation of struct ucred. 8172650Sgreen */ 8272650Sgreenstruct xucred { 8391354Sdd u_int cr_version; /* structure layout version */ 8472650Sgreen uid_t cr_uid; /* effective user id */ 8572650Sgreen short cr_ngroups; /* number of groups */ 86194498Sbrooks gid_t cr_groups[XU_NGROUPS]; /* groups */ 8772650Sgreen void *_cr_unused1; /* compatibility with old ucred */ 8872650Sgreen}; 8991354Sdd#define XUCRED_VERSION 0 9072650Sgreen 9194020Sdd/* This can be used for both ucred and xucred structures. */ 9298745Sbde#define cr_gid cr_groups[0] 9394020Sdd 9455205Speter#ifdef _KERNEL 95194498Sbrooksstruct proc; 9694020Sddstruct thread; 973438Sphk 9898745Sbdevoid change_egid(struct ucred *newcred, gid_t egid); 9998745Sbdevoid change_euid(struct ucred *newcred, struct uidinfo *euip); 10098745Sbdevoid change_rgid(struct ucred *newcred, gid_t rgid); 10198745Sbdevoid change_ruid(struct ucred *newcred, struct uidinfo *ruip); 10298745Sbdevoid change_svgid(struct ucred *newcred, gid_t svgid); 10398745Sbdevoid change_svuid(struct ucred *newcred, uid_t svuid); 10498745Sbdevoid crcopy(struct ucred *dest, struct ucred *src); 105194498Sbrooksstruct ucred *crcopysafe(struct proc *p, struct ucred *cr); 10690757Sjulianstruct ucred *crdup(struct ucred *cr); 107293897Sglebiusvoid crextend(struct ucred *cr, int n); 10898745Sbdevoid cred_update_thread(struct thread *td); 109303846Sbdreweryvoid proc_set_cred_init(struct proc *p, struct ucred *cr); 110302229Sbdrewerystruct ucred *proc_set_cred(struct proc *p, struct ucred *cr); 11198745Sbdevoid crfree(struct ucred *cr); 11290757Sjulianstruct ucred *crget(void); 11390757Sjulianstruct ucred *crhold(struct ucred *cr); 11498745Sbdeint crshared(struct ucred *cr); 11598745Sbdevoid cru2x(struct ucred *cr, struct xucred *xcr); 116194498Sbrooksvoid crsetgroups(struct ucred *cr, int n, gid_t *groups); 11798745Sbdeint groupmember(gid_t gid, struct ucred *cred); 11855205Speter#endif /* _KERNEL */ 1191541Srgrimes 1201541Srgrimes#endif /* !_SYS_UCRED_H_ */ 121