public object Invoke(string methodName, params object[] args) { object nativeObject = this.NativeObject; Type type = nativeObject.GetType(); object adsObject = null; try { adsObject = type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, nativeObject, args, CultureInfo.InvariantCulture); GC.KeepAlive(this); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } catch (TargetInvocationException exception2) { if ((exception2.InnerException != null) && (exception2.InnerException is COMException)) { COMException innerException = (COMException)exception2.InnerException; throw new TargetInvocationException(exception2.Message, COMExceptionHelper.CreateFormattedComException(innerException)); } throw exception2; } if (adsObject is System.DirectoryServices.Interop.UnsafeNativeMethods.IAds) { return(new DirectoryEntry(adsObject, this.UsePropertyCache, this.GetUsername(), this.GetPassword(), this.AuthenticationType)); } return(adsObject); }
public void CommitChanges() { if (this.justCreated) { try { this.SetObjectSecurityInCache(); this.adsObject.SetInfo(); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } this.justCreated = false; this.objectSecurityInitialized = false; this.objectSecurityModified = false; this.propertyCollection = null; } else if ((this.useCache || ((this.objectSecurity != null) && this.objectSecurity.IsModified())) && this.Bound) { try { this.SetObjectSecurityInCache(); this.adsObject.SetInfo(); this.objectSecurityInitialized = false; this.objectSecurityModified = false; } catch (COMException exception2) { throw COMExceptionHelper.CreateFormattedComException(exception2); } this.propertyCollection = null; } }
public object InvokeGet(string propertyName) { object nativeObject = this.NativeObject; Type type = nativeObject.GetType(); object obj3 = null; try { obj3 = type.InvokeMember(propertyName, BindingFlags.GetProperty, null, nativeObject, null, CultureInfo.InvariantCulture); GC.KeepAlive(this); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } catch (TargetInvocationException exception2) { if ((exception2.InnerException != null) && (exception2.InnerException is COMException)) { COMException innerException = (COMException)exception2.InnerException; throw new TargetInvocationException(exception2.Message, COMExceptionHelper.CreateFormattedComException(innerException)); } throw exception2; } return(obj3); }
internal void FillCache(string propertyName) { if (this.UsePropertyCache) { if (!this.cacheFilled) { this.RefreshCache(); this.cacheFilled = true; } } else { this.Bind(); try { if (propertyName.Length > 0) { this.adsObject.GetInfoEx(new object[] { propertyName }, 0); } else { this.adsObject.GetInfo(); } } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } } }
internal void InitADsObjectOptions() { if (this.adsObject is System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsObjectOptions2) { object obj2 = null; int hr = 0; hr = ((System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsObjectOptions2) this.adsObject).GetOption(8, out obj2); if (hr != 0) { if ((hr != -2147467263) && (hr != -2147463160)) { throw COMExceptionHelper.CreateFormattedComException(hr); } } else { System.DirectoryServices.Interop.Variant variant = new System.DirectoryServices.Interop.Variant { varType = 11, boolvalue = -1 }; ((System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsObjectOptions2) this.adsObject).SetOption(8, variant); this.allowMultipleChange = true; } } }
/// <include file='doc\PropertyValueCollection.uex' path='docs/doc[@for="PropertyValueCollection.PopulateList"]/*' /> ///<internalonly/> private void PopulateList() { //No need to fill the cache here, when GetEx is calles, an implicit //call to GetInfo will be called against an uninitialized property //cache. Which is exactly what FillCache does. //entry.FillCache(propertyName); object var; int unmanagedResult = _entry.AdsObject.GetEx(_propertyName, out var); if (unmanagedResult != 0) { // property not found (IIS provider returns 0x80005006, other provides return 0x8000500D). if ((unmanagedResult == unchecked ((int)0x8000500D)) || (unmanagedResult == unchecked ((int)0x80005006))) { return; } else { throw COMExceptionHelper.CreateFormattedComException(unmanagedResult); } } if (var is ICollection) { InnerList.AddRange((ICollection)var); } else { InnerList.Add(var); } }
public void Remove(DirectoryEntry entry) { this.CheckIsContainer(); try { this.container.ContainerObject.Delete(entry.SchemaClassName, entry.Name); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } }
public void MoveTo(DirectoryEntry newParent, string newName) { object obj2 = null; if (!(newParent.AdsObject is System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsContainer)) { throw new InvalidOperationException(Res.GetString("DSNotAContainer", new object[] { newParent.Path })); } try { if (this.AdsObject.ADsPath.StartsWith("WinNT:", StringComparison.Ordinal)) { string aDsPath = this.AdsObject.ADsPath; string str2 = newParent.AdsObject.ADsPath; if (Utils.Compare(aDsPath, 0, str2.Length, str2, 0, str2.Length) == 0) { uint compareFlags = ((Utils.NORM_IGNORENONSPACE | Utils.NORM_IGNOREKANATYPE) | Utils.NORM_IGNOREWIDTH) | Utils.SORT_STRINGSORT; if (Utils.Compare(aDsPath, 0, str2.Length, str2, 0, str2.Length, compareFlags) != 0) { aDsPath = str2 + aDsPath.Substring(str2.Length); } } obj2 = newParent.ContainerObject.MoveHere(aDsPath, newName); } else { obj2 = newParent.ContainerObject.MoveHere(this.Path, newName); } } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } if (this.Bound) { Marshal.ReleaseComObject(this.adsObject); } this.adsObject = (System.DirectoryServices.Interop.UnsafeNativeMethods.IAds)obj2; this.path = this.adsObject.ADsPath; this.InitADsObjectOptions(); if (!this.useCache) { this.CommitChanges(); } else { this.RefreshCache(); } }
public bool Contains(string propertyName) { object obj2; int ex = this.entry.AdsObject.GetEx(propertyName, out obj2); if (ex == 0) { return(true); } if ((ex != -2147463155) && (ex != -2147463162)) { throw COMExceptionHelper.CreateFormattedComException(ex); } return(false); }
public DirectoryEntry Find(string name, string schemaClassName) { this.CheckIsContainer(); object adsObject = null; try { adsObject = this.container.ContainerObject.GetObject(schemaClassName, name); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } return(new DirectoryEntry(adsObject, this.container.UsePropertyCache, this.container.GetUsername(), this.container.GetPassword(), this.container.AuthenticationType)); }
public void RefreshCache(string[] propertyNames) { this.Bind(); object[] vProperties = new object[propertyNames.Length]; for (int i = 0; i < propertyNames.Length; i++) { vProperties[i] = propertyNames[i]; } try { this.AdsObject.GetInfoEx(vProperties, 0); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } this.cacheFilled = true; if ((this.propertyCollection != null) && (propertyNames != null)) { for (int j = 0; j < propertyNames.Length; j++) { if (propertyNames[j] != null) { string key = propertyNames[j].ToLower(CultureInfo.InvariantCulture); this.propertyCollection.valueTable.Remove(key); string[] strArray = key.Split(new char[] { ';' }); if (strArray.Length != 1) { string str2 = ""; for (int k = 0; k < strArray.Length; k++) { if (!strArray[k].StartsWith("range=", StringComparison.Ordinal)) { str2 = str2 + strArray[k] + ";"; } } str2 = str2.Remove(str2.Length - 1, 1); this.propertyCollection.valueTable.Remove(str2); } if (string.Compare(propertyNames[j], securityDescriptorProperty, StringComparison.OrdinalIgnoreCase) == 0) { this.objectSecurityInitialized = false; this.objectSecurityModified = false; } } } } }
/// <devdoc> /// Returns the child with the given name and of the given type. /// </devdoc> public DirectoryEntry Find(string name, string?schemaClassName) { CheckIsContainer(); // Note: schemaClassName == null does not work for IIS: provider. object?o = null; try { o = _container.ContainerObject.GetObject(schemaClassName, name); } catch (COMException e) { throw COMExceptionHelper.CreateFormattedComException(e); } return(new DirectoryEntry(o, _container.UsePropertyCache, _container.GetUsername(), _container.GetPassword(), _container.AuthenticationType)); }
public void RefreshCache() { this.Bind(); try { this.adsObject.GetInfo(); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } this.cacheFilled = true; this.propertyCollection = null; this.objectSecurityInitialized = false; this.objectSecurityModified = false; }
public void DeleteTree() { if (!(this.AdsObject is System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsDeleteOps)) { throw new InvalidOperationException(Res.GetString("DSCannotDelete")); } System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsDeleteOps adsObject = (System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsDeleteOps) this.AdsObject; try { adsObject.DeleteObject(0); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } GC.KeepAlive(this); }
public DirectoryEntry CopyTo(DirectoryEntry newParent, string newName) { if (!newParent.IsContainer) { throw new InvalidOperationException(Res.GetString("DSNotAContainer", new object[] { newParent.Path })); } object adsObject = null; try { adsObject = newParent.ContainerObject.CopyHere(this.Path, newName); } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } return(new DirectoryEntry(adsObject, newParent.UsePropertyCache, this.GetUsername(), this.GetPassword(), this.AuthenticationType)); }
internal void CommitIfNotCaching() { if ((!this.justCreated && !this.useCache) && this.Bound) { new DirectoryServicesPermission(PermissionState.Unrestricted).Demand(); try { this.SetObjectSecurityInCache(); this.adsObject.SetInfo(); this.objectSecurityInitialized = false; this.objectSecurityModified = false; } catch (COMException exception) { throw COMExceptionHelper.CreateFormattedComException(exception); } this.propertyCollection = null; } }
public bool Contains(string propertyName) { object var; int unmanagedResult = _entry.AdsObject.GetEx(propertyName, out var); if (unmanagedResult != 0) { // property not found (IIS provider returns 0x80005006, other provides return 0x8000500D). if ((unmanagedResult == unchecked ((int)0x8000500D)) || (unmanagedResult == unchecked ((int)0x80005006))) { return(false); } else { throw COMExceptionHelper.CreateFormattedComException(unmanagedResult); } } return(true); }
private void PopulateList() { object obj2; int ex = this.entry.AdsObject.GetEx(this.propertyName, out obj2); if (ex != 0) { if ((ex != -2147463155) && (ex != -2147463162)) { throw COMExceptionHelper.CreateFormattedComException(ex); } } else if (obj2 is ICollection) { base.InnerList.AddRange((ICollection)obj2); } else { base.InnerList.Add(obj2); } }
internal void Bind(bool throwIfFail) { if (this.disposed) { throw new ObjectDisposedException(base.GetType().Name); } if (this.adsObject == null) { string path = this.Path; if ((path == null) || (path.Length == 0)) { DirectoryEntry entry = new DirectoryEntry("LDAP://RootDSE", true, null, null, AuthenticationTypes.Secure); string str2 = (string)entry.Properties["defaultNamingContext"][0]; entry.Dispose(); path = "LDAP://" + str2; } if (Thread.CurrentThread.GetApartmentState() == ApartmentState.Unknown) { Thread.CurrentThread.SetApartmentState(ApartmentState.MTA); } System.Guid iid = new System.Guid("00000000-0000-0000-c000-000000000046"); object ppObject = null; int hr = System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject(path, this.GetUsername(), this.GetPassword(), (int)this.authenticationType, ref iid, out ppObject); if (hr != 0) { if (throwIfFail) { throw COMExceptionHelper.CreateFormattedComException(hr); } } else { this.adsObject = (System.DirectoryServices.Interop.UnsafeNativeMethods.IAds)ppObject; } this.InitADsObjectOptions(); } }
public bool MoveNext() { int errorCode = 0; if (this.eof) { return(false); } this.currentResult = null; if (!this.initialized) { int firstRow = this.results.SearchObject.GetFirstRow(this.results.Handle); switch (firstRow) { case 0x5012: this.initialized = true; break; case -2147016642: throw new ArgumentException(Res.GetString("DSInvalidSearchFilter", new object[] { this.results.Filter })); default: if (firstRow != 0) { throw COMExceptionHelper.CreateFormattedComException(firstRow); } this.eof = false; this.initialized = true; return(true); } } Label_0091: this.CleanLastError(); errorCode = 0; int nextRow = this.results.SearchObject.GetNextRow(this.results.Handle); switch (nextRow) { case 0x5012: case -2147016669: if (nextRow == 0x5012) { nextRow = this.GetLastError(ref errorCode); if (nextRow != 0) { throw COMExceptionHelper.CreateFormattedComException(nextRow); } } if (errorCode != 0xea) { if (this.results.srch.directorySynchronizationSpecified) { DirectorySynchronization directorySynchronization = this.results.srch.DirectorySynchronization; } if (this.results.srch.directoryVirtualListViewSpecified) { DirectoryVirtualListView virtualListView = this.results.srch.VirtualListView; } this.results.srch.searchResult = null; this.eof = true; this.initialized = false; return(false); } if (!this.waitForResult) { uint num4 = (uint)errorCode; num4 = ((num4 & 0xffff) | 0x70000) | 0x80000000; throw COMExceptionHelper.CreateFormattedComException((int)num4); } goto Label_0091; case -2147016642: throw new ArgumentException(Res.GetString("DSInvalidSearchFilter", new object[] { this.results.Filter })); } if (nextRow != 0) { throw COMExceptionHelper.CreateFormattedComException(nextRow); } this.eof = false; return(true); }
/// <include file='doc\SearchResultCollection.uex' path='docs/doc[@for="SearchResultCollection.ResultsEnumerator.MoveNext"]/*' /> /// <devdoc> /// <para>Advances /// the enumerator to the next element of the collection /// and returns a Boolean value indicating whether a valid element is available.</para> /// </devdoc> public bool MoveNext() { DirectorySynchronization tempsync = null; DirectoryVirtualListView tempvlv = null; int errorCode = 0; if (_eof) { return(false); } _currentResult = null; if (!_initialized) { int hr = _results.SearchObject.GetFirstRow(_results.Handle); if (hr != UnsafeNativeMethods.S_ADS_NOMORE_ROWS) { //throw a clearer exception if the filter was invalid if (hr == UnsafeNativeMethods.INVALID_FILTER) { throw new ArgumentException(Res.GetString(Res.DSInvalidSearchFilter, _results.Filter)); } if (hr != 0) { throw COMExceptionHelper.CreateFormattedComException(hr); } _eof = false; _initialized = true; return(true); } _initialized = true; } while (true) { // clear the last error first CleanLastError(); errorCode = 0; int hr = _results.SearchObject.GetNextRow(_results.Handle); // SIZE_LIMIT_EXCEEDED occurs when we supply too generic filter or small SizeLimit value. if (hr == UnsafeNativeMethods.S_ADS_NOMORE_ROWS || hr == UnsafeNativeMethods.SIZE_LIMIT_EXCEEDED) { // need to make sure this is not the case that server actually still has record not returned yet if (hr == UnsafeNativeMethods.S_ADS_NOMORE_ROWS) { hr = GetLastError(ref errorCode); // get last error call failed, we need to bail out if (hr != 0) { throw COMExceptionHelper.CreateFormattedComException(hr); } } // not the case that server still has result, we are done here if (errorCode != SafeNativeMethods.ERROR_MORE_DATA) { // get the dirsync cookie as we finished all the rows if (_results.srch.directorySynchronizationSpecified) { tempsync = _results.srch.DirectorySynchronization; } // get the vlv response as we finished all the rows if (_results.srch.directoryVirtualListViewSpecified) { tempvlv = _results.srch.VirtualListView; } _results.srch.searchResult = null; _eof = true; _initialized = false; return(false); } else { // if user chooses to wait to continue the search if (_waitForResult) { continue; } else { uint temp = (uint)errorCode; temp = ((((temp) & 0x0000FFFF) | (7 << 16) | 0x80000000)); throw COMExceptionHelper.CreateFormattedComException((int)temp); } } } //throw a clearer exception if the filter was invalid if (hr == UnsafeNativeMethods.INVALID_FILTER) { throw new ArgumentException(Res.GetString(Res.DSInvalidSearchFilter, _results.Filter)); } if (hr != 0) { throw COMExceptionHelper.CreateFormattedComException(hr); } _eof = false; return(true); } }