diff --git a/options.c b/options.c index 1117a0a7..77089956 100644 --- a/options.c +++ b/options.c @@ -766,11 +766,23 @@ init_options (struct options *o, const bool init_gc) #ifdef ENABLE_X509ALTUSERNAME o->x509_username_field = X509_USERNAME_FIELD_DEFAULT; #endif -#endif -#endif +#endif /* USE_SSL */ +#endif /* USE_CRYPTO */ #ifdef ENABLE_PKCS11 o->pkcs11_pin_cache_period = -1; #endif /* ENABLE_PKCS11 */ + + /* Set default --tmp-dir */ +#ifdef WIN32 + /* On Windows, find temp dir via enviroment variables */ + o->tmp_dir = win_get_tempdir(); +#else + /* Non-windows platforms use $TMPDIR, and if not set, default to '/tmp' */ + o->tmp_dir = getenv("TMPDIR"); + if( !o->tmp_dir ) { + o->tmp_dir = "/tmp"; + } +#endif /* WIN32 */ } void @@ -1916,8 +1928,6 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--client-connect requires --mode server"); if (options->client_disconnect_script) msg (M_USAGE, "--client-disconnect requires --mode server"); - if (options->tmp_dir) - msg (M_USAGE, "--tmp-dir requires --mode server"); if (options->client_config_dir || options->ccd_exclusive) msg (M_USAGE, "--client-config-dir/--ccd-exclusive requires --mode server"); if (options->enable_c2c) diff --git a/win32.c b/win32.c index 7c9901e0..2b7bf7b3 100644 --- a/win32.c +++ b/win32.c @@ -1093,4 +1093,23 @@ env_set_add_win32 (struct env_set *es) set_win_sys_path (DEFAULT_WIN_SYS_PATH, es); } + +const char * +win_get_tempdir() +{ + static char buf[MAX_PATH]; + char *tmpdir = buf; + + CLEAR(buf); + + if (!GetTempPath(sizeof(buf),buf)) { + /* Warn if we can't find a valid temporary directory, which should + * be unlikely. + */ + msg (M_WARN, "Could not find a suitable temporary directory." + " (GetTempPath() failed). Consider to use --tmp-dir"); + tmpdir = NULL; + } + return tmpdir; +} #endif diff --git a/win32.h b/win32.h index fcc3062d..b6a162ea 100644 --- a/win32.h +++ b/win32.h @@ -270,5 +270,8 @@ char *get_win_sys_path (void); /* call self in a subprocess */ void fork_to_self (const char *cmdline); +/* Find temporary directory */ +const char *win_get_tempdir(); + #endif #endif