diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -5,6 +5,7 @@ #include <string.h> #include <signal.h> #include <errno.h> +#include <stdlib.h> #include <sys/wait.h> struct auth_env a_env; @@ -70,21 +71,29 @@ int main(int argc, char **argv) { sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); - int r = sd_setup(); - if (r == -1) { - sd_cleanup(); - return 13; - } - if (r) { - sd_cleanup(); + int r; + /* Very naive way to determine console and remote sessions. + * Better to use PAM_RHOST, ConsoleKit, or systemd-logind. */ + if (getenv("SSH_CONNECTION")) { 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(); + r = sd_setup(); + if (r == -1) { + sd_cleanup(); + return 13; + } + if (r) { + sd_cleanup(); + 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; } if (chld == -1) { |