diff options
Diffstat (limited to 'src/validate.c')
| -rw-r--r-- | src/validate.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/validate.c b/src/validate.c index 81865d5..7004731 100644 --- a/src/validate.c +++ b/src/validate.c @@ -1,16 +1,10 @@ -/* validate.c - does this policy, and the host around it, add up? - * - * Run from the entrypoint before anything is served, and from CI. A container - * that starts with a policy nobody can read, or a hooks path that points - * nowhere, is a container that serves repositories nobody can push to - or - * anybody can. Both are found here, in the second, rather than in the first - * push of the morning. - * - * Errors mean "a push would be authorised wrongly". Warnings mean "a human is - * going to file a ticket". Missing files are skipped, not warned about: on a - * developer machine there is no sshd_config here, and a validator that cries - * about that gets ignored, which is worse than not checking. - */ +// Run from the entrypoint before anything is served, and from CI. +// +// An error means a push would be authorised wrongly; a warning means a human is +// about to file a ticket. Missing files are skipped rather than warned about: a +// validator that cries about a developer machine gets ignored, which is worse +// than not checking. + #include "authz.h" #include <ctype.h> @@ -22,8 +16,8 @@ #include <sys/stat.h> #include <unistd.h> -/* Tally of what this one run found. One validate per process, so file scope - * is enough and the helpers stay readable. */ +// One validate per process, so file scope is enough. + static int g_errors; static int g_warnings; @@ -62,8 +56,6 @@ static void vok(const char *fmt, ...) fputc('\n', stdout); } -/* ------------------------------------------------------------- file lookups */ - static int ci_equal(const char *a, const char *b) { for (; *a != '\0' && *b != '\0'; a++, b++) { @@ -86,8 +78,9 @@ static char *strip(char *s) return s; } -/* An ini file's value for [section] key = value, last one winning. Used for - * gitconfig, where a value set twice is exactly the mistake worth reporting. */ +// [section] key = value, last one winning - which is the mistake worth +// reporting in a gitconfig. + static int ini_value(const char *path, const char *section, const char *key, char *out, size_t outsz) { @@ -122,7 +115,7 @@ static int ini_value(const char *path, const char *section, const char *key, if (!ci_equal(strip(t), key)) continue; snprintf(out, outsz, "%s", strip(eq + 1)); - { /* gitconfig allows quoting */ + { // gitconfig allows quoting size_t n = strlen(out); if (n >= 2 && out[0] == '"' && out[n - 1] == '"') { @@ -137,7 +130,7 @@ 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", last one winning, case-insensitive. static int directive_value(const char *path, const char *name, char *out, size_t outsz) { FILE *f; @@ -171,8 +164,6 @@ static int directive_value(const char *path, const char *name, char *out, size_t return found; } -/* -------------------------------------------------------------- the checks */ - static void check_repos(const policy_t *p, const char *root) { DIR *d; @@ -206,8 +197,9 @@ static void check_repos(const policy_t *p, const char *root) } closedir(d); - /* The other direction: a rule naming a repository that is not there is - * almost always a repository that was renamed, and the rule looks fine. */ + // A rule naming a repository that is not there is a renamed repository, + // and the rule still looks fine. + for (i = 0; i < p->nrules; i++) { const char *r = p->rules[i].repo; @@ -307,8 +299,9 @@ static void check_account(const policy_t *p, validate_opts o) int nf = 0; char *q = line; - /* name:password:uid:gid:gecos:home:shell - the seventh field decides - * whether a key can open a shell at all. */ + // The seventh field is the shell, which decides whether a key can open + // a shell at all. Splitting on eight would make the shell field 6. + while (*q != '\0') { char *start = q; @@ -370,7 +363,7 @@ static void check_keys(const policy_t *p, validate_opts o) *nl = '\0'; sp = strchr(t, ' '); if (sp != NULL) - *sp = '\0'; /* leave the key type, e.g. ssh-ed25519 */ + *sp = '\0'; // leave the key type, e.g. ssh-ed25519 vwarn("a %s key carries no GIT_HOST_USER: pushes made with it are " "anonymous and will be denied", t); continue; @@ -443,9 +436,9 @@ int cmd_validate(const policy_t *p, validate_opts o) g_errors = 0; g_warnings = 0; - /* Anything the parser already complained about went to stderr with its line - * number. A policy with errors is not used at all, so nothing else here - * matters until it is fixed. */ + // The parser already printed the line numbers. A policy with errors is not + // used at all, so nothing else matters until it is fixed. + if (p->unreadable) { verr("%s cannot be read: the hook fails closed on this, so every push is " "denied until it is mounted", p->path); |
