private void SendPath(bool selectPath = true, bool queryGui = false) { IsHidden = false; string path = this.tvLdap.SelectedNode.Name; switch (Caller) { case CALLING_CONTROL.GUI_BASE: ADObjectInfo objectinfo = (ADObjectInfo)this.tvLdap.SelectedNode.Tag; GlobalEventHandler.RaiseGuiBaseObjectSelected(objectinfo, queryGui); break; case CALLING_CONTROL.GUI_ASQ: GlobalEventHandler.RaiseGuiAsqPathSelected(path); break; case CALLING_CONTROL.WIZARD: GlobalEventHandler.RaiseWizardPathSelected(path); break; default: break; } if (selectPath) { IsHidden = true; this.Hide(); } }
public void ShowTree(CALLING_CONTROL whoCalled, QueryControl mustQuery, string entryPoint = null, string dcName = null, ForestInfo fiH = null) { bool mustreload = false; Caller = whoCalled; if (entryPoint != null) { mustreload = FindNode(entryPoint); } if (QueryCtrl.ShowDeleted != mustQuery.ShowDeleted) { mustreload = true; } QueryCtrl.ShowDeleted = mustQuery.ShowDeleted; if (QueryCtrl.ShowRecycled != mustQuery.ShowRecycled) { mustreload = true; } QueryCtrl.ShowRecycled = mustQuery.ShowRecycled; if (QueryCtrl.Port != mustQuery.Port) { mustreload = true; } QueryCtrl.Port = mustQuery.Port; if (dcName != null) { DC = dcName; } if (fiH != null) { ThisForestInfo = fiH; } TreeNode parent = null; if (mustreload) { ADObjectInfo oinfo = new ADObjectInfo() { Name = entryPoint, Path = entryPoint, ObjectClass = "nc" }; mustreload = AddEntry(ref parent, oinfo); } this.Show(); if (mustreload) { ExpandNode(parent); } this.tvLdap.Sort(); }
public static void RaiseGuiBaseObjectSelected(ADObjectInfo objectInfo, bool queryGui) { if (GuiBaseObjectSelected != null) { GuiBaseObjectSelected(objectInfo, new GlobalEventArgs() { BoolVal = new bool[] { queryGui } }); } }
private bool AddEntry(ref TreeNode parentNode, ADObjectInfo objectInfo) { bool ret = true; TreeNode child = new TreeNode(); child.Name = objectInfo.Path; child.Text = objectInfo.Name; child.ImageIndex = (int)GetImageIndex(objectInfo.ObjectClass); child.SelectedImageIndex = child.ImageIndex; child.Tag = objectInfo; if (parentNode == null) { if (this.tvLdap.Nodes.ContainsKey(objectInfo.Path)) { ret = false; } else { this.tvLdap.Nodes.Add(child); parentNode = child; } } else { parentNode.Nodes.Add(child); ((ADObjectInfo)parentNode.Tag).Tag = true; } return(ret); }
public bool RestoreObject(string dc, ADObjectInfo objectInfo, QueryControl queryInfo) { bool ret = false; ForestBase.CurrentPorts.SelectedPort = queryInfo.Port; Connect(dc, ReferralChasingOptions.None); DirectoryAttributeModification damdel = new DirectoryAttributeModification() { Name = "isDeleted", Operation = DirectoryAttributeOperation.Delete }; string newdn = (objectInfo.ObjectClass.ToLowerInvariant() == "organizationalunit") ? "OU=" : "CN="; newdn = newdn + objectInfo.LastKnownRDN.ToEscapedLdapComponent() + ","; newdn = newdn + objectInfo.LastKnownParent; GlobalEventHandler.RaiseMessageOccured("Restoring:", true); GlobalEventHandler.RaiseMessageOccured("\t" + objectInfo.Path, true); GlobalEventHandler.RaiseMessageOccured("to:", true); GlobalEventHandler.RaiseMessageOccured("\t" + newdn, true); DirectoryAttributeModification damdn = new DirectoryAttributeModification() { Name = "distinguishedName", Operation = DirectoryAttributeOperation.Replace }; damdn.Add(newdn); DirectoryAttributeModification[] damlist = new DirectoryAttributeModification[] { damdel, damdn }; string delpath = String.Format("<GUID={0}>", objectInfo.ObjectGuid); delpath = objectInfo.Path; ModifyRequest mrcall = new ModifyRequest(delpath, damlist); mrcall.Controls.Add(new ShowDeletedControl { ServerSide = true }); mrcall.Controls.Add(new PermissiveModifyControl()); try { ModifyResponse mrresult = (ModifyResponse)base.Connection.SendRequest(mrcall); if (mrresult.ResultCode == ResultCode.Success) { GlobalEventHandler.RaiseMessageOccured("Restored " + objectInfo.LastKnownRDN, true); ret = true; } else { GlobalEventHandler.RaiseErrorOccured("ERROR: " + mrresult.ResultCode.ToString(), true); } } catch (DirectoryOperationException doex) { GlobalEventHandler.RaiseErrorOccured("ERROR: " + doex.Message, true); } catch (Exception ex) { GlobalEventHandler.RaiseErrorOccured("ERROR: " + ex.Message, true); } return(ret); }
private void WalkSubs(TreeNode parentNode) { GlobalControlHandler.UpdateLabel(this.lbProcess, "walking children"); this.Cursor = Cursors.WaitCursor; bool isbad; DirectoryAttribute dat; string[] attribs = new string[] { "ou", "cn", "distinguishedName", "objectClass", "objectGUID", "lastKnownParent", "msDS-LastKnownRDN", "isDeleted", "isRecycled" }; List <SearchResultEntry> result = ThisForestInfo.Query(DC, parentNode.Name, "(objectClass=*)", attribs, SearchScope.OneLevel, ReferralChasingOptions.None, QueryCtrl, returnResults: true); if (ThisForestInfo.HasError) { GlobalControlHandler.UpdateLabel(this.lbProcess, "Failed: walking children: " + ThisForestInfo.ErrorMSG); } else { GlobalControlHandler.UpdateLabel(this.lbProcess, "Found " + result.Count); long cnt = 0; long step = 100; bool storedecodeguid = MainBase.UserSettings.DecodeGUID; MainBase.UserSettings.DecodeGUID = true; foreach (SearchResultEntry res in result) { ADObjectInfo oinfo = new ADObjectInfo(); cnt++; if (cnt == step) { GlobalControlHandler.UpdateLabel(this.lbProcess, String.Format("Found {0} (walked {1})", result.Count, cnt)); step += 100; } string nodename = String.Empty; string nodepath = String.Empty; string objectclass = OBJECT_TYPES.DEFAULT.ToString(); int successcount = 0; if (res.Attributes.Contains("ou")) { dat = res.Attributes["ou"]; oinfo.Name = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.CaseIgnoreString, out isbad, true)[0]; successcount = 1; } else if (res.Attributes.Contains("cn")) { dat = res.Attributes["cn"]; oinfo.Name = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.CaseIgnoreString, out isbad, true)[0]; successcount = 1; } if (res.Attributes.Contains("distinguishedName")) { dat = res.Attributes["distinguishedName"]; oinfo.Path = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.DN, out isbad, true)[0]; if (nodename.Length == 0) { nodename = nodepath; } successcount++; } if (res.Attributes.Contains("objectClass")) { dat = res.Attributes["objectClass"]; List <string> ocl = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.DirectoryString, out isbad, true); oinfo.ObjectClass = ocl[ocl.Count - 1]; } if (res.Attributes.Contains("objectGuid")) { dat = res.Attributes["objectGuid"]; List <string> guidl = ThisForestInfo.DecodeByteData(dat, ActiveDirectorySyntax.OctetString, out isbad, false, true); oinfo.ObjectGuid = guidl[0]; } if (res.Attributes.Contains("lastKnownParent")) { dat = res.Attributes["lastKnownParent"]; oinfo.LastKnownParent = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.DN, out isbad, true)[0]; } if (res.Attributes.Contains("msDS-LastKnownRDN")) { dat = res.Attributes["msDS-LastKnownRDN"]; oinfo.LastKnownRDN = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.DirectoryString, out isbad, true)[0]; } if (res.Attributes.Contains("isDeleted")) { dat = res.Attributes["isDeleted"]; string temp = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.Bool, out isbad, true)[0]; bool btmp = false; Boolean.TryParse(temp, out btmp); oinfo.IsDeleted = btmp; } if (res.Attributes.Contains("isRecycled")) { dat = res.Attributes["isRecycled"]; string temp = ThisForestInfo.DecodeStringData(dat, ActiveDirectorySyntax.Bool, out isbad, true)[0]; bool btmp = false; Boolean.TryParse(temp, out btmp); oinfo.IsRecycled = btmp; } if (successcount == 2) { AddEntry(ref parentNode, oinfo); } } MainBase.UserSettings.DecodeGUID = storedecodeguid; GlobalControlHandler.UpdateLabel(this.lbProcess, visible: false); } this.Cursor = Cursors.Default; }