private static void GetLibraryHandle() { string systemDirectory = Environment.SystemDirectory; IntPtr intPtr = UnsafeNativeMethods.LoadLibrary(string.Concat(systemDirectory, "\\ntdsapi.dll")); if (intPtr != (IntPtr)0) { DirectoryContext.ADHandle = new LoadLibrarySafeHandle(intPtr); DirectoryInfo parent = Directory.GetParent(systemDirectory); intPtr = UnsafeNativeMethods.LoadLibrary(string.Concat(parent.FullName, "\\ADAM\\ntdsapi.dll")); if (intPtr != (IntPtr)0) { DirectoryContext.ADAMHandle = new LoadLibrarySafeHandle(intPtr); return; } else { DirectoryContext.ADAMHandle = DirectoryContext.ADHandle; return; } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } }
private static void GetLibraryHandle() { // first get AD handle string systemPath = Environment.SystemDirectory; IntPtr tempHandle = UnsafeNativeMethods.LoadLibrary(systemPath + "\\ntdsapi.dll"); if (tempHandle == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } else { ADHandle = new LoadLibrarySafeHandle(tempHandle); } // not get the ADAM handle // got to the windows\adam directory DirectoryInfo windowsDirectory = Directory.GetParent(systemPath); tempHandle = UnsafeNativeMethods.LoadLibrary(windowsDirectory.FullName + "\\ADAM\\ntdsapi.dll"); if (tempHandle == (IntPtr)0) { ADAMHandle = ADHandle; } else { ADAMHandle = new LoadLibrarySafeHandle(tempHandle); } }
private static void GetLibraryHandle() { IntPtr ptr = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LoadLibrary(Environment.SystemDirectory + @"\ntdsapi.dll"); if (ptr == IntPtr.Zero) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } ADHandle = new LoadLibrarySafeHandle(ptr); ptr = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LoadLibrary(Environment.CurrentDirectory + @"\ntdsapi.dll"); if (ptr == IntPtr.Zero) { StringBuilder builder = new StringBuilder(); builder.Append(Environment.SystemDirectory, 0, Environment.SystemDirectory.Length - 8); ptr = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.LoadLibrary(builder.ToString() + @"ADAM\ntdsapi.dll"); if (ptr == IntPtr.Zero) { ADAMHandle = ADHandle; } else { ADAMHandle = new LoadLibrarySafeHandle(ptr); } } else { ADAMHandle = new LoadLibrarySafeHandle(ptr); } }
private void FreeReplicaInfo(DS_REPL_INFO_TYPE type, IntPtr value, LoadLibrarySafeHandle libHandle) { if (value != IntPtr.Zero) { IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaFreeInfo"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaFreeInfo delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaFreeInfo)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaFreeInfo)); delegateForFunctionPointer((int)type, value); } }
internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaConsistencyCheck"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck)); int errorCode = delegateForFunctionPointer(dsHandle, 0, 0); if (errorCode != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, this.Name); } }
private void FreeReplicaInfo(DS_REPL_INFO_TYPE type, IntPtr value, LoadLibrarySafeHandle libHandle) { if (value != (IntPtr)0) { // call DsReplicaFreeInfo IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaFreeInfo"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaFreeInfo dsReplicaFreeInfo = (UnsafeNativeMethods.DsReplicaFreeInfo)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaFreeInfo)); dsReplicaFreeInfo((int)type, value); } }
internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaConsistencyCheck"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaConsistencyCheck)); int errorCode = delegateForFunctionPointer(dsHandle, 0, 0); if (errorCode != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, this.Name); } }
internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { // call DsReplicaConsistencyCheck IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaConsistencyCheck"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaConsistencyCheck replicaConsistencyCheck = (UnsafeNativeMethods.DsReplicaConsistencyCheck)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaConsistencyCheck)); int result = replicaConsistencyCheck(dsHandle, 0, 0); if (result != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } }
internal ActiveDirectoryReplicationMetadata ConstructMetaData(bool advanced, IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ActiveDirectoryReplicationMetadata metadata = new ActiveDirectoryReplicationMetadata(server); int count = 0; if (advanced) { try { if (info != IntPtr.Zero) { DS_REPL_OBJ_META_DATA_2 structure = new DS_REPL_OBJ_META_DATA_2(); Marshal.PtrToStructure(info, structure); count = structure.cNumEntries; if (count > 0) { metadata.AddHelper(count, info, true); } } return metadata; } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ, info, libHandle); } } try { DS_REPL_OBJ_META_DATA ds_repl_obj_meta_data = new DS_REPL_OBJ_META_DATA(); Marshal.PtrToStructure(info, ds_repl_obj_meta_data); count = ds_repl_obj_meta_data.cNumEntries; if (count > 0) { metadata.AddHelper(count, info, false); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_FOR_OBJ, info, libHandle); } return metadata; }
internal ReplicationFailureCollection ConstructFailures(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationFailureCollection failures = new ReplicationFailureCollection(server); try { if (info != IntPtr.Zero) { DS_REPL_KCC_DSA_FAILURES structure = new DS_REPL_KCC_DSA_FAILURES(); Marshal.PtrToStructure(info, structure); if (structure.cNumEntries > 0) { failures.AddHelper(structure, info); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES, info, libHandle); } return failures; }
internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaConsistencyCheck"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaConsistencyCheck delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaConsistencyCheck)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaConsistencyCheck)); int num = delegateForFunctionPointer(dsHandle, 0, 0); if (num == 0) { return; } else { throw ExceptionHelper.GetExceptionFromErrorCode(num, this.Name); } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } }
internal ReplicationCursorCollection ConstructReplicationCursors(IntPtr dsHandle, bool advanced, IntPtr info, string partition, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int context = 0; int cNumCursors = 0; ReplicationCursorCollection cursors = new ReplicationCursorCollection(server); if (!advanced) { try { if (info != IntPtr.Zero) { DS_REPL_CURSORS structure = new DS_REPL_CURSORS(); Marshal.PtrToStructure(info, structure); cursors.AddHelper(partition, structure, advanced, info); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, info, libHandle); } return(cursors); } Label_000F: try { if (info != IntPtr.Zero) { DS_REPL_CURSORS_3 ds_repl_cursors_ = new DS_REPL_CURSORS_3(); Marshal.PtrToStructure(info, ds_repl_cursors_); cNumCursors = ds_repl_cursors_.cNumCursors; if (cNumCursors > 0) { cursors.AddHelper(partition, ds_repl_cursors_, advanced, info); } context = ds_repl_cursors_.dwEnumerationContext; if ((context != -1) && (cNumCursors != 0)) { goto Label_005F; } } return(cursors); } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, info, libHandle); } Label_005F: info = this.GetReplicationInfoHelper(dsHandle, 8, 1, partition, ref advanced, context, libHandle); goto Label_000F; }
internal ReplicationNeighborCollection ConstructNeighbors(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationNeighborCollection neighbors = new ReplicationNeighborCollection(server); try { if (info != IntPtr.Zero) { DS_REPL_NEIGHBORS structure = new DS_REPL_NEIGHBORS(); Marshal.PtrToStructure(info, structure); if (structure.cNumNeighbors > 0) { neighbors.AddHelper(structure, info); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_NEIGHBORS, info, libHandle); } return(neighbors); }
internal static IntPtr GetAuthIdentity(DirectoryContext context, LoadLibrarySafeHandle libHandle) { IntPtr ptr; string str; string str2; int errorCode = 0; GetDomainAndUsername(context, out str, out str2); IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsMakePasswordCredentialsW"); if (procAddress == IntPtr.Zero) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.NativeMethods.DsMakePasswordCredentials delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.NativeMethods.DsMakePasswordCredentials) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.NativeMethods.DsMakePasswordCredentials)); errorCode = delegateForFunctionPointer(str, str2, context.Password, out ptr); if (errorCode != 0) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(errorCode); } return ptr; }
internal static IntPtr GetAuthIdentity(DirectoryContext context, LoadLibrarySafeHandle libHandle) { IntPtr intPtr; string str = null; string str1 = null; Utils.GetDomainAndUsername(context, out str, out str1); IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsMakePasswordCredentialsW"); if (procAddress != (IntPtr)0) { NativeMethods.DsMakePasswordCredentials delegateForFunctionPointer = (NativeMethods.DsMakePasswordCredentials)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(NativeMethods.DsMakePasswordCredentials)); int password = delegateForFunctionPointer(str, str1, context.Password, out intPtr); if (password == 0) { return intPtr; } else { throw ExceptionHelper.GetExceptionFromErrorCode(password); } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } }
internal ReplicationFailureCollection ConstructFailures(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationFailureCollection failures = new ReplicationFailureCollection(server); try { if (info != IntPtr.Zero) { DS_REPL_KCC_DSA_FAILURES structure = new DS_REPL_KCC_DSA_FAILURES(); Marshal.PtrToStructure(info, structure); if (structure.cNumEntries > 0) { failures.AddHelper(structure, info); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES, info, libHandle); } return(failures); }
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 IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; int num = 0; bool flag = true; IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfo2W delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); num = delegateForFunctionPointer(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref intPtr); } else { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; flag = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (flag && num == 50) { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW delegateForFunctionPointer1 = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = delegateForFunctionPointer1(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (num == 0) { return intPtr; } else { if (partition != null) { if (type != 9) { if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } else { if (num == ExceptionHelper.ERROR_DS_DRA_BAD_DN || num == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(num, false), "objectPath"); } else { DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { string[] strArrays = new string[1]; strArrays[0] = "name"; directoryEntry.RefreshCache(strArrays); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (!(cOMException.ErrorCode == -2147016672 | cOMException.ErrorCode == -2147016656)) { if (cOMException.ErrorCode == -2147463168 | cOMException.ErrorCode == -2147016654) { throw new ArgumentException(Res.GetString("DSInvalidPath"), "objectPath"); } } else { throw new ArgumentException(Res.GetString("DSNoObject"), "objectPath"); } } } } } throw ExceptionHelper.GetExceptionFromErrorCode(num, this.Name); } }
internal ReplicationCursorCollection ConstructReplicationCursors(IntPtr dsHandle, bool advanced, IntPtr info, string partition, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int num = 0; ReplicationCursorCollection replicationCursorCollection = new ReplicationCursorCollection(server); if (!advanced) { try { if (info != (IntPtr)0) { DS_REPL_CURSORS dSREPLCURSOR = new DS_REPL_CURSORS(); Marshal.PtrToStructure(info, dSREPLCURSOR); replicationCursorCollection.AddHelper(partition, dSREPLCURSOR, advanced, info); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, info, libHandle); } } else { while (true) { try { if (info == (IntPtr)0) { break; } else { DS_REPL_CURSORS_3 dSREPLCURSORS3 = new DS_REPL_CURSORS_3(); Marshal.PtrToStructure(info, dSREPLCURSORS3); int num1 = dSREPLCURSORS3.cNumCursors; if (num1 > 0) { replicationCursorCollection.AddHelper(partition, dSREPLCURSORS3, advanced, info); } num = dSREPLCURSORS3.dwEnumerationContext; if (num == -1 || num1 == 0) { break; } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, info, libHandle); } info = this.GetReplicationInfoHelper(dsHandle, 8, 1, partition, ref advanced, num, libHandle); } } return replicationCursorCollection; }
internal ReplicationOperationInformation ConstructPendingOperations(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationOperationInformation replicationOperationInformation = new ReplicationOperationInformation(); ReplicationOperationCollection replicationOperationCollection = new ReplicationOperationCollection(server); replicationOperationInformation.collection = replicationOperationCollection; try { if (info != (IntPtr)0) { DS_REPL_PENDING_OPS dSREPLPENDINGOP = new DS_REPL_PENDING_OPS(); Marshal.PtrToStructure(info, dSREPLPENDINGOP); int num = dSREPLPENDINGOP.cNumPendingOps; if (num > 0) { replicationOperationCollection.AddHelper(dSREPLPENDINGOP, info); replicationOperationInformation.startTime = DateTime.FromFileTime(dSREPLPENDINGOP.ftimeCurrentOpStarted); replicationOperationInformation.currentOp = replicationOperationCollection.GetFirstOperation(); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_PENDING_OPS, info, libHandle); } return replicationOperationInformation; }
internal ReplicationNeighborCollection ConstructNeighbors(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationNeighborCollection replicationNeighborCollection = new ReplicationNeighborCollection(server); try { if (info != (IntPtr)0) { DS_REPL_NEIGHBORS dSREPLNEIGHBOR = new DS_REPL_NEIGHBORS(); Marshal.PtrToStructure(info, dSREPLNEIGHBOR); int num = dSREPLNEIGHBOR.cNumNeighbors; if (num > 0) { replicationNeighborCollection.AddHelper(dSREPLNEIGHBOR, info); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_NEIGHBORS, info, libHandle); } return replicationNeighborCollection; }
internal ActiveDirectoryReplicationMetadata ConstructMetaData(bool advanced, IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int num; ActiveDirectoryReplicationMetadata activeDirectoryReplicationMetadatum = new ActiveDirectoryReplicationMetadata(server); if (!advanced) { try { DS_REPL_OBJ_META_DATA dSREPLOBJMETADATum = new DS_REPL_OBJ_META_DATA(); Marshal.PtrToStructure(info, dSREPLOBJMETADATum); num = dSREPLOBJMETADATum.cNumEntries; if (num > 0) { activeDirectoryReplicationMetadatum.AddHelper(num, info, false); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_FOR_OBJ, info, libHandle); } } else { try { if (info != (IntPtr)0) { DS_REPL_OBJ_META_DATA_2 dSREPLOBJMETADATA2 = new DS_REPL_OBJ_META_DATA_2(); Marshal.PtrToStructure(info, dSREPLOBJMETADATA2); num = dSREPLOBJMETADATA2.cNumEntries; if (num > 0) { activeDirectoryReplicationMetadatum.AddHelper(num, info, true); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ, info, libHandle); } } return activeDirectoryReplicationMetadatum; }
internal ReplicationFailureCollection ConstructFailures(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationFailureCollection replicationFailureCollection = new ReplicationFailureCollection(server); try { if (info != (IntPtr)0) { DS_REPL_KCC_DSA_FAILURES dSREPLKCCDSAFAILURE = new DS_REPL_KCC_DSA_FAILURES(); Marshal.PtrToStructure(info, dSREPLKCCDSAFAILURE); int num = dSREPLKCCDSAFAILURE.cNumEntries; if (num > 0) { replicationFailureCollection.AddHelper(dSREPLKCCDSAFAILURE, info); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES, info, libHandle); } return replicationFailureCollection; }
internal static IntPtr GetDSHandle(string domainControllerName, string domainName, IntPtr authIdentity, LoadLibrarySafeHandle libHandle) { IntPtr intPtr; string str; IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsBindWithCredW"); if (procAddress != (IntPtr)0) { NativeMethods.DsBindWithCred delegateForFunctionPointer = (NativeMethods.DsBindWithCred)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(NativeMethods.DsBindWithCred)); int num = delegateForFunctionPointer(domainControllerName, domainName, authIdentity, out intPtr); if (num == 0) { return intPtr; } else { int num1 = num; if (domainControllerName != null) { str = domainControllerName; } else { str = domainName; } throw ExceptionHelper.GetExceptionFromErrorCode(num1, str); } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } }
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 void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string sourceServer, int option, LoadLibrarySafeHandle libHandle) { Guid ntdsaObjectGuid; int num = Marshal.SizeOf(typeof(Guid)); AdamInstance adamInstance = null; DomainController domainController = null; IntPtr intPtr = Marshal.AllocHGlobal(num); try { if (sourceServer != null) { DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(sourceServer, DirectoryContextType.DirectoryServer, this.context); if (!isADAM) { domainController = DomainController.GetDomainController(newDirectoryContext); ntdsaObjectGuid = domainController.NtdsaObjectGuid; } else { adamInstance = AdamInstance.GetAdamInstance(newDirectoryContext); ntdsaObjectGuid = adamInstance.NtdsaObjectGuid; } Marshal.StructureToPtr(ntdsaObjectGuid, intPtr, false); } IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaSyncW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncW)); int num1 = delegateForFunctionPointer(dsHandle, partition, intPtr, option); if (num1 != 0) { if (this.Partitions.Contains(partition)) { string name = null; if (num1 != ExceptionHelper.RPC_S_SERVER_UNAVAILABLE) { if (num1 == ExceptionHelper.RPC_S_CALL_FAILED) { name = this.Name; } } else { name = sourceServer; } throw ExceptionHelper.GetExceptionFromErrorCode(num1, name); } else { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } finally { if (intPtr != (IntPtr)0) { Marshal.FreeHGlobal(intPtr); } if (adamInstance != null) { adamInstance.Dispose(); } if (domainController != null) { domainController.Dispose(); } } }
public extern static IntPtr GetProcAddress(LoadLibrarySafeHandle hModule, string entryPoint);
internal ReplicationOperationInformation ConstructPendingOperations(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationOperationInformation replicationOperationInformation = new ReplicationOperationInformation(); ReplicationOperationCollection replicationOperationCollection = new ReplicationOperationCollection(server); replicationOperationInformation.collection = replicationOperationCollection; try { if (info != (IntPtr)0) { DS_REPL_PENDING_OPS dSREPLPENDINGOP = new DS_REPL_PENDING_OPS(); Marshal.PtrToStructure(info, dSREPLPENDINGOP); int num = dSREPLPENDINGOP.cNumPendingOps; if (num > 0) { replicationOperationCollection.AddHelper(dSREPLPENDINGOP, info); replicationOperationInformation.startTime = DateTime.FromFileTime(dSREPLPENDINGOP.ftimeCurrentOpStarted); replicationOperationInformation.currentOp = replicationOperationCollection.GetFirstOperation(); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_PENDING_OPS, info, libHandle); } return(replicationOperationInformation); }
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 ReplicationCursorCollection ConstructReplicationCursors(IntPtr dsHandle, bool advanced, IntPtr info, string partition, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int num = 0; ReplicationCursorCollection replicationCursorCollection = new ReplicationCursorCollection(server); if (!advanced) { try { if (info != (IntPtr)0) { DS_REPL_CURSORS dSREPLCURSOR = new DS_REPL_CURSORS(); Marshal.PtrToStructure(info, dSREPLCURSOR); replicationCursorCollection.AddHelper(partition, dSREPLCURSOR, advanced, info); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, info, libHandle); } } else { while (true) { try { if (info == (IntPtr)0) { break; } else { DS_REPL_CURSORS_3 dSREPLCURSORS3 = new DS_REPL_CURSORS_3(); Marshal.PtrToStructure(info, dSREPLCURSORS3); int num1 = dSREPLCURSORS3.cNumCursors; if (num1 > 0) { replicationCursorCollection.AddHelper(partition, dSREPLCURSORS3, advanced, info); } num = dSREPLCURSORS3.dwEnumerationContext; if (num == -1 || num1 == 0) { break; } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, info, libHandle); } info = this.GetReplicationInfoHelper(dsHandle, 8, 1, partition, ref advanced, num, libHandle); } } return(replicationCursorCollection); }
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 IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr intPtr = (IntPtr)0; int num = 0; bool flag = true; IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfo2W delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); num = delegateForFunctionPointer(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref intPtr); } else { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; flag = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (flag && num == 50) { procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress != (IntPtr)0) { UnsafeNativeMethods.DsReplicaGetInfoW delegateForFunctionPointer1 = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); num = delegateForFunctionPointer1(dsHandle, secondaryType, partition, (IntPtr)0, ref intPtr); advanced = false; } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } if (num == 0) { return(intPtr); } else { if (partition != null) { if (type != 9) { if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } else { if (num == ExceptionHelper.ERROR_DS_DRA_BAD_DN || num == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(num, false), "objectPath"); } else { DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { string[] strArrays = new string[1]; strArrays[0] = "name"; directoryEntry.RefreshCache(strArrays); } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (!(cOMException.ErrorCode == -2147016672 | cOMException.ErrorCode == -2147016656)) { if (cOMException.ErrorCode == -2147463168 | cOMException.ErrorCode == -2147016654) { throw new ArgumentException(Res.GetString("DSInvalidPath"), "objectPath"); } } else { throw new ArgumentException(Res.GetString("DSNoObject"), "objectPath"); } } } } } throw ExceptionHelper.GetExceptionFromErrorCode(num, this.Name); } }
internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string sourceServer, int option, LoadLibrarySafeHandle libHandle) { int structSize = Marshal.SizeOf(typeof(Guid)); IntPtr unmanagedGuid = (IntPtr)0; Guid guid = Guid.Empty; AdamInstance adamServer = null; DomainController dcServer = null; unmanagedGuid = Marshal.AllocHGlobal(structSize); try { if (sourceServer != null) { DirectoryContext newContext = Utils.GetNewDirectoryContext(sourceServer, DirectoryContextType.DirectoryServer, context); if (isADAM) { adamServer = AdamInstance.GetAdamInstance(newContext); guid = adamServer.NtdsaObjectGuid; } else { dcServer = DomainController.GetDomainController(newContext); guid = dcServer.NtdsaObjectGuid; } Marshal.StructureToPtr(guid, unmanagedGuid, false); } // call DsReplicaSyncW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncW dsReplicaSyncW = (UnsafeNativeMethods.DsReplicaSyncW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncW)); int result = dsReplicaSyncW(dsHandle, partition, unmanagedGuid, (int)option); // check the result if (result != 0) { if (!Partitions.Contains(partition)) throw new ArgumentException(Res.GetString(Res.ServerNotAReplica), "partition"); string serverDownName = null; // this is the error returned when the server that we want to sync from is down if (result == ExceptionHelper.RPC_S_SERVER_UNAVAILABLE) serverDownName = sourceServer; // this is the error returned when the server that we want to get synced is down else if (result == ExceptionHelper.RPC_S_CALL_FAILED) serverDownName = Name; throw ExceptionHelper.GetExceptionFromErrorCode(result, serverDownName); } } finally { if (unmanagedGuid != (IntPtr)0) Marshal.FreeHGlobal(unmanagedGuid); if (adamServer != null) adamServer.Dispose(); if (dcServer != null) dcServer.Dispose(); } }
internal ReplicationOperationInformation ConstructPendingOperations(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationOperationInformation information = new ReplicationOperationInformation(); ReplicationOperationCollection operations = new ReplicationOperationCollection(server); information.collection = operations; try { if (info != IntPtr.Zero) { DS_REPL_PENDING_OPS structure = new DS_REPL_PENDING_OPS(); Marshal.PtrToStructure(info, structure); if (structure.cNumPendingOps > 0) { operations.AddHelper(structure, info); information.startTime = DateTime.FromFileTime(structure.ftimeCurrentOpStarted); information.currentOp = operations.GetFirstOperation(); } } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_PENDING_OPS, info, libHandle); } return(information); }
internal void CheckConsistencyHelper(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { // call DsReplicaConsistencyCheck IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaConsistencyCheck"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaConsistencyCheck replicaConsistencyCheck = (UnsafeNativeMethods.DsReplicaConsistencyCheck)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaConsistencyCheck)); int result = replicaConsistencyCheck(dsHandle, 0, 0); if (result != 0) throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); }
internal static void FreeAuthIdentity(IntPtr authIdentity, LoadLibrarySafeHandle libHandle) { if (authIdentity != IntPtr.Zero) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsFreePasswordCredentials"); if (procAddress != (IntPtr)0) { NativeMethods.DsFreePasswordCredentials delegateForFunctionPointer = (NativeMethods.DsFreePasswordCredentials)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(NativeMethods.DsFreePasswordCredentials)); delegateForFunctionPointer(authIdentity); } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr info = (IntPtr)0; int result = 0; bool needToTryAgain = true; IntPtr functionPtr; // first try to use the DsReplicaGetInfo2W API which does not exist on win2k machine // call DsReplicaGetInfo2W functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (functionPtr == (IntPtr)0) { // a win2k machine which does not have it. functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; needToTryAgain = false; } else { UnsafeNativeMethods.DsReplicaGetInfo2W dsReplicaGetInfo2W = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); result = dsReplicaGetInfo2W(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref info); } // check the result if (needToTryAgain && result == DS_REPL_NOTSUPPORTED) { // this is the case that client is xp/win2k3, dc is win2k functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; } if (result != 0) { if (partition != null) { // this is the case of meta data if (type == (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ) { if (result == ExceptionHelper.ERROR_DS_DRA_BAD_DN || result == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) throw new ArgumentException(ExceptionHelper.GetErrorMessage(result, false), "objectPath"); DirectoryEntry verifyEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { verifyEntry.RefreshCache(new string[] { "name" }); } catch (COMException e) { if (e.ErrorCode == unchecked((int)0x80072020) | // dir_error on server side e.ErrorCode == unchecked((int)0x80072030)) // object not exists throw new ArgumentException(Res.GetString(Res.DSNoObject), "objectPath"); else if (e.ErrorCode == unchecked((int)0x80005000) | // bad path name e.ErrorCode == unchecked((int)0x80072032)) // ERROR_DS_INVALID_DN_SYNTAX throw new ArgumentException(Res.GetString(Res.DSInvalidPath), "objectPath"); } } else { if (!Partitions.Contains(partition)) throw new ArgumentException(Res.GetString(Res.ServerNotAReplica), "partition"); } } throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } return info; }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr zero = IntPtr.Zero; int errorCode = 0; bool flag = true; IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (procAddress == IntPtr.Zero) { procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)); errorCode = delegateForFunctionPointer(dsHandle, secondaryType, partition, IntPtr.Zero, ref zero); advanced = false; flag = false; } else { System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W infow = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfo2W)); errorCode = infow(dsHandle, type, partition, IntPtr.Zero, null, null, 0, context, ref zero); } if (flag && (errorCode == 50)) { procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW ow2 = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaGetInfoW)); errorCode = ow2(dsHandle, secondaryType, partition, IntPtr.Zero, ref zero); advanced = false; } if (errorCode == 0) { return(zero); } if (partition != null) { if (type == 9) { if ((errorCode == ExceptionHelper.ERROR_DS_DRA_BAD_DN) || (errorCode == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE)) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(errorCode, false), "objectPath"); } DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { directoryEntry.RefreshCache(new string[] { "name" }); } catch (COMException exception) { if ((exception.ErrorCode == -2147016672) | (exception.ErrorCode == -2147016656)) { throw new ArgumentException(Res.GetString("DSNoObject"), "objectPath"); } if ((exception.ErrorCode == -2147463168) | (exception.ErrorCode == -2147016654)) { throw new ArgumentException(Res.GetString("DSInvalidPath"), "objectPath"); } } } else if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } } throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, this.Name); }
internal IntPtr GetReplicationInfoHelper(IntPtr dsHandle, int type, int secondaryType, string partition, ref bool advanced, int context, LoadLibrarySafeHandle libHandle) { IntPtr info = (IntPtr)0; int result = 0; bool needToTryAgain = true; IntPtr functionPtr; // first try to use the DsReplicaGetInfo2W API which does not exist on win2k machine // call DsReplicaGetInfo2W functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfo2W"); if (functionPtr == (IntPtr)0) { // a win2k machine which does not have it. functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; needToTryAgain = false; } else { UnsafeNativeMethods.DsReplicaGetInfo2W dsReplicaGetInfo2W = (UnsafeNativeMethods.DsReplicaGetInfo2W)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfo2W)); result = dsReplicaGetInfo2W(dsHandle, type, partition, (IntPtr)0, null, null, 0, context, ref info); } // check the result if (needToTryAgain && result == DS_REPL_NOTSUPPORTED) { // this is the case that client is xp/win2k3, dc is win2k functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaGetInfoW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaGetInfoW dsReplicaGetInfoW = (UnsafeNativeMethods.DsReplicaGetInfoW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaGetInfoW)); result = dsReplicaGetInfoW(dsHandle, secondaryType, partition, (IntPtr)0, ref info); advanced = false; } if (result != 0) { if (partition != null) { // this is the case of meta data if (type == (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ) { if (result == ExceptionHelper.ERROR_DS_DRA_BAD_DN || result == ExceptionHelper.ERROR_DS_NAME_UNPARSEABLE) { throw new ArgumentException(ExceptionHelper.GetErrorMessage(result, false), "objectPath"); } DirectoryEntry verifyEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, partition); try { verifyEntry.RefreshCache(new string[] { "name" }); } catch (COMException e) { if (e.ErrorCode == unchecked ((int)0x80072020) | // dir_error on server side e.ErrorCode == unchecked ((int)0x80072030)) // object not exists { throw new ArgumentException(SR.DSNoObject, "objectPath"); } else if (e.ErrorCode == unchecked ((int)0x80005000) | // bad path name e.ErrorCode == unchecked ((int)0x80072032)) // ERROR_DS_INVALID_DN_SYNTAX { throw new ArgumentException(SR.DSInvalidPath, "objectPath"); } } } else { if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } } } throw ExceptionHelper.GetExceptionFromErrorCode(result, Name); } return(info); }
internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string sourceServer, int option, LoadLibrarySafeHandle libHandle) { int cb = Marshal.SizeOf(typeof(Guid)); IntPtr zero = IntPtr.Zero; Guid empty = Guid.Empty; AdamInstance adamInstance = null; DomainController domainController = null; zero = Marshal.AllocHGlobal(cb); try { if (sourceServer != null) { DirectoryContext context = Utils.GetNewDirectoryContext(sourceServer, DirectoryContextType.DirectoryServer, this.context); if (isADAM) { adamInstance = AdamInstance.GetAdamInstance(context); empty = adamInstance.NtdsaObjectGuid; } else { domainController = DomainController.GetDomainController(context); empty = domainController.NtdsaObjectGuid; } Marshal.StructureToPtr(empty, zero, false); } IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncW"); if (procAddress == IntPtr.Zero) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncW delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.DsReplicaSyncW)); int errorCode = delegateForFunctionPointer(dsHandle, partition, zero, option); if (errorCode != 0) { if (!this.Partitions.Contains(partition)) { throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition"); } string targetName = null; if (errorCode == ExceptionHelper.RPC_S_SERVER_UNAVAILABLE) { targetName = sourceServer; } else if (errorCode == ExceptionHelper.RPC_S_CALL_FAILED) { targetName = this.Name; } throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, targetName); } } finally { if (zero != IntPtr.Zero) { Marshal.FreeHGlobal(zero); } if (adamInstance != null) { adamInstance.Dispose(); } if (domainController != null) { domainController.Dispose(); } } }
internal ReplicationOperationInformation ConstructPendingOperations(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationOperationInformation replicationInfo = new ReplicationOperationInformation(); ReplicationOperationCollection collection = new ReplicationOperationCollection(server); replicationInfo.collection = collection; int count = 0; try { if (info != (IntPtr)0) { DS_REPL_PENDING_OPS operations = new DS_REPL_PENDING_OPS(); Marshal.PtrToStructure(info, operations); count = operations.cNumPendingOps; if (count > 0) { collection.AddHelper(operations, info); replicationInfo.startTime = DateTime.FromFileTime(operations.ftimeCurrentOpStarted); replicationInfo.currentOp = collection.GetFirstOperation(); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_PENDING_OPS, info, libHandle); } return(replicationInfo); }
internal ActiveDirectoryReplicationMetadata ConstructMetaData(bool advanced, IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ActiveDirectoryReplicationMetadata metadata = new ActiveDirectoryReplicationMetadata(server); int count = 0; if (advanced) { try { if (info != IntPtr.Zero) { DS_REPL_OBJ_META_DATA_2 structure = new DS_REPL_OBJ_META_DATA_2(); Marshal.PtrToStructure(info, structure); count = structure.cNumEntries; if (count > 0) { metadata.AddHelper(count, info, true); } } return(metadata); } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ, info, libHandle); } } try { DS_REPL_OBJ_META_DATA ds_repl_obj_meta_data = new DS_REPL_OBJ_META_DATA(); Marshal.PtrToStructure(info, ds_repl_obj_meta_data); count = ds_repl_obj_meta_data.cNumEntries; if (count > 0) { metadata.AddHelper(count, info, false); } } finally { this.FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_FOR_OBJ, info, libHandle); } return(metadata); }
internal ReplicationFailureCollection ConstructFailures(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationFailureCollection collection = new ReplicationFailureCollection(server); int count = 0; try { if (info != (IntPtr)0) { DS_REPL_KCC_DSA_FAILURES failures = new DS_REPL_KCC_DSA_FAILURES(); Marshal.PtrToStructure(info, failures); count = failures.cNumEntries; if (count > 0) { collection.AddHelper(failures, info); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES, info, libHandle); } return(collection); }
internal ReplicationCursorCollection ConstructReplicationCursors(IntPtr dsHandle, bool advanced, IntPtr info, string partition, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int context = 0; int count = 0; ReplicationCursorCollection collection = new ReplicationCursorCollection(server); // construct the collection if (advanced) { // using paging to get all the results while (true) { try { if (info != (IntPtr)0) { DS_REPL_CURSORS_3 cursors = new DS_REPL_CURSORS_3(); Marshal.PtrToStructure(info, cursors); count = cursors.cNumCursors; if (count > 0) collection.AddHelper(partition, cursors, advanced, info); context = cursors.dwEnumerationContext; // we already get all the results or there is no result if (context == -1 || count == 0) break; } else { // should not happen, treat as no result is returned. break; } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, info, libHandle); } // get the next batch of results info = GetReplicationInfoHelper(dsHandle, (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, partition, ref advanced, context, libHandle); } } else { try { if (info != (IntPtr)0) { // structure of DS_REPL_CURSORS_3 and DS_REPL_CURSORS actually are the same DS_REPL_CURSORS cursors = new DS_REPL_CURSORS(); Marshal.PtrToStructure(info, cursors); collection.AddHelper(partition, cursors, advanced, info); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, info, libHandle); } } return collection; }
internal static IntPtr GetDSHandle(string domainControllerName, string domainName, IntPtr authIdentity, LoadLibrarySafeHandle libHandle) { IntPtr ptr; int errorCode = 0; IntPtr procAddress = System.DirectoryServices.ActiveDirectory.UnsafeNativeMethods.GetProcAddress(libHandle, "DsBindWithCredW"); if (procAddress == IntPtr.Zero) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } System.DirectoryServices.ActiveDirectory.NativeMethods.DsBindWithCred delegateForFunctionPointer = (System.DirectoryServices.ActiveDirectory.NativeMethods.DsBindWithCred) Marshal.GetDelegateForFunctionPointer(procAddress, typeof(System.DirectoryServices.ActiveDirectory.NativeMethods.DsBindWithCred)); errorCode = delegateForFunctionPointer(domainControllerName, domainName, authIdentity, out ptr); if (errorCode != 0) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(errorCode, (domainControllerName != null) ? domainControllerName : domainName); } return ptr; }
internal ReplicationCursorCollection ConstructReplicationCursors(IntPtr dsHandle, bool advanced, IntPtr info, string partition, DirectoryServer server, LoadLibrarySafeHandle libHandle) { int context = 0; int count = 0; ReplicationCursorCollection collection = new ReplicationCursorCollection(server); // construct the collection if (advanced) { // using paging to get all the results while (true) { try { if (info != (IntPtr)0) { DS_REPL_CURSORS_3 cursors = new DS_REPL_CURSORS_3(); Marshal.PtrToStructure(info, cursors); count = cursors.cNumCursors; if (count > 0) { collection.AddHelper(partition, cursors, advanced, info); } context = cursors.dwEnumerationContext; // we already get all the results or there is no result if (context == -1 || count == 0) { break; } } else { // should not happen, treat as no result is returned. break; } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, info, libHandle); } // get the next batch of results info = GetReplicationInfoHelper(dsHandle, (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_3_FOR_NC, (int)DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, partition, ref advanced, context, libHandle); } } else { try { if (info != (IntPtr)0) { // structure of DS_REPL_CURSORS_3 and DS_REPL_CURSORS actually are the same DS_REPL_CURSORS cursors = new DS_REPL_CURSORS(); Marshal.PtrToStructure(info, cursors); collection.AddHelper(partition, cursors, advanced, info); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_CURSORS_FOR_NC, info, libHandle); } } return(collection); }
internal void SyncReplicaHelper(IntPtr dsHandle, bool isADAM, string partition, string sourceServer, int option, LoadLibrarySafeHandle libHandle) { int structSize = Marshal.SizeOf(typeof(Guid)); IntPtr unmanagedGuid = (IntPtr)0; Guid guid = Guid.Empty; AdamInstance adamServer = null; DomainController dcServer = null; unmanagedGuid = Marshal.AllocHGlobal(structSize); try { if (sourceServer != null) { DirectoryContext newContext = Utils.GetNewDirectoryContext(sourceServer, DirectoryContextType.DirectoryServer, context); if (isADAM) { adamServer = AdamInstance.GetAdamInstance(newContext); guid = adamServer.NtdsaObjectGuid; } else { dcServer = DomainController.GetDomainController(newContext); guid = dcServer.NtdsaObjectGuid; } Marshal.StructureToPtr(guid, unmanagedGuid, false); } // call DsReplicaSyncW IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncW"); if (functionPtr == (IntPtr)0) { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } UnsafeNativeMethods.DsReplicaSyncW dsReplicaSyncW = (UnsafeNativeMethods.DsReplicaSyncW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncW)); int result = dsReplicaSyncW(dsHandle, partition, unmanagedGuid, (int)option); // check the result if (result != 0) { if (!Partitions.Contains(partition)) { throw new ArgumentException(SR.ServerNotAReplica, "partition"); } string serverDownName = null; // this is the error returned when the server that we want to sync from is down if (result == ExceptionHelper.RPC_S_SERVER_UNAVAILABLE) { serverDownName = sourceServer; } // this is the error returned when the server that we want to get synced is down else if (result == ExceptionHelper.RPC_S_CALL_FAILED) { serverDownName = Name; } throw ExceptionHelper.GetExceptionFromErrorCode(result, serverDownName); } } finally { if (unmanagedGuid != (IntPtr)0) { Marshal.FreeHGlobal(unmanagedGuid); } if (adamServer != null) { adamServer.Dispose(); } if (dcServer != null) { dcServer.Dispose(); } } }
internal ReplicationNeighborCollection ConstructNeighbors(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationNeighborCollection collection = new ReplicationNeighborCollection(server); int count = 0; try { if (info != (IntPtr)0) { DS_REPL_NEIGHBORS neighbors = new DS_REPL_NEIGHBORS(); Marshal.PtrToStructure(info, neighbors); Debug.Assert(neighbors != null); count = neighbors.cNumNeighbors; if (count > 0) { collection.AddHelper(neighbors, info); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_NEIGHBORS, info, libHandle); } return(collection); }
internal ReplicationFailureCollection ConstructFailures(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationFailureCollection collection = new ReplicationFailureCollection(server); int count = 0; try { if (info != (IntPtr)0) { DS_REPL_KCC_DSA_FAILURES failures = new DS_REPL_KCC_DSA_FAILURES(); Marshal.PtrToStructure(info, failures); count = failures.cNumEntries; if (count > 0) collection.AddHelper(failures, info); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES, info, libHandle); } return collection; }
internal ActiveDirectoryReplicationMetadata ConstructMetaData(bool advanced, IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ActiveDirectoryReplicationMetadata collection = new ActiveDirectoryReplicationMetadata(server); int count = 0; if (advanced) { try { if (info != (IntPtr)0) { DS_REPL_OBJ_META_DATA_2 objMetaData = new DS_REPL_OBJ_META_DATA_2(); Marshal.PtrToStructure(info, objMetaData); count = objMetaData.cNumEntries; if (count > 0) { collection.AddHelper(count, info, true); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ, info, libHandle); } } else { try { DS_REPL_OBJ_META_DATA objMetadata = new DS_REPL_OBJ_META_DATA(); Marshal.PtrToStructure(info, objMetadata); count = objMetadata.cNumEntries; if (count > 0) { collection.AddHelper(count, info, false); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_FOR_OBJ, info, libHandle); } } return(collection); }
internal ActiveDirectoryReplicationMetadata ConstructMetaData(bool advanced, IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ActiveDirectoryReplicationMetadata collection = new ActiveDirectoryReplicationMetadata(server); int count = 0; if (advanced) { try { if (info != (IntPtr)0) { DS_REPL_OBJ_META_DATA_2 objMetaData = new DS_REPL_OBJ_META_DATA_2(); Marshal.PtrToStructure(info, objMetaData); count = objMetaData.cNumEntries; if (count > 0) { collection.AddHelper(count, info, true); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_2_FOR_OBJ, info, libHandle); } } else { try { DS_REPL_OBJ_META_DATA objMetadata = new DS_REPL_OBJ_META_DATA(); Marshal.PtrToStructure(info, objMetadata); count = objMetadata.cNumEntries; if (count > 0) { collection.AddHelper(count, info, false); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_METADATA_FOR_OBJ, info, libHandle); } } return collection; }
internal ReplicationOperationInformation ConstructPendingOperations(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationOperationInformation replicationInfo = new ReplicationOperationInformation(); ReplicationOperationCollection collection = new ReplicationOperationCollection(server); replicationInfo.collection = collection; int count = 0; try { if (info != (IntPtr)0) { DS_REPL_PENDING_OPS operations = new DS_REPL_PENDING_OPS(); Marshal.PtrToStructure(info, operations); count = operations.cNumPendingOps; if (count > 0) { collection.AddHelper(operations, info); replicationInfo.startTime = DateTime.FromFileTime(operations.ftimeCurrentOpStarted); replicationInfo.currentOp = collection.GetFirstOperation(); } } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_PENDING_OPS, info, libHandle); } return replicationInfo; }
internal static void FreeDSHandle(IntPtr dsHandle, LoadLibrarySafeHandle libHandle) { if (dsHandle != IntPtr.Zero) { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsUnBindW"); if (procAddress != (IntPtr)0) { NativeMethods.DsUnBind delegateForFunctionPointer = (NativeMethods.DsUnBind)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(NativeMethods.DsUnBind)); delegateForFunctionPointer(ref dsHandle); } else { throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error()); } } }
internal ReplicationNeighborCollection ConstructNeighbors(IntPtr info, DirectoryServer server, LoadLibrarySafeHandle libHandle) { ReplicationNeighborCollection collection = new ReplicationNeighborCollection(server); int count = 0; try { if (info != (IntPtr)0) { DS_REPL_NEIGHBORS neighbors = new DS_REPL_NEIGHBORS(); Marshal.PtrToStructure(info, neighbors); Debug.Assert(neighbors != null); count = neighbors.cNumNeighbors; if (count > 0) collection.AddHelper(neighbors, info); } } finally { FreeReplicaInfo(DS_REPL_INFO_TYPE.DS_REPL_INFO_NEIGHBORS, info, libHandle); } return collection; }