aboutsummaryrefslogtreecommitdiffstats
path: root/key2root-addkey.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-06-23 11:58:57 +0200
committerMattias Andrée <maandree@kth.se>2023-06-23 11:58:57 +0200
commit050bab470f8187e40f6dba587d335af9c645c392 (patch)
tree09f3c1b2fe1fe57bf5eefab11d044d11777dc208 /key2root-addkey.c
parentAdd code from key2root-rmkey.c to key2root-addkey.c (diff)
downloadkey2root-050bab470f8187e40f6dba587d335af9c645c392.tar.gz
key2root-050bab470f8187e40f6dba587d335af9c645c392.tar.bz2
key2root-050bab470f8187e40f6dba587d335af9c645c392.tar.xz
key2root-addkey: mkdir /etc/key2root before saving changes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--key2root-addkey.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/key2root-addkey.c b/key2root-addkey.c
index ad3554b..f61063e 100644
--- a/key2root-addkey.c
+++ b/key2root-addkey.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <sys/mman.h>
+#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -113,6 +114,10 @@ main(int argc, char *argv[])
exit(1);
}
+ if (mkdir(KEYPATH, 0700) && errno != EEXIST) {
+ fprintf(stderr, "%s: mkdir %s: %s\n", argv0, KEYPATH, strerror(errno));
+ exit(1);
+ }
fd = open(path2, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fd < 0) {
fprintf(stderr, "%s: open %s O_WRONLY|O_CREAT|O_EXCL 0600: %s\n", argv0, path2, strerror(errno));