Пример #1
0
        public Unlocker()
        {
            InitializeComponent();
            this.Text += " v" + AuditSec.curver;
            AuditSec.Speak("Welcome to A.D. account unlocker.", false, false, AuditSec.TTSReplace);


            Console.WriteLine("Opening domain... ");
            try
            {
                DomainCollection dc      = Forest.GetCurrentForest().Domains;
                Domain[]         domains = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                domainBox.Items.AddRange(domains);

                domainBox.Text = Domain.GetCurrentDomain().Name;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }


            string me = new DirectorySearcher("(&(ObjectClass=user)(sAMAccountName="
                                              + UserPrincipal.Current.SamAccountName + "))")
                        .FindOne().GetDirectoryEntry().Properties["DistinguishedName"].Value.ToString();

            foreach (string s in me.Split(',').Reverse())
            {
                string[] t = s.Split(new char[] { '=' }, 2);
                if (t[0].Equals("OU"))
                {
                    OUBox.Text = t[1]; break;
                }
            }

            Console.WriteLine("Setting masks... ");
            if (AuditSec.settings.oumask != null && AuditSec.settings.oumask.Length > 0)
            {
                OUMaskBox.Text = AuditSec.settings.oumask;
            }
            sm0 = OUMaskBox.Text;

            speakWorker.RunWorkerAsync();
            actionsWorker.RunWorkerAsync();
            new Thread(new ThreadStart(delegate
            {
                Thread.Sleep(1000);

//                Console.WriteLine("Loading configuration files... ");

                Invoke(new picpwDelegate(setpicpw));

                Invoke(new welcomeButtonDelegate(welcomeButtonPerformClick));
            })).Start();
        }
Пример #2
0
        private void Reenabler_Load(object sender, EventArgs e)
        {
            //Console.WriteLine("form load");
            domainBox.Items.Clear();

            if (parent != null)
            {
                domainBox.Items.Add(parent.domainBox.SelectedItem);
                domainBox.SelectedItem = parent.domainBox.SelectedItem;
            }
            else
            {
                try
                {
                    DomainCollection dc      = Forest.GetCurrentForest().Domains;
                    Domain[]         domains = new Domain[dc.Count]; dc.CopyTo(domains, 0);
                    domainBox.Items.AddRange(domains);
                    domainBox.Text = Domain.GetCurrentDomain().Name;
                }
                catch (Exception ee)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            if (targetDomain != null)
            {
                domainBox.Text = targetDomain;
            }

            OUBox.Items.Clear();
            if (parent != null)
            {
                OUBox.Items.AddRange(parent.OUBox.Items.OfType <string>().ToList().ToArray <string>());
                startBox.Text = OUBox.Text = parent.OUBox.Text;
            }
            else
            {
                string           domain  = domainBox.SelectedItem.ToString();
                DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain);
                Domain           d       = Domain.GetDomain(context);
                DirectoryEntry   de      = d.GetDirectoryEntry();

                DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=organizationalUnit)", null, SearchScope.OneLevel);
                ds.PropertiesToLoad.Add("name");

                foreach (SearchResult r in ds.FindAll())
                {
                    string ou    = r.Properties["name"][0].ToString();
                    bool   match = false; try
                    {
                        match = System.Text.RegularExpressions.Regex.IsMatch(ou, AuditSec.defaultOUMask,
                                                                             System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("OU=" + ou + " IsMatch Regex=" + AuditSec.defaultOUMask + " = " + ee.Message);
                    }
                    if (match)
                    {
                        OUBox.Items.Add(ou);
                    }
                    //Console.WriteLine("OU=" + ou + " IsMatch Regex=" + OUMaskBox.Text + " = " + match);
                }

                string me = new DirectorySearcher("(&(ObjectClass=user)(sAMAccountName="
                                                  + UserPrincipal.Current.SamAccountName + "))")
                            .FindOne().GetDirectoryEntry().Properties["DistinguishedName"].Value.ToString();
                foreach (string s in me.Split(',').Reverse())
                {
                    string[] t = s.Split(new char[] { '=' }, 2);
                    if (t[0].Equals("OU"))
                    {
                        OUBox.Text = t[1]; break;
                    }
                }
            }

            OUBox_SelectionChangeCommitted(sender, e);
            change = true;
            timer1_Tick(sender, e);

            if (targetMachine != null)
            {
                OUBox.SelectedItem = null; OUBox.Text = "";
                startBox.Text      = targetMachine;
            }
        }