summaryrefslogtreecommitdiffstats
path: root/src/validate.c
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 11:16:29 +0000
committerdev <dev@example>2026-11-14 11:16:29 +0000
commita2a702cb81eaf73a8989cc31c682592c8acb769a (patch)
treed652ff6531c03176dd6280b5b8f77987a62da180 /src/validate.c
parent312ddd4936f09ae27a180ca495cacf2c06faf33e (diff)
downloadaccess-control-a2a702cb81eaf73a8989cc31c682592c8acb769a.tar.gz
access-control-a2a702cb81eaf73a8989cc31c682592c8acb769a.zip
Nine bugs the suite did not reach, and a test for each
Every one was found by reading a module against what the program promises, or by driving the built binary with input the suite never sends. None of them was visible from a green run: the run was already green. Two are validate saying "ok" about a machine that is wide open: ForceCommand none is how a Match block turns a forced command back off. It is the same state as having none at all, which is the state this check exists to catch. sshd directives sshd keeps the first value it reads for a keyword, not the last. "PermitUserEnvironment no" with a later "yes" read as yes, and every push arrives anonymous. One is a grant that grants more than was typed. A ref argument went into the file verbatim, so grant x team write 'refs/heads/a b' landed as "x team write refs/heads/a b", which reads back as two patterns and quietly grants refs/heads/b as well. A '#' argument was cut short at the comment marker, and a newline argument wrote a file that no longer parses - which denies every push there is. An argument that is not one field is refused now. authorize did not accept the options its own usage text prints. The help says "--user U" and "--ff auto|yes|no"; the parser took only --user=U, so the documented spelling came back "unknown argument" while validate accepted both forms. Both work now, and an option with no value says so. Three are the boundary and status distinctions the exit codes are made of. A rule with exactly MAX_FIELDS fields was refused as "too many", and a file that does not parse denies every push. A directory passed as the policy read as a policy that happens to be empty, so every push answered 1, person not allowed, where the host is broken and the answer has to be 3. A gitconfig section name was matched case-sensitively, so [CORE] reported a broken host that is not broken; git folds section names without regard to case. Two are smaller. "appended as line N" was printed when the pair's rule was the last line and had been replaced rather than appended. And the Makefile tracked no header dependencies, so editing src/authz.h rebuilt nothing and make test passed against a binary that was not the code on disk. Each fix went in as a failing test first, so the suite goes from 162 cases to 176 and no existing test was changed. Clean under -Werror and clean under ASan/UBSan.
Diffstat (limited to 'src/validate.c')
-rw-r--r--src/validate.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/validate.c b/src/validate.c
index 7004731..91be26a 100644
--- a/src/validate.c
+++ b/src/validate.c
@@ -65,6 +65,18 @@ static int ci_equal(const char *a, const char *b)
return *a == '\0' && *b == '\0';
}
+// git reads a section name without regard to case, so [CORE] opens core.
+static int ci_prefix(const char *line, const char *want)
+{
+ while (*want != '\0') {
+ if (tolower((unsigned char)*line) != tolower((unsigned char)*want))
+ return 0;
+ line++;
+ want++;
+ }
+ return 1;
+}
+
static char *strip(char *s)
{
char *end;
@@ -103,7 +115,7 @@ static int ini_value(const char *path, const char *section, const char *key,
if (*t == '\0' || *t == '#' || *t == ';')
continue;
if (*t == '[') {
- in = strncmp(t, here, strlen(here)) == 0;
+ in = ci_prefix(t, here);
continue;
}
if (!in)
@@ -130,14 +142,17 @@ static int ini_value(const char *path, const char *section, const char *key,
return found;
}
-// sshd_config's "Directive value", last one winning, case-insensitive.
+// sshd_config's "Directive value", case-insensitive. sshd keeps the first value
+// it reads for a directive, not the last, so the first match is the answer and
+// every later line is one sshd never looked at - which is the difference between
+// a host that accepts key identities and one that silently drops them.
+
static int directive_value(const char *path, const char *name, char *out, size_t outsz)
{
FILE *f;
char *line = NULL;
size_t cap = 0;
ssize_t len;
- int found = 0;
f = fopen(path, "r");
if (f == NULL)
@@ -157,11 +172,13 @@ static int directive_value(const char *path, const char *name, char *out, size_t
if (!ci_equal(t, name))
continue;
snprintf(out, outsz, "%s", strip(sp + 1));
- found = 1;
+ free(line);
+ fclose(f);
+ return 1;
}
free(line);
fclose(f);
- return found;
+ return 0;
}
static void check_repos(const policy_t *p, const char *root)
@@ -268,9 +285,12 @@ static void check_sshd(const policy_t *p, validate_opts o)
vok("PermitUserEnvironment yes");
rc = directive_value(o.sshd_config, "ForceCommand", value, sizeof(value));
- if (rc == 0)
+ if (rc != 1)
verr("%s sets no ForceCommand: a key can run an interactive shell",
o.sshd_config);
+ else if (ci_equal(value, "none"))
+ verr("ForceCommand is none in %s: that is how a Match block turns it back "
+ "off, and a key can run an interactive shell", o.sshd_config);
else
vok("ForceCommand %s", value);