Exemplo n.º 1
0
 public SchemaType(string cName, string attributeSyntax , string attrDisplayName ,string attributeType)
 {
     _cName = cName;
     if (attributeSyntax != null)
     {
         _adsType = ADTypeLookup.GetADSType(attributeSyntax);
     }
     _isSingleValued = false;
     _attributeSyntax = attributeSyntax;
     _attrDisplayName = attrDisplayName;
     _attributeType = attributeType;
 }
Exemplo n.º 2
0
 public SchemaType(string cName, string attributeSyntax, string attrDisplayName, string attributeType)
 {
     _cName = cName;
     if (attributeSyntax != null)
     {
         _adsType = ADTypeLookup.GetADSType(attributeSyntax);
     }
     _isSingleValued  = false;
     _attributeSyntax = attributeSyntax;
     _attrDisplayName = attrDisplayName;
     _attributeType   = attributeType;
 }
Exemplo n.º 3
0
        public LdapValue[] GetAttributeValues(IntPtr ldapEntry, string attrName, DirectoryContext dirContext)
        {
            if (dirContext == null ||
                String.IsNullOrEmpty(attrName))
            {
                return(null);
            }

            if (dirContext.SchemaCache == null)
            {
                return(GetNonBervals(ldapEntry, attrName));
            }

            LDAPSchemaCache schema    = dirContext.SchemaCache;
            SchemaType      foundType = schema.GetSchemaTypeByDisplayName(attrName);

            // if cannot find type in schemaCache, get byte[] first
            //(sometimes schemaCache doesn't contain objectGUID,...type information)
            if (foundType == null)
            {
                if (String.Equals(attrName, "objectGUID", StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(attrName, "objectSid", StringComparison.InvariantCultureIgnoreCase) ||
                    String.Equals(attrName, "nTsecurityDescriptor", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(ReformatBervalsInHex(ldapEntry, attrName));
                }
                else
                {
                    return(GetNonBervals(ldapEntry, attrName));
                }
            }
            ADSType adstype = foundType.DataType;

            if (adstype == ADSType.ADSTYPE_OCTET_STRING ||
                adstype == ADSType.ADSTYPE_NT_SECURITY_DESCRIPTOR)
            {
                return(ReformatBervalsInHex(ldapEntry, attrName));
            }
            else if (adstype == ADSType.ADSTYPE_INTEGER ||
                     adstype == ADSType.ADSTYPE_LARGE_INTEGER)
            {
                LdapValue[] values = GetBervals(ldapEntry, attrName);

                if (values == null || values.Length == 0)
                {
                    return(values);
                }
                foreach (LdapValue value in values)
                {
                    string replace      = value.stringData.Replace("-", "");
                    char[] intValuechrs = new char[replace.Length / 2];

                    for (int i = 0; i < replace.Length / 2; i++)
                    {
                        intValuechrs[i] = replace[i * 2 + 1];
                    }

                    for (int i = 0; i < intValuechrs.Length; i++)
                    {
                        if (intValuechrs[i] < '0' || intValuechrs[i] > '9')
                        {
                            intValuechrs[i] = '-';
                        }
                    }
                    value.stringData = new string(intValuechrs);
                    value.stringData.Replace("-", "");

                    if (adstype == ADSType.ADSTYPE_INTEGER)
                    {
                        value.intData = Convert.ToInt32(value.stringData);
                        value.AdsType = ADSType.ADSTYPE_INTEGER;
                    }
                    else if (adstype == ADSType.ADSTYPE_LARGE_INTEGER)
                    {
                        value.longData = Convert.ToInt64(value.stringData);
                        value.AdsType  = ADSType.ADSTYPE_LARGE_INTEGER;
                    }
                }
            }
            return(GetNonBervals(ldapEntry, attrName));
        }
        /// <summary>
        /// Returns the attribute type based on attribute syntax
        /// </summary>
        /// <param name="schemaType"></param>
        /// <returns></returns>
        public static string GetADSTypeString(SchemaType schemaType)
        {
            ADSType syntaxID = schemaType.DataType;

            switch (syntaxID)
            {
            case ADSType.ADSTYPE_DN_STRING:
                return("DN");

            case ADSType.ADSTYPE_CASE_IGNORE_STRING:
                if (schemaType.AttributeSyntax.Equals("2.5.5.2"))
                {
                    return("OID");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.4"))
                {
                    return("CaseIgnoreString");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.12"))
                {
                    return("DirectoryString");
                }
                else if (schemaType.AttributeSyntax.Equals("2.5.5.13"))
                {
                    return("PresentationAddress");
                }
                return("IA5String");

            case ADSType.ADSTYPE_CASE_EXACT_STRING:
                return("CaseSensitiveString");

            case ADSType.ADSTYPE_PRINTABLE_STRING:
                return("PrintableString");

            case ADSType.ADSTYPE_NUMERIC_STRING:
                return("NumericString");

            case ADSType.ADSTYPE_DN_WITH_STRING:
                return("DNWithString");

            case ADSType.ADSTYPE_BOOLEAN:
                return("Boolean");

            case ADSType.ADSTYPE_INTEGER:
                return("INTEGER");

            case ADSType.ADSTYPE_OCTET_STRING:
                return("OctetString");

            case ADSType.ADSTYPE_UTC_TIME:
                return("GeneralizedTime");

            case ADSType.ADSTYPE_NT_SECURITY_DESCRIPTOR:
                return("NTSecurityDescriptor");

            case ADSType.ADSTYPE_LARGE_INTEGER:
                return("INTEGER8");

            default:
                return("");
            }
        }
Exemplo n.º 5
0
 public LdapValue(ADSType adsType, byte[] byteData)
 {
     _adstype  = adsType;
     _byteData = byteData;
 }
Exemplo n.º 6
0
 public LdapValue(ADSType adsType, string stringData)
 {
     _adstype    = adsType;
     _stringData = stringData;
 }
Exemplo n.º 7
0
 public LdapValue(ADSType adsType, byte[] byteData)
 {
     _adstype = adsType;
     _byteData = byteData;
 }
Exemplo n.º 8
0
 public LdapValue(ADSType adsType, string stringData)
 {
     _adstype = adsType;
     _stringData = stringData;
 }