diff options
Diffstat (limited to 'src/authz.h')
| -rw-r--r-- | src/authz.h | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/authz.h b/src/authz.h index d107fd8..ad39b35 100644 --- a/src/authz.h +++ b/src/authz.h @@ -10,7 +10,10 @@ #include <getopt.h> #include <stddef.h> -#define MAX_FIELDS 64 // one rule line, split on whitespace // one rule line, split on whitespace +#define MAX_FIELDS 64 // one rule line, split on whitespace +#define AUTHZ_MSGSZ 512 // one complaint, in the words the caller prints +#define DEFAULT_ROOT "/var/lib/git" // where the repositories live; the hook + // derives a repo name from this too typedef enum { LV_NONE = 0, @@ -67,6 +70,9 @@ char *authz_norm_ref(const char *in); char *authz_trim(char *s); +// A policy line's body: trimmed, comment and all after it gone. Edits the line. +char *authz_line_body(char *line); + // More than 'max' fields returns max+1, so the caller complains rather than // reading past the array. int authz_split_ws(char *line, char **fields, int max); @@ -83,6 +89,14 @@ int authz_level_of(const char *name); // -1 for anything that is not one // '@all' means everybody this policy already names; it never invents a name. int authz_user_known(const policy_t *p, const char *user); +// The grammar, in one place: check and the file parser must refuse the same +// lines for the same reason, because a rule the parser rejects denies every push +// in the repository. Fills msg with the complaint in the words the caller +// prints; returns 0 when the fields parse. A NULL user or repo is a field the +// caller is not asking about. +int authz_rule_validate(const char *user, const char *repo, const char *level, + char *const *refs, int nrefs, char *msg, size_t msgs); + // What a ref costs beyond what the rule said. Neither a branch nor a tag is // admin whatever a rule grants - refs/notes, refs/merge-requests, whatever a tool // invents next. The reason goes in raised (>= 64 bytes). @@ -95,10 +109,6 @@ level_t authz_need_for(const char *ref, level_t have, char *raised, void authz_check(const policy_t *p, const char *user, const char *repo, level_t need, const char *ref, decision_t *out); -// False means no rule reaches it at all - usually a name that stopped matching. - -int authz_repo_reachable(const policy_t *p, const char *repo); - // hook.c -------------------------------------------------------------------- // authorize mode: identity from the environment, "old new ref" on stdin, the @@ -121,35 +131,11 @@ int cmd_authorize(const policy_t *p, hook_opts o, int argc, char **argv); // validate.c ---------------------------------------------------------------- typedef struct { - const char *root; // where the repositories live - const char *hook_dir; - const char *gitconfig; - const char *sshd_config; - const char *passwd; - const char *keys; - const char *htpasswd; int strict; // warnings are errors } validate_opts; int cmd_validate(const policy_t *p, validate_opts o); -// edit.c -------------------------------------------------------------------- - -typedef struct { - const char *out; // NULL edits in place; "-" is stdout -} edit_opts; - -// Pulls --out and --stdout out of argv wherever they sit and compacts what is -// left, returning the count in *consumed. -1 on a missing value. -int authz_parse_out(int argc, char **argv, edit_opts *o, int *consumed); - -// A name starting with "--" is a mistyped option, not something to grant. -// Prints and returns 1 when it finds one. -int authz_reject_options(int argc, char **argv); - -int cmd_grant(const char *path, edit_opts o, int argc, char **argv); -int cmd_revoke(const char *path, edit_opts o, int argc, char **argv); - // util.c -------------------------------------------------------------------- // A growing string. strncat with hand-computed room is how buffer bugs are @@ -174,8 +160,8 @@ void lines_free(lines_t *l); // 0, -1 when the file cannot be opened, or -2 when reading stopped before the // end - a directory, an I/O error halfway, a mount pulled out. errno says which. -// The caller decides what a missing file means: an emergency for the policy, a -// plain fact for a validator cross-checking a host. +// The caller decides what a missing file means: an emergency for the policy, +// nothing at all for a file that is optional here. int authz_read_lines(const char *path, lines_t *l); void sb_init(strbuf_t *b); @@ -202,4 +188,8 @@ const char *authz_optname(int val, const struct option *lo); void authz_opt_reset(void); +// The two complaints every getopt_long loop would otherwise write by hand. +void authz_opt_need_value(const struct option *lo); +void authz_opt_unknown(const char *cmd, const char *arg); + #endif /* AUTHZ_H */ |
