From 362ca9cb9221c69b465c371c29cf855f7d069654 Mon Sep 17 00:00:00 2001 From: Alex Feinberg Date: Tue, 4 Aug 2015 20:17:51 -0700 Subject: [PATCH] Support comments in authfile Adds support for comments (indicated by lines starting with '#') in authfiles. --- tests/util_test.c | 2 ++ util.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/tests/util_test.c b/tests/util_test.c index 6e8627d..da296bc 100644 --- a/tests/util_test.c +++ b/tests/util_test.c @@ -58,7 +58,9 @@ static void test_check_user_token(void) { assert(fd != -1); handle = fdopen(fd, "w"); + fprintf(handle, "# This is a comment containing foobar:foobar\n"); fprintf(handle, "foobar:hhhvhvhdhbid:hnhbhnhbhnhb:\n"); + fprintf(handle, "# This is a comment in the middle\n"); fprintf(handle, "kaka:hdhrhbhjhvhu:hihbhdhrhbhj\n"); fprintf(handle, "bar:hnhbhnhbhnhb\n"); fclose(handle); diff --git a/util.c b/util.c index 303eaf9..ada30ba 100644 --- a/util.c +++ b/util.c @@ -147,6 +147,12 @@ check_user_token (const char *authfile, char *saveptr = NULL; if (buf[strlen (buf) - 1] == '\n') buf[strlen (buf) - 1] = '\0'; + if (buf[0] == '#') { + /* This is a comment and we may skip it. */ + if(verbose) + D (("Skipping comment line: %s", buf)); + continue; + } if(verbose) D (("Authorization line: %s", buf)); s_user = strtok_r (buf, ":", &saveptr);