4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 * svc-auditset - auditset transient service (AUDITSET_FMRI) startup method;
27 * sets non-/attributable mask in the kernel context.
30 #include <audit_scf.h>
32 #include <bsm/libbsm.h>
38 #if !defined(SMF_EXIT_ERR_OTHER)
39 #define SMF_EXIT_ERR_OTHER 1
43 * update_kcontext() - updates the non-/attributable preselection masks in
44 * the kernel context. Returns B_TRUE on success, B_FALSE otherwise.
47 update_kcontext(int cmd
, char *cmask
)
51 (void) getauditflagsbin(cmask
, &bmask
);
52 if (auditon(cmd
, (caddr_t
)&bmask
, sizeof (bmask
)) == -1) {
53 (void) printf("Could not update kernel context (%s).\n",
54 cmd
== A_SETAMASK
? "A_SETAMASK" : "A_SETKMASK");
59 (void) printf("svc-auditset: %s mask set to %s",
60 cmd
== A_SETAMASK
? "Attributable" : "Non-Attributable", cmask
);
73 (void) setlocale(LC_ALL
, "");
74 (void) textdomain(TEXT_DOMAIN
);
76 /* allow execution only inside the SMF facility */
77 if ((auditset_fmri
= getenv("SMF_FMRI")) == NULL
||
78 strcmp(auditset_fmri
, AUDITSET_FMRI
) != 0) {
79 (void) printf(gettext("svc-auditset can be executed only "
80 "inside the SMF facility.\n"));
81 return (SMF_EXIT_ERR_NOSMF
);
84 /* check the c2audit module state */
85 if (adt_audit_state(AUC_DISABLED
)) {
87 if (errno
== ENOTSUP
) {
88 (void) printf("c2audit module is excluded from "
89 "the system(4); kernel won't be updated.\n");
91 (void) printf("%s\n", strerror(errno
));
97 /* check the audit policy */
98 if (auditon(A_GETPOLICY
, (caddr_t
)&policy
, 0) == -1) {
99 (void) printf("Could not read audit policy: %s\n",
101 return (SMF_EXIT_ERR_OTHER
);
104 if (!(policy
& AUDIT_PERZONE
) && (getzoneid() != GLOBAL_ZONEID
))
105 return (SMF_EXIT_OK
);
107 /* update attributable mask */
108 if (!do_getflags_scf(&mask_cfg
) || mask_cfg
== NULL
) {
109 (void) printf("Could not get configured attributable audit "
111 return (SMF_EXIT_ERR_OTHER
);
113 if (!update_kcontext(A_SETAMASK
, mask_cfg
)) {
115 return (SMF_EXIT_ERR_OTHER
);
119 /* update non-attributable mask */
120 if (!do_getnaflags_scf(&mask_cfg
) || mask_cfg
== NULL
) {
121 (void) printf("Could not get configured non-attributable "
123 return (SMF_EXIT_ERR_OTHER
);
125 if (!update_kcontext(A_SETKMASK
, mask_cfg
)) {
127 return (SMF_EXIT_ERR_OTHER
);
131 return (SMF_EXIT_OK
);