ucred.h revision 94020
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3314488Shsu *	@(#)ucred.h	8.4 (Berkeley) 1/9/95
3450477Speter * $FreeBSD: head/sys/sys/ucred.h 94020 2002-04-07 03:59:31Z dd $
351541Srgrimes */
361541Srgrimes
371541Srgrimes#ifndef _SYS_UCRED_H_
381541Srgrimes#define	_SYS_UCRED_H_
391541Srgrimes
401541Srgrimes/*
411541Srgrimes * Credentials.
4243429Sphk *
4343429Sphk * Please do not inspect cr_uid directly to determine superuserness.
4493593Sjhb * Only the suser() or suser_cred() function should be used for this.
451541Srgrimes */
461541Srgrimesstruct ucred {
4790757Sjulian	u_int		cr_ref;		/* reference count */
4884827Sjhb#define	cr_startcopy cr_uid
4990757Sjulian	uid_t		cr_uid;		/* effective user id */
5090757Sjulian	uid_t		cr_ruid;	/* real user id */
5190757Sjulian	uid_t		cr_svuid;	/* saved user id */
5290757Sjulian	short		cr_ngroups;	/* number of groups */
5390757Sjulian	gid_t		cr_groups[NGROUPS]; /* groups */
5490757Sjulian	gid_t		cr_rgid;	/* real group id */
5590757Sjulian	gid_t		cr_svgid;	/* saved user id */
5690757Sjulian	struct uidinfo	*cr_uidinfo;	/* per euid resource consumption */
5790757Sjulian	struct uidinfo	*cr_ruidinfo;	/* per ruid resource consumption */
5890757Sjulian	struct prison	*cr_prison;	/* jail(4) */
5990756Sdillon#define	cr_endcopy cr_mtxp
6094020Sdd	struct mtx	*cr_mtxp;      	/* protect refcount */
611541Srgrimes};
6214488Shsu#define NOCRED ((struct ucred *)0)	/* no credential available */
6314488Shsu#define FSCRED ((struct ucred *)-1)	/* filesystem credential */
641541Srgrimes
6572650Sgreen/*
6694020Sdd * This is the external representation of struct ucred.
6772650Sgreen */
6872650Sgreenstruct xucred {
6991354Sdd	u_int	cr_version;		/* structure layout version */
7072650Sgreen	uid_t	cr_uid;			/* effective user id */
7172650Sgreen	short	cr_ngroups;		/* number of groups */
7272650Sgreen	gid_t	cr_groups[NGROUPS];	/* groups */
7372650Sgreen	void	*_cr_unused1;		/* compatibility with old ucred */
7472650Sgreen};
7591354Sdd#define	XUCRED_VERSION	0
7672650Sgreen
7794020Sdd/* This can be used for both ucred and xucred structures. */
7894020Sdd#define cr_gid cr_groups[0]
7994020Sdd
8055205Speter#ifdef _KERNEL
8194020Sddstruct thread;
823438Sphk
8392823Sjhb#ifdef DIAGNOSTIC
8492823Sjhbvoid		cred_free_thread(struct thread *td);
8592823Sjhb#endif
8690748Sjulianvoid		cred_update_thread(struct thread *td);
8790757Sjulianvoid		change_egid(struct ucred *newcred, gid_t egid);
8890757Sjulianvoid		change_euid(struct ucred *newcred, uid_t euid);
8990757Sjulianvoid		change_rgid(struct ucred *newcred, gid_t rgid);
9090757Sjulianvoid		change_ruid(struct ucred *newcred, uid_t ruid);
9190757Sjulianvoid		change_svgid(struct ucred *newcred, gid_t svgid);
9290757Sjulianvoid		change_svuid(struct ucred *newcred, uid_t svuid);
9390757Sjulianvoid		crcopy(struct ucred *dest, struct ucred *src);
9490757Sjulianstruct ucred	*crdup(struct ucred *cr);
9590757Sjulianvoid		crfree(struct ucred *cr);
9690757Sjulianstruct ucred	*crget(void);
9790757Sjulianstruct ucred	*crhold(struct ucred *cr);
9890757Sjulianint		crshared(struct ucred *cr);
9991354Sddvoid		cru2x(struct ucred *cr, struct xucred *xcr);
10090757Sjulianint		groupmember(gid_t gid, struct ucred *cred);
10155205Speter#endif /* _KERNEL */
1021541Srgrimes
1031541Srgrimes#endif /* !_SYS_UCRED_H_ */
104