commit 7635272738912ebf7fe2b852e0a216e137616d66
parent 975aac18ec7afa1a2d257b11e05f645e169aff71
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Thu, 21 Oct 2021 21:15:09 -0500
extract configurable parameters into config.def.h
Diffstat:
6 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
@@ -9,6 +9,11 @@ NPM_CORE = "npm-core"
all: npm-core npm-agent npmc
+$(OBJ): config.h
+
+config.h: config.def.h
+ cp $< $@
+
npm-core: npm-core.o monocypher.o util.o
$(CC) $(LDFLAGS) npm-core.o monocypher.o util.o -o $@
diff --git a/common.h b/common.h
@@ -1,18 +1 @@
#define PASSWORD_MAX_LEN 512
-#define PASSPHRASE_MAX_LEN 512
-#define KEY_LEN 32
-#define NONCE_LEN 24
-#define SALT_LEN 8
-#define MAC_LEN 16
-
-// Argon2 parameters
-#define T_COST 250
-#define M_COST 1024 // 1 mibibyte
-
-#if SALT_LEN == 0 || SALT_LEN > SIZE_MAX - 4
-#error Invalid salt size
-#endif
-
-#ifndef SOCKPATH
-#define SOCKPATH "/tmp/npm-agent"
-#endif
diff --git a/config.def.h b/config.def.h
@@ -0,0 +1,15 @@
+// in bytes
+#define KEY_LEN 32
+#define NONCE_LEN 24
+#define SALT_LEN 8
+#define MAC_LEN 16
+
+// Argon2 parameters
+#define T_COST 250
+#define M_COST 1024 // 1 mibibyte
+
+#ifndef SOCKPATH
+#define SOCKPATH "/tmp/npm-agent"
+#endif
+
+char *const getpasscmd[] = { "bemenu", "-x", "-p", "Password:", NULL };
diff --git a/npm-agent.c b/npm-agent.c
@@ -23,6 +23,7 @@
#include <unistd.h>
#include "common.h"
+#include "config.h"
#include "util.h"
#ifndef TIMEOUT
@@ -34,8 +35,6 @@
#define CLIENT 2
char *corecmd[] = { NPM_CORE, "-d", NULL, NULL };
-//char *const getpasscmd[] = { "dmenu", "-P", "-p", "Password:", NULL };
-char *const getpasscmd[] = { "bemenu", "-x", "-p", "Password:", NULL };
bool cached = false;
@@ -143,13 +142,21 @@ run_core()
default:
close(stdinpipe[0]);
- if (xwrite(stdinpipe[1], master, masterlen) == -1) {
+ FILE *stdinfile = fdopen(stdinpipe[1], "r");
+ if (!stdinfile) {
+ perror("failed to open npm-core stdin as FILE");
+ close(stdinpipe[1]);
+ goto here;
+ }
+
+ if (fwrite(master, 1, masterlen, stdinfile) == -1) {
perror("failed to write master password to pipe");
return 1;
}
- close(stdinpipe[1]);
+ fclose(stdinfile);
+here:
waitpid(pid, &status, 0);
}
diff --git a/npm-core.c b/npm-core.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include "common.h"
+#include "config.h"
#include "monocypher.h"
#include "util.h"
diff --git a/npmc.c b/npmc.c
@@ -12,6 +12,7 @@
#include <errno.h>
#include "common.h"
+#include "config.h"
#include "util.h"
char answer[PASSWORD_MAX_LEN + 1];