From 3abb8e63bfc79eb0bfb21b7fd8430b19fbddaec5 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Tue, 31 May 2005 09:31:49 +0000 Subject: [PATCH] - implement Crypt{Get|Set}OIDFunctionValue - fix bug and memory leak in last patch --- dlls/crypt32/crypt32.spec | 2 +- dlls/crypt32/encode.c | 77 ++++++++++++++++++++++++++++++++++++++- dlls/crypt32/main.c | 10 ----- 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/dlls/crypt32/crypt32.spec b/dlls/crypt32/crypt32.spec index 69061a0b348..11fdc1818b9 100644 --- a/dlls/crypt32/crypt32.spec +++ b/dlls/crypt32/crypt32.spec @@ -143,7 +143,7 @@ @ stdcall CryptSIPRemoveProvider(ptr) @ stdcall CryptSIPRetrieveSubjectGuid(wstr long ptr) @ stub CryptSetAsyncParam -@ stub CryptSetOIDFunctionValue +@ stdcall CryptSetOIDFunctionValue(long str str wstr long ptr long) @ stub CryptSetProviderU @ stub CryptSignAndEncodeCertificate @ stub CryptSignAndEncryptMessage diff --git a/dlls/crypt32/encode.c b/dlls/crypt32/encode.c index ecb3b4a5e49..9439782065d 100644 --- a/dlls/crypt32/encode.c +++ b/dlls/crypt32/encode.c @@ -132,11 +132,86 @@ BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey); - if (!rc) + HeapFree(GetProcessHeap(), 0, szKey); + if (rc) SetLastError(rc); return rc ? FALSE : TRUE; } +BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, + LPCSTR pszOID, LPCWSTR pwszValueName, DWORD *pdwValueType, BYTE *pbValueData, + DWORD *pcbValueData) +{ + LPSTR szKey; + LONG rc; + HKEY hKey; + + TRACE("%lx %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName), + debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData, + pcbValueData); + + if (!GET_CERT_ENCODING_TYPE(dwEncodingType)) + return TRUE; + + if (!pszFuncName || !pszOID || !pwszValueName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); + rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); + HeapFree(GetProcessHeap(), 0, szKey); + if (rc) + SetLastError(rc); + else + { + rc = RegQueryValueExW(hKey, pwszValueName, NULL, pdwValueType, + pbValueData, pcbValueData); + if (rc) + SetLastError(rc); + RegCloseKey(hKey); + } + return rc ? FALSE : TRUE; +} + +BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, + LPCSTR pszOID, LPCWSTR pwszValueName, DWORD dwValueType, + const BYTE *pbValueData, DWORD cbValueData) +{ + LPSTR szKey; + LONG rc; + HKEY hKey; + + TRACE("%lx %s %s %s %ld %p %ld\n", dwEncodingType, debugstr_a(pszFuncName), + debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData, + cbValueData); + + if (!GET_CERT_ENCODING_TYPE(dwEncodingType)) + return TRUE; + + if (!pszFuncName || !pszOID || !pwszValueName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); + rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); + HeapFree(GetProcessHeap(), 0, szKey); + if (rc) + SetLastError(rc); + else + { + rc = RegSetValueExW(hKey, pwszValueName, 0, dwValueType, pbValueData, + cbValueData); + if (rc) + SetLastError(rc); + RegCloseKey(hKey); + } + return rc ? FALSE : TRUE; +} + /* Gets the registered function named szFuncName for dwCertEncodingType and * lpszStructType, or NULL if one could not be found. *lib will be set to the * handle of the module it's in, or NULL if no module was loaded. If the diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c index 3041c4eb247..32df7475d02 100644 --- a/dlls/crypt32/main.c +++ b/dlls/crypt32/main.c @@ -183,16 +183,6 @@ BOOL WINAPI CryptSIPLoad return FALSE; } -BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, - LPCSTR pszOID, LPCWSTR pwszValueName, - DWORD *pdwValueType, BYTE *pbValueData, - DWORD *pcbValueData) -{ - FIXME("(%lx,%s,%s,%s,%p,%p,%p) stub!\n", dwEncodingType, pszFuncName, pszOID, - debugstr_w(pwszValueName), pdwValueType, pbValueData, pcbValueData); - return FALSE; -} - BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)