From 71ee75477e2f772bd9093ffe4b7c390514cfc6a6 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 4 Jul 2026 22:41:09 +0200 Subject: [PATCH] [WKSSVC][NETAPI32] Fix NetGetJoinInformation --- base/services/wkssvc/domain.c | 69 +++++++++++++++++++++++--------- base/services/wkssvc/rpcserver.c | 2 +- dll/win32/netapi32/wksta_new.c | 11 ++--- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/base/services/wkssvc/domain.c b/base/services/wkssvc/domain.c index 69340adfd54..79d959c1215 100644 --- a/base/services/wkssvc/domain.c +++ b/base/services/wkssvc/domain.c @@ -69,16 +69,17 @@ NetpJoinWorkgroup( NET_API_STATUS NetpGetJoinInformation( - LPWSTR *NameBuffer, - PNETSETUP_JOIN_STATUS BufferType) + _Out_ LPWSTR *NameBuffer, + _Out_ PNETSETUP_JOIN_STATUS BufferType) { LSA_OBJECT_ATTRIBUTES ObjectAttributes; PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomainInfo = NULL; LSA_HANDLE PolicyHandle = NULL; + LPWSTR Name = NULL; + NETSETUP_JOIN_STATUS Type = NetSetupUnknownStatus; NTSTATUS Status; - *BufferType = NetSetupUnknownStatus; - *NameBuffer = NULL; + TRACE("NetpGetJoinInformation(%p, %p)\n", NameBuffer, BufferType); ZeroMemory(&ObjectAttributes, sizeof(LSA_OBJECT_ATTRIBUTES)); ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES); @@ -93,34 +94,66 @@ NetpGetJoinInformation( Status = LsaQueryInformationPolicy(PolicyHandle, PolicyPrimaryDomainInformation, (PVOID*)&PrimaryDomainInfo); - if (LSA_SUCCESS(Status)) + if (!LSA_SUCCESS(Status)) { - TRACE("Sid: %p\n", PrimaryDomainInfo->Sid); - TRACE("Name: %S\n", PrimaryDomainInfo->Name.Buffer); + ERR("LsaQueryInformationPolicy failed (Status 0x%lx)\n", Status); + goto done; + } - if (PrimaryDomainInfo->Name.Length > 0) + TRACE("Sid: %p\n", PrimaryDomainInfo->Sid); + TRACE("Name: %hu %S\n", PrimaryDomainInfo->Name.Length, PrimaryDomainInfo->Name.Buffer); + + if (PrimaryDomainInfo->Name.Length > 0) + { + TRACE("PD name!\n"); + if (PrimaryDomainInfo->Sid != NULL) { - if (PrimaryDomainInfo->Sid != NULL) - *BufferType = NetSetupDomainName; - else - *BufferType = NetSetupWorkgroupName; - - *NameBuffer = midl_user_allocate(PrimaryDomainInfo->Name.Length + sizeof(WCHAR)); - if (*NameBuffer) - wcscpy(*NameBuffer, PrimaryDomainInfo->Name.Buffer); + TRACE("PD SID! -->Domain\n"); + Type = NetSetupDomainName; } else { - *BufferType = NetSetupUnjoined; + TRACE("No PD SID! --> Workgroup\n"); + Type = NetSetupWorkgroupName; + } + } + else + { + TRACE("No PD name!\n"); + Type = NetSetupUnjoined; + } + + TRACE("BufferType: %u\n", *BufferType); + + if ((Type != NetSetupUnjoined) && (PrimaryDomainInfo->Name.Length > 0)) + { + Name = midl_user_allocate(PrimaryDomainInfo->Name.Length + sizeof(WCHAR)); + if (Name == NULL) + { + Status = STATUS_INSUFFICIENT_RESOURCES; + goto done; } + wcscpy(Name, PrimaryDomainInfo->Name.Buffer); + } + +done: + if (PrimaryDomainInfo) + { if (PrimaryDomainInfo->Sid) LsaFreeMemory(PrimaryDomainInfo->Sid); LsaFreeMemory(PrimaryDomainInfo); } - LsaClose(PolicyHandle); + if (PolicyHandle) + LsaClose(PolicyHandle); + + if (LSA_SUCCESS(Status)) + { + *NameBuffer = Name; + *BufferType = Type; + } return LsaNtStatusToWinError(Status); } diff --git a/base/services/wkssvc/rpcserver.c b/base/services/wkssvc/rpcserver.c index ea7ac051fb8..e81df9f87b3 100644 --- a/base/services/wkssvc/rpcserver.c +++ b/base/services/wkssvc/rpcserver.c @@ -1126,7 +1126,7 @@ NetrGetJoinInformation( wchar_t **NameBuffer, PNETSETUP_JOIN_STATUS BufferType) { - TRACE("NetrGetJoinInformation(%p %p %p)\n", + ERR("NetrGetJoinInformation(%p %p %p)\n", ServerName, NameBuffer, BufferType); if (NameBuffer == NULL) diff --git a/dll/win32/netapi32/wksta_new.c b/dll/win32/netapi32/wksta_new.c index d4ce646e653..860c1f7e286 100644 --- a/dll/win32/netapi32/wksta_new.c +++ b/dll/win32/netapi32/wksta_new.c @@ -319,6 +319,7 @@ NetGetJoinInformation( _Out_ LPWSTR *lpNameBuffer, _Out_ PNETSETUP_JOIN_STATUS BufferType) { + PWSTR pName = NULL; NET_API_STATUS status = NERR_Success; TRACE("NetGetJoinInformation(%s %p %p)\n", @@ -327,13 +328,10 @@ NetGetJoinInformation( if (lpNameBuffer == NULL || BufferType == NULL) return ERROR_INVALID_PARAMETER; - /* Disabled because of CORE-17679 */ -#if 0 - *lpNameBuffer = NULL; RpcTryExcept { status = NetrGetJoinInformation((LPWSTR)lpServer, - lpNameBuffer, + &pName, BufferType); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) @@ -341,10 +339,9 @@ NetGetJoinInformation( status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; -#endif - *lpNameBuffer = NULL; - *BufferType = NetSetupUnknownStatus; + if (status == NERR_Success) + *lpNameBuffer = pName; return status; }