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>
26 #include <sys/param.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>
37 #include <netinet/in.h>
38 #include <tsol/label.h>
43 static au_event_t rshd_event
; /* audit event number */
44 static uint32_t rshd_addr
[4]; /* peer address */
46 static void generate_record(char *, char *, char *, int, char *);
47 static void setup_session(char *);
48 static int selected(uid_t
, char *, au_event_t
, int);
53 rshd_event
= AUE_rshd
;
59 audit_rshd_fail(msg
, hostname
, remuser
, locuser
, cmdbuf
)
60 char *msg
; /* message containing failure information */
61 char *hostname
; /* hostname of machine requesting service */
62 char *remuser
; /* username at machine requesting service */
63 char *locuser
; /* username of local machine */
64 char *cmdbuf
; /* command line to be executed locally */
66 if (cannot_audit(0)) {
69 generate_record(remuser
, locuser
, cmdbuf
, -1, msg
);
75 audit_rshd_success(hostname
, remuser
, locuser
, cmdbuf
)
76 char *hostname
; /* hostname of machine requesting service */
77 char *remuser
; /* username at machine requesting service */
78 char *locuser
; /* username at local machine */
79 char *cmdbuf
; /* command line to be executed locally */
81 if (cannot_audit(0)) {
84 generate_record(remuser
, locuser
, cmdbuf
, 0, "");
85 setup_session(locuser
);
93 generate_record(char *remuser
, /* username at machine requesting service */
94 char *locuser
, /* username of local machine */
95 char *cmdbuf
, /* command line to be executed locally */
96 int sf_flag
, /* success (0) or failure (-1) flag */
97 char *msg
) /* message containing failure information */
99 int rd
; /* audit record descriptor */
100 char buf
[256]; /* temporary buffer */
101 char *tbuf
; /* temporary buffer */
108 struct auditinfo_addr info
;
110 if (cannot_audit(0)) {
114 pwd
= getpwnam(locuser
);
123 if (!selected(uid
, locuser
, rshd_event
, sf_flag
))
128 /* see if terminal id already set */
129 if (getaudit_addr(&info
, sizeof (info
)) < 0) {
134 (void) au_write(rd
, au_to_subject_ex(uid
, uid
, gid
, uid
, gid
, pid
, pid
,
136 if (is_system_labeled())
137 (void) au_write(rd
, au_to_mylabel());
139 gtxt
= dgettext(bsm_dom
, "cmd %s");
140 tlen
= strlen(gtxt
) + strlen(cmdbuf
) + 1;
141 if ((tbuf
= malloc(tlen
)) == NULL
) {
142 (void) au_close(rd
, 0, 0);
145 (void) snprintf(tbuf
, tlen
, gtxt
, cmdbuf
);
146 (void) au_write(rd
, au_to_text(tbuf
));
149 if (strcmp(remuser
, locuser
) != 0) {
150 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
151 "remote user %s"), remuser
);
152 (void) au_write(rd
, au_to_text(buf
));
156 (void) snprintf(buf
, sizeof (buf
), dgettext(bsm_dom
,
157 "local user %s"), locuser
);
158 (void) au_write(rd
, au_to_text(buf
));
159 (void) au_write(rd
, au_to_text(msg
));
163 (void) au_write(rd
, au_to_return64(sf_flag
, (int64_t)0));
165 (void) au_write(rd
, au_to_return32(sf_flag
, (int32_t)0));
168 if (au_close(rd
, 1, rshd_event
) < 0) {
169 (void) au_close(rd
, 0, 0);
174 selected(uid_t uid
, char *locuser
, au_event_t event
, int sf
)
179 mask
.am_success
= mask
.am_failure
= 0;
180 if (uid
> MAXEPHUID
) {
181 /* get non-attrib flags */
182 (void) auditon(A_GETKMASK
, (caddr_t
)&mask
, sizeof (mask
));
184 (void) au_user_mask(locuser
, &mask
);
188 sorf
= AU_PRS_SUCCESS
;
189 } else if (sf
== -1) {
190 sorf
= AU_PRS_FAILURE
;
195 return (au_preselect(event
, &mask
, sorf
, AU_PRS_REREAD
));
199 setup_session(char *locuser
)
202 struct auditinfo_addr info
;
207 pwd
= getpwnam(locuser
);
213 /* see if terminal id already set */
214 if (getaudit_addr(&info
, sizeof (info
)) < 0) {
219 info
.ai_asid
= getpid();
223 (void) au_user_mask(locuser
, &mask
);
225 info
.ai_mask
.am_success
= mask
.am_success
;
226 info
.ai_mask
.am_failure
= mask
.am_failure
;
228 rshd_addr
[0] = info
.ai_termid
.at_addr
[0];
229 rshd_addr
[1] = info
.ai_termid
.at_addr
[1];
230 rshd_addr
[2] = info
.ai_termid
.at_addr
[2];
231 rshd_addr
[3] = info
.ai_termid
.at_addr
[3];
233 rc
= setaudit_addr(&info
, sizeof (info
));