summaryrefslogtreecommitdiff
path: root/src/tool_doswin.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-09-20 15:58:35 +0200
committerYang Tse <yangsita@gmail.com>2011-09-20 15:59:19 +0200
commit84221006c9acf2b97a80564364df22e03184a1d8 (patch)
treeca43199e0bccec687f89fabb81ce52528544ffd0 /src/tool_doswin.c
parenta6c168b893205f4a6660250699ac3f046b424b76 (diff)
downloadcurl-84221006c9acf2b97a80564364df22e03184a1d8.tar.gz
curl tool: reviewed code moved to tool_*.[ch] files
Overhauled FindWin32CACert()
Diffstat (limited to 'src/tool_doswin.c')
-rw-r--r--src/tool_doswin.c59
1 files changed, 59 insertions, 0 deletions
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 <libgen.h>
#endif
+#ifdef WIN32
+# include <curl/curl.h>
+# 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 */