internal static SafeRpcMemoryHandle MarshalPropValueCollection(ICollection <PropValue> properties) { SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(); safeRpcMemoryHandle.Allocate(PropValue.GetBytesToMarshal(properties)); PropValue.MarshalToNative(properties, safeRpcMemoryHandle); return(safeRpcMemoryHandle); }
public NspiStatus End(out PropertyTag[] propertyTags, out SafeRpcMemoryHandle namesHandle) { base.CheckDisposed(); base.CheckCompletion(); propertyTags = null; namesHandle = null; return(base.Status); }
private static PropRowSet GetRowSetAndDisposeHandle(SafeRpcMemoryHandle rowsetHandle) { PropRowSet result; if (rowsetHandle != null) { result = new PropRowSet(rowsetHandle, true); rowsetHandle.Dispose(); } else { result = null; } return(result); }
internal static SafeRpcMemoryHandle MarshalRow(PropRow row) { if (row == null) { return(null); } SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(); SafeRpcMemoryHandle safeRpcMemoryHandle2 = NspiMarshal.MarshalPropValueCollection(row.Properties); row.MarshalledPropertiesHandle = safeRpcMemoryHandle2; safeRpcMemoryHandle.AddAssociatedHandle(safeRpcMemoryHandle2); safeRpcMemoryHandle.Allocate(row.GetBytesToMarshal()); row.MarshalToNative(safeRpcMemoryHandle); return(safeRpcMemoryHandle); }
public NspiStatus Bind(NspiBindFlags flags) { NspiStatus result; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(16)) { this.MarshalStatToNative(); NspiStatus nspiStatus = this.client.Bind(flags, this.statHandle.DangerousGetHandle(), safeRpcMemoryHandle.DangerousGetHandle()); this.MarshalNativeToStat(); byte[] array = new byte[16]; Marshal.Copy(safeRpcMemoryHandle.DangerousGetHandle(), array, 0, array.Length); this.serverGuid = new Guid(array); this.needToUnbind = (nspiStatus == NspiStatus.Success); result = nspiStatus; } return(result); }
// Token: 0x06000196 RID: 406 RVA: 0x000086E4 File Offset: 0x000068E4 public NspiStatus EndGetNamesFromIDs(ICancelableAsyncResult asyncResult, out PropertyTag[] propTags, out SafeRpcMemoryHandle namesHandle) { PropertyTag[] localPropTags = null; SafeRpcMemoryHandle localNamesHandle = null; NspiStatus result; try { result = this.EndContextWrapper("EndGetNamesFromIDs", asyncResult, (NspiDispatchTask task) => ((NspiGetNamesFromIDsDispatchTask)task).End(out localPropTags, out localNamesHandle)); } finally { propTags = localPropTags; namesHandle = localNamesHandle; } return(result); }
public NspiStatus ModProps(IList <PropTag> propTags, PropRow row) { int[] intArrayFromPropTagArray = NspiClient.GetIntArrayFromPropTagArray(propTags); NspiStatus result; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(row.GetBytesToMarshal())) { SafeRpcMemoryHandle safeRpcMemoryHandle2 = NspiMarshal.MarshalPropValueCollection(row.Properties); row.MarshalledPropertiesHandle = safeRpcMemoryHandle2; safeRpcMemoryHandle.AddAssociatedHandle(safeRpcMemoryHandle2); row.MarshalToNative(safeRpcMemoryHandle); this.MarshalStatToNative(); NspiStatus nspiStatus = this.client.ModProps(this.statHandle.DangerousGetHandle(), intArrayFromPropTagArray, safeRpcMemoryHandle.DangerousGetHandle()); this.MarshalNativeToStat(); result = nspiStatus; } return(result); }
internal static SafeRpcMemoryHandle MarshalRowSet(PropRowSet rowset) { if (rowset == null) { return(null); } SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(); foreach (PropRow propRow in rowset.Rows) { SafeRpcMemoryHandle safeRpcMemoryHandle2 = NspiMarshal.MarshalPropValueCollection(propRow.Properties); propRow.MarshalledPropertiesHandle = safeRpcMemoryHandle2; safeRpcMemoryHandle.AddAssociatedHandle(safeRpcMemoryHandle2); } safeRpcMemoryHandle.Allocate(rowset.GetBytesToMarshal()); rowset.MarshalToNative(safeRpcMemoryHandle); return(safeRpcMemoryHandle); }
internal static int GetEstimatedRowCount(IConfigurationSession session, Guid addressListObjectGuid) { int result; try { using (NspiRpcClientConnection nspiRpcClientConnection = session.GetNspiRpcClientConnection()) { int addressListEphemeralId = NspiVirtualListView.GetAddressListEphemeralId(nspiRpcClientConnection, addressListObjectGuid); if (addressListEphemeralId == 0) { result = -1; } else { NspiState nspiState = new NspiState { ContainerId = addressListEphemeralId, CodePage = 1252, TemplateLocale = 1033, SortLocale = 1033 }; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(nspiState.GetBytesToMarshal())) { IntPtr intPtr = safeRpcMemoryHandle.DangerousGetHandle(); nspiState.MarshalToNative(intPtr); int num = nspiRpcClientConnection.RpcClient.UpdateStat(intPtr); if (num != 0) { throw new NspiFailureException(num); } nspiState.MarshalFromNative(intPtr); } result = nspiState.TotalRecords; } } } catch (RpcException ex) { throw new DataSourceOperationException(DirectoryStrings.NspiRpcError(ex.Message), ex); } return(result); }
public NspiStatus SeekEntries(PropValue propValue, int[] mids, IList <PropTag> propTags, out PropRowSet rowset) { int[] intArrayFromPropTagArray = NspiClient.GetIntArrayFromPropTagArray(propTags); IList <PropValue> list = new List <PropValue>(); list.Add(propValue); NspiStatus result; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(propValue.GetBytesToMarshal())) { PropValue.MarshalToNative(list, safeRpcMemoryHandle); this.MarshalStatToNative(); SafeRpcMemoryHandle rowsetHandle; NspiStatus nspiStatus = this.client.SeekEntries(this.statHandle.DangerousGetHandle(), safeRpcMemoryHandle.DangerousGetHandle(), mids, intArrayFromPropTagArray, out rowsetHandle); this.MarshalNativeToStat(); rowset = NspiClient.GetRowSetAndDisposeHandle(rowsetHandle); result = nspiStatus; } return(result); }
internal static SafeRpcMemoryHandle MarshalIntList(IList <int> list) { if (list == null) { return(null); } int size = (list.Count + 1) * 4; SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(); safeRpcMemoryHandle.Allocate(size); int num = 0; Marshal.WriteInt32(safeRpcMemoryHandle.DangerousGetHandle(), num, list.Count); foreach (int val in list) { num += 4; Marshal.WriteInt32(safeRpcMemoryHandle.DangerousGetHandle(), num, val); } return(safeRpcMemoryHandle); }
public NspiStatus GetMatches(Restriction restriction, object propName, int maxRows, IList <PropTag> propTags, out int[] mids, out PropRowSet rowset) { NspiStatus result; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle()) { if (restriction != null) { safeRpcMemoryHandle.Allocate(restriction.GetBytesToMarshalNspi()); restriction.MarshalToNativeNspi(safeRpcMemoryHandle); } int[] intArrayFromPropTagArray = NspiClient.GetIntArrayFromPropTagArray(propTags); this.MarshalStatToNative(); SafeRpcMemoryHandle rowsetHandle; NspiStatus matches = this.client.GetMatches(this.statHandle.DangerousGetHandle(), safeRpcMemoryHandle.DangerousGetHandle(), IntPtr.Zero, maxRows, intArrayFromPropTagArray, out mids, out rowsetHandle); this.MarshalNativeToStat(); rowset = NspiClient.GetRowSetAndDisposeHandle(rowsetHandle); result = matches; } return(result); }
public static NspiRpcClientConnection GetNspiRpcClientConnection(string domainController) { NspiRpcClientConnection nspiRpcClientConnection = new NspiRpcClientConnection(); int hashCode = nspiRpcClientConnection.GetHashCode(); int num = 0; while (!nspiRpcClientConnection.bound) { try { NspiRpcClientConnection.TraceDebug(hashCode, "Creating NspiRpcClient and attempting bind to domain controller {0}", new object[] { domainController }); nspiRpcClientConnection.nspiRpcClient = new NspiRpcClient(domainController, "ncacn_ip_tcp", null); using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(36)) { using (SafeRpcMemoryHandle safeRpcMemoryHandle2 = new SafeRpcMemoryHandle(16)) { IntPtr ptr = safeRpcMemoryHandle.DangerousGetHandle(); Marshal.WriteInt32(ptr, 0, 0); Marshal.WriteInt32(ptr, 4, 0); Marshal.WriteInt32(ptr, 8, 0); Marshal.WriteInt32(ptr, 12, 0); Marshal.WriteInt32(ptr, 16, 0); Marshal.WriteInt32(ptr, 20, 0); Marshal.WriteInt32(ptr, 24, 1252); Marshal.WriteInt32(ptr, 28, 1033); Marshal.WriteInt32(ptr, 32, 1033); int num2 = nspiRpcClientConnection.nspiRpcClient.Bind(0, safeRpcMemoryHandle.DangerousGetHandle(), safeRpcMemoryHandle2.DangerousGetHandle()); if (num2 != 0) { NspiRpcClientConnection.TraceError(hashCode, "Bind returned non-zero SCODE {0}", new object[] { num2 }); throw new NspiFailureException(num2); } NspiRpcClientConnection.TraceDebug(hashCode, "Bind to domain controller {0} succeeded", new object[] { domainController }); nspiRpcClientConnection.bound = true; NspiRpcClientConnection.PerfCounterInstance.NumberOfOpenConnections.Increment(); } } } catch (RpcException ex) { num++; if (ex.ErrorCode != 1753 && ex.ErrorCode != 1727) { NspiRpcClientConnection.TraceError(hashCode, "Caught RpcException \"{0}\" with error code {1}. We will not retry the bind.", new object[] { ex.Message, ex.ErrorCode }); throw new ADOperationException(DirectoryStrings.NspiRpcError(ex.Message), ex); } if (num >= 3) { NspiRpcClientConnection.TraceError(hashCode, "Caught RpcException \"{0}\" with error code {1}. Out of retries; giving up.", new object[] { ex.Message, ex.ErrorCode }); throw new ADTransientException(DirectoryStrings.NspiRpcError(ex.Message), ex); } NspiRpcClientConnection.TraceWarning(hashCode, "Caught RpcException \"{0}\" with error code {1}. We will retry the bind; this is retry {2}.", new object[] { ex.Message, ex.ErrorCode, num }); Thread.Sleep(1000); } finally { if (nspiRpcClientConnection != null && !nspiRpcClientConnection.bound) { NspiRpcClientConnection.TraceDebug(hashCode, "Disposing the NspiRpcClient because we did not successfully bind", new object[0]); nspiRpcClientConnection.nspiRpcClient.Dispose(); nspiRpcClientConnection.nspiRpcClient = null; } } } return(nspiRpcClientConnection); }
public ADRawEntry[] GetPropertyBags(int offset, int count) { if (count < 0) { throw new ArgumentOutOfRangeException("count"); } if (count == 0) { return(Array <ADRawEntry> .Empty); } Encoding encoding = Encoding.GetEncoding(this.codePage); NspiPropertyMap nspiPropertyMap = NspiPropertyMap.Create(this.properties, encoding); PropRowSet propRowSet = null; try { using (NspiRpcClientConnection nspiRpcClientConnection = this.session.GetNspiRpcClientConnection()) { int addressListEphemeralId = NspiVirtualListView.GetAddressListEphemeralId(nspiRpcClientConnection, this.addressListId.ObjectGuid); if (addressListEphemeralId == 0) { return(null); } NspiState nspiState = new NspiState { SortIndex = SortIndex.DisplayName, ContainerId = addressListEphemeralId, CurrentRecord = 0, Delta = offset, CodePage = this.codePage, TemplateLocale = this.session.Lcid, SortLocale = this.session.Lcid }; using (SafeRpcMemoryHandle safeRpcMemoryHandle = new SafeRpcMemoryHandle(nspiState.GetBytesToMarshal())) { SafeRpcMemoryHandle safeRpcMemoryHandle2 = null; try { IntPtr intPtr = safeRpcMemoryHandle.DangerousGetHandle(); nspiState.MarshalToNative(intPtr); int num = nspiRpcClientConnection.RpcClient.UpdateStat(intPtr); if (num != 0) { throw new NspiFailureException(num); } num = nspiRpcClientConnection.RpcClient.QueryRows(0, intPtr, null, count, nspiPropertyMap.NspiProperties, out safeRpcMemoryHandle2); if (num != 0) { throw new NspiFailureException(num); } nspiState.MarshalFromNative(intPtr); this.currentRow = nspiState.Position; this.estimatedRowCount = nspiState.TotalRecords; if (safeRpcMemoryHandle2 != null) { propRowSet = new PropRowSet(safeRpcMemoryHandle2, true); } } finally { if (safeRpcMemoryHandle2 != null) { safeRpcMemoryHandle2.Dispose(); } } } } } catch (RpcException ex) { throw new DataSourceOperationException(DirectoryStrings.NspiRpcError(ex.Message), ex); } if (propRowSet == null) { return(null); } return(nspiPropertyMap.Convert(propRowSet)); }