Some applications crash when the storage provider its null.
Signed-off-by: Santino Mazza mazzasantino1206@gmail.com --- dlls/ncrypt/main.c | 17 ++++++++++- dlls/ncrypt/ncrypt_internal.h | 56 +++++++++++++++++++++++++++++++++++ dlls/ncrypt/tests/ncrypt.c | 2 -- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 dlls/ncrypt/ncrypt_internal.h
diff --git a/dlls/ncrypt/main.c b/dlls/ncrypt/main.c index f23b239d93f..3a916e5b722 100644 --- a/dlls/ncrypt/main.c +++ b/dlls/ncrypt/main.c @@ -19,10 +19,12 @@ */
#include <stdarg.h> +#include <stdlib.h>
#include "windef.h" #include "winbase.h" #include "ncrypt.h" +#include "ncrypt_internal.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ncrypt); @@ -129,10 +131,23 @@ SECURITY_STATUS WINAPI NCryptOpenKey(NCRYPT_PROV_HANDLE provider, NCRYPT_KEY_HAN return NTE_NOT_SUPPORTED; }
+int allocate_storage_provider_object(struct ncrypt_object **providerobject) +{ + *providerobject = malloc(sizeof(struct ncrypt_object)); + if (providerobject == NULL) + { + ERR("Error allocating memory.\n"); + return NTE_NO_MEMORY; + } + memset(*providerobject, 0, sizeof(struct ncrypt_object)); + (*providerobject)->type = STORAGE_PROVIDER; + return ERROR_SUCCESS; +} + SECURITY_STATUS WINAPI NCryptOpenStorageProvider(NCRYPT_PROV_HANDLE *provider, const WCHAR *name, DWORD flags) { FIXME("(%p, %s, %u): stub\n", provider, wine_dbgstr_w(name), flags); - return NTE_NOT_SUPPORTED; + return allocate_storage_provider_object((struct ncrypt_object**)provider); }
SECURITY_STATUS WINAPI NCryptSetProperty(NCRYPT_HANDLE object, const WCHAR *property, diff --git a/dlls/ncrypt/ncrypt_internal.h b/dlls/ncrypt/ncrypt_internal.h new file mode 100644 index 00000000000..1201cdd857a --- /dev/null +++ b/dlls/ncrypt/ncrypt_internal.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 Santino Mazza + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef NCRYPT_INTERNAL_H +#define NCRYPT_INTERNAL_H + +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "winternl.h" + +struct ncrypt_storage_provider_object +{ + // FIXME Stub +}; + +enum ncrypt_object_type +{ + STORAGE_PROVIDER, +}; + +struct ncrypt_object_property +{ + WCHAR *key; + DWORD value_size; + VOID *value; +}; + +struct ncrypt_object +{ + enum ncrypt_object_type type; + DWORD number_of_properties; + struct ncrypt_object_property *properties; + union + { + struct ncrypt_storage_provider_object storage_provider; + } object; +}; + +#endif // NCRYPT_INTERNAL_H diff --git a/dlls/ncrypt/tests/ncrypt.c b/dlls/ncrypt/tests/ncrypt.c index 045dd60c793..df2179ca10a 100644 --- a/dlls/ncrypt/tests/ncrypt.c +++ b/dlls/ncrypt/tests/ncrypt.c @@ -92,12 +92,10 @@ static void test_key_import_rsa(void) NCRYPT_KEY_HANDLE key; SECURITY_STATUS ret;
- todo_wine { prov = 0; ret = NCryptOpenStorageProvider(&prov, NULL, 0); ok(ret == ERROR_SUCCESS, "got %#lx\n", ret); ok(prov, "got null handle\n"); - }
todo_wine { key = 0;