// public DsPicker(DialogType dt,string sProtocal,string targetServer,string sDCs,bool allowMultiSelect):this() public void SetData(DialogType dt, string sProtocal, string targetServer, string sDCs, bool allowMultiSelect) { if (timer.Enabled) { timer.Start(); } else { timer.Enabled = true; timer.Start(); } lvUserToGroup.MultiSelect = allowMultiSelect; // if no server specified, try to synthesize it from the dc's if (targetServer == null && sDCs != null) { targetServer = SDSUtils.DNToDomainName(sDCs); } sDomainName = SDSUtils.DNToDomainName(sDCs); string sPath = SDSUtils.MakePath(sProtocal, targetServer, null, sDCs); de = new DirectoryEntry(sPath); deList = new Dictionary <string, DirectoryEntry>(); this.dt = dt; try { waitForm = new WaitForm(backgroundWorker, timer, de); backgroundWorker.RunWorkerAsync(null); //System.Threading.Thread.Sleep(1000); if (waitForm != null) { waitForm.ShowDialog(this); } //this.lvUserToGroup.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Likewise Administrator Console", MessageBoxButtons.OK); } this.CancelBtn.Enabled = true; lvUserToGroup.Enabled = true; lvUserToGroup.Sort(); }
private void FindParentDomain() { DirectoryEntry rootDse = new DirectoryEntry(string.Format("LDAP://{0}/RootDSE", dName), dc.UserName, dc.Password); string configureName = rootDse.DirContext.ConfigurationNamingContext; if (configureName == null || configureName == "") { parent = null; return; } DirectoryEntry sys = new DirectoryEntry(string.Format("LDAP://{0}/CN=Partitions,{1}", SDSUtils.DNToDomainName(configureName), configureName), dc.UserName, dc.Password); DirectorySearcher ds = new DirectorySearcher(sys); ds.Filter = "(objectClass=crossRef)"; ds.SearchScope = SearchScope.OneLevel; SearchResultCollection src = ds.FindAll(); if (src != null && src.Count > 0) { foreach (SearchResult sr in src) { string sProtocol, sServer, sCNs, sDCs; SDSUtils.CrackPath(sr.Path, out sProtocol, out sServer, out sCNs, out sDCs); DirectoryEntry partEntry = new DirectoryEntry(sr.Path, dc.UserName, dc.Password); string partName = partEntry.Properties["nCName"].Value as string; if (dName.Equals(SDSUtils.DNToDomainName(partName), StringComparison.InvariantCultureIgnoreCase)) { string parentDomainDN = partEntry.Properties["trustParent"].Value as string; if (parentDomainDN != null && parentDomainDN != "") { parent = new Domain(SDSUtils.DNToDomainName(parentDomainDN)); break; } } } } return; }
public TrustRelationshipInformationCollection GetAllTrustRelationships() { if (trustCollection == null) { try { DirectoryEntry rootDse = new DirectoryEntry(string.Format("LDAP://{0}/RootDSE", dName), dc.UserName, dc.Password); string defaultName = rootDse.DirContext.DefaultNamingContext; if (defaultName == null || defaultName == "") { trustCollection = null; return(trustCollection); } DirectoryEntry sys = new DirectoryEntry(string.Format("LDAP://{0}/CN=System,{1}", SDSUtils.DNToDomainName(defaultName), defaultName), dc.UserName, dc.Password); DirectorySearcher ds = new DirectorySearcher(sys); ds.Filter = "(objectClass=trustedDomain)"; ds.SearchScope = SearchScope.Subtree; SearchResultCollection src = ds.FindAll(); if (src != null && src.Count > 0) { trustCollection = new TrustRelationshipInformationCollection(); foreach (SearchResult sr in src) { string sProtocol, sServer, sCNs, sDCs; SDSUtils.CrackPath(sr.Path, out sProtocol, out sServer, out sCNs, out sDCs); /*Console.WriteLine("sProtocol " + sProtocol); * Console.WriteLine("sServer " + sServer); * Console.WriteLine("sCNs " + sCNs); * Console.WriteLine("sDCs " + sDCs);*/ string sourcename, targetname; TrustDirection trustdirection; TrustType trusttype = TrustType.Unknown; DirectoryEntry trustEntry = new DirectoryEntry(sr.Path, dc.UserName, dc.Password); int trustdir = (int)trustEntry.Properties["trustDirection"].Value; string trustDn = trustEntry.Properties["distinguishedName"].Value.ToString(); string[] splits = trustDn.Split(','); trustDn = splits[0].Substring(3); int trustattr = (int)trustEntry.Properties["trustAttributes"].Value; int trusttp = (int)trustEntry.Properties["trustType"].Value; //Note:the following implementation of how to determine the TrustType is still under investigation if (trusttp == (int)ADTrustType.TYPE_UPLEVEL) //windows 2003 trust { switch (trustattr) { case 0: trusttype = TrustType.External; //this trust is non-transitive break; case 1: //ATTRIBUTES_NON_TRANSITIVE break; case 2: //ATTRIBUTES_UPLEVEL_ONLY break; case 4: //ATTRIBUTES_QUARANTINED_DOMAIN trusttype = TrustType.External; break; case 8: //ATTRIBUTES_FOREST_TRANSITIVE trusttype = TrustType.Forest; //and this trust is transitive break; case 16: //ATTRIBUTES_CROSS_ORGANIZATION trusttype = TrustType.CrossLink; break; case 32: //ATTRIBUTES_WITHIN_FOREST if (trustDn.ToLower().Contains(dName.ToLower())) { trusttype = TrustType.ParentChild; } else { trusttype = TrustType.External; //this trust is non-transitive } break; case 64: //ATTRIBUTES_TREAT_AS_EXTERNAL trusttype = TrustType.External; break; default: trusttype = TrustType.Unknown; break; } } else if (trusttp == (int)ADTrustType.TYPE_MIT) { trusttype = TrustType.Kerberos; } switch (trustdir) { case 1: trustdirection = TrustDirection.Inbound; sourcename = dName; targetname = trustDn; break; case 2: trustdirection = TrustDirection.Outbound; sourcename = trustDn; targetname = dName; break; case 3: trustdirection = TrustDirection.Bidirectional; sourcename = dName; targetname = trustDn; break; default: trustdirection = TrustDirection.Disabled; sourcename = targetname = ""; break; } TrustRelationshipInformation trustinfo = new TrustRelationshipInformation(sourcename, targetname, trusttype, trustdirection); trustCollection.Add(trustinfo); } } } catch { return(null); } } return(trustCollection); }