Commit b540d57c authored by Aric Stewart's avatar Aric Stewart Committed by Alexandre Julliard

advapi32: Modify check_well_known_name test to be more robust on more Windows platforms.

Thanks to Paul Vriens for pointing out the need for this.
parent c5dadf47
......@@ -1700,11 +1700,16 @@ 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)
static void check_wellknown_name(const char* name, WELL_KNOWN_SID_TYPE result)
{
SID_IDENTIFIER_AUTHORITY ident = { SECURITY_NT_AUTHORITY };
PSID domainsid;
char wk_sid[SECURITY_MAX_SID_SIZE];
DWORD cb;
DWORD sid_size, domain_size;
SID_NAME_USE sid_use;
LPSTR domain, account, sid_dom;
LPSTR domain, account, sid_domain, wk_domain, wk_account;
PSID psid;
BOOL ret;
......@@ -1715,20 +1720,31 @@ static void check_wellknown_name(const char* name, const char* exp_account, int
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)
if (!result)
{
ok(!ret, " %s Should have failed to lookup account name\n",name);
return;
}
AllocateAndInitializeSid(&ident, 6, SECURITY_NT_NON_UNIQUE, 12, 23, 34, 45, 56, 0, 0, &domainsid);
cb = sizeof(wk_sid);
if (!pCreateWellKnownSid(result, domainsid, wk_sid, &cb))
{
win_skip("SID %i is not avalable on the system\n",result);
return;
}
get_sid_info(psid, &account, &sid_domain);
get_sid_info(wk_sid, &wk_account, &wk_domain);
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);
ok(EqualSid(psid,wk_sid),"(%s) Sids fail to match well known sid!\n",name);
ok(!lstrcmp(account, wk_account), "Expected %s , got %s\n", account, wk_account);
ok(!lstrcmp(domain, wk_domain), "Expected %s, got %s\n", wk_domain, domain);
ok(sid_use == SidTypeWellKnownGroup , "Expected Use (5), got %d\n", sid_use);
HeapFree(GetProcessHeap(),0,psid);
HeapFree(GetProcessHeap(),0,domain);
......@@ -1934,26 +1950,38 @@ static void test_LookupAccountName(void)
}
/* Well Known names */
check_wellknown_name("LocalService", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("Local Service", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
if (!pCreateWellKnownSid)
{
win_skip("CreateWellKnownSid not available\n");
return;
}
if (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) != LANG_ENGLISH)
{
skip("Non-english locale (skipping well know name creation tests)\n");
return;
}
check_wellknown_name("LocalService", WinLocalServiceSid);
check_wellknown_name("Local Service", WinLocalServiceSid);
/* 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);
check_wellknown_name("Local Service", 0);
check_wellknown_name("NetworkService", WinNetworkServiceSid);
check_wellknown_name("Network Service", WinNetworkServiceSid);
/* 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("Terminal Server User", WinTerminalServerSid);
check_wellknown_name("TerminalServer User", 0);
check_wellknown_name("TerminalServerUser", 0);
check_wellknown_name("Terminal ServerUser", 0);
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);
check_wellknown_name("enterprise domain controllers",WinEnterpriseControllersSid);
check_wellknown_name("enterprisedomain controllers", 0);
check_wellknown_name("enterprise domaincontrollers", 0);
check_wellknown_name("enterprisedomaincontrollers", 0);
/* case insensitivity */
check_wellknown_name("lOCAlServICE", "LOCAL SERVICE", 12, SidTypeWellKnownGroup, TRUE);
check_wellknown_name("lOCAlServICE", WinLocalServiceSid);
}
static void test_security_descriptor(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment