aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/main.c b/main.c
index a5f091b..0865bb4 100644
--- a/main.c
+++ b/main.c
@@ -4,14 +4,19 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
+#include <errno.h>
struct auth_env a_env;
struct proc_env p_env = {
.in = STDIN_FILENO,
.out = STDOUT_FILENO,
- .err = STDERR_FILENO
+ .err = STDERR_FILENO,
+ .vt = -1
};
+static void interrupt_int(int signum) {
+}
+
int main(int argc, char **argv) {
if (argc != 2 && argc != 3) {
fprintf(stderr, "Usage: %s consent|password|auth [prompt]\n",
@@ -38,11 +43,29 @@ int main(int argc, char **argv) {
}
} while (*(++ p));
}
+ a_env.pid = getppid();
+ a_env.usr = getuid();
+
+ ssize_t len;
+ snprintf(a_env.exe, sizeof(a_env.exe) - 1, "/proc/%d/exe", a_env.pid);
+ if ((len = readlink(a_env.exe, a_env.exe, sizeof(a_env.exe) - 1)) == -1) {
+ LOGFV("Read caller binary: %m.", errno);
+ return errno;
+ }
+ a_env.exe[len] = '\0';
/* Because we need to frequently dup(2). */
setbuf(stdout, NULL);
- a_env.pid = getppid();
signal(SIGHUP, SIG_IGN);
+ struct sigaction sa = {
+ .sa_flags = 0,
+ .sa_handler = interrupt_int
+ };
+ sigemptyset(&sa.sa_mask);
+ /* Return EINTR on these signals to exit safely. */
+ sigaction(SIGINT, &sa, NULL);
+ sigaction(SIGTERM, &sa, NULL);
+
int r = sd_setup();
if (r == -1) {
sd_cleanup();
@@ -50,10 +73,13 @@ int main(int argc, char **argv) {
}
if (r) {
sd_cleanup();
- return main_consent(0);
+ r = main_consent(0);
} else {
+ dprintf(p_env.err, "Complete authorization on TTY %d by running `chvt %d`.\n",
+ p_env.vt,
+ p_env.vt);
r = main_consent(1);
sd_cleanup();
- return r;
}
+ return r;
}