summaryrefslogtreecommitdiffstats
path: root/src/authz.h
diff options
context:
space:
mode:
authordev <dev@example>2026-11-14 17:46:44 +0000
committerdev <dev@example>2026-11-14 17:46:44 +0000
commit11c976ec713b975568594cf57d9118f58ba8c511 (patch)
tree840912cd000f50fbd4c045a3bceaa2b55261f3fe /src/authz.h
parent12dcb09794c48a333bb850d353540c688c503b76 (diff)
downloadaccess-control-11c976ec713b975568594cf57d9118f58ba8c511.tar.gz
access-control-11c976ec713b975568594cf57d9118f58ba8c511.zip
One reader for every file, one voice for every finding
Seven places opened a file, ran a getline loop, freed the line buffer and closed the handle, and five of them also rewrote the same skip-the-blank- and-comment preamble. authz_read_lines() does it once, and keeps the distinction policy_load needed: a file that would not give an answer is not an empty file. lines_t moves to util.c with it, so edit.c's private copy goes too. verr, vwarn and vok were one function with three tags. cmd_authorize now frees what it read on one path instead of four.
Diffstat (limited to 'src/authz.h')
-rw-r--r--src/authz.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/authz.h b/src/authz.h
index 8e6c2bb..d107fd8 100644
--- a/src/authz.h
+++ b/src/authz.h
@@ -160,6 +160,24 @@ typedef struct {
size_t cap;
} strbuf_t;
+// A file, one entry per line. The newline is kept, and a last line without one
+// is given one, so the lines may be written straight back out again.
+typedef struct {
+ char **v;
+ size_t n;
+ size_t cap;
+} lines_t;
+
+void lines_init(lines_t *l);
+void lines_push(lines_t *l, char *s); // takes ownership
+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.
+int authz_read_lines(const char *path, lines_t *l);
+
void sb_init(strbuf_t *b);
void sb_add(strbuf_t *b, const char *s);
void sb_addf(strbuf_t *b, const char *fmt, ...);