private void PopulateLithnetSchemaStatus()
        {
            try
            {
                this.LithnetAccessManagerSchemaPresentText = "Checking...";
                this.LithnetSchemaLookupInProgress         = true;
                this.IsLithnetSchemaPresent    = false;
                this.IsNotLithnetSchemaPresent = false;

                var schema = ActiveDirectorySchema.GetSchema(new DirectoryContext(DirectoryContextType.Forest, this.Forest.Name));
                schema.FindProperty("lithnetAdminPassword");
                this.IsLithnetSchemaPresent = true;
                this.LithnetAccessManagerSchemaPresentText = "Present";
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                this.IsNotLithnetSchemaPresent             = true;
                this.LithnetAccessManagerSchemaPresentText = "Not present";
            }
            catch (Exception ex)
            {
                this.logger.LogError(EventIDs.UISchemaLookupError, ex, "Could not determine Lithnet Access Manager schema status");
                this.IsNotLithnetSchemaPresent             = true;
                this.LithnetAccessManagerSchemaPresentText = "Error looking up schema";
            }
            finally
            {
                this.LithnetSchemaLookupInProgress = false;
            }
        }
        private void PopulateMsLapsSchemaStatus()
        {
            try
            {
                this.MsLapsSchemaPresentText      = "Checking...";
                this.MsLapsSchemaLookupInProgress = true;
                this.IsMsLapsSchemaPresent        = false;
                this.IsNotMsLapsSchemaPresent     = false;

                var schema = ActiveDirectorySchema.GetSchema(new DirectoryContext(DirectoryContextType.Forest, this.Forest.Name));
                schema.FindProperty("ms-Mcs-AdmPwd");
                this.IsMsLapsSchemaPresent   = true;
                this.MsLapsSchemaPresentText = "Present";
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                this.IsNotMsLapsSchemaPresent = true;
                this.MsLapsSchemaPresentText  = "Not present";
            }
            catch (Exception ex)
            {
                this.logger.LogError(EventIDs.UISchemaLookupError, ex, "Could not determine Microsoft LAPS schema status");
                this.IsNotMsLapsSchemaPresent = true;
                this.MsLapsSchemaPresentText  = "Error looking up schema";
            }
            finally
            {
                this.MsLapsSchemaLookupInProgress = false;
            }
        }
        public void TestSchemaFilter()
        {
            // using (ActiveDirectorySchemaClass schema = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user"))
            using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(ActiveDirectoryContext))
                using (DirectoryEntry de = schema.GetDirectoryEntry())
                {
                    // by default there is no filters
                    Assert.Equal(0, de.Children.SchemaFilter.Count);

                    int topClassCount = 0;

                    foreach (DirectoryEntry child in de.Children)
                    {
                        string s = (string)child.Properties["objectClass"][0];
                        topClassCount += s.Equals("top", StringComparison.OrdinalIgnoreCase) ? 1 : 0;
                    }

                    de.Children.SchemaFilter.Add("top");
                    Assert.Equal(1, de.Children.SchemaFilter.Count);
                    Assert.True(de.Children.SchemaFilter.Contains("top"));
                    Assert.Equal(0, de.Children.SchemaFilter.IndexOf("top"));
                    Assert.Equal("top", de.Children.SchemaFilter[0]);

                    int newTopClassCount = 0;

                    foreach (DirectoryEntry child in de.Children)
                    {
                        // we expect to get top only entries
                        string s = (string)child.Properties["objectClass"][0];
                        Assert.True(s.Equals("top", StringComparison.OrdinalIgnoreCase));
                        newTopClassCount += 1;
                    }

                    Assert.Equal(topClassCount, newTopClassCount);

                    de.Children.SchemaFilter.Remove("top");
                    Assert.Equal(0, de.Children.SchemaFilter.Count);

                    de.Children.SchemaFilter.Add("top");
                    Assert.Equal(1, de.Children.SchemaFilter.Count);
                    de.Children.SchemaFilter.RemoveAt(0);
                    Assert.Equal(0, de.Children.SchemaFilter.Count);

                    de.Children.SchemaFilter.AddRange(new string [] { "top", "user" });
                    Assert.Equal(2, de.Children.SchemaFilter.Count);
                    de.Children.SchemaFilter.Insert(0, "person");
                    Assert.Equal(3, de.Children.SchemaFilter.Count);
                    Assert.Equal("person", de.Children.SchemaFilter[0]);
                    Assert.Equal("user", de.Children.SchemaFilter[2]);

                    de.Children.SchemaFilter.Clear();
                    Assert.Equal(0, de.Children.SchemaFilter.Count);
                }
        }
        public void TestSchema()
        {
            using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(ActiveDirectoryContext))
            {
                Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user")));
                Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "samDomainBase")));
                Assert.NotNull(schema.FindAllDefunctClasses());
                Assert.NotNull(schema.FindAllDefunctProperties());
                Assert.True(schema.FindAllProperties(PropertyTypes.Indexed).Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "ou")));
                Assert.True(schema.FindAllProperties().Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "cn")));
                Assert.Equal("person", schema.FindClass("person").Name);
                Assert.Equal("cn", schema.FindProperty("cn").Name);

                using (DirectoryEntry de = schema.GetDirectoryEntry())
                {
                    Assert.True("CN=Schema".Equals(de.Name, StringComparison.OrdinalIgnoreCase));
                }
            }
        }
Esempio n. 5
0
        public List <String> GetAllADUserProperties(string domain) //"dcs.azdcs.gov"
        {
            List <String> properties = new List <String>();

            IPAddress[] ips = Dns.GetHostAddresses(domain).Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray();
            if (ips.Length > 0)
            {
                DirectoryContext           directoryContext = new DirectoryContext(DirectoryContextType.Forest);//DirectoryContextType.DirectoryServer, ips[0].ToString() + ":389", Username, Password);
                ActiveDirectorySchema      adschema         = ActiveDirectorySchema.GetSchema(directoryContext);
                ActiveDirectorySchemaClass adschemaclass    = adschema.FindClass("User");

                // Read the OptionalProperties & MandatoryProperties
                ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();

                foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)
                {
                    properties.Add(schemaProperty.Name.ToLower());
                }
            }

            return(properties);
        }
Esempio n. 6
0
        private ReadUserResponse GetUserInfo(Principal up)
        {
            using (var o = (DirectoryEntry)up.GetUnderlyingObject())
            {
                //Lekérdezem az összes attributumot, azt is, amit
                //nem töltöttek még ki. Erre azért van szükség, mert
                //ha nincs kitöltve egy attributum, akkor nem nem kapok
                //róla vissza adatot
                var adschema      = ActiveDirectorySchema.GetSchema(directoryContext);
                var adschemaclass = adschema.FindClass(GlobalStrings.User);
                var allAttributes = adschemaclass.GetAllProperties();

                //jogosultság lista lekérése, majd az attributumok erre a listára szűrése
                o.RefreshCache(new string[] { GlobalStrings.AllowedAttributesEffective });
                //ide jön az írható attributumok listája
                var writableProperties = new List <string>();
                foreach (ActiveDirectorySchemaProperty item in allAttributes)
                {
                    if (o.Properties[GlobalStrings.AllowedAttributesEffective].Contains(item.Name))
                    {
                        writableProperties.Add(item.Name);
                    }
                }

                //és ezek az adatok kellenek nekünk
                var user = new ReadUserResponse
                {
                    DisplayName       = up.DisplayName,
                    Description       = up.Description,
                    DistinguishedName = up.DistinguishedName,
                    Name = up.Name,
                    Sid  = up.Sid,
                    UserPrincipalName = up.UserPrincipalName,
                    SamAccountName    = up.SamAccountName,
                };

                //az előbb a cache-t leszűkítettem az allowedAttributesEffective
                //attributumra, mert máshogy nem tudtam betölteni. Így viszont újra kell
                //a cache-t frissíteni
                o.RefreshCache();
                var fields = o.Properties;

                foreach (string fieldName in writableProperties)
                {
                    var list = new List <AdhrValue>();
                    if (fields[fieldName].Value != null)
                    {
                        foreach (var item in fields[fieldName])
                        {
                            list.Add(new AdhrValue(item.ToString()));
                        }
                    }
                    else
                    {
                        list.Add(new AdhrValue(null));
                    }
                    user.Properties.Add(fieldName, new ReadOnlyCollection <AdhrValue>(list));
                }

                return(user);
            }
        }
Esempio n. 7
0
        public void buttonRunQuery_Click(object sender, EventArgs e)
        {
            Setup  setup      = new Setup();
            String OldOraHome = Environment.GetEnvironmentVariable("ORACLE_HOME");

            if (!String.IsNullOrEmpty(setup.textBoxOraHome.Text))
            {
                Environment.SetEnvironmentVariable("ORACLE_HOME", setup.textBoxOraHome.Text);
            }
            OracleConnection conn = new OracleConnection(setup.ConnectionStringOracle);

            try
            {
                conn.Open();
                OracleCommand cmd = new OracleCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "SELECT column_name FROM all_tab_columns WHERE upper(table_name) = upper('" +
                                  setup.textBoxOraView.Text + "') ORDER BY column_name ASC";
                cmd.CommandType = CommandType.Text;
                OracleDataReader dr = cmd.ExecuteReader();
                m_Fields.Clear();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        try
                        {
                            m_Fields.Add(dr[0].ToString());
                        }
                        catch
                        {
                        }
                    }
                }

                m_Fields.Add("*BRANCO*");
                m_Fields.Sort();
                dr.Close();
                conn.Dispose();
                dataGridView.Rows.Clear();
                DataGridViewComboBoxColumn column = dataGridView.Columns["CampoOrigem"] as DataGridViewComboBoxColumn;
                if (column != null)
                {
                    column.DataSource = m_Fields;
                }

                List <String> properties = new List <String>();
                properties.Clear();
                IPAddress[] ips =
                    Dns.GetHostAddresses(setup.textBoxLdapServer.Text)
                    .Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    .ToArray();
                if (ips.Length > 0)
                {
                    DirectoryContext directoryContext = new DirectoryContext(DirectoryContextType.DirectoryServer,
                                                                             ips[0].ToString() + ":389", setup.textBoxLdapUsername.Text, setup.textBoxLdapPassword.Text);
                    ActiveDirectorySchema      adschema      = ActiveDirectorySchema.GetSchema(directoryContext);
                    ActiveDirectorySchemaClass adschemaclass = adschema.FindClass("User");

                    // Read the OptionalProperties & MandatoryProperties
                    ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();

                    foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)
                    {
                        properties.Add(schemaProperty.Name.ToLower());
                    }
                }
                DataGridViewComboBoxColumn column2 = dataGridView.Columns["CampoDestino"] as DataGridViewComboBoxColumn;
                if (column2 != null)
                {
                    column2.DataSource = properties;
                }

                try
                {
                    FileInfo file = new FileInfo(Path.Combine(Application.StartupPath, "DePara.xml"));
                    if (file.Exists)
                    {
                        Dictionary <Int32, Dictionary <String, String> > data =
                            new Dictionary <int, Dictionary <string, string> >();
                        XmlReader xr = XmlReader.Create(file.FullName);
                        xr.MoveToContent();
                        while (xr.Read())
                        {
                            Dictionary <String, String> attributes = new Dictionary <string, string>();
                            while (xr.MoveToNextAttribute())
                            {
                                if (xr.Name != "CampoOrigem" && xr.Name != "CampoDestino")
                                {
                                    continue;
                                }
                                attributes.Add(xr.Name, xr.Value);
                            }
                            if (attributes.Count > 0)
                            {
                                data.Add(data.Count, attributes);
                            }
                        }
                        xr.Close();
                        foreach (KeyValuePair <Int32, Dictionary <String, String> > kp in data)
                        {
                            dataGridView.Rows.Add(kp.Value["CampoOrigem"], kp.Value["CampoDestino"]);
                        }
                    }
                }
                catch
                {
                }
            }
            catch (Exception exc)
            {
                try
                {
                    MessageBox.Show(exc.Message, "Erro ao conectar com o BD", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch
                {
                }
            }
            if (!String.IsNullOrEmpty(setup.textBoxOraHome.Text))
            {
                Environment.SetEnvironmentVariable("ORACLE_HOME", OldOraHome);
            }
        }
Esempio n. 8
0
        public static void GetSchemaData()
        {
            Console.WriteLine("<--SCHEMA Information-->\n");

            ActiveDirectorySchema schema;

            try
            {
                // bind to the schema associated with the ADAM instance
                schema = ActiveDirectorySchema.GetSchema(adamContext);
            }
            catch (ActiveDirectoryObjectNotFoundException e)
            {
                // current context could not be obtained
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("Current schema: {0}", schema);

            // get all class names
            Console.WriteLine("\nAll schema classes:");
            foreach (ActiveDirectorySchemaClass schemaClass in
                     schema.FindAllClasses())
            {
                Console.WriteLine("Common name: {0}\n\tlDAPDisplayName: {1}",
                                  schemaClass.CommonName, schemaClass.Name);
            }


            // get all the abstract classes in the schema
            Console.WriteLine("\nAll abstract schema classes:");
            foreach (ActiveDirectorySchemaClass schemaClass in
                     schema.FindAllClasses(SchemaClassType.Abstract))
            {
                Console.WriteLine(schemaClass);
            }

            // get all the defunct classes in the schema
            // This searches for all classes with the isDefunct attribute set to True
            // You cannot instantiate a defunct class. Since you cannot delete an
            // attribute, setting an attribute to defunct is the next best thing.
            // By default, an ADAM instance doesn't contain any defunct classes.
            Console.WriteLine("\nAll defunct schema classes:");
            foreach (ActiveDirectorySchemaClass schemaClass in
                     schema.FindAllDefunctClasses())
            {
                Console.WriteLine(schemaClass);
            }

            Console.WriteLine("\nAll defunct schema attributes:");

            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schema.FindAllDefunctProperties())
            {
                Console.WriteLine(schemaProperty);
            }

            Console.WriteLine("\nIndexed attributes:");

            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schema.FindAllProperties(
                         PropertyTypes.Indexed))
            {
                Console.WriteLine(schemaProperty);
            }
        }