diff --git a/cmdline.c b/cmdline.c index 812b71e7..99a46b5f 100644 --- a/cmdline.c +++ b/cmdline.c @@ -130,10 +130,15 @@ SeatPromptResult cmdline_get_passwd_input( return SPR_OK; } +static void cmdline_report_unavailable(const char *p) +{ + cmdline_error("option \"%s\" not available in this tool", p); +} + static bool cmdline_check_unavailable(int flag, const char *p) { if (cmdline_tooltype & flag) { - cmdline_error("option \"%s\" not available in this tool", p); + cmdline_report_unavailable(p); return true; } return false; @@ -906,6 +911,15 @@ int cmdline_process_param(const char *p, char *value, conf_set_str(conf, CONF_proxy_telnet_command, value); } + if (!strcmp(p, "-batch")) { + RETURN(1); + SAVEABLE(0); + if (!console_set_batch_mode(true)) { + cmdline_report_unavailable(p); + return ret; + } + } + #ifdef _WINDOWS /* * Cross-tool options only available on Windows. diff --git a/console.c b/console.c index 78c2da1b..c817c85e 100644 --- a/console.c +++ b/console.c @@ -36,6 +36,12 @@ const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat) bool console_batch_mode = false; +bool console_set_batch_mode(bool newvalue) +{ + console_batch_mode = newvalue; + return true; +} + /* * Error message and/or fatal exit functions, all based on * console_print_error_msg which the platform front end provides. diff --git a/pscp.c b/pscp.c index d5ac8845..d240ddd6 100644 --- a/pscp.c +++ b/pscp.c @@ -2298,8 +2298,6 @@ int psftp_main(int argc, char *argv[]) version(); } else if (strcmp(argv[i], "-ls") == 0) { list = true; - } else if (strcmp(argv[i], "-batch") == 0) { - console_batch_mode = true; } else if (strcmp(argv[i], "-unsafe") == 0) { scp_unsafe_mode = true; } else if (strcmp(argv[i], "-sftp") == 0) { diff --git a/psftp.c b/psftp.c index bf8782d3..e8ef3ea4 100644 --- a/psftp.c +++ b/psftp.c @@ -2836,8 +2836,6 @@ int psftp_main(int argc, char *argv[]) } else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) { version(); - } else if (strcmp(argv[i], "-batch") == 0) { - console_batch_mode = true; } else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) { mode = 1; batchfile = argv[++i]; diff --git a/putty.h b/putty.h index e5691bca..7927277b 100644 --- a/putty.h +++ b/putty.h @@ -2562,6 +2562,7 @@ bool have_ssh_host_key(const char *host, int port, const char *keytype); * that aren't equivalents to things in windlg.c et al. */ extern bool console_batch_mode, console_antispoof_prompt; +extern bool console_set_batch_mode(bool); SeatPromptResult console_get_userpass_input(prompts_t *p); bool is_interactive(void); void console_print_error_msg(const char *prefix, const char *msg); @@ -2627,6 +2628,7 @@ extern const unsigned cmdline_tooltype; X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \ X(TOOLTYPE_PORT_ARG) \ X(TOOLTYPE_NO_VERBOSE_OPTION) \ + X(TOOLTYPE_GUI) \ /* end of list */ #define BITFLAG_INDEX(val) val ## _bitflag_index, enum { TOOLTYPE_LIST(BITFLAG_INDEX) }; diff --git a/stubs/no-console.c b/stubs/no-console.c new file mode 100644 index 00000000..b7a3ef75 --- /dev/null +++ b/stubs/no-console.c @@ -0,0 +1,10 @@ +/* + * Stub functions for when console.c is not linked into a program. + */ + +#include "putty.h" + +bool console_set_batch_mode(bool newvalue) +{ + return false; +} diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index d4de28df..2ea1416c 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -137,6 +137,7 @@ if(GTK_FOUND) main-gtk-simple.c ${CMAKE_SOURCE_DIR}/stubs/no-gss.c ${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c ${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c pty.c) be_list(pterm pterm) @@ -152,6 +153,7 @@ if(GTK_FOUND) ${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c ${CMAKE_SOURCE_DIR}/stubs/no-gss.c ${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c ${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c pty.c) be_list(ptermapp pterm) @@ -162,7 +164,8 @@ if(GTK_FOUND) add_executable(putty putty.c - main-gtk-simple.c) + main-gtk-simple.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c) be_list(putty PuTTY SSH SERIAL OTHERBACKENDS) target_link_libraries(putty guiterminal eventloop sshclient otherbackends settings @@ -176,7 +179,8 @@ if(GTK_FOUND) add_executable(puttyapp putty.c main-gtk-application.c - ${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c) + ${CMAKE_SOURCE_DIR}/stubs/no-cmdline.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c) be_list(puttyapp PuTTY SSH SERIAL OTHERBACKENDS) target_link_libraries(puttyapp guiterminal eventloop sshclient otherbackends settings @@ -189,6 +193,7 @@ if(GTK_FOUND) main-gtk-simple.c ${CMAKE_SOURCE_DIR}/stubs/no-gss.c ${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c ${CMAKE_SOURCE_DIR}/stubs/no-rand.c ${CMAKE_SOURCE_DIR}/proxy/nocproxy.c ${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c) diff --git a/unix/plink.c b/unix/plink.c index c1738e10..3f7f7bd8 100644 --- a/unix/plink.c +++ b/unix/plink.c @@ -735,8 +735,6 @@ int main(int argc, char **argv) --argc, ++argv; } else if (ret == 1) { continue; - } else if (!strcmp(p, "-batch")) { - console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ use_subsystem = true; diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 1d50a91c..b6f9ab1c 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -101,6 +101,7 @@ add_executable(putty window.c putty.c help.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c putty.rc) be_list(putty PuTTY SSH SERIAL OTHERBACKENDS) add_dependencies(putty generated_licence_h) @@ -119,6 +120,7 @@ add_executable(puttytel help.c ${CMAKE_SOURCE_DIR}/stubs/no-gss.c ${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c ${CMAKE_SOURCE_DIR}/stubs/no-rand.c ${CMAKE_SOURCE_DIR}/proxy/nocproxy.c ${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c @@ -161,6 +163,7 @@ if(HAVE_CONPTY) conpty.c ${CMAKE_SOURCE_DIR}/stubs/no-gss.c ${CMAKE_SOURCE_DIR}/stubs/no-ca-config.c + ${CMAKE_SOURCE_DIR}/stubs/no-console.c ${CMAKE_SOURCE_DIR}/stubs/no-rand.c ${CMAKE_SOURCE_DIR}/proxy/nosshproxy.c pterm.rc) diff --git a/windows/plink.c b/windows/plink.c index 48429ba2..a84f0e4b 100644 --- a/windows/plink.c +++ b/windows/plink.c @@ -340,8 +340,6 @@ int main(int argc, char **argv) --argc, ++argv; } else if (ret == 1) { continue; - } else if (!strcmp(p, "-batch")) { - console_batch_mode = true; } else if (!strcmp(p, "-s")) { /* Save status to write to conf later. */ use_subsystem = true;