diff options
| author | dev <dev@example> | 2026-11-13 20:33:51 +0000 |
|---|---|---|
| committer | dev <dev@example> | 2026-11-13 20:34:17 +0000 |
| commit | 1fd64267f678b8c6d17b2bcae702d577df1fc9e4 (patch) | |
| tree | 01a7d8a235c8e78c80c511dbee8cf738f7646053 /src/validate.c | |
| parent | f87a792743227ea06cfa1580f8d30a618b4d1a04 (diff) | |
| download | access-control-1fd64267f678b8c6d17b2bcae702d577df1fc9e4.tar.gz access-control-1fd64267f678b8c6d17b2bcae702d577df1fc9e4.zip | |
A refusal names the level held on the ref in question
"carol has force on team; refs/heads/main needs force", said while refusing
carol a force push to main, is a sentence nobody can act on: her force is on
refs/heads/feature/*, and the message reported the strongest level she holds
somewhere in the repository rather than the one she holds on the ref that was
refused. scope() now records both, and the refusal uses the level that covers
the ref, with a separate sentence for the case where nothing covers it at all -
"a rule for team but nothing on this ref" is a different problem from "not
enough for this ref", and the person pushing cannot tell them apart without
reading the file the way the matcher does.
Also: a policy that could not be opened is remembered (unreadable), so
validate reports "every push is denied until it is mounted" instead of
announcing that an empty policy is in force, and /etc/passwd is split by its
seven fields rather than eight - the old loop marked the colons as the fields
and so never found the git account at all, which meant a login shell for git
passed validation.
Both were found by driving the binary the way a receive hook is driven; that
suite is in a later commit of this series.
Diffstat (limited to 'src/validate.c')
| -rw-r--r-- | src/validate.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/validate.c b/src/validate.c index fd8abb9..ab8348c 100644 --- a/src/validate.c +++ b/src/validate.c @@ -303,22 +303,28 @@ static void check_account(const policy_t *p, validate_opts o) return; } while ((len = getline(&line, &cap, f)) != -1) { - char *fields[9]; + char *fields[8]; 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. */ while (*q != '\0') { + char *start = q; + while (*q != '\0' && *q != ':') q++; - fields[nf++] = q; - if (*q == '\0') + if (*q == '\0') { + fields[nf++] = start; break; + } *q++ = '\0'; - if (nf == 8) + fields[nf++] = start; + if (nf == 7) break; } - if (nf == 8 && strcmp(fields[0], "git") == 0) { - char *shell = strip(fields[7]); + if (nf >= 7 && strcmp(fields[0], "git") == 0) { + char *shell = strip(fields[6]); found = 1; if (strstr(shell, "git-shell") == NULL) @@ -440,6 +446,11 @@ int cmd_validate(const policy_t *p, validate_opts o) /* 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. */ + 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); + return 3; + } if (p->errors > 0) { verr("%s: %d error(s): the policy is not used, and every push is denied", p->path, p->errors); |
