docs/how-to-build.md: use proper markup for directory names
[unleashed/tickless.git] / include / sys / ucred.h
blobe5baba7ebb66fbd883168dac40488f6a7aa4d4cf
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * File with private definitions for the ucred structure for use by the
26 * kernel and library routines.
29 #ifndef _SYS_UCRED_H
30 #define _SYS_UCRED_H
32 #include <sys/types.h>
33 #include <sys/procfs.h>
34 #include <sys/cred.h>
35 #include <sys/priv.h>
37 #ifdef _KERNEL
38 #include <c2/audit.h>
39 #else
40 #include <bsm/audit.h>
41 #endif
43 #ifndef _KERNEL
44 #include <unistd.h>
45 #endif
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
53 #if defined(_KERNEL) || _STRUCTURED_PROC != 0
55 * bitness neutral struct
57 * Add new fixed fields at the end of the structure.
59 struct ucred_s {
60 uint32_t uc_size; /* Size of the full structure */
61 uint32_t uc_credoff; /* Credential offset: 0 - no cred */
62 uint32_t uc_privoff; /* Privilege offset: 0 - no privs */
63 pid_t uc_pid; /* Process id */
64 uint32_t uc_audoff; /* Audit info offset: 0 - no aud */
65 zoneid_t uc_zoneid; /* Zone id */
66 projid_t uc_projid; /* Project id */
67 /* The rest goes here */
70 /* Get the process credentials */
71 #define UCCRED(uc) (prcred_t *)(((uc)->uc_credoff == 0) ? NULL : \
72 ((char *)(uc)) + (uc)->uc_credoff)
74 /* Get the process privileges */
75 #define UCPRIV(uc) (prpriv_t *)(((uc)->uc_privoff == 0) ? NULL : \
76 ((char *)(uc)) + (uc)->uc_privoff)
78 /* Get the process audit info */
79 #define UCAUD(uc) (auditinfo64_addr_t *)(((uc)->uc_audoff == 0) ? NULL : \
80 ((char *)(uc)) + (uc)->uc_audoff)
82 #endif /* _KERNEL || _STRUCTURED_PROC != 0 */
85 * SYS_ucredsys subcodes.
87 #define UCREDSYS_UCREDGET 0
88 #define UCREDSYS_GETPEERUCRED 1
90 #ifdef _KERNEL
92 extern uint32_t ucredminsize(const cred_t *);
94 #define UCRED_PRIV_OFF (sizeof (struct ucred_s))
95 #define UCRED_AUD_OFF (UCRED_PRIV_OFF + priv_prgetprivsize(NULL))
96 /* The prcred_t has a variable size; it should be last. */
97 #define UCRED_CRED_OFF (UCRED_AUD_OFF + get_audit_ucrsize())
99 #define UCRED_SIZE (UCRED_CRED_OFF + sizeof (prcred_t) + \
100 (ngroups_max - 1) * sizeof (gid_t))
103 struct proc;
105 extern struct ucred_s *pgetucred(struct proc *);
106 extern struct ucred_s *cred2ucred(const cred_t *, pid_t, void *,
107 const cred_t *);
108 extern int get_audit_ucrsize(void);
110 #else
112 /* Definition only valid for structured proc. */
113 #if _STRUCTURED_PROC != 0
114 #define UCRED_SIZE(ip) (sizeof (struct ucred_s) + sizeof (prcred_t) + \
115 ((int)sysconf(_SC_NGROUPS_MAX) - 1) * sizeof (gid_t) + \
116 sizeof (prpriv_t) + \
117 sizeof (priv_chunk_t) * \
118 ((ip)->priv_setsize * (ip)->priv_nsets - 1) + \
119 (ip)->priv_infosize + \
120 sizeof (auditinfo64_addr_t))
121 #endif
123 extern struct ucred_s *_ucred_alloc(void);
125 #endif
127 #ifdef __cplusplus
129 #endif
131 #endif /* _SYS_UCRED_H */