summaryrefslogtreecommitdiffstats
path: root/src/validate.c
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/validate.c
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/validate.c')
-rw-r--r--src/validate.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/validate.c b/src/validate.c
index 91be26a..c5d05ab 100644
--- a/src/validate.c
+++ b/src/validate.c
@@ -77,19 +77,6 @@ static int ci_prefix(const char *line, const char *want)
return 1;
}
-static char *strip(char *s)
-{
- char *end;
-
- while (*s != '\0' && isspace((unsigned char)*s))
- s++;
- end = s + strlen(s);
- while (end > s && isspace((unsigned char)end[-1]))
- end--;
- *end = '\0';
- return s;
-}
-
// [section] key = value, last one winning - which is the mistake worth
// reporting in a gitconfig.
@@ -109,7 +96,7 @@ static int ini_value(const char *path, const char *section, const char *key,
if (f == NULL)
return -1;
while ((len = getline(&line, &cap, f)) != -1) {
- char *t = strip(line);
+ char *t = authz_trim(line);
char *eq;
if (*t == '\0' || *t == '#' || *t == ';')
@@ -124,9 +111,9 @@ static int ini_value(const char *path, const char *section, const char *key,
if (eq == NULL)
continue;
*eq = '\0';
- if (!ci_equal(strip(t), key))
+ if (!ci_equal(authz_trim(t), key))
continue;
- snprintf(out, outsz, "%s", strip(eq + 1));
+ snprintf(out, outsz, "%s", authz_trim(eq + 1));
{ // gitconfig allows quoting
size_t n = strlen(out);
@@ -158,7 +145,7 @@ static int directive_value(const char *path, const char *name, char *out, size_t
if (f == NULL)
return -1;
while ((len = getline(&line, &cap, f)) != -1) {
- char *t = strip(line);
+ char *t = authz_trim(line);
char *sp;
if (*t == '\0' || *t == '#')
@@ -171,7 +158,7 @@ static int directive_value(const char *path, const char *name, char *out, size_t
*sp = '\0';
if (!ci_equal(t, name))
continue;
- snprintf(out, outsz, "%s", strip(sp + 1));
+ snprintf(out, outsz, "%s", authz_trim(sp + 1));
free(line);
fclose(f);
return 1;
@@ -337,7 +324,7 @@ static void check_account(const policy_t *p, validate_opts o)
break;
}
if (nf >= 7 && strcmp(fields[0], "git") == 0) {
- char *shell = strip(fields[6]);
+ char *shell = authz_trim(fields[6]);
found = 1;
if (strstr(shell, "git-shell") == NULL)
@@ -368,7 +355,7 @@ static void check_keys(const policy_t *p, validate_opts o)
return;
}
while ((len = getline(&line, &cap, f)) != -1) {
- char *t = strip(line);
+ char *t = authz_trim(line);
char *at;
if (*t == '\0' || *t == '#')
@@ -426,7 +413,7 @@ static void check_htpasswd(const policy_t *p, validate_opts o)
return;
}
while ((len = getline(&line, &cap, f)) != -1) {
- char *t = strip(line);
+ char *t = authz_trim(line);
char *colon;
if (*t == '\0' || *t == '#')