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 511706SJan.Friedel@Sun.COM * Common Development and Distribution License (the "License"). 611706SJan.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*12160SMarek.Pospisil@Sun.COM * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #include <sys/types.h> 260Sstevel@tonic-gate #include <unistd.h> 270Sstevel@tonic-gate #include <stdlib.h> 280Sstevel@tonic-gate #include <bsm/audit.h> 290Sstevel@tonic-gate #include <bsm/audit_record.h> 300Sstevel@tonic-gate #include <bsm/audit_uevents.h> 310Sstevel@tonic-gate #include <bsm/libbsm.h> 320Sstevel@tonic-gate #include <bsm/audit_private.h> 330Sstevel@tonic-gate #include <generic.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef C2_DEBUG 3611706SJan.Friedel@Sun.COM #define dprintf(x) { (void) printf x; } 370Sstevel@tonic-gate #else 380Sstevel@tonic-gate #define dprintf(x) 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate static int audit_reboot_generic(int); 420Sstevel@tonic-gate 430Sstevel@tonic-gate int audit_reboot_setup()440Sstevel@tonic-gateaudit_reboot_setup() 450Sstevel@tonic-gate { 460Sstevel@tonic-gate dprintf(("audit_reboot_setup()\n")); 470Sstevel@tonic-gate 480Sstevel@tonic-gate if (cannot_audit(0)) { 490Sstevel@tonic-gate return (0); 500Sstevel@tonic-gate } 510Sstevel@tonic-gate 520Sstevel@tonic-gate (void) aug_init(); 530Sstevel@tonic-gate aug_save_event(AUE_reboot_solaris); 540Sstevel@tonic-gate (void) aug_save_me(); 550Sstevel@tonic-gate return (0); 560Sstevel@tonic-gate } 570Sstevel@tonic-gate 580Sstevel@tonic-gate int audit_reboot_fail()590Sstevel@tonic-gateaudit_reboot_fail() 600Sstevel@tonic-gate { 610Sstevel@tonic-gate return (audit_reboot_generic(-1)); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate 640Sstevel@tonic-gate int audit_reboot_success()650Sstevel@tonic-gateaudit_reboot_success() 660Sstevel@tonic-gate { 670Sstevel@tonic-gate int res = 0; 680Sstevel@tonic-gate 690Sstevel@tonic-gate (void) audit_reboot_generic(0); 700Sstevel@tonic-gate /* 710Sstevel@tonic-gate * wait for audit daemon 720Sstevel@tonic-gate * to put reboot message onto audit trail 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate if (!cannot_audit(0)) { 750Sstevel@tonic-gate int cond = AUC_NOAUDIT; 760Sstevel@tonic-gate int canaudit; 770Sstevel@tonic-gate 780Sstevel@tonic-gate (void) sleep(1); 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* find out if audit daemon is running */ 810Sstevel@tonic-gate (void) auditon(A_GETCOND, (caddr_t)&cond, sizeof (cond)); 820Sstevel@tonic-gate canaudit = ((cond == AUC_AUDITING) || (cond == AUC_NOSPACE)); 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* turn off audit daemon and try to flush audit queue */ 85*12160SMarek.Pospisil@Sun.COM if (canaudit && system("/usr/sbin/audit -T")) 860Sstevel@tonic-gate res = -1; 870Sstevel@tonic-gate 880Sstevel@tonic-gate (void) sleep(5); 890Sstevel@tonic-gate } 900Sstevel@tonic-gate 910Sstevel@tonic-gate return (res); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate 940Sstevel@tonic-gate int audit_reboot_generic(int sorf)950Sstevel@tonic-gateaudit_reboot_generic(int sorf) 960Sstevel@tonic-gate { 970Sstevel@tonic-gate dprintf(("audit_reboot_generic(%d)\n", sorf)); 980Sstevel@tonic-gate 990Sstevel@tonic-gate if (cannot_audit(0)) { 1000Sstevel@tonic-gate return (0); 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate aug_save_sorf(sorf); 1040Sstevel@tonic-gate (void) aug_audit(); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate return (0); 1070Sstevel@tonic-gate } 108