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) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
28 #include <sys/fcntl.h>
29 #include <bsm/audit.h>
30 #include <bsm/audit_record.h>
31 #include <bsm/audit_uevents.h>
32 #include <bsm/libbsm.h>
33 #include <bsm/audit_private.h>
38 #include <netinet/in.h>
39 #include <tsol/label.h>
44 #define dprintf(x) { (void) printf x; }
49 static au_event_t event
;
50 static int audit_rexecd_status
= 0;
53 selected(uid
, user
, event
, sf
)
62 mask
.am_success
= mask
.am_failure
= 0;
63 if (uid
> MAXEPHUID
) {
64 /* get non-attrib flags */
65 (void) auditon(A_GETKMASK
, (caddr_t
)&mask
, sizeof (mask
));
67 (void) au_user_mask(user
, &mask
);
71 sorf
= AU_PRS_SUCCESS
;
72 } else if (sf
== -1) {
73 sorf
= AU_PRS_FAILURE
;
78 return (au_preselect(event
, &mask
, sorf
, AU_PRS_REREAD
));
84 dprintf(("audit_rexecd_setup()\n"));
91 audit_rexecd_session_setup(char *name
, char *mach
, uid_t uid
)
95 struct auditinfo_addr info
;
96 uint32_t addr
[4], type
;
99 info
.ai_asid
= getpid();
104 (void) au_user_mask(name
, &mask
);
106 info
.ai_mask
.am_success
= mask
.am_success
;
107 info
.ai_mask
.am_failure
= mask
.am_failure
;
109 rc
= aug_get_machine(mach
, addr
, &type
);
111 perror("get address");
113 info
.ai_termid
.at_port
= aug_get_port();
114 info
.ai_termid
.at_type
= type
;
115 info
.ai_termid
.at_addr
[0] = addr
[0];
116 info
.ai_termid
.at_addr
[1] = addr
[1];
117 info
.ai_termid
.at_addr
[2] = addr
[2];
118 info
.ai_termid
.at_addr
[3] = addr
[3];
120 rc
= setaudit_addr(&info
, sizeof (info
));
127 audit_rexecd_fail(msg
, hostname
, user
, cmdbuf
)
128 char *msg
; /* message containing failure information */
129 char *hostname
; /* hostname of machine requesting service */
130 char *user
; /* username of user requesting service */
131 char *cmdbuf
; /* command line to be executed locally */
133 int rd
; /* audit record descriptor */
134 char buf
[256]; /* temporary buffer */
135 char *tbuf
; /* temporary buffer */
143 uint32_t addr
[4], type
;
146 dprintf(("audit_rexecd_fail()\n"));
149 * check if audit_rexecd_fail() or audit_rexecd_success()
150 * have been called already.
152 if (audit_rexecd_status
== 1) {
156 if (cannot_audit(0)) {
161 * set status to prevent multiple calls
162 * to audit_rexecd_fail() and audit_rexecd_success()
164 audit_rexecd_status
= 1;
166 pwd
= getpwnam(user
);
175 /* determine if we're preselected */
176 if (!selected(uid
, user
, event
, -1))
180 rc
= aug_get_machine(hostname
, addr
, &type
);
182 perror("get address");
185 tid
.at_port
= aug_get_port();
186 tid
.at_addr
[0] = addr
[0];
187 tid
.at_addr
[1] = addr
[1];
188 tid
.at_addr
[2] = addr
[2];
189 tid
.at_addr
[3] = addr
[3];
194 /* add subject token */
196 au_to_subject_ex(uid
, uid
, gid
, uid
, gid
, pid
, pid
, &tid
));
197 if (is_system_labeled())
198 (void) au_write(rd
, au_to_mylabel());
200 /* add reason for failure */
201 (void) au_write(rd
, au_to_text(msg
));
203 /* add hostname of machine requesting service */
204 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
205 "Remote execution requested by: %s"), hostname
);
206 (void) au_write(rd
, au_to_text(buf
));
208 /* add username of user requesting service */
209 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
210 "Username: %s"), user
);
211 (void) au_write(rd
, au_to_text(buf
));
213 /* add command line to be executed locally */
214 gtxt
= dgettext(bsm_dom
, "Command line: %s");
215 tlen
= strlen(gtxt
) + strlen(cmdbuf
) + 1;
216 if ((tbuf
= malloc(tlen
)) == NULL
) {
217 (void) au_close(rd
, 0, 0);
220 (void) snprintf(tbuf
, tlen
, gtxt
, cmdbuf
);
221 (void) au_write(rd
, au_to_text(tbuf
));
224 /* add return token */
226 (void) au_write(rd
, au_to_return64(-1, (int64_t)0));
228 (void) au_write(rd
, au_to_return32(-1, (int32_t)0));
231 /* write audit record */
232 if (au_close(rd
, 1, event
) < 0) {
233 (void) au_close(rd
, 0, 0);
239 audit_rexecd_success(hostname
, user
, cmdbuf
)
240 char *hostname
; /* hostname of machine requesting service */
241 char *user
; /* username of user requesting service */
242 char *cmdbuf
; /* command line to be executed locally */
244 int rd
; /* audit record descriptor */
245 char buf
[256]; /* temporary buffer */
246 char *tbuf
; /* temporary buffer */
254 uint32_t addr
[4], type
;
257 dprintf(("audit_rexecd_success()\n"));
260 * check if audit_rexecd_fail() or audit_rexecd_success()
261 * have been called already.
263 if (audit_rexecd_status
== 1) {
267 if (cannot_audit(0)) {
272 * set status to prevent multiple calls
273 * to audit_rexecd_fail() and audit_rexecd_success()
275 audit_rexecd_status
= 1;
277 pwd
= getpwnam(user
);
286 /* determine if we're preselected */
287 if (!selected(uid
, user
, event
, 0))
288 goto rexecd_audit_session
;
291 rc
= aug_get_machine(hostname
, addr
, &type
);
293 perror("get address");
296 tid
.at_port
= aug_get_port();
297 tid
.at_addr
[0] = addr
[0];
298 tid
.at_addr
[1] = addr
[1];
299 tid
.at_addr
[2] = addr
[2];
300 tid
.at_addr
[3] = addr
[3];
305 /* add subject token */
307 au_to_subject_ex(uid
, uid
, gid
, uid
, gid
, pid
, pid
, &tid
));
308 if (is_system_labeled())
309 (void) au_write(rd
, au_to_mylabel());
311 /* add hostname of machine requesting service */
312 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
313 "Remote execution requested by: %s"), hostname
);
314 (void) au_write(rd
, au_to_text(buf
));
316 /* add username at machine requesting service */
317 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
318 "Username: %s"), user
);
319 (void) au_write(rd
, au_to_text(buf
));
321 /* add command line to be executed locally */
322 gtxt
= dgettext(bsm_dom
, "Command line: %s");
323 tlen
= strlen(gtxt
) + strlen(cmdbuf
) + 1;
324 if ((tbuf
= malloc(tlen
)) == NULL
) {
325 (void) au_close(rd
, 0, 0);
327 (void) snprintf(tbuf
, tlen
, gtxt
, cmdbuf
);
328 (void) au_write(rd
, au_to_text(tbuf
));
331 /* add return token */
333 (void) au_write(rd
, au_to_return64(0, (int64_t)0));
335 (void) au_write(rd
, au_to_return32(0, (int32_t)0));
338 /* write audit record */
339 if (au_close(rd
, 1, event
) < 0) {
340 (void) au_close(rd
, 0, 0);
344 rexecd_audit_session
:
345 audit_rexecd_session_setup(user
, hostname
, uid
);