|
Lines 35-47
Link Here
|
| 35 |
|
35 |
|
| 36 |
#include "log.h" |
36 |
#include "log.h" |
| 37 |
#include "audit.h" |
37 |
#include "audit.h" |
|
|
38 |
#include "key.h" |
| 39 |
#include "hostfile.h" |
| 40 |
#include "auth.h" |
| 41 |
#include "servconf.h" |
| 38 |
#include "canohost.h" |
42 |
#include "canohost.h" |
| 39 |
|
43 |
|
|
|
44 |
extern ServerOptions options; |
| 45 |
extern Authctxt *the_authctxt; |
| 46 |
extern u_int utmp_len; |
| 40 |
const char* audit_username(void); |
47 |
const char* audit_username(void); |
| 41 |
|
48 |
|
| 42 |
int |
49 |
static void |
| 43 |
linux_audit_record_event(int uid, const char *username, |
50 |
linux_audit_user_logxxx(int uid, const char *username, |
| 44 |
const char *hostname, const char *ip, const char *ttyn, int success) |
51 |
const char *hostname, const char *ip, const char *ttyn, int success, int event) |
| 45 |
{ |
52 |
{ |
| 46 |
int audit_fd, rc, saved_errno; |
53 |
int audit_fd, rc, saved_errno; |
| 47 |
|
54 |
|
|
Lines 49-59
linux_audit_record_event(int uid, const
Link Here
|
| 49 |
if (audit_fd < 0) { |
56 |
if (audit_fd < 0) { |
| 50 |
if (errno == EINVAL || errno == EPROTONOSUPPORT || |
57 |
if (errno == EINVAL || errno == EPROTONOSUPPORT || |
| 51 |
errno == EAFNOSUPPORT) |
58 |
errno == EAFNOSUPPORT) |
| 52 |
return 1; /* No audit support in kernel */ |
59 |
return; /* No audit support in kernel */ |
| 53 |
else |
60 |
else |
| 54 |
return 0; /* Must prevent login */ |
61 |
goto fatal_report; /* Must prevent login */ |
| 55 |
} |
62 |
} |
| 56 |
rc = audit_log_acct_message(audit_fd, AUDIT_USER_LOGIN, |
63 |
rc = audit_log_acct_message(audit_fd, event, |
| 57 |
NULL, "login", username ? username : "(unknown)", |
64 |
NULL, "login", username ? username : "(unknown)", |
| 58 |
username == NULL ? uid : -1, hostname, ip, ttyn, success); |
65 |
username == NULL ? uid : -1, hostname, ip, ttyn, success); |
| 59 |
saved_errno = errno; |
66 |
saved_errno = errno; |
|
Lines 65-99
linux_audit_record_event(int uid, const
Link Here
|
| 65 |
if ((rc == -EPERM) && (geteuid() != 0)) |
72 |
if ((rc == -EPERM) && (geteuid() != 0)) |
| 66 |
rc = 0; |
73 |
rc = 0; |
| 67 |
errno = saved_errno; |
74 |
errno = saved_errno; |
| 68 |
return (rc >= 0); |
75 |
if (rc < 0) { |
|
|
76 |
fatal_report: |
| 77 |
fatal("linux_audit_write_entry failed: %s", strerror(errno)); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
static void |
| 82 |
linux_audit_user_auth(int uid, const char *username, |
| 83 |
const char *hostname, const char *ip, const char *ttyn, int success, int event) |
| 84 |
{ |
| 85 |
int audit_fd, rc, saved_errno; |
| 86 |
static const char *event_name[] = { |
| 87 |
"maxtries exceeded", |
| 88 |
"root denied", |
| 89 |
"success", |
| 90 |
"none", |
| 91 |
"password", |
| 92 |
"challenge-response", |
| 93 |
"pubkey", |
| 94 |
"hostbased", |
| 95 |
"gssapi", |
| 96 |
"invalid user", |
| 97 |
"nologin", |
| 98 |
"connection closed", |
| 99 |
"connection abandoned", |
| 100 |
"unknown" |
| 101 |
}; |
| 102 |
|
| 103 |
audit_fd = audit_open(); |
| 104 |
if (audit_fd < 0) { |
| 105 |
if (errno == EINVAL || errno == EPROTONOSUPPORT || |
| 106 |
errno == EAFNOSUPPORT) |
| 107 |
return; /* No audit support in kernel */ |
| 108 |
else |
| 109 |
goto fatal_report; /* Must prevent login */ |
| 110 |
} |
| 111 |
|
| 112 |
if ((event < 0) || (event > SSH_AUDIT_UNKNOWN)) |
| 113 |
event = SSH_AUDIT_UNKNOWN; |
| 114 |
|
| 115 |
rc = audit_log_acct_message(audit_fd, AUDIT_USER_AUTH, |
| 116 |
NULL, event_name[event], username ? username : "(unknown)", |
| 117 |
username == NULL ? uid : -1, hostname, ip, ttyn, success); |
| 118 |
saved_errno = errno; |
| 119 |
close(audit_fd); |
| 120 |
/* |
| 121 |
* Do not report error if the error is EPERM and sshd is run as non |
| 122 |
* root user. |
| 123 |
*/ |
| 124 |
if ((rc == -EPERM) && (geteuid() != 0)) |
| 125 |
rc = 0; |
| 126 |
errno = saved_errno; |
| 127 |
if (rc < 0) { |
| 128 |
fatal_report: |
| 129 |
fatal("linux_audit_write_entry failed: %s", strerror(errno)); |
| 130 |
} |
| 69 |
} |
131 |
} |
| 70 |
|
132 |
|
|
|
133 |
static int user_login_count = 0; |
| 134 |
|
| 71 |
/* Below is the sshd audit API code */ |
135 |
/* Below is the sshd audit API code */ |
| 72 |
|
136 |
|
| 73 |
void |
137 |
void |
| 74 |
audit_connection_from(const char *host, int port) |
138 |
audit_connection_from(const char *host, int port) |
| 75 |
{ |
139 |
{ |
| 76 |
} |
|
|
| 77 |
/* not implemented */ |
140 |
/* not implemented */ |
|
|
141 |
} |
| 78 |
|
142 |
|
| 79 |
void |
143 |
int |
| 80 |
audit_run_command(const char *command) |
144 |
audit_run_command(const char *command) |
| 81 |
{ |
145 |
{ |
| 82 |
/* not implemented */ |
146 |
if (!user_login_count++) |
|
|
147 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 148 |
NULL, "ssh", 1, AUDIT_USER_LOGIN); |
| 149 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 150 |
NULL, "ssh", 1, AUDIT_USER_START); |
| 151 |
return 0; |
| 152 |
} |
| 153 |
|
| 154 |
void |
| 155 |
audit_end_command(int handle, const char *command) |
| 156 |
{ |
| 157 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 158 |
NULL, "ssh", 1, AUDIT_USER_END); |
| 159 |
if (user_login_count && !--user_login_count) |
| 160 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 161 |
NULL, "ssh", 1, AUDIT_USER_LOGOUT); |
| 162 |
} |
| 163 |
|
| 164 |
void |
| 165 |
audit_count_session_open(void) |
| 166 |
{ |
| 167 |
user_login_count++; |
| 83 |
} |
168 |
} |
| 84 |
|
169 |
|
| 85 |
void |
170 |
void |
| 86 |
audit_session_open(struct logininfo *li) |
171 |
audit_session_open(struct logininfo *li) |
| 87 |
{ |
172 |
{ |
| 88 |
if (linux_audit_record_event(li->uid, NULL, li->hostname, |
173 |
if (!user_login_count++) |
| 89 |
NULL, li->line, 1) == 0) |
174 |
linux_audit_user_logxxx(li->uid, NULL, li->hostname, |
| 90 |
fatal("linux_audit_write_entry failed: %s", strerror(errno)); |
175 |
NULL, li->line, 1, AUDIT_USER_LOGIN); |
|
|
176 |
linux_audit_user_logxxx(li->uid, NULL, li->hostname, |
| 177 |
NULL, li->line, 1, AUDIT_USER_START); |
| 91 |
} |
178 |
} |
| 92 |
|
179 |
|
| 93 |
void |
180 |
void |
| 94 |
audit_session_close(struct logininfo *li) |
181 |
audit_session_close(struct logininfo *li) |
| 95 |
{ |
182 |
{ |
| 96 |
/* not implemented */ |
183 |
linux_audit_user_logxxx(li->uid, NULL, li->hostname, |
|
|
184 |
NULL, li->line, 1, AUDIT_USER_END); |
| 185 |
if (user_login_count && !--user_login_count) |
| 186 |
linux_audit_user_logxxx(li->uid, NULL, li->hostname, |
| 187 |
NULL, li->line, 1, AUDIT_USER_LOGOUT); |
| 97 |
} |
188 |
} |
| 98 |
|
189 |
|
| 99 |
void |
190 |
void |
|
Lines 101-121
audit_event(ssh_audit_event_t event)
Link Here
|
| 101 |
{ |
192 |
{ |
| 102 |
switch(event) { |
193 |
switch(event) { |
| 103 |
case SSH_AUTH_SUCCESS: |
194 |
case SSH_AUTH_SUCCESS: |
| 104 |
case SSH_CONNECTION_CLOSE: |
195 |
linux_audit_user_auth(-1, audit_username(), NULL, |
|
|
196 |
get_remote_ipaddr(), "ssh", 1, event); |
| 197 |
break; |
| 198 |
|
| 105 |
case SSH_NOLOGIN: |
199 |
case SSH_NOLOGIN: |
| 106 |
case SSH_LOGIN_EXCEED_MAXTRIES: |
|
|
| 107 |
case SSH_LOGIN_ROOT_DENIED: |
200 |
case SSH_LOGIN_ROOT_DENIED: |
|
|
201 |
linux_audit_user_auth(-1, audit_username(), NULL, |
| 202 |
get_remote_ipaddr(), "ssh", 0, event); |
| 203 |
linux_audit_user_logxxx(-1, audit_username(), NULL, |
| 204 |
get_remote_ipaddr(), "ssh", 0, AUDIT_USER_LOGIN); |
| 108 |
break; |
205 |
break; |
| 109 |
|
206 |
|
|
|
207 |
case SSH_LOGIN_EXCEED_MAXTRIES: |
| 110 |
case SSH_AUTH_FAIL_NONE: |
208 |
case SSH_AUTH_FAIL_NONE: |
| 111 |
case SSH_AUTH_FAIL_PASSWD: |
209 |
case SSH_AUTH_FAIL_PASSWD: |
| 112 |
case SSH_AUTH_FAIL_KBDINT: |
210 |
case SSH_AUTH_FAIL_KBDINT: |
| 113 |
case SSH_AUTH_FAIL_PUBKEY: |
211 |
case SSH_AUTH_FAIL_PUBKEY: |
| 114 |
case SSH_AUTH_FAIL_HOSTBASED: |
212 |
case SSH_AUTH_FAIL_HOSTBASED: |
| 115 |
case SSH_AUTH_FAIL_GSSAPI: |
213 |
case SSH_AUTH_FAIL_GSSAPI: |
|
|
214 |
linux_audit_user_auth(-1, audit_username(), NULL, |
| 215 |
get_remote_ipaddr(), "ssh", 0, event); |
| 216 |
break; |
| 217 |
|
| 218 |
case SSH_CONNECTION_CLOSE: |
| 219 |
if (user_login_count) { |
| 220 |
while (user_login_count--) |
| 221 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 222 |
NULL, "ssh", 1, AUDIT_USER_END); |
| 223 |
linux_audit_user_logxxx(the_authctxt->pw->pw_uid, NULL, get_remote_name_or_ip(utmp_len, options.use_dns), |
| 224 |
NULL, "ssh", 1, AUDIT_USER_LOGOUT); |
| 225 |
} |
| 226 |
break; |
| 227 |
|
| 228 |
case SSH_CONNECTION_ABANDON: |
| 116 |
case SSH_INVALID_USER: |
229 |
case SSH_INVALID_USER: |
| 117 |
linux_audit_record_event(-1, audit_username(), NULL, |
230 |
linux_audit_user_logxxx(-1, audit_username(), NULL, |
| 118 |
get_remote_ipaddr(), "sshd", 0); |
231 |
get_remote_ipaddr(), "ssh", 0, AUDIT_USER_LOGIN); |
| 119 |
break; |
232 |
break; |
| 120 |
|
233 |
|
| 121 |
default: |
234 |
default: |