1f8994074SJan Friedel /* 2f8994074SJan Friedel * CDDL HEADER START 3f8994074SJan Friedel * 4f8994074SJan Friedel * The contents of this file are subject to the terms of the 5f8994074SJan Friedel * Common Development and Distribution License (the "License"). 6f8994074SJan Friedel * You may not use this file except in compliance with the License. 7f8994074SJan Friedel * 8f8994074SJan Friedel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9f8994074SJan Friedel * or http://www.opensolaris.org/os/licensing. 10f8994074SJan Friedel * See the License for the specific language governing permissions 11f8994074SJan Friedel * and limitations under the License. 12f8994074SJan Friedel * 13f8994074SJan Friedel * When distributing Covered Code, include this CDDL HEADER in each 14f8994074SJan Friedel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15f8994074SJan Friedel * If applicable, add the following below this CDDL HEADER, with the 16f8994074SJan Friedel * fields enclosed by brackets "[]" replaced with your own identifying 17f8994074SJan Friedel * information: Portions Copyright [yyyy] [name of copyright owner] 18f8994074SJan Friedel * 19f8994074SJan Friedel * CDDL HEADER END 20f8994074SJan Friedel */ 21f8994074SJan Friedel /* 22f8994074SJan Friedel * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 23f8994074SJan Friedel */ 24f8994074SJan Friedel 25f8994074SJan Friedel /* 26f8994074SJan Friedel * svc-auditset - auditset transient service (AUDITSET_FMRI) startup method; 27f8994074SJan Friedel * sets non-/attributable mask in the kernel context. 28f8994074SJan Friedel */ 29f8994074SJan Friedel 30f8994074SJan Friedel #include <audit_scf.h> 31f8994074SJan Friedel #include <bsm/adt.h> 32f8994074SJan Friedel #include <bsm/libbsm.h> 33*da5086c1SAlbert Lee #include <zone.h> 34f8994074SJan Friedel #include <errno.h> 35f8994074SJan Friedel #include <locale.h> 36f8994074SJan Friedel #include <stdio.h> 37f8994074SJan Friedel 38f8994074SJan Friedel #if !defined(SMF_EXIT_ERR_OTHER) 39f8994074SJan Friedel #define SMF_EXIT_ERR_OTHER 1 40f8994074SJan Friedel #endif 41f8994074SJan Friedel 42f8994074SJan Friedel /* 43f8994074SJan Friedel * update_kcontext() - updates the non-/attributable preselection masks in 44f8994074SJan Friedel * the kernel context. Returns B_TRUE on success, B_FALSE otherwise. 45f8994074SJan Friedel */ 46f8994074SJan Friedel boolean_t 47f8994074SJan Friedel update_kcontext(int cmd, char *cmask) 48f8994074SJan Friedel { 49f8994074SJan Friedel au_mask_t bmask; 50f8994074SJan Friedel 51f8994074SJan Friedel (void) getauditflagsbin(cmask, &bmask); 52f8994074SJan Friedel if (auditon(cmd, (caddr_t)&bmask, sizeof (bmask)) == -1) { 53f8994074SJan Friedel (void) printf("Could not update kernel context (%s).\n", 54f8994074SJan Friedel cmd == A_SETAMASK ? "A_SETAMASK" : "A_SETKMASK"); 55f8994074SJan Friedel return (B_FALSE); 56f8994074SJan Friedel } 57f8994074SJan Friedel 58f8994074SJan Friedel #ifdef DEBUG 59f8994074SJan Friedel (void) printf("svc-auditset: %s mask set to %s", 60f8994074SJan Friedel cmd == A_SETAMASK ? "Attributable" : "Non-Attributable", cmask); 61f8994074SJan Friedel #endif 62f8994074SJan Friedel 63f8994074SJan Friedel return (B_TRUE); 64f8994074SJan Friedel } 65f8994074SJan Friedel 66f8994074SJan Friedel int 67f8994074SJan Friedel main(void) 68f8994074SJan Friedel { 69f8994074SJan Friedel char *auditset_fmri; 70f8994074SJan Friedel char *mask_cfg; 71*da5086c1SAlbert Lee uint32_t policy; 72f8994074SJan Friedel 73f8994074SJan Friedel (void) setlocale(LC_ALL, ""); 74f8994074SJan Friedel (void) textdomain(TEXT_DOMAIN); 75f8994074SJan Friedel 76f8994074SJan Friedel /* allow execution only inside the SMF facility */ 77f8994074SJan Friedel if ((auditset_fmri = getenv("SMF_FMRI")) == NULL || 78f8994074SJan Friedel strcmp(auditset_fmri, AUDITSET_FMRI) != 0) { 79f8994074SJan Friedel (void) printf(gettext("svc-auditset can be executed only " 80f8994074SJan Friedel "inside the SMF facility.\n")); 81f8994074SJan Friedel return (SMF_EXIT_ERR_NOSMF); 82f8994074SJan Friedel } 83f8994074SJan Friedel 84f8994074SJan Friedel /* check the c2audit module state */ 85f8994074SJan Friedel if (adt_audit_state(AUC_DISABLED)) { 86f8994074SJan Friedel #ifdef DEBUG 87f8994074SJan Friedel if (errno == ENOTSUP) { 88f8994074SJan Friedel (void) printf("c2audit module is excluded from " 89f8994074SJan Friedel "the system(4); kernel won't be updated.\n"); 90f8994074SJan Friedel } else { 91f8994074SJan Friedel (void) printf("%s\n", strerror(errno)); 92f8994074SJan Friedel } 93f8994074SJan Friedel #endif 94f8994074SJan Friedel return (SMF_EXIT_OK); 95f8994074SJan Friedel } 96f8994074SJan Friedel 97*da5086c1SAlbert Lee /* check the audit policy */ 98*da5086c1SAlbert Lee if (auditon(A_GETPOLICY, (caddr_t)&policy, 0) == -1) { 99*da5086c1SAlbert Lee (void) printf("Could not read audit policy: %s\n", 100*da5086c1SAlbert Lee strerror(errno)); 101*da5086c1SAlbert Lee return (SMF_EXIT_ERR_OTHER); 102*da5086c1SAlbert Lee } 103*da5086c1SAlbert Lee 104*da5086c1SAlbert Lee if (!(policy & AUDIT_PERZONE) && (getzoneid() != GLOBAL_ZONEID)) 105*da5086c1SAlbert Lee return (SMF_EXIT_OK); 106*da5086c1SAlbert Lee 107f8994074SJan Friedel /* update attributable mask */ 108f8994074SJan Friedel if (!do_getflags_scf(&mask_cfg) || mask_cfg == NULL) { 109f8994074SJan Friedel (void) printf("Could not get configured attributable audit " 110f8994074SJan Friedel "flags.\n"); 111f8994074SJan Friedel return (SMF_EXIT_ERR_OTHER); 112f8994074SJan Friedel } 113f8994074SJan Friedel if (!update_kcontext(A_SETAMASK, mask_cfg)) { 114f8994074SJan Friedel free(mask_cfg); 115f8994074SJan Friedel return (SMF_EXIT_ERR_OTHER); 116f8994074SJan Friedel } 117f8994074SJan Friedel free(mask_cfg); 118f8994074SJan Friedel 119f8994074SJan Friedel /* update non-attributable mask */ 120f8994074SJan Friedel if (!do_getnaflags_scf(&mask_cfg) || mask_cfg == NULL) { 121f8994074SJan Friedel (void) printf("Could not get configured non-attributable " 122f8994074SJan Friedel "audit flags.\n"); 123f8994074SJan Friedel return (SMF_EXIT_ERR_OTHER); 124f8994074SJan Friedel } 125f8994074SJan Friedel if (!update_kcontext(A_SETKMASK, mask_cfg)) { 126f8994074SJan Friedel free(mask_cfg); 127f8994074SJan Friedel return (SMF_EXIT_ERR_OTHER); 128f8994074SJan Friedel } 129f8994074SJan Friedel free(mask_cfg); 130f8994074SJan Friedel 131f8994074SJan Friedel return (SMF_EXIT_OK); 132f8994074SJan Friedel } 133