xref: /titanic_44/usr/src/lib/libbsm/common/audit_reboot.c (revision 1b2d1c944935c64d6eeb28c8054864f4bdf20e9f)
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 /*
22  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <bsm/audit.h>
29 #include <bsm/audit_record.h>
30 #include <bsm/audit_uevents.h>
31 #include <bsm/libbsm.h>
32 #include <bsm/audit_private.h>
33 #include <generic.h>
34 
35 #ifdef C2_DEBUG
36 #define	dprintf(x) { (void) printf x; }
37 #else
38 #define	dprintf(x)
39 #endif
40 
41 static int audit_reboot_generic(int);
42 
43 int
audit_reboot_setup()44 audit_reboot_setup()
45 {
46 	dprintf(("audit_reboot_setup()\n"));
47 
48 	if (cannot_audit(0)) {
49 		return (0);
50 	}
51 
52 	(void) aug_init();
53 	aug_save_event(AUE_reboot_solaris);
54 	(void) aug_save_me();
55 	return (0);
56 }
57 
58 int
audit_reboot_fail()59 audit_reboot_fail()
60 {
61 	return (audit_reboot_generic(-1));
62 }
63 
64 int
audit_reboot_success()65 audit_reboot_success()
66 {
67 	int res = 0;
68 
69 	(void) audit_reboot_generic(0);
70 	/*
71 	 * wait for audit daemon
72 	 * to put reboot message onto audit trail
73 	 */
74 	if (!cannot_audit(0)) {
75 		int cond = AUC_NOAUDIT;
76 		int canaudit;
77 
78 		(void) sleep(1);
79 
80 		/* find out if audit daemon is running */
81 		(void) auditon(A_GETCOND, (caddr_t)&cond, sizeof (cond));
82 		canaudit = ((cond == AUC_AUDITING) || (cond == AUC_NOSPACE));
83 
84 		/* turn off audit daemon and try to flush audit queue */
85 		if (canaudit && system("/usr/sbin/audit -T"))
86 			res = -1;
87 
88 		(void) sleep(5);
89 	}
90 
91 	return (res);
92 }
93 
94 int
audit_reboot_generic(int sorf)95 audit_reboot_generic(int sorf)
96 {
97 	dprintf(("audit_reboot_generic(%d)\n", sorf));
98 
99 	if (cannot_audit(0)) {
100 		return (0);
101 	}
102 
103 	aug_save_sorf(sorf);
104 	(void) aug_audit();
105 
106 	return (0);
107 }
108