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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * @(#)audit_path.c 2.7 92/02/16 SMI; SunOS CMW
28 * @(#)audit_path.c 4.2.1.2 91/05/08 SMI; BSM Module
30 * This code does the audit path processes. Part of this is still in
31 * audit.c and will be moved here when time permits.
33 * Note that audit debuging is enabled here. We will turn it off at
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #include <sys/vnode.h>
43 #include <sys/kmem.h> /* for KM_SLEEP */
48 #include <sys/pathname.h>
51 #include <c2/audit_kernel.h>
52 #include <c2/audit_record.h>
53 #include <sys/sysmacros.h>
54 #include <sys/atomic.h>
63 if (m
== (token_t
*)0)
66 for (i
= 0; m
!= (token_t
*)0; m
= m
->next_buf
)
82 tail
= NULL
; /* only to satisfy lint */
86 l
= MIN(size
, AU_BUFSIZE
);
87 bcopy(cp
, memtod(m
, char *), l
);
91 tail
->next_buf
= m
; /* tail set if head set */
103 au_append_token(chain
, m
)
109 if (chain
== (token_t
*)0)
112 if (m
== (token_t
*)0)
115 for (mbp
= chain
; mbp
->next_buf
!= (token_t
*)0; mbp
= mbp
->next_buf
)
123 audit_fixpath(struct audit_path
*app
, int len
)
125 int id
; /* index of where we are in destination string */
126 int is
; /* index of where we are in source string */
127 int cnt
; /* # of levels in audit_path */
128 int slashseen
; /* have we seen a slash */
129 char *s
; /* start of top-level string */
133 s
= app
->audp_sect
[cnt
- 1];
134 is
= (app
->audp_sect
[cnt
] - s
) - len
;
136 is
= 0; /* catch leading // or ./ */
137 slashseen
= (is
> 0);
138 for (id
= is
; ; is
++) {
139 if ((c
= s
[is
]) == '\0') {
140 /* that's all folks, we've reached the end of input */
141 if (id
> 1 && s
[id
-1] == '/') {
142 /* remove terminating / */
149 /* previous character was a / */
151 /* another slash, ignore it */
154 } else if (c
== '/') {
155 /* we see a /, just copy it and try again */
161 if ((c
= s
[is
+1]) == '\0') {
172 if (c
== '.' && (s
[is
+2] == '\0' || s
[is
+2] == '/')) {
173 /* XXX/.. or XXX/../ seen */
175 if (id
== 0 && cnt
> 1) {
177 /* .. refers to attributed object */
178 app
->audp_cnt
= --cnt
;
180 s
= app
->audp_sect
[cnt
- 1];
187 /* backup over previous component */
190 while (id
> 0 && s
[id
- 1] != '/')
195 /* copy component name and terminating /, if any */
198 if (c
== '\0' || c
== '/')
202 /* back up to before terminating '\0' or / */
206 /* fill empty attribute directory reference */
207 if (id
== 1 && cnt
> 1) {
212 /* correct end pointer */
213 app
->audp_sect
[cnt
] = s
+ id
;