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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 1991-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* @(#)audit_path.c 2.7 92/02/16 SMI; SunOS CMW
* @(#)audit_path.c 4.2.1.2 91/05/08 SMI; BSM Module
*
* This code does the audit path processes. Part of this is still in
* audit.c and will be moved here when time permits.
*
* Note that audit debuging is enabled here. We will turn it off at
* beta shipment.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
#include <sys/kmem.h> /* for KM_SLEEP */
#include <sys/proc.h>
#include <sys/uio.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/pathname.h>
#include <sys/acct.h>
#include <c2/audit.h>
#include <c2/audit_kernel.h>
#include <c2/audit_record.h>
#include <sys/sysmacros.h>
#include <sys/atomic.h>
/*
* allocate a new auditpath
* newsect = increment sections count,
* charincr = change in strings storage
*/
struct audit_path *
au_pathdup(const struct audit_path *oldapp, int newsect, int charincr)
{
struct audit_path *newapp;
int i, alloc_size, oldlen;
char *oldcp, *newcp;
newsect = (newsect != 0);
oldcp = oldapp->audp_sect[0];
oldlen = (oldapp->audp_sect[oldapp->audp_cnt] - oldcp);
alloc_size = sizeof (struct audit_path) +
(oldapp->audp_cnt + newsect) * sizeof (char *) +
oldlen + charincr;
newapp = kmem_alloc(alloc_size, KM_SLEEP);
newapp->audp_ref = 1;
newapp->audp_size = alloc_size;
newapp->audp_cnt = oldapp->audp_cnt + newsect;
newcp = (char *)(&newapp->audp_sect[newapp->audp_cnt + 1]);
for (i = 0; i <= oldapp->audp_cnt; i++) {
newapp->audp_sect[i] = newcp +
(oldapp->audp_sect[i] - oldcp);
}
/*
* if this is a new section, set its end
* if this is an extended section, reset its end
*/
newapp->audp_sect[newapp->audp_cnt] = newcp + oldlen + charincr;
/* copy all of the old strings */
bcopy(oldcp, newcp, oldlen);
return (newapp);
}
/*
* increment audit path reference count
*/
void
au_pathhold(struct audit_path *app)
{
atomic_add_32(&app->audp_ref, 1);
}
/*
* decrement audit path reference count
*/
void
au_pathrele(struct audit_path *app)
{
if (atomic_add_32_nv(&app->audp_ref, -1) > 0)
return;
kmem_free(app, app->audp_size);
}
int
au_token_size(m)
token_t *m;
{
int i;
if (m == (token_t *)0)
return (0);
for (i = 0; m != (token_t *)0; m = m->next_buf)
i += m->len;
return (i);
}
token_t *
au_set(cp, size)
caddr_t cp;
uint_t size;
{
au_buff_t *head;
au_buff_t *tail;
au_buff_t *m;
uint_t l;
head = NULL;
tail = NULL; /* only to satisfy lint */
while (size) {
m = au_get_buff();
l = MIN(size, AU_BUFSIZE);
bcopy(cp, memtod(m, char *), l);
m->len = l;
if (head)
tail->next_buf = m; /* tail set if head set */
else
head = m;
tail = m;
size -= l;
cp += l;
}
return (head);
}
token_t *
au_append_token(chain, m)
token_t *chain;
token_t *m;
{
token_t *mbp;
if (chain == (token_t *)0)
return (m);
if (m == (token_t *)0)
return (chain);
for (mbp = chain; mbp->next_buf != (token_t *)0; mbp = mbp->next_buf)
;
mbp->next_buf = m;
return (chain);
}
void
audit_fixpath(struct audit_path *app, int len)
{
int id; /* index of where we are in destination string */
int is; /* index of where we are in source string */
int cnt; /* # of levels in audit_path */
int slashseen; /* have we seen a slash */
char *s; /* start of top-level string */
char c;
cnt = app->audp_cnt;
s = app->audp_sect[cnt - 1];
is = (app->audp_sect[cnt] - s) - len;
if (is <= 2)
is = 0; /* catch leading // or ./ */
slashseen = (is > 0);
for (id = is; ; is++) {
if ((c = s[is]) == '\0') {
/* that's all folks, we've reached the end of input */
if (id > 1 && s[id-1] == '/') {
/* remove terminating / */
--id;
}
s[id++] = '\0';
break;
}
if (slashseen) {
/* previous character was a / */
if (c == '/') {
/* another slash, ignore it */
continue;
}
} else if (c == '/') {
/* we see a /, just copy it and try again */
slashseen = 1;
s[id++] = c;
continue;
}
if (c == '.') {
if ((c = s[is+1]) == '\0') {
/* XXX/. seen */
if (id > 1)
id--;
continue;
}
if (c == '/') {
/* XXX/./ seen */
is += 1;
continue;
}
if (c == '.' && (s[is+2] == '\0' || s[is+2] == '/')) {
/* XXX/.. or XXX/../ seen */
is++;
if (id == 0 && cnt > 1) {
char *s_attr;
/* .. refers to attributed object */
app->audp_cnt = --cnt;
s_attr = s;
s = app->audp_sect[cnt - 1];
id = s_attr - s;
is += id;
id--;
slashseen = 0;
continue;
}
/* backup over previous component */
if (id > 0)
id--;
while (id > 0 && s[id - 1] != '/')
id--;
continue;
}
}
/* copy component name and terminating /, if any */
for (;;) {
c = s[is++];
if (c == '\0' || c == '/')
break;
s[id++] = c;
}
/* back up to before terminating '\0' or / */
slashseen = 0;
is -= 2;
}
/* fill empty attribute directory reference */
if (id == 1 && cnt > 1) {
s[0] = '.';
s[1] = '\0';
id = 2;
}
/* correct end pointer */
app->audp_sect[cnt] = s + id;
}
|