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 56d59ee37Spaulson * Common Development and Distribution License (the "License"). 66d59ee37Spaulson * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*1b2d1c94SMarek Pospisil 227c478bd9Sstevel@tonic-gate /* 23*1b2d1c94SMarek Pospisil * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <fcntl.h> 277c478bd9Sstevel@tonic-gate #include <libscf.h> 287c478bd9Sstevel@tonic-gate #include <secdb.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <stdio.h> 317c478bd9Sstevel@tonic-gate #include <string.h> 327c478bd9Sstevel@tonic-gate #include <sys/file.h> 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/wait.h> 357c478bd9Sstevel@tonic-gate #include <signal.h> 367c478bd9Sstevel@tonic-gate #include <sys/param.h> 377c478bd9Sstevel@tonic-gate #include <unistd.h> 387c478bd9Sstevel@tonic-gate #include <bsm/audit.h> 397c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h> 407c478bd9Sstevel@tonic-gate #include <locale.h> 417c478bd9Sstevel@tonic-gate #include <audit_sig_infc.h> 427c478bd9Sstevel@tonic-gate #include <zone.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 457c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SUNW_OST_OSCMD" 467c478bd9Sstevel@tonic-gate #endif 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #define VERIFY -1 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* GLOBALS */ 517c478bd9Sstevel@tonic-gate static char *progname = "audit"; 527c478bd9Sstevel@tonic-gate static char *usage = "audit [-n] | [-s] | [-t] | [-v filepath]"; 53*1b2d1c94SMarek Pospisil static int silent = 0; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static void display_smf_error(); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate static boolean_t is_audit_control_ok(char *); /* file validation */ 587c478bd9Sstevel@tonic-gate static boolean_t is_valid_zone(boolean_t); /* operation ok in this zone? */ 596d59ee37Spaulson static int start_auditd(); /* start audit daemon */ 604c17c04fSgww static int sig_auditd(int); /* send signal to auditd */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * audit() - This program serves as a general administrator's interface to 647c478bd9Sstevel@tonic-gate * the audit trail. Only one option is valid at a time. 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * input: 677c478bd9Sstevel@tonic-gate * audit -s 687c478bd9Sstevel@tonic-gate * - signal audit daemon to read audit_control file and 697c478bd9Sstevel@tonic-gate * start auditd if needed. 707c478bd9Sstevel@tonic-gate * audit -n 717c478bd9Sstevel@tonic-gate * - signal audit daemon to use next audit_control audit directory. 727c478bd9Sstevel@tonic-gate * audit -t 73*1b2d1c94SMarek Pospisil * - signal audit daemon to disable auditing. 74*1b2d1c94SMarek Pospisil * audit -T 75*1b2d1c94SMarek Pospisil * - signal audit daemon to temporarily disable auditing reporting 76*1b2d1c94SMarek Pospisil * no errors. 777c478bd9Sstevel@tonic-gate * audit -v filepath 787c478bd9Sstevel@tonic-gate * - validate audit_control parameters but use filepath for 797c478bd9Sstevel@tonic-gate * the name. Emit errors or "syntax ok" 807c478bd9Sstevel@tonic-gate * 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * output: 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * returns: 0 - command successful 857c478bd9Sstevel@tonic-gate * >0 - command failed 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate 887883e825Spaulson int 897c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 907c478bd9Sstevel@tonic-gate { 917c478bd9Sstevel@tonic-gate char c; 927c478bd9Sstevel@tonic-gate char *first_option; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* Internationalization */ 957c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 967c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* first option required */ 99*1b2d1c94SMarek Pospisil if ((c = getopt(argc, argv, "nstTv:")) == -1) { 1007c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1017c478bd9Sstevel@tonic-gate exit(3); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate first_option = optarg; 1047c478bd9Sstevel@tonic-gate /* second or more options not allowed; please pick one */ 105*1b2d1c94SMarek Pospisil if (getopt(argc, argv, "nstTv:") != -1) { 1067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1077c478bd9Sstevel@tonic-gate exit(5); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate switch (c) { 1107c478bd9Sstevel@tonic-gate case 'n': 1117c478bd9Sstevel@tonic-gate if (!is_valid_zone(1)) /* 1 == display error if any */ 1127c478bd9Sstevel@tonic-gate exit(10); 1137c478bd9Sstevel@tonic-gate 1144c17c04fSgww if (sig_auditd(AU_SIG_NEXT_DIR) != 0) 1154c17c04fSgww exit(1); 1167c478bd9Sstevel@tonic-gate break; 1177c478bd9Sstevel@tonic-gate case 's': 1187c478bd9Sstevel@tonic-gate if (!is_valid_zone(1)) /* 1 == display error if any */ 1197c478bd9Sstevel@tonic-gate exit(10); 1207c478bd9Sstevel@tonic-gate else if (!is_audit_control_ok(NULL)) 1217c478bd9Sstevel@tonic-gate exit(7); 1227c478bd9Sstevel@tonic-gate 1236d59ee37Spaulson return (start_auditd()); 1247c478bd9Sstevel@tonic-gate case 't': 1257c478bd9Sstevel@tonic-gate if (!is_valid_zone(0)) /* 0 == no error message display */ 1266d59ee37Spaulson exit(10); 127005d3febSMarek Pospisil if (smf_disable_instance(AUDITD_FMRI, 0) != 0) { 1287c478bd9Sstevel@tonic-gate display_smf_error(); 1296d59ee37Spaulson exit(11); 1306d59ee37Spaulson } 1317c478bd9Sstevel@tonic-gate break; 132*1b2d1c94SMarek Pospisil case 'T': 133*1b2d1c94SMarek Pospisil silent = 1; 134*1b2d1c94SMarek Pospisil if (!is_valid_zone(0)) /* 0 == no error message display */ 135*1b2d1c94SMarek Pospisil exit(10); 136*1b2d1c94SMarek Pospisil 137*1b2d1c94SMarek Pospisil if (smf_disable_instance(AUDITD_FMRI, SMF_TEMPORARY) != 0) { 138*1b2d1c94SMarek Pospisil exit(11); 139*1b2d1c94SMarek Pospisil } 140*1b2d1c94SMarek Pospisil break; 1417c478bd9Sstevel@tonic-gate case 'v': 1427c478bd9Sstevel@tonic-gate if (is_audit_control_ok(first_option)) { 1437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("syntax ok\n")); 1447c478bd9Sstevel@tonic-gate exit(0); 1457c478bd9Sstevel@tonic-gate } else { 1467c478bd9Sstevel@tonic-gate exit(8); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate break; 1497c478bd9Sstevel@tonic-gate default: 1507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("usage: %s\n"), usage); 1517c478bd9Sstevel@tonic-gate exit(6); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate return (0); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1584c17c04fSgww * sig_auditd(sig) 1597c478bd9Sstevel@tonic-gate * 1604c17c04fSgww * send a signal to auditd service 1617c478bd9Sstevel@tonic-gate * 1627c478bd9Sstevel@tonic-gate * returns: 0 - successful 1637c478bd9Sstevel@tonic-gate * 1 - error 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate static int 1674c17c04fSgww sig_auditd(int sig) 1687c478bd9Sstevel@tonic-gate { 1694c17c04fSgww scf_simple_prop_t *prop = NULL; 1704c17c04fSgww uint64_t *cid = NULL; 1717c478bd9Sstevel@tonic-gate 1724c17c04fSgww if ((prop = scf_simple_prop_get(NULL, AUDITD_FMRI, SCF_PG_RESTARTER, 1734c17c04fSgww SCF_PROPERTY_CONTRACT)) == NULL) { 1744c17c04fSgww display_smf_error(); 1757c478bd9Sstevel@tonic-gate return (1); 1767c478bd9Sstevel@tonic-gate } 1774c17c04fSgww if ((scf_simple_prop_numvalues(prop) < 0) || 1784c17c04fSgww (cid = scf_simple_prop_next_count(prop)) == NULL) { 1794c17c04fSgww scf_simple_prop_free(prop); 1804c17c04fSgww display_smf_error(); 1814c17c04fSgww return (1); 1824c17c04fSgww } 1834c17c04fSgww if (sigsend(P_CTID, (ctid_t)*cid, sig) != 0) { 1844c17c04fSgww perror("audit: can't signal auditd"); 1854c17c04fSgww scf_simple_prop_free(prop); 1864c17c04fSgww return (1); 1874c17c04fSgww } 1884c17c04fSgww scf_simple_prop_free(prop); 1894c17c04fSgww return (0); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * perform reasonableness check on audit_control or its standin; goal 1947c478bd9Sstevel@tonic-gate * is that "audit -s" (1) not crash the system and (2) c2audit/auditd 1957c478bd9Sstevel@tonic-gate * actually generates data. 1967c478bd9Sstevel@tonic-gate * 1977c478bd9Sstevel@tonic-gate * A NULL input is ok -- it is used to tell _openac() to use the 1987c478bd9Sstevel@tonic-gate * real audit_control file, not a substitute. 1997c478bd9Sstevel@tonic-gate */ 2007c478bd9Sstevel@tonic-gate #define TRADITIONAL_MAX 1024 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate static boolean_t 2037c478bd9Sstevel@tonic-gate is_audit_control_ok(char *filename) { 2047c478bd9Sstevel@tonic-gate char buf[TRADITIONAL_MAX]; 2057c478bd9Sstevel@tonic-gate int outputs = 0; 2067c478bd9Sstevel@tonic-gate int state = 1; /* 1 is ok, 0 is not */ 2077c478bd9Sstevel@tonic-gate int rc; 2087c478bd9Sstevel@tonic-gate int min; 2097c478bd9Sstevel@tonic-gate kva_t *kvlist; 2101a578a15Spaulson char *plugin_name; 2111a578a15Spaulson char *plugin_dir; 2127c478bd9Sstevel@tonic-gate au_acinfo_t *ach; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate ach = _openac(filename); /* open audit_control */ 2157c478bd9Sstevel@tonic-gate if (ach == NULL) { 2167c478bd9Sstevel@tonic-gate perror(progname); 2177c478bd9Sstevel@tonic-gate exit(9); 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate /* 2207c478bd9Sstevel@tonic-gate * There must be at least one directory or one plugin 2217c478bd9Sstevel@tonic-gate * defined. 2227c478bd9Sstevel@tonic-gate */ 2237c478bd9Sstevel@tonic-gate if ((rc = _getacdir(ach, buf, TRADITIONAL_MAX)) == 0) { 2247c478bd9Sstevel@tonic-gate outputs++; 2257c478bd9Sstevel@tonic-gate } else if (rc < -1) { /* -1 is not found, others are errors */ 2267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2277c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"dir:\" spec invalid\n"), 2287c478bd9Sstevel@tonic-gate progname); 2297c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * _getacplug -- all that is of interest is the return code. 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate _rewindac(ach); /* rewind audit_control */ 2361a578a15Spaulson while ((rc = _getacplug(ach, &kvlist)) == 0) { 2371a578a15Spaulson plugin_name = kva_match(kvlist, "name"); 2381a578a15Spaulson if (plugin_name == NULL) { 2397c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("%s: audit_control " 2407c478bd9Sstevel@tonic-gate "\"plugin:\" missing name\n"), progname); 2417c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2421a578a15Spaulson } else { 2431a578a15Spaulson if (strcmp(plugin_name, "audit_binfile.so") == 0) { 2441a578a15Spaulson plugin_dir = kva_match(kvlist, "p_dir"); 2451a578a15Spaulson if ((plugin_dir == NULL) && (outputs == 0)) { 2461a578a15Spaulson (void) fprintf(stderr, 2471a578a15Spaulson gettext("%s: audit_control " 2481a578a15Spaulson "\"plugin:\" missing p_dir\n"), 2491a578a15Spaulson progname); 2501a578a15Spaulson state = 0; /* is_not_ok */ 2511a578a15Spaulson } else { 2527c478bd9Sstevel@tonic-gate outputs++; 2531a578a15Spaulson } 2541a578a15Spaulson } 2551a578a15Spaulson } 2567c478bd9Sstevel@tonic-gate _kva_free(kvlist); 2571a578a15Spaulson } 2581a578a15Spaulson if (rc < -1) { 2597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2607c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"plugin:\" spec invalid\n"), 2617c478bd9Sstevel@tonic-gate progname); 2627c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate if (outputs == 0) { 2657c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2667c478bd9Sstevel@tonic-gate gettext("%s: audit_control must have either a " 2671a578a15Spaulson "valid \"dir:\" entry or a valid \"plugin:\" " 2681a578a15Spaulson "entry with \"p_dir:\" specified.\n"), 2697c478bd9Sstevel@tonic-gate progname); 2707c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2717c478bd9Sstevel@tonic-gate } 2727c478bd9Sstevel@tonic-gate /* minfree is not required */ 2737c478bd9Sstevel@tonic-gate _rewindac(ach); 2747c478bd9Sstevel@tonic-gate if ((rc = _getacmin(ach, &min)) < -1) { 2757c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2767c478bd9Sstevel@tonic-gate gettext( 2777c478bd9Sstevel@tonic-gate "%s: audit_control \"minfree:\" spec invalid\n"), 2787c478bd9Sstevel@tonic-gate progname); 2797c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate /* flags is not required */ 2827c478bd9Sstevel@tonic-gate _rewindac(ach); 2837c478bd9Sstevel@tonic-gate if ((rc = _getacflg(ach, buf, TRADITIONAL_MAX)) < -1) { 2847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2857c478bd9Sstevel@tonic-gate gettext("%s: audit_control \"flags:\" spec invalid\n"), 2867c478bd9Sstevel@tonic-gate progname); 2877c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate /* naflags is not required */ 2907c478bd9Sstevel@tonic-gate _rewindac(ach); 2917c478bd9Sstevel@tonic-gate if ((rc = _getacna(ach, buf, TRADITIONAL_MAX)) < -1) { 2927c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2937c478bd9Sstevel@tonic-gate gettext( 2947c478bd9Sstevel@tonic-gate "%s: audit_control \"naflags:\" spec invalid\n"), 2957c478bd9Sstevel@tonic-gate progname); 2967c478bd9Sstevel@tonic-gate state = 0; /* is_not_ok */ 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate _endac(ach); 2997c478bd9Sstevel@tonic-gate return (state); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate /* 3037c478bd9Sstevel@tonic-gate * The operations that call this function are only valid in the global 3047c478bd9Sstevel@tonic-gate * zone unless the perzone audit policy is set. 305*1b2d1c94SMarek Pospisil * 306*1b2d1c94SMarek Pospisil * "!silent" and "show_err" are slightly different; silent is from 307*1b2d1c94SMarek Pospisil * -T for which no error messages should be displayed and show_err 308*1b2d1c94SMarek Pospisil * applies to more options (including -T) 309*1b2d1c94SMarek Pospisil * 3107c478bd9Sstevel@tonic-gate */ 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate static boolean_t 3137c478bd9Sstevel@tonic-gate is_valid_zone(boolean_t show_err) 3147c478bd9Sstevel@tonic-gate { 31596093503SMarek Pospisil uint32_t policy; 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate if (auditon(A_GETPOLICY, (char *)&policy, 0) == -1) { 318*1b2d1c94SMarek Pospisil if (!silent) { 3197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 3207c478bd9Sstevel@tonic-gate "%s: Cannot read audit policy: %s\n"), 3217c478bd9Sstevel@tonic-gate progname, strerror(errno)); 322*1b2d1c94SMarek Pospisil } 3237c478bd9Sstevel@tonic-gate return (0); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate if (policy & AUDIT_PERZONE) 3267c478bd9Sstevel@tonic-gate return (1); 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate if (getzoneid() != GLOBAL_ZONEID) { 3297c478bd9Sstevel@tonic-gate if (show_err) 3307c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3317c478bd9Sstevel@tonic-gate gettext("%s: Not valid in a local zone.\n"), 3327c478bd9Sstevel@tonic-gate progname); 3337c478bd9Sstevel@tonic-gate return (0); 3347c478bd9Sstevel@tonic-gate } else { 3357c478bd9Sstevel@tonic-gate return (1); 3367c478bd9Sstevel@tonic-gate } 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate /* 3407c478bd9Sstevel@tonic-gate * if auditd isn't running, start it. Otherwise refresh. 3417c478bd9Sstevel@tonic-gate * First check to see if c2audit is loaded via the auditon() 3427c478bd9Sstevel@tonic-gate * system call, then check SMF state. 3437c478bd9Sstevel@tonic-gate */ 3446d59ee37Spaulson static int 3457c478bd9Sstevel@tonic-gate start_auditd() 3467c478bd9Sstevel@tonic-gate { 3477c478bd9Sstevel@tonic-gate int audit_state; 3487c478bd9Sstevel@tonic-gate char *state; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate if (auditon(A_GETCOND, (caddr_t)&audit_state, 3517c478bd9Sstevel@tonic-gate sizeof (audit_state)) != 0) 3526d59ee37Spaulson return (12); 3537c478bd9Sstevel@tonic-gate 3544c17c04fSgww if ((state = smf_get_state(AUDITD_FMRI)) == NULL) { 3557c478bd9Sstevel@tonic-gate display_smf_error(); 3566d59ee37Spaulson return (13); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate if (strcmp(SCF_STATE_STRING_ONLINE, state) != 0) { 3594c17c04fSgww if (smf_enable_instance(AUDITD_FMRI, 0) != 0) { 3607c478bd9Sstevel@tonic-gate display_smf_error(); 3616d59ee37Spaulson free(state); 3626d59ee37Spaulson return (14); 3636d59ee37Spaulson } 3647c478bd9Sstevel@tonic-gate } else { 3654c17c04fSgww if (smf_refresh_instance(AUDITD_FMRI) != 0) { 3667c478bd9Sstevel@tonic-gate display_smf_error(); 3676d59ee37Spaulson free(state); 3686d59ee37Spaulson return (15); 3696d59ee37Spaulson } 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate free(state); 3726d59ee37Spaulson return (0); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate static void 3767c478bd9Sstevel@tonic-gate display_smf_error() 3777c478bd9Sstevel@tonic-gate { 3784c17c04fSgww scf_error_t rc = scf_error(); 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate switch (rc) { 3817c478bd9Sstevel@tonic-gate case SCF_ERROR_NOT_FOUND: 3827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3837c478bd9Sstevel@tonic-gate "SMF error: \"%s\" not found.\n", 3844c17c04fSgww AUDITD_FMRI); 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate default: 3876d59ee37Spaulson (void) fprintf(stderr, "SMF error: %s\n", scf_strerror(rc)); 3887c478bd9Sstevel@tonic-gate break; 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate } 391