diff options
| author | Jakob Kaivo <jkk@ung.org> | 2021-02-01 12:05:48 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2021-02-01 12:05:48 -0500 |
| commit | 5fd418a22a0b9631328b7516a901f829016a3be2 (patch) | |
| tree | f9cf274b58bf417dfc1d6429c9895c616d0d6655 /check/parse.c | |
| parent | 93854e37b25f7bb134291fc36956a3488e5cd201 (diff) | |
outline of check program
Diffstat (limited to 'check/parse.c')
| -rw-r--r-- | check/parse.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/check/parse.c b/check/parse.c new file mode 100644 index 0000000..aded0b1 --- /dev/null +++ b/check/parse.c @@ -0,0 +1,44 @@ +#define _POSIX_C_SOURCE 200809L +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "check.h" + +enum permission get_permission(const char *user, const char *group, const char *cmd) +{ + (void)user; (void)group; (void)cmd; + enum permission perm = UNKNOWN; + FILE *f = fopen(CONFIG_PATH, "r"); + if (f == NULL) { + fatal(1, CONFIG_PATH); + } + + ssize_t s = 0; + char *buf = NULL; + size_t len = 0; + while ((s = getline(&buf, &len, f)) > 0) { + if (*buf == '#') { + continue; + } + if (*buf == '\n') { + continue; + } + + char *space = strchr(buf, ' '); + if (!space) { + fatal(0, "invalid line in config: %s\n", buf); + } + } + if (s == -1 && ferror(f)) { + fatal(1, "reading configuration"); + } + + if (buf) { + free(buf); + } + if (f) { + fclose(f); + } + return perm; +} |
