void WinRegistryKey::deleteKey() { Keys keys; subKeys(keys); close(); for (Keys::iterator it = keys.begin(); it != keys.end(); ++it) { string subKey(_subKey); subKey += "\\"; subKey += *it; WinRegistryKey subRegKey(_hRootKey, subKey); subRegKey.deleteKey(); } // NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later. // We cannot call it directly as this would prevent the code running on Windows XP 32-bit. // Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for // its existence in ADVAPI32.DLL and call it indirectly. typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved); if (_extraSam != 0) { AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL")); if (advAPI32.handle()) { RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA")); if (pRegDeleteKeyExA) { (*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0); return; } } } RegDeleteKey(_hRootKey, _subKey.c_str()); }
void WinRegistryKey::deleteKey() { Keys keys; subKeys(keys); close(); for (Keys::iterator it = keys.begin(); it != keys.end(); ++it) { std::string subKey(_subKey); subKey += "\\"; subKey += *it; WinRegistryKey subRegKey(_hRootKey, subKey); subRegKey.deleteKey(); } // NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later. // We cannot call it directly as this would prevent the code running on Windows XP 32-bit. // Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for // its existence in ADVAPI32.DLL and call it indirectly. #if defined(POCO_WIN32_UTF8) std::wstring usubKey; Poco::UnicodeConverter::toUTF16(_subKey, usubKey); typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved); if (_extraSam != 0) { AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL")); if (advAPI32.handle()) { RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW")); if (pRegDeleteKeyExW) { if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS) throw NotFoundException(key()); return; } } } if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #else typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved); if (_extraSam != 0) { AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL")); if (advAPI32.handle()) { RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA")); if (pRegDeleteKeyExA) { if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS) throw NotFoundException(key()); return; } } } if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #endif }
/*! Removes a QMailFolder with QMailFolderId \a id from the message store. Also removes any sub-folders of the identified folder, and any messages contained in any of the folders removed. If \a option is QMailStore::CreateRemovalRecord then removal records will be created for each removed message. Returns \c true if the operation completed successfully, \c false otherwise. */ bool QMailStore::removeFolder(const QMailFolderId& id, QMailStore::MessageRemovalOption option) { // Remove the identified folder and any sub-folders QMailFolderKey idKey(QMailFolderKey::id(id)); QMailFolderKey subKey(QMailFolderKey::ancestorFolderIds(id, QMailDataComparator::Includes)); return removeFolders(idKey | subKey, option); }
//get device driver name static QString getNativeDriver(const QString &service) { QString result; QString subKey("SYSTEM\\CurrentControlSet\\services\\"); subKey.append(service); ::HKEY key; ::LONG res = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, reinterpret_cast<const wchar_t *>(subKey.utf16()), 0, KEY_QUERY_VALUE, &key); if (ERROR_SUCCESS == res) { DWORD dataType = 0; DWORD dataSize = 0; subKey = "ImagePath"; res = ::RegQueryValueEx(key, reinterpret_cast<const wchar_t *>(subKey.utf16()), 0, &dataType, 0, &dataSize); if (ERROR_SUCCESS == res) { QByteArray data(dataSize, 0); res = ::RegQueryValueEx(key, reinterpret_cast<const wchar_t *>(subKey.utf16()), 0, 0, reinterpret_cast<unsigned char*>(data.data()), &dataSize); if (ERROR_SUCCESS == res) { switch (dataType) { case REG_EXPAND_SZ: case REG_SZ: { if (dataSize) { result = QString::fromWCharArray(((const wchar_t *)data.constData())); } break; } default: ; } } } ::RegCloseKey(key); } return result; }
std::vector<Key> Key::subKeys() const { std::vector<Key> rval; int num = numSubKeys(); for (int i = 0; i < num; i++) { rval.push_back( subKey( i ) ); } return rval; }
bool RegistrySettingsManager::setBinaryData(const TCHAR *name, const void *value, size_t size) { StringStorage keyName; StringStorage valueName; extractKeyName(name, &keyName); extractValueName(name, &valueName); RegistryKey subKey(m_key, keyName.getString(), false); return subKey.setValueAsBinary(name, value, size); }
bool RegistrySettingsManager::setInt(const TCHAR *name, int value) { StringStorage keyName; StringStorage valueName; extractKeyName(name, &keyName); extractValueName(name, &valueName); RegistryKey subKey(m_key, keyName.getString(), false); return subKey.setValueAsInt32(name, value); }
bool RegistrySettingsManager::getLong(const TCHAR *name, long *value) { StringStorage keyName; StringStorage valueName; extractKeyName(name, &keyName); extractValueName(name, &valueName); RegistryKey subKey(m_key, keyName.getString(), false); return subKey.getValueAsInt64(valueName.getString(), value); }
bool RegistrySettingsManager::deleteKey(const TCHAR *name) { StringStorage keyName; StringStorage valueName; extractKeyName(name, &keyName); extractValueName(name, &valueName); RegistryKey subKey(m_key, keyName.getString(), false); bool deleteAsSubKey = m_key->deleteSubKeyTree(valueName.getString()); bool deleteAsValue = subKey.deleteValue(valueName.getString()); return deleteAsSubKey || deleteAsValue; }
void XmlBlasterCommObject::subscribe(const std::string& key, SubscriptionType subType) { /* Minimal constructor */ SubscribeKey subKey(global_); /* * Subscribe key. By invoking setOid you implicitly choose the 'EXACT' mode. * If you want to subscribe with XPATH use setQueryString instead */ if (subType == XPATH) { subKey.setQueryString(key); } else if (subType == MESSAGE) { subKey.setOid(key); } else { log_.error(ME, "unknown subsription type: " + subType); } SubscribeQos subQos(global_); log_.info(ME, "subscribing to xmlBlaster with key: \"" + subKey.toXml() + "\""); SubscribeReturnQos subRetQos = con.subscribe(subKey, subQos); log_.info(ME, "successfully subscribed to xmlBlaster"); };
void WinRegistryKey::deleteKey() { Keys keys; subKeys(keys); close(); for (Keys::iterator it = keys.begin(); it != keys.end(); ++it) { std::string subKey(_subKey); subKey += "\\"; subKey += *it; WinRegistryKey subRegKey(_hRootKey, subKey); subRegKey.deleteKey(); } #if defined(POCO_WIN32_UTF8) std::wstring usubKey; Poco::UnicodeConverter::toUTF16(_subKey, usubKey); if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #else if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS) throw NotFoundException(key()); #endif }
bool RegistrySettingsManager::keyExist(const TCHAR *name) { if (!isOk()) return false; RegistryKey subKey(m_key, name, false); return subKey.isOpened(); }
/** * Verifies if the file path matches any certificate stored in the registry. * * @param filePath The file path of the application to check if allowed. * @param allowFallbackKeySkip when this is TRUE the fallback registry key will * be used to skip the certificate check. This is the default since the * fallback registry key is located under HKEY_LOCAL_MACHINE which can't be * written to by a low integrity process. * Note: the maintenance service binary can be used to perform this check for * testing or troubleshooting. * @return TRUE if the binary matches any of the allowed certificates. */ BOOL DoesBinaryMatchAllowedCertificates(LPCWSTR basePathForUpdate, LPCWSTR filePath, BOOL allowFallbackKeySkip) { WCHAR maintenanceServiceKey[MAX_PATH + 1]; if (!CalculateRegistryPathFromFilePath(basePathForUpdate, maintenanceServiceKey)) { return FALSE; } // We use KEY_WOW64_64KEY to always force 64-bit view. // The user may have both x86 and x64 applications installed // which each register information. We need a consistent place // to put those certificate attributes in and hence why we always // force the non redirected registry under Wow6432Node. // This flag is ignored on 32bit systems. HKEY baseKeyRaw; LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, maintenanceServiceKey, 0, KEY_READ | KEY_WOW64_64KEY, &baseKeyRaw); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not open key. (%d)", retCode)); // Our tests run with a different apply directory for each test. // We use this registry key on our test slaves to store the // allowed name/issuers. retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, TEST_ONLY_FALLBACK_KEY_PATH, 0, KEY_READ | KEY_WOW64_64KEY, &baseKeyRaw); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not open fallback key. (%d)", retCode)); return FALSE; } else if (allowFallbackKeySkip) { LOG_WARN(("Fallback key present, skipping VerifyCertificateTrustForFile " "check and the certificate attribute registry matching " "check.")); return TRUE; } } nsAutoRegKey baseKey(baseKeyRaw); // Get the number of subkeys. DWORD subkeyCount = 0; retCode = RegQueryInfoKeyW(baseKey, nullptr, nullptr, nullptr, &subkeyCount, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not query info key. (%d)", retCode)); return FALSE; } // Enumerate the subkeys, each subkey represents an allowed certificate. for (DWORD i = 0; i < subkeyCount; i++) { WCHAR subkeyBuffer[MAX_KEY_LENGTH]; DWORD subkeyBufferCount = MAX_KEY_LENGTH; retCode = RegEnumKeyExW(baseKey, i, subkeyBuffer, &subkeyBufferCount, nullptr, nullptr, nullptr, nullptr); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not enum certs. (%d)", retCode)); return FALSE; } // Open the subkey for the current certificate HKEY subKeyRaw; retCode = RegOpenKeyExW(baseKey, subkeyBuffer, 0, KEY_READ | KEY_WOW64_64KEY, &subKeyRaw); nsAutoRegKey subKey(subKeyRaw); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not open subkey. (%d)", retCode)); continue; // Try the next subkey } const int MAX_CHAR_COUNT = 256; DWORD valueBufSize = MAX_CHAR_COUNT * sizeof(WCHAR); WCHAR name[MAX_CHAR_COUNT] = { L'\0' }; WCHAR issuer[MAX_CHAR_COUNT] = { L'\0' }; // Get the name from the registry retCode = RegQueryValueExW(subKey, L"name", 0, nullptr, (LPBYTE)name, &valueBufSize); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not obtain name from registry. (%d)", retCode)); continue; // Try the next subkey } // Get the issuer from the registry valueBufSize = MAX_CHAR_COUNT * sizeof(WCHAR); retCode = RegQueryValueExW(subKey, L"issuer", 0, nullptr, (LPBYTE)issuer, &valueBufSize); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Could not obtain issuer from registry. (%d)", retCode)); continue; // Try the next subkey } CertificateCheckInfo allowedCertificate = { name, issuer, }; retCode = CheckCertificateForPEFile(filePath, allowedCertificate); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Error on certificate check. (%d)", retCode)); continue; // Try the next subkey } retCode = VerifyCertificateTrustForFile(filePath); if (retCode != ERROR_SUCCESS) { LOG_WARN(("Error on certificate trust check. (%d)", retCode)); continue; // Try the next subkey } // Raise the roof, we found a match! return TRUE; } // No certificates match, :'( return FALSE; }
// Explore the registry to find a suitable version of Java. // Returns an int which is the version of Java found (e.g. 1006 for 1.6) and the // matching path in outJavaPath. // Returns 0 if nothing suitable was found. static int exploreJavaRegistry(const char *entry, REGSAM access, CPath *outJavaPath) { // Let's visit HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment [CurrentVersion] CPath rootKey("SOFTWARE\\JavaSoft\\"); rootKey.addPath(entry); int versionInt = 0; CString currentVersion; CPath subKey(rootKey); if (getRegValue(subKey.cstr(), "CurrentVersion", access, ¤tVersion)) { // CurrentVersion should be something like "1.7". // We want to read HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.7 [JavaHome] subKey.addPath(currentVersion); CPath javaHome; if (getRegValue(subKey.cstr(), "JavaHome", access, &javaHome)) { versionInt = checkBinPath(&javaHome); if (versionInt >= 0) { if (gIsDebug) { fprintf(stderr, "Java %d found via registry: %s\n", versionInt, javaHome.cstr()); } *outJavaPath = javaHome; } if (versionInt >= MIN_JAVA_VERSION) { // Heuristic: if the current version is good enough, stop here return versionInt; } } } // Try again, but this time look at all the versions available HKEY javaHomeKey; LSTATUS status = RegOpenKeyExA( HKEY_LOCAL_MACHINE, // hKey "SOFTWARE\\JavaSoft", // lpSubKey 0, // ulOptions KEY_READ | access, // samDesired &javaHomeKey); // phkResult if (status == ERROR_SUCCESS) { char name[256]; DWORD index = 0; CPath javaHome; for (LONG result = ERROR_SUCCESS; result == ERROR_SUCCESS; index++) { DWORD nameLen = 255; name[nameLen] = 0; result = RegEnumKeyExA( javaHomeKey, // hKey index, // dwIndex name, // lpName &nameLen, // lpcName NULL, // lpReserved NULL, // lpClass NULL, // lpcClass, NULL); // lpftLastWriteTime if (result == ERROR_SUCCESS && nameLen < 256) { name[nameLen] = 0; CPath subKey(rootKey); subKey.addPath(name); if (getRegValue(subKey.cstr(), "JavaHome", access, &javaHome)) { int v = checkBinPath(&javaHome); if (v > versionInt) { if (gIsDebug) { fprintf(stderr, "Java %d found via registry: %s\n", versionInt, javaHome.cstr()); } *outJavaPath = javaHome; versionInt = v; } } } } RegCloseKey(javaHomeKey); } return 0; }