diff --git a/src/rnp/rnpcfg.h b/src/rnp/rnpcfg.h index c9478bbd8..37c296eea 100644 --- a/src/rnp/rnpcfg.h +++ b/src/rnp/rnpcfg.h @@ -56,7 +56,6 @@ #define CFG_PASSFD "pass-fd" /* password file descriptor */ #define CFG_PASSWD "password" /* password as command-line constant */ #define CFG_PASSWORDC "passwordc" /* number of passwords for symmetric encryption */ -#define CFG_USERINPUTFD "user-input-fd" /* user input file descriptor */ #define CFG_NUMTRIES "numtries" /* number of password request tries, or 'unlimited' */ #define CFG_EXPIRATION "expiration" /* signature expiration time */ #define CFG_CREATION "creation" /* signature validity start */ diff --git a/src/rnpkeys/tui.cpp b/src/rnpkeys/tui.cpp index 73f26dc2d..5d3dca773 100644 --- a/src/rnpkeys/tui.cpp +++ b/src/rnpkeys/tui.cpp @@ -365,18 +365,6 @@ cli_rnp_set_generate_params(rnp_cfg &cfg, bool subkey) cfg.set_int(CFG_KG_SUBKEY_BITS, cfg.get_int(CFG_NUMBITS)); } else { FILE *input = stdin; - if (cfg.has(CFG_USERINPUTFD)) { - int inputfd = dup(cfg.get_int(CFG_USERINPUTFD)); - if (inputfd != -1) { - input = rnp_fdopen(inputfd, "r"); - if (!input) { - close(inputfd); - } - } - } - if (!input) { - return false; - } if (subkey) { res = rnpkeys_ask_generate_params_subkey(cfg, input); } else { diff --git a/src/tests/generatekey.cpp b/src/tests/generatekey.cpp index b846ebb4b..3fc682c58 100644 --- a/src/tests/generatekey.cpp +++ b/src/tests/generatekey.cpp @@ -582,6 +582,7 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) bool ret = false; int pipefd[2] = {-1, -1}; int user_input_pipefd[2] = {-1, -1}; + int saved_stdin = -1; size_t rsp_len; if (pipe(pipefd) == -1) { @@ -605,13 +606,21 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) } close(user_input_pipefd[1]); - /* Mock user-input*/ - ctx->cfg().set_int(CFG_USERINPUTFD, user_input_pipefd[0]); + /* Replace stdin with our pipe */ + saved_stdin = dup(STDIN_FILENO); + if (dup2(user_input_pipefd[0], STDIN_FILENO) == -1) { + ret = false; + goto end; + } if (!rnp_cmd(ctx, CMD_GENERATE_KEY, NULL)) { ret = false; goto end; } + if (dup2(saved_stdin, STDIN_FILENO) == -1) { + ret = false; + goto end; + } ops.copy(ctx->cfg()); ret = true; end: @@ -619,6 +628,7 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) if (user_input_pipefd[0]) { close(user_input_pipefd[0]); } + close(saved_stdin); return ret; } diff --git a/src/tests/support.h b/src/tests/support.h index 620692450..09be356f6 100644 --- a/src/tests/support.h +++ b/src/tests/support.h @@ -59,6 +59,8 @@ #ifdef _WIN32 #define pipe(fds) _pipe(fds, 256, O_BINARY) +#define dup(fd) _dup(fd) +#define dup2(fd1, fd2) _dup2(fd1, fd2) int setenv(const char *name, const char *value, int overwrite); int unsetenv(const char *name); #endif