diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index de7b42a3121b6b83bec05cc8ad1dcb9b51916362..9f4d5e9f23e273140c63ddfb511641ff8ddbad2b 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -1,5 +1,6 @@
 /*
  * dlls/advapi32/security.c
+ *  FIXME: for all functions thunking down to Rtl* functions:  implement SetLastError()
  */
 #include <string.h>
 
@@ -8,8 +9,17 @@
 #include "winerror.h"
 #include "heap.h"
 #include "ntdll.h"
+#include "ntddk.h"
 #include "debug.h"
 
+#define CallWin32ToNt(func) \
+	{ NTSTATUS ret; \
+	  ret = (func); \
+	  if (ret !=STATUS_SUCCESS) \
+	  { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
+	  return TRUE; \
+	}
+
 /* FIXME: move it to a header */
 BOOL32 WINAPI IsValidSid (PSID pSid);
 BOOL32 WINAPI EqualSid (PSID pSid1, PSID pSid2);
@@ -24,6 +34,10 @@ BYTE*  WINAPI GetSidSubAuthorityCount(PSID pSid);
 DWORD  WINAPI GetLengthSid(PSID pSid);
 BOOL32 WINAPI CopySid(DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid);
 
+/*	##############################
+	######	TOKEN FUNCTIONS ######
+	##############################
+*/
 
 /******************************************************************************
  * OpenProcessToken			[ADVAPI32.109]
@@ -40,8 +54,27 @@ BOOL32 WINAPI
 OpenProcessToken( HANDLE32 ProcessHandle, DWORD DesiredAccess, 
                   HANDLE32 *TokenHandle )
 {
-	FIXME(advapi,"(%08x,%08lx,%p): stub\n",ProcessHandle,DesiredAccess,
-          TokenHandle);
+	FIXME(advapi,"(%08x,%08lx,%p): stub\n",ProcessHandle,DesiredAccess, TokenHandle);
+	SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+	return FALSE;
+}
+
+/******************************************************************************
+ * AdjustTokenPrivileges [ADVAPI32.10]
+ *
+ * PARAMS
+ *   TokenHandle          []
+ *   DisableAllPrivileges []
+ *   NewState             []
+ *   BufferLength         []
+ *   PreviousState        []
+ *   ReturnLength         []
+ */
+BOOL32 WINAPI
+AdjustTokenPrivileges( HANDLE32 TokenHandle, BOOL32 DisableAllPrivileges,
+                       LPVOID NewState, DWORD BufferLength, 
+                       LPVOID PreviousState, LPDWORD ReturnLength )
+{	FIXME(advapi, "stub\n"); 
 	SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
 	return FALSE;
 }
@@ -65,102 +98,98 @@ OpenThreadToken( HANDLE32 thread, DWORD desiredaccess, BOOL32 openasself,
 	return TRUE;
 }
 
-
 /******************************************************************************
- * LookupPrivilegeValue32A			[ADVAPI32.92]
- */
-BOOL32 WINAPI
-LookupPrivilegeValue32A( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
-{
-    LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
-    LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
-    BOOL32 ret = LookupPrivilegeValue32W( lpSystemNameW, lpNameW, lpLuid);
-    HeapFree(GetProcessHeap(), 0, lpNameW);
-    HeapFree(GetProcessHeap(), 0, lpSystemNameW);
-    return ret;
-}
-
-/******************************************************************************
- * LookupPrivilegeValue32W			[ADVAPI32.93]
- * Retrieves LUID used on a system to represent the privilege name.
- *
- * NOTES
- *   lpLuid should be PLUID
+ * GetTokenInformation [ADVAPI32.66]
  *
  * PARAMS
- *   lpSystemName [I] Address of string specifying the system
- *   lpName       [I] Address of string specifying the privilege
- *   lpLuid       [I] Address of locally unique identifier
- *
- * RETURNS STD
- */
-BOOL32 WINAPI
-LookupPrivilegeValue32W( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
-{
-    FIXME(advapi,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName), 
-                  debugstr_w(lpName), lpLuid);
-    return TRUE;
-}
-/******************************************************************************
- * GetFileSecurity32A [ADVAPI32.45]
+ *   token           []
+ *   tokeninfoclass  []
+ *   tokeninfo       []
+ *   tokeninfolength []
+ *   retlen          []
  *
- * Obtains Specified information about the security of a file or directory
- * The information obtained is constrained by the callers access rights and
- * privileges
+ * FIXME
+ *   tokeninfoclas should be TOKEN_INFORMATION_CLASS
  */
 BOOL32 WINAPI
-GetFileSecurity32A( LPCSTR lpFileName, 
-                    SECURITY_INFORMATION RequestedInformation,
-                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
-                    DWORD nLength, LPDWORD lpnLengthNeeded )
+GetTokenInformation( HANDLE32 token, DWORD tokeninfoclass, LPVOID tokeninfo,
+                     DWORD tokeninfolength, LPDWORD retlen )
 {
-  FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
-  return TRUE;
+	FIXME(advapi,"(%08x,%ld,%p,%ld,%p): stub\n",
+	      token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
+	return FALSE;
 }
 
+/*	##############################
+	######	SID FUNCTIONS	######
+	##############################
+*/
+
 /******************************************************************************
- * GetFileSecurity32W [ADVAPI32.46]
- *
- * Obtains Specified information about the security of a file or directory
- * The information obtained is constrained by the callers access rights and
- * privileges
+ * AllocateAndInitializeSid [ADVAPI32.11]
  *
  * PARAMS
- *   lpFileName           []
- *   RequestedInformation []
- *   pSecurityDescriptor  []
- *   nLength              []
- *   lpnLengthNeeded      []
+ *   pIdentifierAuthority []
+ *   nSubAuthorityCount   []
+ *   nSubAuthority0       []
+ *   nSubAuthority1       []
+ *   nSubAuthority2       []
+ *   nSubAuthority3       []
+ *   nSubAuthority4       []
+ *   nSubAuthority5       []
+ *   nSubAuthority6       []
+ *   nSubAuthority7       []
+ *   pSid                 []
  */
 BOOL32 WINAPI
-GetFileSecurity32W( LPCWSTR lpFileName, 
-                    SECURITY_INFORMATION RequestedInformation,
-                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
-                    DWORD nLength, LPDWORD lpnLengthNeeded )
+AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+                          BYTE nSubAuthorityCount,
+                          DWORD nSubAuthority0, DWORD nSubAuthority1,
+                          DWORD nSubAuthority2, DWORD nSubAuthority3,
+                          DWORD nSubAuthority4, DWORD nSubAuthority5,
+                          DWORD nSubAuthority6, DWORD nSubAuthority7,
+                          PSID *pSid )
 {
-  FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) ); 
-  return TRUE;
-}
+    if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
+                             GetSidLengthRequired(nSubAuthorityCount))))
+        return FALSE;
+    (*pSid)->Revision = SID_REVISION;
+    if (pIdentifierAuthority)
+        memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
+               sizeof (SID_IDENTIFIER_AUTHORITY));
+    *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
 
+    if (nSubAuthorityCount > 0)
+        *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
+    if (nSubAuthorityCount > 1)
+        *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
+    if (nSubAuthorityCount > 2)
+        *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
+    if (nSubAuthorityCount > 3)
+        *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
+    if (nSubAuthorityCount > 4)
+        *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
+    if (nSubAuthorityCount > 5)
+        *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
+    if (nSubAuthorityCount > 6)
+        *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
+    if (nSubAuthorityCount > 7)
+        *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
+
+    return TRUE;
+}
 
 /******************************************************************************
- * AdjustTokenPrivileges [ADVAPI32.10]
+ * FreeSid [ADVAPI32.42]
  *
  * PARAMS
- *   TokenHandle          []
- *   DisableAllPrivileges []
- *   NewState             []
- *   BufferLength         []
- *   PreviousState        []
- *   ReturnLength         []
+ *   pSid []
  */
-BOOL32 WINAPI
-AdjustTokenPrivileges( HANDLE32 TokenHandle, BOOL32 DisableAllPrivileges,
-                       LPVOID NewState, DWORD BufferLength, 
-                       LPVOID PreviousState, LPDWORD ReturnLength )
-{	FIXME(advapi, "stub\n"); 
-	SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-	return FALSE;
+VOID* WINAPI
+FreeSid( PSID pSid )
+{
+    HeapFree( GetProcessHeap(), 0, pSid );
+    return NULL;
 }
 
 /******************************************************************************
@@ -253,94 +282,83 @@ GetSidLengthRequired( BYTE nSubAuthorityCount )
 }
 
 /******************************************************************************
- * GetTokenInformation [ADVAPI32.66]
+ * InitializeSid [ADVAPI32.74]
  *
  * PARAMS
- *   token           []
- *   tokeninfoclass  []
- *   tokeninfo       []
- *   tokeninfolength []
- *   retlen          []
- *
- * FIXME
- *   tokeninfoclas should be TOKEN_INFORMATION_CLASS
+ *   pIdentifierAuthority []
  */
 BOOL32 WINAPI
-GetTokenInformation( HANDLE32 token, DWORD tokeninfoclass, LPVOID tokeninfo,
-                     DWORD tokeninfolength, LPDWORD retlen )
+InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+                    BYTE nSubAuthorityCount)
 {
-	FIXME(advapi,"(%08x,%ld,%p,%ld,%p): stub\n",
-	      token,tokeninfoclass,tokeninfo,tokeninfolength,retlen);
-	return FALSE;
+    int i;
+
+    pSid->Revision = SID_REVISION;
+    if (pIdentifierAuthority)
+        memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
+               sizeof (SID_IDENTIFIER_AUTHORITY));
+    *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
+
+    for (i = 0; i < nSubAuthorityCount; i++)
+        *GetSidSubAuthority(pSid, i) = 0;
+
+    return TRUE;
 }
 
 /******************************************************************************
- * AllocateAndInitializeSid [ADVAPI32.11]
+ * GetSidIdentifierAuthority [ADVAPI32.62]
  *
  * PARAMS
- *   pIdentifierAuthority []
- *   nSubAuthorityCount   []
- *   nSubAuthority0       []
- *   nSubAuthority1       []
- *   nSubAuthority2       []
- *   nSubAuthority3       []
- *   nSubAuthority4       []
- *   nSubAuthority5       []
- *   nSubAuthority6       []
- *   nSubAuthority7       []
- *   pSid                 []
+ *   pSid []
  */
-BOOL32 WINAPI
-AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
-                          BYTE nSubAuthorityCount,
-                          DWORD nSubAuthority0, DWORD nSubAuthority1,
-                          DWORD nSubAuthority2, DWORD nSubAuthority3,
-                          DWORD nSubAuthority4, DWORD nSubAuthority5,
-                          DWORD nSubAuthority6, DWORD nSubAuthority7,
-                          PSID *pSid )
+PSID_IDENTIFIER_AUTHORITY WINAPI
+GetSidIdentifierAuthority( PSID pSid )
 {
-    if (!(*pSid = HeapAlloc( GetProcessHeap(), 0,
-                             GetSidLengthRequired(nSubAuthorityCount))))
-        return FALSE;
-    (*pSid)->Revision = SID_REVISION;
-    if (pIdentifierAuthority)
-        memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority,
-               sizeof (SID_IDENTIFIER_AUTHORITY));
-    *GetSidSubAuthorityCount(*pSid) = nSubAuthorityCount;
+    return &pSid->IdentifierAuthority;
+}
 
-    if (nSubAuthorityCount > 0)
-        *GetSidSubAuthority(*pSid, 0) = nSubAuthority0;
-    if (nSubAuthorityCount > 1)
-        *GetSidSubAuthority(*pSid, 1) = nSubAuthority1;
-    if (nSubAuthorityCount > 2)
-        *GetSidSubAuthority(*pSid, 2) = nSubAuthority2;
-    if (nSubAuthorityCount > 3)
-        *GetSidSubAuthority(*pSid, 3) = nSubAuthority3;
-    if (nSubAuthorityCount > 4)
-        *GetSidSubAuthority(*pSid, 4) = nSubAuthority4;
-    if (nSubAuthorityCount > 5)
-        *GetSidSubAuthority(*pSid, 5) = nSubAuthority5;
-    if (nSubAuthorityCount > 6)
-        *GetSidSubAuthority(*pSid, 6) = nSubAuthority6;
-    if (nSubAuthorityCount > 7)
-        *GetSidSubAuthority(*pSid, 7) = nSubAuthority7;
+/******************************************************************************
+ * GetSidSubAuthority [ADVAPI32.64]
+ *
+ * PARAMS
+ *   pSid          []
+ *   nSubAuthority []
+ */
+DWORD * WINAPI
+GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
+{
+    return &pSid->SubAuthority[nSubAuthority];
+}
 
-    return TRUE;
+/******************************************************************************
+ * GetSidSubAuthorityCount [ADVAPI32.65]
+ *
+ * PARAMS
+ *   pSid []
+ */
+BYTE * WINAPI
+GetSidSubAuthorityCount (PSID pSid)
+{
+    return &pSid->SubAuthorityCount;
 }
 
 /******************************************************************************
- * FreeSid [ADVAPI32.42]
+ * GetLengthSid [ADVAPI32.48]
  *
  * PARAMS
  *   pSid []
  */
-VOID* WINAPI
-FreeSid( PSID pSid )
+DWORD WINAPI
+GetLengthSid (PSID pSid)
 {
-    HeapFree( GetProcessHeap(), 0, pSid );
-    return NULL;
+    return GetSidLengthRequired( * GetSidSubAuthorityCount(pSid) );
 }
 
+/*	##############################################
+	######	SECURITY DESCRIPTOR FUNCTIONS	######
+	##############################################
+*/
+	
 /******************************************************************************
  * InitializeSecurityDescriptor [ADVAPI32.73]
  *
@@ -349,13 +367,9 @@ FreeSid( PSID pSid )
  *   revision []
  */
 BOOL32 WINAPI
-InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
-                              DWORD revision )
+InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision )
 {
-    TRACE (security, "(%p,%lx): stub\n", pDescr, revision);
-    ZeroMemory (pDescr, sizeof (SECURITY_DESCRIPTOR));
-    pDescr->Revision = revision;
-    return TRUE;
+	CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
 }
 
 /******************************************************************************
@@ -363,8 +377,7 @@ InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr,
  */
 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
 {
-    FIXME(security, "(%p), stub\n", pDescr);
-    return 0;
+	return (RtlLengthSecurityDescriptor(pDescr));
 }
 
 /******************************************************************************
@@ -376,115 +389,194 @@ DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
  */
 BOOL32 WINAPI
 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
-                            LPBOOL32 lpbOwnerDefaulted )
+			    LPBOOL32 lpbOwnerDefaulted )
 {
-    FIXME(security, "(%p,%p,%p), stub\n", pDescr,pOwner,lpbOwnerDefaulted);
-    *lpbOwnerDefaulted = TRUE;
-    return 0;
+	CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
 }
 
 /******************************************************************************
- * GetSecurityDescriptorGroup [ADVAPI32.54]
+ * SetSecurityDescriptorOwner [ADVAPI32]
  *
  * PARAMS
- *   pGroup            []
- *   lpbOwnerDefaulted []
  */
-BOOL32 WINAPI
-GetSecurityDescriptorGroup( SECURITY_DESCRIPTOR *pDescr, PSID *pGroup,
-                            LPBOOL32 lpbOwnerDefaulted )
+BOOL32 SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor, 
+				   PSID pOwner, BOOL32 bOwnerDefaulted)
+{
+	CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
+}
+/******************************************************************************
+ * GetSecurityDescriptorGroup			[ADVAPI32.54]
+ */
+BOOL32 WINAPI GetSecurityDescriptorGroup(
+	PSECURITY_DESCRIPTOR SecurityDescriptor,
+	PSID *Group,
+	LPBOOL32 GroupDefaulted)
+{
+	CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
+}	
+/******************************************************************************
+ * SetSecurityDescriptorGroup
+ */
+BOOL32 WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
+					   PSID Group, BOOL32 GroupDefaulted)
 {
-    FIXME(security, "(%p,%p,%p), stub\n", pDescr,pGroup,lpbOwnerDefaulted);
-    *lpbOwnerDefaulted = TRUE;
-    return 0;
+	CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
 }
 
 /******************************************************************************
- * InitializeSid [ADVAPI32.74]
+ * IsValidSecurityDescriptor [ADVAPI32.79]
  *
  * PARAMS
- *   pIdentifierAuthority []
+ *   lpsecdesc []
  */
 BOOL32 WINAPI
-InitializeSid (PSID pSid, PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
-                    BYTE nSubAuthorityCount)
+IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
 {
-    int i;
-
-    pSid->Revision = SID_REVISION;
-    if (pIdentifierAuthority)
-        memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority,
-               sizeof (SID_IDENTIFIER_AUTHORITY));
-    *GetSidSubAuthorityCount(pSid) = nSubAuthorityCount;
+	CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
+}
 
-    for (i = 0; i < nSubAuthorityCount; i++)
-        *GetSidSubAuthority(pSid, i) = 0;
+/******************************************************************************
+ *  GetSecurityDescriptorDacl			[ADVAPI.91]
+ */
+BOOL32 WINAPI GetSecurityDescriptorDacl(
+	IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
+	OUT LPBOOL32 lpbDaclPresent,
+	OUT PACL *pDacl,
+	OUT LPBOOL32 lpbDaclDefaulted)
+{
+	CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
+					       pDacl, (PBOOLEAN)lpbDaclDefaulted));
+}	
 
-    return TRUE;
+/******************************************************************************
+ *  SetSecurityDescriptorDacl			[ADVAPI.224]
+ */
+BOOL32 WINAPI 
+SetSecurityDescriptorDacl ( PSECURITY_DESCRIPTOR lpsd, BOOL32 daclpresent,
+			    PACL dacl, BOOL32 dacldefaulted )
+{
+	CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
+}	
+/**************************************************************************
+ * SetSecurityDescriptorSacl			[NTDLL.488]
+ */
+BOOL32  WINAPI SetSecurityDescriptorSacl (
+	PSECURITY_DESCRIPTOR lpsd,
+	BOOL32 saclpresent,
+	PACL sacl,
+	BOOL32 sacldefaulted)
+{
+	CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, sacl, sacldefaulted));
 }
-
 /******************************************************************************
- * GetSidIdentifierAuthority [ADVAPI32.62]
+ * MakeSelfRelativeSD [ADVAPI32.95]
  *
  * PARAMS
- *   pSid []
+ *   lpabssecdesc  []
+ *   lpselfsecdesc []
+ *   lpbuflen      []
  */
-PSID_IDENTIFIER_AUTHORITY WINAPI
-GetSidIdentifierAuthority( PSID pSid )
+BOOL32 WINAPI
+MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc,
+                    PSECURITY_DESCRIPTOR lpselfsecdesc, LPDWORD lpbuflen )
 {
-    return &pSid->IdentifierAuthority;
+	FIXME(advapi,"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
+	return TRUE;
 }
 
 /******************************************************************************
- * GetSidSubAuthority [ADVAPI32.64]
+ * GetSecurityDescriptorControl32			[ADVAPI32]
+ */
+
+BOOL32 GetSecurityDescriptorControl32 ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
+		 /* fixme: PSECURITY_DESCRIPTOR_CONTROL*/ LPVOID pControl, LPDWORD lpdwRevision)
+{	FIXME(advapi,"(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
+	return 1;
+}		
+
+/*	##############################
+	######	MISC FUNCTIONS	######
+	##############################
+*/
+
+/******************************************************************************
+ * LookupPrivilegeValue32W			[ADVAPI32.93]
+ * Retrieves LUID used on a system to represent the privilege name.
+ *
+ * NOTES
+ *   lpLuid should be PLUID
  *
  * PARAMS
- *   pSid          []
- *   nSubAuthority []
+ *   lpSystemName [I] Address of string specifying the system
+ *   lpName       [I] Address of string specifying the privilege
+ *   lpLuid       [I] Address of locally unique identifier
+ *
+ * RETURNS STD
  */
-DWORD * WINAPI
-GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
+BOOL32 WINAPI
+LookupPrivilegeValue32W( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
 {
-    return &pSid->SubAuthority[nSubAuthority];
+    FIXME(advapi,"(%s,%s,%p): stub\n",debugstr_w(lpSystemName), 
+                  debugstr_w(lpName), lpLuid);
+    return TRUE;
 }
 
 /******************************************************************************
- * GetSidSubAuthorityCount [ADVAPI32.65]
- *
- * PARAMS
- *   pSid []
+ * LookupPrivilegeValue32A			[ADVAPI32.92]
  */
-BYTE * WINAPI
-GetSidSubAuthorityCount (PSID pSid)
+BOOL32 WINAPI
+LookupPrivilegeValue32A( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
 {
-    return &pSid->SubAuthorityCount;
+    LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
+    LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
+    BOOL32 ret = LookupPrivilegeValue32W( lpSystemNameW, lpNameW, lpLuid);
+    HeapFree(GetProcessHeap(), 0, lpNameW);
+    HeapFree(GetProcessHeap(), 0, lpSystemNameW);
+    return ret;
 }
 
 /******************************************************************************
- * GetLengthSid [ADVAPI32.48]
+ * GetFileSecurity32A [ADVAPI32.45]
  *
- * PARAMS
- *   pSid []
+ * Obtains Specified information about the security of a file or directory
+ * The information obtained is constrained by the callers access rights and
+ * privileges
  */
-DWORD WINAPI
-GetLengthSid (PSID pSid)
+BOOL32 WINAPI
+GetFileSecurity32A( LPCSTR lpFileName, 
+                    SECURITY_INFORMATION RequestedInformation,
+                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
+                    DWORD nLength, LPDWORD lpnLengthNeeded )
 {
-    return GetSidLengthRequired( * GetSidSubAuthorityCount(pSid) );
+  FIXME(advapi, "(%s) : stub\n", debugstr_a(lpFileName));
+  return TRUE;
 }
 
 /******************************************************************************
- * IsValidSecurityDescriptor [ADVAPI32.79]
+ * GetFileSecurity32W [ADVAPI32.46]
+ *
+ * Obtains Specified information about the security of a file or directory
+ * The information obtained is constrained by the callers access rights and
+ * privileges
  *
  * PARAMS
- *   lpsecdesc []
+ *   lpFileName           []
+ *   RequestedInformation []
+ *   pSecurityDescriptor  []
+ *   nLength              []
+ *   lpnLengthNeeded      []
  */
 BOOL32 WINAPI
-IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR lpsecdesc )
+GetFileSecurity32W( LPCWSTR lpFileName, 
+                    SECURITY_INFORMATION RequestedInformation,
+                    PSECURITY_DESCRIPTOR pSecurityDescriptor,
+                    DWORD nLength, LPDWORD lpnLengthNeeded )
 {
-	FIXME(advapi,"(%p):stub\n",lpsecdesc);
-	return TRUE;
+  FIXME(advapi, "(%s) : stub\n", debugstr_w(lpFileName) ); 
+  return TRUE;
 }
 
+
 /******************************************************************************
  * LookupAccountSid32A [ADVAPI32.86]
  */
@@ -552,22 +644,6 @@ SetFileSecurity32W( LPCWSTR lpFileName,
   return TRUE;
 }
 
-/******************************************************************************
- * MakeSelfRelativeSD [ADVAPI32.95]
- *
- * PARAMS
- *   lpabssecdesc  []
- *   lpselfsecdesc []
- *   lpbuflen      []
- */
-BOOL32 WINAPI
-MakeSelfRelativeSD( PSECURITY_DESCRIPTOR lpabssecdesc,
-                    PSECURITY_DESCRIPTOR lpselfsecdesc, LPDWORD lpbuflen )
-{
-	FIXME(advapi,"(%p,%p,%p),stub!\n",lpabssecdesc,lpselfsecdesc,lpbuflen);
-	return TRUE;
-}
-
 /******************************************************************************
  * QueryWindows31FilesMigration [ADVAPI32.266]
  *
@@ -627,16 +703,6 @@ NotifyBootConfigStatus( DWORD x1 )
 	return 1;
 }
 
-/******************************************************************************
- * GetSecurityDescriptorControl32			[ADVAPI32]
- */
-
-BOOL32 GetSecurityDescriptorControl32 ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
-		 /* fixme: PSECURITY_DESCRIPTOR_CONTROL*/ LPVOID pControl, LPDWORD lpdwRevision)
-{	FIXME(advapi,"(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
-	return 1;
-}		
-
 /******************************************************************************
  * RevertToSelf [ADVAPI32.180]
  *
@@ -660,6 +726,9 @@ ImpersonateSelf32(DWORD/*SECURITY_IMPERSONATION_LEVEL*/ ImpersonationLevel)
     return TRUE;
 }
 
+/******************************************************************************
+ * AccessCheck32 [ADVAPI32.71]
+ */
 BOOL32 WINAPI
 AccessCheck32(PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE32 ClientToken, DWORD DesiredAccess, LPVOID/*LPGENERIC_MAPPING*/ GenericMapping, LPVOID/*LPPRIVILEGE_SET*/ PrivilegeSet, LPDWORD PrivilegeSetLength, LPDWORD GrantedAccess, LPBOOL32 AccessStatus)
 {
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index 259048063e62d1730ea7b2eb61d30d51521e9558..005c29178730398b5909bf15ca6b4844eabfaabc 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -44,7 +44,8 @@ NTSTATUS WINAPI NtOpenFile(
 	ULONG OpenOptions)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),%p,0x%08lx,0x%08lx) stub\n",
-	FileHandle, DesiredAccess, ObjectAttributes, debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	FileHandle, DesiredAccess, ObjectAttributes, 
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	IoStatusBlock, ShareAccess, OpenOptions);
 	return 0;
 }
@@ -81,7 +82,8 @@ NTSTATUS WINAPI NtCreateFile(
 	ULONG EaLength)  
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),%p,%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p,0x%08lx) stub\n",
-	FileHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	FileHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	IoStatusBlock,AllocateSize,FileAttributes,
 	ShareAccess,CreateDisposition,CreateOptions,EaBuffer,EaLength);
 	return 0;
@@ -96,7 +98,8 @@ NTSTATUS WINAPI NtCreateTimer(
 	IN TIMER_TYPE TimerType)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),0x%08x) stub\n",
-	TimerHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	TimerHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	TimerType);
 	return 0;
 }
@@ -108,11 +111,11 @@ NTSTATUS WINAPI NtSetTimer(
 	IN PLARGE_INTEGER DueTime,
 	IN PTIMERAPCROUTINE TimerApcRoutine,
 	IN PVOID TimerContext,
-	IN BOOL WakeTimer,
+	IN BOOLEAN WakeTimer,
 	IN ULONG Period OPTIONAL,
 	OUT PBOOLEAN PreviousState OPTIONAL)
 {
-	FIXME(ntdll,"(0x%08x,%p,%p,%p,%08lx,0x%08lx,%p) stub\n",
+	FIXME(ntdll,"(0x%08x,%p,%p,%p,%08x,0x%08lx,%p) stub\n",
 	TimerHandle,DueTime,TimerApcRoutine,TimerContext,WakeTimer,Period,PreviousState);
 	return 0;
 }
@@ -128,7 +131,8 @@ NTSTATUS WINAPI NtCreateEvent(
 	IN BOOLEAN InitialState)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),%08x,%08x): empty stub\n",
-	EventHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	EventHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	ManualReset,InitialState);
 	return 0;
 }
@@ -168,7 +172,8 @@ NTSTATUS WINAPI NtOpenDirectoryObject(
 	POBJECT_ATTRIBUTES ObjectAttributes)
 {
     FIXME(ntdll,"(%p,0x%08lx,%p(%s)): stub\n", 
-    DirectoryHandle, DesiredAccess, ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+    DirectoryHandle, DesiredAccess, ObjectAttributes,
+    ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
     return 0;
 }
 
@@ -393,7 +398,7 @@ NTSTATUS WINAPI NtDuplicateToken(
  */
 NTSTATUS WINAPI NtAdjustPrivilegesToken(
 	IN HANDLE32 TokenHandle,
-	IN BOOL32 DisableAllPrivileges,
+	IN BOOLEAN DisableAllPrivileges,
 	IN PTOKEN_PRIVILEGES NewState,
 	IN DWORD BufferLength,
 	OUT PTOKEN_PRIVILEGES PreviousState,
@@ -509,7 +514,8 @@ NTSTATUS WINAPI NtOpenEvent(
 	IN POBJECT_ATTRIBUTES ObjectAttributes)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s)),stub!\n",
-	EventHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+	EventHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
 	return 0;
 }
 
@@ -529,7 +535,8 @@ NTSTATUS WINAPI NtWaitForSingleObject(
  *  NtConnectPort		[NTDLL] 
  */
 NTSTATUS WINAPI NtConnectPort(DWORD x1,PUNICODE_STRING uni,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8) {
-	FIXME(ntdll,"(0x%08lx,%s,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,debugstr_w(uni->Buffer),x3,x4,x5,x6,x7,x8);
+	FIXME(ntdll,"(0x%08lx,%s,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",
+	x1,debugstr_w(uni->Buffer),x3,x4,x5,x6,x7,x8);
 	return 0;
 }
 
@@ -558,7 +565,8 @@ NTSTATUS WINAPI NtCreateDirectoryObject(
 	POBJECT_ATTRIBUTES ObjectAttributes) 
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s)),stub!\n",
-	DirectoryHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+	DirectoryHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
 	return 0;
 }
 
@@ -651,7 +659,8 @@ NTSTATUS WINAPI NtCreateSection(
 	IN HANDLE32 FileHandle OPTIONAL)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),%p,0x%08lx,0x%08lx,0x%08x) stub\n",
-	SectionHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	SectionHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	MaximumSize,SectionPageProtection,AllocationAttributes,FileHandle);
 	return 0;
 }
@@ -707,10 +716,9 @@ NTSTATUS WINAPI NtTerminateThread(
 	IN HANDLE32 ThreadHandle,
 	IN NTSTATUS ExitStatus)
 {
-	BOOL32	ret = TerminateThread(ThreadHandle,ExitStatus);
+	if ( TerminateThread(ThreadHandle,ExitStatus) )
+	  return 0;
 
-	if (ret)
-		return 0;
 	return 0xc0000000; /* FIXME: lasterror->ntstatus */
 }
 
@@ -731,13 +739,14 @@ NTSTATUS WINAPI NtOpenSection(
 	POBJECT_ATTRIBUTES ObjectAttributes)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s)),stub!\n",
-	SectionHandle,DesiredAccess,ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+	SectionHandle,DesiredAccess,ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
 	return 0;
 }
 /******************************************************************************
  *  NtQueryPerformanceCounter	[NTDLL] 
  */
-BOOL32 WINAPI NtQueryPerformanceCounter(
+NTSTATUS WINAPI NtQueryPerformanceCounter(
 	IN PLARGE_INTEGER Counter,
 	IN PLARGE_INTEGER Frequency) 
 {
@@ -778,7 +787,8 @@ NTSTATUS WINAPI NtCreateSemaphore(
 	IN ULONG MaximumCount) 
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s),0x%08lx,0x%08lx) stub!\n",
-	SemaphoreHandle, DesiredAccess, ObjectAttributes, debugstr_w(ObjectAttributes->ObjectName->Buffer),
+	SemaphoreHandle, DesiredAccess, ObjectAttributes, 
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL,
 	InitialCount, MaximumCount);
 	return 0;
 }
@@ -791,7 +801,8 @@ NTSTATUS WINAPI NtOpenSemaphore(
 	IN POBJECT_ATTRIBUTES ObjectAttributes)
 {
 	FIXME(ntdll,"(0x%08x,0x%08lx,%p(%s)) stub!\n",
-	SemaphoreHandle, DesiredAcces, ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+	SemaphoreHandle, DesiredAcces, ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
 	return 0;
 }
 
@@ -832,7 +843,8 @@ NTSTATUS WINAPI NtCreateSymbolicLinkObject(
 	IN PUNICODE_STRING Name)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s), %p) stub\n",
-	SymbolicLinkHandle, DesiredAccess, ObjectAttributes, debugstr_w(ObjectAttributes->ObjectName->Buffer), Name);
+	SymbolicLinkHandle, DesiredAccess, ObjectAttributes, 
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL, Name);
 	return 0;
 }
 
@@ -845,7 +857,8 @@ NTSTATUS WINAPI NtOpenSymbolicLinkObject(
 	IN POBJECT_ATTRIBUTES ObjectAttributes)
 {
 	FIXME(ntdll,"(%p,0x%08lx,%p(%s)) stub\n",
-	LinkHandle, DesiredAccess, ObjectAttributes,debugstr_w(ObjectAttributes->ObjectName->Buffer));
+	LinkHandle, DesiredAccess, ObjectAttributes,
+	ObjectAttributes ? debugstr_w(ObjectAttributes->ObjectName->Buffer) : NULL);
 	return 0;
 }
 /******************************************************************************
diff --git a/dlls/ntdll/rtl.c b/dlls/ntdll/rtl.c
index 517faf7d3558548177cc8b4bd48ef306f43dd19b..b58e51ef9723e917cb8ed3e17646f4cecbd533c4 100644
--- a/dlls/ntdll/rtl.c
+++ b/dlls/ntdll/rtl.c
@@ -17,18 +17,53 @@
 #include "winuser.h"
 #include "wine/winestring.h"
 #include "file.h"
-#include "stackframe.h"
+#include "heap.h"
 #include "winnls.h"
-#include "ntdll.h"
 #include "debugstr.h"
-#include "heap.h"
+#include "debug.h"
+#include "winuser.h"
+#include "winerror.h"
+#include "stackframe.h"
+
+#include "ntdll.h"
 #include "ntdef.h"
 #include "winreg.h"
 
-#include "debug.h"
 
-/* fixme: move to windef.h*/
-typedef BOOL32 *LPBOOL;   
+/*	##############################
+	######	SID FUNCTIONS	######
+	##############################
+*/
+/******************************************************************************
+ *  RtlAllocateAndInitializeSid		[NTDLL.265] 
+ *
+ */
+BOOLEAN WINAPI RtlAllocateAndInitializeSid (PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+	DWORD nSubAuthorityCount,DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8,DWORD x9,DWORD x10, PSID pSid) 
+{
+	FIXME(ntdll,"(%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p),stub!\n",
+		pIdentifierAuthority,nSubAuthorityCount,x3,x4,x5,x6,x7,x8,x9,x10,pSid);
+	return 0;
+}
+/******************************************************************************
+ *  RtlEqualSid		[NTDLL.352] 
+ *
+ */
+DWORD WINAPI RtlEqualSid(DWORD x1,DWORD x2) 
+{	
+	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n", x1,x2);
+	return TRUE;
+}
+
+/******************************************************************************
+ *  RtlFreeSid		[NTDLL.376] 
+ */
+DWORD WINAPI RtlFreeSid(DWORD x1) 
+{
+	FIXME(ntdll,"(0x%08lx),stub!\n", x1);
+	return TRUE;
+}
+
 /**************************************************************************
  *                 RtlLengthRequiredSid			[NTDLL.427]
  */
@@ -41,90 +76,64 @@ DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
  *                 RtlLengthSid				[NTDLL.429]
  */
 DWORD WINAPI RtlLengthSid(PSID sid)
-{	TRACE(ntdll,"sid=%p\n",sid);
+{
+	TRACE(ntdll,"sid=%p\n",sid);
 	if (!sid)
 	  return FALSE; 
 	return sizeof(DWORD)*sid->SubAuthorityCount+sizeof(SID);
 }
 
 /**************************************************************************
- *                 RtlCreateAcl				[NTDLL.306]
- *
- * NOTES
- *    This should return NTSTATUS
+ *                 RtlInitializeSid			[NTDLL.410]
  */
-DWORD WINAPI RtlCreateAcl(PACL acl,DWORD size,DWORD rev)
+DWORD WINAPI RtlInitializeSid(PSID PSID,PSID_IDENTIFIER_AUTHORITY PSIDauth,
+                              DWORD c)
 {
-	if (rev!=ACL_REVISION)
-		return STATUS_INVALID_PARAMETER;
-	if (size<sizeof(ACL))
-		return STATUS_BUFFER_TOO_SMALL;
-	if (size>0xFFFF)
-		return STATUS_INVALID_PARAMETER;
+	BYTE	a = c&0xff;
 
-	memset(acl,'\0',sizeof(ACL));
-	acl->AclRevision	= rev;
-	acl->AclSize		= size;
-	acl->AceCount		= 0;
-	return 0;
+	if (a>=SID_MAX_SUB_AUTHORITIES)
+		return a;
+	PSID->SubAuthorityCount = a;
+	PSID->Revision		 = SID_REVISION;
+	memcpy(&(PSID->IdentifierAuthority),PSIDauth,sizeof(SID_IDENTIFIER_AUTHORITY));
+	return STATUS_SUCCESS;
 }
 
 /**************************************************************************
- *                 RtlFirstFreeAce			[NTDLL.370]
- * looks for the AceCount+1 ACE, and if it is still within the alloced
- * ACL, return a pointer to it
+ *                 RtlSubAuthoritySid			[NTDLL.497]
  */
-BOOL32 WINAPI RtlFirstFreeAce(
-	PACL acl,
-	LPACE_HEADER *x)
+LPDWORD WINAPI RtlSubAuthoritySid(PSID PSID,DWORD nr)
 {
-	LPACE_HEADER	ace;
-	int		i;
-
-	*x = 0;
-	ace = (LPACE_HEADER)(acl+1);
-	for (i=0;i<acl->AceCount;i++) {
-		if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
-			return 0;
-		ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
-	}
-	if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
-		return 0;
-	*x = ace;
-	return 1;
+	return &(PSID->SubAuthority[nr]);
 }
 
 /**************************************************************************
- *                 RtlAddAce				[NTDLL.260]
+ *                 RtlSubAuthorityCountSid		[NTDLL.496]
  */
-NTSTATUS WINAPI RtlAddAce(
-	PACL acl,
-	DWORD rev,
-	DWORD xnrofaces,
-	LPACE_HEADER acestart,
-	DWORD acelen)
+
+LPBYTE WINAPI RtlSubAuthorityCountSid(PSID PSID)
 {
-	LPACE_HEADER	ace,targetace;
-	int		nrofaces;
+	return ((LPBYTE)PSID)+1;
+}
 
-	if (acl->AclRevision != ACL_REVISION)
-		return STATUS_INVALID_PARAMETER;
-	if (!RtlFirstFreeAce(acl,&targetace))
-		return STATUS_INVALID_PARAMETER;
-	nrofaces=0;ace=acestart;
-	while (((DWORD)ace-(DWORD)acestart)<acelen) {
-		nrofaces++;
-		ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
-	}
-	if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
-		return STATUS_INVALID_PARAMETER;
-	memcpy((LPBYTE)targetace,acestart,acelen);
-	acl->AceCount+=nrofaces;
+/**************************************************************************
+ *                 RtlCopySid				[NTDLL.302]
+ */
+DWORD WINAPI RtlCopySid(DWORD len,PSID to,PSID from)
+{	if (!from)
+		return 0;
+	if (len<(from->SubAuthorityCount*4+8))
+		return STATUS_BUFFER_TOO_SMALL;
+	memmove(to,from,from->SubAuthorityCount*4+8);
 	return STATUS_SUCCESS;
 }
 
+/*	##############################################
+	######	SECURITY DESCRIPTOR FUNCTIONS	######
+	##############################################
+*/
 /**************************************************************************
- *                 RtlCreateSecurityDescriptor		[NTDLL.313]
+ * RtlCreateSecurityDescriptor			[NTDLL.313]
  *
  * RETURNS:
  *  0 success, 
@@ -141,26 +150,74 @@ NTSTATUS WINAPI RtlCreateSecurityDescriptor(
 	lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
 	return STATUS_SUCCESS;
 }
+/**************************************************************************
+ * RtlValidSecurityDescriptor			[NTDLL.313]
+ *
+ */
+NTSTATUS WINAPI RtlValidSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+	if ( ! SecurityDescriptor )
+		return STATUS_INVALID_SECURITY_DESCR;
+	if ( SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION )
+		return STATUS_UNKNOWN_REVISION;
+
+	return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ *  RtlGetDaclSecurityDescriptor		[NTDLL] 
+ *
+ */
+DWORD WINAPI RtlGetDaclSecurityDescriptor(
+	IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
+	OUT PBOOLEAN lpbDaclPresent,
+	OUT PACL *pDacl,
+	OUT PBOOLEAN lpbDaclDefaulted)
+{
+	TRACE(ntdll,"(%p,%p,%p,%p)\n",
+	pSecurityDescriptor, lpbDaclPresent, *pDacl, lpbDaclDefaulted);
+
+	if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
+	  return STATUS_UNKNOWN_REVISION ;
+
+	if ( (*lpbDaclPresent = (SE_DACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
+	{
+	  if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
+	  { *pDacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Dacl);
+	  }
+	  else
+	  { *pDacl = pSecurityDescriptor->Dacl;
+	  }
+	}
+
+	*lpbDaclDefaulted = (( SE_DACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
+	
+	return STATUS_SUCCESS;
+}
 
 /**************************************************************************
- *                 RtlSetDaclSecurityDescriptor		[NTDLL.483]
+ *  RtlSetDaclSecurityDescriptor		[NTDLL.483]
  */
 NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (
 	PSECURITY_DESCRIPTOR lpsd,
-	BOOL32 daclpresent,
+	BOOLEAN daclpresent,
 	PACL dacl,
-	BOOL32 dacldefaulted )
+	BOOLEAN dacldefaulted )
 {
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
 	if (lpsd->Control & SE_SELF_RELATIVE)
 		return STATUS_INVALID_SECURITY_DESCR;
+
 	if (!daclpresent) 
 	{	lpsd->Control &= ~SE_DACL_PRESENT;
 		return TRUE;
 	}
+
 	lpsd->Control |= SE_DACL_PRESENT;
 	lpsd->Dacl = dacl;
+
 	if (dacldefaulted)
 		lpsd->Control |= SE_DACL_DEFAULTED;
 	else
@@ -168,15 +225,38 @@ NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (
 
 	return STATUS_SUCCESS;
 }
+/**************************************************************************
+ *  RtlLengthSecurityDescriptor			[NTDLL]
+ */
+ULONG WINAPI RtlLengthSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor)
+{
+	ULONG Size;
+	Size = SECURITY_DESCRIPTOR_MIN_LENGTH;
+	if ( SecurityDescriptor == NULL )
+		return 0;
 
+	if ( SecurityDescriptor->Owner != NULL )
+		Size += SecurityDescriptor->Owner->SubAuthorityCount;
+	if ( SecurityDescriptor->Group != NULL )
+		Size += SecurityDescriptor->Group->SubAuthorityCount;
+
+
+	if ( SecurityDescriptor->Sacl != NULL )
+		Size += SecurityDescriptor->Sacl->AclSize;
+	if ( SecurityDescriptor->Dacl != NULL )
+		Size += SecurityDescriptor->Dacl->AclSize;
+
+	return Size;
+}
 /**************************************************************************
- *                 RtlSetSaclSecurityDescriptor		[NTDLL.488]
+ * RtlSetSaclSecurityDescriptor			[NTDLL.488]
  */
 DWORD  WINAPI RtlSetSaclSecurityDescriptor (
 	PSECURITY_DESCRIPTOR lpsd,
-	BOOL32 saclpresent,
+	BOOLEAN saclpresent,
 	PACL sacl,
-	BOOL32 sacldefaulted)
+	BOOLEAN sacldefaulted)
 {
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
@@ -195,13 +275,34 @@ DWORD  WINAPI RtlSetSaclSecurityDescriptor (
 	return STATUS_SUCCESS;
 }
 
+/**************************************************************************
+ * RtlGetOwnerSecurityDescriptor		[NTDLL.488]
+ */
+NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor,
+	PSID *Owner,
+	PBOOLEAN OwnerDefaulted)
+{
+	if ( !SecurityDescriptor  || !Owner || !OwnerDefaulted )
+		return STATUS_INVALID_PARAMETER;
+
+	*Owner = SecurityDescriptor->Owner;
+	if ( *Owner != NULL )  {
+		if ( SecurityDescriptor->Control & SE_OWNER_DEFAULTED )
+			*OwnerDefaulted = TRUE;
+		else
+			*OwnerDefaulted = FALSE;
+	}
+	return STATUS_SUCCESS;
+}
+
 /**************************************************************************
  *                 RtlSetOwnerSecurityDescriptor		[NTDLL.487]
  */
 NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(
 	PSECURITY_DESCRIPTOR lpsd,
 	PSID owner,
-	BOOL32 ownerdefaulted)
+	BOOLEAN ownerdefaulted)
 {
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
@@ -222,7 +323,7 @@ NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(
 NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (
 	PSECURITY_DESCRIPTOR lpsd,
 	PSID group,
-	BOOL32 groupdefaulted)
+	BOOLEAN groupdefaulted)
 {
 	if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
 		return STATUS_UNKNOWN_REVISION;
@@ -236,68 +337,136 @@ NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (
 		lpsd->Control &= ~SE_GROUP_DEFAULTED;
 	return STATUS_SUCCESS;
 }
-
-
-/**************************************************************************
- *                 RtlNormalizeProcessParams		[NTDLL.441]
- */
-LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
-{
-    FIXME(ntdll,"(%p), stub\n",x);
-    return x;
-}
-
 /**************************************************************************
- *                 RtlInitializeSid			[NTDLL.410]
+ *                 RtlGetGroupSecurityDescriptor		[NTDLL]
  */
-DWORD WINAPI RtlInitializeSid(PSID PSID,PSID_IDENTIFIER_AUTHORITY PSIDauth,
-                              DWORD c)
+NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor,
+	PSID *Group,
+	PBOOLEAN GroupDefaulted)
 {
-	BYTE	a = c&0xff;
+	if ( !SecurityDescriptor || !Group || !GroupDefaulted )
+		return STATUS_INVALID_PARAMETER;
 
-	if (a>=SID_MAX_SUB_AUTHORITIES)
-		return a;
-	PSID->SubAuthorityCount = a;
-	PSID->Revision		 = SID_REVISION;
-	memcpy(&(PSID->IdentifierAuthority),PSIDauth,sizeof(SID_IDENTIFIER_AUTHORITY));
+	*Group = SecurityDescriptor->Group;
+	if ( *Group != NULL )  {
+		if ( SecurityDescriptor->Control & SE_GROUP_DEFAULTED )
+			*GroupDefaulted = TRUE;
+		else
+			*GroupDefaulted = FALSE;
+	}
 	return STATUS_SUCCESS;
-}
+} 
+
+/*	##############################
+	######	ACL FUNCTIONS	######
+	##############################
+*/
 
 /**************************************************************************
- *                 RtlSubAuthoritySid			[NTDLL.497]
+ *                 RtlCreateAcl				[NTDLL.306]
+ *
+ * NOTES
+ *    This should return NTSTATUS
  */
-LPDWORD WINAPI RtlSubAuthoritySid(PSID PSID,DWORD nr)
+DWORD WINAPI RtlCreateAcl(PACL acl,DWORD size,DWORD rev)
 {
-	return &(PSID->SubAuthority[nr]);
+	if (rev!=ACL_REVISION)
+		return STATUS_INVALID_PARAMETER;
+	if (size<sizeof(ACL))
+		return STATUS_BUFFER_TOO_SMALL;
+	if (size>0xFFFF)
+		return STATUS_INVALID_PARAMETER;
+
+	memset(acl,'\0',sizeof(ACL));
+	acl->AclRevision	= rev;
+	acl->AclSize		= size;
+	acl->AceCount		= 0;
+	return 0;
 }
 
 /**************************************************************************
- *                 RtlSubAuthorityCountSid		[NTDLL.496]
+ *                 RtlFirstFreeAce			[NTDLL.370]
+ * looks for the AceCount+1 ACE, and if it is still within the alloced
+ * ACL, return a pointer to it
  */
-LPBYTE WINAPI RtlSubAuthorityCountSid(PSID PSID)
+BOOLEAN WINAPI RtlFirstFreeAce(
+	PACL acl,
+	LPACE_HEADER *x)
 {
-	return ((LPBYTE)PSID)+1;
-}
+	LPACE_HEADER	ace;
+	int		i;
 
-/**************************************************************************
- *                 RtlCopySid				[NTDLL.302]
- */
-DWORD WINAPI RtlCopySid(DWORD len,PSID to,PSID from)
-{	if (!from)
+	*x = 0;
+	ace = (LPACE_HEADER)(acl+1);
+	for (i=0;i<acl->AceCount;i++) {
+		if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
+			return 0;
+		ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
+	}
+	if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
 		return 0;
-	if (len<(from->SubAuthorityCount*4+8))
-		return STATUS_BUFFER_TOO_SMALL;
-	memmove(to,from,from->SubAuthorityCount*4+8);
-	return STATUS_SUCCESS;
+	*x = ace;
+	return 1;
 }
 
 /**************************************************************************
- *                 RtlAnsiStringToUnicodeString		[NTDLL.269]
+ *                 RtlAddAce				[NTDLL.260]
  */
-DWORD /* NTSTATUS */ 
-WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,PANSI_STRING ansi,BOOL32 doalloc)
-{
-	DWORD	unilen = (ansi->Length+1)*sizeof(WCHAR);
+NTSTATUS WINAPI RtlAddAce(
+	PACL acl,
+	DWORD rev,
+	DWORD xnrofaces,
+	LPACE_HEADER acestart,
+	DWORD acelen)
+{
+	LPACE_HEADER	ace,targetace;
+	int		nrofaces;
+
+	if (acl->AclRevision != ACL_REVISION)
+		return STATUS_INVALID_PARAMETER;
+	if (!RtlFirstFreeAce(acl,&targetace))
+		return STATUS_INVALID_PARAMETER;
+	nrofaces=0;ace=acestart;
+	while (((DWORD)ace-(DWORD)acestart)<acelen) {
+		nrofaces++;
+		ace = (LPACE_HEADER)(((BYTE*)ace)+ace->AceSize);
+	}
+	if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
+		return STATUS_INVALID_PARAMETER;
+	memcpy((LPBYTE)targetace,acestart,acelen);
+	acl->AceCount+=nrofaces;
+	return STATUS_SUCCESS;
+}
+
+/******************************************************************************
+ *  RtlAddAccessAllowedAce		[NTDLL] 
+ */
+DWORD WINAPI RtlAddAccessAllowedAce(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlGetAce		[NTDLL] 
+ */
+DWORD WINAPI RtlGetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) {
+	FIXME(ntdll,"(%p,%ld,%p),stub!\n",pAcl,dwAceIndex,pAce);
+	return 0;
+}
+
+/*	######################################
+	######	STRING FUNCTIONS	######
+	######################################
+*/
+
+/**************************************************************************
+ *                 RtlAnsiStringToUnicodeString		[NTDLL.269]
+ */
+DWORD /* NTSTATUS */ 
+WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,PANSI_STRING ansi,BOOLEAN doalloc)
+{
+	DWORD	unilen = (ansi->Length+1)*sizeof(WCHAR);
 
 	if (unilen>0xFFFF)
 		return STATUS_INVALID_PARAMETER_2;
@@ -318,7 +487,7 @@ WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,PANSI_STRING ansi,BOOL32
  *                 RtlOemStringToUnicodeString		[NTDLL.447]
  */
 DWORD /* NTSTATUS */ 
-WINAPI RtlOemStringToUnicodeString(PUNICODE_STRING uni,PSTRING ansi,BOOL32 doalloc)
+WINAPI RtlOemStringToUnicodeString(PUNICODE_STRING uni,PSTRING ansi,BOOLEAN doalloc)
 {
 	DWORD	unilen = (ansi->Length+1)*sizeof(WCHAR);
 
@@ -455,7 +624,7 @@ WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,D
  *                 RtlUnicodeStringToOemString		[NTDLL.511]
  */
 DWORD /* NTSTATUS */ 
-WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,PUNICODE_STRING uni,BOOL32 alloc)
+WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc)
 {
 	if (alloc) {
 		oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
@@ -470,7 +639,7 @@ WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,PUNICODE_STRING uni,BOOL32 a
  *                 RtlUnicodeStringToAnsiString		[NTDLL.507]
  */
 DWORD /* NTSTATUS */ 
-WINAPI RtlUnicodeStringToAnsiString(PANSI_STRING oem,PUNICODE_STRING uni,BOOL32 alloc)
+WINAPI RtlUnicodeStringToAnsiString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc)
 {
 	if (alloc) {
 		oem->Buffer = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,uni->Length/2)+1;
@@ -492,29 +661,10 @@ DWORD WINAPI RtlEqualUnicodeString(PUNICODE_STRING s1,PUNICODE_STRING s2,DWORD x
 	return !lstrncmp32W(s1->Buffer,s2->Buffer,s1->Length/2);
 }
 
-/**************************************************************************
- *                 RtlNtStatusToDosErro			[NTDLL.442]
- */
-DWORD WINAPI RtlNtStatusToDosError(DWORD error)
-{
-    FIXME(ntdll, "(%lx): map STATUS_ to ERROR_\n",error);
-    return error;
-}
-
-/**************************************************************************
- *                 RtlGetNtProductType			[NTDLL.390]
- */
-BOOL32 WINAPI RtlGetNtProductType(LPDWORD type)
-{
-    FIXME(ntdll, "(%p): stub\n", type);
-    *type=3; /* dunno. 1 for client, 3 for server? */
-    return 1;
-}
-
 /**************************************************************************
  *                 RtlUpcaseUnicodeString		[NTDLL.520]
  */
-DWORD WINAPI RtlUpcaseUnicodeString(PUNICODE_STRING dest,PUNICODE_STRING src,BOOL32 doalloc)
+DWORD WINAPI RtlUpcaseUnicodeString(PUNICODE_STRING dest,PUNICODE_STRING src,BOOLEAN doalloc)
 {
 	LPWSTR	s,t;
 	DWORD	i,len;
@@ -595,324 +745,22 @@ out:
 	return len;
 }
 
-/**************************************************************************
- *                 RtlDosPathNameToNtPathName_U		[NTDLL.338]
- *
- * FIXME: convert to UNC or whatever is expected here
- */
-BOOL32  WINAPI RtlDosPathNameToNtPathName_U(
-	LPWSTR from,PUNICODE_STRING us,DWORD x2,DWORD x3)
-{
-	LPSTR	fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
-
-	FIXME(ntdll,"(%s,%p,%08lx,%08lx)\n",fromA,us,x2,x3);
-	if (us)
-		RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
-	return TRUE;
-}
-
-/**************************************************************************
- *                 NTDLL_chkstk				[NTDLL.862]
- *                 NTDLL_alloca_probe				[NTDLL.861]
- * Glorified "enter xxxx".
- */
-REGS_ENTRYPOINT(NTDLL_chkstk)
-{
-    ESP_reg(context) -= EAX_reg(context);
-}
-REGS_ENTRYPOINT(NTDLL_alloca_probe)
-{
-    ESP_reg(context) -= EAX_reg(context);
-}
-
-/******************************************************************************
- * RtlTimeToElapsedTimeFields [NTDLL.502]
- */
-DWORD WINAPI RtlTimeToElapsedTimeFields( DWORD x1, DWORD x2 )
-{
-    FIXME(ntdll,"(%lx,%lx): stub\n",x1,x2);
-    return 0;
-}
-
-
-/******************************************************************************
- * RtlExtendedLargeIntegerDivide [NTDLL.359]
- */
-INT32 WINAPI RtlExtendedLargeIntegerDivide(
-	LARGE_INTEGER dividend,
-	DWORD divisor,
-	LPDWORD rest
-) {
-#if SIZEOF_LONG_LONG==8
-	long long x1 = *(long long*)&dividend;
-
-	if (*rest)
-		*rest = x1 % divisor;
-	return x1/divisor;
-#else
-	FIXME(ntdll,"((%d<<32)+%d,%d,%p), implement this using normal integer arithmetic!\n",dividend.HighPart,dividend.LowPart,divisor,rest);
-	return 0;
-#endif
-}
-
-/******************************************************************************
- * RtlExtendedLargeIntegerMultiply [NTDLL.359]
- * Note: This even works, since gcc returns 64bit values in eax/edx just like
- * the caller expects. However... The relay code won't grok this I think.
- */
-long long /*LARGE_INTEGER*/ 
-WINAPI RtlExtendedIntegerMultiply(
-	LARGE_INTEGER factor1,INT32 factor2
-) {
-#if SIZEOF_LONG_LONG==8
-	return (*(long long*)&factor1)*factor2;
-#else
-	FIXME(ntdll,"((%d<<32)+%d,%ld), implement this using normal integer arithmetic!\n",factor1.HighPart,factor1.LowPart,factor2);
-	return 0;
-#endif
-}
-
-/******************************************************************************
- *  RtlFormatCurrentUserKeyPath		[NTDLL.371] 
- */
-DWORD WINAPI RtlFormatCurrentUserKeyPath(DWORD x)
-{
-    FIXME(ntdll,"(0x%08lx): stub\n",x);
-    return 1;
-}
-
-/******************************************************************************
- *  RtlOpenCurrentUser		[NTDLL] 
- */
-DWORD WINAPI RtlOpenCurrentUser(DWORD x1, DWORD *x2)
-{
-/* Note: this is not the correct solution, 
- * But this works pretty good on wine and NT4.0 binaries
- */
-	if  ( x1 == 0x2000000 )  {
-		*x2 = HKEY_CURRENT_USER; 
-		return TRUE;
-	}
-		
-	return FALSE;
-}
-/******************************************************************************
- *  RtlAllocateAndInitializeSid		[NTDLL.265] 
- *
- */
-BOOL32 WINAPI RtlAllocateAndInitializeSid (PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,DWORD nSubAuthorityCount,
-		DWORD x3,DWORD x4,DWORD x5,DWORD x6,DWORD x7,DWORD x8,DWORD x9,DWORD x10, PSID pSid) 
-{	FIXME(ntdll,"(%p,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p),stub!\n",
-		pIdentifierAuthority,nSubAuthorityCount,x3,x4,x5,x6,x7,x8,x9,x10,pSid);
-	return 0;
-}
-/******************************************************************************
- *  RtlEqualSid		[NTDLL.352] 
- *
- */
-DWORD WINAPI RtlEqualSid(DWORD x1,DWORD x2) {	
-	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n", x1,x2);
-	return TRUE;
-}
-
-/******************************************************************************
- *  RtlFreeSid		[NTDLL.376] 
- */
-DWORD WINAPI RtlFreeSid(DWORD x1) 
-{	FIXME(ntdll,"(0x%08lx),stub!\n", x1);
-	return TRUE;
-}
-
-/******************************************************************************
- *  RtlGetDaclSecurityDescriptor		[NTDLL] 
- *
- * NOTES: seems to be like GetSecurityDescriptorDacl (js)
- */
-DWORD WINAPI RtlGetDaclSecurityDescriptor(
-	IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
-	OUT LPBOOL lpbDaclPresent,
-	OUT PACL *pDacl,
-	OUT LPBOOL lpbDaclDefaulted)
-{	DWORD ret = 0;
-
-	TRACE(ntdll,"(%p,%p,%p,%p)\n",
-	pSecurityDescriptor, lpbDaclPresent, *pDacl, lpbDaclDefaulted);
-
-	if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
-	  return STATUS_UNKNOWN_REVISION ;
-
-	if ( (*lpbDaclPresent = (SE_DACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
-	{
-	  if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
-	  { *pDacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Dacl);
-	  }
-	  else
-	  { *pDacl = pSecurityDescriptor->Dacl;
-	  }
-	}
-
-	*lpbDaclDefaulted = (( SE_DACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
-	
-	return ret;
-}
-
-/******************************************************************************
- *  RtlCreateEnvironment		[NTDLL] 
- */
-DWORD WINAPI RtlCreateEnvironment(DWORD x1,DWORD x2) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
-	return 0;
-}
-
-
-/******************************************************************************
- *  RtlDestroyEnvironment		[NTDLL] 
- */
-DWORD WINAPI RtlDestroyEnvironment(DWORD x) {
-	FIXME(ntdll,"(0x%08lx),stub!\n",x);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlQueryEnvironmentVariable_U		[NTDLL] 
- */
-DWORD WINAPI RtlQueryEnvironmentVariable_U(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val) {
-	FIXME(ntdll,"(0x%08lx,%s,%p),stub!\n",x1,debugstr_w(key->Buffer),val);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlSetEnvironmentVariable		[NTDLL] 
- */
-DWORD WINAPI RtlSetEnvironmentVariable(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val) {
-	FIXME(ntdll,"(0x%08lx,%s,%s),stub!\n",x1,debugstr_w(key->Buffer),debugstr_w(val->Buffer));
-	return 0;
-}
-
-/******************************************************************************
- *  RtlNewSecurityObject		[NTDLL] 
- */
-DWORD WINAPI RtlNewSecurityObject(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlDeleteSecurityObject		[NTDLL] 
- */
-DWORD WINAPI RtlDeleteSecurityObject(DWORD x1) {
-	FIXME(ntdll,"(0x%08lx),stub!\n",x1);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlToTimeInSecondsSince1980		[NTDLL] 
- */
-BOOL32 WINAPI RtlTimeToSecondsSince1980(LPFILETIME ft,LPDWORD timeret) {
-	/* 1980 = 1970+10*365 days +  29. februar 1972 + 29.februar 1976 */
-	*timeret = DOSFS_FileTimeToUnixTime(ft,NULL) - (10*365+2)*24*3600;
-	return 1;
-}
-
-/******************************************************************************
- *  RtlToTimeInSecondsSince1970		[NTDLL] 
- */
-BOOL32 WINAPI RtlTimeToSecondsSince1970(LPFILETIME ft,LPDWORD timeret) {
-	*timeret = DOSFS_FileTimeToUnixTime(ft,NULL);
-	return 1;
-}
-
-/******************************************************************************
- *  RtlAcquirePebLock		[NTDLL] 
- */
-VOID WINAPI RtlAcquirePebLock(void) {
-	FIXME(ntdll,"()\n");
-	/* enter critical section ? */
-}
-
-/******************************************************************************
- *  RtlReleasePebLock		[NTDLL] 
- */
-VOID WINAPI RtlReleasePebLock(void) {
-	FIXME(ntdll,"()\n");
-	/* leave critical section ? */
-}
-
-/******************************************************************************
- *  RtlAddAccessAllowedAce		[NTDLL] 
- */
-DWORD WINAPI RtlAddAccessAllowedAce(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlGetAce		[NTDLL] 
- */
-DWORD WINAPI RtlGetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce ) {
-	FIXME(ntdll,"(%p,%ld,%p),stub!\n",pAcl,dwAceIndex,pAce);
-	return 0;
-}
-
-/******************************************************************************
- *  RtlAdjustPrivilege		[NTDLL] 
- */
-DWORD WINAPI RtlAdjustPrivilege(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
-	return 0;
-}
 
-/******************************************************************************
- *  RtlIntegerToChar	[NTDLL] 
- */
-DWORD WINAPI RtlIntegerToChar(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
-	return 0;
-}
-/******************************************************************************
- *  RtlSystemTimeToLocalTime 	[NTDLL] 
- */
-DWORD WINAPI RtlSystemTimeToLocalTime(DWORD x1,DWORD x2) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
-	return 0;
-}
-/******************************************************************************
- *  RtlTimeToTimeFields 	[NTDLL] 
- */
-DWORD WINAPI RtlTimeToTimeFields(DWORD x1,DWORD x2) {
-	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
-	return 0;
-}
 /******************************************************************************
  *	RtlCompareUnicodeString	[NTDLL] 
  */
 NTSTATUS WINAPI RtlCompareUnicodeString(
 	PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive) 
-{
-	FIXME(ntdll,"(%s,%s,0x%08x),stub!\n",debugstr_w(String1->Buffer),debugstr_w(String1->Buffer),CaseInSensitive);
-	return 0;
-}
-
-/******************************************************************************
- *	DbgPrint	[NTDLL] 
- */
-void __cdecl DbgPrint(LPCSTR fmt,LPVOID args) {
-	char buf[512];
-
-	wvsprintf32A(buf,fmt,&args);
-	MSG("DbgPrint says: %s",buf);
-	/* hmm, raise exception? */
-}
-DWORD NtRaiseException ( DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments,CONST ULONG_PTR *lpArguments)
-{	FIXME(ntdll,"0x%08lx 0x%08lx 0x%08lx %p\n", dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments);
-	return 0;
-}
-
-DWORD RtlRaiseException ( DWORD x)
-{	FIXME(ntdll, "0x%08lx\n", x);
+{
+	FIXME(ntdll,"(%s,%s,0x%08x),stub!\n",debugstr_w(String1->Buffer),debugstr_w(String1->Buffer),CaseInSensitive);
 	return 0;
 }
 
+
+/*	######################################
+	######	RESOURCE FUNCTIONS	######
+	######################################
+*/
 /***********************************************************************
  *           RtlInitializeResource	(NTDLL.409)
  *
@@ -1098,3 +946,276 @@ void WINAPI RtlDumpResource(LPRTL_RWLOCK rwl)
     }
 }
 
+/*	##############################
+	######	MISC FUNCTIONS	######
+	##############################
+*/
+
+/******************************************************************************
+ *	DbgPrint	[NTDLL] 
+ */
+void __cdecl DbgPrint(LPCSTR fmt,LPVOID args) {
+	char buf[512];
+
+	wvsprintf32A(buf,fmt,&args);
+	MSG("DbgPrint says: %s",buf);
+	/* hmm, raise exception? */
+}
+DWORD NtRaiseException ( DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments,CONST ULONG_PTR *lpArguments)
+{	FIXME(ntdll,"0x%08lx 0x%08lx 0x%08lx %p\n", dwExceptionCode, dwExceptionFlags, nNumberOfArguments, lpArguments);
+	return 0;
+}
+
+DWORD RtlRaiseException ( DWORD x)
+{	FIXME(ntdll, "0x%08lx\n", x);
+	return 0;
+}
+/******************************************************************************
+ *  RtlAcquirePebLock		[NTDLL] 
+ */
+VOID WINAPI RtlAcquirePebLock(void) {
+	FIXME(ntdll,"()\n");
+	/* enter critical section ? */
+}
+
+/******************************************************************************
+ *  RtlReleasePebLock		[NTDLL] 
+ */
+VOID WINAPI RtlReleasePebLock(void) {
+	FIXME(ntdll,"()\n");
+	/* leave critical section ? */
+}
+
+/******************************************************************************
+ *  RtlAdjustPrivilege		[NTDLL] 
+ */
+DWORD WINAPI RtlAdjustPrivilege(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlIntegerToChar	[NTDLL] 
+ */
+DWORD WINAPI RtlIntegerToChar(DWORD x1,DWORD x2,DWORD x3,DWORD x4) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
+	return 0;
+}
+/******************************************************************************
+ *  RtlSystemTimeToLocalTime 	[NTDLL] 
+ */
+DWORD WINAPI RtlSystemTimeToLocalTime(DWORD x1,DWORD x2) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
+	return 0;
+}
+/******************************************************************************
+ *  RtlTimeToTimeFields 	[NTDLL] 
+ */
+DWORD WINAPI RtlTimeToTimeFields(DWORD x1,DWORD x2) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
+	return 0;
+}
+/******************************************************************************
+ *  RtlSetEnvironmentVariable		[NTDLL] 
+ */
+DWORD WINAPI RtlSetEnvironmentVariable(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val) {
+	FIXME(ntdll,"(0x%08lx,%s,%s),stub!\n",x1,debugstr_w(key->Buffer),debugstr_w(val->Buffer));
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlNewSecurityObject		[NTDLL] 
+ */
+DWORD WINAPI RtlNewSecurityObject(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4,x5,x6);
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlDeleteSecurityObject		[NTDLL] 
+ */
+DWORD WINAPI RtlDeleteSecurityObject(DWORD x1) {
+	FIXME(ntdll,"(0x%08lx),stub!\n",x1);
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlToTimeInSecondsSince1980		[NTDLL] 
+ */
+BOOLEAN WINAPI RtlTimeToSecondsSince1980(LPFILETIME ft,LPDWORD timeret) {
+	/* 1980 = 1970+10*365 days +  29. februar 1972 + 29.februar 1976 */
+	*timeret = DOSFS_FileTimeToUnixTime(ft,NULL) - (10*365+2)*24*3600;
+	return 1;
+}
+
+/******************************************************************************
+ *  RtlToTimeInSecondsSince1970		[NTDLL] 
+ */
+BOOLEAN WINAPI RtlTimeToSecondsSince1970(LPFILETIME ft,LPDWORD timeret) {
+	*timeret = DOSFS_FileTimeToUnixTime(ft,NULL);
+	return 1;
+}
+/**************************************************************************
+ *                 RtlNormalizeProcessParams		[NTDLL.441]
+ */
+LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x)
+{
+    FIXME(ntdll,"(%p), stub\n",x);
+    return x;
+}
+
+/**************************************************************************
+ *                 RtlNtStatusToDosError			[NTDLL.442]
+ */
+DWORD WINAPI RtlNtStatusToDosError(DWORD error)
+{
+	FIXME(ntdll, "(%lx): map STATUS_ to ERROR_\n",error);
+	switch (error)
+	{ case STATUS_SUCCESS:			return ERROR_SUCCESS;
+	  case STATUS_INVALID_PARAMETER:	return ERROR_BAD_ARGUMENTS;
+	  case STATUS_BUFFER_TOO_SMALL:		return ERROR_INSUFFICIENT_BUFFER;
+/*	  case STATUS_INVALID_SECURITY_DESCR:	return ERROR_INVALID_SECURITY_DESCR;*/
+	  case STATUS_NO_MEMORY:		return ERROR_NOT_ENOUGH_MEMORY;
+/*	  case STATUS_UNKNOWN_REVISION:
+	  case STATUS_BUFFER_OVERFLOW:*/
+	}
+	FIXME(ntdll, "unknown status (%lx)\n",error);
+	return ERROR_SUCCESS;
+}
+
+/**************************************************************************
+ *                 RtlGetNtProductType			[NTDLL.390]
+ */
+BOOLEAN WINAPI RtlGetNtProductType(LPDWORD type)
+{
+    FIXME(ntdll, "(%p): stub\n", type);
+    *type=3; /* dunno. 1 for client, 3 for server? */
+    return 1;
+}
+
+/**************************************************************************
+ *                 NTDLL_chkstk				[NTDLL.862]
+ *                 NTDLL_alloca_probe				[NTDLL.861]
+ * Glorified "enter xxxx".
+ */
+REGS_ENTRYPOINT(NTDLL_chkstk)
+{
+    ESP_reg(context) -= EAX_reg(context);
+}
+REGS_ENTRYPOINT(NTDLL_alloca_probe)
+{
+    ESP_reg(context) -= EAX_reg(context);
+}
+
+/******************************************************************************
+ * RtlTimeToElapsedTimeFields [NTDLL.502]
+ */
+DWORD WINAPI RtlTimeToElapsedTimeFields( DWORD x1, DWORD x2 )
+{
+    FIXME(ntdll,"(%lx,%lx): stub\n",x1,x2);
+    return 0;
+}
+
+
+/******************************************************************************
+ * RtlExtendedLargeIntegerDivide [NTDLL.359]
+ */
+INT32 WINAPI RtlExtendedLargeIntegerDivide(
+	LARGE_INTEGER dividend,
+	DWORD divisor,
+	LPDWORD rest
+) {
+#if SIZEOF_LONG_LONG==8
+	long long x1 = *(long long*)&dividend;
+
+	if (*rest)
+		*rest = x1 % divisor;
+	return x1/divisor;
+#else
+	FIXME(ntdll,"((%d<<32)+%d,%d,%p), implement this using normal integer arithmetic!\n",dividend.HighPart,dividend.LowPart,divisor,rest);
+	return 0;
+#endif
+}
+
+/******************************************************************************
+ * RtlExtendedLargeIntegerMultiply [NTDLL.359]
+ * Note: This even works, since gcc returns 64bit values in eax/edx just like
+ * the caller expects. However... The relay code won't grok this I think.
+ */
+long long /*LARGE_INTEGER*/ 
+WINAPI RtlExtendedIntegerMultiply(
+	LARGE_INTEGER factor1,INT32 factor2
+) {
+#if SIZEOF_LONG_LONG==8
+	return (*(long long*)&factor1)*factor2;
+#else
+	FIXME(ntdll,"((%d<<32)+%d,%ld), implement this using normal integer arithmetic!\n",factor1.HighPart,factor1.LowPart,factor2);
+	return 0;
+#endif
+}
+
+/******************************************************************************
+ *  RtlFormatCurrentUserKeyPath		[NTDLL.371] 
+ */
+DWORD WINAPI RtlFormatCurrentUserKeyPath(DWORD x)
+{
+    FIXME(ntdll,"(0x%08lx): stub\n",x);
+    return 1;
+}
+
+/******************************************************************************
+ *  RtlOpenCurrentUser		[NTDLL] 
+ */
+DWORD WINAPI RtlOpenCurrentUser(DWORD x1, DWORD *x2)
+{
+/* Note: this is not the correct solution, 
+ * But this works pretty good on wine and NT4.0 binaries
+ */
+	if  ( x1 == 0x2000000 )  {
+		*x2 = HKEY_CURRENT_USER; 
+		return TRUE;
+	}
+		
+	return FALSE;
+}
+/**************************************************************************
+ *                 RtlDosPathNameToNtPathName_U		[NTDLL.338]
+ *
+ * FIXME: convert to UNC or whatever is expected here
+ */
+BOOLEAN  WINAPI RtlDosPathNameToNtPathName_U(
+	LPWSTR from,PUNICODE_STRING us,DWORD x2,DWORD x3)
+{
+	LPSTR	fromA = HEAP_strdupWtoA(GetProcessHeap(),0,from);
+
+	FIXME(ntdll,"(%s,%p,%08lx,%08lx)\n",fromA,us,x2,x3);
+	if (us)
+		RtlInitUnicodeString(us,HEAP_strdupW(GetProcessHeap(),0,from));
+	return TRUE;
+}
+
+/******************************************************************************
+ *  RtlCreateEnvironment		[NTDLL] 
+ */
+DWORD WINAPI RtlCreateEnvironment(DWORD x1,DWORD x2) {
+	FIXME(ntdll,"(0x%08lx,0x%08lx),stub!\n",x1,x2);
+	return 0;
+}
+
+
+/******************************************************************************
+ *  RtlDestroyEnvironment		[NTDLL] 
+ */
+DWORD WINAPI RtlDestroyEnvironment(DWORD x) {
+	FIXME(ntdll,"(0x%08lx),stub!\n",x);
+	return 0;
+}
+
+/******************************************************************************
+ *  RtlQueryEnvironmentVariable_U		[NTDLL] 
+ */
+DWORD WINAPI RtlQueryEnvironmentVariable_U(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val) {
+	FIXME(ntdll,"(0x%08lx,%s,%p),stub!\n",x1,debugstr_w(key->Buffer),val);
+	return 0;
+}
+
diff --git a/include/ntddk.h b/include/ntddk.h
index 08ac12f4e22f8cc603a253c206ee3e43465bca6a..02eae9b9b9c09a1b8c975c9d2ea72f2643b897a7 100644
--- a/include/ntddk.h
+++ b/include/ntddk.h
@@ -8,16 +8,13 @@
 
 #include <ntdef.h>
 
-/* fixme: put it elsewhere */
-typedef long BOOL; 
 /* end fixme */
 
 /****************** 
  * asynchronous I/O 
  */
-/* conflict with X11-includes*/
+#undef Status	/* conflict with X11-includes*/
 
-#undef Status
 typedef struct _IO_STATUS_BLOCK 
 {	union 
 	{ NTSTATUS Status;
@@ -156,7 +153,7 @@ typedef enum SYSTEM_INFORMATION_CLASS
 typedef struct _SYSTEM_TIME_ADJUSTMENT
 {
 	ULONG	TimeAdjustment;
-	BOOL	TimeAdjustmentDisabled;
+	BOOLEAN	TimeAdjustmentDisabled;
 
 } SYSTEM_TIME_ADJUSTMENT, *PSYSTEM_TIME_ADJUSTMENT;
 
@@ -201,4 +198,168 @@ typedef enum _TIMER_TYPE
 	SynchronizationTimer
 } TIMER_TYPE;
 
+/*	##############################
+	######	SID FUNCTIONS	######
+	##############################
+*/
+
+BOOLEAN WINAPI RtlAllocateAndInitializeSid (
+	PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
+	DWORD nSubAuthorityCount,
+	DWORD x3,
+	DWORD x4,
+	DWORD x5,
+	DWORD x6,
+	DWORD x7,
+	DWORD x8,
+	DWORD x9,
+	DWORD x10,
+	PSID pSid);
+	
+DWORD WINAPI RtlEqualSid(DWORD x1,DWORD x2);
+DWORD WINAPI RtlFreeSid(DWORD x1);
+DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths);
+DWORD WINAPI RtlLengthSid(PSID sid);
+DWORD WINAPI RtlInitializeSid(PSID PSID,PSID_IDENTIFIER_AUTHORITY PSIDauth, DWORD c);
+LPDWORD WINAPI RtlSubAuthoritySid(PSID PSID,DWORD nr);
+LPBYTE WINAPI RtlSubAuthorityCountSid(PSID PSID);
+DWORD WINAPI RtlCopySid(DWORD len,PSID to,PSID from);
+
+/*	##############################################
+	######	SECURITY DESCRIPTOR FUNCTIONS	######
+	##############################################
+*/
+
+NTSTATUS WINAPI RtlCreateSecurityDescriptor(
+	PSECURITY_DESCRIPTOR lpsd,
+	DWORD rev);
+
+BOOLEAN WINAPI RtlValidSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor);
+
+DWORD WINAPI RtlGetDaclSecurityDescriptor(
+	IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
+	OUT PBOOLEAN lpbDaclPresent,
+	OUT PACL *pDacl,
+	OUT PBOOLEAN lpbDaclDefaulted);
+
+NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (
+	PSECURITY_DESCRIPTOR lpsd,
+	BOOLEAN daclpresent,
+	PACL dacl,
+	BOOLEAN dacldefaulted );
+
+ULONG WINAPI RtlLengthSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor);
+
+DWORD  WINAPI RtlSetSaclSecurityDescriptor (
+	PSECURITY_DESCRIPTOR lpsd,
+	BOOLEAN saclpresent,
+	PACL sacl,
+	BOOLEAN sacldefaulted);
+
+NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor,
+	PSID *Owner,
+	PBOOLEAN OwnerDefaulted);
+
+NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(
+	PSECURITY_DESCRIPTOR lpsd,
+	PSID owner,
+	BOOLEAN ownerdefaulted);
+
+NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (
+	PSECURITY_DESCRIPTOR lpsd,
+	PSID group,
+	BOOLEAN groupdefaulted);
+
+NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(
+	PSECURITY_DESCRIPTOR SecurityDescriptor,
+	PSID *Group,
+	PBOOLEAN GroupDefaulted);
+
+/*	##############################
+	######	ACL FUNCTIONS	######
+	##############################
+*/
+
+DWORD WINAPI RtlCreateAcl(PACL acl,DWORD size,DWORD rev);
+
+BOOLEAN WINAPI RtlFirstFreeAce(
+	PACL acl,
+	LPACE_HEADER *x);
+NTSTATUS WINAPI RtlAddAce(
+	PACL acl,
+	DWORD rev,
+	DWORD xnrofaces,
+	LPACE_HEADER acestart,
+	DWORD acelen);
+	
+DWORD WINAPI RtlAddAccessAllowedAce(DWORD x1,DWORD x2,DWORD x3,DWORD x4);
+DWORD WINAPI RtlGetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce );
+
+/*	######################################
+	######	STRING FUNCTIONS	######
+	######################################
+*/
+
+DWORD WINAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING uni,PANSI_STRING ansi,BOOLEAN doalloc);
+DWORD WINAPI RtlOemStringToUnicodeString(PUNICODE_STRING uni,PSTRING ansi,BOOLEAN doalloc);
+DWORD WINAPI RtlMultiByteToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen);
+DWORD WINAPI RtlOemToUnicodeN(LPWSTR unistr,DWORD unilen,LPDWORD reslen,LPSTR oemstr,DWORD oemlen);
+VOID WINAPI RtlInitAnsiString(PANSI_STRING target,LPCSTR source);
+VOID WINAPI RtlInitString(PSTRING target,LPCSTR source);
+VOID WINAPI RtlInitUnicodeString(PUNICODE_STRING target,LPCWSTR source);
+VOID WINAPI RtlFreeUnicodeString(PUNICODE_STRING str);
+VOID WINAPI RtlFreeAnsiString(PANSI_STRING AnsiString);
+DWORD WINAPI RtlUnicodeToOemN(LPSTR oemstr,DWORD oemlen,LPDWORD reslen,LPWSTR unistr,DWORD unilen);
+DWORD WINAPI RtlUnicodeStringToOemString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc);
+DWORD WINAPI RtlUnicodeStringToAnsiString(PANSI_STRING oem,PUNICODE_STRING uni,BOOLEAN alloc);
+DWORD WINAPI RtlEqualUnicodeString(PUNICODE_STRING s1,PUNICODE_STRING s2,DWORD x);
+DWORD WINAPI RtlUpcaseUnicodeString(PUNICODE_STRING dest,PUNICODE_STRING src,BOOLEAN doalloc);
+UINT32 WINAPI RtlxOemStringToUnicodeSize(PSTRING str);
+UINT32 WINAPI RtlxAnsiStringToUnicodeSize(PANSI_STRING str);
+DWORD WINAPI RtlIsTextUnicode(LPVOID buf, DWORD len, DWORD *pf);
+NTSTATUS WINAPI RtlCompareUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive);
+
+/*	######################################
+	######	RESOURCE FUNCTIONS	######
+	######################################
+*/
+void WINAPI RtlInitializeResource(LPRTL_RWLOCK rwl);
+void WINAPI RtlDeleteResource(LPRTL_RWLOCK rwl);
+BYTE WINAPI RtlAcquireResourceExclusive(LPRTL_RWLOCK rwl, BYTE fWait);
+BYTE WINAPI RtlAcquireResourceShared(LPRTL_RWLOCK rwl, BYTE fWait);
+void WINAPI RtlReleaseResource(LPRTL_RWLOCK rwl);
+void WINAPI RtlDumpResource(LPRTL_RWLOCK rwl);
+
+void __cdecl DbgPrint(LPCSTR fmt,LPVOID args);
+DWORD NtRaiseException ( DWORD dwExceptionCode, DWORD dwExceptionFlags, DWORD nNumberOfArguments,CONST ULONG_PTR *lpArguments);
+DWORD RtlRaiseException ( DWORD x);
+VOID WINAPI RtlAcquirePebLock(void);
+VOID WINAPI RtlReleasePebLock(void);
+DWORD WINAPI RtlAdjustPrivilege(DWORD x1,DWORD x2,DWORD x3,DWORD x4);
+DWORD WINAPI RtlIntegerToChar(DWORD x1,DWORD x2,DWORD x3,DWORD x4);
+DWORD WINAPI RtlSystemTimeToLocalTime(DWORD x1,DWORD x2);
+DWORD WINAPI RtlTimeToTimeFields(DWORD x1,DWORD x2);
+DWORD WINAPI RtlSetEnvironmentVariable(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val);
+DWORD WINAPI RtlNewSecurityObject(DWORD x1,DWORD x2,DWORD x3,DWORD x4,DWORD x5,DWORD x6);
+DWORD WINAPI RtlDeleteSecurityObject(DWORD x1);
+BOOLEAN WINAPI RtlTimeToSecondsSince1980(LPFILETIME ft,LPDWORD timeret);
+BOOLEAN WINAPI RtlTimeToSecondsSince1970(LPFILETIME ft,LPDWORD timeret);
+LPVOID WINAPI RtlNormalizeProcessParams(LPVOID x);
+DWORD WINAPI RtlNtStatusToDosError(DWORD error);
+BOOLEAN WINAPI RtlGetNtProductType(LPDWORD type);
+DWORD WINAPI RtlTimeToElapsedTimeFields( DWORD x1, DWORD x2 );
+INT32 WINAPI RtlExtendedLargeIntegerDivide(LARGE_INTEGER dividend, DWORD divisor, LPDWORD rest);
+LARGE_INTEGER WINAPI RtlExtendedIntegerMultiply(LARGE_INTEGER factor1,INT32 factor2);
+DWORD WINAPI RtlFormatCurrentUserKeyPath(DWORD x);
+DWORD WINAPI RtlOpenCurrentUser(DWORD x1, DWORD *x2);
+BOOLEAN WINAPI RtlDosPathNameToNtPathName_U( LPWSTR from,PUNICODE_STRING us,DWORD x2,DWORD x3);
+DWORD WINAPI RtlCreateEnvironment(DWORD x1,DWORD x2);
+DWORD WINAPI RtlDestroyEnvironment(DWORD x);
+DWORD WINAPI RtlQueryEnvironmentVariable_U(DWORD x1,PUNICODE_STRING key,PUNICODE_STRING val) ;
+
+
+
 #endif
diff --git a/include/ntdef.h b/include/ntdef.h
index 47d287c529e788d0f6da9e02027ec8227e2afb30..059267c45d92a74f4e14ee11f645dd60ae9fe6b9 100644
--- a/include/ntdef.h
+++ b/include/ntdef.h
@@ -3,6 +3,18 @@
 
 #define NTAPI   __stdcall 
 
+#ifndef IN
+#define IN
+#endif
+
+#ifndef OUT
+#define OUT
+#endif
+
+#ifndef OPTIONAL
+#define OPTIONAL
+#endif
+
 /* NT lowlevel Strings (handled by Rtl* functions in NTDLL)
  * If they are zero terminated, Length does not include the terminating 0.
  */
diff --git a/include/ntdll.h b/include/ntdll.h
index 2fb7a08d146c0060ec228eac784d445bf84d6d2b..6aff6d8a384e9c479e4a59d1f2777e6e483691d6 100644
--- a/include/ntdll.h
+++ b/include/ntdll.h
@@ -15,23 +15,6 @@ extern "C" {
 
 typedef DWORD NTSTATUS;
 
-/* Security Ids of NT */
-
-/* Moved to windows.h
-typedef struct {
-	BYTE	Value[6];
-} SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY;
-*/
-
-/* Moved to windows.h
-typedef struct _SID {
-	BYTE	Revision;
-	BYTE	SubAuthorityCount;
-	SID_IDENTIFIER_AUTHORITY	IdentifierAuthority;
-	DWORD	SubAuthority[1];
-} SID,*PSID,*PSID;
-*/
-
 #define	SID_REVISION			(1)	/* Current revision */
 #define	SID_MAX_SUB_AUTHORITIES		(15)	/* current max subauths */
 #define	SID_RECOMMENDED_SUB_AUTHORITIES	(1)	/* recommended subauths */
@@ -43,16 +26,6 @@ typedef struct _SID {
 #define	ACL_REVISION1	1
 #define	ACL_REVISION2	2
 
-/* Moved to windows.h
-typedef struct _ACL {
-	BYTE	AclRevision;
-	BYTE	Sbz1;
-	WORD	AclSize;
-	WORD	AceCount;
-	WORD	Sbz2;
-} ACL,*LPACL;
-*/
-
 /* ACEs, directly starting after an ACL */
 typedef struct _ACE_HEADER {
 	BYTE	AceType;
@@ -108,33 +81,6 @@ typedef struct _SYSTEM_ALARM_ACE {
 	DWORD		SidStart;
 } SYSTEM_ALARM_ACE,*LPSYSTEM_ALARM_ACE;
 
-#define	SECURITY_DESCRIPTOR_REVISION	1
-#define	SECURITY_DESCRIPTOR_REVISION1	1
-
-/*
-typedef WORD SECURITY_DESCRIPTOR_CONTROL;
- */
-
-#define	SE_OWNER_DEFAULTED	0x0001
-#define	SE_GROUP_DEFAULTED	0x0002
-#define	SE_DACL_PRESENT		0x0004
-#define	SE_DACL_DEFAULTED	0x0008
-#define	SE_SACL_PRESENT		0x0010
-#define	SE_SACL_DEFAULTED	0x0020
-#define	SE_SELF_RELATIVE	0x8000
-
-/* This was moved to windows.h
-typedef struct {
-	BYTE	Revision;
-	BYTE	Sbz1;
-	SECURITY_DESCRIPTOR_CONTROL Control;
-	PSID	Owner;
-	PSID	Group;
-	LPACL	Sacl;
-	LPACL	Dacl;
-} SECURITY_DESCRIPTOR,*PSECURITY_DESCRIPTOR,*LPSECURITY_DESCRIPTOR;
-*/
-
 typedef enum tagSID_NAME_USE {
 	SidTypeUser = 1,
 	SidTypeGroup,
diff --git a/include/queue.h b/include/queue.h
index 3ad74a9d08048c7b45db09861be0ecf1d248b81e..483f274365e29ec82b492ee04a42b78292320856 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -129,7 +129,7 @@ typedef struct tagMESSAGEQUEUE
 #define QUEUE_MAGIC        0xD46E80AF
 
 /* Per queue data management methods */
-PERQUEUEDATA* PERQDATA_CreateInstance( );
+PERQUEUEDATA* PERQDATA_CreateInstance( void );
 ULONG PERQDATA_Addref( PERQUEUEDATA* pQData );
 ULONG PERQDATA_Release( PERQUEUEDATA* pQData );
 HWND32 PERQDATA_GetFocusWnd( PERQUEUEDATA *pQData );
diff --git a/include/winbase.h b/include/winbase.h
index 7960fa9f9bf18075c4b8d61885fb35a466c5beb0..73abf0c42d195ec039c23d225dacfd6ffa8eacfe 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -162,10 +162,7 @@ typedef struct
     DWORD   nLength;
     LPVOID  lpSecurityDescriptor;
     BOOL32  bInheritHandle;
-} SECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
-
-typedef DWORD SECURITY_INFORMATION;
-
+} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
 
 #ifndef _FILETIME_
 #define _FILETIME_
diff --git a/include/winnt.h b/include/winnt.h
index 4f125cbe013315e744a6feee80738d7dbb4e67b7..4a71a2296b0008f24675a0ae60bc68a26707a6ea 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -358,6 +358,8 @@ typedef enum _TOKEN_INFORMATION_CLASS {
 #ifndef _SECURITY_DEFINED
 #define _SECURITY_DEFINED
 
+#pragma pack (1)
+
 typedef struct {
     BYTE Value[6];
 } SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY;
@@ -381,6 +383,20 @@ typedef struct _ACL {
     WORD Sbz2;
 } ACL, *PACL;
 
+/* SECURITY_DESCRIPTOR */
+#define	SECURITY_DESCRIPTOR_REVISION	1
+#define	SECURITY_DESCRIPTOR_REVISION1	1
+
+
+#define	SE_OWNER_DEFAULTED	0x0001
+#define	SE_GROUP_DEFAULTED	0x0002
+#define	SE_DACL_PRESENT		0x0004
+#define	SE_DACL_DEFAULTED	0x0008
+#define	SE_SACL_PRESENT		0x0010
+#define	SE_SACL_DEFAULTED	0x0020
+#define	SE_SELF_RELATIVE	0x8000
+
+typedef DWORD SECURITY_INFORMATION;
 typedef WORD SECURITY_DESCRIPTOR_CONTROL;
 
 /* The security descriptor structure */
@@ -394,6 +410,8 @@ typedef struct {
     PACL Dacl;
 } SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
 
+#define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR)) 
+
 #endif /* _SECURITY_DEFINED */
 
 /* 
diff --git a/include/winreg.h b/include/winreg.h
index e5907d4a10a993fed3a9f39a8d3e80076d9d6de5..6dfbdb0ac39be33f44802546e48dfc876edea705 100644
--- a/include/winreg.h
+++ b/include/winreg.h
@@ -5,23 +5,9 @@
 #define __WINE_WINREG_H
 
 #include "winbase.h"
+#include "winnt.h"
 
-/* FIXME: should be in security.h or whereever */
-#ifndef READ_CONTROL
-#define READ_CONTROL		0x00020000
-#endif
-#ifndef STANDARD_RIGHTS_READ
-#define STANDARD_RIGHTS_READ	READ_CONTROL
-#endif
-#ifndef STANDARD_RIGHTS_WRITE
-#define STANDARD_RIGHTS_WRITE	READ_CONTROL	/* yes, it's right (js) */
-#endif
-#ifndef STANDARD_RIGHTS_ALL
-#define STANDARD_RIGHTS_ALL	0x001f0000
-#endif
-/* ... */
-
-
+/*
 #define SHELL_ERROR_SUCCESS           0L
 #define SHELL_ERROR_BADDB             1L
 #define SHELL_ERROR_BADKEY            2L
@@ -31,6 +17,7 @@
 #define SHELL_ERROR_OUTOFMEMORY       6L
 #define SHELL_ERROR_INVALID_PARAMETER 7L
 #define SHELL_ERROR_ACCESS_DENIED     8L
+*/
 
 #define REG_NONE		0	/* no type */
 #define REG_SZ                  1	/* string type (ASCII) */
diff --git a/ole/oleobj.c b/ole/oleobj.c
index 738ebd3c42254b7977b1a0a301ee60084bdb3ba2..a561ba8ad0a915f36bf1a8c14a4fa8201204fee9 100644
--- a/ole/oleobj.c
+++ b/ole/oleobj.c
@@ -8,7 +8,6 @@
 #include "ole.h"
 #include "ole2.h"
 #include "winerror.h"
-#include "windows.h"
 #include "wine/obj_base.h"
 #include "wine/obj_storage.h"
 #include "wine/obj_moniker.h"
diff --git a/relay32/advapi32.spec b/relay32/advapi32.spec
index af0764d24b75eb576e9a4d8cec33c42c1e1d01a9..fd8261049718e603554bd094c40bfa89666bd579 100644
--- a/relay32/advapi32.spec
+++ b/relay32/advapi32.spec
@@ -92,7 +92,7 @@ type	win32
 0088 stdcall GetOldestEventLogRecord (long ptr) GetOldestEventLogRecord32
 0089 stub GetPrivateObjectSecurity
 0090 stdcall GetSecurityDescriptorControl (ptr ptr ptr) GetSecurityDescriptorControl32
-0091 stub GetSecurityDescriptorDacl
+0091 stdcall GetSecurityDescriptorDacl (ptr ptr ptr ptr) GetSecurityDescriptorDacl
 0092 stdcall GetSecurityDescriptorGroup(ptr ptr ptr) GetSecurityDescriptorGroup
 0093 stdcall GetSecurityDescriptorLength(ptr) GetSecurityDescriptorLength
 0094 stdcall GetSecurityDescriptorOwner(ptr ptr ptr) GetSecurityDescriptorOwner
@@ -225,10 +225,10 @@ type	win32
 0221 stdcall SetFileSecurityW(wstr long ptr) SetFileSecurity32W
 0222 stub SetKernelObjectSecurity
 0223 stub SetPrivateObjectSecurity
-0224 stdcall SetSecurityDescriptorDacl(ptr long ptr long) RtlSetDaclSecurityDescriptor
-0225 stub SetSecurityDescriptorGroup
-0226 stub SetSecurityDescriptorOwner
-0227 stub SetSecurityDescriptorSacl
+0224 stdcall SetSecurityDescriptorDacl(ptr long ptr long) SetSecurityDescriptorDacl
+0225 stdcall SetSecurityDescriptorGroup (ptr ptr long) SetSecurityDescriptorGroup
+0226 stdcall SetSecurityDescriptorOwner (ptr ptr long) SetSecurityDescriptorOwner
+0227 stdcall SetSecurityDescriptorSacl(ptr long ptr long) SetSecurityDescriptorSacl
 0228 stub SetServiceBits
 0229 stub SetServiceObjectSecurity
 0230 stdcall SetServiceStatus(long long)SetServiceStatus