static bool get_console_input_systemd(const char *prompt, const bool echo, char *input, const int capacity) { int std_out; bool ret = false; struct argv argv = argv_new(); argv_printf(&argv, SYSTEMD_ASK_PASSWORD_PATH); #ifdef SYSTEMD_NEWER_THAN_216 /* the --echo support arrived in upstream systemd 217 */ if (echo) { argv_printf_cat(&argv, "--echo"); } #endif argv_printf_cat(&argv, "--icon network-vpn"); argv_printf_cat(&argv, "%s", prompt); if ((std_out = openvpn_popen(&argv, NULL)) < 0) { return false; } memset(input, 0, capacity); if (read(std_out, input, capacity-1) != 0) { chomp(input); ret = true; } close(std_out); argv_reset(&argv); return ret; }
static bool get_console_input_systemd (const char *prompt, const bool echo, char *input, const int capacity) { int std_out; bool ret = false; struct argv argv; argv_init (&argv); argv_printf (&argv, SYSTEMD_ASK_PASSWORD_PATH); argv_printf_cat (&argv, "%s", prompt); if ((std_out = openvpn_popen (&argv, NULL)) < 0) { return false; } memset (input, 0, capacity); if (read (std_out, input, capacity-1) > 0) { chomp (input); ret = true; } close (std_out); argv_reset (&argv); return ret; }