xref: /titanic_50/usr/src/lib/libbsm/common/audit_reboot.c (revision 1b2d1c944935c64d6eeb28c8054864f4bdf20e9f)
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
5dfc7be02SJan Friedel  * Common Development and Distribution License (the "License").
6dfc7be02SJan Friedel  * 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 /*
22*1b2d1c94SMarek Pospisil  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #include <sys/types.h>
267c478bd9Sstevel@tonic-gate #include <unistd.h>
277c478bd9Sstevel@tonic-gate #include <stdlib.h>
287c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
297c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
307c478bd9Sstevel@tonic-gate #include <bsm/audit_uevents.h>
317c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
327c478bd9Sstevel@tonic-gate #include <bsm/audit_private.h>
337c478bd9Sstevel@tonic-gate #include <generic.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifdef C2_DEBUG
36dfc7be02SJan Friedel #define	dprintf(x) { (void) printf x; }
377c478bd9Sstevel@tonic-gate #else
387c478bd9Sstevel@tonic-gate #define	dprintf(x)
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate static int audit_reboot_generic(int);
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate int
audit_reboot_setup()447c478bd9Sstevel@tonic-gate audit_reboot_setup()
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate 	dprintf(("audit_reboot_setup()\n"));
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 	if (cannot_audit(0)) {
497c478bd9Sstevel@tonic-gate 		return (0);
507c478bd9Sstevel@tonic-gate 	}
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 	(void) aug_init();
537c478bd9Sstevel@tonic-gate 	aug_save_event(AUE_reboot_solaris);
547c478bd9Sstevel@tonic-gate 	(void) aug_save_me();
557c478bd9Sstevel@tonic-gate 	return (0);
567c478bd9Sstevel@tonic-gate }
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate int
audit_reboot_fail()597c478bd9Sstevel@tonic-gate audit_reboot_fail()
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate 	return (audit_reboot_generic(-1));
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate int
audit_reboot_success()657c478bd9Sstevel@tonic-gate audit_reboot_success()
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 	int res = 0;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	(void) audit_reboot_generic(0);
707c478bd9Sstevel@tonic-gate 	/*
717c478bd9Sstevel@tonic-gate 	 * wait for audit daemon
727c478bd9Sstevel@tonic-gate 	 * to put reboot message onto audit trail
737c478bd9Sstevel@tonic-gate 	 */
747c478bd9Sstevel@tonic-gate 	if (!cannot_audit(0)) {
757c478bd9Sstevel@tonic-gate 		int cond = AUC_NOAUDIT;
767c478bd9Sstevel@tonic-gate 		int canaudit;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 		(void) sleep(1);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 		/* find out if audit daemon is running */
817c478bd9Sstevel@tonic-gate 		(void) auditon(A_GETCOND, (caddr_t)&cond, sizeof (cond));
827c478bd9Sstevel@tonic-gate 		canaudit = ((cond == AUC_AUDITING) || (cond == AUC_NOSPACE));
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 		/* turn off audit daemon and try to flush audit queue */
85*1b2d1c94SMarek Pospisil 		if (canaudit && system("/usr/sbin/audit -T"))
867c478bd9Sstevel@tonic-gate 			res = -1;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 		(void) sleep(5);
897c478bd9Sstevel@tonic-gate 	}
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	return (res);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate int
audit_reboot_generic(int sorf)957c478bd9Sstevel@tonic-gate audit_reboot_generic(int sorf)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate 	dprintf(("audit_reboot_generic(%d)\n", sorf));
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	if (cannot_audit(0)) {
1007c478bd9Sstevel@tonic-gate 		return (0);
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	aug_save_sorf(sorf);
1047c478bd9Sstevel@tonic-gate 	(void) aug_audit();
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	return (0);
1077c478bd9Sstevel@tonic-gate }
108