Nikolay Sivov : advapi32: Partially implement LsaLookupPrivilegeName().

Alexandre Julliard julliard at winehq.org
Sun Mar 18 09:02:31 CDT 2018


Module: wine
Branch: oldstable
Commit: f13ad9e3169bf365cbe4a82c7301edba5acc0d48
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=f13ad9e3169bf365cbe4a82c7301edba5acc0d48

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Thu Nov  2 23:56:19 2017 +0300

advapi32: Partially implement LsaLookupPrivilegeName().

Based on patch by Michael Müller.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 2c8427e0dc59edcbafc3d664d92f04063c69c30c)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/advapi32/advapi32_misc.h |  1 +
 dlls/advapi32/lsa.c           | 32 ++++++++++++++++++++++++++------
 dlls/advapi32/security.c      |  9 +++++++++
 dlls/advapi32/tests/lsa.c     | 36 ++++++++++++++++++++++++++++++++++++
 include/Makefile.in           |  1 +
 include/ntlsa.h               | 19 +++++++++++++++++++
 6 files changed, 92 insertions(+), 6 deletions(-)

diff --git a/dlls/advapi32/advapi32_misc.h b/dlls/advapi32/advapi32_misc.h
index 425a7be..240abc8 100644
--- a/dlls/advapi32/advapi32_misc.h
+++ b/dlls/advapi32/advapi32_misc.h
@@ -34,6 +34,7 @@ WCHAR *SERV_dup(const char *str) DECLSPEC_HIDDEN;
 DWORD SERV_OpenSCManagerW(LPCWSTR, LPCWSTR, DWORD, SC_HANDLE*) DECLSPEC_HIDDEN;
 DWORD SERV_OpenServiceW(SC_HANDLE, LPCWSTR, DWORD, SC_HANDLE*) DECLSPEC_HIDDEN;
 NTSTATUS SERV_QueryServiceObjectSecurity(SC_HANDLE, SECURITY_INFORMATION, PSECURITY_DESCRIPTOR, DWORD, LPDWORD) DECLSPEC_HIDDEN;
+const WCHAR *get_wellknown_privilege_name(const LUID *) DECLSPEC_HIDDEN;
 
 /* heap allocation helpers */
 static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
diff --git a/dlls/advapi32/lsa.c b/dlls/advapi32/lsa.c
index 28d9061..47ed8e5 100644
--- a/dlls/advapi32/lsa.c
+++ b/dlls/advapi32/lsa.c
@@ -966,11 +966,31 @@ NTSTATUS WINAPI LsaUnregisterPolicyChangeNotification(
  * LsaLookupPrivilegeName [ADVAPI32.@]
  *
  */
-NTSTATUS WINAPI LsaLookupPrivilegeName(
-    LSA_HANDLE handle,
-    LUID *luid,
-    UNICODE_STRING **name)
+NTSTATUS WINAPI LsaLookupPrivilegeName(LSA_HANDLE handle, LUID *luid, LSA_UNICODE_STRING **name)
 {
-    FIXME("(%p,%p,%p) stub\n", handle, luid, name);
-    return STATUS_NO_SUCH_PRIVILEGE;
+    const WCHAR *privnameW;
+    DWORD length;
+    WCHAR *strW;
+
+    TRACE("(%p,%p,%p)\n", handle, luid, name);
+
+    if (!luid || !handle)
+        return STATUS_INVALID_PARAMETER;
+
+    *name = NULL;
+
+    if (!(privnameW = get_wellknown_privilege_name(luid)))
+        return STATUS_NO_SUCH_PRIVILEGE;
+
+    length = strlenW(privnameW);
+    *name = heap_alloc(sizeof(**name) + (length + 1) * sizeof(WCHAR));
+    if (!*name)
+        return STATUS_NO_MEMORY;
+
+    strW = (WCHAR *)(*name + 1);
+    memcpy(strW, privnameW, length * sizeof(WCHAR));
+    strW[length] = 0;
+    RtlInitUnicodeString(*name, strW);
+
+    return STATUS_SUCCESS;
 }
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 7e41c0a..9c419a3 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -1872,6 +1872,15 @@ static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
     SE_CREATE_GLOBAL_NAME_W,
 };
 
+const WCHAR *get_wellknown_privilege_name(const LUID *luid)
+{
+    if (luid->HighPart || luid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
+            luid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE || !WellKnownPrivNames[luid->LowPart])
+        return NULL;
+
+    return WellKnownPrivNames[luid->LowPart];
+}
+
 /******************************************************************************
  * LookupPrivilegeValueW			[ADVAPI32.@]
  *
diff --git a/dlls/advapi32/tests/lsa.c b/dlls/advapi32/tests/lsa.c
index 1a0d211..6e3694a 100644
--- a/dlls/advapi32/tests/lsa.c
+++ b/dlls/advapi32/tests/lsa.c
@@ -32,6 +32,8 @@
 #include "objbase.h"
 #include "initguid.h"
 #include "wine/test.h"
+#include "winternl.h"
+#include "ntlsa.h"
 
 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
 
@@ -405,6 +407,39 @@ static void test_LsaLookupSids(void)
     ok(status == STATUS_SUCCESS, "got 0x%08x\n", status);
 }
 
+static void test_LsaLookupPrivilegeName(void)
+{
+    LSA_OBJECT_ATTRIBUTES attrs;
+    LSA_UNICODE_STRING *name;
+    LSA_HANDLE policy;
+    NTSTATUS status;
+    LUID luid;
+
+    memset(&attrs, 0, sizeof(attrs));
+    attrs.Length = sizeof(attrs);
+
+    status = LsaOpenPolicy(NULL, &attrs, POLICY_LOOKUP_NAMES, &policy);
+    ok(status == STATUS_SUCCESS, "Failed to open policy, %#x.\n", status);
+
+    name = (void *)0xdeadbeef;
+    status = LsaLookupPrivilegeName(policy, NULL, &name);
+    ok(status != STATUS_SUCCESS, "Unexpected status %#x.\n", status);
+    ok(name == (void *)0xdeadbeef, "Unexpected name pointer.\n");
+
+    name = (void *)0xdeadbeef;
+    luid.HighPart = 1;
+    luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
+    status = LsaLookupPrivilegeName(policy, &luid, &name);
+    ok(status == STATUS_NO_SUCH_PRIVILEGE, "Unexpected status %#x.\n", status);
+    ok(name == NULL, "Unexpected name pointer.\n");
+
+    luid.HighPart = 0;
+    luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
+    status = LsaLookupPrivilegeName(policy, &luid, &name);
+    ok(status == 0, "got %#x.\n", status);
+    LsaFreeMemory(name);
+}
+
 START_TEST(lsa)
 {
     if (!init()) {
@@ -415,4 +450,5 @@ START_TEST(lsa)
     test_lsa();
     test_LsaLookupNames2();
     test_LsaLookupSids();
+    test_LsaLookupPrivilegeName();
 }
diff --git a/include/Makefile.in b/include/Makefile.in
index 0b5e6ad..94d8f75 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -521,6 +521,7 @@ HEADER_SRCS = \
 	ntddstor.h \
 	ntdef.h \
 	ntdsapi.h \
+	ntlsa.h \
 	ntquery.h \
 	ntsecapi.h \
 	ntsecpkg.h \
diff --git a/include/ntlsa.h b/include/ntlsa.h
new file mode 100644
index 0000000..468c14e
--- /dev/null
+++ b/include/ntlsa.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017 Nikolay Sivov
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+NTSTATUS WINAPI LsaLookupPrivilegeName(LSA_HANDLE policy, LUID *value, LSA_UNICODE_STRING **name);




More information about the wine-cvs mailing list