Import from WINE 25.04.05 (just because we have old version sitting in our SVN, which shows failures even on WinXP).

Now "advapi32_test registry" has 0 failures on Windows XP Pro. (and generally should have 0 failures under ROS too...)

svn path=/trunk/; revision=14860
This commit is contained in:
Aleksey Bragin 2005-04-29 11:25:55 +00:00
parent aa182938a2
commit 11e90a8e41
7 changed files with 2020 additions and 1703 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,63 +1,63 @@
/* /*
* Unit tests for SystemFunction006 (LMHash?) * Unit tests for SystemFunction006 (LMHash?)
* *
* Copyright 2004 Hans Leidekker * Copyright 2004 Hans Leidekker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include <stdio.h>
#include "wine/test.h" #include "wine/test.h"
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
typedef VOID (WINAPI *fnSystemFunction006)( PCSTR passwd, PSTR lmhash ); typedef VOID (WINAPI *fnSystemFunction006)( PCSTR passwd, PSTR lmhash );
fnSystemFunction006 pSystemFunction006; fnSystemFunction006 pSystemFunction006;
static void test_SystemFunction006() static void test_SystemFunction006()
{ {
static unsigned char lmhash[16 + 1]; static unsigned char lmhash[16 + 1];
unsigned char passwd[] = { 's','e','c','r','e','t', 0, 0, 0, 0, 0, 0, 0, 0 }; unsigned char passwd[] = { 's','e','c','r','e','t', 0, 0, 0, 0, 0, 0, 0, 0 };
unsigned char expect[] = unsigned char expect[] =
{ 0x85, 0xf5, 0x28, 0x9f, 0x09, 0xdc, 0xa7, 0xeb, { 0x85, 0xf5, 0x28, 0x9f, 0x09, 0xdc, 0xa7, 0xeb,
0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee }; 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee };
pSystemFunction006( passwd, lmhash ); pSystemFunction006( passwd, lmhash );
ok( !memcmp( lmhash, expect, sizeof(expect) ), ok( !memcmp( lmhash, expect, sizeof(expect) ),
"lmhash: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", "lmhash: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
lmhash[0], lmhash[1], lmhash[2], lmhash[3], lmhash[4], lmhash[5], lmhash[0], lmhash[1], lmhash[2], lmhash[3], lmhash[4], lmhash[5],
lmhash[6], lmhash[7], lmhash[8], lmhash[9], lmhash[10], lmhash[11], lmhash[6], lmhash[7], lmhash[8], lmhash[9], lmhash[10], lmhash[11],
lmhash[12], lmhash[13], lmhash[14], lmhash[15] ); lmhash[12], lmhash[13], lmhash[14], lmhash[15] );
} }
START_TEST(crypt_lmhash) START_TEST(crypt_lmhash)
{ {
HMODULE module; HMODULE module;
if (!(module = LoadLibrary("advapi32.dll"))) return; if (!(module = LoadLibrary("advapi32.dll"))) return;
pSystemFunction006 = (fnSystemFunction006)GetProcAddress( module, "SystemFunction006" ); pSystemFunction006 = (fnSystemFunction006)GetProcAddress( module, "SystemFunction006" );
if (!pSystemFunction006) goto out; if (!pSystemFunction006) goto out;
if (pSystemFunction006) if (pSystemFunction006)
test_SystemFunction006(); test_SystemFunction006();
out: out:
FreeLibrary( module ); FreeLibrary( module );
} }

View file

@ -1,109 +1,109 @@
/* /*
* Unit tests for MD4 functions * Unit tests for MD4 functions
* *
* Copyright 2004 Hans Leidekker * Copyright 2004 Hans Leidekker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include <stdio.h>
#include "wine/test.h" #include "wine/test.h"
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
typedef struct typedef struct
{ {
unsigned int buf[4]; unsigned int buf[4];
unsigned int i[2]; unsigned int i[2];
unsigned char in[64]; unsigned char in[64];
unsigned char digest[16]; unsigned char digest[16];
} MD4_CTX; } MD4_CTX;
typedef VOID (WINAPI *fnMD4Init)( MD4_CTX *ctx ); typedef VOID (WINAPI *fnMD4Init)( MD4_CTX *ctx );
typedef VOID (WINAPI *fnMD4Update)( MD4_CTX *ctx, const unsigned char *src, const int len ); typedef VOID (WINAPI *fnMD4Update)( MD4_CTX *ctx, const unsigned char *src, const int len );
typedef VOID (WINAPI *fnMD4Final)( MD4_CTX *ctx ); typedef VOID (WINAPI *fnMD4Final)( MD4_CTX *ctx );
fnMD4Init pMD4Init; fnMD4Init pMD4Init;
fnMD4Update pMD4Update; fnMD4Update pMD4Update;
fnMD4Final pMD4Final; fnMD4Final pMD4Final;
#define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD4_CTX, in ) ) #define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD4_CTX, in ) )
void test_md4_ctx() void test_md4_ctx()
{ {
static unsigned char message[] = static unsigned char message[] =
"In our Life there's If" "In our Life there's If"
"In our beliefs there's Lie" "In our beliefs there's Lie"
"In our business there is Sin" "In our business there is Sin"
"In our bodies, there is Die"; "In our bodies, there is Die";
int size = strlen( message ); int size = strlen( message );
HMODULE module; HMODULE module;
MD4_CTX ctx; MD4_CTX ctx;
MD4_CTX ctx_initialized = MD4_CTX ctx_initialized =
{ {
{ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }, { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 },
{ 0, 0 } { 0, 0 }
}; };
MD4_CTX ctx_update1 = MD4_CTX ctx_update1 =
{ {
{ 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd }, { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd },
{ 0x00000338, 0 } { 0x00000338, 0 }
}; };
MD4_CTX ctx_update2 = MD4_CTX ctx_update2 =
{ {
{ 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 }, { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 },
{ 0x00000670, 0 } { 0x00000670, 0 }
}; };
unsigned char expect[16] = unsigned char expect[16] =
{ 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf, { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf,
0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda }; 0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda };
if (!(module = LoadLibrary( "advapi32.dll" ))) return; if (!(module = LoadLibrary( "advapi32.dll" ))) return;
pMD4Init = (fnMD4Init)GetProcAddress( module, "MD4Init" ); pMD4Init = (fnMD4Init)GetProcAddress( module, "MD4Init" );
pMD4Update = (fnMD4Update)GetProcAddress( module, "MD4Update" ); pMD4Update = (fnMD4Update)GetProcAddress( module, "MD4Update" );
pMD4Final = (fnMD4Final)GetProcAddress( module, "MD4Final" ); pMD4Final = (fnMD4Final)GetProcAddress( module, "MD4Final" );
if (!pMD4Init || !pMD4Update || !pMD4Final) goto out; if (!pMD4Init || !pMD4Update || !pMD4Final) goto out;
memset( &ctx, 0, sizeof(ctx) ); memset( &ctx, 0, sizeof(ctx) );
pMD4Init( &ctx ); pMD4Init( &ctx );
ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" ); ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
pMD4Update( &ctx, message, size ); pMD4Update( &ctx, message, size );
ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" ); ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
pMD4Update( &ctx, message, size ); pMD4Update( &ctx, message, size );
ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" ); ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
pMD4Final( &ctx ); pMD4Final( &ctx );
ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" ); ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" ); ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
out: out:
FreeLibrary( module ); FreeLibrary( module );
} }
START_TEST(crypt_md4) START_TEST(crypt_md4)
{ {
test_md4_ctx(); test_md4_ctx();
} }

View file

@ -1,109 +1,109 @@
/* /*
* Unit tests for MD5 functions * Unit tests for MD5 functions
* *
* Copyright 2004 Hans Leidekker * Copyright 2004 Hans Leidekker
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include <stdio.h>
#include "wine/test.h" #include "wine/test.h"
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
typedef struct typedef struct
{ {
unsigned int i[2]; unsigned int i[2];
unsigned int buf[4]; unsigned int buf[4];
unsigned char in[64]; unsigned char in[64];
unsigned char digest[16]; unsigned char digest[16];
} MD5_CTX; } MD5_CTX;
typedef VOID (WINAPI *fnMD5Init)( MD5_CTX *ctx ); typedef VOID (WINAPI *fnMD5Init)( MD5_CTX *ctx );
typedef VOID (WINAPI *fnMD5Update)( MD5_CTX *ctx, const unsigned char *src, const int len ); typedef VOID (WINAPI *fnMD5Update)( MD5_CTX *ctx, const unsigned char *src, const int len );
typedef VOID (WINAPI *fnMD5Final)( MD5_CTX *ctx ); typedef VOID (WINAPI *fnMD5Final)( MD5_CTX *ctx );
fnMD5Init pMD5Init; fnMD5Init pMD5Init;
fnMD5Update pMD5Update; fnMD5Update pMD5Update;
fnMD5Final pMD5Final; fnMD5Final pMD5Final;
#define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD5_CTX, in ) ) #define ctxcmp( a, b ) memcmp( (char*)a, (char*)b, FIELD_OFFSET( MD5_CTX, in ) )
void test_md5_ctx() void test_md5_ctx()
{ {
static unsigned char message[] = static unsigned char message[] =
"In our Life there's If" "In our Life there's If"
"In our beliefs there's Lie" "In our beliefs there's Lie"
"In our business there is Sin" "In our business there is Sin"
"In our bodies, there is Die"; "In our bodies, there is Die";
int size = strlen( message ); int size = strlen( message );
HMODULE module; HMODULE module;
MD5_CTX ctx; MD5_CTX ctx;
MD5_CTX ctx_initialized = MD5_CTX ctx_initialized =
{ {
{ 0, 0 }, { 0, 0 },
{ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 } { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }
}; };
MD5_CTX ctx_update1 = MD5_CTX ctx_update1 =
{ {
{ 0x00000338, 0 }, { 0x00000338, 0 },
{ 0x068cb64d, 0xb7a05790, 0x426979ee, 0xed67e221 } { 0x068cb64d, 0xb7a05790, 0x426979ee, 0xed67e221 }
}; };
MD5_CTX ctx_update2 = MD5_CTX ctx_update2 =
{ {
{ 0x00000670, 0 }, { 0x00000670, 0 },
{ 0x2f7afe58, 0xcc3e9315, 0x709c465c, 0xbf6414c8 } { 0x2f7afe58, 0xcc3e9315, 0x709c465c, 0xbf6414c8 }
}; };
unsigned char expect[16] = unsigned char expect[16] =
{ 0x43, 0x03, 0xdd, 0x8c, 0x60, 0xd9, 0x3a, 0x22, { 0x43, 0x03, 0xdd, 0x8c, 0x60, 0xd9, 0x3a, 0x22,
0x0b, 0x28, 0xd0, 0xb2, 0x65, 0x93, 0xd0, 0x36 }; 0x0b, 0x28, 0xd0, 0xb2, 0x65, 0x93, 0xd0, 0x36 };
if (!(module = LoadLibrary( "advapi32.dll" ))) return; if (!(module = LoadLibrary( "advapi32.dll" ))) return;
pMD5Init = (fnMD5Init)GetProcAddress( module, "MD5Init" ); pMD5Init = (fnMD5Init)GetProcAddress( module, "MD5Init" );
pMD5Update = (fnMD5Update)GetProcAddress( module, "MD5Update" ); pMD5Update = (fnMD5Update)GetProcAddress( module, "MD5Update" );
pMD5Final = (fnMD5Final)GetProcAddress( module, "MD5Final" ); pMD5Final = (fnMD5Final)GetProcAddress( module, "MD5Final" );
if (!pMD5Init || !pMD5Update || !pMD5Final) goto out; if (!pMD5Init || !pMD5Update || !pMD5Final) goto out;
memset( &ctx, 0, sizeof(ctx) ); memset( &ctx, 0, sizeof(ctx) );
pMD5Init( &ctx ); pMD5Init( &ctx );
ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" ); ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" );
pMD5Update( &ctx, message, size ); pMD5Update( &ctx, message, size );
ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" ); ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" );
pMD5Update( &ctx, message, size ); pMD5Update( &ctx, message, size );
ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" ); ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" );
pMD5Final( &ctx ); pMD5Final( &ctx );
ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" ); ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" );
ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" ); ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" );
out: out:
FreeLibrary( module ); FreeLibrary( module );
} }
START_TEST(crypt_md5) START_TEST(crypt_md5)
{ {
test_md5_ctx(); test_md5_ctx();
} }

View file

@ -1,81 +1,81 @@
/* /*
* Unit tests for SHA functions * Unit tests for SHA functions
* *
* Copyright (c) 2004 Filip Navara * Copyright (c) 2004 Filip Navara
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdarg.h> #include <stdarg.h>
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
#include "wine/test.h" #include "wine/test.h"
typedef struct { typedef struct {
ULONG Unknown[6]; ULONG Unknown[6];
ULONG State[5]; ULONG State[5];
ULONG Count[2]; ULONG Count[2];
UCHAR Buffer[64]; UCHAR Buffer[64];
} SHA_CTX, *PSHA_CTX; } SHA_CTX, *PSHA_CTX;
#define ctxcmp(a,b) memcmp((char*)a, (char*)b, FIELD_OFFSET(SHA_CTX, Buffer)) #define ctxcmp(a,b) memcmp((char*)a, (char*)b, FIELD_OFFSET(SHA_CTX, Buffer))
static void test_sha_ctx(void) static void test_sha_ctx(void)
{ {
FARPROC pA_SHAInit, pA_SHAUpdate, pA_SHAFinal; FARPROC pA_SHAInit, pA_SHAUpdate, pA_SHAFinal;
static const char test_buffer[] = "In our Life there's If" static const char test_buffer[] = "In our Life there's If"
"In our beliefs there's Lie" "In our beliefs there's Lie"
"In our business there is Sin" "In our business there is Sin"
"In our bodies, there is Die"; "In our bodies, there is Die";
ULONG test_buffer_size = strlen(test_buffer); ULONG test_buffer_size = strlen(test_buffer);
HMODULE hmod; HMODULE hmod;
SHA_CTX ctx; SHA_CTX ctx;
SHA_CTX ctx_initialized = {{0, 0, 0, 0, 0}, {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0}, {0, 0}}; SHA_CTX ctx_initialized = {{0, 0, 0, 0, 0}, {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0}, {0, 0}};
SHA_CTX ctx_update1 = {{0, 0, 0, 0, 0}, {0xdbe5eba8, 0x6b4335ca, 0xf7c94abe, 0xc9f34e31, 0x311023f0}, {0, 0x67}}; SHA_CTX ctx_update1 = {{0, 0, 0, 0, 0}, {0xdbe5eba8, 0x6b4335ca, 0xf7c94abe, 0xc9f34e31, 0x311023f0}, {0, 0x67}};
SHA_CTX ctx_update2 = {{0, 0, 0, 0, 0}, {0x5ecc818d, 0x52498169, 0xf6758559, 0xd035a164, 0x871dd125}, {0, 0xce}}; SHA_CTX ctx_update2 = {{0, 0, 0, 0, 0}, {0x5ecc818d, 0x52498169, 0xf6758559, 0xd035a164, 0x871dd125}, {0, 0xce}};
ULONG result[5]; ULONG result[5];
ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb}; ULONG result_correct[5] = {0xe014f93, 0xe09791ec, 0x6dcf96c8, 0x8e9385fc, 0x1611c1bb};
hmod = LoadLibrary("advapi32.dll"); hmod = LoadLibrary("advapi32.dll");
pA_SHAInit = GetProcAddress(hmod, "A_SHAInit"); pA_SHAInit = GetProcAddress(hmod, "A_SHAInit");
pA_SHAUpdate = GetProcAddress(hmod, "A_SHAUpdate"); pA_SHAUpdate = GetProcAddress(hmod, "A_SHAUpdate");
pA_SHAFinal = GetProcAddress(hmod, "A_SHAFinal"); pA_SHAFinal = GetProcAddress(hmod, "A_SHAFinal");
if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal) return; if (!pA_SHAInit || !pA_SHAUpdate || !pA_SHAFinal) return;
RtlZeroMemory(&ctx, sizeof(ctx)); RtlZeroMemory(&ctx, sizeof(ctx));
pA_SHAInit(&ctx); pA_SHAInit(&ctx);
ok(!ctxcmp(&ctx, &ctx_initialized), "invalid initialization\n"); ok(!ctxcmp(&ctx, &ctx_initialized), "invalid initialization\n");
pA_SHAUpdate(&ctx, test_buffer, test_buffer_size); pA_SHAUpdate(&ctx, test_buffer, test_buffer_size);
ok(!ctxcmp(&ctx, &ctx_update1), "update doesn't work correctly\n"); ok(!ctxcmp(&ctx, &ctx_update1), "update doesn't work correctly\n");
pA_SHAUpdate(&ctx, test_buffer, test_buffer_size); pA_SHAUpdate(&ctx, test_buffer, test_buffer_size);
ok(!ctxcmp(&ctx, &ctx_update2), "update doesn't work correctly\n"); ok(!ctxcmp(&ctx, &ctx_update2), "update doesn't work correctly\n");
pA_SHAFinal(&ctx, result); pA_SHAFinal(&ctx, result);
ok(!ctxcmp(&ctx, &ctx_initialized), "context hasn't been reinitialized\n"); ok(!ctxcmp(&ctx, &ctx_initialized), "context hasn't been reinitialized\n");
ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n"); ok(!memcmp(result, result_correct, sizeof(result)), "incorrect result\n");
FreeLibrary(hmod); FreeLibrary(hmod);
} }
START_TEST(crypt_sha) START_TEST(crypt_sha)
{ {
test_sha_ctx(); test_sha_ctx();
} }

View file

@ -1,358 +1,451 @@
/* /*
* Unit tests for registry functions * Unit tests for registry functions
* *
* Copyright (c) 2002 Alexandre Julliard * Copyright (c) 2002 Alexandre Julliard
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <assert.h> #include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include "wine/test.h" #include "wine/test.h"
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winreg.h" #include "winreg.h"
#include "winerror.h" #include "winerror.h"
static HKEY hkey_main; static HKEY hkey_main;
static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1"; static const char * sTestpath1 = "%LONGSYSTEMVAR%\\subdir1";
static const char * sTestpath2 = "%FOO%\\subdir1"; static const char * sTestpath2 = "%FOO%\\subdir1";
/* delete key and all its subkeys */ /* delete key and all its subkeys */
static DWORD delete_key( HKEY hkey ) static DWORD delete_key( HKEY hkey )
{ {
char name[MAX_PATH]; char name[MAX_PATH];
DWORD ret; DWORD ret;
while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name)))) while (!(ret = RegEnumKeyA(hkey, 0, name, sizeof(name))))
{ {
HKEY tmp; HKEY tmp;
if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp ))) if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ENUMERATE_SUB_KEYS, &tmp )))
{ {
ret = delete_key( tmp ); ret = delete_key( tmp );
RegCloseKey( tmp ); RegCloseKey( tmp );
} }
if (ret) break; if (ret) break;
} }
if (ret != ERROR_NO_MORE_ITEMS) return ret; if (ret != ERROR_NO_MORE_ITEMS) return ret;
RegDeleteKeyA( hkey, NULL ); RegDeleteKeyA( hkey, "" );
return 0; return 0;
} }
static void setup_main_key(void) static void setup_main_key(void)
{ {
if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main ); if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )) delete_key( hkey_main );
assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main )); assert (!RegCreateKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkey_main ));
} }
static void create_test_entries(void) static void create_test_entries(void)
{ {
SetEnvironmentVariableA("LONGSYSTEMVAR", "bar"); SetEnvironmentVariableA("LONGSYSTEMVAR", "bar");
SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString"); SetEnvironmentVariableA("FOO", "ImARatherLongButIndeedNeededString");
ok(!RegSetValueExA(hkey_main,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1), ok(!RegSetValueExA(hkey_main,"Test1",0,REG_EXPAND_SZ, sTestpath1, strlen(sTestpath1)+1),
"RegSetValueExA failed\n"); "RegSetValueExA failed\n");
ok(!RegSetValueExA(hkey_main,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1), ok(!RegSetValueExA(hkey_main,"Test2",0,REG_SZ, sTestpath1, strlen(sTestpath1)+1),
"RegSetValueExA failed\n"); "RegSetValueExA failed\n");
ok(!RegSetValueExA(hkey_main,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1), ok(!RegSetValueExA(hkey_main,"Test3",0,REG_EXPAND_SZ, sTestpath2, strlen(sTestpath2)+1),
"RegSetValueExA failed\n"); "RegSetValueExA failed\n");
} }
static void test_enum_value(void) static void test_enum_value(void)
{ {
DWORD res; DWORD res;
char value[20], data[20]; HKEY test_key;
WCHAR valueW[20], dataW[20]; char value[20], data[20];
DWORD val_count, data_count, type; WCHAR valueW[20], dataW[20];
static const WCHAR foobarW[] = {'f','o','o','b','a','r',0}; DWORD val_count, data_count, type;
static const WCHAR testW[] = {'T','e','s','t',0}; static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0}; static const WCHAR testW[] = {'T','e','s','t',0};
static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
/* check NULL data with zero length */
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 ); /* create the working key for new 'Test' value */
if (GetVersion() & 0x80000000) res = RegCreateKeyA( hkey_main, "TestKey", &test_key );
ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res ); ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res);
else
ok( !res, "RegSetValueExA returned %ld\n", res ); /* check NULL data with zero length */
res = RegSetValueExA( hkey_main, "Test", 0, REG_EXPAND_SZ, NULL, 0 ); res = RegSetValueExA( test_key, "Test", 0, REG_SZ, NULL, 0 );
ok( !res, "RegSetValueExA returned %ld\n", res ); if (GetVersion() & 0x80000000)
res = RegSetValueExA( hkey_main, "Test", 0, REG_BINARY, NULL, 0 ); ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %ld\n", res );
ok( !res, "RegSetValueExA returned %ld\n", res ); else
ok( !res, "RegSetValueExA returned %ld\n", res );
res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 ); res = RegSetValueExA( test_key, "Test", 0, REG_EXPAND_SZ, NULL, 0 );
ok( res == 0, "RegSetValueExA failed error %ld\n", res ); ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
res = RegSetValueExA( test_key, "Test", 0, REG_BINARY, NULL, 0 );
/* overflow both name and data */ ok( ERROR_SUCCESS == res || ERROR_INVALID_PARAMETER == res, "RegSetValueExA returned %ld\n", res );
val_count = 2;
data_count = 2; res = RegSetValueExA( test_key, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
type = 1234; ok( res == 0, "RegSetValueExA failed error %ld\n", res );
strcpy( value, "xxxxxxxxxx" );
strcpy( data, "xxxxxxxxxx" ); /* overflow both name and data */
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count ); val_count = 2;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 2;
ok( val_count == 2, "val_count set to %ld\n", val_count ); type = 1234;
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count ); strcpy( value, "xxxxxxxxxx" );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); strcpy( data, "xxxxxxxxxx" );
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value ); res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data ); ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
ok( val_count == 2, "val_count set to %ld\n", val_count );
/* overflow name */ ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
val_count = 3; ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
data_count = 20; ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
type = 1234; ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
strcpy( value, "xxxxxxxxxx" );
strcpy( data, "xxxxxxxxxx" ); /* overflow name */
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count ); val_count = 3;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 20;
/* Win9x returns 2 as specified by MSDN but NT returns 3... */ type = 1234;
ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count ); strcpy( value, "xxxxxxxxxx" );
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count ); strcpy( data, "xxxxxxxxxx" );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
#if 0 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
/* v5.1.2600.0 (XP Home) does not touch value or data in this case */ /* Win9x returns 2 as specified by MSDN but NT returns 3... */
ok( !strcmp( value, "Te" ), "value set to '%s' instead of 'Te'\n", value ); ok( val_count == 2 || val_count == 3, "val_count set to %ld\n", val_count );
ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data ); ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
#endif ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
#if 0
/* overflow empty name */ /* v5.1.2600.0 (XP Home) does not touch value or data in this case */
val_count = 0; ok( !strcmp( value, "Te" ), "value set to '%s' instead of 'Te'\n", value );
data_count = 20; ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
type = 1234; #endif
strcpy( value, "xxxxxxxxxx" );
strcpy( data, "xxxxxxxxxx" ); /* overflow empty name */
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count ); val_count = 0;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 20;
ok( val_count == 0, "val_count set to %ld\n", val_count ); type = 1234;
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count ); strcpy( value, "xxxxxxxxxx" );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); strcpy( data, "xxxxxxxxxx" );
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value ); res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
#if 0 ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
/* v5.1.2600.0 (XP Home) does not touch data in this case */ ok( val_count == 0, "val_count set to %ld\n", val_count );
ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data ); ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
#endif ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
/* overflow data */ #if 0
val_count = 20; /* v5.1.2600.0 (XP Home) does not touch data in this case */
data_count = 2; ok( !strcmp( data, "foobar" ), "data set to '%s' instead of 'foobar'\n", data );
type = 1234; #endif
strcpy( value, "xxxxxxxxxx" );
strcpy( data, "xxxxxxxxxx" ); /* overflow data */
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count ); val_count = 20;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 2;
ok( val_count == 20, "val_count set to %ld\n", val_count ); type = 1234;
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count ); strcpy( value, "xxxxxxxxxx" );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); strcpy( data, "xxxxxxxxxx" );
ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value ); res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data ); ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
ok( val_count == 20, "val_count set to %ld\n", val_count );
/* no overflow */ ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
val_count = 20; ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
data_count = 20; ok( !strcmp( value, "xxxxxxxxxx" ), "value set to '%s'\n", value );
type = 1234; ok( !strcmp( data, "xxxxxxxxxx" ), "data set to '%s'\n", data );
strcpy( value, "xxxxxxxxxx" );
strcpy( data, "xxxxxxxxxx" ); /* no overflow */
res = RegEnumValueA( hkey_main, 0, value, &val_count, NULL, &type, data, &data_count ); val_count = 20;
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res ); data_count = 20;
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count ); type = 1234;
ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count ); strcpy( value, "xxxxxxxxxx" );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); strcpy( data, "xxxxxxxxxx" );
ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value ); res = RegEnumValueA( test_key, 0, value, &val_count, NULL, &type, data, &data_count );
ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data ); ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
/* Unicode tests */ ok( data_count == 7, "data_count set to %ld instead of 7\n", data_count );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
SetLastError(0); ok( !strcmp( value, "Test" ), "value is '%s' instead of Test\n", value );
res = RegSetValueExW( hkey_main, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) ); ok( !strcmp( data, "foobar" ), "data is '%s' instead of foobar\n", data );
if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
goto CLEANUP; /* Unicode tests */
ok( res == 0, "RegSetValueExW failed error %ld\n", res );
SetLastError(0);
/* overflow both name and data */ res = RegSetValueExW( test_key, testW, 0, REG_SZ, (const BYTE *)foobarW, 7*sizeof(WCHAR) );
val_count = 2; if (res==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
data_count = 2; return;
type = 1234; ok( res == 0, "RegSetValueExW failed error %ld\n", res );
memcpy( valueW, xxxW, sizeof(xxxW) );
memcpy( dataW, xxxW, sizeof(xxxW) ); /* overflow both name and data */
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count ); val_count = 2;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 2;
ok( val_count == 2, "val_count set to %ld\n", val_count ); type = 1234;
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count ); memcpy( valueW, xxxW, sizeof(xxxW) );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); memcpy( dataW, xxxW, sizeof(xxxW) );
ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" ); res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" ); ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
ok( val_count == 2, "val_count set to %ld\n", val_count );
/* overflow name */ ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
val_count = 3; ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
data_count = 20; ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
type = 1234; ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
memcpy( valueW, xxxW, sizeof(xxxW) );
memcpy( dataW, xxxW, sizeof(xxxW) ); /* overflow name */
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count ); val_count = 3;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 20;
ok( val_count == 3, "val_count set to %ld\n", val_count ); type = 1234;
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count ); memcpy( valueW, xxxW, sizeof(xxxW) );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); memcpy( dataW, xxxW, sizeof(xxxW) );
ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" ); res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" ); ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
ok( val_count == 3, "val_count set to %ld\n", val_count );
/* overflow data */ ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
val_count = 20; ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
data_count = 2; ok( !memcmp( valueW, xxxW, sizeof(xxxW) ), "value modified\n" );
type = 1234; ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
memcpy( valueW, xxxW, sizeof(xxxW) );
memcpy( dataW, xxxW, sizeof(xxxW) ); /* overflow data */
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count ); val_count = 20;
ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res ); data_count = 2;
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count ); type = 1234;
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count ); memcpy( valueW, xxxW, sizeof(xxxW) );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); memcpy( dataW, xxxW, sizeof(xxxW) );
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" ); res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" ); ok( res == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %ld\n", res );
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
/* no overflow */ ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
val_count = 20; ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
data_count = 20; ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
type = 1234; ok( !memcmp( dataW, xxxW, sizeof(xxxW) ), "data modified\n" );
memcpy( valueW, xxxW, sizeof(xxxW) );
memcpy( dataW, xxxW, sizeof(xxxW) ); /* no overflow */
res = RegEnumValueW( hkey_main, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count ); val_count = 20;
ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res ); data_count = 20;
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count ); type = 1234;
ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count ); memcpy( valueW, xxxW, sizeof(xxxW) );
ok( type == REG_SZ, "type %ld is not REG_SZ\n", type ); memcpy( dataW, xxxW, sizeof(xxxW) );
ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" ); res = RegEnumValueW( test_key, 0, valueW, &val_count, NULL, &type, (BYTE*)dataW, &data_count );
ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" ); ok( res == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", res );
ok( val_count == 4, "val_count set to %ld instead of 4\n", val_count );
CLEANUP: ok( data_count == 7*sizeof(WCHAR), "data_count set to %ld instead of 7*sizeof(WCHAR)\n", data_count );
/* cleanup */ ok( type == REG_SZ, "type %ld is not REG_SZ\n", type );
RegDeleteValueA( hkey_main, "Test" ); ok( !memcmp( valueW, testW, sizeof(testW) ), "value is not 'Test'\n" );
} ok( !memcmp( dataW, foobarW, sizeof(foobarW) ), "data is not 'foobar'\n" );
}
static void test_query_value_ex()
{ static void test_query_value_ex()
DWORD ret; {
DWORD size; DWORD ret;
DWORD type; DWORD size;
DWORD type;
ret = RegQueryValueExA(hkey_main, "Test2", NULL, &type, NULL, &size);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegQueryValueExA(hkey_main, "Test2", NULL, &type, NULL, &size);
ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ok(type == REG_SZ, "type %ld is not REG_SZ\n", type); ok(size == strlen(sTestpath1) + 1, "(%ld,%ld)\n", (DWORD)strlen(sTestpath1) + 1, size);
} ok(type == REG_SZ, "type %ld is not REG_SZ\n", type);
}
static void test_reg_open_key()
{ static void test_reg_open_key()
DWORD ret = 0; {
HKEY hkResult = NULL; DWORD ret = 0;
HKEY hkPreserve = NULL; HKEY hkResult = NULL;
HKEY hkPreserve = NULL;
/* successful open */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult); /* successful open */
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
ok(hkResult != NULL, "expected hkResult != NULL\n"); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
hkPreserve = hkResult; ok(hkResult != NULL, "expected hkResult != NULL\n");
hkPreserve = hkResult;
/* open same key twice */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult); /* open same key twice */
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkResult);
ok(hkResult != hkPreserve && hkResult != NULL, ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
"expected hkResult != hkPreserve and hkResult != NULL\n"); ok(hkResult != hkPreserve, "epxected hkResult != hkPreserve\n");
RegCloseKey(hkResult); ok(hkResult != NULL, "hkResult != NULL\n");
RegCloseKey(hkResult);
/* open nonexistent key
* check that hkResult is set to NULL /* open nonexistent key
*/ * check that hkResult is set to NULL
hkResult = hkPreserve; */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
ok(hkResult == NULL, "expected hkResult == NULL\n"); ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
ok(hkResult == NULL, "expected hkResult == NULL\n");
/* open the same nonexistent key again to make sure the key wasn't created */
hkResult = hkPreserve; /* open the same nonexistent key again to make sure the key wasn't created */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Nonexistent", &hkResult);
ok(hkResult == NULL, "expected hkResult == NULL\n"); ok(ret == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %ld\n", ret);
ok(hkResult == NULL, "expected hkResult == NULL\n");
/* send in NULL lpSubKey
* check that hkResult receives the value of hKey /* send in NULL lpSubKey
*/ * check that hkResult receives the value of hKey
hkResult = hkPreserve; */
ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, NULL, &hkResult);
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n"); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
/* send empty-string in lpSubKey */
hkResult = hkPreserve; /* send empty-string in lpSubKey */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "", &hkResult);
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n"); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ok(hkResult == HKEY_CURRENT_USER, "expected hkResult == HKEY_CURRENT_USER\n");
/* send in NULL lpSubKey and NULL hKey
* hkResult is set to NULL /* send in NULL lpSubKey and NULL hKey
*/ * hkResult is set to NULL
hkResult = hkPreserve; */
ret = RegOpenKeyA(NULL, NULL, &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(NULL, NULL, &hkResult);
ok(hkResult == NULL, "expected hkResult == NULL\n"); ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ok(hkResult == NULL, "expected hkResult == NULL\n");
/* only send NULL hKey
* the value of hkResult remains unchanged /* only send NULL hKey
*/ * the value of hkResult remains unchanged
hkResult = hkPreserve; */
ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult); hkResult = hkPreserve;
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret); ret = RegOpenKeyA(NULL, "Software\\Wine\\Test", &hkResult);
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n"); ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
RegCloseKey(hkResult); "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
/* send in NULL hkResult */ RegCloseKey(hkResult);
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret); /* send in NULL hkResult */
} ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
ok(ret == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %ld\n", ret);
static void test_reg_close_key() }
{
DWORD ret = 0; static void test_reg_close_key()
HKEY hkHandle; {
DWORD ret = 0;
/* successfully close key HKEY hkHandle;
* hkHandle remains changed after call to RegCloseKey
*/ /* successfully close key
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle); * hkHandle remains changed after call to RegCloseKey
ret = RegCloseKey(hkHandle); */
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", &hkHandle);
ret = RegCloseKey(hkHandle);
/* try to close the key twice */ ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ret = RegCloseKey(hkHandle);
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret); /* try to close the key twice */
ret = RegCloseKey(hkHandle); /* Windows 95 doesn't mind. */
/* try to close a NULL handle */ ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_SUCCESS,
ret = RegCloseKey(NULL); "expected ERROR_INVALID_HANDLE or ERROR_SUCCESS, got %ld\n", ret);
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %ld\n", ret);
} /* try to close a NULL handle */
ret = RegCloseKey(NULL);
START_TEST(registry) ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
{ "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %ld\n", ret);
setup_main_key(); }
create_test_entries();
test_enum_value(); static void test_reg_delete_key()
test_query_value_ex(); {
test_reg_open_key(); DWORD ret;
test_reg_close_key();
ret = RegDeleteKey(hkey_main, NULL);
/* cleanup */ ok(ret == ERROR_INVALID_PARAMETER || ret == ERROR_ACCESS_DENIED,
delete_key( hkey_main ); "expected ERROR_INVALID_PARAMETER or ERROR_ACCESS_DENIED, got %ld\n", ret);
} }
static void test_reg_save_key()
{
DWORD ret;
ret = RegSaveKey(hkey_main, "saved_key", NULL);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
}
static void test_reg_load_key()
{
DWORD ret;
HKEY hkHandle;
ret = RegLoadKey(HKEY_LOCAL_MACHINE, "Test", "saved_key");
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "Test", &hkHandle);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
RegCloseKey(hkHandle);
}
static void test_reg_unload_key()
{
DWORD ret;
ret = RegUnLoadKey(HKEY_LOCAL_MACHINE, "Test");
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", ret);
DeleteFile("saved_key");
}
static BOOL set_privileges(LPCSTR privilege, BOOL set)
{
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
return FALSE;
if(!LookupPrivilegeValue(NULL, privilege, &luid))
{
CloseHandle(hToken);
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (set)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
if (GetLastError() != ERROR_SUCCESS)
{
CloseHandle(hToken);
return FALSE;
}
CloseHandle(hToken);
return TRUE;
}
START_TEST(registry)
{
setup_main_key();
create_test_entries();
test_enum_value();
#if 0
test_query_value_ex();
test_reg_open_key();
test_reg_close_key();
test_reg_delete_key();
/* SaveKey/LoadKey require the SE_BACKUP_NAME privilege to be set */
if (set_privileges(SE_BACKUP_NAME, TRUE) &&
set_privileges(SE_RESTORE_NAME, TRUE))
{
test_reg_save_key();
test_reg_load_key();
test_reg_unload_key();
set_privileges(SE_BACKUP_NAME, FALSE);
set_privileges(SE_RESTORE_NAME, FALSE);
}
#endif
/* cleanup */
delete_key( hkey_main );
}

View file

@ -1,408 +1,443 @@
/* /*
* Unit tests for security functions * Unit tests for security functions
* *
* Copyright (c) 2004 Mike McCormack * Copyright (c) 2004 Mike McCormack
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include <stdio.h>
#include "wine/test.h" #include "wine/test.h"
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
#include "aclapi.h" #include "aclapi.h"
#include "winnt.h" #include "winnt.h"
typedef BOOL (WINAPI *fnBuildTrusteeWithSidA)( TRUSTEE *trustee, PSID psid ); typedef BOOL (WINAPI *fnBuildTrusteeWithSidA)( TRUSTEE *trustee, PSID psid );
typedef BOOL (WINAPI *fnBuildTrusteeWithNameA)( TRUSTEE *trustee, LPSTR str ); typedef BOOL (WINAPI *fnBuildTrusteeWithNameA)( TRUSTEE *trustee, LPSTR str );
typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str ); typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid ); typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid );
typedef BOOL (WINAPI *fnGetFileSecurityA)(LPCSTR, SECURITY_INFORMATION,
static HMODULE hmod; PSECURITY_DESCRIPTOR, DWORD, LPDWORD);
fnBuildTrusteeWithSidA pBuildTrusteeWithSidA; static HMODULE hmod;
fnBuildTrusteeWithNameA pBuildTrusteeWithNameA;
fnConvertSidToStringSidA pConvertSidToStringSidA; fnBuildTrusteeWithSidA pBuildTrusteeWithSidA;
fnConvertStringSidToSidA pConvertStringSidToSidA; fnBuildTrusteeWithNameA pBuildTrusteeWithNameA;
fnConvertSidToStringSidA pConvertSidToStringSidA;
struct sidRef fnConvertStringSidToSidA pConvertStringSidToSidA;
{ fnGetFileSecurityA pGetFileSecurityA;
SID_IDENTIFIER_AUTHORITY auth;
const char *refStr; struct sidRef
}; {
SID_IDENTIFIER_AUTHORITY auth;
static void init(void) const char *refStr;
{ };
hmod = GetModuleHandle("advapi32.dll");
} static void init(void)
{
void test_sid() hmod = GetModuleHandle("advapi32.dll");
{ }
struct sidRef refs[] = {
{ { {0x00,0x00,0x33,0x44,0x55,0x66} }, "S-1-860116326-1" }, void test_sid()
{ { {0x00,0x00,0x01,0x02,0x03,0x04} }, "S-1-16909060-1" }, {
{ { {0x00,0x00,0x00,0x01,0x02,0x03} }, "S-1-66051-1" }, struct sidRef refs[] = {
{ { {0x00,0x00,0x00,0x00,0x01,0x02} }, "S-1-258-1" }, { { {0x00,0x00,0x33,0x44,0x55,0x66} }, "S-1-860116326-1" },
{ { {0x00,0x00,0x00,0x00,0x00,0x02} }, "S-1-2-1" }, { { {0x00,0x00,0x01,0x02,0x03,0x04} }, "S-1-16909060-1" },
{ { {0x00,0x00,0x00,0x00,0x00,0x0c} }, "S-1-12-1" }, { { {0x00,0x00,0x00,0x01,0x02,0x03} }, "S-1-66051-1" },
}; { { {0x00,0x00,0x00,0x00,0x01,0x02} }, "S-1-258-1" },
const char noSubAuthStr[] = "S-1-5"; { { {0x00,0x00,0x00,0x00,0x00,0x02} }, "S-1-2-1" },
unsigned int i; { { {0x00,0x00,0x00,0x00,0x00,0x0c} }, "S-1-12-1" },
PSID psid = NULL; };
BOOL r; const char noSubAuthStr[] = "S-1-5";
LPSTR str = NULL; unsigned int i;
PSID psid = NULL;
pConvertSidToStringSidA = (fnConvertSidToStringSidA) BOOL r;
GetProcAddress( hmod, "ConvertSidToStringSidA" ); LPSTR str = NULL;
if( !pConvertSidToStringSidA )
return; pConvertSidToStringSidA = (fnConvertSidToStringSidA)
pConvertStringSidToSidA = (fnConvertStringSidToSidA) GetProcAddress( hmod, "ConvertSidToStringSidA" );
GetProcAddress( hmod, "ConvertStringSidToSidA" ); if( !pConvertSidToStringSidA )
if( !pConvertStringSidToSidA ) return;
return; pConvertStringSidToSidA = (fnConvertStringSidToSidA)
GetProcAddress( hmod, "ConvertStringSidToSidA" );
r = pConvertStringSidToSidA( NULL, NULL ); if( !pConvertStringSidToSidA )
ok( !r, "expected failure with NULL parameters\n" ); return;
if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
return; r = pConvertStringSidToSidA( NULL, NULL );
ok( GetLastError() == ERROR_INVALID_PARAMETER, ok( !r, "expected failure with NULL parameters\n" );
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n", if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
GetLastError() ); return;
ok( GetLastError() == ERROR_INVALID_PARAMETER,
r = pConvertStringSidToSidA( refs[0].refStr, NULL ); "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER, GetLastError() );
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
GetLastError() ); r = pConvertStringSidToSidA( refs[0].refStr, NULL );
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
r = pConvertStringSidToSidA( NULL, &str ); "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER, GetLastError() );
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
GetLastError() ); r = pConvertStringSidToSidA( NULL, &str );
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
r = pConvertStringSidToSidA( noSubAuthStr, &psid ); "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
ok( !r, GetLastError() );
"expected failure with no sub authorities\n" );
ok( GetLastError() == ERROR_INVALID_SID, r = pConvertStringSidToSidA( noSubAuthStr, &psid );
"expected GetLastError() is ERROR_INVALID_SID, got %ld\n", ok( !r,
GetLastError() ); "expected failure with no sub authorities\n" );
ok( GetLastError() == ERROR_INVALID_SID,
for( i = 0; i < sizeof(refs) / sizeof(refs[0]); i++ ) "expected GetLastError() is ERROR_INVALID_SID, got %ld\n",
{ GetLastError() );
PISID pisid;
for( i = 0; i < sizeof(refs) / sizeof(refs[0]); i++ )
r = AllocateAndInitializeSid( &refs[i].auth, 1,1,0,0,0,0,0,0,0, {
&psid ); PISID pisid;
ok( r, "failed to allocate sid\n" );
r = pConvertSidToStringSidA( psid, &str ); r = AllocateAndInitializeSid( &refs[i].auth, 1,1,0,0,0,0,0,0,0,
ok( r, "failed to convert sid\n" ); &psid );
ok( !strcmp( str, refs[i].refStr ), ok( r, "failed to allocate sid\n" );
"incorrect sid, expected %s, got %s\n", refs[i].refStr, str ); r = pConvertSidToStringSidA( psid, &str );
if( str ) ok( r, "failed to convert sid\n" );
LocalFree( str ); if (r)
if( psid ) {
FreeSid( psid ); ok( !strcmp( str, refs[i].refStr ),
"incorrect sid, expected %s, got %s\n", refs[i].refStr, str );
r = pConvertStringSidToSidA( refs[i].refStr, &psid ); LocalFree( str );
ok( r, "failed to parse sid string\n" ); }
pisid = (PISID)psid; if( psid )
ok( pisid && FreeSid( psid );
!memcmp( pisid->IdentifierAuthority.Value, refs[i].auth.Value,
sizeof(refs[i].auth) ), r = pConvertStringSidToSidA( refs[i].refStr, &psid );
"string sid %s didn't parse to expected value\n" ok( r, "failed to parse sid string\n" );
"(got 0x%04x%08lx, expected 0x%04x%08lx)\n", pisid = (PISID)psid;
refs[i].refStr, ok( pisid &&
MAKEWORD( pisid->IdentifierAuthority.Value[1], !memcmp( pisid->IdentifierAuthority.Value, refs[i].auth.Value,
pisid->IdentifierAuthority.Value[0] ), sizeof(refs[i].auth) ),
MAKELONG( MAKEWORD( pisid->IdentifierAuthority.Value[5], "string sid %s didn't parse to expected value\n"
pisid->IdentifierAuthority.Value[4] ), "(got 0x%04x%08lx, expected 0x%04x%08lx)\n",
MAKEWORD( pisid->IdentifierAuthority.Value[3], refs[i].refStr,
pisid->IdentifierAuthority.Value[2] ) ), MAKEWORD( pisid->IdentifierAuthority.Value[1],
MAKEWORD( refs[i].auth.Value[1], refs[i].auth.Value[0] ), pisid->IdentifierAuthority.Value[0] ),
MAKELONG( MAKEWORD( refs[i].auth.Value[5], refs[i].auth.Value[4] ), MAKELONG( MAKEWORD( pisid->IdentifierAuthority.Value[5],
MAKEWORD( refs[i].auth.Value[3], refs[i].auth.Value[2] ) ) ); pisid->IdentifierAuthority.Value[4] ),
if( psid ) MAKEWORD( pisid->IdentifierAuthority.Value[3],
LocalFree( psid ); pisid->IdentifierAuthority.Value[2] ) ),
} MAKEWORD( refs[i].auth.Value[1], refs[i].auth.Value[0] ),
} MAKELONG( MAKEWORD( refs[i].auth.Value[5], refs[i].auth.Value[4] ),
MAKEWORD( refs[i].auth.Value[3], refs[i].auth.Value[2] ) ) );
void test_trustee() if( psid )
{ LocalFree( psid );
TRUSTEE trustee; }
PSID psid; }
LPSTR str = "2jjj";
void test_trustee()
SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} }; {
TRUSTEE trustee;
pBuildTrusteeWithSidA = (fnBuildTrusteeWithSidA) PSID psid;
GetProcAddress( hmod, "BuildTrusteeWithSidA" ); LPSTR str = "2jjj";
pBuildTrusteeWithNameA = (fnBuildTrusteeWithNameA)
GetProcAddress( hmod, "BuildTrusteeWithNameA" ); SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} };
if( !pBuildTrusteeWithSidA || !pBuildTrusteeWithNameA)
return; pBuildTrusteeWithSidA = (fnBuildTrusteeWithSidA)
GetProcAddress( hmod, "BuildTrusteeWithSidA" );
if ( ! AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid ) ) pBuildTrusteeWithNameA = (fnBuildTrusteeWithNameA)
{ GetProcAddress( hmod, "BuildTrusteeWithNameA" );
trace( "failed to init SID\n" ); if( !pBuildTrusteeWithSidA || !pBuildTrusteeWithNameA)
return; return;
}
if ( ! AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid ) )
memset( &trustee, 0xff, sizeof trustee ); {
pBuildTrusteeWithSidA( &trustee, psid ); trace( "failed to init SID\n" );
return;
ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n"); }
ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
"MultipleTrusteeOperation wrong\n"); memset( &trustee, 0xff, sizeof trustee );
ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n"); pBuildTrusteeWithSidA( &trustee, psid );
ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" ); ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
FreeSid( psid ); ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
"MultipleTrusteeOperation wrong\n");
/* test BuildTrusteeWithNameA */ ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n");
memset( &trustee, 0xff, sizeof trustee ); ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
pBuildTrusteeWithNameA( &trustee, str ); ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" );
FreeSid( psid );
ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, /* test BuildTrusteeWithNameA */
"MultipleTrusteeOperation wrong\n"); memset( &trustee, 0xff, sizeof trustee );
ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n"); pBuildTrusteeWithNameA( &trustee, str );
ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
ok( trustee.ptstrName == str, "ptstrName wrong\n" ); ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
} ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
"MultipleTrusteeOperation wrong\n");
/* If the first isn't defined, assume none is */ ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n");
#ifndef SE_MIN_WELL_KNOWN_PRIVILEGE ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
#define SE_MIN_WELL_KNOWN_PRIVILEGE 2L ok( trustee.ptstrName == str, "ptstrName wrong\n" );
#define SE_CREATE_TOKEN_PRIVILEGE 2L }
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3L
#define SE_LOCK_MEMORY_PRIVILEGE 4L /* If the first isn't defined, assume none is */
#define SE_INCREASE_QUOTA_PRIVILEGE 5L #ifndef SE_MIN_WELL_KNOWN_PRIVILEGE
#define SE_MACHINE_ACCOUNT_PRIVILEGE 6L #define SE_MIN_WELL_KNOWN_PRIVILEGE 2L
#define SE_TCB_PRIVILEGE 7L #define SE_CREATE_TOKEN_PRIVILEGE 2L
#define SE_SECURITY_PRIVILEGE 8L #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3L
#define SE_TAKE_OWNERSHIP_PRIVILEGE 9L #define SE_LOCK_MEMORY_PRIVILEGE 4L
#define SE_LOAD_DRIVER_PRIVILEGE 10L #define SE_INCREASE_QUOTA_PRIVILEGE 5L
#define SE_SYSTEM_PROFILE_PRIVILEGE 11L #define SE_MACHINE_ACCOUNT_PRIVILEGE 6L
#define SE_SYSTEMTIME_PRIVILEGE 12L #define SE_TCB_PRIVILEGE 7L
#define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13L #define SE_SECURITY_PRIVILEGE 8L
#define SE_INC_BASE_PRIORITY_PRIVILEGE 14L #define SE_TAKE_OWNERSHIP_PRIVILEGE 9L
#define SE_CREATE_PAGEFILE_PRIVILEGE 15L #define SE_LOAD_DRIVER_PRIVILEGE 10L
#define SE_CREATE_PERMANENT_PRIVILEGE 16L #define SE_SYSTEM_PROFILE_PRIVILEGE 11L
#define SE_BACKUP_PRIVILEGE 17L #define SE_SYSTEMTIME_PRIVILEGE 12L
#define SE_RESTORE_PRIVILEGE 18L #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13L
#define SE_SHUTDOWN_PRIVILEGE 19L #define SE_INC_BASE_PRIORITY_PRIVILEGE 14L
#define SE_DEBUG_PRIVILEGE 20L #define SE_CREATE_PAGEFILE_PRIVILEGE 15L
#define SE_AUDIT_PRIVILEGE 21L #define SE_CREATE_PERMANENT_PRIVILEGE 16L
#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22L #define SE_BACKUP_PRIVILEGE 17L
#define SE_CHANGE_NOTIFY_PRIVILLEGE 23L #define SE_RESTORE_PRIVILEGE 18L
#define SE_REMOTE_SHUTDOWN_PRIVILEGE 24L #define SE_SHUTDOWN_PRIVILEGE 19L
#define SE_UNDOCK_PRIVILEGE 25L #define SE_DEBUG_PRIVILEGE 20L
#define SE_SYNC_AGENT_PRIVILEGE 26L #define SE_AUDIT_PRIVILEGE 21L
#define SE_ENABLE_DELEGATION_PRIVILEGE 27L #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22L
#define SE_MANAGE_VOLUME_PRIVILEGE 28L #define SE_CHANGE_NOTIFY_PRIVILLEGE 23L
#define SE_IMPERSONATE_PRIVILEGE 29L #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24L
#define SE_CREATE_GLOBAL_PRIVILEGE 30L #define SE_UNDOCK_PRIVILEGE 25L
#define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_GLOBAL_PRIVILEGE #define SE_SYNC_AGENT_PRIVILEGE 26L
#endif /* ndef SE_MIN_WELL_KNOWN_PRIVILEGE */ #define SE_ENABLE_DELEGATION_PRIVILEGE 27L
#define SE_MANAGE_VOLUME_PRIVILEGE 28L
static void test_allocateLuid(void) #define SE_IMPERSONATE_PRIVILEGE 29L
{ #define SE_CREATE_GLOBAL_PRIVILEGE 30L
BOOL (WINAPI *pAllocateLocallyUniqueId)(PLUID); #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_GLOBAL_PRIVILEGE
LUID luid1, luid2; #endif /* ndef SE_MIN_WELL_KNOWN_PRIVILEGE */
BOOL ret;
static void test_allocateLuid(void)
pAllocateLocallyUniqueId = (void*)GetProcAddress(hmod, "AllocateLocallyUniqueId"); {
if (!pAllocateLocallyUniqueId) return; BOOL (WINAPI *pAllocateLocallyUniqueId)(PLUID);
LUID luid1, luid2;
ret = pAllocateLocallyUniqueId(&luid1); BOOL ret;
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
return; pAllocateLocallyUniqueId = (void*)GetProcAddress(hmod, "AllocateLocallyUniqueId");
if (!pAllocateLocallyUniqueId) return;
ok(ret,
"AllocateLocallyUniqueId failed: %ld\n", GetLastError()); ret = pAllocateLocallyUniqueId(&luid1);
ret = pAllocateLocallyUniqueId(&luid2); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
ok( ret, return;
"AllocateLocallyUniqueId failed: %ld\n", GetLastError());
ok(luid1.LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE || luid1.HighPart != 0, ok(ret,
"AllocateLocallyUniqueId returned a well-known LUID\n"); "AllocateLocallyUniqueId failed: %ld\n", GetLastError());
ok(luid1.LowPart != luid2.LowPart || luid1.HighPart != luid2.HighPart, ret = pAllocateLocallyUniqueId(&luid2);
"AllocateLocallyUniqueId returned non-unique LUIDs\n"); ok( ret,
ret = pAllocateLocallyUniqueId(NULL); "AllocateLocallyUniqueId failed: %ld\n", GetLastError());
ok( !ret && GetLastError() == ERROR_NOACCESS, ok(luid1.LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE || luid1.HighPart != 0,
"AllocateLocallyUniqueId(NULL) didn't return ERROR_NOACCESS: %ld\n", "AllocateLocallyUniqueId returned a well-known LUID\n");
GetLastError()); ok(luid1.LowPart != luid2.LowPart || luid1.HighPart != luid2.HighPart,
} "AllocateLocallyUniqueId returned non-unique LUIDs\n");
ret = pAllocateLocallyUniqueId(NULL);
static void test_lookupPrivilegeName(void) ok( !ret && GetLastError() == ERROR_NOACCESS,
{ "AllocateLocallyUniqueId(NULL) didn't return ERROR_NOACCESS: %ld\n",
BOOL (WINAPI *pLookupPrivilegeNameA)(LPSTR, PLUID, LPSTR, LPDWORD); GetLastError());
char buf[MAX_PATH]; /* arbitrary, seems long enough */ }
DWORD cchName = sizeof(buf);
LUID luid = { 0, 0 }; static void test_lookupPrivilegeName(void)
LONG i; {
BOOL ret; BOOL (WINAPI *pLookupPrivilegeNameA)(LPSTR, PLUID, LPSTR, LPDWORD);
char buf[MAX_PATH]; /* arbitrary, seems long enough */
/* check whether it's available first */ DWORD cchName = sizeof(buf);
pLookupPrivilegeNameA = (void*)GetProcAddress(hmod, "LookupPrivilegeNameA"); LUID luid = { 0, 0 };
if (!pLookupPrivilegeNameA) return; LONG i;
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE; BOOL ret;
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) /* check whether it's available first */
return; pLookupPrivilegeNameA = (void*)GetProcAddress(hmod, "LookupPrivilegeNameA");
if (!pLookupPrivilegeNameA) return;
/* check with a short buffer */ luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
cchName = 0; ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE; if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
ret = pLookupPrivilegeNameA(NULL, &luid, NULL, &cchName); return;
ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
"LookupPrivilegeNameA didn't fail with ERROR_INSUFFICIENT_BUFFER: %ld\n", /* check with a short buffer */
GetLastError()); cchName = 0;
ok(cchName == strlen("SeCreateTokenPrivilege") + 1, luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
"LookupPrivilegeNameA returned an incorrect required length for\n" ret = pLookupPrivilegeNameA(NULL, &luid, NULL, &cchName);
"SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName, ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
strlen("SeCreateTokenPrivilege") + 1); "LookupPrivilegeNameA didn't fail with ERROR_INSUFFICIENT_BUFFER: %ld\n",
/* check a known value and its returned length on success */ GetLastError());
cchName = sizeof(buf); ok(cchName == strlen("SeCreateTokenPrivilege") + 1,
ok(pLookupPrivilegeNameA(NULL, &luid, buf, &cchName) && "LookupPrivilegeNameA returned an incorrect required length for\n"
cchName == strlen("SeCreateTokenPrivilege"), "SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName,
"LookupPrivilegeNameA returned an incorrect output length for\n" strlen("SeCreateTokenPrivilege") + 1);
"SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName, /* check a known value and its returned length on success */
(int)strlen("SeCreateTokenPrivilege")); cchName = sizeof(buf);
/* check known values */ ok(pLookupPrivilegeNameA(NULL, &luid, buf, &cchName) &&
for (i = SE_MIN_WELL_KNOWN_PRIVILEGE; i < SE_MAX_WELL_KNOWN_PRIVILEGE; i++) cchName == strlen("SeCreateTokenPrivilege"),
{ "LookupPrivilegeNameA returned an incorrect output length for\n"
luid.LowPart = i; "SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName,
cchName = sizeof(buf); (int)strlen("SeCreateTokenPrivilege"));
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName); /* check known values */
ok( ret && GetLastError() != ERROR_NO_SUCH_PRIVILEGE, for (i = SE_MIN_WELL_KNOWN_PRIVILEGE; i < SE_MAX_WELL_KNOWN_PRIVILEGE; i++)
"LookupPrivilegeNameA(0.%ld) failed: %ld\n", i, GetLastError()); {
} luid.LowPart = i;
/* check a bogus LUID */ cchName = sizeof(buf);
luid.LowPart = 0xdeadbeef; ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
cchName = sizeof(buf); ok( ret || GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName); "LookupPrivilegeNameA(0.%ld) failed: %ld\n", i, GetLastError());
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE, }
"LookupPrivilegeNameA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n", /* check a bogus LUID */
GetLastError()); luid.LowPart = 0xdeadbeef;
/* check on a bogus system */ cchName = sizeof(buf);
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE; ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
cchName = sizeof(buf); ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
ret = pLookupPrivilegeNameA("b0gu5.Nam3", &luid, buf, &cchName); "LookupPrivilegeNameA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE, GetLastError());
"LookupPrivilegeNameA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n", /* check on a bogus system */
GetLastError()); luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
} cchName = sizeof(buf);
ret = pLookupPrivilegeNameA("b0gu5.Nam3", &luid, buf, &cchName);
struct NameToLUID ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
{ "LookupPrivilegeNameA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n",
const char *name; GetLastError());
DWORD lowPart; }
};
struct NameToLUID
static void test_lookupPrivilegeValue(void) {
{ const char *name;
static const struct NameToLUID privs[] = { DWORD lowPart;
{ "SeCreateTokenPrivilege", SE_CREATE_TOKEN_PRIVILEGE }, };
{ "SeAssignPrimaryTokenPrivilege", SE_ASSIGNPRIMARYTOKEN_PRIVILEGE },
{ "SeLockMemoryPrivilege", SE_LOCK_MEMORY_PRIVILEGE }, static void test_lookupPrivilegeValue(void)
{ "SeIncreaseQuotaPrivilege", SE_INCREASE_QUOTA_PRIVILEGE }, {
{ "SeMachineAccountPrivilege", SE_MACHINE_ACCOUNT_PRIVILEGE }, static const struct NameToLUID privs[] = {
{ "SeTcbPrivilege", SE_TCB_PRIVILEGE }, { "SeCreateTokenPrivilege", SE_CREATE_TOKEN_PRIVILEGE },
{ "SeSecurityPrivilege", SE_SECURITY_PRIVILEGE }, { "SeAssignPrimaryTokenPrivilege", SE_ASSIGNPRIMARYTOKEN_PRIVILEGE },
{ "SeTakeOwnershipPrivilege", SE_TAKE_OWNERSHIP_PRIVILEGE }, { "SeLockMemoryPrivilege", SE_LOCK_MEMORY_PRIVILEGE },
{ "SeLoadDriverPrivilege", SE_LOAD_DRIVER_PRIVILEGE }, { "SeIncreaseQuotaPrivilege", SE_INCREASE_QUOTA_PRIVILEGE },
{ "SeSystemProfilePrivilege", SE_SYSTEM_PROFILE_PRIVILEGE }, { "SeMachineAccountPrivilege", SE_MACHINE_ACCOUNT_PRIVILEGE },
{ "SeSystemtimePrivilege", SE_SYSTEMTIME_PRIVILEGE }, { "SeTcbPrivilege", SE_TCB_PRIVILEGE },
{ "SeProfileSingleProcessPrivilege", SE_PROF_SINGLE_PROCESS_PRIVILEGE }, { "SeSecurityPrivilege", SE_SECURITY_PRIVILEGE },
{ "SeIncreaseBasePriorityPrivilege", SE_INC_BASE_PRIORITY_PRIVILEGE }, { "SeTakeOwnershipPrivilege", SE_TAKE_OWNERSHIP_PRIVILEGE },
{ "SeCreatePagefilePrivilege", SE_CREATE_PAGEFILE_PRIVILEGE }, { "SeLoadDriverPrivilege", SE_LOAD_DRIVER_PRIVILEGE },
{ "SeCreatePermanentPrivilege", SE_CREATE_PERMANENT_PRIVILEGE }, { "SeSystemProfilePrivilege", SE_SYSTEM_PROFILE_PRIVILEGE },
{ "SeBackupPrivilege", SE_BACKUP_PRIVILEGE }, { "SeSystemtimePrivilege", SE_SYSTEMTIME_PRIVILEGE },
{ "SeRestorePrivilege", SE_RESTORE_PRIVILEGE }, { "SeProfileSingleProcessPrivilege", SE_PROF_SINGLE_PROCESS_PRIVILEGE },
{ "SeShutdownPrivilege", SE_SHUTDOWN_PRIVILEGE }, { "SeIncreaseBasePriorityPrivilege", SE_INC_BASE_PRIORITY_PRIVILEGE },
{ "SeDebugPrivilege", SE_DEBUG_PRIVILEGE }, { "SeCreatePagefilePrivilege", SE_CREATE_PAGEFILE_PRIVILEGE },
{ "SeAuditPrivilege", SE_AUDIT_PRIVILEGE }, { "SeCreatePermanentPrivilege", SE_CREATE_PERMANENT_PRIVILEGE },
{ "SeSystemEnvironmentPrivilege", SE_SYSTEM_ENVIRONMENT_PRIVILEGE }, { "SeBackupPrivilege", SE_BACKUP_PRIVILEGE },
{ "SeChangeNotifyPrivilege", SE_CHANGE_NOTIFY_PRIVILLEGE }, { "SeRestorePrivilege", SE_RESTORE_PRIVILEGE },
{ "SeRemoteShutdownPrivilege", SE_REMOTE_SHUTDOWN_PRIVILEGE }, { "SeShutdownPrivilege", SE_SHUTDOWN_PRIVILEGE },
{ "SeUndockPrivilege", SE_UNDOCK_PRIVILEGE }, { "SeDebugPrivilege", SE_DEBUG_PRIVILEGE },
{ "SeSyncAgentPrivilege", SE_SYNC_AGENT_PRIVILEGE }, { "SeAuditPrivilege", SE_AUDIT_PRIVILEGE },
{ "SeEnableDelegationPrivilege", SE_ENABLE_DELEGATION_PRIVILEGE }, { "SeSystemEnvironmentPrivilege", SE_SYSTEM_ENVIRONMENT_PRIVILEGE },
{ "SeManageVolumePrivilege", SE_MANAGE_VOLUME_PRIVILEGE }, { "SeChangeNotifyPrivilege", SE_CHANGE_NOTIFY_PRIVILLEGE },
{ "SeImpersonatePrivilege", SE_IMPERSONATE_PRIVILEGE }, { "SeRemoteShutdownPrivilege", SE_REMOTE_SHUTDOWN_PRIVILEGE },
{ "SeCreateGlobalPrivilege", SE_CREATE_GLOBAL_PRIVILEGE }, { "SeUndockPrivilege", SE_UNDOCK_PRIVILEGE },
}; { "SeSyncAgentPrivilege", SE_SYNC_AGENT_PRIVILEGE },
BOOL (WINAPI *pLookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID); { "SeEnableDelegationPrivilege", SE_ENABLE_DELEGATION_PRIVILEGE },
int i; { "SeManageVolumePrivilege", SE_MANAGE_VOLUME_PRIVILEGE },
LUID luid; { "SeImpersonatePrivilege", SE_IMPERSONATE_PRIVILEGE },
BOOL ret; { "SeCreateGlobalPrivilege", SE_CREATE_GLOBAL_PRIVILEGE },
};
/* check whether it's available first */ BOOL (WINAPI *pLookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID);
pLookupPrivilegeValueA = (void*)GetProcAddress(hmod, "LookupPrivilegeValueA"); int i;
if (!pLookupPrivilegeValueA) return; LUID luid;
ret = pLookupPrivilegeValueA(NULL, "SeCreateTokenPrivilege", &luid); BOOL ret;
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
return; /* check whether it's available first */
pLookupPrivilegeValueA = (void*)GetProcAddress(hmod, "LookupPrivilegeValueA");
/* check a bogus system name */ if (!pLookupPrivilegeValueA) return;
ret = pLookupPrivilegeValueA("b0gu5.Nam3", "SeCreateTokenPrivilege", &luid); ret = pLookupPrivilegeValueA(NULL, "SeCreateTokenPrivilege", &luid);
ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE, if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
"LookupPrivilegeValueA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n", return;
GetLastError());
/* check a NULL string */ /* check a bogus system name */
ret = pLookupPrivilegeValueA(NULL, 0, &luid); ret = pLookupPrivilegeValueA("b0gu5.Nam3", "SeCreateTokenPrivilege", &luid);
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE, ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
"LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n", "LookupPrivilegeValueA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n",
GetLastError()); GetLastError());
/* check a bogus privilege name */ /* check a NULL string */
ret = pLookupPrivilegeValueA(NULL, "SeBogusPrivilege", &luid); ret = pLookupPrivilegeValueA(NULL, 0, &luid);
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE, ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
"LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n", "LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
GetLastError()); GetLastError());
/* check case insensitive */ /* check a bogus privilege name */
ret = pLookupPrivilegeValueA(NULL, "sEcREATEtOKENpRIVILEGE", &luid); ret = pLookupPrivilegeValueA(NULL, "SeBogusPrivilege", &luid);
ok( ret, ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
"LookupPrivilegeValueA(NULL, sEcREATEtOKENpRIVILEGE, &luid) failed: %ld\n", "LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
GetLastError()); GetLastError());
for (i = 0; i < sizeof(privs) / sizeof(privs[0]); i++) /* check case insensitive */
{ ret = pLookupPrivilegeValueA(NULL, "sEcREATEtOKENpRIVILEGE", &luid);
/* Not all privileges are implemented on all Windows versions, so ok( ret,
* don't worry if the call fails "LookupPrivilegeValueA(NULL, sEcREATEtOKENpRIVILEGE, &luid) failed: %ld\n",
*/ GetLastError());
if (pLookupPrivilegeValueA(NULL, privs[i].name, &luid)) for (i = 0; i < sizeof(privs) / sizeof(privs[0]); i++)
{ {
ok(luid.LowPart == privs[i].lowPart, /* Not all privileges are implemented on all Windows versions, so
"LookupPrivilegeValueA returned an invalid LUID for %s\n", * don't worry if the call fails
privs[i].name); */
} if (pLookupPrivilegeValueA(NULL, privs[i].name, &luid))
} {
} ok(luid.LowPart == privs[i].lowPart,
"LookupPrivilegeValueA returned an invalid LUID for %s\n",
static void test_luid(void) privs[i].name);
{ }
test_allocateLuid(); }
test_lookupPrivilegeName(); }
test_lookupPrivilegeValue();
} static void test_luid(void)
{
START_TEST(security) test_allocateLuid();
{ test_lookupPrivilegeName();
init(); test_lookupPrivilegeValue();
if (!hmod) return; }
test_sid();
test_trustee(); static void test_FileSecurity(void)
test_luid(); {
} char directory[MAX_PATH];
DWORD retval, outSize;
BOOL result;
BYTE buffer[0x40];
pGetFileSecurityA = (fnGetFileSecurityA)
GetProcAddress( hmod, "GetFileSecurityA" );
if( !pGetFileSecurityA )
return;
retval = GetTempPathA(sizeof(directory), directory);
if (!retval) {
trace("GetTempPathA failed\n");
return;
}
strcpy(directory, "\\Should not exist");
SetLastError(NO_ERROR);
result = pGetFileSecurityA( directory,OWNER_SECURITY_INFORMATION,buffer,0x40,&outSize);
ok(!result, "GetFileSecurityA should fail for not existing directories/files\n");
ok( (GetLastError() == ERROR_FILE_NOT_FOUND ) ||
(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) ,
"last error ERROR_FILE_NOT_FOUND / ERROR_CALL_NOT_IMPLEMENTED (98) "
"expected, got %ld\n", GetLastError());
}
START_TEST(security)
{
init();
if (!hmod) return;
test_sid();
test_trustee();
test_luid();
test_FileSecurity();
}