Exemplo n.º 1
0
        internal static void SetAvailabilityAces(SecurityIdentifier exchangeServersSid, AvailabilityConfig availabilityConfig, Task.TaskVerboseLoggingDelegate verboseLogger)
        {
            Guid schemaGuid;

            using (ActiveDirectorySchema currentSchema = ActiveDirectorySchema.GetCurrentSchema())
            {
                using (ActiveDirectorySchemaClass activeDirectorySchemaClass = currentSchema.FindClass("msExchAvailabilityAddressSpace"))
                {
                    schemaGuid = activeDirectorySchemaClass.SchemaGuid;
                }
            }
            Guid schemaGuid2;

            using (ActiveDirectorySchema currentSchema2 = ActiveDirectorySchema.GetCurrentSchema())
            {
                using (ActiveDirectorySchemaProperty activeDirectorySchemaProperty = currentSchema2.FindProperty("msExchAvailabilityUserPassword"))
                {
                    schemaGuid2 = activeDirectorySchemaProperty.SchemaGuid;
                }
            }
            DirectoryCommon.SetAces(verboseLogger, null, availabilityConfig, new List <ActiveDirectoryAccessRule>
            {
                new ActiveDirectoryAccessRule(exchangeServersSid, ActiveDirectoryRights.ReadProperty, AccessControlType.Allow, schemaGuid2, ActiveDirectorySecurityInheritance.Descendents, schemaGuid)
            }.ToArray());
        }
 public void TestForestSchema()
 {
     using (Forest forest = Forest.GetForest(ActiveDirectoryContext))
     {
         using (ActiveDirectorySchema schema = forest.Schema)
             using (ActiveDirectorySchemaClass adsc = schema.FindClass("top"))
             {
                 Assert.True("top".Equals(adsc.CommonName, StringComparison.OrdinalIgnoreCase));
             }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the AD ObjectClass associated with a particular
        /// Connector ObjectClass
        /// </summary>
        /// <param name="oclass"></param>
        /// <returns></returns>
        internal String GetADObjectClass(ObjectClass oclass)
        {
            if (oclass.Equals(ObjectClass.ACCOUNT))
            {
                return(_configuration.ObjectClass);
            }
            else if (ActiveDirectoryConnector.groupObjectClass.Equals(oclass))
            {
                return("Group");
            }
            else if (ActiveDirectoryConnector.ouObjectClass.Equals(oclass))
            {
                return("organizationalUnit");
            }
            else
            {
                // It's not something I know about, so I'll consult the AD schema.
                // if it's there, fine, but if not throw an exception.

                //first check to see if we have seen it before.
                String objectClassName = oclass.GetObjectClassValue();
                if (_knownObjectClasses.Contains(objectClassName))
                {
                    return(objectClassName);
                }

                // if we havent seen it before, consult AD's schema
                ActiveDirectorySchema      ADSchema      = GetADSchema();
                ActiveDirectorySchemaClass ADSchemaClass = null;
                try
                {
                    ADSchemaClass = ADSchema.FindClass(objectClassName);
                    _knownObjectClasses.Add(objectClassName);
                    return(objectClassName);
                }
                catch (ActiveDirectoryObjectNotFoundException exception)
                {
                    String msg = _configuration.ConnectorMessages.Format(
                        "ex_ObjectClassInvalidForConnector",
                        "ObjectClass \'{0}\' is not valid for this connector",
                        objectClassName);
                    throw new ConnectorException(msg);
                }
            }
        }
        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));
                }
            }
        }
Exemplo n.º 5
0
 private static SchemaClass GetSchemaClass(string className)
 {
     if (!schemaClassCache.TryGetValue(className, out SchemaClass schemaClass))
     {
         using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetCurrentSchema())
         {
             ActiveDirectorySchemaClass result = schema.FindClass(className);
             System.DirectoryServices.DirectoryEntry directoryEntry = result.GetDirectoryEntry();
             schemaClass = new SchemaClass()
             {
                 LdapDisplayName   = result.Name,
                 SchemaGuid        = result.SchemaGuid,
                 DistinguishedName = (string)directoryEntry.Properties["distinguishedName"][0]
             };
             schemaClassCache.Add(result.Name, schemaClass);
         }
     }
     return(schemaClass);
 }
        static void Main(string[] args)
        {
            DirectorySearcher          deSearch   = new DirectorySearcher();
            ActiveDirectorySchema      currSchema = ActiveDirectorySchema.GetCurrentSchema();
            ActiveDirectorySchemaClass collection = currSchema.FindClass("user");
            ReadOnlyActiveDirectorySchemaPropertyCollection properties = collection.GetAllProperties();
            IEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                try
                {
                    deSearch.PropertiesToLoad.Add(enumerator.Current.ToString());
                }
                catch (Exception ex)
                {
                    // MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
            }
        }