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>
34 #include <sys/socket.h>
35 #include <sys/sockio.h>
36 #include <netinet/in.h>
38 #include <bsm/audit.h>
39 #include <bsm/audit_record.h>
40 #include <bsm/audit_uevents.h>
41 #include <bsm/libbsm.h>
42 #include <bsm/audit_private.h>
48 #define BAD_PASSWD (1)
49 #define UNKNOWN_USER (2)
50 #define EXCLUDED_USER (3)
51 #define NO_ANONYMOUS (4)
52 #define MISC_FAILURE (5)
54 static char luser
[LOGNAME_MAX
+ 1];
56 static void generate_record(char *, int, char *);
57 static int selected(uid_t
, char *, au_event_t
, int);
60 audit_ftpd_bad_pw(char *uname
)
62 if (cannot_audit(0)) {
65 (void) strncpy(luser
, uname
, LOGNAME_MAX
);
66 generate_record(luser
, BAD_PASSWD
, dgettext(bsm_dom
, "bad password"));
71 audit_ftpd_unknown(char *uname
)
73 if (cannot_audit(0)) {
76 (void) strncpy(luser
, uname
, LOGNAME_MAX
);
77 generate_record(luser
, UNKNOWN_USER
, dgettext(bsm_dom
, "unknown user"));
82 audit_ftpd_excluded(char *uname
)
84 if (cannot_audit(0)) {
87 (void) strncpy(luser
, uname
, LOGNAME_MAX
);
88 generate_record(luser
, EXCLUDED_USER
, dgettext(bsm_dom
,
94 audit_ftpd_no_anon(void)
96 if (cannot_audit(0)) {
99 generate_record("", NO_ANONYMOUS
, dgettext(bsm_dom
, "no anonymous"));
103 audit_ftpd_failure(char *uname
)
105 if (cannot_audit(0)) {
108 generate_record(uname
, MISC_FAILURE
, dgettext(bsm_dom
, "misc failure"));
112 audit_ftpd_success(char *uname
)
114 if (cannot_audit(0)) {
117 (void) strncpy(luser
, uname
, LOGNAME_MAX
);
118 generate_record(luser
, 0, "");
125 char *locuser
, /* username of local user */
126 int err
, /* error status */
127 /* (=0 success, >0 error code) */
128 char *msg
) /* error message */
130 int rd
; /* audit record descriptor */
131 char buf
[256]; /* temporary buffer */
134 uid_t ruid
; /* real uid */
135 gid_t rgid
; /* real gid */
138 uid_t ceuid
; /* current effective uid */
139 struct auditinfo_addr info
;
141 if (cannot_audit(0)) {
145 pwd
= getpwnam(locuser
);
154 ceuid
= geteuid(); /* save current euid */
155 (void) seteuid(0); /* change to root so you can audit */
157 /* determine if we're preselected */
158 if (!selected(uid
, locuser
, AUE_ftpd
, err
)) {
159 (void) seteuid(ceuid
);
163 ruid
= getuid(); /* get real uid */
164 rgid
= getgid(); /* get real gid */
168 /* see if terminal id already set */
169 if (getaudit_addr(&info
, sizeof (info
)) < 0) {
175 /* add subject token */
176 (void) au_write(rd
, au_to_subject_ex(uid
, uid
, gid
,
177 ruid
, rgid
, pid
, pid
, &info
.ai_termid
));
179 /* add return token */
182 /* add reason for failure */
183 if (err
== UNKNOWN_USER
)
184 (void) snprintf(buf
, sizeof (buf
),
185 "%s %s", msg
, locuser
);
187 (void) snprintf(buf
, sizeof (buf
), "%s", msg
);
188 (void) au_write(rd
, au_to_text(buf
));
190 (void) au_write(rd
, au_to_return64(-1, (int64_t)err
));
192 (void) au_write(rd
, au_to_return32(-1, (int32_t)err
));
196 (void) au_write(rd
, au_to_return64(0, (int64_t)0));
198 (void) au_write(rd
, au_to_return32(0, (int32_t)0));
202 /* write audit record */
203 if (au_close(rd
, 1, AUE_ftpd
) < 0) {
204 (void) au_close(rd
, 0, 0);
206 (void) seteuid(ceuid
);
220 mask
.am_success
= mask
.am_failure
= 0;
221 if (uid
> MAXEPHUID
) {
222 /* get non-attrib flags */
223 (void) auditon(A_GETKMASK
, (caddr_t
)&mask
, sizeof (mask
));
225 (void) au_user_mask(locuser
, &mask
);
229 sorf
= AU_PRS_SUCCESS
;
230 } else if (err
>= 1) {
231 sorf
= AU_PRS_FAILURE
;
236 return (au_preselect(event
, &mask
, sorf
, AU_PRS_REREAD
));
241 audit_ftpd_logout(void)
243 int rd
; /* audit record descriptor */
249 struct auditinfo_addr info
;
251 if (cannot_audit(0)) {
255 (void) priv_set(PRIV_ON
, PRIV_EFFECTIVE
, PRIV_PROC_AUDIT
, NULL
);
257 /* see if terminal id already set */
258 if (getaudit_addr(&info
, sizeof (info
)) < 0) {
262 /* determine if we're preselected */
263 if (au_preselect(AUE_ftpd_logout
, &info
.ai_mask
, AU_PRS_SUCCESS
,
264 AU_PRS_USECACHE
) == 0) {
265 (void) priv_set(PRIV_OFF
, PRIV_EFFECTIVE
, PRIV_PROC_AUDIT
,
278 /* add subject token */
279 (void) au_write(rd
, au_to_subject_ex(info
.ai_auid
, euid
,
280 egid
, uid
, gid
, pid
, pid
, &info
.ai_termid
));
282 /* add return token */
285 (void) au_write(rd
, au_to_return64(0, (int64_t)0));
287 (void) au_write(rd
, au_to_return32(0, (int32_t)0));
290 /* write audit record */
291 if (au_close(rd
, 1, AUE_ftpd_logout
) < 0) {
292 (void) au_close(rd
, 0, 0);
294 (void) priv_set(PRIV_OFF
, PRIV_EFFECTIVE
, PRIV_PROC_AUDIT
, NULL
);