#pragma once #include "drsr.h" #include "drsr_alloc.h" #include namespace DSInternals { namespace Replication { namespace Interop { using namespace DSInternals::Common::Data; using namespace DSInternals::Replication::Model; using namespace System::Security::Principal; using namespace Microsoft::Win32::SafeHandles; using namespace System; using namespace System::Runtime::InteropServices; delegate void SecurityCallback(void* rpcContext); public ref class DrsConnection : SafeHandleZeroOrMinusOneIsInvalid { private: array^ _sessionKey; Guid _clientDsa; Guid _serverSiteObjectGuid; DRS_EXT _serverCapabilities; DWORD _serverReplEpoch; SecurityCallback^ _securityCallback; static const size_t defaultMaxObjects = 1000; // 8MB static const size_t defaultMaxBytes = 8 * 1024 * 1024; static const DWORD defaultReplEpoch = 0; public: DrsConnection(IntPtr rpcHandle, Guid clientDsa); DrsConnection(IntPtr preexistingDrssHandle, bool ownsHandle); property array^ SessionKey { array^ get(); } property Guid ServerSiteGuid { Guid get(); } array^ GetReplicationCursors(String^ namingContext); ReplicaObject^ ReplicateSingleObject(Guid objectGuid); ReplicaObject^ ReplicateSingleObject(Guid objectGuid, array^ partialAttributeSet); ReplicaObject^ ReplicateSingleObject(String^ distinguishedName); ReplicaObject^ ReplicateSingleObject(String^ distinguishedName, array^ partialAttributeSet); ReplicationResult^ ReplicateAllObjects(ReplicationCookie^ cookie); ReplicationResult^ ReplicateAllObjects(ReplicationCookie^ cookie, ULONG maxBytes, ULONG maxObjects); ReplicationResult^ ReplicateAllObjects(ReplicationCookie^ cookie, array^ partialAttributeSet, ULONG maxBytes, ULONG maxObjects); String^ ResolveDistinguishedName(NTAccount^ accountName); String^ ResolveDistinguishedName(SecurityIdentifier^ objectSid); Guid ResolveGuid(NTAccount^ accountName); Guid ResolveGuid(SecurityIdentifier^ objectSid); Guid ResolveGuid(String^ userPrincipalName); bool TestObjectExistence(String^ distinguishedName); bool TestObjectExistence(Guid objectGuid); protected: virtual bool ReleaseHandle() override; private: property DWORD MaxSupportedReplicationRequestVersion { DWORD get(); } DrsConnection(); void Bind(IntPtr rpcHandle); midl_ptr GetNCChanges(midl_ptr &&request); midl_ptr CrackNames(midl_ptr &&request); String^ TryResolveName(String^ name, DS_NAME_FORMAT formatOffered, DS_NAME_FORMAT formatDesired); midl_ptr CreateClientInfo(); midl_ptr CreateReplicateAllRequest(ReplicationCookie^ cookie, array^ partialAttributeSet, ULONG maxBytes, ULONG maxObjects); midl_ptr CreateReplicateSingleRequest(String^ distinguishedName, array^ partialAttributeSet); midl_ptr CreateReplicateSingleRequest(Guid objectGuid, array^ partialAttributeSet); midl_ptr CreateGenericReplicateRequest(midl_ptr &&dsName, array^ partialAttributeSet, ULONG maxBytes, ULONG maxObjects); void RetrieveSessionKey(void* rpcContext); static midl_ptr CreateReplicationCursorsRequest(String^ namingContext); static midl_ptr CreateNativePas(array^ partialAttributeSet); static array^ ReadValue(const ATTRVAL &value); static array^>^ ReadValues(const ATTRVALBLOCK &values); static ReplicaAttribute^ ReadAttribute(const ATTR &attribute); static ReplicaAttribute^ ReadAttribute(const REPLVALINF_V3 &attribute); static ReplicaAttributeCollection^ ReadAttributes(const ATTRBLOCK &attributes); static ReplicaObject^ ReadObject(const ENTINF &object); static ReplicaObjectCollection^ ReadObjects(const REPLENTINFLIST *objects, int objectCount, const REPLVALINF_V3 *linkedValues, int valueCount); static Guid ReadGuid(GUID const &guid); static String^ ReadName(const DSNAME* dsName); static SecurityIdentifier^ ReadSid(const DSNAME* dsName); }; } } }