Exemplo n.º 1
0
        internal static bool TryParse(byte[] data, out byte[] token, out string oid)
        {
            token = null;
            oid   = string.Empty;
            try {
                BinaryReader reader = new BinaryReader(new MemoryStream(data));

                byte start = reader.ReadByte();
                if (start != 0x60)
                {
                    return(false);
                }
                int    length      = DERUtils.ReadLength(reader);
                byte[] inner_token = reader.ReadAllBytes(length);
                reader = new BinaryReader(new MemoryStream(inner_token));
                if (reader.ReadByte() != 0x06)
                {
                    return(false);
                }
                int oid_length = DERUtils.ReadLength(reader);
                oid   = DERUtils.ReadObjID(reader.ReadAllBytes(oid_length));
                token = reader.ReadAllBytes((int)reader.RemainingLength());
                return(true);
            } catch (EndOfStreamException) {
                return(false);
            }
        }
Exemplo n.º 2
0
        private static DirectoryServiceSchemaObject ConvertToSchemaClass(string domain, Guid?schema_id, DirectoryEntry dir_entry)
        {
            if (dir_entry is null)
            {
                return(null);
            }
            var    prop        = dir_entry.ToPropertyClass();
            string cn          = prop.GetPropertyValue <string>(kCommonName);
            string ldap_name   = prop.GetPropertyValue <string>(kLDAPDisplayName);
            string dn          = prop.GetPropertyValue <string>(kDistinguishedName);
            string description = prop.GetPropertyValue <string>(kAdminDescription);
            string class_name  = dir_entry.SchemaClassName;

            if (schema_id == null)
            {
                schema_id = prop.GetPropertyGuid(kSchemaIDGUID);
            }

            if (cn == null || ldap_name == null || !schema_id.HasValue)
            {
                return(null);
            }

            switch (class_name.ToLower())
            {
            case "classschema":
            {
                string subclass_of = prop.GetPropertyValue <string>(kSubClassOf);

                List <DirectoryServiceSchemaClassAttribute> attrs = new List <DirectoryServiceSchemaClassAttribute>();
                AddAttributes(attrs, prop.GetPropertyValues <string>(kMustContain), true, false);
                AddAttributes(attrs, prop.GetPropertyValues <string>(kSystemMustContain), true, true);
                AddAttributes(attrs, prop.GetPropertyValues <string>(kMayContain), false, false);
                AddAttributes(attrs, prop.GetPropertyValues <string>(kSystemMayContain), false, true);
                var default_security_desc = prop.GetPropertyValue <string>(kDefaultSecurityDescriptor);

                return(new DirectoryServiceSchemaClass(domain, dn, schema_id.Value, cn,
                                                       ldap_name, description, class_name, subclass_of, attrs, default_security_desc));
            }

            case "attributeschema":
            {
                var attribute_syntax      = prop.GetPropertyValue <string>("attributeSyntax") ?? string.Empty;
                var om_syntax             = prop.GetPropertyValue <int>("oMSyntax");
                var om_object_class_bytes = prop.GetPropertyValue <byte[]>("oMObjectClass");

                string om_object_class_name = string.Empty;
                if (om_object_class_bytes?.Length > 0)
                {
                    try
                    {
                        om_object_class_name = DERUtils.ReadObjID(om_object_class_bytes);
                    }
                    catch (EndOfStreamException)
                    {
                    }
                }

                return(new DirectoryServiceSchemaAttribute(domain, dn, schema_id.Value, cn,
                                                           ldap_name, description, class_name, attribute_syntax, om_syntax, om_object_class_name));
            }

            default:
                return(new DirectoryServiceSchemaObject(domain, dn, schema_id.Value, cn,
                                                        ldap_name, description, class_name));
            }
        }