17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <fcntl.h> 297c478bd9Sstevel@tonic-gate #include <libscf.h> 307c478bd9Sstevel@tonic-gate #include <secdb.h> 317c478bd9Sstevel@tonic-gate #include <stdlib.h> 327c478bd9Sstevel@tonic-gate #include <stdio.h> 337c478bd9Sstevel@tonic-gate #include <string.h> 347c478bd9Sstevel@tonic-gate #include <sys/file.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <sys/wait.h> 377c478bd9Sstevel@tonic-gate #include <signal.h> 387c478bd9Sstevel@tonic-gate #include <sys/param.h> 397c478bd9Sstevel@tonic-gate #include <unistd.h> 407c478bd9Sstevel@tonic-gate #include <bsm/audit.h> 417c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 427c478bd9Sstevel@tonic-gate #include <locale.h> 437c478bd9Sstevel@tonic-gate #include <audit_sig_infc.h> 447c478bd9Sstevel@tonic-gate #include <zone.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 477c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SUNW_OST_OSCMD" 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #define VERIFY -1 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* GLOBALS */ 537c478bd9Sstevel@tonic-gate static char *auditdatafile = AUDITDATAFILE; 547c478bd9Sstevel@tonic-gate static char *progname = "audit"; 557c478bd9Sstevel@tonic-gate static char *usage = "audit [-n] | [-s] | [-t] | [-v filepath]"; 567c478bd9Sstevel@tonic-gate static int silent = 0; 577c478bd9Sstevel@tonic-gate static char *instance_name = "svc:/system/auditd:default"; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate static int get_auditd_pid(); 607c478bd9Sstevel@tonic-gate static void display_smf_error(); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate static boolean_t is_audit_control_ok(char *); /* file validation */ 637c478bd9Sstevel@tonic-gate static boolean_t is_valid_zone(boolean_t); /* operation ok in this zone? */ 647c478bd9Sstevel@tonic-gate static void start_auditd(); /* start audit daemon */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * audit() - This program serves as a general administrator's interface to 687c478bd9Sstevel@tonic-gate * the audit trail. Only one option is valid at a time. 697c478bd9Sstevel@tonic-gate * 707c478bd9Sstevel@tonic-gate * input: 717c478bd9Sstevel@tonic-gate * audit -s 727c478bd9Sstevel@tonic-gate * - signal audit daemon to read audit_control file and 737c478bd9Sstevel@tonic-gate * start auditd if needed. 747c478bd9Sstevel@tonic-gate * audit -n 757c478bd9Sstevel@tonic-gate * - signal audit daemon to use next audit_control audit directory. 767c478bd9Sstevel@tonic-gate * audit -t 777c478bd9Sstevel@tonic-gate * - signal audit daemon to disable auditing. 787c478bd9Sstevel@tonic-gate * audit -T 797c478bd9Sstevel@tonic-gate * - signal audit daemon to disable auditing report no errors. 807c478bd9Sstevel@tonic-gate * audit -v filepath 817c478bd9Sstevel@tonic-gate * - validate audit_control parameters but use filepath for 827c478bd9Sstevel@tonic-gate * the name. Emit errors or "syntax ok" 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate * output: 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate * returns: 0 - command successful 887c478bd9Sstevel@tonic-gate * >0 - command failed 897c478bd9Sstevel@tonic-gate */ 907c478bd9Sstevel@tonic-gate 91*7883e825Spaulson int 927c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 937c478bd9Sstevel@tonic-gate { 947c478bd9Sstevel@tonic-gate pid_t pid; /* process id of auditd read from auditdatafile */ 957c478bd9Sstevel@tonic-gate int sig = 0; /* signal to send auditd */ 967c478bd9Sstevel@tonic-gate char c; 977c478bd9Sstevel@tonic-gate char *first_option; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* Internationalization */ 1007c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1017c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate if (getuid() != 0) { 1047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: not super-user\n"), 1057c478bd9Sstevel@tonic-gate progname); 1067c478bd9Sstevel@tonic-gate exit(2); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate /* first option required */ 1097c478bd9Sstevel@tonic-gate if ((c = getopt(argc, argv, "nstTv:")) == -1) { 1107c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1117c478bd9Sstevel@tonic-gate exit(3); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate first_option = optarg; 1147c478bd9Sstevel@tonic-gate /* second or more options not allowed; please pick one */ 1157c478bd9Sstevel@tonic-gate if (getopt(argc, argv, "nstTv:") != -1) { 1167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1177c478bd9Sstevel@tonic-gate exit(5); 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate switch (c) { 1207c478bd9Sstevel@tonic-gate case 'n': 1217c478bd9Sstevel@tonic-gate if (!is_valid_zone(1)) /* 1 == display error if any */ 1227c478bd9Sstevel@tonic-gate exit(10); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate sig = AU_SIG_NEXT_DIR; 1257c478bd9Sstevel@tonic-gate break; 1267c478bd9Sstevel@tonic-gate case 's': 1277c478bd9Sstevel@tonic-gate if (!is_valid_zone(1)) /* 1 == display error if any */ 1287c478bd9Sstevel@tonic-gate exit(10); 1297c478bd9Sstevel@tonic-gate else if (!is_audit_control_ok(NULL)) 1307c478bd9Sstevel@tonic-gate exit(7); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate start_auditd(); 1337c478bd9Sstevel@tonic-gate break; 1347c478bd9Sstevel@tonic-gate case 't': 1357c478bd9Sstevel@tonic-gate if (!is_valid_zone(0)) /* 0 == no error message display */ 1367c478bd9Sstevel@tonic-gate exit(0); 1377c478bd9Sstevel@tonic-gate /* use bmsunconv to permanently disable, -t for temporary */ 1387c478bd9Sstevel@tonic-gate if (smf_disable_instance(instance_name, SMF_TEMPORARY) != 0) 1397c478bd9Sstevel@tonic-gate display_smf_error(); 1407c478bd9Sstevel@tonic-gate break; 1417c478bd9Sstevel@tonic-gate case 'T': 1427c478bd9Sstevel@tonic-gate if (!is_valid_zone(0)) /* 0 == no error message display */ 1437c478bd9Sstevel@tonic-gate exit(0); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate (void) smf_disable_instance(instance_name, SMF_TEMPORARY); 1467c478bd9Sstevel@tonic-gate silent = 1; 1477c478bd9Sstevel@tonic-gate break; 1487c478bd9Sstevel@tonic-gate case 'v': 1497c478bd9Sstevel@tonic-gate if (is_audit_control_ok(first_option)) { 1507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("syntax ok\n")); 1517c478bd9Sstevel@tonic-gate exit(0); 1527c478bd9Sstevel@tonic-gate } else { 1537c478bd9Sstevel@tonic-gate exit(8); 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate break; 1567c478bd9Sstevel@tonic-gate default: 1577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1587c478bd9Sstevel@tonic-gate exit(6); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate if (get_auditd_pid(&pid) != 0) { 1627c478bd9Sstevel@tonic-gate if (silent) { 1637c478bd9Sstevel@tonic-gate exit(0); 1647c478bd9Sstevel@tonic-gate } else { 1657c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s\n", progname, gettext( 1667c478bd9Sstevel@tonic-gate "can't get process id of auditd from audit_data(4)")); 1677c478bd9Sstevel@tonic-gate exit(4); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate if ((sig != 0) && (kill(pid, sig) != 0)) { 1727c478bd9Sstevel@tonic-gate if (silent) { 1737c478bd9Sstevel@tonic-gate exit(0); 1747c478bd9Sstevel@tonic-gate } else { 1757c478bd9Sstevel@tonic-gate perror(progname); 1767c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1777c478bd9Sstevel@tonic-gate gettext("%s: cannot signal auditd\n"), progname); 1787c478bd9Sstevel@tonic-gate exit(1); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate return (0); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * get_auditd_pid(&pid): 1877c478bd9Sstevel@tonic-gate * 1887c478bd9Sstevel@tonic-gate * reads PID from audit_data 1897c478bd9Sstevel@tonic-gate * 1907c478bd9Sstevel@tonic-gate * returns: 0 - successful 1917c478bd9Sstevel@tonic-gate * 1 - error 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate static int 1957c478bd9Sstevel@tonic-gate get_auditd_pid(pid_t *p_pid) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate FILE *adp; /* audit_data file pointer */ 1987c478bd9Sstevel@tonic-gate int retstat; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate if ((adp = fopen(auditdatafile, "r")) == NULL) { 2017c478bd9Sstevel@tonic-gate if (!silent) 2027c478bd9Sstevel@tonic-gate perror(progname); 2037c478bd9Sstevel@tonic-gate return (1); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate retstat = (fscanf(adp, "%ld", p_pid) != 1); 2067c478bd9Sstevel@tonic-gate (void) fclose(adp); 2077c478bd9Sstevel@tonic-gate return (retstat); 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * perform reasonableness check on audit_control or its standin; goal 2127c478bd9Sstevel@tonic-gate * is that "audit -s" (1) not crash the system and (2) c2audit/auditd 2137c478bd9Sstevel@tonic-gate * actually generates data. 2147c478bd9Sstevel@tonic-gate * 2157c478bd9Sstevel@tonic-gate * A NULL input is ok -- it is used to tell _openac() to use the 2167c478bd9Sstevel@tonic-gate * real audit_control file, not a substitute. 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate #define TRADITIONAL_MAX 1024 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate static boolean_t 2217c478bd9Sstevel@tonic-gate is_audit_control_ok(char *filename) { 2227c478bd9Sstevel@tonic-gate char buf[TRADITIONAL_MAX]; 2237c478bd9Sstevel@tonic-gate int outputs = 0; 2247c478bd9Sstevel@tonic-gate int state = 1; /* 1 is ok, 0 is not */ 2257c478bd9Sstevel@tonic-gate int rc; 2267c478bd9Sstevel@tonic-gate int min; 2277c478bd9Sstevel@tonic-gate kva_t *kvlist; 2287c478bd9Sstevel@tonic-gate char *value; 2297c478bd9Sstevel@tonic-gate au_acinfo_t *ach; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate ach = _openac(filename); /* open audit_control */ 2327c478bd9Sstevel@tonic-gate if (ach == NULL) { 2337c478bd9Sstevel@tonic-gate perror(progname); 2347c478bd9Sstevel@tonic-gate exit(9); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate /* 2377c478bd9Sstevel@tonic-gate * There must be at least one directory or one plugin 2387c478bd9Sstevel@tonic-gate * defined. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate if ((rc = _getacdir(ach, buf, TRADITIONAL_MAX)) == 0) { 2417c478bd9Sstevel@tonic-gate outputs++; 2427c478bd9Sstevel@tonic-gate } else if (rc < -1) { /* -1 is not found, others are errors */ 2437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2447c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"dir:\" spec invalid\n"), 2457c478bd9Sstevel@tonic-gate progname); 2467c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * _getacplug -- all that is of interest is the return code. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate _rewindac(ach); /* rewind audit_control */ 2537c478bd9Sstevel@tonic-gate if ((rc = _getacplug(ach, &kvlist)) == 0) { 2547c478bd9Sstevel@tonic-gate value = kva_match(kvlist, "name"); 2557c478bd9Sstevel@tonic-gate if (value == NULL) { 2567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: audit_control " 2577c478bd9Sstevel@tonic-gate "\"plugin:\" missing name\n"), progname); 2587c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate else 2617c478bd9Sstevel@tonic-gate outputs++; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate _kva_free(kvlist); 2647c478bd9Sstevel@tonic-gate } else if (rc < -1) { 2657c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2667c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"plugin:\" spec invalid\n"), 2677c478bd9Sstevel@tonic-gate progname); 2687c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate if (outputs == 0) { 2717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2727c478bd9Sstevel@tonic-gate gettext("%s: audit_control must have either a " 2737c478bd9Sstevel@tonic-gate "\"dir:\" or a \"plugin:\" specified.\n"), 2747c478bd9Sstevel@tonic-gate progname); 2757c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate /* minfree is not required */ 2787c478bd9Sstevel@tonic-gate _rewindac(ach); 2797c478bd9Sstevel@tonic-gate if ((rc = _getacmin(ach, &min)) < -1) { 2807c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2817c478bd9Sstevel@tonic-gate gettext( 2827c478bd9Sstevel@tonic-gate "%s: audit_control \"minfree:\" spec invalid\n"), 2837c478bd9Sstevel@tonic-gate progname); 2847c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate /* flags is not required */ 2877c478bd9Sstevel@tonic-gate _rewindac(ach); 2887c478bd9Sstevel@tonic-gate if ((rc = _getacflg(ach, buf, TRADITIONAL_MAX)) < -1) { 2897c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2907c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"flags:\" spec invalid\n"), 2917c478bd9Sstevel@tonic-gate progname); 2927c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate /* naflags is not required */ 2957c478bd9Sstevel@tonic-gate _rewindac(ach); 2967c478bd9Sstevel@tonic-gate if ((rc = _getacna(ach, buf, TRADITIONAL_MAX)) < -1) { 2977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2987c478bd9Sstevel@tonic-gate gettext( 2997c478bd9Sstevel@tonic-gate "%s: audit_control \"naflags:\" spec invalid\n"), 3007c478bd9Sstevel@tonic-gate progname); 3017c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate _endac(ach); 3047c478bd9Sstevel@tonic-gate return (state); 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate /* 3087c478bd9Sstevel@tonic-gate * The operations that call this function are only valid in the global 3097c478bd9Sstevel@tonic-gate * zone unless the perzone audit policy is set. 3107c478bd9Sstevel@tonic-gate * 3117c478bd9Sstevel@tonic-gate * "!silent" and "show_err" are slightly different; silent is from 3127c478bd9Sstevel@tonic-gate * -T for which no error messages should be displayed and show_err 3137c478bd9Sstevel@tonic-gate * applies to more options (including -T) 3147c478bd9Sstevel@tonic-gate * 3157c478bd9Sstevel@tonic-gate */ 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate static boolean_t 3187c478bd9Sstevel@tonic-gate is_valid_zone(boolean_t show_err) 3197c478bd9Sstevel@tonic-gate { 3207c478bd9Sstevel@tonic-gate long policy; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate if (auditon(A_GETPOLICY, (char *)&policy, 0) == -1) { 3237c478bd9Sstevel@tonic-gate if (!silent) 3247c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 3257c478bd9Sstevel@tonic-gate "%s: Cannot read audit policy: %s\n"), 3267c478bd9Sstevel@tonic-gate progname, strerror(errno)); 3277c478bd9Sstevel@tonic-gate return (0); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate if (policy & AUDIT_PERZONE) 3307c478bd9Sstevel@tonic-gate return (1); 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 3337c478bd9Sstevel@tonic-gate if (show_err) 3347c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3357c478bd9Sstevel@tonic-gate gettext("%s: Not valid in a local zone.\n"), 3367c478bd9Sstevel@tonic-gate progname); 3377c478bd9Sstevel@tonic-gate return (0); 3387c478bd9Sstevel@tonic-gate } else { 3397c478bd9Sstevel@tonic-gate return (1); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate /* 3447c478bd9Sstevel@tonic-gate * if auditd isn't running, start it. Otherwise refresh. 3457c478bd9Sstevel@tonic-gate * First check to see if c2audit is loaded via the auditon() 3467c478bd9Sstevel@tonic-gate * system call, then check SMF state. 3477c478bd9Sstevel@tonic-gate */ 3487c478bd9Sstevel@tonic-gate static void 3497c478bd9Sstevel@tonic-gate start_auditd() 3507c478bd9Sstevel@tonic-gate { 3517c478bd9Sstevel@tonic-gate int audit_state; 3527c478bd9Sstevel@tonic-gate char *state; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate if (auditon(A_GETCOND, (caddr_t)&audit_state, 3557c478bd9Sstevel@tonic-gate sizeof (audit_state)) != 0) 3567c478bd9Sstevel@tonic-gate return; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate if ((state = smf_get_state(instance_name)) == NULL) { 3597c478bd9Sstevel@tonic-gate display_smf_error(); 3607c478bd9Sstevel@tonic-gate return; 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate if (strcmp(SCF_STATE_STRING_ONLINE, state) != 0) { 3637c478bd9Sstevel@tonic-gate if (smf_enable_instance(instance_name, 0) != 0) 3647c478bd9Sstevel@tonic-gate display_smf_error(); 3657c478bd9Sstevel@tonic-gate } else { 3667c478bd9Sstevel@tonic-gate if (smf_refresh_instance(instance_name) != 0) 3677c478bd9Sstevel@tonic-gate display_smf_error(); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate free(state); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate static void 3737c478bd9Sstevel@tonic-gate display_smf_error() 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate int rc = scf_error(); 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate switch (rc) { 3787c478bd9Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 3797c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3807c478bd9Sstevel@tonic-gate "SMF error: \"%s\" not found.\n", 3817c478bd9Sstevel@tonic-gate instance_name); 3827c478bd9Sstevel@tonic-gate break; 3837c478bd9Sstevel@tonic-gate default: 3847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "SMF error %d\n", rc); 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 388