From 48ae39cf004d22c0cf96703e382dec41304c3280 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Sun, 22 Sep 2013 23:26:20 +0200 Subject: add confirmation via ssh-askpass --- ssh-agent-filter.C | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C index 8d87d0b..75759d7 100644 --- a/ssh-agent-filter.C +++ b/ssh-agent-filter.C @@ -37,9 +37,11 @@ namespace fs = boost::filesystem; #include #include #include +#include #include #include #include +#include #include #include #include @@ -234,6 +236,27 @@ void setup_filters () { } } +bool confirm (std::string const & question) { + char const * sap; + if (!(sap = getenv("SSH_ASKPASS"))) + sap = "ssh-askpass"; + pid_t pid = fork(); + if (pid < 0) + throw std::runtime_error("fork()"); + if (pid == 0) { + // child + char const * args[3] = { sap, question.c_str(), nullptr }; + // see execvp(3p) for cast rationale + execvp(sap, const_cast(args)); + perror("exec"); + exit(EX_UNAVAILABLE); + } else { + // parent + int status; + return waitpid(pid, &status, 0) > 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0; + } +} + rfc4251string handle_request (rfc4251string const & r) { std::istringstream request{r}; std::ostringstream answer; -- cgit v1.2.3