|
Lines 176-181
Link Here
|
| 176 |
#include "auth.h" |
176 |
#include "auth.h" |
| 177 |
#include "buffer.h" |
177 |
#include "buffer.h" |
| 178 |
|
178 |
|
|
|
179 |
#ifdef HAVE_LINUX_AUDIT |
| 180 |
# include <libaudit.h> |
| 181 |
#endif |
| 182 |
|
| 179 |
#ifdef HAVE_UTIL_H |
183 |
#ifdef HAVE_UTIL_H |
| 180 |
# include <util.h> |
184 |
# include <util.h> |
| 181 |
#endif |
185 |
#endif |
|
Lines 202-207
int utmp_write_entry(struct logininfo *l
Link Here
|
| 202 |
int utmpx_write_entry(struct logininfo *li); |
206 |
int utmpx_write_entry(struct logininfo *li); |
| 203 |
int wtmp_write_entry(struct logininfo *li); |
207 |
int wtmp_write_entry(struct logininfo *li); |
| 204 |
int wtmpx_write_entry(struct logininfo *li); |
208 |
int wtmpx_write_entry(struct logininfo *li); |
|
|
209 |
#ifdef HAVE_LINUX_AUDIT |
| 210 |
int linux_audit_write_entry(struct logininfo *li); |
| 211 |
#endif |
| 205 |
int lastlog_write_entry(struct logininfo *li); |
212 |
int lastlog_write_entry(struct logininfo *li); |
| 206 |
int syslogin_write_entry(struct logininfo *li); |
213 |
int syslogin_write_entry(struct logininfo *li); |
| 207 |
|
214 |
|
|
Lines 440-445
login_write(struct logininfo *li)
Link Here
|
| 440 |
|
447 |
|
| 441 |
/* set the timestamp */ |
448 |
/* set the timestamp */ |
| 442 |
login_set_current_time(li); |
449 |
login_set_current_time(li); |
|
|
450 |
#ifdef HAVE_LINUX_AUDIT |
| 451 |
if (linux_audit_write_entry(li) == 0) |
| 452 |
fatal("linux_audit_write_entry failed: %s", strerror(errno)); |
| 453 |
#endif |
| 443 |
#ifdef USE_LOGIN |
454 |
#ifdef USE_LOGIN |
| 444 |
syslogin_write_entry(li); |
455 |
syslogin_write_entry(li); |
| 445 |
#endif |
456 |
#endif |
|
Lines 1394-1399
wtmpx_get_entry(struct logininfo *li)
Link Here
|
| 1394 |
} |
1405 |
} |
| 1395 |
#endif /* USE_WTMPX */ |
1406 |
#endif /* USE_WTMPX */ |
| 1396 |
|
1407 |
|
|
|
1408 |
#ifdef HAVE_LINUX_AUDIT |
| 1409 |
static void |
| 1410 |
_audit_hexscape(const char *what, char *where, unsigned int size) |
| 1411 |
{ |
| 1412 |
const char *ptr = what; |
| 1413 |
const char *hex = "0123456789ABCDEF"; |
| 1414 |
|
| 1415 |
while (*ptr) { |
| 1416 |
if (*ptr == '"' || *ptr < 0x21 || *ptr > 0x7E) { |
| 1417 |
unsigned int i; |
| 1418 |
ptr = what; |
| 1419 |
for (i = 0; *ptr && i+2 < size; i += 2) { |
| 1420 |
where[i] = hex[((unsigned)*ptr & 0xF0)>>4]; /* Upper nibble */ |
| 1421 |
where[i+1] = hex[(unsigned)*ptr & 0x0F]; /* Lower nibble */ |
| 1422 |
ptr++; |
| 1423 |
} |
| 1424 |
where[i] = '\0'; |
| 1425 |
return; |
| 1426 |
} |
| 1427 |
ptr++; |
| 1428 |
} |
| 1429 |
where[0] = '"'; |
| 1430 |
if ((unsigned)(ptr - what) < size - 3) |
| 1431 |
{ |
| 1432 |
size = ptr - what + 3; |
| 1433 |
} |
| 1434 |
strncpy(where + 1, what, size - 3); |
| 1435 |
where[size-2] = '"'; |
| 1436 |
where[size-1] = '\0'; |
| 1437 |
} |
| 1438 |
|
| 1439 |
#define AUDIT_LOG_SIZE 128 |
| 1440 |
#define AUDIT_ACCT_SIZE (AUDIT_LOG_SIZE - 8) |
| 1441 |
|
| 1442 |
int |
| 1443 |
linux_audit_record_event(int uid, const char *username, |
| 1444 |
const char *hostname, const char *ip, const char *ttyn, int success) |
| 1445 |
{ |
| 1446 |
char buf[AUDIT_LOG_SIZE]; |
| 1447 |
int audit_fd, rc; |
| 1448 |
|
| 1449 |
audit_fd = audit_open(); |
| 1450 |
if (audit_fd < 0) { |
| 1451 |
if (errno == EINVAL || errno == EPROTONOSUPPORT || |
| 1452 |
errno == EAFNOSUPPORT) |
| 1453 |
return 1; /* No audit support in kernel */ |
| 1454 |
else |
| 1455 |
return 0; /* Must prevent login */ |
| 1456 |
} |
| 1457 |
if (username == NULL) |
| 1458 |
snprintf(buf, sizeof(buf), "uid=%d", uid); |
| 1459 |
else { |
| 1460 |
char encoded[AUDIT_ACCT_SIZE]; |
| 1461 |
_audit_hexscape(username, encoded, sizeof(encoded)); |
| 1462 |
snprintf(buf, sizeof(buf), "acct=%s", encoded); |
| 1463 |
} |
| 1464 |
rc = audit_log_user_message(audit_fd, AUDIT_USER_LOGIN, |
| 1465 |
buf, hostname, ip, ttyn, success); |
| 1466 |
close(audit_fd); |
| 1467 |
if (rc >= 0) |
| 1468 |
return 1; |
| 1469 |
else |
| 1470 |
return 0; |
| 1471 |
} |
| 1472 |
|
| 1473 |
int |
| 1474 |
linux_audit_write_entry(struct logininfo *li) |
| 1475 |
{ |
| 1476 |
switch(li->type) { |
| 1477 |
case LTYPE_LOGIN: |
| 1478 |
return (linux_audit_record_event(li->uid, NULL, li->hostname, |
| 1479 |
NULL, li->line, 1)); |
| 1480 |
case LTYPE_LOGOUT: |
| 1481 |
return (1); /* We only care about logins */ |
| 1482 |
default: |
| 1483 |
logit("%s: invalid type field", __func__); |
| 1484 |
return (0); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
#endif /* HAVE_LINUX_AUDIT */ |
| 1488 |
|
| 1397 |
/** |
1489 |
/** |
| 1398 |
** Low-level libutil login() functions |
1490 |
** Low-level libutil login() functions |
| 1399 |
**/ |
1491 |
**/ |