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);
- funcSetCS.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": 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)
{
DeleteCriticalSection(&setCursor->cs);
CryptMemFree(setCursor);
}
- funcSetCS.DebugInfo->Spare[0] = 0;
- DeleteCriticalSection(&funcSetCS);
}
/* There is no free function associated with this; therefore, the sets are
{
if (!strcasecmp(pszFuncName, cursor->name))
{
- ret = (HCRYPTOIDFUNCSET)cursor;
+ ret = cursor;
break;
}
}
}
LeaveCriticalSection(&funcSetCS);
- return (HCRYPTOIDFUNCSET)ret;
+ return ret;
}
static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
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, %d, %p, %p)\n", hFuncSet, dwEncodingType, pwszDllList,
pcchDllList);
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);
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))
{
LPSTR oid;
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, %d, %s, %08x, %p, %p)\n", hFuncSet, dwEncodingType,
debugstr_a(pszOID), dwFlags, ppvFuncAddr, phFuncAddr);
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 (!*ppvFuncAddr)
ret = CRYPT_GetFuncFromReg(dwEncodingType, pszOID, set->name,
ppvFuncAddr, phFuncAddr);
+ TRACE("returning %d\n", ret);
return ret;
}
* 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;
}
+static BOOL CRYPT_GetFuncFromDll(LPCWSTR dll, LPCSTR func, HMODULE *lib,
+ void **ppvFuncAddr)
+{
+ BOOL ret = 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, %d, %s, %08x, %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;
}
/***********************************************************************
TRACE("(%x, %s, %s, %s, %s)\n", dwEncodingType, pszFuncName,
debugstr_a(pszOID), debugstr_w(pwszDll), pszOverrideFuncName);
- /* This only registers functions for encoding certs, not messages */
- if (!GET_CERT_ENCODING_TYPE(dwEncodingType))
- return TRUE;
-
/* Native does nothing pwszDll is NULL */
if (!pwszDll)
return TRUE;
RegCloseKey(hKey);
- if (r != ERROR_SUCCESS)
+ 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.@)
*/
LPSTR szKey;
LONG rc;
- TRACE("%x %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)
{
{
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
{
HKEY key;
LPWSTR dlls;
- LPCWSTR existing;
BOOL ret = FALSE;
- TRACE("(%x, %s, %x, %s)\n", dwEncodingType, pszFuncName, dwIndex,
- debugstr_w(pwszDll));
+ TRACE("(%x, %s, %d, %s)\n", dwEncodingType, debugstr_a(pszFuncName),
+ dwIndex, debugstr_w(pwszDll));
if (!pwszDll)
{
return FALSE;
dlls = CRYPT_GetDefaultOIDDlls(key);
- if ((existing = CRYPT_FindStringInMultiString(dlls, pwszDll)))
+ if (CRYPT_FindStringInMultiString(dlls, pwszDll))
SetLastError(ERROR_FILE_EXISTS);
else
{
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);
- oidInfoCS.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": 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);
}
- oidInfoCS.DebugInfo->Spare[0] = 0;
- DeleteCriticalSection(&oidInfoCS);
}
/***********************************************************************
{
struct OIDInfo *info;
- TRACE("CRYPT_OID_INFO_NAME_KEY: %s\n", debugstr_w((LPWSTR)pvKey));
+ 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);