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