mirror of
https://github.com/reactos/reactos.git
synced 2024-11-23 19:43:31 +08:00
[NETID] Disable the 'Network ID' and 'Change' buttons and show the admin note when the current user is not an administrator
This commit is contained in:
parent
226878563f
commit
8c4b0c9142
@ -159,6 +159,68 @@ GetComputerNames(
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
IsUserAdmin(VOID)
|
||||
{
|
||||
SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
|
||||
PSID pAdminsSid = NULL;
|
||||
HANDLE hToken = NULL;
|
||||
PTOKEN_GROUPS pGroups = NULL;
|
||||
BOOL bIsAdmin = FALSE;
|
||||
DWORD dwSize, i;
|
||||
|
||||
if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
|
||||
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
|
||||
&pAdminsSid))
|
||||
return FALSE;
|
||||
|
||||
if (!OpenProcessToken(GetCurrentProcess(),
|
||||
TOKEN_QUERY,
|
||||
&hToken))
|
||||
goto done;
|
||||
|
||||
dwSize = 0;
|
||||
GetTokenInformation(hToken,
|
||||
TokenGroups,
|
||||
NULL,
|
||||
0,
|
||||
&dwSize);
|
||||
if (dwSize == 0)
|
||||
goto done;
|
||||
|
||||
pGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
|
||||
if (pGroups == NULL)
|
||||
goto done;
|
||||
|
||||
if (!GetTokenInformation(hToken,
|
||||
TokenGroups,
|
||||
pGroups,
|
||||
dwSize,
|
||||
&dwSize))
|
||||
goto done;
|
||||
|
||||
for (i = 0; i < pGroups->GroupCount; i++)
|
||||
{
|
||||
if (EqualSid(pGroups->Groups[i].Sid, pAdminsSid))
|
||||
{
|
||||
bIsAdmin = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (pGroups != NULL)
|
||||
HeapFree(GetProcessHeap(), 0, pGroups);
|
||||
|
||||
if (hToken != NULL)
|
||||
CloseHandle(hToken);
|
||||
|
||||
if (pAdminsSid != NULL)
|
||||
FreeSid(pAdminsSid);
|
||||
|
||||
return bIsAdmin;
|
||||
}
|
||||
|
||||
static
|
||||
BOOL
|
||||
IsValidDomainName(
|
||||
@ -611,6 +673,16 @@ NetIDPage_OnInitDialog(
|
||||
LoadStringW(hDllInstance, (pNetIdData->JoinStatus == NetSetupDomainName)? 6 : 5, szBuffer, ARRAYSIZE(szBuffer));
|
||||
SetDlgItemText(hwndDlg, IDC_WORKGROUPDOMAIN, szBuffer);
|
||||
SetDlgItemText(hwndDlg, IDC_WORKGROUPDOMAIN_NAME, pNetIdData->JoinName);
|
||||
|
||||
/* Show the administrator note and disable controls when the user is not an administator */
|
||||
if (!IsUserAdmin())
|
||||
{
|
||||
LoadStringW(hDllInstance, 1021, szBuffer, ARRAYSIZE(szBuffer));
|
||||
SetDlgItemText(hwndDlg, IDC_MESSAGETEXT, szBuffer);
|
||||
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_NETWORK_ID), FALSE);
|
||||
EnableWindow(GetDlgItem(hwndDlg, IDC_NETWORK_PROPERTY), FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
|
Loading…
Reference in New Issue
Block a user