summaryrefslogtreecommitdiff
path: root/check/parse.c
blob: aded0b10d5f0af105654e355a2e4de095e1aaafd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}