2006-08-16 01:01:55 +02:00
|
|
|
/*
|
|
|
|
* tests
|
|
|
|
*
|
|
|
|
* Copyright 2006 Robert Reif
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
2006-11-08 00:59:30 +01:00
|
|
|
#include <winnls.h>
|
2016-06-27 17:07:38 +02:00
|
|
|
#include <rpc.h>
|
|
|
|
#include <rpcdce.h>
|
2006-08-16 01:01:55 +02:00
|
|
|
#define SECURITY_WIN32
|
|
|
|
#include <security.h>
|
|
|
|
#include <schannel.h>
|
2017-01-27 10:28:41 +01:00
|
|
|
#include <wincred.h>
|
2018-02-28 04:29:33 +01:00
|
|
|
#include <winsock2.h>
|
2021-04-21 10:19:42 +02:00
|
|
|
#include <ntsecapi.h>
|
|
|
|
#include <winternl.h>
|
2006-08-16 01:01:55 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-08-16 13:42:23 +02:00
|
|
|
static HMODULE secdll;
|
|
|
|
|
2015-08-14 14:59:52 +02:00
|
|
|
static SECURITY_STATUS (SEC_ENTRY *pSspiEncodeAuthIdentityAsStrings)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE, PCWSTR *, PCWSTR *, PCWSTR *);
|
|
|
|
static SECURITY_STATUS (SEC_ENTRY *pSspiEncodeStringsAsAuthIdentity)
|
|
|
|
(PCWSTR, PCWSTR, PCWSTR, PSEC_WINNT_AUTH_IDENTITY_OPAQUE *);
|
|
|
|
static void (SEC_ENTRY *pSspiFreeAuthIdentity)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE);
|
|
|
|
static void (SEC_ENTRY *pSspiLocalFree)
|
|
|
|
(void *);
|
2017-01-27 10:28:41 +01:00
|
|
|
static SECURITY_STATUS (SEC_ENTRY *pSspiPrepareForCredWrite)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE, PCWSTR, PULONG, PCWSTR *, PCWSTR *, PUCHAR *, PULONG);
|
2015-08-14 14:59:52 +02:00
|
|
|
static void (SEC_ENTRY *pSspiZeroAuthIdentity)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE);
|
|
|
|
|
2006-08-16 13:42:23 +02:00
|
|
|
static BOOLEAN (WINAPI * pGetComputerObjectNameA)(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG lpnSize);
|
|
|
|
static BOOLEAN (WINAPI * pGetComputerObjectNameW)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG lpnSize);
|
2009-04-07 10:54:08 +02:00
|
|
|
static BOOLEAN (WINAPI * pGetUserNameExA)(EXTENDED_NAME_FORMAT NameFormat, LPSTR lpNameBuffer, PULONG lpnSize);
|
|
|
|
static BOOLEAN (WINAPI * pGetUserNameExW)(EXTENDED_NAME_FORMAT NameFormat, LPWSTR lpNameBuffer, PULONG lpnSize);
|
2007-05-24 14:05:28 +02:00
|
|
|
static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
|
|
|
|
static PSecurityFunctionTableW (SEC_ENTRY * pInitSecurityInterfaceW)(void);
|
2006-08-16 13:42:23 +02:00
|
|
|
|
|
|
|
static EXTENDED_NAME_FORMAT formats[] = {
|
|
|
|
NameUnknown, NameFullyQualifiedDN, NameSamCompatible, NameDisplay,
|
|
|
|
NameUniqueId, NameCanonical, NameUserPrincipal, NameCanonicalEx,
|
|
|
|
NameServicePrincipal, NameDnsDomain
|
|
|
|
};
|
|
|
|
|
|
|
|
static void testGetComputerObjectNameA(void)
|
2006-08-16 01:01:55 +02:00
|
|
|
{
|
|
|
|
char name[256];
|
|
|
|
ULONG size;
|
|
|
|
BOOLEAN rc;
|
2009-05-08 17:39:46 +02:00
|
|
|
UINT i;
|
2006-08-16 01:01:55 +02:00
|
|
|
|
2018-05-30 21:15:46 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); i++) {
|
2018-02-28 04:29:33 +01:00
|
|
|
size = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc = pGetComputerObjectNameA(formats[i], NULL, &size);
|
|
|
|
ok(!rc, "GetComputerObjectName(%u) should fail\n", formats[i]);
|
|
|
|
switch (formats[i])
|
|
|
|
{
|
|
|
|
case NameUnknown:
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(GetLastError() == ERROR_NONE_MAPPED ||
|
|
|
|
GetLastError() == ERROR_NO_SUCH_USER ||
|
|
|
|
GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO ||
|
|
|
|
GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
|
|
|
"%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) continue;
|
|
|
|
|
2006-08-16 01:01:55 +02:00
|
|
|
size = sizeof(name);
|
2018-02-28 04:29:33 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2006-08-16 13:42:23 +02:00
|
|
|
rc = pGetComputerObjectNameA(formats[i], name, &size);
|
2018-02-28 04:29:33 +01:00
|
|
|
switch (formats[i])
|
|
|
|
{
|
|
|
|
case NameUnknown:
|
|
|
|
ok(!rc, "GetComputerObjectName(%u) should fail\n", formats[i]);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(rc, "GetComputerObjectName(%u) error %u\n", formats[i], GetLastError());
|
|
|
|
trace("GetComputerObjectName(%u) returned %s\n", formats[i], name);
|
|
|
|
break;
|
|
|
|
}
|
2006-08-16 13:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testGetComputerObjectNameW(void)
|
|
|
|
{
|
|
|
|
WCHAR nameW[256];
|
|
|
|
ULONG size;
|
|
|
|
BOOLEAN rc;
|
2009-05-08 17:39:46 +02:00
|
|
|
UINT i;
|
2006-08-16 01:01:55 +02:00
|
|
|
|
2018-05-30 21:15:46 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); i++) {
|
2018-02-28 04:29:33 +01:00
|
|
|
size = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
rc = pGetComputerObjectNameW(formats[i], NULL, &size);
|
|
|
|
ok(!rc || broken(rc) /* win10 */, "GetComputerObjectName(%u) should fail\n", formats[i]);
|
|
|
|
switch (formats[i])
|
|
|
|
{
|
|
|
|
case NameUnknown:
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(GetLastError() == ERROR_NONE_MAPPED ||
|
|
|
|
GetLastError() == ERROR_NO_SUCH_USER ||
|
|
|
|
GetLastError() == ERROR_CANT_ACCESS_DOMAIN_INFO ||
|
|
|
|
GetLastError() == WSAHOST_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
|
|
|
"%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) continue;
|
|
|
|
|
2018-05-30 21:15:46 +02:00
|
|
|
size = ARRAY_SIZE(nameW);
|
2018-02-28 04:29:33 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2006-08-16 13:42:23 +02:00
|
|
|
rc = pGetComputerObjectNameW(formats[i], nameW, &size);
|
2018-02-28 04:29:33 +01:00
|
|
|
switch (formats[i])
|
|
|
|
{
|
|
|
|
case NameUnknown:
|
|
|
|
ok(!rc, "GetComputerObjectName(%u) should fail\n", formats[i]);
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "%u: got %u\n", formats[i], GetLastError());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ok(rc, "GetComputerObjectName(%u) error %u\n", formats[i], GetLastError());
|
|
|
|
trace("GetComputerObjectName(%u) returned %s\n", formats[i], wine_dbgstr_w(nameW));
|
|
|
|
break;
|
2006-08-26 13:34:53 +02:00
|
|
|
}
|
2006-08-16 01:01:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
static void testGetUserNameExA(void)
|
|
|
|
{
|
|
|
|
char name[256];
|
|
|
|
ULONG size;
|
|
|
|
BOOLEAN rc;
|
2009-05-08 17:39:46 +02:00
|
|
|
UINT i;
|
2009-04-07 10:54:08 +02:00
|
|
|
|
2018-05-30 21:15:46 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); i++) {
|
2009-04-07 10:54:08 +02:00
|
|
|
size = sizeof(name);
|
|
|
|
ZeroMemory(name, sizeof(name));
|
|
|
|
rc = pGetUserNameExA(formats[i], name, &size);
|
2009-04-14 14:33:08 +02:00
|
|
|
ok(rc ||
|
|
|
|
(formats[i] == NameUnknown &&
|
|
|
|
GetLastError() == ERROR_NO_SUCH_USER) ||
|
|
|
|
GetLastError() == ERROR_NONE_MAPPED ||
|
|
|
|
broken(formats[i] == NameDnsDomain &&
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER),
|
|
|
|
"GetUserNameExW(%d) failed: %d\n",
|
2009-04-07 10:54:08 +02:00
|
|
|
formats[i], GetLastError());
|
|
|
|
}
|
|
|
|
|
2009-04-09 14:44:23 +02:00
|
|
|
if (0) /* Crashes on Windows */
|
2011-02-09 22:43:47 +01:00
|
|
|
pGetUserNameExA(NameSamCompatible, NULL, NULL);
|
2009-04-09 14:44:23 +02:00
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
size = 0;
|
|
|
|
rc = pGetUserNameExA(NameSamCompatible, NULL, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(size != 0, "Expected size to be set to required size\n");
|
2009-04-09 14:44:23 +02:00
|
|
|
|
|
|
|
if (0) /* Crashes on Windows with big enough size */
|
|
|
|
{
|
|
|
|
/* Returned size is already big enough */
|
2011-02-09 22:43:47 +01:00
|
|
|
pGetUserNameExA(NameSamCompatible, NULL, &size);
|
2009-04-09 14:44:23 +02:00
|
|
|
}
|
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
size = 0;
|
|
|
|
rc = pGetUserNameExA(NameSamCompatible, name, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(size != 0, "Expected size to be set to required size\n");
|
|
|
|
size = 1;
|
|
|
|
name[0] = 0xff;
|
|
|
|
rc = pGetUserNameExA(NameSamCompatible, name, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(1 < size, "Expected size to be set to required size\n");
|
|
|
|
ok(name[0] == (char) 0xff, "Expected unchanged buffer\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testGetUserNameExW(void)
|
|
|
|
{
|
|
|
|
WCHAR nameW[256];
|
|
|
|
ULONG size;
|
|
|
|
BOOLEAN rc;
|
2009-05-08 17:39:46 +02:00
|
|
|
UINT i;
|
2009-04-07 10:54:08 +02:00
|
|
|
|
2018-05-30 21:15:46 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(formats); i++) {
|
2009-04-07 10:54:08 +02:00
|
|
|
size = sizeof(nameW);
|
|
|
|
ZeroMemory(nameW, sizeof(nameW));
|
|
|
|
rc = pGetUserNameExW(formats[i], nameW, &size);
|
2009-04-14 14:33:08 +02:00
|
|
|
ok(rc ||
|
|
|
|
(formats[i] == NameUnknown &&
|
|
|
|
GetLastError() == ERROR_NO_SUCH_USER) ||
|
|
|
|
GetLastError() == ERROR_NONE_MAPPED ||
|
|
|
|
broken(formats[i] == NameDnsDomain &&
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER),
|
2009-04-07 10:54:08 +02:00
|
|
|
"GetUserNameExW(%d) failed: %d\n",
|
|
|
|
formats[i], GetLastError());
|
|
|
|
}
|
|
|
|
|
2009-04-09 14:44:23 +02:00
|
|
|
if (0) /* Crashes on Windows */
|
2011-02-09 22:43:47 +01:00
|
|
|
pGetUserNameExW(NameSamCompatible, NULL, NULL);
|
2009-04-09 14:44:23 +02:00
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
size = 0;
|
|
|
|
rc = pGetUserNameExW(NameSamCompatible, NULL, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(size != 0, "Expected size to be set to required size\n");
|
2009-04-09 14:44:23 +02:00
|
|
|
|
|
|
|
if (0) /* Crashes on Windows with big enough size */
|
|
|
|
{
|
|
|
|
/* Returned size is already big enough */
|
2011-02-09 22:43:47 +01:00
|
|
|
pGetUserNameExW(NameSamCompatible, NULL, &size);
|
2009-04-09 14:44:23 +02:00
|
|
|
}
|
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
size = 0;
|
|
|
|
rc = pGetUserNameExW(NameSamCompatible, nameW, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(size != 0, "Expected size to be set to required size\n");
|
|
|
|
size = 1;
|
|
|
|
nameW[0] = 0xff;
|
|
|
|
rc = pGetUserNameExW(NameSamCompatible, nameW, &size);
|
|
|
|
ok(! rc && GetLastError() == ERROR_MORE_DATA, "Expected fail with ERROR_MORE_DATA, got %d with %u\n", rc, GetLastError());
|
|
|
|
ok(1 < size, "Expected size to be set to required size\n");
|
|
|
|
ok(nameW[0] == (WCHAR) 0xff, "Expected unchanged buffer\n");
|
|
|
|
}
|
|
|
|
|
2007-05-24 14:05:28 +02:00
|
|
|
static void test_InitSecurityInterface(void)
|
|
|
|
{
|
|
|
|
PSecurityFunctionTableA sftA;
|
|
|
|
PSecurityFunctionTableW sftW;
|
|
|
|
|
|
|
|
sftA = pInitSecurityInterfaceA();
|
|
|
|
ok(sftA != NULL, "pInitSecurityInterfaceA failed\n");
|
2009-01-06 00:06:04 +01:00
|
|
|
ok(sftA->dwVersion == SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, "wrong dwVersion %d in security function table\n", sftA->dwVersion);
|
2011-02-28 22:05:45 +01:00
|
|
|
ok(!sftA->Reserved2,
|
2009-02-03 16:48:59 +01:00
|
|
|
"Reserved2 should be NULL instead of %p in security function table\n",
|
|
|
|
sftA->Reserved2);
|
2011-02-28 22:05:45 +01:00
|
|
|
ok(sftA->Reserved3 == sftA->EncryptMessage,
|
2009-02-03 16:48:59 +01:00
|
|
|
"Reserved3 should be equal to EncryptMessage in the security function table\n");
|
2011-02-28 22:05:45 +01:00
|
|
|
ok(sftA->Reserved4 == sftA->DecryptMessage,
|
2009-02-03 16:48:59 +01:00
|
|
|
"Reserved4 should be equal to DecryptMessage in the security function table\n");
|
2007-05-24 14:05:28 +02:00
|
|
|
|
|
|
|
if (!pInitSecurityInterfaceW)
|
|
|
|
{
|
2009-04-14 14:33:08 +02:00
|
|
|
win_skip("InitSecurityInterfaceW not exported by secur32.dll\n");
|
2007-05-24 14:05:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sftW = pInitSecurityInterfaceW();
|
|
|
|
ok(sftW != NULL, "pInitSecurityInterfaceW failed\n");
|
2009-01-06 00:06:04 +01:00
|
|
|
ok(sftW->dwVersion == SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, "wrong dwVersion %d in security function table\n", sftW->dwVersion);
|
2007-05-24 14:05:28 +02:00
|
|
|
ok(!sftW->Reserved2, "Reserved2 should be NULL instead of %p in security function table\n", sftW->Reserved2);
|
2008-08-19 17:50:53 +02:00
|
|
|
ok(sftW->Reserved3 == sftW->EncryptMessage, "Reserved3 should be equal to EncryptMessage in the security function table\n");
|
|
|
|
ok(sftW->Reserved4 == sftW->DecryptMessage, "Reserved4 should be equal to DecryptMessage in the security function table\n");
|
2007-05-24 14:05:28 +02:00
|
|
|
}
|
|
|
|
|
2015-08-14 14:59:52 +02:00
|
|
|
static void test_SspiEncodeStringsAsAuthIdentity(void)
|
|
|
|
{
|
|
|
|
static const WCHAR username[] = {'u','s','e','r','n','a','m','e',0};
|
|
|
|
static const WCHAR domainname[] = {'d','o','m','a','i','n','n','a','m','e',0};
|
|
|
|
static const WCHAR password[] = {'p','a','s','s','w','o','r','d',0};
|
|
|
|
const WCHAR *username_ptr, *domainname_ptr, *password_ptr;
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY_OPAQUE id;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
|
|
|
|
if (!pSspiEncodeStringsAsAuthIdentity)
|
|
|
|
{
|
|
|
|
win_skip( "SspiEncodeAuthIdentityAsStrings not exported by secur32.dll\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( NULL, NULL, NULL, NULL );
|
|
|
|
ok( status == SEC_E_INVALID_TOKEN, "got %08x\n", status );
|
|
|
|
|
|
|
|
id = (PSEC_WINNT_AUTH_IDENTITY_OPAQUE)0xdeadbeef;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( NULL, NULL, NULL, &id );
|
|
|
|
ok( status == SEC_E_INVALID_TOKEN, "got %08x\n", status );
|
|
|
|
ok( id == (PSEC_WINNT_AUTH_IDENTITY_OPAQUE)0xdeadbeef, "id set\n" );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( NULL, NULL, password, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( NULL, domainname, password, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( username, NULL, password, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( username, NULL, NULL, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( username, domainname, password, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
|
|
|
|
username_ptr = domainname_ptr = password_ptr = NULL;
|
|
|
|
status = pSspiEncodeAuthIdentityAsStrings( id, &username_ptr, &domainname_ptr, &password_ptr );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( !lstrcmpW( username, username_ptr ), "wrong username\n" );
|
|
|
|
ok( !lstrcmpW( domainname, domainname_ptr ), "wrong domainname\n" );
|
|
|
|
ok( !lstrcmpW( password, password_ptr ), "wrong password\n" );
|
|
|
|
|
|
|
|
pSspiZeroAuthIdentity( id );
|
|
|
|
|
|
|
|
pSspiLocalFree( (void *)username_ptr );
|
|
|
|
pSspiLocalFree( (void *)domainname_ptr );
|
|
|
|
pSspiLocalFree( (void *)password_ptr );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
|
|
|
|
id = NULL;
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( username, NULL, password, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
|
|
|
|
username_ptr = password_ptr = NULL;
|
|
|
|
domainname_ptr = (const WCHAR *)0xdeadbeef;
|
|
|
|
status = pSspiEncodeAuthIdentityAsStrings( id, &username_ptr, &domainname_ptr, &password_ptr );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( !lstrcmpW( username, username_ptr ), "wrong username\n" );
|
|
|
|
ok( domainname_ptr == NULL, "domainname_ptr not cleared\n" );
|
|
|
|
ok( !lstrcmpW( password, password_ptr ), "wrong password\n" );
|
|
|
|
|
|
|
|
pSspiLocalFree( (void *)username_ptr );
|
|
|
|
pSspiLocalFree( (void *)password_ptr );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:28:41 +01:00
|
|
|
static void test_SspiPrepareForCredWrite(void)
|
|
|
|
{
|
|
|
|
static const WCHAR usernameW[] =
|
|
|
|
{'u','s','e','r','n','a','m','e',0};
|
|
|
|
static const WCHAR domainnameW[] =
|
|
|
|
{'d','o','m','a','i','n','n','a','m','e',0};
|
|
|
|
static const WCHAR passwordW[] =
|
|
|
|
{'p','a','s','s','w','o','r','d',0};
|
|
|
|
static const WCHAR targetW[] =
|
|
|
|
{'d','o','m','a','i','n','n','a','m','e','\\','u','s','e','r','n','a','m','e',0};
|
|
|
|
static const WCHAR target2W[] =
|
|
|
|
{'d','o','m','a','i','n','n','a','m','e','2','\\','u','s','e','r','n','a','m','e','2',0};
|
|
|
|
const WCHAR *target, *username;
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY_OPAQUE id;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
ULONG type, size;
|
|
|
|
UCHAR *blob;
|
|
|
|
|
|
|
|
if (!pSspiPrepareForCredWrite)
|
|
|
|
{
|
|
|
|
win_skip( "SspiPrepareForCredWrite not exported by secur32.dll\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = pSspiEncodeStringsAsAuthIdentity( usernameW, domainnameW, passwordW, &id );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
|
|
|
|
type = size = 0;
|
|
|
|
status = pSspiPrepareForCredWrite( id, NULL, &type, &target, &username, &blob, &size );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( type == CRED_TYPE_DOMAIN_PASSWORD, "got %u\n", type );
|
|
|
|
ok( !lstrcmpW( target, targetW ), "got %s\n", wine_dbgstr_w(target) );
|
|
|
|
ok( !lstrcmpW( username, targetW ), "got %s\n", wine_dbgstr_w(username) );
|
|
|
|
ok( !memcmp( blob, passwordW, sizeof(passwordW) - sizeof(WCHAR) ), "wrong data\n" );
|
|
|
|
ok( size == sizeof(passwordW) - sizeof(WCHAR), "got %u\n", size );
|
|
|
|
pSspiLocalFree( (void *)target );
|
|
|
|
pSspiLocalFree( (void *)username );
|
|
|
|
pSspiLocalFree( blob );
|
|
|
|
|
|
|
|
type = size = 0;
|
|
|
|
status = pSspiPrepareForCredWrite( id, target2W, &type, &target, &username, &blob, &size );
|
|
|
|
ok( status == SEC_E_OK, "got %08x\n", status );
|
|
|
|
ok( type == CRED_TYPE_DOMAIN_PASSWORD, "got %u\n", type );
|
|
|
|
ok( !lstrcmpW( target, target2W ), "got %s\n", wine_dbgstr_w(target) );
|
|
|
|
ok( !lstrcmpW( username, targetW ), "got %s\n", wine_dbgstr_w(username) );
|
|
|
|
ok( !memcmp( blob, passwordW, sizeof(passwordW) - sizeof(WCHAR) ), "wrong data\n" );
|
|
|
|
ok( size == sizeof(passwordW) - sizeof(WCHAR), "got %u\n", size );
|
|
|
|
pSspiLocalFree( (void *)target );
|
|
|
|
pSspiLocalFree( (void *)username );
|
|
|
|
pSspiLocalFree( blob );
|
|
|
|
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
}
|
|
|
|
|
2016-06-27 17:07:38 +02:00
|
|
|
static void test_kerberos(void)
|
|
|
|
{
|
|
|
|
SecPkgInfoA *info;
|
|
|
|
TimeStamp ttl;
|
|
|
|
CredHandle cred;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
|
|
|
|
SEC_CHAR provider[] = {'K','e','r','b','e','r','o','s',0};
|
|
|
|
|
|
|
|
static const ULONG expected_flags =
|
|
|
|
SECPKG_FLAG_INTEGRITY
|
|
|
|
| SECPKG_FLAG_PRIVACY
|
|
|
|
| SECPKG_FLAG_TOKEN_ONLY
|
|
|
|
| SECPKG_FLAG_DATAGRAM
|
|
|
|
| SECPKG_FLAG_CONNECTION
|
|
|
|
| SECPKG_FLAG_MULTI_REQUIRED
|
|
|
|
| SECPKG_FLAG_EXTENDED_ERROR
|
|
|
|
| SECPKG_FLAG_IMPERSONATION
|
|
|
|
| SECPKG_FLAG_ACCEPT_WIN32_NAME
|
|
|
|
| SECPKG_FLAG_NEGOTIABLE
|
|
|
|
| SECPKG_FLAG_GSS_COMPATIBLE
|
|
|
|
| SECPKG_FLAG_LOGON
|
|
|
|
| SECPKG_FLAG_MUTUAL_AUTH
|
|
|
|
| SECPKG_FLAG_DELEGATION
|
|
|
|
| SECPKG_FLAG_READONLY_WITH_CHECKSUM;
|
|
|
|
static const ULONG optional_mask =
|
|
|
|
SECPKG_FLAG_RESTRICTED_TOKENS
|
2019-03-27 19:03:15 +01:00
|
|
|
| SECPKG_FLAG_APPCONTAINER_CHECKS
|
|
|
|
| 0x02000000; /* not defined in the SDK */
|
|
|
|
|
2016-06-27 17:07:38 +02:00
|
|
|
|
|
|
|
status = QuerySecurityPackageInfoA(provider, &info);
|
|
|
|
ok(status == SEC_E_OK, "Kerberos package not installed, skipping test\n");
|
|
|
|
if(status != SEC_E_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ok( (info->fCapabilities & ~optional_mask) == expected_flags, "got %08x, expected %08x\n", info->fCapabilities, expected_flags );
|
|
|
|
ok( info->wVersion == 1, "got %u\n", info->wVersion );
|
|
|
|
ok( info->wRPCID == RPC_C_AUTHN_GSS_KERBEROS, "got %u\n", info->wRPCID );
|
|
|
|
ok( info->cbMaxToken >= 12000, "got %u\n", info->cbMaxToken );
|
|
|
|
ok( !lstrcmpA( info->Name, "Kerberos" ), "got %s\n", info->Name );
|
|
|
|
ok( !lstrcmpA( info->Comment, "Microsoft Kerberos V1.0" ), "got %s\n", info->Comment );
|
|
|
|
FreeContextBuffer( info );
|
|
|
|
|
|
|
|
status = AcquireCredentialsHandleA( NULL, provider, SECPKG_CRED_OUTBOUND, NULL,
|
|
|
|
NULL, NULL, NULL, &cred, &ttl );
|
|
|
|
todo_wine ok( status == SEC_E_OK, "AcquireCredentialsHandleA returned %08x\n", status );
|
|
|
|
if(status == SEC_E_OK)
|
|
|
|
FreeCredentialHandle( &cred );
|
|
|
|
}
|
|
|
|
|
2021-04-21 10:19:42 +02:00
|
|
|
static void test_ticket_cache(void)
|
|
|
|
{
|
|
|
|
KERB_QUERY_TKT_CACHE_REQUEST req = { KerbQueryTicketCacheMessage };
|
|
|
|
KERB_QUERY_TKT_CACHE_RESPONSE *resp;
|
|
|
|
NTSTATUS status;
|
|
|
|
HANDLE lsa;
|
|
|
|
ULONG package, len, i;
|
|
|
|
LSA_STRING name;
|
|
|
|
|
|
|
|
status = LsaConnectUntrusted( &lsa );
|
|
|
|
ok( !status, "got %08x\n", status );
|
|
|
|
|
|
|
|
RtlInitAnsiString( &name, MICROSOFT_KERBEROS_NAME_A );
|
|
|
|
status = LsaLookupAuthenticationPackage( lsa, &name, &package );
|
|
|
|
ok( !status, "got %08x\n", status );
|
|
|
|
|
|
|
|
status = LsaCallAuthenticationPackage( lsa, package, &req, sizeof(req), (void **)&resp, &len, &status );
|
|
|
|
ok( !status, "got %08x\n", status );
|
|
|
|
ok( resp->MessageType == KerbQueryTicketCacheMessage, "got %u\n", resp->MessageType );
|
|
|
|
|
|
|
|
for (i = 0; i < resp->CountOfTickets; i++)
|
|
|
|
{
|
|
|
|
KERB_TICKET_CACHE_INFO *info = &resp->Tickets[i];
|
|
|
|
trace( "ServerName %s\n", wine_dbgstr_wn(info->ServerName.Buffer, info->ServerName.Length/sizeof(WCHAR)) );
|
|
|
|
trace( "RealmName %s\n", wine_dbgstr_wn(info->RealmName.Buffer, info->RealmName.Length/sizeof(WCHAR)) );
|
|
|
|
trace( "EncryptionType %08x\n", info->EncryptionType );
|
|
|
|
trace( "TicketFlags %08x\n", info->TicketFlags );
|
|
|
|
}
|
|
|
|
LsaFreeReturnBuffer( resp );
|
|
|
|
LsaDeregisterLogonProcess( lsa );
|
|
|
|
}
|
|
|
|
|
2006-08-16 01:01:55 +02:00
|
|
|
START_TEST(secur32)
|
|
|
|
{
|
2006-08-16 13:42:23 +02:00
|
|
|
secdll = LoadLibraryA("secur32.dll");
|
|
|
|
|
|
|
|
if (!secdll)
|
|
|
|
secdll = LoadLibraryA("security.dll");
|
|
|
|
|
|
|
|
if (secdll)
|
|
|
|
{
|
2015-08-14 14:59:52 +02:00
|
|
|
pSspiEncodeAuthIdentityAsStrings = (void *)GetProcAddress(secdll, "SspiEncodeAuthIdentityAsStrings");
|
|
|
|
pSspiEncodeStringsAsAuthIdentity = (void *)GetProcAddress(secdll, "SspiEncodeStringsAsAuthIdentity");
|
|
|
|
pSspiFreeAuthIdentity = (void *)GetProcAddress(secdll, "SspiFreeAuthIdentity");
|
|
|
|
pSspiLocalFree = (void *)GetProcAddress(secdll, "SspiLocalFree");
|
2017-01-27 10:28:41 +01:00
|
|
|
pSspiPrepareForCredWrite = (void *)GetProcAddress(secdll, "SspiPrepareForCredWrite");
|
2015-08-14 14:59:52 +02:00
|
|
|
pSspiZeroAuthIdentity = (void *)GetProcAddress(secdll, "SspiZeroAuthIdentity");
|
2006-08-16 13:42:23 +02:00
|
|
|
pGetComputerObjectNameA = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameA");
|
|
|
|
pGetComputerObjectNameW = (PVOID)GetProcAddress(secdll, "GetComputerObjectNameW");
|
2009-04-07 10:54:08 +02:00
|
|
|
pGetUserNameExA = (PVOID)GetProcAddress(secdll, "GetUserNameExA");
|
|
|
|
pGetUserNameExW = (PVOID)GetProcAddress(secdll, "GetUserNameExW");
|
2007-05-24 14:05:28 +02:00
|
|
|
pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
|
|
|
|
pInitSecurityInterfaceW = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceW");
|
2017-01-27 10:28:41 +01:00
|
|
|
|
2006-08-16 13:42:23 +02:00
|
|
|
if (pGetComputerObjectNameA)
|
|
|
|
testGetComputerObjectNameA();
|
2009-04-14 14:33:08 +02:00
|
|
|
else
|
|
|
|
win_skip("GetComputerObjectNameA not exported by secur32.dll\n");
|
2006-08-16 13:42:23 +02:00
|
|
|
|
|
|
|
if (pGetComputerObjectNameW)
|
|
|
|
testGetComputerObjectNameW();
|
2009-04-14 14:33:08 +02:00
|
|
|
else
|
|
|
|
win_skip("GetComputerObjectNameW not exported by secur32.dll\n");
|
2006-08-16 13:42:23 +02:00
|
|
|
|
2009-04-07 10:54:08 +02:00
|
|
|
if (pGetUserNameExA)
|
|
|
|
testGetUserNameExA();
|
2009-04-14 14:33:08 +02:00
|
|
|
else
|
|
|
|
win_skip("GetUserNameExA not exported by secur32.dll\n");
|
2009-04-07 10:54:08 +02:00
|
|
|
|
|
|
|
if (pGetUserNameExW)
|
|
|
|
testGetUserNameExW();
|
2009-04-14 14:33:08 +02:00
|
|
|
else
|
|
|
|
win_skip("GetUserNameExW not exported by secur32.dll\n");
|
2009-04-07 10:54:08 +02:00
|
|
|
|
2007-05-24 14:05:28 +02:00
|
|
|
test_InitSecurityInterface();
|
2015-08-14 14:59:52 +02:00
|
|
|
test_SspiEncodeStringsAsAuthIdentity();
|
2017-01-27 10:28:41 +01:00
|
|
|
test_SspiPrepareForCredWrite();
|
2007-05-24 14:05:28 +02:00
|
|
|
|
2006-08-16 13:42:23 +02:00
|
|
|
FreeLibrary(secdll);
|
|
|
|
}
|
2016-06-27 17:07:38 +02:00
|
|
|
|
|
|
|
test_kerberos();
|
2021-04-21 10:19:42 +02:00
|
|
|
test_ticket_cache();
|
2006-08-16 01:01:55 +02:00
|
|
|
}
|