aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.mk4
-rw-r--r--key2root-lskeys.c20
-rw-r--r--key2root-rmkey.c6
3 files changed, 16 insertions, 14 deletions
diff --git a/config.mk b/config.mk
index 97a6f0f..38b5163 100644
--- a/config.mk
+++ b/config.mk
@@ -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);