* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
+#include "config.h"
+#include "wine/port.h"
+
#include <stdio.h>
#include <stdarg.h>
#define NONAMELESSUNION
static const WCHAR DllW[] = { 'D','l','l',0 };
-static void init_function_sets(void);
-static void init_oid_info(HINSTANCE hinst);
+static void init_oid_info(void);
static void free_function_sets(void);
static void free_oid_info(void);
-void crypt_oid_init(HINSTANCE hinst)
+void crypt_oid_init(void)
{
- init_function_sets();
- init_oid_info(hinst);
+ init_oid_info();
}
void crypt_oid_free(void)
}
static CRITICAL_SECTION funcSetCS;
-static struct list funcSets;
+static CRITICAL_SECTION_DEBUG funcSetCSDebug =
+{
+ 0, 0, &funcSetCS,
+ { &funcSetCSDebug.ProcessLocksList, &funcSetCSDebug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": funcSetCS") }
+};
+static CRITICAL_SECTION funcSetCS = { &funcSetCSDebug, -1, 0, 0, 0, 0 };
+static struct list funcSets = { &funcSets, &funcSets };
struct OIDFunctionSet
{
struct list next;
};
-static void init_function_sets(void)
-{
- InitializeCriticalSection(&funcSetCS);
- list_init(&funcSets);
-}
+static const WCHAR ROOT[] = {'R','O','O','T',0};
+static const WCHAR MY[] = {'M','Y',0};
+static const WCHAR CA[] = {'C','A',0};
+static const WCHAR ADDRESSBOOK[] = {'A','D','D','R','E','S','S','B','O','O','K',0};
+static const WCHAR TRUSTEDPUBLISHER[] = {'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r',0};
+static const WCHAR DISALLOWED[] = {'D','i','s','a','l','l','o','w','e','d',0};
+static const LPCWSTR LocalizedKeys[] = {ROOT,MY,CA,ADDRESSBOOK,TRUSTEDPUBLISHER,DISALLOWED};
+static WCHAR LocalizedNames[sizeof(LocalizedKeys)/sizeof(LocalizedKeys[0])][256];
static void free_function_sets(void)
{
list_remove(&functionCursor->next);
CryptMemFree(functionCursor);
}
+ setCursor->cs.DebugInfo->Spare[0] = 0;
DeleteCriticalSection(&setCursor->cs);
CryptMemFree(setCursor);
}
- DeleteCriticalSection(&funcSetCS);
}
/* There is no free function associated with this; therefore, the sets are
{
struct OIDFunctionSet *cursor, *ret = NULL;
- TRACE("(%s, %lx)\n", debugstr_a(pszFuncName), dwFlags);
+ TRACE("(%s, %x)\n", debugstr_a(pszFuncName), dwFlags);
EnterCriticalSection(&funcSetCS);
LIST_FOR_EACH_ENTRY(cursor, &funcSets, struct OIDFunctionSet, next)
{
if (!strcasecmp(pszFuncName, cursor->name))
{
- ret = (HCRYPTOIDFUNCSET)cursor;
+ ret = cursor;
break;
}
}
if (ret->name)
{
InitializeCriticalSection(&ret->cs);
+ ret->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": OIDFunctionSet.cs");
list_init(&ret->functions);
strcpy(ret->name, pszFuncName);
list_add_tail(&funcSets, &ret->next);
}
LeaveCriticalSection(&funcSetCS);
- return (HCRYPTOIDFUNCSET)ret;
+ return ret;
}
static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID)
{
static const char szEncodingTypeFmt[] =
- "Software\\Microsoft\\Cryptography\\OID\\EncodingType %ld\\%s\\%s";
+ "Software\\Microsoft\\Cryptography\\OID\\EncodingType %d\\%s\\%s";
UINT len;
char numericOID[7]; /* enough for "#65535" */
const char *oid;
len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
szKey = CryptMemAlloc(len);
if (szKey)
- sprintf(szKey, szEncodingTypeFmt, dwEncodingType, pszFuncName, oid);
+ sprintf(szKey, szEncodingTypeFmt,
+ GET_CERT_ENCODING_TYPE(dwEncodingType), pszFuncName, oid);
return szKey;
}
DWORD dwEncodingType, LPWSTR pwszDllList, DWORD *pcchDllList)
{
BOOL ret = TRUE;
- struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
+ struct OIDFunctionSet *set = hFuncSet;
char *keyName;
HKEY key;
- long rc;
+ LSTATUS rc;
- TRACE("(%p, %ld, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
+ TRACE("(%p, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
pcchDllList);
keyName = CRYPT_GetKeyName(dwEncodingType, set->name, "DEFAULT");
else
{
/* No value, return an empty list */
- if (*pcchDllList)
+ if (pwszDllList && *pcchDllList)
*pwszDllList = '\0';
*pcchDllList = 1;
}
}
else
{
- SetLastError(rc);
- ret = FALSE;
+ /* No value, return an empty list */
+ if (pwszDllList && *pcchDllList)
+ *pwszDllList = '\0';
+ *pcchDllList = 1;
}
CryptMemFree(keyName);
BOOL ret = TRUE;
struct OIDFunctionSet *set;
- TRACE("(%p, %ld, %s, %ld, %p, %08lx)\n", hModule, dwEncodingType,
+ TRACE("(%p, %d, %s, %d, %p, %08x)\n", hModule, dwEncodingType,
debugstr_a(pszFuncName), cFuncEntry, rgFuncEntry, dwFlags);
- set = (struct OIDFunctionSet *)CryptInitOIDFunctionSet(pszFuncName, 0);
+ set = CryptInitOIDFunctionSet(pszFuncName, 0);
if (set)
{
DWORD i;
func = CryptMemAlloc(sizeof(struct OIDFunction));
if (func)
{
- func->encoding = dwEncodingType;
+ func->encoding = GET_CERT_ENCODING_TYPE(dwEncodingType);
if (HIWORD(rgFuncEntry[i].pszOID))
{
- func->entry.pszOID = (LPSTR)((LPBYTE)func + sizeof(*func));
- strcpy((LPSTR)func->entry.pszOID, rgFuncEntry[i].pszOID);
+ LPSTR oid;
+
+ oid = (LPSTR)((LPBYTE)func + sizeof(*func));
+ strcpy(oid, rgFuncEntry[i].pszOID);
+ func->entry.pszOID = oid;
}
else
func->entry.pszOID = rgFuncEntry[i].pszOID;
return ret;
}
+struct FuncAddr
+{
+ HMODULE lib;
+ LPWSTR dllList;
+ LPWSTR currentDll;
+};
+
static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
{
char *keyName;
const char *funcName;
HKEY key;
- long rc;
+ LSTATUS rc;
keyName = CRYPT_GetKeyName(dwEncodingType, szFuncName, pszOID);
rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &key);
DWORD type, size = 0;
rc = RegQueryValueExA(key, "FuncName", NULL, &type, NULL, &size);
- if (rc == ERROR_MORE_DATA && type == REG_SZ)
+ if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
{
funcName = CryptMemAlloc(size);
rc = RegQueryValueExA(key, "FuncName", NULL, &type,
else
funcName = szFuncName;
rc = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
- if (rc == ERROR_MORE_DATA && type == REG_SZ)
+ if ((!rc || rc == ERROR_MORE_DATA) && type == REG_SZ)
{
LPWSTR dllName = CryptMemAlloc(size);
lib = LoadLibraryW(dllName);
if (lib)
{
- *ppvFuncAddr = GetProcAddress(lib, szFuncName);
+ *ppvFuncAddr = GetProcAddress(lib, funcName);
if (*ppvFuncAddr)
{
- *phFuncAddr = (HCRYPTOIDFUNCADDR)lib;
- ret = TRUE;
+ struct FuncAddr *addr =
+ CryptMemAlloc(sizeof(struct FuncAddr));
+
+ if (addr)
+ {
+ addr->lib = lib;
+ addr->dllList = addr->currentDll = NULL;
+ *phFuncAddr = addr;
+ ret = TRUE;
+ }
+ else
+ {
+ *phFuncAddr = NULL;
+ FreeLibrary(lib);
+ }
}
else
{
HCRYPTOIDFUNCADDR *phFuncAddr)
{
BOOL ret = FALSE;
- struct OIDFunctionSet *set = (struct OIDFunctionSet *)hFuncSet;
+ struct OIDFunctionSet *set = hFuncSet;
- TRACE("(%p, %ld, %s, %08lx, %p, %p)\n", hFuncSet, dwEncodingType,
+ TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
*ppvFuncAddr = NULL;
EnterCriticalSection(&set->cs);
LIST_FOR_EACH_ENTRY(function, &set->functions, struct OIDFunction, next)
{
- if (function->encoding == dwEncodingType)
+ if (function->encoding == GET_CERT_ENCODING_TYPE(dwEncodingType))
{
if (HIWORD(pszOID))
{
- if (HIWORD(function->entry.pszOID &&
- !strcasecmp(function->entry.pszOID, pszOID)))
+ if (HIWORD(function->entry.pszOID) &&
+ !strcasecmp(function->entry.pszOID, pszOID))
{
*ppvFuncAddr = function->entry.pvFuncAddr;
*phFuncAddr = NULL; /* FIXME: what should it be? */
if (!*ppvFuncAddr)
ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
ppvFuncAddr, phFuncAddr);
+ TRACE("returning %d\n", ret);
return ret;
}
BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
DWORD dwFlags)
{
- TRACE("(%p, %08lx)\n", hFuncAddr, dwFlags);
+ TRACE("(%p, %08x)\n", hFuncAddr, dwFlags);
/* FIXME: as MSDN states, need to check for DllCanUnloadNow in the DLL,
* and only unload it if it can be unloaded. Also need to implement ref
* counting on the functions.
*/
- FreeLibrary((HMODULE)hFuncAddr);
+ if (hFuncAddr)
+ {
+ struct FuncAddr *addr = hFuncAddr;
+
+ CryptMemFree(addr->dllList);
+ FreeLibrary(addr->lib);
+ CryptMemFree(addr);
+ }
return TRUE;
}
-BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
- LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
+static BOOL CRYPT_GetFuncFromDll(LPCWSTR dll, LPCSTR func, HMODULE *lib,
+ void **ppvFuncAddr)
{
- FIXME("(%lx,%s,%lx,%s) stub!\n", dwEncodingType, pszFuncName, dwIndex,
- debugstr_w(pwszDll));
- return FALSE;
-}
+ BOOL ret = FALSE;
-BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
- LPCSTR pszFuncName, LPCWSTR pwszDll)
-{
- FIXME("(%lx %s %s): stub\n", dwEncodingType, debugstr_a(pszFuncName),
- debugstr_w(pwszDll));
- return FALSE;
+ *lib = LoadLibraryW(dll);
+ if (*lib)
+ {
+ *ppvFuncAddr = GetProcAddress(*lib, func);
+ if (*ppvFuncAddr)
+ ret = TRUE;
+ else
+ {
+ FreeLibrary(*lib);
+ *lib = NULL;
+ }
+ }
+ return ret;
}
BOOL WINAPI CryptGetDefaultOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet,
- DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void *ppvFuncAddr,
+ DWORD dwEncodingType, LPCWSTR pwszDll, DWORD dwFlags, void **ppvFuncAddr,
HCRYPTOIDFUNCADDR *phFuncAddr)
{
- FIXME("(%p, %ld, %s, %08lx, %p, %p): stub\n", hFuncSet, dwEncodingType,
+ struct OIDFunctionSet *set = hFuncSet;
+ BOOL ret = FALSE;
+
+ TRACE("(%p, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
debugstr_w(pwszDll), dwFlags, ppvFuncAddr, phFuncAddr);
- return FALSE;
+
+ if (pwszDll)
+ {
+ HMODULE lib;
+
+ *phFuncAddr = NULL;
+ ret = CRYPT_GetFuncFromDll(pwszDll, set->name, &lib, ppvFuncAddr);
+ if (ret)
+ {
+ struct FuncAddr *addr = CryptMemAlloc(sizeof(struct FuncAddr));
+
+ if (addr)
+ {
+ addr->lib = lib;
+ addr->dllList = addr->currentDll = NULL;
+ *phFuncAddr = addr;
+ }
+ else
+ {
+ FreeLibrary(lib);
+ *ppvFuncAddr = NULL;
+ SetLastError(ERROR_OUTOFMEMORY);
+ ret = FALSE;
+ }
+ }
+ else
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ }
+ else
+ {
+ struct FuncAddr *addr = *phFuncAddr;
+
+ if (!addr)
+ {
+ DWORD size;
+
+ ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType, NULL,
+ &size);
+ if (ret)
+ {
+ LPWSTR dllList = CryptMemAlloc(size * sizeof(WCHAR));
+
+ if (dllList)
+ {
+ ret = CryptGetDefaultOIDDllList(hFuncSet, dwEncodingType,
+ dllList, &size);
+ if (ret)
+ {
+ addr = CryptMemAlloc(sizeof(struct FuncAddr));
+ if (addr)
+ {
+ addr->dllList = dllList;
+ addr->currentDll = dllList;
+ addr->lib = NULL;
+ *phFuncAddr = addr;
+ }
+ else
+ {
+ CryptMemFree(dllList);
+ SetLastError(ERROR_OUTOFMEMORY);
+ ret = FALSE;
+ }
+ }
+ }
+ else
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ ret = FALSE;
+ }
+ }
+ }
+ if (addr)
+ {
+ if (!*addr->currentDll)
+ {
+ CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ *phFuncAddr = NULL;
+ ret = FALSE;
+ }
+ else
+ {
+ /* FIXME: as elsewhere, can't free until DllCanUnloadNow says
+ * it's possible, and should defer unloading for some time to
+ * avoid repeated LoadLibrary/FreeLibrary on the same dll.
+ */
+ FreeLibrary(addr->lib);
+ ret = CRYPT_GetFuncFromDll(addr->currentDll, set->name,
+ &addr->lib, ppvFuncAddr);
+ if (ret)
+ {
+ /* Move past the current DLL */
+ addr->currentDll += lstrlenW(addr->currentDll) + 1;
+ *phFuncAddr = addr;
+ }
+ else
+ {
+ CryptFreeOIDFunctionAddress(*phFuncAddr, 0);
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ *phFuncAddr = NULL;
+ }
+ }
+ }
+ }
+ return ret;
}
+/***********************************************************************
+ * CryptRegisterOIDFunction (CRYPT32.@)
+ *
+ * Register the DLL and the functions it uses to cover the combination
+ * of encoding type, functionname and OID.
+ *
+ * PARAMS
+ * dwEncodingType [I] Encoding type to be used.
+ * pszFuncName [I] Name of the function to be registered.
+ * pszOID [I] OID of the function (numeric or string).
+ * pwszDll [I] The DLL that is to be registered.
+ * pszOverrideFuncName [I] Name of the function in the DLL.
+ *
+ * RETURNS
+ * Success: TRUE.
+ * Failure: FALSE. (Look at GetLastError()).
+ *
+ * NOTES
+ * Registry errors are always reported via SetLastError().
+ */
BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
{
HKEY hKey;
LPSTR szKey;
- TRACE("(%lx, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName, pszOID,
- debugstr_w(pwszDll), pszOverrideFuncName);
-
- /* This only registers functions for encoding certs, not messages */
- if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
- return TRUE;
+ TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName,
+ debugstr_a(pszOID), debugstr_w(pwszDll), pszOverrideFuncName);
/* Native does nothing pwszDll is NULL */
if (!pwszDll)
r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
CryptMemFree(szKey);
- if(r != ERROR_SUCCESS)
- return FALSE;
+
+ if (r != ERROR_SUCCESS) goto error_close_key;
/* write the values */
if (pszOverrideFuncName)
- RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
- (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
- RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
- (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
+ {
+ r = RegSetValueExA(hKey, "FuncName", 0, REG_SZ,
+ (const BYTE*)pszOverrideFuncName, lstrlenA(pszOverrideFuncName) + 1);
+ if (r != ERROR_SUCCESS) goto error_close_key;
+ }
+ r = RegSetValueExW(hKey, DllW, 0, REG_SZ, (const BYTE*) pwszDll,
+ (lstrlenW(pwszDll) + 1) * sizeof (WCHAR));
+
+error_close_key:
RegCloseKey(hKey);
+
+ if (r != ERROR_SUCCESS)
+ {
+ SetLastError(r);
+ return FALSE;
+ }
+
return TRUE;
}
+/***********************************************************************
+ * CryptRegisterOIDInfo (CRYPT32.@)
+ */
+BOOL WINAPI CryptRegisterOIDInfo(PCCRYPT_OID_INFO pInfo, DWORD dwFlags)
+{
+ FIXME("(%p, %x): stub\n", pInfo, dwFlags );
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+/***********************************************************************
+ * CryptUnregisterOIDFunction (CRYPT32.@)
+ */
BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
LPCSTR pszOID)
{
LPSTR szKey;
LONG rc;
- TRACE("%lx %s %s\n", dwEncodingType, pszFuncName, pszOID);
-
- if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
- return TRUE;
+ TRACE("%x %s %s\n", dwEncodingType, debugstr_a(pszFuncName),
+ debugstr_a(pszOID));
if (!pszFuncName || !pszOID)
{
LONG rc;
HKEY hKey;
- TRACE("%lx %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
+ TRACE("%x %s %s %s %p %p %p\n", dwEncodingType, debugstr_a(pszFuncName),
debugstr_a(pszOID), debugstr_w(pwszValueName), pdwValueType, pbValueData,
pcbValueData);
LONG rc;
HKEY hKey;
- TRACE("%lx %s %s %s %ld %p %ld\n", dwEncodingType, debugstr_a(pszFuncName),
+ TRACE("%x %s %s %s %d %p %d\n", dwEncodingType, debugstr_a(pszFuncName),
debugstr_a(pszOID), debugstr_w(pwszValueName), dwValueType, pbValueData,
cbValueData);
return rc ? FALSE : TRUE;
}
+static LPCWSTR CRYPT_FindStringInMultiString(LPCWSTR multi, LPCWSTR toFind)
+{
+ LPCWSTR ret = NULL, ptr;
+
+ for (ptr = multi; ptr && *ptr && !ret; ptr += lstrlenW(ptr) + 1)
+ {
+ if (!lstrcmpiW(ptr, toFind))
+ ret = ptr;
+ }
+ return ret;
+}
+
+static DWORD CRYPT_GetMultiStringCharacterLen(LPCWSTR multi)
+{
+ DWORD ret;
+
+ if (multi)
+ {
+ LPCWSTR ptr;
+
+ /* Count terminating empty string */
+ ret = 1;
+ for (ptr = multi; *ptr; ptr += lstrlenW(ptr) + 1)
+ ret += lstrlenW(ptr) + 1;
+ }
+ else
+ ret = 0;
+ return ret;
+}
+
+static LPWSTR CRYPT_AddStringToMultiString(LPWSTR multi, LPCWSTR toAdd,
+ DWORD index)
+{
+ LPWSTR ret;
+
+ if (!multi)
+ {
+ /* FIXME: ignoring index, is that okay? */
+ ret = CryptMemAlloc((lstrlenW(toAdd) + 2) * sizeof(WCHAR));
+ if (ret)
+ {
+ /* copy string, including NULL terminator */
+ memcpy(ret, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
+ /* add terminating empty string */
+ *(ret + lstrlenW(toAdd) + 1) = 0;
+ }
+ }
+ else
+ {
+ DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
+
+ ret = CryptMemRealloc(multi, (len + lstrlenW(toAdd) + 1) *
+ sizeof(WCHAR));
+ if (ret)
+ {
+ LPWSTR spotToAdd;
+
+ if (index == CRYPT_REGISTER_LAST_INDEX)
+ spotToAdd = ret + len - 1;
+ else
+ {
+ DWORD i;
+
+ /* FIXME: if index is too large for the string, toAdd is
+ * added to the end. Is that okay?
+ */
+ for (i = 0, spotToAdd = ret; i < index && *spotToAdd;
+ spotToAdd += lstrlenW(spotToAdd) + 1)
+ ;
+ }
+ if (spotToAdd)
+ {
+ /* Copy existing string "right" */
+ memmove(spotToAdd + lstrlenW(toAdd) + 1, spotToAdd,
+ (len - (spotToAdd - ret)) * sizeof(WCHAR));
+ /* Copy new string */
+ memcpy(spotToAdd, toAdd, (lstrlenW(toAdd) + 1) * sizeof(WCHAR));
+ }
+ else
+ {
+ CryptMemFree(ret);
+ ret = NULL;
+ }
+ }
+ }
+ return ret;
+}
+
+static BOOL CRYPT_RemoveStringFromMultiString(LPWSTR multi, LPCWSTR toRemove)
+{
+ LPWSTR spotToRemove = (LPWSTR)CRYPT_FindStringInMultiString(multi,
+ toRemove);
+ BOOL ret;
+
+ if (spotToRemove)
+ {
+ DWORD len = CRYPT_GetMultiStringCharacterLen(multi);
+
+ if (spotToRemove + lstrlenW(toRemove) + 2 >= multi + len)
+ {
+ /* Removing last string in list, terminate multi string directly */
+ *spotToRemove = 0;
+ *(spotToRemove + 1) = 0;
+ }
+ else
+ {
+ /* Copy remainder of string "left" */
+ memmove(spotToRemove, spotToRemove + lstrlenW(toRemove) + 1,
+ (len - (spotToRemove - multi)) * sizeof(WCHAR));
+ }
+ ret = TRUE;
+ }
+ else
+ {
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ ret = FALSE;
+ }
+ return ret;
+}
+
+static BOOL CRYPT_GetDefaultOIDKey(DWORD dwEncodingType, LPCSTR pszFuncName,
+ PHKEY key)
+{
+ LPSTR keyName;
+ LONG r;
+
+ keyName = CRYPT_GetKeyName(dwEncodingType, pszFuncName, "DEFAULT");
+ TRACE("Key name is %s\n", debugstr_a(keyName));
+
+ if (!keyName)
+ return FALSE;
+
+ r = RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyName, 0, NULL, 0, KEY_ALL_ACCESS,
+ NULL, key, NULL);
+ CryptMemFree(keyName);
+ if (r != ERROR_SUCCESS)
+ {
+ SetLastError(r);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static LPWSTR CRYPT_GetDefaultOIDDlls(HKEY key)
+{
+ LONG r;
+ DWORD type, size;
+ LPWSTR dlls;
+
+ r = RegQueryValueExW(key, DllW, NULL, &type, NULL, &size);
+ if (r == ERROR_SUCCESS && type == REG_MULTI_SZ)
+ {
+ dlls = CryptMemAlloc(size);
+ r = RegQueryValueExW(key, DllW, NULL, &type, (LPBYTE)dlls, &size);
+ if (r != ERROR_SUCCESS)
+ {
+ CryptMemFree(dlls);
+ dlls = NULL;
+ }
+ }
+ else
+ dlls = NULL;
+ return dlls;
+}
+
+static inline BOOL CRYPT_SetDefaultOIDDlls(HKEY key, LPCWSTR dlls)
+{
+ DWORD len = CRYPT_GetMultiStringCharacterLen(dlls);
+ LONG r;
+
+ if ((r = RegSetValueExW(key, DllW, 0, REG_MULTI_SZ, (const BYTE *)dlls,
+ len * sizeof (WCHAR))))
+ SetLastError(r);
+ return r == ERROR_SUCCESS;
+}
+
+/***********************************************************************
+ * CryptRegisterDefaultOIDFunction (CRYPT32.@)
+ */
+BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
+ LPCSTR pszFuncName, DWORD dwIndex, LPCWSTR pwszDll)
+{
+ HKEY key;
+ LPWSTR dlls;
+ BOOL ret = FALSE;
+
+ TRACE("(%x, %s, %d, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
+ dwIndex, debugstr_w(pwszDll));
+
+ if (!pwszDll)
+ {
+ SetLastError(E_INVALIDARG);
+ return FALSE;
+ }
+
+ if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
+ return FALSE;
+
+ dlls = CRYPT_GetDefaultOIDDlls(key);
+ if (CRYPT_FindStringInMultiString(dlls, pwszDll))
+ SetLastError(ERROR_FILE_EXISTS);
+ else
+ {
+ dlls = CRYPT_AddStringToMultiString(dlls, pwszDll, dwIndex);
+ if (dlls)
+ ret = CRYPT_SetDefaultOIDDlls(key, dlls);
+ }
+ CryptMemFree(dlls);
+ RegCloseKey(key);
+ return ret;
+}
+
+BOOL WINAPI CryptUnregisterDefaultOIDFunction(DWORD dwEncodingType,
+ LPCSTR pszFuncName, LPCWSTR pwszDll)
+{
+ HKEY key;
+ LPWSTR dlls;
+ BOOL ret;
+
+ TRACE("(%x, %s, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
+ debugstr_w(pwszDll));
+
+ if (!pwszDll)
+ {
+ SetLastError(E_INVALIDARG);
+ return FALSE;
+ }
+
+ if (!CRYPT_GetDefaultOIDKey(dwEncodingType, pszFuncName, &key))
+ return FALSE;
+
+ dlls = CRYPT_GetDefaultOIDDlls(key);
+ if ((ret = CRYPT_RemoveStringFromMultiString(dlls, pwszDll)))
+ ret = CRYPT_SetDefaultOIDDlls(key, dlls);
+ CryptMemFree(dlls);
+ RegCloseKey(key);
+ return ret;
+}
+
+static void oid_init_localizednames(void)
+{
+ unsigned int i;
+
+ for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
+ {
+ LoadStringW(hInstance, IDS_LOCALIZEDNAME_ROOT+i, LocalizedNames[i], 256);
+ }
+}
+
+/********************************************************************
+ * CryptFindLocalizedName (CRYPT32.@)
+ */
+LPCWSTR WINAPI CryptFindLocalizedName(LPCWSTR pwszCryptName)
+{
+ unsigned int i;
+
+ for(i = 0; i < sizeof(LocalizedKeys)/sizeof(LPCWSTR); i++)
+ {
+ if(!lstrcmpiW(LocalizedKeys[i], pwszCryptName))
+ {
+ return LocalizedNames[i];
+ }
+ }
+
+ FIXME("No name for: %s - stub\n",debugstr_w(pwszCryptName));
+ return NULL;
+}
+
static CRITICAL_SECTION oidInfoCS;
-static struct list oidInfo;
+static CRITICAL_SECTION_DEBUG oidInfoCSDebug =
+{
+ 0, 0, &oidInfoCS,
+ { &oidInfoCSDebug.ProcessLocksList, &oidInfoCSDebug.ProcessLocksList },
+ 0, 0, { (DWORD_PTR)(__FILE__ ": oidInfoCS") }
+};
+static CRITICAL_SECTION oidInfoCS = { &oidInfoCSDebug, -1, 0, 0, 0, 0 };
+static struct list oidInfo = { &oidInfo, &oidInfo };
static const WCHAR tripledes[] = { '3','d','e','s',0 };
static const WCHAR cms3deswrap[] = { 'C','M','S','3','D','E','S','w','r','a',
struct list entry;
};
-static void init_oid_info(HINSTANCE hinst)
+static void init_oid_info(void)
{
DWORD i;
- InitializeCriticalSection(&oidInfoCS);
- list_init(&oidInfo);
+ oid_init_localizednames();
for (i = 0; i < sizeof(oidInfoConstructors) /
sizeof(oidInfoConstructors[0]); i++)
{
}
else
{
- int len = LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
- NULL, 0);
+ LPCWSTR stringresource;
+ int len = LoadStringW(hInstance,
+ (UINT_PTR)oidInfoConstructors[i].pwszName,
+ (LPWSTR)&stringresource, 0);
if (len)
{
memset(info, 0, sizeof(*info));
info->info.cbSize = sizeof(CRYPT_OID_INFO);
info->info.pszOID = oidInfoConstructors[i].pszOID;
- info->info.pwszName =
- (LPWSTR)((LPBYTE)info + sizeof(struct OIDInfo));
+ info->info.pwszName = (LPWSTR)(info + 1);
info->info.dwGroupId = oidInfoConstructors[i].dwGroupId;
info->info.u.Algid = oidInfoConstructors[i].Algid;
- LoadStringW(hinst, (UINT_PTR)oidInfoConstructors[i].pwszName,
- (LPWSTR)info->info.pwszName, len + 1);
+ memcpy(info + 1, stringresource, len*sizeof(WCHAR));
+ ((LPWSTR)(info + 1))[len] = 0;
if (oidInfoConstructors[i].blob)
{
info->info.ExtraInfo.cbData =
list_remove(&info->entry);
CryptMemFree(info);
}
- DeleteCriticalSection(&oidInfoCS);
}
+/***********************************************************************
+ * CryptEnumOIDInfo (CRYPT32.@)
+ */
BOOL WINAPI CryptEnumOIDInfo(DWORD dwGroupId, DWORD dwFlags, void *pvArg,
PFN_CRYPT_ENUM_OID_INFO pfnEnumOIDInfo)
{
BOOL ret = TRUE;
struct OIDInfo *info;
- TRACE("(%ld, %08lx, %p, %p)\n", dwGroupId, dwFlags, pvArg,
+ TRACE("(%d, %08x, %p, %p)\n", dwGroupId, dwFlags, pvArg,
pfnEnumOIDInfo);
EnterCriticalSection(&oidInfoCS);
{
PCCRYPT_OID_INFO ret = NULL;
- TRACE("(%ld, %p, %ld)\n", dwKeyType, pvKey, dwGroupId);
+ TRACE("(%d, %p, %d)\n", dwKeyType, pvKey, dwGroupId);
switch(dwKeyType)
{
{
struct OIDInfo *info;
+ TRACE("CRYPT_OID_INFO_ALGID_KEY: %d\n", *(DWORD *)pvKey);
EnterCriticalSection(&oidInfoCS);
LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
{
{
struct OIDInfo *info;
+ TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w(pvKey));
EnterCriticalSection(&oidInfoCS);
LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
{
- if (!lstrcmpW(info->info.pwszName, (LPWSTR)pvKey) &&
+ if (!lstrcmpW(info->info.pwszName, pvKey) &&
(!dwGroupId || info->info.dwGroupId == dwGroupId))
{
ret = &info->info;
case CRYPT_OID_INFO_OID_KEY:
{
struct OIDInfo *info;
- LPSTR oid = (LPSTR)pvKey;
+ LPSTR oid = pvKey;
+ TRACE("CRYPT_OID_INFO_OID_KEY: %s\n", debugstr_a(oid));
EnterCriticalSection(&oidInfoCS);
LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
{
{
struct OIDInfo *info;
+ TRACE("CRYPT_OID_INFO_SIGN_KEY: %d\n", *(DWORD *)pvKey);
EnterCriticalSection(&oidInfoCS);
LIST_FOR_EACH_ENTRY(info, &oidInfo, struct OIDInfo, entry)
{