- Implement DoesUserHavePrivilege and EnablePrivilege.
- Fix IsUserAdmin.
Modified: trunk/reactos/include/wine/setupapi.h
Modified: trunk/reactos/lib/setupapi/misc.c
Modified: trunk/reactos/lib/setupapi/setupapi.spec

Modified: trunk/reactos/include/wine/setupapi.h
--- trunk/reactos/include/wine/setupapi.h	2005-01-30 19:40:24 UTC (rev 13369)
+++ trunk/reactos/include/wine/setupapi.h	2005-01-31 12:49:46 UTC (rev 13370)
@@ -666,7 +666,9 @@
 
 
 LONG     WINAPI AddTagToGroupOrderList(PCWSTR lpGroupName, DWORD dwUnknown2, DWORD dwUnknown3);
+BOOL     WINAPI DoesUserHavePrivilege(PCWSTR lpPrivilegeName);
 PWSTR    WINAPI DuplicateString(PCWSTR lpSrc);
+BOOL     WINAPI EnablePrivilege(PCWSTR lpPrivilegeName, BOOL bEnable);
 void     WINAPI InstallHinfSectionA( HWND hwnd, HINSTANCE handle, PCSTR cmdline, INT show );
 void     WINAPI InstallHinfSectionW( HWND hwnd, HINSTANCE handle, PCWSTR cmdline, INT show );
 #define         InstallHinfSection WINELIB_NAME_AW(InstallHinfSection)

Modified: trunk/reactos/lib/setupapi/misc.c
--- trunk/reactos/lib/setupapi/misc.c	2005-01-30 19:40:24 UTC (rev 13369)
+++ trunk/reactos/lib/setupapi/misc.c	2005-01-31 12:49:46 UTC (rev 13370)
@@ -206,12 +206,17 @@
     TRACE("\n");
 
     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
+    {
         return FALSE;
+    }
 
     if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
     {
-        CloseHandle(hToken);
-        return FALSE;
+        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+        {
+            CloseHandle(hToken);
+            return FALSE;
+        }
     }
 
     lpGroups = MyMalloc(dwSize);
@@ -338,3 +343,118 @@
 
     return lpMultiByteStr;
 }
+
+
+/**************************************************************************
+ * DoesUserHavePrivilege [SETUPAPI.@]
+ *
+ * Check whether the current user has got a given privilege.
+ *
+ * PARAMS
+ *     lpPrivilegeName  [I] Name of the privilege to be checked
+ *
+ * RETURNS
+ *     Success: TRUE
+ *     Failure: FALSE
+ */
+BOOL WINAPI DoesUserHavePrivilege(LPCWSTR lpPrivilegeName)
+{
+    HANDLE hToken;
+    DWORD dwSize;
+    PTOKEN_PRIVILEGES lpPrivileges;
+    LUID PrivilegeLuid;
+    DWORD i;
+    BOOL bResult = FALSE;
+
+    TRACE("%s\n", debugstr_w(lpPrivilegeName));
+
+    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
+        return FALSE;
+
+    if (!GetTokenInformation(hToken, TokenPrivileges, NULL, 0, &dwSize))
+    {
+        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+        {
+            CloseHandle(hToken);
+            return FALSE;
+        }
+    }
+
+    lpPrivileges = MyMalloc(dwSize);
+    if (lpPrivileges == NULL)
+    {
+        CloseHandle(hToken);
+        return FALSE;
+    }
+
+    if (!GetTokenInformation(hToken, TokenPrivileges, lpPrivileges, dwSize, &dwSize))
+    {
+        MyFree(lpPrivileges);
+        CloseHandle(hToken);
+        return FALSE;
+    }
+
+    CloseHandle(hToken);
+
+    if (!LookupPrivilegeValueW(NULL, lpPrivilegeName, &PrivilegeLuid))
+    {
+        MyFree(lpPrivileges);
+        return FALSE;
+    }
+
+    for (i = 0; i < lpPrivileges->PrivilegeCount; i++)
+    {
+        if (lpPrivileges->Privileges[i].Luid.HighPart == PrivilegeLuid.HighPart &&
+            lpPrivileges->Privileges[i].Luid.LowPart == PrivilegeLuid.LowPart)
+        {
+            bResult = TRUE;
+        }
+    }
+
+    MyFree(lpPrivileges);
+
+    return bResult;
+}
+
+
+/**************************************************************************
+ * EnablePrivilege [SETUPAPI.@]
+ *
+ * Enables or disables one of the current users privileges.
+ *
+ * PARAMS
+ *     lpPrivilegeName  [I] Name of the privilege to be changed
+ *     bEnable          [I] TRUE: Enables the privilege
+ *                          FALSE: Disables the privilege
+ *
+ * RETURNS
+ *     Success: TRUE
+ *     Failure: FALSE
+ */
+BOOL WINAPI EnablePrivilege(LPCWSTR lpPrivilegeName, BOOL bEnable)
+{
+    TOKEN_PRIVILEGES Privileges;
+    HANDLE hToken;
+    BOOL bResult;
+
+    TRACE("%s %s\n", debugstr_w(lpPrivilegeName), bEnable ? "TRUE" : "FALSE");
+
+    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
+        return FALSE;
+
+    Privileges.PrivilegeCount = 1;
+    Privileges.Privileges[0].Attributes = (bEnable) ? SE_PRIVILEGE_ENABLED : 0;
+
+    if (!LookupPrivilegeValueW(NULL, lpPrivilegeName,
+                               &Privileges.Privileges[0].Luid))
+    {
+        CloseHandle(hToken);
+        return FALSE;
+    }
+
+    bResult = AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, NULL, NULL);
+
+    CloseHandle(hToken);
+
+    return bResult;
+}

Modified: trunk/reactos/lib/setupapi/setupapi.spec
--- trunk/reactos/lib/setupapi/setupapi.spec	2005-01-30 19:40:24 UTC (rev 13369)
+++ trunk/reactos/lib/setupapi/setupapi.spec	2005-01-31 12:49:46 UTC (rev 13370)
@@ -197,9 +197,9 @@
 @ stub DelayedMove
 @ stub DelimStringToMultiSz
 @ stub DestroyTextFileReadBuffer
-@ stub DoesUserHavePrivilege
+@ stdcall DoesUserHavePrivilege(wstr)
 @ stdcall DuplicateString(wstr)
-@ stub EnablePrivilege
+@ stdcall EnablePrivilege(wstr long)
 @ stub ExtensionPropSheetPageProc
 @ stub FileExists
 @ stub FreeStringArray