Exemple #1
0
static enum install_res install_from_registered_dir(void)
{
    char *package_dir;
    HKEY hkey;
    DWORD res, type, size = MAX_PATH;
    enum install_res ret;

    hkey = open_config_key();
    if(!hkey)
        return INSTALL_NEXT;

    package_dir = heap_alloc(size);
    res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
    if(res == ERROR_MORE_DATA) {
        package_dir = heap_realloc(package_dir, size);
        res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
    }
    RegCloseKey(hkey);
    if(res == ERROR_FILE_NOT_FOUND) {
        heap_free(package_dir);
        return INSTALL_NEXT;
    } else if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
        heap_free(package_dir);
        return INSTALL_FAILED;
    }

    TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));

    ret = install_from_unix_file(package_dir, "", addon->file_name);

    heap_free(package_dir);
    return ret;
}
void DebugCheckState(void)
{

#ifdef __WINDOWS__
	char buf[1024];
	DWORD size = sizeof(buf);

	LSTATUS err = RegGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Silicondust\\HDHomeRun", "DebugFilename", RRF_RT_REG_SZ, NULL, (PVOID) buf, &size);
	if (err != 0) {
		buf[0] = '\0';
	}

	DebugFilename = buf;

	size = sizeof(DebugExpireTime);
	err = RegGetValueA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Silicondust\\HDHomeRun", "DebugEnabled", RRF_RT_REG_QWORD, NULL, (PVOID) & DebugExpireTime, &size);
	if (err != 0) {
		DebugExpireTime = 0;
	}
#endif

	if (DebugFilename.empty()) {
		hdhomerun_debug_set_filename(dbg, NULL);
	} else {
		hdhomerun_debug_set_filename(dbg, DebugFilename.c_str());
	}

	if (DebugExpireTime > (unsigned long long)time(NULL)) {
		hdhomerun_debug_enable(dbg);
	} else {
		hdhomerun_debug_disable(dbg);
	}
}
Exemple #3
0
static enum install_res install_from_registered_dir(void)
{
    char *package_dir;
    DWORD res, type, size = MAX_PATH;
    enum install_res ret;

    package_dir = heap_alloc(size + sizeof(addon->file_name));

    res = RegGetValueA(HKEY_CURRENT_USER, mshtml_keyA, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
    if(res == ERROR_MORE_DATA) {
        package_dir = heap_realloc(package_dir, size + sizeof(addon->file_name));
        res = RegGetValueA(HKEY_CURRENT_USER, mshtml_keyA, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
    }

    if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
        heap_free(package_dir);
        return INSTALL_FAILED;
    }

    TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));

    ret = install_from_unix_file(package_dir, "", addon->file_name);

    heap_free(package_dir);
    return ret;
}
Exemple #4
0
static BOOL install_from_registered_dir(void)
{
    char *file_name;
    HKEY hkey;
    DWORD res, type, size = MAX_PATH;
    BOOL ret;

    /* @@ Wine registry key: HKCU\Software\Wine\MSHTML */
    res = RegOpenKeyW(HKEY_CURRENT_USER, mshtml_keyW, &hkey);
    if(res != ERROR_SUCCESS)
        return FALSE;

    file_name = heap_alloc(size+sizeof(GECKO_FILE_NAME));
    res = RegGetValueA(hkey, NULL, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)file_name, &size);
    if(res == ERROR_MORE_DATA) {
        file_name = heap_realloc(file_name, size+sizeof(GECKO_FILE_NAME));
        res = RegGetValueA(hkey, NULL, "GeckoCabDir", RRF_RT_ANY, &type, (PBYTE)file_name, &size);
    }
    RegCloseKey(hkey);
    if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
        heap_free(file_name);
        return FALSE;
    }

    strcat(file_name, GECKO_FILE_NAME);

    TRACE("Trying %s\n", debugstr_a(file_name));

    ret = install_from_unix_file(file_name);

    heap_free(file_name);
    return ret;
}
Exemple #5
0
// Read a Registry Key Value into a specified memory buffer
static eEsifError DataVault_ReadRegistry (
	DataVaultPtr self,
	esif_string keyname,
	void * *buffer,
	UInt32 *buf_size
	)
{
	eEsifError rc   = ESIF_E_UNSPECIFIED;
	HKEY hKey       = 0;
	DWORD dwFlags   = RRF_RT_ANY;
	DWORD dwError   = 0;
	DWORD dwSize    = 0;
	char *regkey    = 0;
	char *valuename = 0;
	u32 j;

	UNREFERENCED_PARAMETER(self);

	// Format: HKLM\Subkey\Path\ValueName
	for (j = 0; HKeyList[j].name; j++) {
		size_t namelen = esif_ccb_strlen(HKeyList[j].name, 30);
		if (esif_ccb_strnicmp(HKeyList[j].name, keyname, namelen) == 0 && keyname[namelen] == '\\') {
			hKey     = HKeyList[j].hkey;
			keyname += esif_ccb_strlen(HKeyList[j].name, 30) + 1;
			break;
		}
	}
	if (!hKey) {
		return rc;
	}

	regkey = esif_ccb_strdup(keyname);
	if ((valuename = strrchr(regkey, '\\')) == 0) {
		esif_ccb_free(regkey);
		return rc;
	}
	*valuename++ = 0;

	// Get Data Size from Registry and copy into buffer if found
	if ((dwError = RegGetValueA(hKey, regkey, valuename, dwFlags, NULL, 0, &dwSize)) == 0) {
		void *reg_buf = esif_ccb_malloc(dwSize);
		dwError = RegGetValueA(hKey, regkey, valuename, dwFlags, NULL, reg_buf, &dwSize);
		if (dwError == 0) {
			*buffer   = reg_buf;
			*buf_size = dwSize;
			rc = ESIF_OK;
		} else {
			esif_ccb_free(reg_buf);
		}
	} else {
		rc = ESIF_E_NOT_FOUND;
	}
	esif_ccb_free(regkey);
	return rc;
}
Exemple #6
0
DWORD
VmAfWinCfgReadDWORDValue(
    PVMAF_CFG_KEY       pKey,
    PCSTR               pszSubkey,
    PCSTR               pszName,
    PDWORD              pdwValue
    )
{
    DWORD dwError = 0;
    DWORD dwValue = 0;
    DWORD dwValueSize = sizeof(dwValue);

    dwError = RegGetValueA(
                    pKey->hKey,
                    pszSubkey,
                    pszName,
                    RRF_RT_REG_DWORD,
                    NULL,
                    (PVOID)&dwValue,
                    &dwValueSize);
    BAIL_ON_VMAFD_ERROR_NO_LOG(dwError);

    *pdwValue = dwValue;

cleanup:

    return dwError;

error:

    *pdwValue = 0;

    goto cleanup;
}
BOOL hijack_key(std::string subKey, std::string proxy_path)
{
    std::string commandKey = subKey + "\\shell\\open\\command";
    HKEY hHijackedKey = NULL;
    size_t changed = 0;
    if (RegOpenKeyExA(HKEY_USERS, commandKey.c_str(), 0, KEY_READ | KEY_WRITE, &hHijackedKey) != ERROR_SUCCESS) {
        return FALSE;
    }

    char path_buffer[MAX_KEY_LENGTH];
    DWORD val_len = MAX_KEY_LENGTH;
    DWORD type;
    RegGetValueA(hHijackedKey, NULL, 0, REG_SZ, &type, path_buffer, &val_len);

    printf("[W]%s\n", path_buffer);
    if (strstr(path_buffer, proxy_path.c_str()) != NULL) {
        printf("Already hijacked!\n");
        RegCloseKey(hHijackedKey);
        return TRUE;
    }

    std::string hijacked = proxy_path + " " + std::string(path_buffer);
    printf("[H]%s\n\n", hijacked.c_str());

    if (RegSetValueExA(hHijackedKey, NULL, 0, REG_SZ, (const BYTE*) hijacked.c_str(), hijacked.length()) != ERROR_SUCCESS) {
        RegCloseKey(hHijackedKey);
        return FALSE;
    }
    return TRUE;
}
Exemple #8
0
DWORD
VmDirRegConfigGetValue(
    PVMDIR_CONFIG_CONNECTION_HANDLE pCfgHandle,
    PCSTR  pszSubKey,
    PCSTR  pszKeyName,
    DWORD  valueType,
    PBYTE  pRetValue,
    PDWORD pRetValueLen
    )
{
    DWORD dwError = 0;

    dwError = RegGetValueA(
#ifndef _WIN32
                pCfgHandle->hConnection,
#endif
                pCfgHandle->hKey,
                pszSubKey,
                pszKeyName,
                valueType,
                NULL,
                (PVOID) pRetValue,
                pRetValueLen);
    BAIL_ON_VMDIR_ERROR_NO_LINE(dwError);

error:
    if (dwError)
    {
        *pRetValueLen = 0;
    }

    return dwError;
}
        const std::string& getZusi3Datenpfad() {
            if (zusi3Datenpfad.empty()) {
                HKEY key;
                char buffer[MAX_PATH];
                DWORD len = MAX_PATH;
                if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Zusi3", 0, KEY_READ | KEY_WOW64_32KEY, &key)) &&
				        SUCCEEDED(RegGetValueA(key, nullptr, "DatenVerzeichnis", RRF_RT_REG_SZ, nullptr, (LPBYTE)buffer, &len))) {
                    zusi3Datenpfad = string(buffer, len - 1); // subtract terminating null character
                    RegCloseKey(key);
                }
            }
            return zusi3Datenpfad;
        }
std::string getValueString(HKEY baseKey, std::string subKey)
{
    HKEY commandKey = NULL;
    if (RegOpenKeyExA(baseKey, subKey.c_str(), 0, KEY_READ, &commandKey) != ERROR_SUCCESS) {
        return "";
    }
    char path_buffer[MAX_KEY_LENGTH];
    DWORD val_len = MAX_KEY_LENGTH;
    DWORD type;
    RegGetValueA(commandKey, NULL, 0, REG_SZ, &type, path_buffer, &val_len);
    RegCloseKey(commandKey);
    if (type != REG_SZ) return "";
    if (val_len == 0) return "";
    return path_buffer;
}
bool read_key(HKEY srcBaseKey, std::string subKey, OUT BYTE *path_buffer, OUT DWORD &val_len, OUT DWORD &type)
{
    HKEY commandKey = NULL;
    if (RegOpenKeyExA(srcBaseKey, subKey.c_str(), 0, KEY_READ, &commandKey) != ERROR_SUCCESS) {
        return false;
    }

    RegGetValueA(commandKey, NULL, 0, RRF_RT_ANY, &type, path_buffer, &val_len);
    if (val_len == 0) {
        RegCloseKey(commandKey);
        return false;
    }
    RegCloseKey(commandKey);
    return true;
}
Exemple #12
0
static
DWORD
VmDirRegConfigGetMultiString(
    PVMDIR_CONFIG_CONNECTION_HANDLE pCfgHandle,
    PCSTR   pszSubKey,
    PCSTR   pszKeyName,
    PSTR    *ppszValue
    )
{
    DWORD dwError = 0;
    char szValue[VMDIR_MAX_CONFIG_VALUE_LENGTH] = {0};
    DWORD dwszValueSize = sizeof(szValue);
    PSTR pszValue = NULL;

    dwError = RegGetValueA(
#ifndef _WIN32
                pCfgHandle->hConnection,
#endif
                pCfgHandle->hKey,
                pszSubKey,
                pszKeyName,
                RRF_RT_REG_MULTI_SZ,
                NULL,
                szValue,
                &dwszValueSize);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirAllocateMemory(dwszValueSize, (PVOID)&pszValue);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirCopyMemory(pszValue, dwszValueSize, szValue, dwszValueSize);
    BAIL_ON_VMDIR_ERROR(dwError);

    *ppszValue = pszValue;

cleanup:

    return dwError;

error:

    *ppszValue = NULL;

    VMDIR_SAFE_FREE_MEMORY(pszValue);

    goto cleanup;
}
Exemple #13
0
DWORD
VmAfWinCfgReadStringValue(
    PVMAF_CFG_KEY       pKey,
    PCSTR               pszSubkey,
    PCSTR               pszName,
    PSTR*               ppszValue
    )
{
    DWORD dwError = 0;
    CHAR  szValue[VMAF_MAX_CONFIG_VALUE_BYTE_LENGTH] = {0};
    DWORD dwszValueSize = sizeof(szValue);
    PSTR  pszValue = NULL;

    dwError = RegGetValueA(
                    pKey->hKey,
                    pszSubkey,
                    pszName,
                    RRF_RT_REG_SZ,
                    NULL,
                    szValue,
                    &dwszValueSize);
    BAIL_ON_VMAFD_ERROR_NO_LOG(dwError);

    dwError = VmAfdAllocateStringA(szValue, &pszValue);
    BAIL_ON_VMAFD_ERROR(dwError);

    *ppszValue = pszValue;

cleanup:

    return dwError;

error:

    *ppszValue = NULL;

    if (pszValue)
    {
        VmAfdFreeStringA(pszValue);
    }

    goto cleanup;
}
Exemple #14
0
static
DWORD
VmAuthsvcRegConfigGetString(
    PVMAUTHSVC_CONFIG_CONNECTION_HANDLE pCfgHandle,
    PCSTR   pszSubKey,
    PCSTR   pszKeyName,
    PSTR    *ppszValue)
{
    DWORD dwError = 0;
    char szValue[VMAUTHSVC_MAX_CONFIG_VALUE_LENGTH] = {0};
    DWORD dwszValueSize = sizeof(szValue);
    PSTR pszValue = NULL;

    dwError = RegGetValueA(
                pCfgHandle->hConnection,
                pCfgHandle->hKey,
                pszSubKey,
                pszKeyName,
                RRF_RT_REG_SZ,
                NULL,
                szValue,
                &dwszValueSize);
    BAIL_ON_VMAUTHSVC_ERROR(dwError);

    dwError = VmAuthsvcAllocateStringA(szValue, &pszValue);
    BAIL_ON_VMAUTHSVC_ERROR(dwError);

    *ppszValue = pszValue;

cleanup:

    return dwError;

error:

    *ppszValue = NULL;

    VMAUTHSVC_SAFE_FREE_STRINGA(pszValue);

    goto cleanup;
}
	// Return empty string if registry value was not found.
	// WARNING - Do not use this function for values larger that 2048.
	//////////////////////////////////////////////////////////////////////////////////////////////// 
	std::string RetrieveRegistryStringValue( const HKEY in_hkey, const std::string &in_Key )
	{
		std::string tempString = "";

		DWORD	pdwType;
		char	pvData[MAX_VALUE_NAME];
		DWORD	pcbData = MAX_VALUE_NAME;

		LSTATUS errorStatus = 
			RegGetValueA(	in_hkey,		// A handle to an open registry key
							NULL,			// subkey of the key specified by the hkey parameter.
							in_Key.c_str(), // The name of the registry value. 
							RRF_RT_REG_SZ,  // Flags that restrict the data type of value to be queried.  RRF_RT_REG_SZ only strings.
							&pdwType,		// A pointer to a variable that receives a code indicating the type of data stored
							pvData,			// A pointer to a buffer that receives the value's data. 
							&pcbData  );		// A pointer to a variable that specifies the size of the buffer pointed to by the pvData 
		
		if ( errorStatus == ERROR_SUCCESS ) tempString = (char *) pvData;

		return tempString;
	}
Exemple #16
0
static
DWORD
VmDirRegConfigGetDword(
    PVMDIR_CONFIG_CONNECTION_HANDLE pCfgHandle,
    PCSTR  pszSubKey,
    PCSTR  pszKeyName,
    PDWORD pdwValue
    )
{
    DWORD dwError =0;
    DWORD dwValue = 0;
    DWORD dwValueSize = sizeof(dwValue);

    dwError = RegGetValueA(
#ifndef _WIN32
                pCfgHandle->hConnection,
#endif
                pCfgHandle->hKey,
                pszSubKey,
                pszKeyName,
                RRF_RT_REG_DWORD,
                NULL,
                (PVOID)&dwValue,
                &dwValueSize);
    BAIL_ON_VMDIR_ERROR(dwError);

    *pdwValue = dwValue;

cleanup:

    return dwError;

error:

    *pdwValue = 0;

    goto cleanup;
}
void load_settings()
{
	HKEY hkey;
	RegOpenKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\auto-screengrab", 0, KEY_QUERY_VALUE, &hkey);

	DWORD sz = 128;
	RegGetValueA(hkey, NULL, "smtp_url", RRF_RT_REG_SZ, NULL, &g_smtpURL, &sz);
	sz = 128;
	RegGetValueA(hkey, NULL, "smtp_user", RRF_RT_REG_SZ, NULL, &g_smtpUser, &sz);
	sz = 128;
	RegGetValueA(hkey, NULL, "smtp_pass", RRF_RT_REG_SZ, NULL, &g_smtpPass, &sz);
	sz = 128;
	RegGetValueA(hkey, NULL, "smtp_from", RRF_RT_REG_SZ, NULL, &g_smtpFrom, &sz);
	sz = 128;
	RegGetValueA(hkey, NULL, "smtp_to", RRF_RT_REG_SZ, NULL, &g_smtpTo, &sz);
	sz = 128;
	RegGetValueA(hkey, NULL, "smtp_url", RRF_RT_REG_SZ, NULL, &g_smtpURL, &sz);

	RegCloseKey(hkey);
}
Exemple #18
0
int registry_walker(HKEY hkey, const char * section,  struct a6o_conf * conf){

	int ret = 0;
	HKEY hSubKey = NULL;
	char * subkey_name = NULL;
	int subkey_maxlen = 0;
	int subkey_len = 0;
	char * class = NULL;
	char * value_name = NULL;
	int value_len = 0;
	int value_maxlen = 0;
	int value_type =0;
	int data_len = 0;
	char * data_str = NULL;
	int data_int = 0;
	char ** data_list = NULL;
	char * tmp = NULL;
	int list_len = 0;
	int class_len = 0;
	int class_maxlen = 0;
	int res = 0;
	int nb_index = 0, i =0,j=0;
	int nbvalues = 0;
	struct conf_reg_data data = {0};
	

	if (hkey == NULL) {
		printf("[-] Error :: registry_walker :: invalid parameter!\n");
		return -1;
	}

	__try {


		res = RegQueryInfoKeyA(hkey, NULL, &class_len, NULL, &nb_index, &subkey_maxlen, &class_maxlen, &nbvalues, &value_maxlen, NULL,NULL,NULL);
		if (res != ERROR_SUCCESS) {
			printf("[-] Error :: RegEnumKeyExA failed! :: GLE= %d\n", res);
			ret = -3;
			__leave;
		}
		//printf("[+] Debug :: nbindex = %d :: nbvalues = %d\n",nb_index,nbvalues);
		//printf("[+] Debug :: subkey_maxlen = %d :: index = %d :: class_maxlen = %d :: nbvalues = %d\n",subkey_maxlen ,nb_index, class_maxlen, nbvalues);


		value_maxlen++;
		value_name = (char *)calloc(value_maxlen + 1, sizeof(char));

		// Get values.
		for (i = 0; i < nbvalues; i++) {

			value_len = value_maxlen;
			if ((res = RegEnumValueA(hkey, i, value_name, &value_len, NULL, &value_type, NULL, &data_len)) != ERROR_SUCCESS) {
				printf("[-] Error :: RegEnumValueA failed! :: GLE= %d\n", res);
				ret = -3;
				__leave;
			}

			// get data.
			switch (value_type) {

				case REG_DWORD:					
					if ((res = RegGetValueA(hkey,NULL,value_name,RRF_RT_ANY, NULL, &data_int,&data_len)) != ERROR_SUCCESS ) {
						printf("[-] Error :: RegEnumValueA failed! :: GLE= %d\n", res);
						break;
					}
					//printf("[+] Debug :: value_name = %s :: value_type = %d :: data_len = %d :: data_int = %d\n",value_name,value_type,data_len,data_int );
					//printf("[+] Debug :: (%s) => %d\n",value_name,data_int );

					// add value to conf struct
					if (section != NULL)
						a6o_conf_add_uint(conf, section, value_name, data_int);

					break;
				case REG_SZ:

					//printf("[+] Debug :: value_name = %s :: value_type = %d :: data_len = %d\n",value_name,value_type,data_len );					
					data_str = (char *)calloc(data_len + 1, sizeof(char));
					if ((res = RegGetValueA(hkey,NULL,value_name,RRF_RT_ANY, NULL,data_str,&data_len)) != ERROR_SUCCESS ) {
						printf("[-] Error :: RegEnumValueA failed! :: GLE= %d\n", res);
						break;
					}
					//printf("[+] Debug :: (%s) => %s\n",value_name,data_str);

					if (section != NULL)
						a6o_conf_add_string(conf, section, value_name, data_str);
					break;


				case REG_MULTI_SZ:

					//data_string
					//printf("[+] Debug :: value_name = %s :: value_type = %d :: data_len = %d\n",value_name,value_type,data_len );

					data_str = (char *)calloc(data_len + 1, sizeof(char));
					if ((res = RegGetValueA(hkey,NULL,value_name,RRF_RT_ANY, NULL,data_str,&data_len)) != ERROR_SUCCESS ) {
						printf("[-] Error :: RegEnumValueA failed! :: GLE= %d\n", res);
						break;
					}

					//printf("[+] Debug :: [%s] => %s\n",value_name,data_str);
					//printf("[+] Debug :: (%s) =>\n",value_name);

					list_len = 0;
					tmp = data_str;
					for (; *tmp != '\0'; tmp += strnlen(tmp,MAX_PATH)+1) {
						//printf("\t\tvalue = %s\n",tmp);
						list_len++;
					}
					///printf("\n");

					data_list = (char**)calloc(list_len, sizeof(char*));
					tmp = data_str;
					j = 0;
					//printf("list_len = %d\n",list_len);
					for (; *tmp != '\0'; tmp += strnlen(tmp, MAX_PATH) + 1) {
						
						data_list[j] = (char*)calloc(strnlen(tmp, MAX_PATH) + 1,sizeof(char));
						memcpy(data_list[j],tmp,strnlen(tmp, MAX_PATH) + 1);						
						//printf("\tvalue = %s\n",data_list[j]);
						
						j++;
					}
					
					if (section != NULL)
						a6o_conf_add_list(conf, section, value_name, data_list, list_len);


					if (data_list != NULL) {
						for (j = 0; j < list_len; j++) {
							free(data_list[j]);
							data_list[j] = NULL;
						}
						free(data_list);
						data_list = NULL;
					}

					if (data_str != NULL) {
						free(data_str);
						data_str = NULL;
					}

					break;

				default:
					//printf("[+] Debug :: value_name = %s :: value_type = %d :: data_len = %d\n",value_name,value_type,data_len );
					break;
				
			}

		}


		// Get subkeys
		subkey_maxlen++; // add null terminating character.
		subkey_name = (char *)calloc(subkey_maxlen + 1, sizeof(char));

		for (i = 0; i < nb_index; i++) {

			subkey_len = subkey_maxlen;
			res = RegEnumKeyExA(hkey, i, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
			if (res != ERROR_SUCCESS) {
				printf("[-] Error :: RegEnumKeyExA failed! :: GLE= %d\n", res);
				ret = -3;
				__leave;
			}

			printf("[+] Debug :: section = [%s]\n",subkey_name);
			//printf("[+] Debug :: sub_key_name = [%s] :: sub_key_len = %d :: class_len = %d\n",subkey_name, subkey_len,class_len);

			
			if ((res = RegOpenKeyA(hkey,subkey_name, &hSubKey)) != ERROR_SUCCESS) {
				printf("[-] Error :: RegOpenKeyA failed! :: GLE= %d\n", res);
				ret = -2;
				__leave;
			}


			registry_walker(hSubKey,subkey_name,conf);

			//printf("\n\n");

		}


		


		



	}
	__finally {

		if (subkey_name != NULL) {
			free(subkey_name);
			subkey_name = NULL;
		}

		if (value_name != NULL) {
			free(value_name);
			value_name = NULL;
		}

		if (hSubKey != NULL) {
			RegCloseKey(hSubKey);
			hSubKey = NULL;
		}

		if (data_str != NULL) {
			free(data_str);
			data_str = NULL;
		}

		if (data_list != NULL) {
			for (j = 0; j < list_len; j++) {
				free(data_list[j]);
				data_list[j] = NULL;
			}
			free(data_list);
			data_list = NULL;
		}


		

		

	}

	




	return ret;
}
Exemple #19
0
DWORD
EVTReadConfigDword(
    PEVT_CONFIG_REG pReg,
    PCSTR pszName,
    BOOLEAN bUsePolicy,
    DWORD dwMin,
    DWORD dwMax,
    PDWORD pdwValue
    )
{
    DWORD dwError = 0;

    BOOLEAN bGotValue = FALSE;
    DWORD dwValue;
    DWORD dwSize;
    DWORD dwType;

    if (bUsePolicy)
    {
        dwSize = sizeof(dwValue);
        dwError = RegGetValueA(
                    pReg->hConnection,
                    pReg->hKey,
                    pReg->pszPolicyKey,
                    pszName,
                    RRF_RT_REG_DWORD,
                    &dwType,
                    (PBYTE)&dwValue,
                    &dwSize);
        if (!dwError)
        {
            bGotValue = TRUE;
        }
    }

    if (!bGotValue)
    {
        dwSize = sizeof(dwValue);
        dwError = RegGetValueA(
                    pReg->hConnection,
                    pReg->hKey,
                    pReg->pszConfigKey,
                    pszName,
                    RRF_RT_REG_DWORD,
                    &dwType,
                    (PBYTE)&dwValue,
                    &dwSize);
        if (!dwError)
        {
            bGotValue = TRUE;
        }
    }

    if (bGotValue)
    {
        if ( dwMin <= dwValue && dwValue <= dwMax)
            *pdwValue = dwValue;
    }

    dwError = 0;

    return dwError;
}
Exemple #20
0
DWORD
EVTReadConfigString(
    PEVT_CONFIG_REG pReg,
    PCSTR   pszName,
    BOOLEAN bUsePolicy,
    PSTR    *ppszValue
    )
{
    DWORD dwError = 0;

    BOOLEAN bGotValue = FALSE;
    PSTR pszValue = NULL;
    char szValue[MAX_VALUE_LENGTH];
    DWORD dwType;
    DWORD dwSize;

    if ( bUsePolicy )
    {
        dwSize = sizeof(szValue);
        memset(szValue, 0, dwSize);
        dwError = RegGetValueA(
                    pReg->hConnection,
                    pReg->hKey,
                    pReg->pszPolicyKey,
                    pszName,
                    RRF_RT_REG_SZ,
                    &dwType,
                    szValue,
                    &dwSize);
        if (!dwError)
            bGotValue = TRUE;
    }

    if (!bGotValue )
    {
        dwSize = sizeof(szValue);
        memset(szValue, 0, dwSize);
        dwError = RegGetValueA(
                    pReg->hConnection,
                    pReg->hKey,
                    pReg->pszConfigKey,
                    pszName,
                    RRF_RT_REG_SZ,
                    &dwType,
                    szValue,
                    &dwSize);
        if (!dwError)
            bGotValue = TRUE;
    }

    if (bGotValue)
    {
        dwError = LwAllocateString(szValue, &pszValue);
        BAIL_ON_EVT_ERROR(dwError);

        LW_SAFE_FREE_STRING(*ppszValue);
        *ppszValue = pszValue;
        pszValue = NULL;
    }

    dwError = 0;

cleanup:
    LW_SAFE_FREE_STRING(pszValue);

    return dwError;

error:
    goto cleanup;
}
Exemple #21
0
// Write a Registry Key Value from an EsifData value
static eEsifError DataVault_WriteRegistry (
	DataVaultPtr self,
	esif_string keyname,
	EsifDataPtr value
	)
{
	eEsifError rc   = ESIF_E_UNSPECIFIED;
	HKEY hKey       = 0;
	DWORD dwFlags   = RRF_RT_ANY;
	DWORD dwError   = 0;
	DWORD dwSize    = 0;
	DWORD dwType    = REG_NONE;
	char *regkey    = 0;
	char *valuename = 0;
	u32 j;

	UNREFERENCED_PARAMETER(self);

	// Keyname Format: "HKLM\Subkey\Path\ValueName"
	for (j = 0; HKeyList[j].name; j++) {
		size_t namelen = esif_ccb_strlen(HKeyList[j].name, 30);
		if (esif_ccb_strnicmp(HKeyList[j].name, keyname, namelen) == 0 && keyname[namelen] == '\\') {
			hKey     = HKeyList[j].hkey;
			keyname += esif_ccb_strlen(HKeyList[j].name, 30) + 1;
			break;
		}
	}
	if (!hKey) {
		return rc;
	}

	regkey = esif_ccb_strdup(keyname);
	if ((valuename = strrchr(regkey, '\\')) == 0) {
		esif_ccb_free(regkey);
		return rc;
	}
	*valuename++ = 0;

	// Get Data Type from Registry if value already exists, otherwise deduce it from ESIF Data Type
	if ((dwError = RegGetValueA(hKey, regkey, valuename, dwFlags, &dwType, 0, 0)) != 0) {
		switch (value->type) {
		case ESIF_DATA_INT32:
		case ESIF_DATA_UINT32:
		case ESIF_DATA_TEMPERATURE:
			dwType = REG_DWORD;
			dwSize = value->data_len;
			break;

		case ESIF_DATA_INT64:
		case ESIF_DATA_UINT64:
			dwType = REG_QWORD;
			dwSize = value->data_len;
			break;

		case ESIF_DATA_STRING:
			dwType = REG_SZ;
			dwSize = value->data_len;
			break;

		case ESIF_DATA_BINARY:
		case ESIF_DATA_BLOB:
			dwType = REG_BINARY;
			dwSize = value->data_len;
			break;

		default:
			rc = ESIF_E_NOT_SUPPORTED;
			break;
		}
	}
	// Write Registry Value
	if (dwType != REG_NONE) {
		dwError = RegSetKeyValueA(hKey, regkey, valuename, dwType, value->buf_ptr, value->data_len);
		if (dwError == 0) {
			rc = ESIF_OK;
		}
	}
	esif_ccb_free(regkey);
	return rc;
}
Exemple #22
0
static
DWORD
UmnSrvUpdateAccountInfo(
    long long Now
    )
{
    DWORD dwError = 0;
    HANDLE hLsass = NULL;
    HANDLE hReg = NULL;
    HKEY hParameters = NULL;
    BOOLEAN bLocalDBOpen = FALSE;

    // Do not free
    PSTR pDisableLsassEnum = NULL;
    DWORD lastUpdated = 0;
    DWORD lastUpdatedLen = sizeof(lastUpdated);
    PLW_EVENTLOG_CONNECTION pConn = NULL;

    dwError = LwEvtOpenEventlog(
                    NULL,
                    &pConn);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = LsaOpenServer(&hLsass);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = RegOpenServer(&hReg);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = RegOpenKeyExA(
                hReg,
                NULL,
                HKEY_THIS_MACHINE "\\Services\\" SERVICE_NAME "\\Parameters",
                0,
                KEY_ALL_ACCESS,
                &hParameters);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = RegGetValueA(
                    hReg,
                    hParameters,
                    NULL,
                    "LastUpdated",
                    0,
                    NULL,
                    (PBYTE)&lastUpdated,
                    &lastUpdatedLen);
    if (dwError == LWREG_ERROR_NO_SUCH_KEY_OR_VALUE)
    {
        lastUpdated = 0;
        dwError = 0;
    }
    BAIL_ON_UMN_ERROR(dwError);

    /* processing local users/groups so disable AD user/group enumeration */
    pDisableLsassEnum = getenv("_DISABLE_LSASS_NSS_ENUMERATION");
    if (!pDisableLsassEnum || strcmp(pDisableLsassEnum, "1"))
    {
        /* Note, this code must leak memory.
         *
         * Putenv uses the memory passed to it, that it is it does not copy the
         * string. There is no Unix standard to unset an environment variable,
         * and the string passed to putenv must be accessible as long as the
         * program is running. A static string cannot be used because the
         * container could out live this service. There is no opportunity to
         * free the string before the program ends, because the variable must
         * be accessible for the duration of the program.
         */
        dwError = LwAllocateString(
                    "_DISABLE_LSASS_NSS_ENUMERATION=1",
                    &pDisableLsassEnum);
        BAIL_ON_UMN_ERROR(dwError);
        putenv(pDisableLsassEnum);
    }

    setpwent();
    setgrent();
    bLocalDBOpen = TRUE;

    dwError = UmnSrvUpdateUsers(
                    hLsass,
                    pConn,
                    hReg,
                    hParameters,
                    lastUpdated,
                    Now);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = UmnSrvUpdateGroups(
                    hLsass,
                    pConn,
                    hReg,
                    hParameters,
                    lastUpdated,
                    Now);
    BAIL_ON_UMN_ERROR(dwError);

    endpwent();
    endgrent();
    bLocalDBOpen = FALSE;

    dwError = UmnSrvUpdateADAccounts(
                    hLsass,
                    pConn,
                    hReg,
                    hParameters,
                    lastUpdated,
                    Now);
    BAIL_ON_UMN_ERROR(dwError);

    lastUpdated = Now;
    dwError = RegSetValueExA(
                    hReg,
                    hParameters,
                    "LastUpdated",
                    0,
                    REG_DWORD,
                    (PBYTE)&lastUpdated,
                    sizeof(lastUpdated));
    BAIL_ON_UMN_ERROR(dwError);

cleanup:
    if (bLocalDBOpen)
    {
        endpwent();
        endgrent();
    }
    if (hLsass)
    {
        LsaCloseServer(hLsass);
    }
    if (hReg)
    {
        RegCloseServer(hReg);
    }
    if (pConn)
    {
        LwEvtCloseEventlog(pConn);
    }
    return dwError;

error:
    goto cleanup;
}
Exemple #23
0
DWORD
UmnSrvFindDeletedUsers(
    PLW_EVENTLOG_CONNECTION pEventlog,
    HANDLE hReg,
    PCSTR pUserKeyName,
    HKEY hUsers,
    long long Now
    )
{
    DWORD dwError = 0;
    DWORD subKeyCount = 0;
    DWORD maxSubKeyLen = 0;
    DWORD subKeyLen = 0;
    DWORD i = 0;
    PSTR pKeyName = NULL;
    DWORD lastUpdated = 0;
    DWORD lastUpdatedLen = 0;
    USER_MONITOR_PASSWD old = { 0 };

    dwError = RegQueryInfoKeyA(
                    hReg,
                    hUsers,
                    NULL,
                    NULL,
                    NULL,
                    &subKeyCount,
                    &maxSubKeyLen,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL);
    BAIL_ON_UMN_ERROR(dwError);

    dwError = LwAllocateMemory(
                    maxSubKeyLen + 1,
                    (PVOID *)&pKeyName);

    for (i = 0; i < subKeyCount; i++)
    {
        if (gbPollerThreadShouldExit)
        {
            dwError = ERROR_CANCELLED;
            BAIL_ON_UMN_ERROR(dwError);
        }
        subKeyLen = maxSubKeyLen;

        dwError = RegEnumKeyExA(
                        hReg,
                        hUsers,
                        i,
                        pKeyName,
                        &subKeyLen,
                        NULL,
                        NULL,
                        NULL,
                        NULL);
        BAIL_ON_UMN_ERROR(dwError);

        pKeyName[subKeyLen] = 0;

        lastUpdatedLen = sizeof(lastUpdated);
        dwError = RegGetValueA(
                        hReg,
                        hUsers,
                        pKeyName,
                        "LastUpdated",
                        0,
                        NULL,
                        (PBYTE)&lastUpdated,
                        &lastUpdatedLen);
        if (dwError == LWREG_ERROR_NO_SUCH_KEY_OR_VALUE)
        {
            UMN_LOG_WARNING("User %s not completely written. The user monitor service may have previously terminated ungracefully.",
                        LW_SAFE_LOG_STRING(pKeyName));
            lastUpdated = 0;
            dwError = 0;
        }
        else
        {
            BAIL_ON_UMN_ERROR(dwError);
        }

        if (lastUpdated < Now)
        {
            UmnSrvFreeUserContents(&old);
            dwError = UmnSrvReadUser(
                            pUserKeyName,
                            pKeyName,
                            &old);
            BAIL_ON_UMN_ERROR(dwError);

            UMN_LOG_INFO("User '%s' deleted",
                            old.pw_name);

            dwError = RegDeleteKeyA(
                            hReg,
                            hUsers,
                            pKeyName);
            BAIL_ON_UMN_ERROR(dwError);

            if (!strcmp(pUserKeyName, "Users"))
            {
                dwError = UmnSrvWriteUserEvent(
                                pEventlog,
                                old.LastUpdated,
                                &old,
                                Now,
                                NULL);
                BAIL_ON_UMN_ERROR(dwError);
            }
            else
            {
                dwError = UmnSrvWriteADUserEvent(
                                pEventlog,
                                old.LastUpdated,
                                &old,
                                Now,
                                NULL);
                BAIL_ON_UMN_ERROR(dwError);
            }

            // Make sure we don't skip the next key since this one was deleted
            i--;
            subKeyCount--;
        }
    }

cleanup:
    UmnSrvFreeUserContents(&old);

    LW_SAFE_FREE_STRING(pKeyName);
    return dwError;

error:
    goto cleanup;
}
Exemple #24
0
static void test_registry(void)
{
    static const WCHAR keypathW[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',
        'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t','\\',0};
    static const WCHAR regsz2W[] = {'r','e','g','s','z','2',0};
    static const WCHAR regszW[] = {'r','e','g','s','z',0};
    static const WCHAR regdwordW[] = {'r','e','g','d','w','o','r','d',0};
    static const WCHAR regbinaryW[] = {'r','e','g','b','i','n','a','r','y',0};
    static const WCHAR regmultiszW[] = {'r','e','g','m','u','l','t','i','s','z',0};

    static const WCHAR regsz1W[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','\\',
        'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','T','e','s','t','\\','r','e','g','s','z','1',0};
    static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
    static const WCHAR fooW[] = {'f','o','o',0};
    static const WCHAR brokenW[] = {'H','K','E','Y','_','b','r','o','k','e','n','_','k','e','y',0};
    static const WCHAR broken2W[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R','a',0};
    WCHAR pathW[MAX_PATH];
    DWORD dwvalue, type;
    VARIANT value, v;
    IWshShell3 *sh3;
    VARTYPE vartype;
    LONG bound;
    HRESULT hr;
    BSTR name;
    HKEY root;
    LONG ret;
    UINT dim;

    hr = CoCreateInstance(&CLSID_WshShell, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
            &IID_IWshShell3, (void**)&sh3);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    /* RegRead() */
    V_VT(&value) = VT_I2;
    hr = IWshShell3_RegRead(sh3, NULL, &value);
    ok(hr == E_POINTER, "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));

    name = SysAllocString(brokenW);
    hr = IWshShell3_RegRead(sh3, name, NULL);
    ok(hr == E_POINTER, "got 0x%08x\n", hr);
    V_VT(&value) = VT_I2;
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
    SysFreeString(name);

    name = SysAllocString(broken2W);
    V_VT(&value) = VT_I2;
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
    SysFreeString(name);

    ret = RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &root);
    ok(ret == 0, "got %d\n", ret);

    ret = RegSetValueExA(root, "regsz", 0, REG_SZ, (const BYTE*)"foobar", 7);
    ok(ret == 0, "got %d\n", ret);

    ret = RegSetValueExA(root, "regsz2", 0, REG_SZ, (const BYTE*)"foobar\0f", 9);
    ok(ret == 0, "got %d\n", ret);

    ret = RegSetValueExA(root, "regmultisz", 0, REG_MULTI_SZ, (const BYTE*)"foo\0bar\0", 9);
    ok(ret == 0, "got %d\n", ret);

    dwvalue = 10;
    ret = RegSetValueExA(root, "regdword", 0, REG_DWORD, (const BYTE*)&dwvalue, sizeof(dwvalue));
    ok(ret == 0, "got %d\n", ret);

    dwvalue = 11;
    ret = RegSetValueExA(root, "regbinary", 0, REG_BINARY, (const BYTE*)&dwvalue, sizeof(dwvalue));
    ok(ret == 0, "got %d\n", ret);

    /* REG_SZ */
    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regszW);
    name = SysAllocString(pathW);
    VariantInit(&value);
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
    ok(!lstrcmpW(V_BSTR(&value), foobarW), "got %s\n", wine_dbgstr_w(V_BSTR(&value)));
    VariantClear(&value);
    SysFreeString(name);

    /* REG_SZ with embedded NULL */
    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regsz2W);
    name = SysAllocString(pathW);
    VariantInit(&value);
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_BSTR, "got %d\n", V_VT(&value));
    ok(SysStringLen(V_BSTR(&value)) == 6, "len %d\n", SysStringLen(V_BSTR(&value)));
    VariantClear(&value);
    SysFreeString(name);

    /* REG_DWORD */
    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regdwordW);
    name = SysAllocString(pathW);
    VariantInit(&value);
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_I4, "got %d\n", V_VT(&value));
    ok(V_I4(&value) == 10, "got %d\n", V_I4(&value));
    SysFreeString(name);

    /* REG_BINARY */
    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regbinaryW);
    name = SysAllocString(pathW);
    VariantInit(&value);
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&value) == (VT_ARRAY|VT_VARIANT), "got 0x%x\n", V_VT(&value));
    dim = SafeArrayGetDim(V_ARRAY(&value));
    ok(dim == 1, "got %u\n", dim);

    hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &bound);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(bound == 0, "got %u\n", bound);

    hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &bound);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(bound == 3, "got %u\n", bound);

    hr = SafeArrayGetVartype(V_ARRAY(&value), &vartype);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(vartype == VT_VARIANT, "got %d\n", vartype);

    bound = 0;
    hr = SafeArrayGetElement(V_ARRAY(&value), &bound, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&v) == VT_UI1, "got %d\n", V_VT(&v));
    ok(V_UI1(&v) == 11, "got %u\n", V_UI1(&v));
    VariantClear(&v);
    VariantClear(&value);
    SysFreeString(name);

    /* REG_MULTI_SZ */
    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regmultiszW);
    name = SysAllocString(pathW);
    VariantInit(&value);
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&value) == (VT_ARRAY|VT_VARIANT), "got 0x%x\n", V_VT(&value));
    SysFreeString(name);

    dim = SafeArrayGetDim(V_ARRAY(&value));
    ok(dim == 1, "got %u\n", dim);

    hr = SafeArrayGetLBound(V_ARRAY(&value), 1, &bound);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(bound == 0, "got %u\n", bound);

    hr = SafeArrayGetUBound(V_ARRAY(&value), 1, &bound);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(bound == 1, "got %u\n", bound);

    hr = SafeArrayGetVartype(V_ARRAY(&value), &vartype);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(vartype == VT_VARIANT, "got %d\n", vartype);

    bound = 0;
    hr = SafeArrayGetElement(V_ARRAY(&value), &bound, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
    ok(!lstrcmpW(V_BSTR(&v), fooW), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
    VariantClear(&v);
    VariantClear(&value);

    name = SysAllocString(regsz1W);
    V_VT(&value) = VT_I2;
    hr = IWshShell3_RegRead(sh3, name, &value);
    ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
    ok(V_VT(&value) == VT_I2, "got %d\n", V_VT(&value));
    VariantClear(&value);
    SysFreeString(name);

    delete_key(root);

    /* RegWrite() */
    ret = RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &root);
    ok(ret == 0, "got %d\n", ret);

    hr = IWshShell3_RegWrite(sh3, NULL, NULL, NULL);
    ok(hr == E_POINTER, "got 0x%08x\n", hr);

    lstrcpyW(pathW, keypathW);
    lstrcatW(pathW, regszW);
    name = SysAllocString(pathW);

    hr = IWshShell3_RegWrite(sh3, name, NULL, NULL);
    ok(hr == E_POINTER, "got 0x%08x\n", hr);

    VariantInit(&value);
    hr = IWshShell3_RegWrite(sh3, name, &value, NULL);
    ok(hr == E_POINTER, "got 0x%08x\n", hr);

    hr = IWshShell3_RegWrite(sh3, name, &value, &value);
    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);

    /* type is optional */
    V_VT(&v) = VT_ERROR;
    V_ERROR(&v) = DISP_E_PARAMNOTFOUND;
    hr = IWshShell3_RegWrite(sh3, name, &value, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    /* default type is REG_SZ */
    V_VT(&value) = VT_I4;
    V_I4(&value) = 12;
    hr = IWshShell3_RegWrite(sh3, name, &value, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    type = REG_NONE;
    ret = RegGetValueA(root, NULL, "regsz", RRF_RT_ANY, &type, NULL, NULL);
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    ok(type == REG_SZ, "got %d\n", type);

    ret = RegDeleteValueA(root, "regsz");
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    V_VT(&value) = VT_BSTR;
    V_BSTR(&value) = SysAllocString(regszW);
    hr = IWshShell3_RegWrite(sh3, name, &value, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    VariantClear(&value);

    type = REG_NONE;
    ret = RegGetValueA(root, NULL, "regsz", RRF_RT_ANY, &type, NULL, NULL);
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    ok(type == REG_SZ, "got %d\n", type);

    ret = RegDeleteValueA(root, "regsz");
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    V_VT(&value) = VT_R4;
    V_R4(&value) = 1.2;
    hr = IWshShell3_RegWrite(sh3, name, &value, &v);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    VariantClear(&value);

    type = REG_NONE;
    ret = RegGetValueA(root, NULL, "regsz", RRF_RT_ANY, &type, NULL, NULL);
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    ok(type == REG_SZ, "got %d\n", type);

    ret = RegDeleteValueA(root, "regsz");
    ok(ret == ERROR_SUCCESS, "got %d\n", ret);
    V_VT(&value) = VT_R4;
    V_R4(&value) = 1.2;
    V_VT(&v) = VT_I2;
    V_I2(&v) = 1;
    hr = IWshShell3_RegWrite(sh3, name, &value, &v);
    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
    VariantClear(&value);

    SysFreeString(name);

    delete_key(root);
    IWshShell3_Release(sh3);
}