return 1;
}
+static void parse_failure(char *p, int cnt)
+{
+ DBG("Parse 4: <%s> cnt=%d", p, cnt);
+
+ // Decode attributes
+ bool done = 0;
+ char *rhost = NULL;
+ while (!done)
+ {
+ while (*p == ' ')
+ p++;
+ if (!*p)
+ break;
+
+ char *key = p;
+ while (*p && *p != ' ' && *p != '=')
+ p++;
+ if (*p != '=')
+ continue;
+ *p++ = 0;
+
+ char *val = p;
+ while (*p && *p != ' ')
+ p++;
+ if (*p)
+ *p++ = 0;
+ else
+ done = 1;
+
+ DBG("Parse KV: %s=<%s>", key, val);
+ if (!strcmp(key, "rhost"))
+ rhost = val;
+ }
+
+ // Act on the message
+ struct addr addr;
+ if (addr_parse(&addr, rhost))
+ handle_failed_login(addr, cnt);
+ else
+ msg(L_WARN, "Unable to parse address %s", rhost);
+}
+
static void process_msg(char *line)
{
DBG("Parse: <%s>", line);
DBG("Parse 2: <%s>", p);
// pam_unix(something), colon, space
- if (!check_next(&p, "pam_unix("))
- return;
- do
+ if (check_next(&p, "pam_unix("))
{
- c = *p++;
- if (!c || c == ' ')
+ do
+ {
+ c = *p++;
+ if (!c || c == ' ')
+ return;
+ }
+ while (c != ')');
+ if (!check_next(&p, ": "))
+ return;
+ DBG("Parse 3: <%s>", p);
+
+ if (!check_next(&p, "authentication failure; "))
return;
+
+ parse_failure(p, 1);
}
- while (c != ')');
- if (!check_next(&p, ": "))
- return;
- DBG("Parse 3: <%s>", p);
- // "authentication failure;"
- int cnt = 1;
- if (!check_next(&p, "authentication failure; "))
+ // "PAM <n> more authentication failures;"
+ if (check_next(&p, "PAM "))
{
- // "PAM <n> more authentication failures;"
- if (!check_next(&p, "PAM "))
- return;
if (!(*p >= '0' && *p <= '9'))
return;
- cnt = atoi(p);
+ int cnt = atoi(p);
while (*p >= '0' && *p <= '9')
p++;
+
if (!check_next(&p, " more authentication failures; "))
return;
- }
- DBG("Parse 4: <%s> cnt=%d", p, cnt);
- // Decode attributes
- bool done = 0;
- char *rhost = NULL;
- while (!done)
- {
- while (*p == ' ')
- p++;
- if (!*p)
- break;
-
- char *key = p;
- while (*p && *p != ' ' && *p != '=')
- p++;
- if (*p != '=')
- continue;
- *p++ = 0;
-
- char *val = p;
- while (*p && *p != ' ')
- p++;
- if (*p)
- *p++ = 0;
- else
- done = 1;
-
- DBG("Parse KV: %s=<%s>", key, val);
- if (!strcmp(key, "rhost"))
- rhost = val;
+ parse_failure(p, cnt);
}
-
- // Act on the message
- struct addr addr;
- if (addr_parse(&addr, rhost))
- handle_failed_login(addr, cnt);
- else
- msg(L_WARN, "Unable to parse address %s", rhost);
}
/*** Socket for receiving messages from rsyslog ***/