summaryrefslogtreecommitdiffstats
path: root/src/validate.c
diff options
context:
space:
mode:
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);