aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..4652583
--- /dev/null
+++ b/main.c
@@ -0,0 +1,54 @@
+#include "log.h"
+#include "common.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+struct auth_env a_env;
+struct proc_env p_env = {
+ .in = STDIN_FILENO,
+ .out = STDOUT_FILENO,
+ .err = STDERR_FILENO
+};
+
+int main(int argc, char **argv) {
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: %s consent|password|auth [prompt]\n",
+ argv[0]);
+ return 64;
+ }
+ if (!strcmp(argv[1], "consent")) {
+ a_env.mode = mode_consent;
+ } else if (!strcmp(argv[1], "password")) {
+ a_env.mode = mode_password;
+ } else if (!strcmp(argv[1], "auth")) {
+ a_env.mode = mode_auth;
+ } else {
+ fprintf(stderr, "Unknown mode: %s\n", argv[1]);
+ return 64;
+ }
+
+ if ((a_env.prompt = argv[2])) {
+ char *p = argv[2];
+ do {
+ if ((*p) < 32 || (*p) > 126) {
+ fprintf(stderr, "The given prompt is illegal.\n");
+ return 64;
+ }
+ } while (*(++ p));
+ }
+
+ /* Because we need to frequently dup(2). */
+ setbuf(stdout, NULL);
+ a_env.pid = getppid();
+ signal(SIGHUP, SIG_IGN);
+ if (sd_setup()) {
+ sd_cleanup();
+ return main_consent(0);
+ } else {
+ int r = main_consent(1);
+ sd_cleanup();
+ return r;
+ }
+}