xref: /titanic_50/usr/src/lib/libbsm/common/audit_shutdown.c (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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 <stdio.h>
30 #include <sys/fcntl.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 <stdlib.h>
37 #include <string.h>
38 #include <syslog.h>
39 #include <netinet/in.h>
40 #include <generic.h>
41 
42 #ifdef C2_DEBUG
43 #define	dprintf(x) {printf x; }
44 #else
45 #define	dprintf(x)
46 #endif
47 
48 static int audit_shutdown_generic(int);
49 
50 /* ARGSUSED */
51 int
52 audit_shutdown_setup(int argc, char **argv)
53 {
54 	dprintf(("audit_shutdown_setup()\n"));
55 
56 	if (cannot_audit(0)) {
57 		return (0);
58 	}
59 	(void) aug_init();
60 	aug_save_event(AUE_shutdown_solaris);
61 	(void) aug_save_me();
62 
63 	return (0);
64 }
65 
66 int
67 audit_shutdown_fail()
68 {
69 	return (audit_shutdown_generic(-1));
70 }
71 
72 int
73 audit_shutdown_success()
74 {
75 	return (audit_shutdown_generic(0));
76 }
77 
78 static int
79 audit_shutdown_generic(sorf)
80 	int sorf;
81 {
82 	int r;
83 
84 	dprintf(("audit_shutdown_generic(%d)\n", sorf));
85 
86 	if (cannot_audit(0)) {
87 		return (0);
88 	}
89 
90 	aug_save_sorf(sorf);
91 	r = aug_audit();
92 
93 	return (r);
94 }
95