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 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); } }