#include "validate.h"
LPCTSTR service_instance = TEXT("");
-
+static wchar_t win_sys_path[MAX_PATH];
/*
* These are necessary due to certain buggy implementations of (v)snprintf,
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, n);
return utf16;
}
+
+const wchar_t *
+get_win_sys_path(void)
+{
+ const wchar_t *default_sys_path = L"C:\\Windows\\system32";
+
+ if (!GetSystemDirectoryW(win_sys_path, _countof(win_sys_path)))
+ {
+ wcsncpy(win_sys_path, default_sys_path, _countof(win_sys_path));
+ win_sys_path[_countof(win_sys_path) - 1] = L'\0';
+ }
+
+ return win_sys_path;
+}
{
DWORD err;
DWORD i;
- WCHAR sys_path[MAX_PATH];
DWORD timeout = RDNS_TIMEOUT * 1000; /* in milliseconds */
- /* default path of ipconfig command */
- WCHAR ipcfg[MAX_PATH] = L"C:\\Windows\\system32\\ipconfig.exe";
+ /* path of ipconfig command */
+ WCHAR ipcfg[MAX_PATH];
struct
{
HANDLE wait_handles[2] = {rdns_semaphore, exit_event};
- if (GetSystemDirectory(sys_path, MAX_PATH))
- {
- swprintf(ipcfg, MAX_PATH, L"%s\\%s", sys_path, L"ipconfig.exe");
- ipcfg[MAX_PATH-1] = L'\0';
- }
+ swprintf(ipcfg, _countof(ipcfg), L"%s\\%s", get_win_sys_path(), L"ipconfig.exe");
+ ipcfg[_countof(ipcfg) - 1] = L'\0';
if (WaitForMultipleObjects(2, wait_handles, FALSE, timeout) == WAIT_OBJECT_0)
{
}
/* Path of netsh */
- int n = GetSystemDirectory(argv0, MAX_PATH);
- if (n > 0 && n < MAX_PATH) /* got system directory */
- {
- wcsncat(argv0, L"\\netsh.exe", MAX_PATH - n - 1);
- }
- else
- {
- wcsncpy(argv0, L"C:\\Windows\\system32\\netsh.exe", MAX_PATH);
- }
+ swprintf(argv0, _countof(argv0), L"%s\\%s", get_win_sys_path(), L"netsh.exe");
+ argv0[_countof(argv0) - 1] = L'\0';
/* cmd template:
* netsh interface $proto $action dns $if_name $addr [validate=no]
/* Convert a utf8 string to utf16. Caller should free the result */
wchar_t *utf8to16(const char *utf8);
+/* return windows system directory as a pointer to a static string */
+const wchar_t *get_win_sys_path(void);
+
#endif /* ifndef _SERVICE_H */