0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-03 14:18:53 +02:00

authd/providers/ident: fix up trailing lf/cr at end of username

This bug existed in the original code too, but I have no idea how it
didn't manifest.
This commit is contained in:
Elizabeth Myers 2016-03-26 19:18:54 -05:00
parent d1b70e3524
commit 22946d30d5

View file

@ -45,6 +45,7 @@ static const char *messages[] =
"*** Checking Ident", "*** Checking Ident",
"*** Got Ident response", "*** Got Ident response",
"*** No Ident response", "*** No Ident response",
"*** Cannot verify ident validity, ignoring ident",
}; };
typedef enum typedef enum
@ -52,6 +53,7 @@ typedef enum
REPORT_LOOKUP, REPORT_LOOKUP,
REPORT_FOUND, REPORT_FOUND,
REPORT_FAIL, REPORT_FAIL,
REPORT_INVALID,
} ident_message; } ident_message;
static EVH timeout_ident_queries_event; static EVH timeout_ident_queries_event;
@ -135,11 +137,12 @@ read_ident_reply(rb_fde_t *F, void *data)
{ {
struct auth_client *auth = data; struct auth_client *auth = data;
struct ident_query *query; struct ident_query *query;
char buf[IDENT_BUFSIZE + 1]; /* buffer to read auth reply into */
ident_message message = REPORT_FAIL;
char *s = NULL; char *s = NULL;
char *t = NULL; char *t = NULL;
int len; ssize_t len;
int count; int count;
char buf[IDENT_BUFSIZE + 1]; /* buffer to read auth reply into */
if(auth == NULL) if(auth == NULL)
return; return;
@ -158,9 +161,7 @@ read_ident_reply(rb_fde_t *F, void *data)
if(len > 0) if(len > 0)
{ {
buf[len] = '\0'; if((s = get_valid_ident(buf)) != NULL)
if((s = get_valid_ident(buf)))
{ {
t = auth->username; t = auth->username;
@ -169,10 +170,9 @@ read_ident_reply(rb_fde_t *F, void *data)
for (count = USERLEN; *s && count; s++) for (count = USERLEN; *s && count; s++)
{ {
if(*s == '@') if(*s == '@' || *s == '\r' || *s == '\n')
{
break; break;
}
if(*s != ' ' && *s != ':' && *s != '[') if(*s != ' ' && *s != ':' && *s != '[')
{ {
*t++ = *s; *t++ = *s;
@ -181,10 +181,14 @@ read_ident_reply(rb_fde_t *F, void *data)
} }
*t = '\0'; *t = '\0';
} }
else
message = REPORT_INVALID;
} }
warn_opers(L_DEBUG, "Got username: '%s'", auth->username);
if(s == NULL) if(s == NULL)
client_fail(auth, REPORT_FAIL); client_fail(auth, message);
else else
client_success(auth); client_success(auth);
} }
@ -252,39 +256,39 @@ get_valid_ident(char *buf)
colon1Ptr = strchr(remotePortString, ':'); colon1Ptr = strchr(remotePortString, ':');
if(!colon1Ptr) if(!colon1Ptr)
return 0; return NULL;
*colon1Ptr = '\0'; *colon1Ptr = '\0';
colon1Ptr++; colon1Ptr++;
colon2Ptr = strchr(colon1Ptr, ':'); colon2Ptr = strchr(colon1Ptr, ':');
if(!colon2Ptr) if(!colon2Ptr)
return 0; return NULL;
*colon2Ptr = '\0'; *colon2Ptr = '\0';
colon2Ptr++; colon2Ptr++;
commaPtr = strchr(remotePortString, ','); commaPtr = strchr(remotePortString, ',');
if(!commaPtr) if(!commaPtr)
return 0; return NULL;
*commaPtr = '\0'; *commaPtr = '\0';
commaPtr++; commaPtr++;
remp = atoi(remotePortString); remp = atoi(remotePortString);
if(!remp) if(!remp)
return 0; return NULL;
locp = atoi(commaPtr); locp = atoi(commaPtr);
if(!locp) if(!locp)
return 0; return NULL;
/* look for USERID bordered by first pair of colons */ /* look for USERID bordered by first pair of colons */
if(!strstr(colon1Ptr, "USERID")) if(!strstr(colon1Ptr, "USERID"))
return 0; return NULL;
colon3Ptr = strchr(colon2Ptr, ':'); colon3Ptr = strchr(colon2Ptr, ':');
if(!colon3Ptr) if(!colon3Ptr)
return 0; return NULL;
*colon3Ptr = '\0'; *colon3Ptr = '\0';
colon3Ptr++; colon3Ptr++;