internal AdamInstance(DirectoryContext context, string adamHostName, DirectoryEntryManager directoryEntryMgr) { this.context = context; // the replica name should be in the form dnshostname:port this.replicaName = adamHostName; string portNumber; Utils.SplitServerNameAndPortNumber(context.Name, out portNumber); if (portNumber != null) { this.replicaName = this.replicaName + ":" + portNumber; } // initialize the directory entry manager this.directoryEntryMgr = directoryEntryMgr; // initialize the transfer role owner attributes _becomeRoleOwnerAttrs = new String[2]; _becomeRoleOwnerAttrs[0] = PropertyManager.BecomeSchemaMaster; _becomeRoleOwnerAttrs[1] = PropertyManager.BecomeDomainMaster; // initialize the callback function _syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(SyncAllCallbackRoutine); }
internal DomainController(DirectoryContext context, string domainControllerName, DirectoryEntryManager directoryEntryMgr) { this.dsHandle = IntPtr.Zero; this.authIdentity = IntPtr.Zero; base.context = context; base.replicaName = domainControllerName; base.directoryEntryMgr = directoryEntryMgr; this.becomeRoleOwnerAttrs = new string[] { PropertyManager.BecomeSchemaMaster, PropertyManager.BecomeDomainMaster, PropertyManager.BecomePdc, PropertyManager.BecomeRidMaster, PropertyManager.BecomeInfrastructureMaster }; this.syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(this.SyncAllCallbackRoutine); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo); try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) { return; } else { throw e; } } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } } finally { // release the memory if (errorInfo != (IntPtr)0) { UnsafeNativeMethods.LocalFree(errorInfo); } } }
internal AdamInstance(DirectoryContext context, string adamInstanceName, DirectoryEntryManager directoryEntryMgr, bool nameIncludesPort) { this.cachedLdapPort = -1; this.cachedSslPort = -1; this.ADAMHandle = IntPtr.Zero; this.authIdentity = IntPtr.Zero; base.context = context; base.replicaName = adamInstanceName; base.directoryEntryMgr = directoryEntryMgr; this.becomeRoleOwnerAttrs = new string[] { PropertyManager.BecomeSchemaMaster, PropertyManager.BecomeDomainMaster }; this.syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(this.SyncAllCallbackRoutine); }
internal AdamInstance(DirectoryContext context, string adamInstanceName, DirectoryEntryManager directoryEntryMgr, bool nameIncludesPort) { this.context = context; this.replicaName = adamInstanceName; this.directoryEntryMgr = directoryEntryMgr; // initialize the transfer role owner attributes _becomeRoleOwnerAttrs = new String[2]; _becomeRoleOwnerAttrs[0] = PropertyManager.BecomeSchemaMaster; _becomeRoleOwnerAttrs[1] = PropertyManager.BecomeDomainMaster; // initialize the callback function _syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(SyncAllCallbackRoutine); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; if (this.Partitions.Contains(partition)) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int num = delegateForFunctionPointer(handle, partition, (int)option | 4, syncAllFunctionPointer, (IntPtr)0, ref intPtr); try { if (intPtr == (IntPtr)0) { if (num != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(num, false)); } } else { SyncFromAllServersOperationException syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, false); if (syncFromAllServersOperationException != null) { throw syncFromAllServersOperationException; } } } finally { if (intPtr != (IntPtr)0) { UnsafeNativeMethods.LocalFree(intPtr); } } return; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } else { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } }
internal AdamInstance(DirectoryContext context, string adamHostName, DirectoryEntryManager directoryEntryMgr) { string str; this.cachedLdapPort = -1; this.cachedSslPort = -1; this.ADAMHandle = IntPtr.Zero; this.authIdentity = IntPtr.Zero; base.context = context; base.replicaName = adamHostName; Utils.SplitServerNameAndPortNumber(context.Name, out str); if (str != null) { base.replicaName = base.replicaName + ":" + str; } base.directoryEntryMgr = directoryEntryMgr; this.becomeRoleOwnerAttrs = new string[] { PropertyManager.BecomeSchemaMaster, PropertyManager.BecomeDomainMaster }; this.syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(this.SyncAllCallbackRoutine); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)); int errorCode = delegateForFunctionPointer(handle, partition, ((int)option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero); try { if (zero != IntPtr.Zero) { SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false); if (exception != null) { throw exception; } } else if (errorCode != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false)); } } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero); } } }
internal DomainController(DirectoryContext context, string domainControllerName, DirectoryEntryManager directoryEntryMgr) { this.dsHandle = IntPtr.Zero; this.authIdentity = IntPtr.Zero; this.context = context; this.replicaName = domainControllerName; this.directoryEntryMgr = directoryEntryMgr; this.becomeRoleOwnerAttrs = new string[5]; this.becomeRoleOwnerAttrs[0] = PropertyManager.BecomeSchemaMaster; this.becomeRoleOwnerAttrs[1] = PropertyManager.BecomeDomainMaster; this.becomeRoleOwnerAttrs[2] = PropertyManager.BecomePdc; this.becomeRoleOwnerAttrs[3] = PropertyManager.BecomeRidMaster; this.becomeRoleOwnerAttrs[4] = PropertyManager.BecomeInfrastructureMaster; this.syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(this.SyncAllCallbackRoutine); }
internal DomainController(DirectoryContext context, string domainControllerName, DirectoryEntryManager directoryEntryMgr) { this.context = context; this.replicaName = domainControllerName; this.directoryEntryMgr = directoryEntryMgr; // initialize the transfer role owner attributes _becomeRoleOwnerAttrs = new String[5]; _becomeRoleOwnerAttrs[0] = PropertyManager.BecomeSchemaMaster; _becomeRoleOwnerAttrs[1] = PropertyManager.BecomeDomainMaster; _becomeRoleOwnerAttrs[2] = PropertyManager.BecomePdc; _becomeRoleOwnerAttrs[3] = PropertyManager.BecomeRidMaster; _becomeRoleOwnerAttrs[4] = PropertyManager.BecomeInfrastructureMaster; // initialize the callback function syncAllFunctionPointer = new SyncReplicaFromAllServersCallback(SyncAllCallbackRoutine); }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) throw new ArgumentException(Res.GetString(Res.ServerNotAReplica), "partition"); // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW)); int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo); try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) return; else throw e; } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } finally { // release the memory if (errorInfo != (IntPtr)0) UnsafeNativeMethods.LocalFree(errorInfo); } }
internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncAllW)); int errorCode = delegateForFunctionPointer(handle, partition, ((int) option) | 4, syncAllFunctionPointer, IntPtr.Zero, ref zero); try { if (zero != IntPtr.Zero) { SyncFromAllServersOperationException exception = ExceptionHelper.CreateSyncAllException(zero, false); if (exception != null) { throw exception; } } else if (errorCode != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(errorCode, false)); } } finally { if (zero != IntPtr.Zero) { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LocalFree(zero); } } }
internal unsafe void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllCallback, string partition, SyncFromAllServersOptions option, SyncUpdateCallback?callback, SafeLibraryHandle libHandle) { IntPtr errorInfo = (IntPtr)0; if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, nameof(partition)); } // we want to return the dn instead of DNS guid // call DsReplicaSyncAllW var dsReplicaSyncAllW = (delegate * unmanaged <IntPtr, char *, int, IntPtr, IntPtr, IntPtr *, int>)global::Interop.Kernel32.GetProcAddress(libHandle, "DsReplicaSyncAllW"); if (dsReplicaSyncAllW == null) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } int result; fixed(char *partitionPtr = partition) { IntPtr syncAllFunctionPointer = Marshal.GetFunctionPointerForDelegate(syncAllCallback); result = dsReplicaSyncAllW(handle, partitionPtr, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, &errorInfo); GC.KeepAlive(syncAllCallback); } try { // error happens during the synchronization if (errorInfo != (IntPtr)0) { SyncFromAllServersOperationException?e = ExceptionHelper.CreateSyncAllException(errorInfo, false); if (e == null) { return; } else { throw e; } } else { // API does not return error infor occurred during synchronization, but result is not success. if (result != 0) { throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false)); } } } finally { // release the memory if (errorInfo != (IntPtr)0) { global::Interop.Kernel32.LocalFree(errorInfo); } } }