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