summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/main.c56
1 files changed, 23 insertions, 33 deletions
diff --git a/cmd/main.c b/cmd/main.c
index 8a42b72..0da308f 100644
--- a/cmd/main.c
+++ b/cmd/main.c
@@ -1,15 +1,8 @@
-/* main.c - one program, four jobs.
- *
- * check an operator asking, or a script
- * authorize git asking, once per push (also reached as 'pre-receive')
- * validate the entrypoint and CI asking before anything is served
- * edit changing the file (grant, revoke)
- *
- * They are one program because they must agree, exactly, about what a rule
- * means: a check that answers differently from the hook is worse than two
- * programs, it is a program that lies. The exit status is the interface, and
- * it never changes: 0 allowed, 1 denied, 3 no usable policy, 64 usage.
- */
+// One program, because check and the hook have to agree exactly about what a
+// rule means: a check that answers differently from the hook is a program that
+// lies. Exit status is the interface: 0 allowed, 1 denied, 3 no usable policy,
+// 64 usage.
+
#include "authz.h"
#include <stdio.h>
@@ -92,9 +85,9 @@ static int one_option(int argc, char **argv, int *i, const char *name, const cha
return 0;
}
-/* The policy is not usable, so the only safe answer is no. Three, not one:
- * the push was refused because this host is broken, not because that person is
- * not allowed, and whoever is debugging wants the two to sound different. */
+// 3 and not 1: a push refused because the host is broken has to sound different
+// from one refused because the person is not allowed.
+
static int deny_policy(const char *path, int rc)
{
fprintf(stderr, "%s: deny: the policy at %s %s\n", progname, path,
@@ -102,10 +95,10 @@ static int deny_policy(const char *path, int rc)
return 3;
}
-/* Everything that answers out of a loaded policy. Split out of main so the
- * policy is freed on the way out whichever way that is: a process this short
- * lived could leave the heap to the kernel, but then a sanitizer run reports
- * forty leaks and stops showing the one that matters. */
+// Split out of main so the policy is freed on every exit path: a short-lived
+// process can leave the heap to the kernel, but then the sanitizer reports
+// forty leaks and stops showing the one that matters.
+
static int dispatch(policy_t *p, int rc, const char *cmd, int argc, char **argv,
const char *path, hook_opts ho, validate_opts vo)
{
@@ -134,10 +127,9 @@ static int dispatch(policy_t *p, int rc, const char *cmd, int argc, char **argv,
vo.strict = 1;
continue;
}
- /* The policy is the part that decides who may push. Everything
- * else is how this host is wired, and a host without a git account
- * yet - a container being built, a config directory being checked
- * in - still wants its policy read. */
+ // A host without a git account yet - a container being built -
+ // still wants its policy read.
+
if (got == 0 && strcmp(argv[j], "--no-host") == 0) {
vo.root = NULL;
vo.hook_dir = NULL;
@@ -154,8 +146,9 @@ static int dispatch(policy_t *p, int rc, const char *cmd, int argc, char **argv,
return 64;
}
}
- /* A policy that does not parse is itself the finding, so it is passed
- * down and reported rather than turning this into a bare exit 3. */
+ // A policy that does not parse is the finding, so it is passed down
+ // rather than exiting 3 here.
+
return cmd_validate(p, vo);
}
@@ -223,10 +216,9 @@ int main(int argc, char **argv)
vo.htpasswd = DEFAULT_HTPASSWD;
memset(&eo, 0, sizeof(eo));
- /* Reached through the hook symlink. Git's own arguments to a hook are not
- * this program's, so they are dropped, and the policy comes from the
- * environment - a hook is not in a position to be told where the policy is
- * by a person who is not there. */
+ // Reached through the hook symlink: git's arguments are not this program's,
+ // so they are dropped, and the policy comes from the environment.
+
if (strcmp(progname, "pre-receive") == 0) {
policy_init(&p, path);
rc = policy_load(&p);
@@ -271,15 +263,13 @@ int main(int argc, char **argv)
return 0;
}
- /* The three commands that change the file. They read it themselves, and
- * they must not disagree with the checker about what a rule means, which is
- * why they are in the same binary. */
+
if (strcmp(cmd, "grant") == 0 || strcmp(cmd, "revoke") == 0) {
int consumed = 0;
if (authz_parse_out(argc, argv, &eo, &consumed) != 0)
return 64;
- argc -= consumed; /* what is left was compacted to the front */
+ argc -= consumed; // what is left was compacted to the front
if (strcmp(cmd, "grant") == 0)
return cmd_grant(path, eo, argc, argv);
return cmd_revoke(path, eo, argc, argv);