summaryrefslogtreecommitdiffstats
path: root/src/hook.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hook.c')
-rw-r--r--src/hook.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/hook.c b/src/hook.c
index 1dc4445..e519ae8 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -278,6 +278,33 @@ static int parse_options(int argc, char **argv, hook_opts *o)
return 0;
}
+// The one line a person pushing is given: the input they presented, and the
+// verdict. Nothing else. The reason is a sentence about a policy file they
+// cannot read, and quoting it here sends them to somebody else's configuration
+// while telling a monitor nothing the exit status did not. `check` is where
+// whoever owns the policy reads the reason out, and --explain below prints it in
+// this seat for the operator who is already standing here.
+
+static void deny_ref(const char *user, const char *ref)
+{
+ if (user != NULL && user[0] != '\0')
+ fprintf(stderr, "%s: permission denied [user=%s, obj=%s]\n",
+ progname, user, ref);
+ else
+ fprintf(stderr, "%s: permission denied [obj=%s]\n", progname, ref);
+}
+
+// Input that is not a push at all: not three fields, not object ids, not a ref
+// under refs/. None of it is echoed - the person on the other end can do
+// nothing with a line they did not write, and exit 3 already says whose problem
+// it is. A real git never writes these lines, so what to look at is the pipe,
+// the wrapper, or whoever was debugging the hook by hand.
+
+static void invalid_operation(void)
+{
+ fprintf(stderr, "%s: invalid operation\n", progname);
+}
+
int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
{
char *line = NULL;
@@ -328,9 +355,8 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
if (nf == 0)
continue;
if (nf != 3) {
- fprintf(stderr, "%s: deny: expected \"old new ref\", got %d field(s)\n",
- progname, nf);
- status = 1;
+ invalid_operation();
+ status = 3; // the host's fault, not the pusher's
break;
}
@@ -341,9 +367,8 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
if (!object_id_ok(old) || !object_id_ok(new) ||
strncmp(ref, "refs/", 5) != 0) {
- fprintf(stderr, "%s: deny: \"%s %s %s\" is not an update git would send\n",
- progname, old, new, ref);
- status = 1;
+ invalid_operation();
+ status = 3;
break;
}
@@ -362,7 +387,10 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv)
authz_check(p, user, repo, need, ref, &d);
if (!d.allowed) {
- fprintf(stderr, "%s: deny: %s\n", progname, d.why);
+ if (o.explain)
+ fprintf(stderr, "%s: deny: %s\n", progname, d.why);
+ else
+ deny_ref(user, ref);
status = 1;
break;
}