|
Tomáš Mráz |
c9833c |
--- openssh-4.3p2/loginrec.c.inject-fix 2007-06-20 21:18:00.000000000 +0200
|
|
Tomáš Mráz |
c9833c |
+++ openssh-4.3p2/loginrec.c 2007-07-13 15:25:35.000000000 +0200
|
|
Tomáš Mráz |
c9833c |
@@ -1389,11 +1389,44 @@
|
|
Tomáš Mráz |
c9833c |
#endif /* USE_WTMPX */
|
|
Tomáš Mráz |
c9833c |
|
|
Tomáš Mráz |
c9833c |
#ifdef HAVE_LINUX_AUDIT
|
|
Tomáš Mráz |
c9833c |
+static void
|
|
Tomáš Mráz |
c9833c |
+_audit_hexscape(const char *what, char *where, unsigned int size)
|
|
Tomáš Mráz |
c9833c |
+{
|
|
Tomáš Mráz |
c9833c |
+ const char *ptr = what;
|
|
Tomáš Mráz |
c9833c |
+ const char *hex = "0123456789ABCDEF";
|
|
Tomáš Mráz |
c9833c |
+
|
|
Tomáš Mráz |
c9833c |
+ while (*ptr) {
|
|
Tomáš Mráz |
c9833c |
+ if (*ptr == '"' || *ptr < 0x21 || *ptr > 0x7E) {
|
|
Tomáš Mráz |
c9833c |
+ unsigned int i;
|
|
Tomáš Mráz |
c9833c |
+ ptr = what;
|
|
Tomáš Mráz |
c9833c |
+ for (i = 0; *ptr && i+2 < size; i += 2) {
|
|
Tomáš Mráz |
c9833c |
+ where[i] = hex[((unsigned)*ptr & 0xF0)>>4]; /* Upper nibble */
|
|
Tomáš Mráz |
c9833c |
+ where[i+1] = hex[(unsigned)*ptr & 0x0F]; /* Lower nibble */
|
|
Tomáš Mráz |
c9833c |
+ ptr++;
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c9833c |
+ where[i] = '\0';
|
|
Tomáš Mráz |
c9833c |
+ return;
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c9833c |
+ ptr++;
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c9833c |
+ where[0] = '"';
|
|
Tomáš Mráz |
c9833c |
+ if ((unsigned)(ptr - what) < size - 3)
|
|
Tomáš Mráz |
c9833c |
+ {
|
|
Tomáš Mráz |
c9833c |
+ size = ptr - what + 3;
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c9833c |
+ strncpy(where + 1, what, size - 3);
|
|
Tomáš Mráz |
c9833c |
+ where[size-2] = '"';
|
|
Tomáš Mráz |
c9833c |
+ where[size-1] = '\0';
|
|
Tomáš Mráz |
c9833c |
+}
|
|
Tomáš Mráz |
c9833c |
+
|
|
Tomáš Mráz |
c9833c |
+#define AUDIT_LOG_SIZE 128
|
|
Tomáš Mráz |
c9833c |
+#define AUDIT_ACCT_SIZE (AUDIT_LOG_SIZE - 8)
|
|
Tomáš Mráz |
c9833c |
+
|
|
Tomáš Mráz |
c9833c |
int
|
|
Tomáš Mráz |
c9833c |
linux_audit_record_event(int uid, const char *username,
|
|
Tomáš Mráz |
c9833c |
const char *hostname, const char *ip, const char *ttyn, int success)
|
|
Tomáš Mráz |
c9833c |
{
|
|
Tomáš Mráz |
c9833c |
- char buf[64];
|
|
Tomáš Mráz |
c9833c |
+ char buf[AUDIT_LOG_SIZE];
|
|
Tomáš Mráz |
c9833c |
int audit_fd, rc;
|
|
Tomáš Mráz |
c9833c |
|
|
Tomáš Mráz |
c9833c |
audit_fd = audit_open();
|
|
Tomáš Mráz |
c9833c |
@@ -1406,8 +1439,11 @@
|
|
Tomáš Mráz |
c9833c |
}
|
|
Tomáš Mráz |
c9833c |
if (username == NULL)
|
|
Tomáš Mráz |
c9833c |
snprintf(buf, sizeof(buf), "uid=%d", uid);
|
|
Tomáš Mráz |
c9833c |
- else
|
|
Tomáš Mráz |
c9833c |
- snprintf(buf, sizeof(buf), "acct=%s", username);
|
|
Tomáš Mráz |
c9833c |
+ else {
|
|
Tomáš Mráz |
c9833c |
+ char encoded[AUDIT_ACCT_SIZE];
|
|
Tomáš Mráz |
c9833c |
+ _audit_hexscape(username, encoded, sizeof(encoded));
|
|
Tomáš Mráz |
c9833c |
+ snprintf(buf, sizeof(buf), "acct=%s", encoded);
|
|
Tomáš Mráz |
c9833c |
+ }
|
|
Tomáš Mráz |
c9833c |
rc = audit_log_user_message(audit_fd, AUDIT_USER_LOGIN,
|
|
Tomáš Mráz |
c9833c |
buf, hostname, ip, ttyn, success);
|
|
Tomáš Mráz |
c9833c |
close(audit_fd);
|