4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1992 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/types.h>
32 #include <sys/label.h>
33 #include <sys/audit.h>
60 typedef struct list list_t
;
66 typedef struct exception except_t
;
68 static int stringcopy(char *, char *, int);
71 * getauditflagschar() - convert bit flag to character string
73 * input: masks->as_success - audit on success
74 * masks->as_failure - audit on failure
75 * verbose - string format. 0 if short name; 1 if long name;
77 * output: auditstring - resultant audit string
79 * returns: 0 - entry read ok
84 getauditflagschar(char *auditstring
, audit_state_t
*masks
, int verbose
)
86 int i
, j
, k
, mask_num
;
87 int list
= -1, retstat
= 0;
94 * initialize input buffer
96 strcpy(auditstring
, "");
98 * initialize lists struct
100 for (mask_num
= COMMON
; mask_num
<= FAILURE
; mask_num
++) {
101 lists
[mask_num
].count
= 0;
102 lists
[mask_num
].off
= -1;
103 for (i
=0;i
<MAXEVENT
+1;i
++)
104 lists
[mask_num
].on
[i
] = -1;
107 * initialize exception lists
109 for (i
= 0; i
< 2; i
++) {
111 except
[i
].exception
= -1;
114 for (i
= 0; i
< 3; i
++)
124 * find turned-on events - if on, store index of event
125 * in one of the three event lists, common, success, failure.
127 for ( i
= 0; i
< MAXEVENT
; i
++) {
128 if (((event_class
[i
].event_mask
& masks
->as_success
) > 0) ||
129 ((event_class
[i
].event_mask
& masks
->as_failure
) > 0)) {
132 * check for events in common
134 if (((event_class
[i
].event_mask
& masks
->as_success
) >
136 ((event_class
[i
].event_mask
& masks
->as_failure
) > 0))
137 lists
[COMMON
].on
[lists
[COMMON
].count
++] = i
;
140 * check for success events
142 if ((event_class
[i
].event_mask
& masks
->as_success
) > 0)
143 lists
[SUCCESS
].on
[lists
[SUCCESS
].count
++] = i
;
145 except_list
[SUCCESS
]++;
146 if (lists
[SUCCESS
].off
== -1)
147 lists
[SUCCESS
].off
= i
;
150 * check for failure events
152 if ((event_class
[i
].event_mask
& masks
->as_failure
) > 0)
153 lists
[FAILURE
].on
[lists
[FAILURE
].count
++] = i
;
155 except_list
[FAILURE
]++;
156 if (lists
[FAILURE
].off
== -1)
157 lists
[FAILURE
].off
= i
;
160 except_list
[COMMON
]++;
161 if (lists
[COMMON
].off
== -1)
162 lists
[COMMON
].off
= i
;
166 * check for all set or all-1 set - output all and common exceptions.
167 * the all or common state is exclusive; only one of the
168 * three, (+-)all, allowed
173 if (lists
[COMMON
].count
>= MAXEVENT
-2) {
174 if (lists
[COMMON
].count
== MAXEVENT
)
180 else if (lists
[COMMON
].count
== MAXEVENT
-1) {
181 for (i
=COMMON
;i
<=FAILURE
&& (list
== -1);i
++) {
182 if (except_list
[i
] == 1) {
185 except
[0].exception
= lists
[i
].off
;
192 else if (lists
[COMMON
].count
== MAXEVENT
-2) {
193 if (except_list
[COMMON
] == 1) {
195 except
[0].type
= COMMON
;
196 except
[0].exception
= lists
[COMMON
].off
;
197 for (i
=SUCCESS
;i
<=FAILURE
;i
++) {
198 if (except_list
[i
] == 1) {
200 except
[1].exception
= lists
[i
].off
;
204 } else if (except_list
[COMMON
] == 0) {
205 for (i
=SUCCESS
,j
=0;i
<=FAILURE
;i
++) {
206 if (except_list
[i
] == 1) {
209 except
[j
++].exception
= lists
[i
].off
;
216 * check for +all or -all
218 for (i
=SUCCESS
,j
=0;i
<=FAILURE
;i
++) {
219 if (lists
[i
].count
>= MAXEVENT
-1) {
222 if (lists
[i
].count
!= MAXEVENT
) {
223 if (lists
[i
].off
!= -1)
224 except
[j
++].exception
=
227 except
[j
++].exception
=
234 * output all and exceptions
238 if ((stringcopy(auditstring
, "+", 0)) == -1)
242 if ((stringcopy(auditstring
, "-", 0)) == -1)
249 ((stringcopy(auditstring
,event_class
[11].event_lname
,1)) == -1)
252 if ((stringcopy(auditstring
, event_class
[11].event_sname
,1)) == -1)
260 for (i
=0;i
<2 && except
[i
].exception
!= -1; i
++) {
261 if ((stringcopy(auditstring
, "^", 0)) == -1)
263 if(except
[i
].type
==SUCCESS
) {
264 if ((stringcopy(auditstring
, "+", 0)) == -1)
267 if (except
[i
].type
==FAILURE
) {
268 if ((stringcopy(auditstring
, "-", 0)) == -1)
271 if (length
== 1 && retstat
== 0) {
272 if ((stringcopy(auditstring
,
273 event_class
[except
[i
].exception
].event_lname
, 1))==-1)
275 } else if (retstat
== 0) {
276 if ((stringcopy(auditstring
,
277 event_class
[except
[i
].exception
].event_sname
, 1))==-1)
282 } /* end of " all " processing */
285 * process common events if no "all" was output
287 if (list
== -1 && (lists
[COMMON
].count
> 0) && retstat
== 0) {
289 * output common events first
291 for (j
=0;j
<lists
[COMMON
].count
;j
++) {
293 if ((stringcopy(auditstring
,
294 event_class
[lists
[COMMON
].on
[j
]].event_lname
, 1)) == -1)
296 } else if ((stringcopy(auditstring
,
297 event_class
[lists
[COMMON
].on
[j
]].event_sname
, 1)) == -1)
301 * remove common events from individual lists
304 for (i
=SUCCESS
;i
<=FAILURE
;i
++) {
305 for(j
=0;j
<lists
[COMMON
].count
;j
++) {
306 for(k
=0;k
< lists
[i
].count
;k
++) {
307 if (lists
[COMMON
].on
[j
] ==
317 * start processing individual event flags in success
320 if (list
!= COMMON
&& retstat
== 0) {
321 for (i
=SUCCESS
;i
<=FAILURE
;i
++) {
323 if (i
==SUCCESS
) strcpy(prefix
, "+");
324 if (i
==FAILURE
) strcpy(prefix
, "-");
325 for (j
=0;j
<MAXEVENT
&& j
<lists
[i
].count
;j
++) {
326 if (lists
[i
].on
[j
] != -1) {
327 if ((stringcopy(auditstring
, prefix
, 0)) == -1)
331 if ((stringcopy(auditstring
,
332 event_class
[lists
[i
].on
[j
]].event_lname
, 1))==-1)
334 } else if (retstat
== 0) {
335 if ((stringcopy(auditstring
,
336 event_class
[lists
[i
].on
[j
]].event_sname
, 1))==-1)
344 if ((stringcopy(auditstring
, "\0", 2)) == -1)
351 stringcopy(char *auditstring
, char *event
,
352 int flag
) /* if set, output comma after event */
359 if (pos
>= MAXSTRLEN
) {
360 fprintf(stderr
,"getauditflagschar: Inputted buffer too small.\n");
362 } else if (flag
!= 2) {
363 strcpy(auditstring
+pos
, event
);
364 pos
+= strlen(event
);
366 strcpy(auditstring
+pos
, COMMASTR
);
367 pos
+= strlen(COMMASTR
);
371 * add null terminator only
374 strcpy(auditstring
+(pos
-1), event
);
381 * getauditflagsbin() - converts character string to success and
384 * input: auditstring - audit string
385 * cnt - number of elements in the masks array
387 * output: masks->as_success - audit on success
388 * masks->as_failure - audit on failure
391 * -1 - error - string contains characters which do
392 * not match event flag names
396 getauditflagsbin(char *auditstring
, audit_state_t
*masks
)
398 int i
, gotone
, done
= 0, invert
= 0, tryagain
;
399 int retstat
= 0, succ_event
, fail_event
;
400 char *ptr
, tmp_buff
[MAXFLDLEN
];
403 * process character string
408 * read through string storing chars. until a comma
410 for (ptr
=tmp_buff
; !gotone
;) {
411 if(*auditstring
!=COMMA
&& *auditstring
!='\0' &&
412 *auditstring
!='\n' && *auditstring
!=' ')
413 *ptr
++ = *auditstring
++;
414 else if (*auditstring
== ' ')
417 if (*auditstring
== '\0' ||
418 *auditstring
== '\n') {
427 * process audit state
429 if(gotone
&& done
!= 2) {
430 if(!done
) auditstring
++;
472 /* add audit state to mask */
473 for (i
=0;i
<MAXEVENT
+1 && !gotone
;i
++) {
474 if ((!(strcmp(ptr
, event_class
[i
].event_sname
))) ||
475 (!(strcmp(ptr
, event_class
[i
].event_lname
)))) {
476 if (succ_event
== ON
)
477 masks
->as_success
|= event_class
[i
].event_mask
;
478 else if (succ_event
== OFF
)
479 masks
->as_success
&= ~(event_class
[i
].event_mask
);
480 if (fail_event
== ON
)
481 masks
->as_failure
|= event_class
[i
].event_mask
;
482 else if (fail_event
== OFF
)
483 masks
->as_failure
&= ~(event_class
[i
].event_mask
);