diff options
author | Mattias Andrée <maandree@kth.se> | 2023-06-23 11:43:50 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-06-23 11:43:57 +0200 |
commit | f7b164989f4e9dcb8f5bd87f544adf5c2070eb81 (patch) | |
tree | 41145a93d11fb84a60a247aae85d220480e588c3 | |
parent | Fix minor mistakes i key2root-lskeys.c, implement key2root-rmkey.c, and minor work on key2root-addkey.c (diff) | |
download | key2root-f7b164989f4e9dcb8f5bd87f544adf5c2070eb81.tar.gz key2root-f7b164989f4e9dcb8f5bd87f544adf5c2070eb81.tar.bz2 key2root-f7b164989f4e9dcb8f5bd87f544adf5c2070eb81.tar.xz |
Make key directory compile-time configurable (intended for testing)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | config.mk | 4 | ||||
-rw-r--r-- | key2root-lskeys.c | 20 | ||||
-rw-r--r-- | key2root-rmkey.c | 6 |
3 files changed, 16 insertions, 14 deletions
@@ -1,8 +1,10 @@ PREFIX = /usr MANPREFIX = $(PREFIX)/share/man +KEYPATH = /etc/key2root + CC = cc -CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D'KEYPATH="$(KEYPATH)"' CFLAGS = -std=c99 -Wall -O2 LDFLAGS = -lcrypt diff --git a/key2root-lskeys.c b/key2root-lskeys.c index 69e6319..271b0a9 100644 --- a/key2root-lskeys.c +++ b/key2root-lskeys.c @@ -37,11 +37,11 @@ outputkey(char *data, size_t whead, size_t *rheadp, size_t *rhead2p, size_t *lin *linenop += 1; if (memchr(&data[*rheadp], '\0', len)) { - fprintf(stderr, "%s: NUL byte found in /etc/key2root/%s on line %zu\n", argv0, user, *linenop); + fprintf(stderr, "%s: NUL byte found in %s/%s on line %zu\n", argv0, KEYPATH, user, *linenop); failed = 1; } if (!memchr(&data[*rheadp], ' ', len)) { - fprintf(stderr, "%s: no SP byte found in /etc/key2root/%s on line %zu\n", argv0, user, *linenop); + fprintf(stderr, "%s: no SP byte found in %s/%s on line %zu\n", argv0, KEYPATH, user, *linenop); failed = 1; } @@ -71,7 +71,7 @@ listkeys(int dir, const char *user) if (fd < 0) { if (errno == ENOENT) return 0; - fprintf(stderr, "%s: openat /etc/key2root/ %s O_RDONLY: %s\n", argv0, user, strerror(errno)); + fprintf(stderr, "%s: openat %s/ %s O_RDONLY: %s\n", argv0, KEYPATH, user, strerror(errno)); return 1; } @@ -92,7 +92,7 @@ listkeys(int dir, const char *user) } r = read(fd, &data[whead], size - whead); if (r < 0) { - fprintf(stderr, "%s: read /etc/key2root/%s: %s\n", argv0, user, strerror(errno)); + fprintf(stderr, "%s: read %s/%s: %s\n", argv0, KEYPATH, user, strerror(errno)); close(fd); return 1; } @@ -103,7 +103,7 @@ listkeys(int dir, const char *user) } if (rhead != whead) { - fprintf(stderr, "%s: file truncated: /etc/key2root/%s\n", argv0, user); + fprintf(stderr, "%s: file truncated: %s/%s\n", argv0, KEYPATH, user); failed = 1; } @@ -125,11 +125,11 @@ main(int argc, char *argv[]) } ARGEND; if (argc) { - fd = open("/etc/key2root/", O_PATH); + fd = open(KEYPATH"/", O_PATH); if (fd < 0) { if (errno == ENOENT) return 0; - fprintf(stderr, "%s: open /etc/key2root/ O_PATH: %s\n", argv0, strerror(errno)); + fprintf(stderr, "%s: open %s/ O_PATH: %s\n", argv0, KEYPATH, strerror(errno)); exit(1); } for (; *argv; argv++) { @@ -142,11 +142,11 @@ main(int argc, char *argv[]) } close(fd); } else { - dir = opendir("/etc/key2root/"); + dir = opendir(KEYPATH"/"); if (!dir) { if (errno == ENOENT) return 0; - fprintf(stderr, "%s: opendir /etc/key2root/: %s\n", argv0, strerror(errno)); + fprintf(stderr, "%s: opendir %s/: %s\n", argv0, KEYPATH, strerror(errno)); exit(1); } fd = dirfd(dir); @@ -158,7 +158,7 @@ main(int argc, char *argv[]) listkeys(fd, f->d_name); } if (errno || closedir(dir)) { - fprintf(stderr, "%s: readdir /etc/key2root/: %s\n", argv0, strerror(errno)); + fprintf(stderr, "%s: readdir %s/: %s\n", argv0, KEYPATH, strerror(errno)); exit(1); } } diff --git a/key2root-rmkey.c b/key2root-rmkey.c index d3dbc16..eba2a9a 100644 --- a/key2root-rmkey.c +++ b/key2root-rmkey.c @@ -166,17 +166,17 @@ main(int argc, char *argv[]) for (i = 0; i < (size_t)argc; i++) keys[i] = argv[i]; - path = malloc(sizeof("/etc/key2root/") + strlen(user)); + path = malloc(sizeof(KEYPATH"/") + strlen(user)); if (!path) { fprintf(stderr, "%s: malloc: %s\n", argv0, strerror(errno)); exit(1); } - path2 = malloc(sizeof("/etc/key2root/~") + strlen(user)); + path2 = malloc(sizeof(KEYPATH"/~") + strlen(user)); if (!path) { fprintf(stderr, "%s: malloc: %s\n", argv0, strerror(errno)); exit(1); } - stpcpy(stpcpy(path, "/etc/key2root/"), user); + stpcpy(stpcpy(path, KEYPATH"/"), user); stpcpy(stpcpy(path2, path), "~"); fd = open(path, O_RDONLY); |