2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <stdio.h>
2N/A#include <unistd.h>
2N/A#include <sys/fcntl.h>
2N/A#include <bsm/audit.h>
2N/A#include <bsm/audit_record.h>
2N/A#include <bsm/audit_uevents.h>
2N/A#include <bsm/libbsm.h>
2N/A#include <bsm/audit_private.h>
2N/A#include <stdlib.h>
2N/A#include <string.h>
2N/A#include <syslog.h>
2N/A#include <netinet/in.h>
2N/A#include <libgen.h>
2N/A#include <generic.h>
2N/A
2N/A#ifdef C2_DEBUG
2N/A#define dprintf(x) { (void) printf x; }
2N/A#else
2N/A#define dprintf(x)
2N/A#endif
2N/A
2N/Astatic int audit_halt_generic(int);
2N/A
2N/A/* ARGSUSED */
2N/Aint
2N/Aaudit_halt_setup(int argc, char **argv)
2N/A{
2N/A char *cmdname;
2N/A
2N/A dprintf(("audit_halt_setup()\n"));
2N/A
2N/A if (cannot_audit(0)) {
2N/A return (0);
2N/A }
2N/A
2N/A cmdname = basename(*argv);
2N/A
2N/A aug_init();
2N/A
2N/A if (strcmp(cmdname, "halt") == 0)
2N/A aug_save_event(AUE_halt_solaris);
2N/A else if (strcmp(cmdname, "poweroff") == 0)
2N/A aug_save_event(AUE_poweroff_solaris);
2N/A else
2N/A exit(1);
2N/A (void) aug_save_me();
2N/A return (0);
2N/A}
2N/A
2N/Aint
2N/Aaudit_halt_fail()
2N/A{
2N/A return (audit_halt_generic(-1));
2N/A}
2N/A
2N/Aint
2N/Aaudit_halt_success()
2N/A{
2N/A int res = 0;
2N/A
2N/A (void) audit_halt_generic(0);
2N/A
2N/A /* wait for audit daemon to put halt message onto audit trail */
2N/A if (!cannot_audit(0)) {
2N/A int cond = AUC_NOAUDIT;
2N/A
2N/A (void) sleep(1);
2N/A
2N/A /* find out if audit daemon is running */
2N/A (void) auditon(A_GETCOND, (caddr_t)&cond, sizeof (cond));
2N/A
2N/A /* turn off audit daemon and try to flush audit queue */
2N/A if (cond == AUC_AUDITING && system("/usr/sbin/audit -T"))
2N/A res = -1;
2N/A else
2N/A /* give a chance for syslogd to do the job */
2N/A (void) sleep(5);
2N/A }
2N/A
2N/A return (res);
2N/A}
2N/A
2N/Aint
2N/Aaudit_halt_generic(sorf)
2N/A int sorf;
2N/A{
2N/A int r;
2N/A
2N/A dprintf(("audit_halt_generic(%d)\n", sorf));
2N/A
2N/A if (cannot_audit(0)) {
2N/A return (0);
2N/A }
2N/A
2N/A aug_save_sorf(sorf);
2N/A r = aug_audit();
2N/A
2N/A return (r);
2N/A}