xref: /onnv-gate/usr/src/lib/libbsm/common/audit_shutdown.c (revision 11706:cd830a066051)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11706SJan.Friedel@Sun.COM  * Common Development and Distribution License (the "License").
6*11706SJan.Friedel@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11706SJan.Friedel@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <stdio.h>
280Sstevel@tonic-gate #include <sys/fcntl.h>
290Sstevel@tonic-gate #include <bsm/audit.h>
300Sstevel@tonic-gate #include <bsm/audit_record.h>
310Sstevel@tonic-gate #include <bsm/audit_uevents.h>
320Sstevel@tonic-gate #include <bsm/libbsm.h>
330Sstevel@tonic-gate #include <bsm/audit_private.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <syslog.h>
370Sstevel@tonic-gate #include <netinet/in.h>
380Sstevel@tonic-gate #include <generic.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef C2_DEBUG
41*11706SJan.Friedel@Sun.COM #define	dprintf(x) { (void) printf x; }
420Sstevel@tonic-gate #else
430Sstevel@tonic-gate #define	dprintf(x)
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate static int audit_shutdown_generic(int);
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /* ARGSUSED */
490Sstevel@tonic-gate int
audit_shutdown_setup(int argc,char ** argv)500Sstevel@tonic-gate audit_shutdown_setup(int argc, char **argv)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	dprintf(("audit_shutdown_setup()\n"));
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	if (cannot_audit(0)) {
550Sstevel@tonic-gate 		return (0);
560Sstevel@tonic-gate 	}
570Sstevel@tonic-gate 	(void) aug_init();
580Sstevel@tonic-gate 	aug_save_event(AUE_shutdown_solaris);
590Sstevel@tonic-gate 	(void) aug_save_me();
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 	return (0);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate 
640Sstevel@tonic-gate int
audit_shutdown_fail()650Sstevel@tonic-gate audit_shutdown_fail()
660Sstevel@tonic-gate {
670Sstevel@tonic-gate 	return (audit_shutdown_generic(-1));
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate int
audit_shutdown_success()710Sstevel@tonic-gate audit_shutdown_success()
720Sstevel@tonic-gate {
730Sstevel@tonic-gate 	return (audit_shutdown_generic(0));
740Sstevel@tonic-gate }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate static int
audit_shutdown_generic(sorf)770Sstevel@tonic-gate audit_shutdown_generic(sorf)
780Sstevel@tonic-gate 	int sorf;
790Sstevel@tonic-gate {
800Sstevel@tonic-gate 	int r;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	dprintf(("audit_shutdown_generic(%d)\n", sorf));
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	if (cannot_audit(0)) {
850Sstevel@tonic-gate 		return (0);
860Sstevel@tonic-gate 	}
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	aug_save_sorf(sorf);
890Sstevel@tonic-gate 	r = aug_audit();
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	return (r);
920Sstevel@tonic-gate }
93