xref: /illumos-gate/usr/src/lib/libbsm/common/getfaudflgs.c (revision 50981ffc7e4c5048d14890df805afee6ec113991)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 #pragma ident	"%Z%%M%	%I%	%E% SMI"
22 
23 /*
24  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #include <sys/types.h>
29 #include <bsm/audit.h>
30 
31 #define	MAXSTRLEN 360
32 
33 /*	getfaudflgs.c */
34 
35 /*
36  * getfauditflags() - combines system event flag mask with user event
37  *	flag masks.
38  *
39  * input: usremasks->as_success - always audit on success
40  *	usremasks->as_failure - always audit on failure
41  *	usrdmasks->as_success - never audit on success
42  *	usrdmasks->as_failure - never audit on failure
43  *
44  * output: lastmasks->as_success - audit on success
45  *	lastmasks->as_failure - audit on failure
46  *
47  * returns:	0 - ok
48  * 		-1 - error
49  */
50 
51 extern int getauditflagsbin();
52 extern int getacflg();
53 
54 int
55 getfauditflags(usremasks, usrdmasks, lastmasks)
56 au_mask_t *usremasks;
57 au_mask_t *usrdmasks;
58 au_mask_t *lastmasks;
59 {
60 	int	len = MAXSTRLEN, retstat = 0;
61 	char	s_auditstring[MAXSTRLEN];
62 	audit_state_t masks;
63 
64 	masks.as_success = 0;
65 	masks.as_failure = 0;
66 	/* get system audit mask and convert to bit mask */
67 	if ((getacflg(s_auditstring, len)) >= 0)  {
68 		if ((getauditflagsbin(s_auditstring, &masks)) != 0)
69 			retstat = -1;
70 	} else
71 		retstat = -1;
72 
73 	/* combine system and user event masks */
74 	if (retstat == 0) {
75 		lastmasks->as_success = masks.as_success;
76 		lastmasks->as_failure = masks.as_failure;
77 
78 		lastmasks->as_success |= usremasks->as_success;
79 		lastmasks->as_failure |= usremasks->as_failure;
80 
81 		lastmasks->as_success &= ~(usrdmasks->as_success);
82 		lastmasks->as_failure &= ~(usrdmasks->as_failure);
83 	}
84 	return (retstat);
85 }
86