From a4ed9e2e4e91629b49e638c9274a5ec644f331de Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 1 Mar 2015 15:21:23 +0000 Subject: [PATCH] [LSASRV] Implement the Directory Service Setup (dssetup) server. svn path=/trunk/; revision=66520 --- reactos/dll/win32/lsasrv/CMakeLists.txt | 6 +- reactos/dll/win32/lsasrv/dssetup.c | 169 ++++++++++++++++++++++++ reactos/dll/win32/lsasrv/lsarpc.c | 2 + reactos/dll/win32/lsasrv/lsasrv.h | 4 + 4 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 reactos/dll/win32/lsasrv/dssetup.c diff --git a/reactos/dll/win32/lsasrv/CMakeLists.txt b/reactos/dll/win32/lsasrv/CMakeLists.txt index ec463c8af56..e1b250a53f0 100644 --- a/reactos/dll/win32/lsasrv/CMakeLists.txt +++ b/reactos/dll/win32/lsasrv/CMakeLists.txt @@ -4,13 +4,16 @@ include_directories( ${REACTOS_SOURCE_DIR}/include/reactos/idl ${REACTOS_SOURCE_DIR}/include/reactos/subsys/lsass) -add_rpc_files(server ${REACTOS_SOURCE_DIR}/include/reactos/idl/lsa.idl) +add_rpc_files(server + ${REACTOS_SOURCE_DIR}/include/reactos/idl/dssetup.idl + ${REACTOS_SOURCE_DIR}/include/reactos/idl/lsa.idl) spec2def(lsasrv.dll lsasrv.spec ADD_IMPORTLIB) list(APPEND SOURCE authpackage.c authport.c database.c + dssetup.c lookup.c lsarpc.c lsasrv.c @@ -21,6 +24,7 @@ list(APPEND SOURCE session.c utils.c lsasrv.h + ${CMAKE_CURRENT_BINARY_DIR}/dssetup_s.c ${CMAKE_CURRENT_BINARY_DIR}/lsa_s.c ${CMAKE_CURRENT_BINARY_DIR}/lsasrv_stubs.c) diff --git a/reactos/dll/win32/lsasrv/dssetup.c b/reactos/dll/win32/lsasrv/dssetup.c new file mode 100644 index 00000000000..1ebe39f1346 --- /dev/null +++ b/reactos/dll/win32/lsasrv/dssetup.c @@ -0,0 +1,169 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: Local Security Authority (LSA) Server + * FILE: reactos/dll/win32/lsasrv/dssetup.c + * PURPOSE: Directory Service setup functions + * + * PROGRAMMERS: Eric Kohl + */ + +#include "lsasrv.h" +#include "dssetup_s.h" +#include "resources.h" + +VOID +NTAPI +LsaIFree_LSAPR_POLICY_INFORMATION(IN POLICY_INFORMATION_CLASS InformationClass, + IN PLSAPR_POLICY_INFORMATION PolicyInformation); + +/* GLOBALS *****************************************************************/ + +VOID +DsSetupInit(VOID) +{ + RPC_STATUS Status; + + Status = RpcServerRegisterIf(dssetup_v0_0_s_ifspec, + NULL, + NULL); + if (Status != RPC_S_OK) + { + WARN("RpcServerRegisterIf() failed (Status %lx)\n", Status); + return; + } +} + + +static +NET_API_STATUS +DsRolepGetBasicInfo( + PDSROLER_PRIMARY_DOMAIN_INFORMATION *DomainInfo) +{ + LSAPR_OBJECT_ATTRIBUTES ObjectAttributes; + PDSROLER_PRIMARY_DOMAIN_INFO_BASIC Buffer; + PLSAPR_POLICY_INFORMATION PolicyInfo; + LSA_HANDLE PolicyHandle; + ULONG Size; + NTSTATUS Status; + + ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes)); + Status = LsarOpenPolicy(NULL, + &ObjectAttributes, + POLICY_VIEW_LOCAL_INFORMATION, + &PolicyHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LsarOpenPolicyFailed with NT status %x\n", + LsaNtStatusToWinError(Status)); + return ERROR_OUTOFMEMORY; + } + + Status = LsarQueryInformationPolicy(PolicyHandle, + PolicyAccountDomainInformation, + &PolicyInfo); + LsarClose(PolicyHandle); + if (!NT_SUCCESS(Status)) + { + TRACE("LsarQueryInformationPolicy with NT status %x\n", + LsaNtStatusToWinError(Status)); + return ERROR_OUTOFMEMORY; + } + + Size = sizeof(DSROLER_PRIMARY_DOMAIN_INFO_BASIC) + + PolicyInfo->PolicyAccountDomainInfo.DomainName.Length + sizeof(WCHAR); + + Buffer = midl_user_allocate(Size); + if (Buffer == NULL) + { + LsaIFree_LSAPR_POLICY_INFORMATION(PolicyAccountDomainInformation, + PolicyInfo); + return ERROR_OUTOFMEMORY; + } + + Buffer->MachineRole = DsRole_RoleStandaloneWorkstation; + Buffer->DomainNameFlat = (LPWSTR)((LPBYTE)Buffer + + sizeof(DSROLER_PRIMARY_DOMAIN_INFO_BASIC)); + wcscpy(Buffer->DomainNameFlat, PolicyInfo->PolicyAccountDomainInfo.DomainName.Buffer); + + LsaIFree_LSAPR_POLICY_INFORMATION(PolicyAccountDomainInformation, + PolicyInfo); + + *DomainInfo = (PDSROLER_PRIMARY_DOMAIN_INFORMATION)Buffer; + + return ERROR_SUCCESS; +} + + +static +NET_API_STATUS +DsRolepGetUpdateStatus( + PDSROLER_PRIMARY_DOMAIN_INFORMATION *DomainInfo) +{ + PDSROLE_UPGRADE_STATUS_INFO Buffer; + + Buffer = midl_user_allocate(sizeof(DSROLE_UPGRADE_STATUS_INFO)); + if (Buffer == NULL) + return ERROR_OUTOFMEMORY; + + Buffer->OperationState = 0; + Buffer->PreviousServerState = 0; + + *DomainInfo = (PDSROLER_PRIMARY_DOMAIN_INFORMATION)Buffer; + + return ERROR_SUCCESS; +} + + +static +NET_API_STATUS +DsRolepGetOperationState( + PDSROLER_PRIMARY_DOMAIN_INFORMATION *DomainInfo) +{ + PDSROLE_OPERATION_STATE_INFO Buffer; + + Buffer = midl_user_allocate(sizeof(DSROLE_OPERATION_STATE_INFO)); + if (Buffer == NULL) + return ERROR_OUTOFMEMORY; + + Buffer->OperationState = DsRoleOperationIdle; + + *DomainInfo = (PDSROLER_PRIMARY_DOMAIN_INFORMATION)Buffer; + + return ERROR_SUCCESS; +} + + +DWORD +WINAPI +DsRolerGetPrimaryDomainInformation( + handle_t hBinding, + DSROLE_PRIMARY_DOMAIN_INFO_LEVEL InfoLevel, + PDSROLER_PRIMARY_DOMAIN_INFORMATION *DomainInfo) +{ + NET_API_STATUS ret; + + TRACE("DsRolerGetPrimaryDomainInformation(%p, %d, %p)\n", + hBinding, InfoLevel, DomainInfo); + + switch (InfoLevel) + { + case DsRolePrimaryDomainInfoBasic: + ret = DsRolepGetBasicInfo(DomainInfo); + break; + + case DsRoleUpgradeStatus: + ret = DsRolepGetUpdateStatus(DomainInfo); + break; + + case DsRoleOperationState: + ret = DsRolepGetOperationState(DomainInfo); + break; + + default: + ret = ERROR_CALL_NOT_IMPLEMENTED; + } + + return ret; +} + +/* EOF */ diff --git a/reactos/dll/win32/lsasrv/lsarpc.c b/reactos/dll/win32/lsasrv/lsarpc.c index 243769de142..1f07a4318aa 100644 --- a/reactos/dll/win32/lsasrv/lsarpc.c +++ b/reactos/dll/win32/lsasrv/lsarpc.c @@ -44,6 +44,8 @@ LsarStartRpcServer(VOID) return; } + DsSetupInit(); + Status = RpcServerListen(1, 20, TRUE); if (Status != RPC_S_OK) { diff --git a/reactos/dll/win32/lsasrv/lsasrv.h b/reactos/dll/win32/lsasrv/lsasrv.h index e72db70df48..1fefc9b4e77 100644 --- a/reactos/dll/win32/lsasrv/lsasrv.h +++ b/reactos/dll/win32/lsasrv/lsasrv.h @@ -166,6 +166,10 @@ NTSTATUS LsapDeleteObjectAttribute(PLSA_DB_OBJECT DbObject, LPWSTR AttributeName); +/* dssetup.c */ +VOID +DsSetupInit(VOID); + /* lookup.c */ NTSTATUS LsapInitSids(VOID);