xref: /illumos-gate/usr/src/lib/libbsm/common/getfaudflgs.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 #pragma ident	"%Z%%M%	%I%	%E% SMI"
23 
24 #ifndef lint
25 static char	sccsid[] = "%Z%%M% %I% %E% SMI";
26 #endif
27 
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31 
32 #include <sys/types.h>
33 #include <bsm/audit.h>
34 
35 #define	MAXSTRLEN 360
36 
37 /*	getfaudflgs.c */
38 
39 /*
40  * getfauditflags() - combines system event flag mask with user event
41  *	flag masks.
42  *
43  * input: usremasks->as_success - always audit on success
44  *	usremasks->as_failure - always audit on failure
45  *	usrdmasks->as_success - never audit on success
46  *	usrdmasks->as_failure - never audit on failure
47  *
48  * output: lastmasks->as_success - audit on success
49  *	lastmasks->as_failure - audit on failure
50  *
51  * returns:	0 - ok
52  * 		-1 - error
53  */
54 
55 extern int getauditflagsbin();
56 extern int getacflg();
57 
58 int
59 getfauditflags(usremasks, usrdmasks, lastmasks)
60 au_mask_t *usremasks;
61 au_mask_t *usrdmasks;
62 au_mask_t *lastmasks;
63 {
64 	int	len = MAXSTRLEN, retstat = 0;
65 	char	s_auditstring[MAXSTRLEN];
66 	audit_state_t masks;
67 
68 	masks.as_success = 0;
69 	masks.as_failure = 0;
70 	/* get system audit mask and convert to bit mask */
71 	if ((getacflg(s_auditstring, len)) >= 0)  {
72 		if ((getauditflagsbin(s_auditstring, &masks)) != 0)
73 			retstat = -1;
74 	} else
75 		retstat = -1;
76 
77 	/* combine system and user event masks */
78 	if (retstat == 0) {
79 		lastmasks->as_success = masks.as_success;
80 		lastmasks->as_failure = masks.as_failure;
81 
82 		lastmasks->as_success |= usremasks->as_success;
83 		lastmasks->as_failure |= usremasks->as_failure;
84 
85 		lastmasks->as_success &= ~(usrdmasks->as_success);
86 		lastmasks->as_failure &= ~(usrdmasks->as_failure);
87 	}
88 	return (retstat);
89 }
90