https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8c4b0c91428025b179196…
commit 8c4b0c91428025b179196030a677c512f0af7428
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Fri May 1 22:34:01 2020 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Fri May 1 22:34:01 2020 +0200
[NETID] Disable the 'Network ID' and 'Change' buttons and show the
admin note when the current user is not an administrator
---
dll/win32/netid/netid.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/dll/win32/netid/netid.c b/dll/win32/netid/netid.c
index 4d87a7a6cc7..2e2a1294525 100644
--- a/dll/win32/netid/netid.c
+++ b/dll/win32/netid/netid.c
@@ -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