CVS: winex/dlls/advapi32 advapi32.spec, 1.19, 1.20 security.c, 1.16, 1.17

[email protected] 31 Jul 2007 19:41:07 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/dlls/advapi32 advapi32.spec,1.19,1.20 security.c,1.16,1.17Update of /var/lib/cvsd/cvsroot/winex/dlls/advapi32
In directory agravaine:/tmp/cvs-serv31489/dlls/advapi32

Modified Files:
	advapi32.spec security.c 
Log Message:

- implement LookupPrivilegeName[AW]
- implement LookupPrivilegeValue[AW]
- better implement NtQueryInformationToken() for TokenPrivileges class


Index: advapi32.spec
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/dlls/advapi32/advapi32.spec,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- advapi32.spec	30 Mar 2007 21:18:11 -0000	1.19
+++ advapi32.spec	31 Jul 2007 19:41:05 -0000	1.20
@@ -159,8 +159,8 @@
 @ stdcall LookupAccountSidW(ptr ptr ptr ptr ptr ptr ptr) LookupAccountSidW
 @ stub LookupPrivilegeDisplayNameA
 @ stub LookupPrivilegeDisplayNameW
-@ stub LookupPrivilegeNameA
-@ stub LookupPrivilegeNameW
+@ stdcall LookupPrivilegeNameA(ptr ptr ptr ptr)
+@ stdcall LookupPrivilegeNameW(ptr ptr ptr ptr)
 @ stdcall LookupPrivilegeValueA(ptr ptr ptr) LookupPrivilegeValueA
 @ stdcall LookupPrivilegeValueW(ptr ptr ptr) LookupPrivilegeValueW
 @ stub MakeAbsoluteSD

Index: security.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/dlls/advapi32/security.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- security.c	30 Mar 2007 21:18:18 -0000	1.16
+++ security.c	31 Jul 2007 19:41:05 -0000	1.17
@@ -15,6 +15,101 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
 
+static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
+   {'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
+   {'S','e','A','s','s','i','g','n','P','r','i','m','a','r','y','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
+   {'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
+   {'S','e','I','n','c','r','e','a','s','e','Q','u','o','t','a','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
+   {'S','e','M','a','c','h','i','n','e','A','c','c','o','u','n','t','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_TCB_NAME_W[] =
+   {'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SECURITY_NAME_W[] =
+   {'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
+   {'S','e','T','a','k','e','O','w','n','e','r','s','h','i','p','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
+   {'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
+   {'S','e','S','y','s','t','e','m','P','r','o','f','i','l','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SYSTEMTIME_NAME_W[] =
+   {'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
+   {'S','e','P','r','o','f','i','l','e','S','i','n','g','l','e','P','r','o','c','e','s','s','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
+   {'S','e','I','n','c','r','e','a','s','e','B','a','s','e','P','r','i','o','r','i','t','y','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
+   {'S','e','C','r','e','a','t','e','P','a','g','e','f','i','l','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
+   {'S','e','C','r','e','a','t','e','P','e','r','m','a','n','e','n','t','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_BACKUP_NAME_W[] =
+   {'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_RESTORE_NAME_W[] =
+   {'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SHUTDOWN_NAME_W[] =
+   {'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_DEBUG_NAME_W[] =
+   {'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_AUDIT_NAME_W[] =
+   {'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
+   {'S','e','S','y','s','t','e','m','E','n','v','i','r','o','n','m','e','n','t','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
+   {'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
+   {'S','e','R','e','m','o','t','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_UNDOCK_NAME_W[] =
+   {'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_SYNC_AGENT_NAME_W[] =
+   {'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
+   {'S','e','E','n','a','b','l','e','D','e','l','e','g','a','t','i','o','n','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
+   {'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_IMPERSONATE_NAME_W[] =
+   {'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0};
+static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
+   {'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0};
+
+static const WCHAR *const SePrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
+{
+   NULL,
+   NULL,
+   SE_CREATE_TOKEN_NAME_W,
+   SE_ASSIGNPRIMARYTOKEN_NAME_W,
+   SE_LOCK_MEMORY_NAME_W,
+   SE_INCREASE_QUOTA_NAME_W,
+   SE_MACHINE_ACCOUNT_NAME_W,
+   SE_TCB_NAME_W,
+   SE_SECURITY_NAME_W,
+   SE_TAKE_OWNERSHIP_NAME_W,
+   SE_LOAD_DRIVER_NAME_W,
+   SE_SYSTEM_PROFILE_NAME_W,
+   SE_SYSTEMTIME_NAME_W,
+   SE_PROF_SINGLE_PROCESS_NAME_W,
+   SE_INC_BASE_PRIORITY_NAME_W,
+   SE_CREATE_PAGEFILE_NAME_W,
+   SE_CREATE_PERMANENT_NAME_W,
+   SE_BACKUP_NAME_W,
+   SE_RESTORE_NAME_W,
+   SE_SHUTDOWN_NAME_W,
+   SE_DEBUG_NAME_W,
+   SE_AUDIT_NAME_W,
+   SE_SYSTEM_ENVIRONMENT_NAME_W,
+   SE_CHANGE_NOTIFY_NAME_W,
+   SE_REMOTE_SHUTDOWN_NAME_W,
+   SE_UNDOCK_NAME_W,
+   SE_SYNC_AGENT_NAME_W,
+   SE_ENABLE_DELEGATION_NAME_W,
+   SE_MANAGE_VOLUME_NAME_W,
+   SE_IMPERSONATE_NAME_W,
+   SE_CREATE_GLOBAL_NAME_W,
+};
+
+
 #define CallWin32ToNt(func) \
 	{ NTSTATUS ret; \
 	  ret = (func); \
@@ -547,6 +642,70 @@
 	##############################
 */
 
+
+/*************************************************************************
+ * LookupPrivilegeNameW [ADVAPI32.@]
+ */
+BOOL WINAPI LookupPrivilegeNameW (LPCWSTR lpSystemName, PLUID lpLuid,
+                                  LPWSTR lpName, LPDWORD cchName)
+{
+   INT Len;
+
+   TRACE ("(%s, %p, %p, %p)\n", debugstr_w (lpSystemName), lpLuid,
+          lpName, cchName);
+
+   /* FIXME - check lpSystemName */
+
+   if (lpLuid->HighPart ||
+       (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE) ||
+       (lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
+   {
+      SetLastError (ERROR_NO_SUCH_PRIVILEGE);
+      return FALSE;
+   }
+
+   Len = strlenW (SePrivNames[lpLuid->LowPart]);
+   if (*cchName < (Len + 1))
+   {
+      *cchName = Len + 1;
+      SetLastError (ERROR_INSUFFICIENT_BUFFER);
+      return FALSE;
+   }
+
+   strcpyW (lpName, SePrivNames[lpLuid->LowPart]);
+   *cchName = Len;
+   return TRUE;
+}
+
+
+/*************************************************************************
+ * LookupPrivilegeNameA [ADVAPI32.@]
+ */
+BOOL WINAPI LookupPrivilegeNameA (LPCSTR lpSystemName, PLUID lpLuid,
+                                  LPSTR lpName, LPDWORD cchName)
+{
+   LPWSTR lpSystemNameW = HEAP_strdupAtoW (GetProcessHeap (), 0, lpSystemName);
+   LPWSTR lpNameW = NULL;
+   BOOL Ret;
+
+   TRACE ("(%s, %p, %p, %p)\n", lpSystemName, lpLuid, lpName, cchName);
+
+   if (*cchName)
+      lpNameW = HeapAlloc (GetProcessHeap (), 0, *cchName * sizeof (WCHAR));
+
+   Ret = LookupPrivilegeNameW (lpSystemNameW, lpLuid, lpNameW, cchName);
+   if (Ret)
+      WideCharToMultiByte (CP_ACP, 0, lpNameW, -1, lpName, *cchName,
+                           NULL, NULL);
+
+   if (lpNameW)
+      HeapFree (GetProcessHeap (), 0, lpNameW);
+   HeapFree (GetProcessHeap (), 0, lpSystemNameW);
+
+   return Ret;
+}
+
+
 /******************************************************************************
  * LookupPrivilegeValueW			[ADVAPI32.@]
  * Retrieves LUID used on a system to represent the privilege name.
@@ -562,23 +721,46 @@
  * RETURNS STD
  */
 BOOL WINAPI
-LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
+LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
 {
-    FIXME("(%s,%s,%p): stub\n",debugstr_w(lpSystemName),
-        debugstr_w(lpName), lpLuid);
-    return TRUE;
+   int i;
+
+   TRACE ("(%s, %s, %p)\n", debugstr_w (lpSystemName), debugstr_w (lpName),
+          lpLuid);
+
+   /* FIXME - check lpSystemName */
+
+   if (!lpName)
+   {
+      SetLastError (ERROR_NO_SUCH_PRIVILEGE);
+      return FALSE;
+   }
+
+   for (i = SE_MIN_WELL_KNOWN_PRIVILEGE; i <= SE_MAX_WELL_KNOWN_PRIVILEGE; i++)
+   {
+      if (strcmpiW (SePrivNames[i], lpName))
+         continue;
+
+      lpLuid->HighPart = 0;
+      lpLuid->LowPart = i;
+      return TRUE;
+   }
+
+   SetLastError (ERROR_NO_SUCH_PRIVILEGE);
+   return FALSE;
 }
 
 /******************************************************************************
  * LookupPrivilegeValueA			[ADVAPI32.@]
  */
 BOOL WINAPI
-LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
+LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
 {
     LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
     LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
     BOOL ret;
 
+    TRACE ("(%s, %s, %p)\n", lpSystemName, lpName, lpLuid);
     ret = LookupPrivilegeValueW( lpSystemNameW, lpNameW, lpLuid);
     HeapFree(GetProcessHeap(), 0, lpNameW);
     HeapFree(GetProcessHeap(), 0, lpSystemNameW);