static int wpa_config_write_reg_string(HKEY hk, const char *name, const char *val) { LONG ret; TCHAR *_name, *_val; _name = wpa_strdup_tchar(name); if (_name == NULL) return -1; if (val == NULL) { RegDeleteValue(hk, _name); os_free(_name); return 0; } _val = wpa_strdup_tchar(val); if (_val == NULL) { os_free(_name); return -1; } ret = RegSetValueEx(hk, _name, 0, REG_SZ, (BYTE *) _val, (os_strlen(val) + 1) * sizeof(TCHAR)); if (ret != ERROR_SUCCESS) { wpa_printf(MSG_ERROR, "WINREG: Failed to set %s='%s': " "error %d", name, val, (int) GetLastError()); os_free(_name); os_free(_val); return -1; } os_free(_name); os_free(_val); return 0; }
static int wpa_config_write_blob(HKEY hk, struct wpa_config_blob *blob) { HKEY bhk; LONG ret; TCHAR *name; ret = RegCreateKeyEx(hk, TEXT("blobs"), 0, NULL, 0, KEY_WRITE, NULL, &bhk, NULL); if (ret != ERROR_SUCCESS) { wpa_printf(MSG_DEBUG, "WINREG: Could not add blobs key: " "error 0x%x (%d)", (unsigned int) ret, (int) GetLastError()); return -1; } name = wpa_strdup_tchar(blob->name); ret = RegSetValueEx(bhk, name, 0, REG_BINARY, blob->data, blob->len); if (ret != ERROR_SUCCESS) { wpa_printf(MSG_ERROR, "WINREG: Failed to set blob %s': " "error 0x%x (%d)", blob->name, (unsigned int) ret, (int) GetLastError()); RegCloseKey(bhk); os_free(name); return -1; } os_free(name); RegCloseKey(bhk); return 0; }
static int tncc_load_imc(struct tnc_if_imc *imc) { if (imc->path == NULL) { wpa_printf(MSG_DEBUG, "TNC: No IMC configured"); return -1; } wpa_printf(MSG_DEBUG, "TNC: Opening IMC: %s (%s)", imc->name, imc->path); #ifdef CONFIG_NATIVE_WINDOWS #ifdef UNICODE { TCHAR *lib = wpa_strdup_tchar(imc->path); if (lib == NULL) return -1; imc->dlhandle = LoadLibrary(lib); os_free(lib); } #else /* UNICODE */ imc->dlhandle = LoadLibrary(imc->path); #endif /* UNICODE */ if (imc->dlhandle == NULL) { wpa_printf(MSG_ERROR, "TNC: Failed to open IMC '%s' (%s): %d", imc->name, imc->path, (int) GetLastError()); return -1; } #else /* CONFIG_NATIVE_WINDOWS */ imc->dlhandle = dlopen(imc->path, RTLD_LAZY); if (imc->dlhandle == NULL) { wpa_printf(MSG_ERROR, "TNC: Failed to open IMC '%s' (%s): %s", imc->name, imc->path, dlerror()); return -1; } #endif /* CONFIG_NATIVE_WINDOWS */ if (tncc_imc_resolve_funcs(imc) < 0) { wpa_printf(MSG_ERROR, "TNC: Failed to resolve IMC functions"); return -1; } if (tncc_imc_initialize(imc) < 0 || tncc_imc_provide_bind_function(imc) < 0) { wpa_printf(MSG_ERROR, "TNC: Failed to initialize IMC"); return -1; } return 0; }
int main(int argc, char *argv[]) { SERVICE_TABLE_ENTRY dt[] = { { WPASVC_NAME, service_start }, { NULL, NULL } }; if (argc > 1) { if (os_strcmp(argv[1], "reg") == 0) { TCHAR *path; int ret; if (argc < 3) { path = os_malloc(MAX_PATH * sizeof(TCHAR)); if (path == NULL) return -1; if (!GetModuleFileName(NULL, path, MAX_PATH)) { printf("GetModuleFileName failed: " "%d\n", (int) GetLastError()); os_free(path); return -1; } } else { path = wpa_strdup_tchar(argv[2]); if (path == NULL) return -1; } ret = register_service(path); os_free(path); return ret; } else if (os_strcmp(argv[1], "unreg") == 0) { return unregister_service(); } else if (os_strcmp(argv[1], "app") == 0) { return wpa_supplicant_thread(); } } if (!StartServiceCtrlDispatcher(dt)) { printf("StartServiceCtrlDispatcher failed: %d\n", (int) GetLastError()); } return 0; }
static int ctrl_iface_parse(struct ctrl_iface_priv *priv, const char *params) { const char *sddl = NULL; TCHAR *t_sddl; if (os_strncmp(params, "SDDL=", 5) == 0) sddl = params + 5; if (!sddl) { sddl = os_strstr(params, " SDDL="); if (sddl) sddl += 6; } if (!sddl) return 0; wpa_printf(MSG_DEBUG, "CTRL: SDDL='%s'", sddl); os_memset(&priv->attr, 0, sizeof(priv->attr)); priv->attr.nLength = sizeof(priv->attr); priv->attr.bInheritHandle = FALSE; t_sddl = wpa_strdup_tchar(sddl); if (t_sddl == NULL) return -1; if (!ConvertStringSecurityDescriptorToSecurityDescriptor( t_sddl, SDDL_REVISION_1, (PSECURITY_DESCRIPTOR *) (void *) &priv->attr.lpSecurityDescriptor, NULL)) { os_free(t_sddl); wpa_printf(MSG_ERROR, "CTRL: SDDL='%s' - could not convert to " "security descriptor: %d", sddl, (int) GetLastError()); return -1; } os_free(t_sddl); priv->sec_attr_set = 1; return 0; }