summaryrefslogtreecommitdiffstats
path: root/src/authz.h
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 17:42:44 +0000
committerdev <dev@example>2026-11-14 17:42:44 +0000
commit12dcb09794c48a333bb850d353540c688c503b76 (patch)
treef1538ec1b1c794790b16b2a4f3b6f1cd4cb99231 /src/authz.h
parenta2a702cb81eaf73a8989cc31c682592c8acb769a (diff)
downloadaccess-control-12dcb09794c48a333bb850d353540c688c503b76.tar.gz
access-control-12dcb09794c48a333bb850d353540c688c503b76.zip
Options: getopt_long instead of three hand-rolled parsers
option() in hook.c and one_option() in cmd/main.c were the same function under two names, and validate's seven options were a chain of seven calls to one of them. getopt_long does all of it - both --opt value and --opt=value, the lot - so the parsers are gone and what is left is a table and what each entry sets. Two small helpers carry what getopt_long cannot: the name behind a long option's val, for the 'wants a value' message, and the optind reset that lets a run parse options twice on two different argv slices. A command now gets argv[0] as its own name, which is where getopt_long expects argv[0]; the commands that take names step over it. strip() in validate.c was authz_trim() again, and cmd_authorize freed the same three pointers on four exit paths. One behaviour change: 'authorize --' is now the end-of-options marker rather than an unknown argument. Anything after it is still refused.
Diffstat (limited to 'src/authz.h')
-rw-r--r--src/authz.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/authz.h b/src/authz.h
index 671b45f..8e6c2bb 100644
--- a/src/authz.h
+++ b/src/authz.h
@@ -7,9 +7,10 @@
#ifndef AUTHZ_H
#define AUTHZ_H
+#include <getopt.h>
#include <stddef.h>
-#define MAX_FIELDS 64 // one rule line, split on whitespace
+#define MAX_FIELDS 64 // one rule line, split on whitespace // one rule line, split on whitespace
typedef enum {
LV_NONE = 0,
@@ -172,4 +173,15 @@ char *xsubstr(const char *s, size_t len);
// 'pre-receive' when invoked through the hook symlink, 'git-authz' otherwise.
extern const char *progname;
+// getopt_long hands back an option's val, not the name that was typed, and for
+// a long-only option the val is a number nobody wrote down. The table is the
+// only place that still knows the pair.
+
+const char *authz_optname(int val, const struct option *lo);
+
+// A run parses options twice - the global ones, then the command's own - each on
+// its own argv slice, so getopt_long has to be told to start again.
+
+void authz_opt_reset(void);
+
#endif /* AUTHZ_H */