xref: /titanic_53/usr/src/lib/libbsm/common/getfaudflgs.c (revision d75d0dc9a76c4d28c5b421415de169350a8e844d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d75d0dc9Stz204579  * Common Development and Distribution License (the "License").
6*d75d0dc9Stz204579  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
24*d75d0dc9Stz204579  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25*d75d0dc9Stz204579  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #define	MAXSTRLEN 360
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*	getfaudflgs.c */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * getfauditflags() - combines system event flag mask with user event
377c478bd9Sstevel@tonic-gate  *	flag masks.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * input: usremasks->as_success - always audit on success
407c478bd9Sstevel@tonic-gate  *	usremasks->as_failure - always audit on failure
417c478bd9Sstevel@tonic-gate  *	usrdmasks->as_success - never audit on success
427c478bd9Sstevel@tonic-gate  *	usrdmasks->as_failure - never audit on failure
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * output: lastmasks->as_success - audit on success
457c478bd9Sstevel@tonic-gate  *	lastmasks->as_failure - audit on failure
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * returns:	0 - ok
487c478bd9Sstevel@tonic-gate  * 		-1 - error
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate extern int getauditflagsbin();
527c478bd9Sstevel@tonic-gate extern int getacflg();
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate int
557c478bd9Sstevel@tonic-gate getfauditflags(usremasks, usrdmasks, lastmasks)
567c478bd9Sstevel@tonic-gate au_mask_t *usremasks;
577c478bd9Sstevel@tonic-gate au_mask_t *usrdmasks;
587c478bd9Sstevel@tonic-gate au_mask_t *lastmasks;
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	int	len = MAXSTRLEN, retstat = 0;
617c478bd9Sstevel@tonic-gate 	char	s_auditstring[MAXSTRLEN];
627c478bd9Sstevel@tonic-gate 	audit_state_t masks;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	masks.as_success = 0;
657c478bd9Sstevel@tonic-gate 	masks.as_failure = 0;
667c478bd9Sstevel@tonic-gate 	/* get system audit mask and convert to bit mask */
677c478bd9Sstevel@tonic-gate 	if ((getacflg(s_auditstring, len)) >= 0)  {
687c478bd9Sstevel@tonic-gate 		if ((getauditflagsbin(s_auditstring, &masks)) != 0)
697c478bd9Sstevel@tonic-gate 			retstat = -1;
707c478bd9Sstevel@tonic-gate 	} else
717c478bd9Sstevel@tonic-gate 		retstat = -1;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/* combine system and user event masks */
747c478bd9Sstevel@tonic-gate 	if (retstat == 0) {
757c478bd9Sstevel@tonic-gate 		lastmasks->as_success = masks.as_success;
767c478bd9Sstevel@tonic-gate 		lastmasks->as_failure = masks.as_failure;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 		lastmasks->as_success |= usremasks->as_success;
797c478bd9Sstevel@tonic-gate 		lastmasks->as_failure |= usremasks->as_failure;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 		lastmasks->as_success &= ~(usrdmasks->as_success);
827c478bd9Sstevel@tonic-gate 		lastmasks->as_failure &= ~(usrdmasks->as_failure);
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 	return (retstat);
857c478bd9Sstevel@tonic-gate }
86