From 11c976ec713b975568594cf57d9118f58ba8c511 Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 14 Nov 2026 17:46:44 +0000 Subject: 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. --- src/authz.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/authz.h') 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, ...); -- cgit v1.2.3