Ejemplo n.º 1
0
        /// <summary>Gets a list of requried attributes for a given object class.
        /// </summary>
        /// <param name="objClass">Name of object class</param>
        /// <returns>An array of required attribute names</returns>
        public string[] GetRequiredAttrs(string objClass)
        {
            if (objClass == null)
            {
                return(null);
            }

            LdapSchema            schema = server.GetSchema();
            LdapObjectClassSchema ocs    = schema.getObjectClassSchema(objClass);

            if (ocs != null)
            {
                return(ocs.RequiredAttributes);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>Gets a list of required and optional attributes for
        /// the given object classes.
        /// </summary>
        /// <param name="objClass">List of object classes</param>
        /// <param name="required">Required attributes</param>
        /// <param name="optional">Optional attributes</param>
        public void GetAllAttributes(List <string> objClass, out string[] required, out string[] optional)
        {
            try {
                LdapSchema            schema = server.GetSchema();
                LdapObjectClassSchema ocs;

                List <string> r_attrs = new List <string> ();
                List <string> o_attrs = new List <string> ();

                foreach (string c in objClass)
                {
                    ocs = schema.getObjectClassSchema(c);

                    if (ocs.RequiredAttributes != null)
                    {
                        foreach (string r in ocs.RequiredAttributes)
                        {
                            if (!r_attrs.Contains(r))
                            {
                                r_attrs.Add(r);
                            }
                        }
                    }

                    if (ocs.OptionalAttributes != null)
                    {
                        foreach (string o in ocs.OptionalAttributes)
                        {
                            if (!o_attrs.Contains(o))
                            {
                                o_attrs.Add(o);
                            }
                        }
                    }
                }

                required = r_attrs.ToArray();
                optional = o_attrs.ToArray();
            } catch (Exception e) {
                required = null;
                optional = null;

                Log.Debug(e);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Gets a list of all attributes for the given object class
        /// </summary>
        /// <param name="objClass">Name of object class</param>
        public string[] GetAllAttributes(string objClass)
        {
            try {
                LdapSchema            schema = server.GetSchema();
                LdapObjectClassSchema ocs    = schema.getObjectClassSchema(objClass);

                List <string> attrs = new List <string> ();

                if (ocs.RequiredAttributes != null)
                {
                    foreach (string r in ocs.RequiredAttributes)
                    {
                        if (!attrs.Contains(r))
                        {
                            attrs.Add(r);
                        }
                    }
                }

                if (ocs.OptionalAttributes != null)
                {
                    foreach (string o in ocs.OptionalAttributes)
                    {
                        if (!attrs.Contains(o))
                        {
                            attrs.Add(o);
                        }
                    }
                }

                attrs.Sort();
                return(attrs.ToArray());
            } catch (Exception e) {
                Log.Debug(e);
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>Gets a list of requried attributes for a list of given
        /// object classes.
        /// </summary>
        /// <param name="objClasses">Array of objectclass names</param>
        /// <returns>An array of required attribute names</returns>
        public string[] GetRequiredAttrs(string[] objClasses)
        {
            if (objClasses == null)
            {
                return(null);
            }

            List <string> retVal = new List <string> ();
            LdapSchema    schema = server.GetSchema();

            foreach (string oc in objClasses)
            {
                LdapObjectClassSchema ocs = schema.getObjectClassSchema(oc);
                foreach (string c in ocs.RequiredAttributes)
                {
                    if (!retVal.Contains(c))
                    {
                        retVal.Add(c);
                    }
                }
            }

            return(retVal.ToArray());
        }
Ejemplo n.º 5
0
 public static void Connect(this ILdapConnection connection, string hostname, int port,
                            LdapSchema ldapSchema = LdapSchema.LDAP,
                            LdapVersion version   = LdapVersion.LDAP_VERSION3)
 {
     connection.Connect(new Uri($"{ldapSchema.ToString()}://{hostname}:{port}"), version);
 }
        public static void MainTest(string[] args)
        {
            if (args.Length != 6)
            {
                Console.WriteLine("Usage:   mono GetAttributeSchema <host name> <ldap port>  <login dn>" + " <password> <search base>" + " <search filter>");
                Console.WriteLine("Example: mono GetAttributeSchema Acme.com 389" + " \"cn=admin,o=Acme\"" + " secret \"ou=sales,o=Acme\"" + "         \"(objectclass=*)\"");
                return;
            }
            string ldapHost     = args[0];
            int    ldapPort     = System.Convert.ToInt32(args[1]);
            String loginDN      = args[2];
            String password     = args[3];
            String searchBase   = args[4];
            String searchFilter = args[5];

            try
            {
                LdapConnection conn = new LdapConnection();
                Console.WriteLine("Connecting to:" + ldapHost);
                conn.Connect(ldapHost, ldapPort);
                conn.Bind(loginDN, password);
                LdapSchema        dirschema = conn.FetchSchema(conn.GetSchemaDN());
                LdapSearchResults lsc       = conn.Search(searchBase,
                                                          LdapConnection.SCOPE_ONE,
                                                          searchFilter,
                                                          null,
                                                          false);
                while (lsc.hasMore())
                {
                    LdapEntry nextEntry = null;
                    try
                    {
                        nextEntry = lsc.next();
                    }
                    catch (LdapException e)
                    {
                        Console.WriteLine("Error: " + e.LdapErrorMessage);
                        // Exception is thrown, go for next entry
                        continue;
                    }
                    Console.WriteLine("\n\n\n");
                    Console.WriteLine("\n" + nextEntry.DN);
                    LdapAttributeSet attributeSet        = nextEntry.getAttributeSet();
                    System.Collections.IEnumerator ienum = attributeSet.GetEnumerator();
                    while (ienum.MoveNext())
                    {
                        LdapAttribute attribute     = (LdapAttribute)ienum.Current;
                        string        attributeName = attribute.Name;
                        Console.WriteLine(attributeName + ":  " + dirschema.getAttributeSchema(attributeName).ToString());
                    }
                }
                conn.Disconnect();
            }
            catch (LdapException e)
            {
                Console.WriteLine("Error:" + e.LdapErrorMessage);
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:" + e.Message);
                return;
            }
        }