From 84221006c9acf2b97a80564364df22e03184a1d8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 20 Sep 2011 15:58:35 +0200 Subject: curl tool: reviewed code moved to tool_*.[ch] files Overhauled FindWin32CACert() --- src/tool_doswin.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/tool_doswin.c') diff --git a/src/tool_doswin.c b/src/tool_doswin.c index dc9062798..7fab33b80 100644 --- a/src/tool_doswin.c +++ b/src/tool_doswin.c @@ -27,6 +27,11 @@ # include #endif +#ifdef WIN32 +# include +# include "tool_cfgable.h" +#endif + #include "tool_bname.h" #include "tool_doswin.h" @@ -225,5 +230,59 @@ static char *rename_if_dos_device_name (char *file_name) return file_name; } +#ifdef WIN32 + +/* + * Function to find CACert bundle on a Win32 platform using SearchPath. + * (SearchPath is already declared via inclusions done in setup header file) + * (Use the ASCII version instead of the unicode one!) + * The order of the directories it searches is: + * 1. application's directory + * 2. current working directory + * 3. Windows System directory (e.g. C:\windows\system32) + * 4. Windows Directory (e.g. C:\windows) + * 5. all directories along %PATH% + * + * For WinXP and later search order actually depends on registry value: + * HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode + */ + +CURLcode FindWin32CACert(struct Configurable *config, const char *bundle_file) +{ + CURLcode result = CURLE_OK; + + curl_version_info_data *info = curl_version_info(CURLVERSION_NOW); + + /* search and set cert file only if "we" support SSL */ + if(info->features & CURL_VERSION_SSL) { + + DWORD res_len; + DWORD buf_tchar_size = PATH_MAX + 1; + DWORD buf_bytes_size = sizeof(TCHAR) * buf_tchar_size; + char *ptr = NULL; + + char *buf = malloc(buf_bytes_size); + if(!buf) + return CURLE_OUT_OF_MEMORY; + buf[0] = '\0'; + + res_len = SearchPathA(NULL, bundle_file, NULL, buf_tchar_size, buf, &ptr); + if(res_len > 0) { + Curl_safefree(config->cacert); + config->cacert = strdup(buf); + if(!config->cacert) + result = CURLE_OUT_OF_MEMORY; + } + else + result = CURLE_SSL_CACERT; + + free(buf); + } + + return result; +} + +#endif /* WIN32 */ + #endif /* MSDOS || WIN32 */ -- cgit v1.2.3