[LSASRV]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 29 Sep 2012 22:52:30 +0000 (22:52 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 29 Sep 2012 22:52:30 +0000 (22:52 +0000)
- Fix a typo: LsarEnmuerateAccountRights --> LsarEnumerateAccountRights.
- Implement LsarEnumeratePrivileges.

svn path=/trunk/; revision=57438

reactos/dll/win32/advapi32/sec/lsa.c
reactos/dll/win32/lsasrv/lsarpc.c
reactos/dll/win32/lsasrv/lsasrv.h
reactos/dll/win32/lsasrv/privileges.c
reactos/include/reactos/idl/lsa.idl

index e428f6d..d0675ab 100644 (file)
@@ -417,7 +417,7 @@ LsaEnumerateAccountRights(IN LSA_HANDLE PolicyHandle,
 
     RpcTryExcept
     {
-        Status = LsarEnmuerateAccountRights((LSAPR_HANDLE)PolicyHandle,
+        Status = LsarEnumerateAccountRights((LSAPR_HANDLE)PolicyHandle,
                                             AccountSid,
                                             &UserRightsSet);
 
index 73c8b7d..07ac20c 100644 (file)
@@ -109,8 +109,26 @@ NTSTATUS WINAPI LsarEnumeratePrivileges(
     PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer,
     DWORD PreferedMaximumLength)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PLSA_DB_OBJECT PolicyObject;
+    NTSTATUS Status;
+
+    TRACE("LsarEnumeratePrivileges(%p %p %p %lu)\n",
+          PolicyHandle, EnumerationContext, EnumerationBuffer,
+          PreferedMaximumLength);
+
+    Status = LsapValidateDbObject(PolicyHandle,
+                                  LsaDbPolicyObject,
+                                  POLICY_VIEW_LOCAL_INFORMATION,
+                                  &PolicyObject);
+    if (!NT_SUCCESS(Status))
+        return Status;
+
+    if (EnumerationContext == NULL)
+        return STATUS_INVALID_PARAMETER;
+
+    return LsarpEnumeratePrivileges(EnumerationContext,
+                                    EnumerationBuffer,
+                                    PreferedMaximumLength);
 }
 
 
@@ -1658,7 +1676,7 @@ NTSTATUS WINAPI LsarEnumerateAccountsWithUserRight(
 
 
 /* Function 36 */
-NTSTATUS WINAPI LsarEnmuerateAccountRights(
+NTSTATUS WINAPI LsarEnumerateAccountRights(
     LSAPR_HANDLE PolicyHandle,
     PRPC_SID AccountSid,
     PLSAPR_USER_RIGHT_SET UserRights)
@@ -1666,7 +1684,8 @@ NTSTATUS WINAPI LsarEnmuerateAccountRights(
     PLSA_DB_OBJECT PolicyObject;
     NTSTATUS Status;
 
-    FIXME("(%p,%p,%p) stub\n", PolicyHandle, AccountSid, UserRights);
+    TRACE("LsarEnumerateAccountRights(%p %p %p)\n",
+          PolicyHandle, AccountSid, UserRights);
 
     Status = LsapValidateDbObject(PolicyHandle,
                                   LsaDbPolicyObject,
index 1f387ac..0086868 100644 (file)
@@ -182,6 +182,11 @@ NTSTATUS
 LsarpLookupPrivilegeValue(PUNICODE_STRING Name,
                           PLUID Value);
 
+NTSTATUS
+LsarpEnumeratePrivileges(DWORD *EnumerationContext,
+                         PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer,
+                         DWORD PreferedMaximumLength);
+
 /* sids.h */
 NTSTATUS
 LsapInitSids(VOID);
index b42c5da..d2d21e7 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "lsasrv.h"
 
+WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
+
 
 typedef struct
 {
@@ -17,6 +19,8 @@ typedef struct
 } PRIVILEGE_DATA;
 
 
+/* GLOBALS *****************************************************************/
+
 static const PRIVILEGE_DATA WellKnownPrivileges[] =
 {
     {{SE_CREATE_TOKEN_PRIVILEGE, 0}, SE_CREATE_TOKEN_NAME},
@@ -111,8 +115,6 @@ LsarpLookupPrivilegeValue(PUNICODE_STRING Name,
     {
         if (_wcsicmp(Name->Buffer, WellKnownPrivileges[Priv].Name) == 0)
         {
-//            Value->LowPart = WellKnownPrivileges[Priv].Luid.LowPart;
-//            Value->HighPart = WellKnownPrivileges[Priv].Luid.HighPart;
             *Value = WellKnownPrivileges[Priv].Luid;
             return STATUS_SUCCESS;
         }
@@ -120,3 +122,100 @@ LsarpLookupPrivilegeValue(PUNICODE_STRING Name,
 
     return STATUS_NO_SUCH_PRIVILEGE;
 }
+
+
+NTSTATUS
+LsarpEnumeratePrivileges(DWORD *EnumerationContext,
+                         PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer,
+                         DWORD PreferedMaximumLength)
+{
+    PLSAPR_POLICY_PRIVILEGE_DEF Privileges = NULL;
+    ULONG EnumIndex;
+    ULONG EnumCount = 0;
+    ULONG RequiredLength = 0;
+    ULONG i;
+    BOOLEAN MoreEntries = FALSE;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    EnumIndex = *EnumerationContext;
+
+    for (; EnumIndex < sizeof(WellKnownPrivileges) / sizeof(WellKnownPrivileges[0]); EnumIndex++)
+    {
+        TRACE("EnumIndex: %lu\n", EnumIndex);
+        TRACE("Privilege Name: %S\n", WellKnownPrivileges[EnumIndex].Name);
+        TRACE("Name Length: %lu\n", wcslen(WellKnownPrivileges[EnumIndex].Name));
+
+        if ((RequiredLength +
+             wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR) +
+             sizeof(UNICODE_NULL) +
+             sizeof(LSAPR_POLICY_PRIVILEGE_DEF)) > PreferedMaximumLength)
+        {
+            MoreEntries = TRUE;
+            break;
+        }
+
+        RequiredLength += (wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR) +
+                           sizeof(UNICODE_NULL) + sizeof(LSAPR_POLICY_PRIVILEGE_DEF));
+        EnumCount++;
+    }
+
+    TRACE("EnumCount: %lu\n", EnumCount);
+    TRACE("RequiredLength: %lu\n", RequiredLength);
+
+    if (EnumCount == 0)
+        goto done;
+
+    Privileges = MIDL_user_allocate(EnumCount * sizeof(LSAPR_POLICY_PRIVILEGE_DEF));
+    if (Privileges == NULL)
+    {
+        Status = STATUS_INSUFFICIENT_RESOURCES;
+        goto done;
+    }
+
+    EnumIndex = *EnumerationContext;
+
+    for (i = 0; i < EnumCount; i++, EnumIndex++)
+    {
+        Privileges[i].LocalValue = WellKnownPrivileges[EnumIndex].Luid;
+
+        Privileges[i].Name.Length = (USHORT)wcslen(WellKnownPrivileges[EnumIndex].Name) * sizeof(WCHAR);
+        Privileges[i].Name.MaximumLength = (USHORT)Privileges[i].Name.Length + sizeof(UNICODE_NULL);
+
+        Privileges[i].Name.Buffer = MIDL_user_allocate(Privileges[i].Name.MaximumLength);
+        if (Privileges[i].Name.Buffer == NULL)
+        {
+            Status = STATUS_INSUFFICIENT_RESOURCES;
+            goto done;
+        }
+
+        memcpy(Privileges[i].Name.Buffer,
+               WellKnownPrivileges[EnumIndex].Name,
+               Privileges[i].Name.Length);
+    }
+
+done:
+    if (NT_SUCCESS(Status))
+    {
+        EnumerationBuffer->Entries = EnumCount;
+        EnumerationBuffer->Privileges = Privileges;
+        *EnumerationContext += EnumCount;
+    }
+    else
+    {
+        if (Privileges != NULL)
+        {
+            for (i = 0; i < EnumCount; i++)
+            {
+                if (Privileges[i].Name.Buffer != NULL)
+                    MIDL_user_free(Privileges[i].Name.Buffer);
+            }
+
+            MIDL_user_free(Privileges);
+        }
+    }
+
+    if ((Status == STATUS_SUCCESS) && (MoreEntries == TRUE))
+        Status = STATUS_MORE_ENTRIES;
+
+    return Status;
+}
\ No newline at end of file
index b8840ce..7a33d75 100644 (file)
@@ -821,7 +821,7 @@ cpp_quote("#if _WIN32_WINNT >= 0x0351")
         [out] PLSAPR_ACCOUNT_ENUM_BUFFER EnumerationBuffer);
 
     /* Function 36 */
-    NTSTATUS __stdcall LsarEnmuerateAccountRights(
+    NTSTATUS __stdcall LsarEnumerateAccountRights(
         [in] LSAPR_HANDLE PolicyHandle,
         [in] PRPC_SID AccountSid,
         [out] PLSAPR_USER_RIGHT_SET UserRights);