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