2004-08-09 18:47:22 +00:00
|
|
|
/*
|
|
|
|
* Unit tests for security functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Mike McCormack
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2004-08-16 21:07:50 +00:00
|
|
|
#include "aclapi.h"
|
2004-09-16 20:27:52 +00:00
|
|
|
#include "winnt.h"
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2005-02-14 11:06:16 +00:00
|
|
|
typedef BOOL (WINAPI *fnBuildTrusteeWithSidA)( TRUSTEE *trustee, PSID psid );
|
|
|
|
typedef BOOL (WINAPI *fnBuildTrusteeWithNameA)( TRUSTEE *trustee, LPSTR str );
|
2004-08-09 18:47:22 +00:00
|
|
|
typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
|
2004-09-16 20:27:52 +00:00
|
|
|
typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid );
|
2005-03-28 10:00:59 +00:00
|
|
|
typedef BOOL (WINAPI *fnGetFileSecurityA)(LPCSTR, SECURITY_INFORMATION,
|
|
|
|
PSECURITY_DESCRIPTOR, DWORD, LPDWORD);
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2004-11-04 04:52:17 +00:00
|
|
|
static HMODULE hmod;
|
|
|
|
|
2005-02-14 11:06:16 +00:00
|
|
|
fnBuildTrusteeWithSidA pBuildTrusteeWithSidA;
|
|
|
|
fnBuildTrusteeWithNameA pBuildTrusteeWithNameA;
|
2004-08-09 18:47:22 +00:00
|
|
|
fnConvertSidToStringSidA pConvertSidToStringSidA;
|
2004-09-16 20:27:52 +00:00
|
|
|
fnConvertStringSidToSidA pConvertStringSidToSidA;
|
2005-03-28 10:00:59 +00:00
|
|
|
fnGetFileSecurityA pGetFileSecurityA;
|
2004-09-16 20:27:52 +00:00
|
|
|
|
|
|
|
struct sidRef
|
|
|
|
{
|
|
|
|
SID_IDENTIFIER_AUTHORITY auth;
|
|
|
|
const char *refStr;
|
|
|
|
};
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2004-11-04 04:52:17 +00:00
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
hmod = GetModuleHandle("advapi32.dll");
|
|
|
|
}
|
|
|
|
|
2004-08-09 18:47:22 +00:00
|
|
|
void test_sid()
|
|
|
|
{
|
2004-09-16 20:27:52 +00:00
|
|
|
struct sidRef refs[] = {
|
|
|
|
{ { {0x00,0x00,0x33,0x44,0x55,0x66} }, "S-1-860116326-1" },
|
|
|
|
{ { {0x00,0x00,0x01,0x02,0x03,0x04} }, "S-1-16909060-1" },
|
|
|
|
{ { {0x00,0x00,0x00,0x01,0x02,0x03} }, "S-1-66051-1" },
|
|
|
|
{ { {0x00,0x00,0x00,0x00,0x01,0x02} }, "S-1-258-1" },
|
|
|
|
{ { {0x00,0x00,0x00,0x00,0x00,0x02} }, "S-1-2-1" },
|
|
|
|
{ { {0x00,0x00,0x00,0x00,0x00,0x0c} }, "S-1-12-1" },
|
|
|
|
};
|
|
|
|
const char noSubAuthStr[] = "S-1-5";
|
|
|
|
unsigned int i;
|
|
|
|
PSID psid = NULL;
|
2004-08-09 18:47:22 +00:00
|
|
|
BOOL r;
|
2004-09-16 20:27:52 +00:00
|
|
|
LPSTR str = NULL;
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2004-09-16 20:27:52 +00:00
|
|
|
pConvertSidToStringSidA = (fnConvertSidToStringSidA)
|
|
|
|
GetProcAddress( hmod, "ConvertSidToStringSidA" );
|
|
|
|
if( !pConvertSidToStringSidA )
|
|
|
|
return;
|
|
|
|
pConvertStringSidToSidA = (fnConvertStringSidToSidA)
|
|
|
|
GetProcAddress( hmod, "ConvertStringSidToSidA" );
|
|
|
|
if( !pConvertStringSidToSidA )
|
|
|
|
return;
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2004-09-16 20:27:52 +00:00
|
|
|
r = pConvertStringSidToSidA( NULL, NULL );
|
|
|
|
ok( !r, "expected failure with NULL parameters\n" );
|
|
|
|
if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
|
2004-08-09 18:47:22 +00:00
|
|
|
return;
|
2004-09-16 20:27:52 +00:00
|
|
|
ok( GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
|
|
|
|
GetLastError() );
|
|
|
|
|
|
|
|
r = pConvertStringSidToSidA( refs[0].refStr, NULL );
|
|
|
|
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
|
|
|
|
GetLastError() );
|
|
|
|
|
|
|
|
r = pConvertStringSidToSidA( NULL, &str );
|
|
|
|
ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
|
|
|
|
"expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
|
|
|
|
GetLastError() );
|
|
|
|
|
|
|
|
r = pConvertStringSidToSidA( noSubAuthStr, &psid );
|
|
|
|
ok( !r,
|
|
|
|
"expected failure with no sub authorities\n" );
|
|
|
|
ok( GetLastError() == ERROR_INVALID_SID,
|
|
|
|
"expected GetLastError() is ERROR_INVALID_SID, got %ld\n",
|
|
|
|
GetLastError() );
|
|
|
|
|
|
|
|
for( i = 0; i < sizeof(refs) / sizeof(refs[0]); i++ )
|
|
|
|
{
|
|
|
|
PISID pisid;
|
|
|
|
|
|
|
|
r = AllocateAndInitializeSid( &refs[i].auth, 1,1,0,0,0,0,0,0,0,
|
|
|
|
&psid );
|
|
|
|
ok( r, "failed to allocate sid\n" );
|
|
|
|
r = pConvertSidToStringSidA( psid, &str );
|
|
|
|
ok( r, "failed to convert sid\n" );
|
2005-03-14 17:20:58 +00:00
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
ok( !strcmp( str, refs[i].refStr ),
|
|
|
|
"incorrect sid, expected %s, got %s\n", refs[i].refStr, str );
|
2004-09-16 20:27:52 +00:00
|
|
|
LocalFree( str );
|
2005-03-14 17:20:58 +00:00
|
|
|
}
|
2004-09-16 20:27:52 +00:00
|
|
|
if( psid )
|
|
|
|
FreeSid( psid );
|
|
|
|
|
|
|
|
r = pConvertStringSidToSidA( refs[i].refStr, &psid );
|
|
|
|
ok( r, "failed to parse sid string\n" );
|
|
|
|
pisid = (PISID)psid;
|
|
|
|
ok( pisid &&
|
|
|
|
!memcmp( pisid->IdentifierAuthority.Value, refs[i].auth.Value,
|
|
|
|
sizeof(refs[i].auth) ),
|
|
|
|
"string sid %s didn't parse to expected value\n"
|
|
|
|
"(got 0x%04x%08lx, expected 0x%04x%08lx)\n",
|
|
|
|
refs[i].refStr,
|
|
|
|
MAKEWORD( pisid->IdentifierAuthority.Value[1],
|
|
|
|
pisid->IdentifierAuthority.Value[0] ),
|
|
|
|
MAKELONG( MAKEWORD( pisid->IdentifierAuthority.Value[5],
|
|
|
|
pisid->IdentifierAuthority.Value[4] ),
|
|
|
|
MAKEWORD( pisid->IdentifierAuthority.Value[3],
|
|
|
|
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] ) ) );
|
|
|
|
if( psid )
|
|
|
|
LocalFree( psid );
|
|
|
|
}
|
2004-08-16 21:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_trustee()
|
|
|
|
{
|
|
|
|
TRUSTEE trustee;
|
|
|
|
PSID psid;
|
2004-08-19 19:01:12 +00:00
|
|
|
LPSTR str = "2jjj";
|
2004-08-16 21:07:50 +00:00
|
|
|
|
|
|
|
SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} };
|
|
|
|
|
2005-02-14 11:06:16 +00:00
|
|
|
pBuildTrusteeWithSidA = (fnBuildTrusteeWithSidA)
|
|
|
|
GetProcAddress( hmod, "BuildTrusteeWithSidA" );
|
|
|
|
pBuildTrusteeWithNameA = (fnBuildTrusteeWithNameA)
|
|
|
|
GetProcAddress( hmod, "BuildTrusteeWithNameA" );
|
|
|
|
if( !pBuildTrusteeWithSidA || !pBuildTrusteeWithNameA)
|
|
|
|
return;
|
|
|
|
|
2004-11-03 22:14:55 +00:00
|
|
|
if ( ! AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid ) )
|
|
|
|
{
|
|
|
|
trace( "failed to init SID\n" );
|
|
|
|
return;
|
|
|
|
}
|
2004-08-16 21:07:50 +00:00
|
|
|
|
|
|
|
memset( &trustee, 0xff, sizeof trustee );
|
2005-02-14 11:06:16 +00:00
|
|
|
pBuildTrusteeWithSidA( &trustee, psid );
|
2004-08-16 21:07:50 +00:00
|
|
|
|
|
|
|
ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
|
|
|
|
ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
|
|
|
|
"MultipleTrusteeOperation wrong\n");
|
|
|
|
ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n");
|
|
|
|
ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
|
|
|
|
ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" );
|
|
|
|
FreeSid( psid );
|
2004-08-09 18:47:22 +00:00
|
|
|
|
2004-08-19 19:01:12 +00:00
|
|
|
/* test BuildTrusteeWithNameA */
|
|
|
|
memset( &trustee, 0xff, sizeof trustee );
|
2005-02-14 11:06:16 +00:00
|
|
|
pBuildTrusteeWithNameA( &trustee, str );
|
2004-08-19 19:01:12 +00:00
|
|
|
|
|
|
|
ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
|
|
|
|
ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
|
|
|
|
"MultipleTrusteeOperation wrong\n");
|
|
|
|
ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n");
|
|
|
|
ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
|
|
|
|
ok( trustee.ptstrName == str, "ptstrName wrong\n" );
|
|
|
|
}
|
|
|
|
|
2004-11-04 04:52:17 +00:00
|
|
|
/* If the first isn't defined, assume none is */
|
|
|
|
#ifndef SE_MIN_WELL_KNOWN_PRIVILEGE
|
|
|
|
#define SE_MIN_WELL_KNOWN_PRIVILEGE 2L
|
|
|
|
#define SE_CREATE_TOKEN_PRIVILEGE 2L
|
|
|
|
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3L
|
|
|
|
#define SE_LOCK_MEMORY_PRIVILEGE 4L
|
|
|
|
#define SE_INCREASE_QUOTA_PRIVILEGE 5L
|
|
|
|
#define SE_MACHINE_ACCOUNT_PRIVILEGE 6L
|
|
|
|
#define SE_TCB_PRIVILEGE 7L
|
|
|
|
#define SE_SECURITY_PRIVILEGE 8L
|
|
|
|
#define SE_TAKE_OWNERSHIP_PRIVILEGE 9L
|
|
|
|
#define SE_LOAD_DRIVER_PRIVILEGE 10L
|
|
|
|
#define SE_SYSTEM_PROFILE_PRIVILEGE 11L
|
|
|
|
#define SE_SYSTEMTIME_PRIVILEGE 12L
|
|
|
|
#define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13L
|
|
|
|
#define SE_INC_BASE_PRIORITY_PRIVILEGE 14L
|
|
|
|
#define SE_CREATE_PAGEFILE_PRIVILEGE 15L
|
|
|
|
#define SE_CREATE_PERMANENT_PRIVILEGE 16L
|
|
|
|
#define SE_BACKUP_PRIVILEGE 17L
|
|
|
|
#define SE_RESTORE_PRIVILEGE 18L
|
|
|
|
#define SE_SHUTDOWN_PRIVILEGE 19L
|
|
|
|
#define SE_DEBUG_PRIVILEGE 20L
|
|
|
|
#define SE_AUDIT_PRIVILEGE 21L
|
|
|
|
#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22L
|
|
|
|
#define SE_CHANGE_NOTIFY_PRIVILLEGE 23L
|
|
|
|
#define SE_REMOTE_SHUTDOWN_PRIVILEGE 24L
|
|
|
|
#define SE_UNDOCK_PRIVILEGE 25L
|
|
|
|
#define SE_SYNC_AGENT_PRIVILEGE 26L
|
|
|
|
#define SE_ENABLE_DELEGATION_PRIVILEGE 27L
|
|
|
|
#define SE_MANAGE_VOLUME_PRIVILEGE 28L
|
|
|
|
#define SE_IMPERSONATE_PRIVILEGE 29L
|
|
|
|
#define SE_CREATE_GLOBAL_PRIVILEGE 30L
|
|
|
|
#define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_GLOBAL_PRIVILEGE
|
|
|
|
#endif /* ndef SE_MIN_WELL_KNOWN_PRIVILEGE */
|
|
|
|
|
|
|
|
static void test_allocateLuid(void)
|
|
|
|
{
|
|
|
|
BOOL (WINAPI *pAllocateLocallyUniqueId)(PLUID);
|
|
|
|
LUID luid1, luid2;
|
|
|
|
BOOL ret;
|
|
|
|
|
2005-02-14 21:04:45 +00:00
|
|
|
pAllocateLocallyUniqueId = (void*)GetProcAddress(hmod, "AllocateLocallyUniqueId");
|
2004-11-04 04:52:17 +00:00
|
|
|
if (!pAllocateLocallyUniqueId) return;
|
|
|
|
|
|
|
|
ret = pAllocateLocallyUniqueId(&luid1);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ok(ret,
|
|
|
|
"AllocateLocallyUniqueId failed: %ld\n", GetLastError());
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pAllocateLocallyUniqueId(&luid2);
|
|
|
|
ok( ret,
|
2004-11-04 04:52:17 +00:00
|
|
|
"AllocateLocallyUniqueId failed: %ld\n", GetLastError());
|
|
|
|
ok(luid1.LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE || luid1.HighPart != 0,
|
|
|
|
"AllocateLocallyUniqueId returned a well-known LUID\n");
|
|
|
|
ok(luid1.LowPart != luid2.LowPart || luid1.HighPart != luid2.HighPart,
|
|
|
|
"AllocateLocallyUniqueId returned non-unique LUIDs\n");
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pAllocateLocallyUniqueId(NULL);
|
|
|
|
ok( !ret && GetLastError() == ERROR_NOACCESS,
|
2004-11-04 04:52:17 +00:00
|
|
|
"AllocateLocallyUniqueId(NULL) didn't return ERROR_NOACCESS: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_lookupPrivilegeName(void)
|
|
|
|
{
|
|
|
|
BOOL (WINAPI *pLookupPrivilegeNameA)(LPSTR, PLUID, LPSTR, LPDWORD);
|
|
|
|
char buf[MAX_PATH]; /* arbitrary, seems long enough */
|
|
|
|
DWORD cchName = sizeof(buf);
|
|
|
|
LUID luid = { 0, 0 };
|
|
|
|
LONG i;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* check whether it's available first */
|
2005-02-14 21:04:45 +00:00
|
|
|
pLookupPrivilegeNameA = (void*)GetProcAddress(hmod, "LookupPrivilegeNameA");
|
2004-11-04 04:52:17 +00:00
|
|
|
if (!pLookupPrivilegeNameA) return;
|
|
|
|
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
|
|
|
|
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* check with a short buffer */
|
|
|
|
cchName = 0;
|
|
|
|
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeNameA(NULL, &luid, NULL, &cchName);
|
|
|
|
ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeNameA didn't fail with ERROR_INSUFFICIENT_BUFFER: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(cchName == strlen("SeCreateTokenPrivilege") + 1,
|
|
|
|
"LookupPrivilegeNameA returned an incorrect required length for\n"
|
|
|
|
"SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName,
|
|
|
|
strlen("SeCreateTokenPrivilege") + 1);
|
|
|
|
/* check a known value and its returned length on success */
|
|
|
|
cchName = sizeof(buf);
|
|
|
|
ok(pLookupPrivilegeNameA(NULL, &luid, buf, &cchName) &&
|
|
|
|
cchName == strlen("SeCreateTokenPrivilege"),
|
|
|
|
"LookupPrivilegeNameA returned an incorrect output length for\n"
|
|
|
|
"SeCreateTokenPrivilege (got %ld, expected %d)\n", cchName,
|
2005-02-14 11:52:48 +00:00
|
|
|
(int)strlen("SeCreateTokenPrivilege"));
|
2004-11-04 04:52:17 +00:00
|
|
|
/* check known values */
|
|
|
|
for (i = SE_MIN_WELL_KNOWN_PRIVILEGE; i < SE_MAX_WELL_KNOWN_PRIVILEGE; i++)
|
|
|
|
{
|
|
|
|
luid.LowPart = i;
|
|
|
|
cchName = sizeof(buf);
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
|
2005-03-22 16:39:02 +00:00
|
|
|
ok( ret || GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeNameA(0.%ld) failed: %ld\n", i, GetLastError());
|
|
|
|
}
|
|
|
|
/* check a bogus LUID */
|
|
|
|
luid.LowPart = 0xdeadbeef;
|
|
|
|
cchName = sizeof(buf);
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
|
|
|
|
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeNameA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
/* check on a bogus system */
|
|
|
|
luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
|
|
|
|
cchName = sizeof(buf);
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeNameA("b0gu5.Nam3", &luid, buf, &cchName);
|
|
|
|
ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeNameA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NameToLUID
|
|
|
|
{
|
|
|
|
const char *name;
|
2005-02-14 21:04:45 +00:00
|
|
|
DWORD lowPart;
|
2004-11-04 04:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void test_lookupPrivilegeValue(void)
|
|
|
|
{
|
|
|
|
static const struct NameToLUID privs[] = {
|
|
|
|
{ "SeCreateTokenPrivilege", SE_CREATE_TOKEN_PRIVILEGE },
|
|
|
|
{ "SeAssignPrimaryTokenPrivilege", SE_ASSIGNPRIMARYTOKEN_PRIVILEGE },
|
|
|
|
{ "SeLockMemoryPrivilege", SE_LOCK_MEMORY_PRIVILEGE },
|
|
|
|
{ "SeIncreaseQuotaPrivilege", SE_INCREASE_QUOTA_PRIVILEGE },
|
|
|
|
{ "SeMachineAccountPrivilege", SE_MACHINE_ACCOUNT_PRIVILEGE },
|
|
|
|
{ "SeTcbPrivilege", SE_TCB_PRIVILEGE },
|
|
|
|
{ "SeSecurityPrivilege", SE_SECURITY_PRIVILEGE },
|
|
|
|
{ "SeTakeOwnershipPrivilege", SE_TAKE_OWNERSHIP_PRIVILEGE },
|
|
|
|
{ "SeLoadDriverPrivilege", SE_LOAD_DRIVER_PRIVILEGE },
|
|
|
|
{ "SeSystemProfilePrivilege", SE_SYSTEM_PROFILE_PRIVILEGE },
|
|
|
|
{ "SeSystemtimePrivilege", SE_SYSTEMTIME_PRIVILEGE },
|
|
|
|
{ "SeProfileSingleProcessPrivilege", SE_PROF_SINGLE_PROCESS_PRIVILEGE },
|
|
|
|
{ "SeIncreaseBasePriorityPrivilege", SE_INC_BASE_PRIORITY_PRIVILEGE },
|
|
|
|
{ "SeCreatePagefilePrivilege", SE_CREATE_PAGEFILE_PRIVILEGE },
|
|
|
|
{ "SeCreatePermanentPrivilege", SE_CREATE_PERMANENT_PRIVILEGE },
|
|
|
|
{ "SeBackupPrivilege", SE_BACKUP_PRIVILEGE },
|
|
|
|
{ "SeRestorePrivilege", SE_RESTORE_PRIVILEGE },
|
|
|
|
{ "SeShutdownPrivilege", SE_SHUTDOWN_PRIVILEGE },
|
|
|
|
{ "SeDebugPrivilege", SE_DEBUG_PRIVILEGE },
|
|
|
|
{ "SeAuditPrivilege", SE_AUDIT_PRIVILEGE },
|
|
|
|
{ "SeSystemEnvironmentPrivilege", SE_SYSTEM_ENVIRONMENT_PRIVILEGE },
|
|
|
|
{ "SeChangeNotifyPrivilege", SE_CHANGE_NOTIFY_PRIVILLEGE },
|
|
|
|
{ "SeRemoteShutdownPrivilege", SE_REMOTE_SHUTDOWN_PRIVILEGE },
|
|
|
|
{ "SeUndockPrivilege", SE_UNDOCK_PRIVILEGE },
|
|
|
|
{ "SeSyncAgentPrivilege", SE_SYNC_AGENT_PRIVILEGE },
|
|
|
|
{ "SeEnableDelegationPrivilege", SE_ENABLE_DELEGATION_PRIVILEGE },
|
|
|
|
{ "SeManageVolumePrivilege", SE_MANAGE_VOLUME_PRIVILEGE },
|
|
|
|
{ "SeImpersonatePrivilege", SE_IMPERSONATE_PRIVILEGE },
|
|
|
|
{ "SeCreateGlobalPrivilege", SE_CREATE_GLOBAL_PRIVILEGE },
|
|
|
|
};
|
|
|
|
BOOL (WINAPI *pLookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID);
|
|
|
|
int i;
|
|
|
|
LUID luid;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
/* check whether it's available first */
|
2005-02-14 21:04:45 +00:00
|
|
|
pLookupPrivilegeValueA = (void*)GetProcAddress(hmod, "LookupPrivilegeValueA");
|
2004-11-04 04:52:17 +00:00
|
|
|
if (!pLookupPrivilegeValueA) return;
|
|
|
|
ret = pLookupPrivilegeValueA(NULL, "SeCreateTokenPrivilege", &luid);
|
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* check a bogus system name */
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeValueA("b0gu5.Nam3", "SeCreateTokenPrivilege", &luid);
|
|
|
|
ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeValueA didn't fail with RPC_S_SERVER_UNAVAILABLE: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
/* check a NULL string */
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeValueA(NULL, 0, &luid);
|
|
|
|
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
/* check a bogus privilege name */
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeValueA(NULL, "SeBogusPrivilege", &luid);
|
|
|
|
ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
/* check case insensitive */
|
2004-12-27 17:26:37 +00:00
|
|
|
ret = pLookupPrivilegeValueA(NULL, "sEcREATEtOKENpRIVILEGE", &luid);
|
|
|
|
ok( ret,
|
2004-11-04 04:52:17 +00:00
|
|
|
"LookupPrivilegeValueA(NULL, sEcREATEtOKENpRIVILEGE, &luid) failed: %ld\n",
|
|
|
|
GetLastError());
|
|
|
|
for (i = 0; i < sizeof(privs) / sizeof(privs[0]); i++)
|
|
|
|
{
|
|
|
|
/* Not all privileges are implemented on all Windows versions, so
|
|
|
|
* don't worry if the call fails
|
|
|
|
*/
|
|
|
|
if (pLookupPrivilegeValueA(NULL, privs[i].name, &luid))
|
|
|
|
{
|
|
|
|
ok(luid.LowPart == privs[i].lowPart,
|
|
|
|
"LookupPrivilegeValueA returned an invalid LUID for %s\n",
|
|
|
|
privs[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_luid(void)
|
|
|
|
{
|
|
|
|
test_allocateLuid();
|
|
|
|
test_lookupPrivilegeName();
|
|
|
|
test_lookupPrivilegeValue();
|
|
|
|
}
|
|
|
|
|
2005-03-28 10:00:59 +00:00
|
|
|
static void test_FileSecurity(void)
|
|
|
|
{
|
|
|
|
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);
|
2005-03-29 11:31:18 +00:00
|
|
|
ok(!result, "GetFileSecurityA should fail for not existing directories/files\n");
|
2005-03-31 10:07:11 +00:00
|
|
|
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());
|
2005-03-28 10:00:59 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 18:47:22 +00:00
|
|
|
START_TEST(security)
|
|
|
|
{
|
2004-11-04 04:52:17 +00:00
|
|
|
init();
|
|
|
|
if (!hmod) return;
|
2004-08-09 18:47:22 +00:00
|
|
|
test_sid();
|
2004-08-16 21:07:50 +00:00
|
|
|
test_trustee();
|
2004-11-04 04:52:17 +00:00
|
|
|
test_luid();
|
2005-03-28 10:00:59 +00:00
|
|
|
test_FileSecurity();
|
2004-08-09 18:47:22 +00:00
|
|
|
}
|