advapi32: Alias some sids in LookupAccountName and make comparison case insensitive.

This commit is contained in:
Aric Stewart 2009-03-27 09:47:43 -05:00 committed by Alexandre Julliard
parent 110c287f2f
commit 4ea704d15a
2 changed files with 63 additions and 3 deletions

View File

@ -167,6 +167,7 @@ typedef struct _AccountSid {
LPCWSTR account;
LPCWSTR domain;
SID_NAME_USE name_use;
LPCWSTR alias;
} AccountSid;
static const WCHAR Account_Operators[] = { 'A','c','c','o','u','n','t',' ','O','p','e','r','a','t','o','r','s',0 };
@ -200,9 +201,11 @@ static const WCHAR Guests[] = { 'G','u','e','s','t','s',0 };
static const WCHAR INTERACTIVE[] = { 'I','N','T','E','R','A','C','T','I','V','E',0 };
static const WCHAR LOCAL[] = { 'L','O','C','A','L',0 };
static const WCHAR LOCAL_SERVICE[] = { 'L','O','C','A','L',' ','S','E','R','V','I','C','E',0 };
static const WCHAR LOCAL_SERVICE2[] = { 'L','O','C','A','L','S','E','R','V','I','C','E',0 };
static const WCHAR NETWORK[] = { 'N','E','T','W','O','R','K',0 };
static const WCHAR Network_Configuration_Operators[] = { 'N','e','t','w','o','r','k',' ','C','o','n','f','i','g','u','r','a','t','i','o','n',' ','O','p','e','r','a','t','o','r','s',0 };
static const WCHAR NETWORK_SERVICE[] = { 'N','E','T','W','O','R','K',' ','S','E','R','V','I','C','E',0 };
static const WCHAR NETWORK_SERVICE2[] = { 'N','E','T','W','O','R','K','S','E','R','V','I','C','E',0 };
static const WCHAR NT_AUTHORITY[] = { 'N','T',' ','A','U','T','H','O','R','I','T','Y',0 };
static const WCHAR NT_Pseudo_Domain[] = { 'N','T',' ','P','s','e','u','d','o',' ','D','o','m','a','i','n',0 };
static const WCHAR NTML_Authentication[] = { 'N','T','M','L',' ','A','u','t','h','e','n','t','i','c','a','t','i','o','n',0 };
@ -252,8 +255,8 @@ static const AccountSid ACCOUNT_SIDS[] = {
{ WinTerminalServerSid, TERMINAL_SERVER_USER, NT_AUTHORITY, SidTypeWellKnownGroup },
{ WinRemoteLogonIdSid, REMOTE_INTERACTIVE_LOGON, NT_AUTHORITY, SidTypeWellKnownGroup },
{ WinLocalSystemSid, SYSTEM, NT_AUTHORITY, SidTypeWellKnownGroup },
{ WinLocalServiceSid, LOCAL_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
{ WinNetworkServiceSid, NETWORK_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup },
{ WinLocalServiceSid, LOCAL_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup, LOCAL_SERVICE2 },
{ WinNetworkServiceSid, NETWORK_SERVICE, NT_AUTHORITY, SidTypeWellKnownGroup , NETWORK_SERVICE2},
{ WinBuiltinDomainSid, BUILTIN, BUILTIN, SidTypeDomain },
{ WinBuiltinAdministratorsSid, Administrators, BUILTIN, SidTypeAlias },
{ WinBuiltinUsersSid, Users, BUILTIN, SidTypeAlias },
@ -2667,7 +2670,8 @@ BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSI
for (i = 0; i < (sizeof(ACCOUNT_SIDS) / sizeof(ACCOUNT_SIDS[0])); i++)
{
if (!strcmpW(lpAccountName, ACCOUNT_SIDS[i].account))
if (!strcmpiW(lpAccountName, ACCOUNT_SIDS[i].account) ||
(ACCOUNT_SIDS[i].alias && !strcmpiW(lpAccountName, ACCOUNT_SIDS[i].alias)))
{
DWORD sidLen = SECURITY_MAX_SID_SIZE;

View File

@ -1700,6 +1700,40 @@ static void get_sid_info(PSID psid, LPSTR *user, LPSTR *dom)
LookupAccountSidA(NULL, psid, account, &size, domain, &dom_size, &use);
}
static void check_wellknown_name(const char* name, const char* exp_account, int exp_size, SID_NAME_USE exp_use, BOOL exp_succ)
{
DWORD sid_size, domain_size;
SID_NAME_USE sid_use;
LPSTR domain, account, sid_dom;
PSID psid;
BOOL ret;
sid_size = 0;
domain_size = 0;
ret = LookupAccountNameA(NULL, name, NULL, &sid_size, NULL, &domain_size, &sid_use);
psid = HeapAlloc(GetProcessHeap(),0,sid_size);
domain = HeapAlloc(GetProcessHeap(),0,domain_size);
ret = LookupAccountNameA(NULL, name, psid, &sid_size, domain, &domain_size, &sid_use);
get_sid_info(psid, &account, &sid_dom);
if (!exp_succ)
{
ok(!ret, " %s Should have failed to lookup account name\n",name);
return;
}
ok(ret, "Failed to lookup account name %s\n",name);
ok(sid_size != 0, "sid_size was zero\n");
ok(!lstrcmp(account, exp_account), "Expected %s , got %s\n", exp_account, account);
ok(!lstrcmp(domain, sid_dom), "Expected %s, got %s\n", sid_dom, domain);
ok(domain_size == exp_size, "Expected %i, got %d\n", exp_size, domain_size);
ok(lstrlen(domain) == domain_size, "Expected %d, got %d\n", lstrlen(domain), domain_size);
ok(sid_use == exp_use, "Expected (%d), got %d\n", exp_use, sid_use);
HeapFree(GetProcessHeap(),0,psid);
HeapFree(GetProcessHeap(),0,domain);
}
static void test_LookupAccountName(void)
{
DWORD sid_size, domain_size, user_size;
@ -1898,6 +1932,28 @@ static void test_LookupAccountName(void)
HeapFree(GetProcessHeap(), 0, domain);
HeapFree(GetProcessHeap(), 0, psid);
}
/* Well Known names */
check_wellknown_name("LocalService", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("Local Service", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
/* 2 spaces */
check_wellknown_name("Local Service", "", 0, 0, FALSE);
check_wellknown_name("NetworkService", "NETWORK SERVICE", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("Network Service", "NETWORK SERVICE", 12, SidTypeWellKnownGroup, TRUE);
/* example of some names where the spaces are not optional */
check_wellknown_name("Terminal Server User", "TERMINAL SERVER USER", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("TerminalServer User", "", 0, 0, FALSE);
check_wellknown_name("TerminalServerUser", "", 0, 0, FALSE);
check_wellknown_name("Terminal ServerUser", "", 0, 0, FALSE);
check_wellknown_name("enterprise domain controllers", "ENTERPRISE DOMAIN CONTROLLERS", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("enterprisedomain controllers", "", 0, 0, FALSE);
check_wellknown_name("enterprise domaincontrollers", "", 0, 0, FALSE);
check_wellknown_name("enterprisedomaincontrollers", "", 0, 0, FALSE);
/* case insensitivity */
check_wellknown_name("lOCAlServICE", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
}
static void test_security_descriptor(void)