diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index a9efa2add47..08c0c794fa7 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -30,6 +30,7 @@ #include "lzexpand.h" #include "softpub.h" #include "mscat.h" +#include "shlobj.h" #include "wine/unicode.h" #include "wine/debug.h" @@ -197,67 +198,8 @@ LONG WINAPI QueryRegistryValue(HKEY hKey, */ BOOL WINAPI IsUserAdmin(VOID) { - SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY}; - HANDLE hToken; - DWORD dwSize; - PTOKEN_GROUPS lpGroups; - PSID lpSid; - DWORD i; - BOOL bResult = FALSE; - TRACE("\n"); - - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) - { - return FALSE; - } - - if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize)) - { - if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) - { - CloseHandle(hToken); - return FALSE; - } - } - - lpGroups = MyMalloc(dwSize); - if (lpGroups == NULL) - { - CloseHandle(hToken); - return FALSE; - } - - if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize)) - { - MyFree(lpGroups); - CloseHandle(hToken); - return FALSE; - } - - CloseHandle(hToken); - - if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, - &lpSid)) - { - MyFree(lpGroups); - return FALSE; - } - - for (i = 0; i < lpGroups->GroupCount; i++) - { - if (EqualSid(lpSid, lpGroups->Groups[i].Sid)) - { - bResult = TRUE; - break; - } - } - - FreeSid(lpSid); - MyFree(lpGroups); - - return bResult; + return IsUserAnAdmin(); } diff --git a/dlls/shell32/shell32.spec b/dlls/shell32/shell32.spec index 9d4808fc493..b50890b1a0e 100644 --- a/dlls/shell32/shell32.spec +++ b/dlls/shell32/shell32.spec @@ -251,7 +251,7 @@ 654 stdcall @(long long) shell32_654 # ReadCabinetState@8 660 stdcall -noname FileIconInit(long) - 680 stdcall -noname IsUserAdmin() + 680 stdcall -noname IsUserAnAdmin() 704 stdcall -noname GUIDFromStringW(wstr ptr) diff --git a/dlls/shell32/shellord.c b/dlls/shell32/shellord.c index 5eb45074019..2fef9408570 100644 --- a/dlls/shell32/shellord.c +++ b/dlls/shell32/shellord.c @@ -1279,13 +1279,79 @@ BOOL WINAPI FileIconInit(BOOL bFullInit) { FIXME("(%s)\n", bFullInit ? "true" : "false"); return 0; } + /************************************************************************* - * IsUserAdmin [SHELL32.680] NT 4.0 + * IsUserAnAdmin [SHELL32.680] NT 4.0 * + * Checks whether the current user is a member of the Administrators group. + * + * PARAMS + * None + * + * RETURNS + * Success: TRUE + * Failure: FALSE */ -HRESULT WINAPI IsUserAdmin(void) -{ FIXME("stub\n"); - return TRUE; +BOOL WINAPI IsUserAnAdmin(VOID) +{ + SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY}; + HANDLE hToken; + DWORD dwSize; + PTOKEN_GROUPS lpGroups; + PSID lpSid; + DWORD i; + BOOL bResult = FALSE; + + TRACE("\n"); + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + return FALSE; + } + + if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize)) + { + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) + { + CloseHandle(hToken); + return FALSE; + } + } + + lpGroups = HeapAlloc(GetProcessHeap(), 0, dwSize); + if (lpGroups == NULL) + { + CloseHandle(hToken); + return FALSE; + } + + if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize)) + { + HeapFree(GetProcessHeap(), 0, lpGroups); + CloseHandle(hToken); + return FALSE; + } + + CloseHandle(hToken); + if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID, + DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, + &lpSid)) + { + HeapFree(GetProcessHeap(), 0, lpGroups); + return FALSE; + } + + for (i = 0; i < lpGroups->GroupCount; i++) + { + if (EqualSid(lpSid, lpGroups->Groups[i].Sid)) + { + bResult = TRUE; + break; + } + } + + FreeSid(lpSid); + HeapFree(GetProcessHeap(), 0, lpGroups); + return bResult; } /************************************************************************* diff --git a/include/shlobj.h b/include/shlobj.h index a608a7e359d..01f8368c0b7 100644 --- a/include/shlobj.h +++ b/include/shlobj.h @@ -77,6 +77,7 @@ VOID WINAPI SHUpdateImageW(LPCWSTR,INT,UINT,INT); #define SHUpdateImage WINELIB_NAME_AW(SHUpdateImage) int WINAPI RestartDialog(HWND,LPCWSTR,DWORD); int WINAPI RestartDialogEx(HWND,LPCWSTR,DWORD,DWORD); +BOOL WINAPI IsUserAnAdmin(void); #define SHFMT_ERROR 0xFFFFFFFFL /* Error on last format, drive may be formattable */ #define SHFMT_CANCEL 0xFFFFFFFEL /* Last format was cancelled */