Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better token parsing in authorized_yubikeys file (check_user_token) #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,16 @@ check_user_token (const char *authfile,
return retval;
}

s_user = NULL;
retval = AUTH_NO_TOKENS;
while (fgets (buf, 1024, opwfile))
{
char *saveptr = NULL;
if (buf[strlen (buf) - 1] == '\n')
{
s_user = NULL;
buf[strlen (buf) - 1] = '\0';
}
if (buf[0] == '#') {
/* This is a comment and we may skip it. */
if(verbose)
Expand All @@ -349,7 +353,12 @@ check_user_token (const char *authfile,
}
if(verbose)
D (debug_file, "Authorization line: %s", buf);
s_user = strtok_r (buf, ":", &saveptr);
/* Only get user token if it's not defined. */
if (s_user == NULL)
s_user = strtok_r (buf, ":", &saveptr);
else
/* If the user is already set, we need to set the savedptr to our current buffer */
saveptr = buf;
if (s_user && strcmp (username, s_user) == 0)
{
if(verbose)
Expand All @@ -358,6 +367,15 @@ check_user_token (const char *authfile,
do
{
s_token = strtok_r (NULL, ":", &saveptr);

/* If the last token was less then 12 bytes */
if (s_token != NULL && strlen(s_token) < 12 && saveptr == NULL)
{
/* move the file pointer back to the beggining of the token, so it can be read next time */
fseek(opwfile, ftell(opwfile) - strlen(s_token), SEEK_SET);
continue;
}

if(verbose)
D (debug_file, "Authorization token: %s", s_token);
if (s_token && otp_id && strcmp (otp_id, s_token) == 0)
Expand Down