Exemple #1
0
        public void AddAttributeToCache(string forestName, string attributeName, ActiveDirectorySyntax adSyntax, bool isBad)
        {
            if (ForestBase.LoadedAttributes.ContainsKey(attributeName))
            {
                return;
            }

            return;


            //GetCache(forestName, new DateTime(DateTime.MinValue.Ticks));

            //XElement attribnode = CurrentForestNode.Descendants(attributeName.ToLowerInvariant()).FirstOrDefault();

            //if (attribnode == null)
            //{
            //    attribnode = new XElement(attributeName.ToLowerInvariant());

            //    attribnode.Value = isBad ? "UnKnown" : adSyntax.ToString();

            //    CurrentForestNode.Add(attribnode);

            //    LoadedAttributes.Add(attributeName, isBad ? "UnKnown" : adSyntax.ToString());

            //    SchemaCacheIsDirty = true;
            //}
        }
        public List <string> DecodeSDData(DirectoryAttribute attrib, ActiveDirectorySyntax syntax)
        {
            List <String> ret = new List <string> {
            };

            foreach (byte[] value in attrib.GetValues(typeof(byte[])))
            {
                try
                {
                    CommonSecurityDescriptor oCSD = new CommonSecurityDescriptor(true, true, value, 0);

                    if (!MainBase.UserSettings.DecodeSD)
                    {
                        ret.AddFormatted("\t\t(must not decode) SDDL: <{0}>", oCSD.GetSddlForm(AccessControlSections.All));
                    }

                    else
                    {
                        ret.AddRange(DecodeSD(oCSD));
                    }
                }

                catch
                { ret.AddFormatted("\t\t<not decoded>: {0}", attrib[0].GetType().ToString()); }
            }

            return(ret);
        }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
 {
     this.syntax            = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower        = null;
     this.rangeUpper        = null;
     this.linkId            = null;
     this.context           = context;
     this.ldapDisplayName   = ldapDisplayName;
     this.propertyEntry     = propertyEntry;
     this.isDefunctOnServer = false;
     this.isDefunct         = this.isDefunctOnServer;
     try
     {
         this.abstractPropertyEntry = DirectoryEntryManager.GetDirectoryEntryInternal(context, "LDAP://" + context.GetServerName() + "/schema/" + ldapDisplayName);
         this.iadsProperty          = (NativeComInterfaces.IAdsProperty) this.abstractPropertyEntry.NativeObject;
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode == -2147463168)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (InvalidCastException)
     {
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     this.isBound = true;
 }
 public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName)
 {
     this.syntax = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId = null;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (ldapDisplayName == null)
     {
         throw new ArgumentNullException("ldapDisplayName");
     }
     if (ldapDisplayName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
     }
     this.context = new DirectoryContext(context);
     this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
     this.schemaEntry.Bind(true);
     this.ldapDisplayName = ldapDisplayName;
     this.commonName = ldapDisplayName;
     this.isBound = false;
 }
 public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName)
 {
     this.syntax     = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId     = null;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isADAMConfigSet() && !context.isServer()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (ldapDisplayName == null)
     {
         throw new ArgumentNullException("ldapDisplayName");
     }
     if (ldapDisplayName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
     }
     this.context     = new DirectoryContext(context);
     this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
     this.schemaEntry.Bind(true);
     this.ldapDisplayName = ldapDisplayName;
     this.commonName      = ldapDisplayName;
     this.isBound         = false;
 }
Exemple #6
0
        public bool AttributeIsInCacheOld(string forestName, string attributeName, out ActiveDirectorySyntax adSyntax, out bool isBad)
        {
            bool ret = false;

            adSyntax = ActiveDirectorySyntax.CaseIgnoreString;
            isBad    = false;

            if (GetCacheOld(forestName, new DateTime(DateTime.MinValue.Ticks)))
            {
                if (ForestBase.LoadedAttributes.ContainsKey(attributeName))
                {
                    string syntax = ForestBase.LoadedAttributes[attributeName];

                    if (syntax == "UnKnown")
                    {
                        isBad = true;

                        return(true);
                    }

                    adSyntax = StringSyntaxToADSynatx(attributeName);

                    return(true);
                }

                else
                {
                    ret = ReadSyntaxFromCache(attributeName, out adSyntax, out isBad);
                }
            }

            return(ret);
        }
Exemple #7
0
        public AttributeSchema(ActiveDirectorySchemaProperty entry)
        {
            Name            = entry.Name;
            Syntax          = entry.Syntax;
            SyntaxFromCache = false;

            CheckSyntax();
        }
Exemple #8
0
        private ActiveDirectorySyntax StringSyntaxToADSynatx(string syntax)
        {
            ActiveDirectorySyntax ret = ActiveDirectorySyntax.CaseIgnoreString;;

            try
            { ret = (ActiveDirectorySyntax)Enum.Parse(typeof(ActiveDirectorySyntax), syntax, true); }

            catch (Exception ex)
            { ex.ToDummy(); }

            return(ret);
        }
Exemple #9
0
        public AttributeSchema(string ldapName, ActiveDirectorySyntax adSyntax, bool flags, long linkId)
        {
            Name            = ldapName;
            Syntax          = adSyntax;
            SyntaxFromCache = true;

            IsLinked = (linkId > 0);

            IsConstructed = flags;

            CheckSyntax();
        }
Exemple #10
0
        // You can use the DirectoryServer or Forest value of the DirectoryContextType enumeration
        // for connecting to and then extending an AD schema.
        // However, use caution when extended an AD schema. Additions are not easily reversible


        public static void CreateNewAttribute()
        {
            //specify a common name
            string newAttributeCommonName = "New-Attribute1";

            //specify an OID value. The root name was generated by oidgen.exe
            string newAttributeOid =
                "1.2.840.113556.1.4.7000.233.28688.28684.8.145234.1728134.2034934.1932637.1";

            // specify a syntax
            ActiveDirectorySyntax syntax = ActiveDirectorySyntax.CaseIgnoreString;

            // create a new attribute schema object
            ActiveDirectorySchemaProperty newAttribute =
                new ActiveDirectorySchemaProperty(
                    adamContext,
                    newAttributeLdapDisplayName);

            // set attributes for this schema attribute object
            newAttribute.CommonName     = newAttributeCommonName;
            newAttribute.Oid            = newAttributeOid;
            newAttribute.IsSingleValued = true;
            newAttribute.Syntax         = syntax;

            // do not replicate to the global catalog
            // the default for isMemberOfPartialAttributeSet is already False, but this
            // setting is irrelevant for an ADAM instance.
            // newAttribute.IsInGlobalCatalog = false;

            try
            {
                // save the new attribute schema object to the schema
                newAttribute.Save();
            }
            catch (ActiveDirectoryObjectExistsException e)
            {
                // an object by this name already exists in the schema
                Console.WriteLine("The schema object \"{0}\" was not created. {1}",
                                  newAttributeLdapDisplayName, e.Message);
                return;
            }

            catch (ActiveDirectoryOperationException e)
            {
                // a call to the underlying directory was rejected
                Console.WriteLine("The schema object \"{0}\" was not created. {0}",
                                  newAttributeLdapDisplayName, e.Message);
                return;
            }

            Console.WriteLine("Attribute schema object \"{0}\" created successfully.",
                              newAttributeLdapDisplayName);
        }
        public ActiveDirectorySyntax DecodeLDAPAttributeSyntax(string attributeSyntax, int omSyntax)
        {
            ActiveDirectorySyntax ret = ActiveDirectorySyntax.CaseIgnoreString;

            if (ForestBase.LDAPSyntaxes.ContainsKey(attributeSyntax))
            {
                if (ForestBase.LDAPSyntaxes[attributeSyntax].ContainsKey(omSyntax))
                {
                    ret = ForestBase.LDAPSyntaxes[attributeSyntax][omSyntax];
                }
            }

            return(ret);
        }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
 {
     this.syntax            = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower        = null;
     this.rangeUpper        = null;
     this.linkId            = null;
     this.context           = context;
     this.schemaEntry       = schemaEntry;
     this.propertyEntry     = propertyEntry;
     this.commonName        = commonName;
     this.ldapDisplayName   = ldapDisplayName;
     this.isDefunctOnServer = true;
     this.isDefunct         = this.isDefunctOnServer;
     this.isBound           = true;
 }
        private void SetSyntax(ActiveDirectorySyntax syntax)
        {
            if ((syntax < ActiveDirectorySyntax.CaseExactString) || (syntax > (SyntaxesCount - 1)))
            {
                throw new InvalidEnumArgumentException("syntax", (int)syntax, typeof(ActiveDirectorySyntax));
            }
            this.GetSchemaPropertyDirectoryEntry();
            this.propertyEntry.Properties[PropertyManager.AttributeSyntax].Value = syntaxes[(int)syntax].attributeSyntax;
            this.propertyEntry.Properties[PropertyManager.OMSyntax].Value        = syntaxes[(int)syntax].oMSyntax;
            OMObjectClass oMObjectClass = syntaxes[(int)syntax].oMObjectClass;

            if (oMObjectClass != null)
            {
                this.propertyEntry.Properties[PropertyManager.OMObjectClass].Value = oMObjectClass.Data;
            }
        }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, SearchResult propertyValuesFromServer, DirectoryEntry schemaEntry)
 {
     this.syntax      = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower  = null;
     this.rangeUpper  = null;
     this.linkId      = null;
     this.context     = context;
     this.schemaEntry = schemaEntry;
     this.propertyValuesFromServer = propertyValuesFromServer;
     this.propertiesFromSchemaContainerInitialized = true;
     this.propertyEntry     = this.GetSchemaPropertyDirectoryEntry();
     this.commonName        = commonName;
     this.ldapDisplayName   = (string)this.GetValueFromCache(PropertyManager.LdapDisplayName, true);
     this.isDefunctOnServer = true;
     this.isDefunct         = this.isDefunctOnServer;
     this.isBound           = true;
 }
Exemple #15
0
        private bool ReadSyntaxFromCache(string attributeName, out ActiveDirectorySyntax adSyntax, out bool isBad)
        {
            bool ret = false;

            adSyntax = ActiveDirectorySyntax.CaseIgnoreString;
            isBad    = false;

            XElement attribnode = ForestBase.CurrentAttributesNode.Descendants(attributeName.ToLowerInvariant()).FirstOrDefault();

            if (attribnode != null)
            {
                string syntax = attribnode.Value;

                if (syntax == "UnKnown")
                {
                    isBad = true;

                    return(true);
                }

                try
                {
                    ActiveDirectorySyntax temp = StringSyntaxToADSynatx(syntax);

                    adSyntax = temp;

                    ForestBase.LoadedAttributes.Add(attributeName, syntax);

                    return(true);
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            return(ret);
        }
        public List <string> DecodeIntData(DirectoryAttribute attrib, ActiveDirectorySyntax syntax, out bool isBad)
        {
            List <String> ret = new List <string> {
            };

            isBad = false;

            foreach (string value in attrib.GetValues(typeof(string)))
            {
                try
                { ret.AddFormatted("\t\t<{0}>", value.ToString()); }

                catch (Exception ex)
                {
                    ex.ToDummy();

                    isBad = true;

                    ret.AddFormatted("\t\t<not decoded>: {0}", value.ToString());
                }
            }

            return(ret);
        }
        private ActiveDirectorySyntax SyntaxFromLiveSchema(string name)
        {
            ActiveDirectorySyntax ret = ActiveDirectorySyntax.CaseIgnoreString;

            string filter = String.Format("(&(objectClass=attributeSchema)(lDAPDisplayName={0}))", name);

            string[] attributes = new string[] { "attributeSyntax", "oMSyntax" };

            List <SearchResultEntry> result = Query(ForestBase.CurrentDC, ForestBase.SchemaNamingContext,
                                                    filter, attributes, SearchScope.Subtree,
                                                    ReferralChasingOptions.None,
                                                    new QueryControl()
            {
                CurrentResultEventType = QUERY_RESULT_EVENT_TYPE.FROM_DECODING
            },
                                                    returnResults: true);

            if (result.Count != 0)
            {
                try
                {
                    string attributesyntax = result[0].Attributes["attributeSyntax"][0].ToString();

                    int omsyntax = -1;

                    Int32.TryParse(result[0].Attributes["oMSyntax"][0].ToString(), out omsyntax);

                    ret = DecodeLDAPAttributeSyntax(attributesyntax, omsyntax);
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            return(ret);
        }
        public List <string> DecodeInt64Data(DirectoryAttribute attrib, ActiveDirectorySyntax syntax, out bool isBad, out string plainDataFirst)
        {
            List <String> ret = new List <string> {
            };

            isBad          = false;
            plainDataFirst = null;

            string defaultdata = (new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToString();

            foreach (string value in attrib.GetValues(typeof(string)))
            {
                if (attrib.Name.ToLowerInvariant().StartsWith("usn"))
                {
                    ret.AddFormatted("\t\t<{0}>", value);
                }

                else
                {
                    object val = null;

                    try
                    {
                        if (syntax == ActiveDirectorySyntax.Int64)
                        {
                            Int64 temp = 0;
                            Int64.TryParse(value, out temp);

                            if (temp < 0)
                            {
                                value.TryParsePositiveNumber(out temp);

                                TimeSpan intervall = new TimeSpan(temp);

                                double maxhit = (double)(intervall.Ticks / TimeSpan.MaxValue.Ticks);

                                maxhit = (maxhit < 0) ? -maxhit : maxhit;

                                if (maxhit == 1)
                                {
                                    val = "never";
                                }

                                else
                                {
                                    val = intervall.ToString();
                                }
                            }

                            else if (temp == 0)
                            {
                                val = "none";
                            }

                            else if (temp >= DateTime.MaxValue.Ticks)
                            {
                                val = "never";
                            }

                            else
                            {
                                try
                                { val = DateTime.FromFileTime(temp).ToUniversalTime(); }

                                catch (Exception ex)
                                { val = "never"; ex.ToDummy(); }
                            }
                        }

                        else if (syntax == ActiveDirectorySyntax.GeneralizedTime)
                        {
                            DateTime temp;

                            if (DateTime.TryParseExact(value, ForestBase.GENERALIZED_TIME_FORMAT, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault, out temp))
                            {
                                val = (temp < DateTime.FromFileTimeUtc(0)) ? DateTime.FromFileTimeUtc(0) : temp;
                            }

                            else
                            {
                                val = "not decoded";
                            }
                        }

                        else if (syntax == ActiveDirectorySyntax.UtcTime)
                        {
                            DateTime temp;

                            if (DateTime.TryParseExact(value, ForestBase.GENERALIZED_TIME_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out temp))
                            {
                                val = (temp < DateTime.FromFileTimeUtc(0)) ? DateTime.FromFileTimeUtc(0) : temp;
                            }

                            else
                            {
                                val = "not decoded";
                            }
                        }

                        else
                        {
                            val = "not decoded";
                        }

                        if (val.GetType() != typeof(string))
                        {
                            DateTime vtime = (DateTime)val;
                            vtime = vtime.Subtract(new TimeSpan(vtime.TimeOfDay.Ticks));

                            if (vtime.Ticks == (new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks))
                            {
                                val = "never";
                            }

                            else
                            {
                                defaultdata = val.ToString();

                                val = String.Format("{0} (UTC)", val.ToString());
                            }
                        }
                    }

                    catch (Exception ex)
                    { val = "not decoded"; isBad = true; ex.ToDummy(); }

                    if (plainDataFirst == null)
                    {
                        plainDataFirst = defaultdata;
                    }

                    ret.AddFormatted("\t\t<{0}> ({1})", val.ToString(), value);
                }
            }

            return(ret);
        }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
 {
     this.syntax = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId = null;
     this.context = context;
     this.ldapDisplayName = ldapDisplayName;
     this.propertyEntry = propertyEntry;
     this.isDefunctOnServer = false;
     this.isDefunct = this.isDefunctOnServer;
     try
     {
         this.abstractPropertyEntry = DirectoryEntryManager.GetDirectoryEntryInternal(context, "LDAP://" + context.GetServerName() + "/schema/" + ldapDisplayName);
         this.iadsProperty = (NativeComInterfaces.IAdsProperty) this.abstractPropertyEntry.NativeObject;
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode == -2147463168)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (InvalidCastException)
     {
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     this.isBound = true;
 }
        private void SetSyntax(ActiveDirectorySyntax syntax)
        {
            if ((((int)syntax) < 0) || (((int)syntax) > (s_syntaxesCount - 1)))
            {
                throw new InvalidEnumArgumentException("syntax", (int)syntax, typeof(ActiveDirectorySyntax));
            }

            // get the distinguished name to construct the directory entry 
            GetSchemaPropertyDirectoryEntry();
            Debug.Assert(_propertyEntry != null);

            _propertyEntry.Properties[PropertyManager.AttributeSyntax].Value = s_syntaxes[(int)syntax].attributeSyntax;
            _propertyEntry.Properties[PropertyManager.OMSyntax].Value = s_syntaxes[(int)syntax].oMSyntax;
            OMObjectClass oMObjectClass = s_syntaxes[(int)syntax].oMObjectClass;
            if (oMObjectClass != null)
            {
                _propertyEntry.Properties[PropertyManager.OMObjectClass].Value = oMObjectClass.Data;
            }
        }
 private void SetSyntax(ActiveDirectorySyntax syntax)
 {
     if ((syntax < ActiveDirectorySyntax.CaseExactString) || (syntax > (SyntaxesCount - 1)))
     {
         throw new InvalidEnumArgumentException("syntax", (int) syntax, typeof(ActiveDirectorySyntax));
     }
     this.GetSchemaPropertyDirectoryEntry();
     this.propertyEntry.Properties[PropertyManager.AttributeSyntax].Value = syntaxes[(int) syntax].attributeSyntax;
     this.propertyEntry.Properties[PropertyManager.OMSyntax].Value = syntaxes[(int) syntax].oMSyntax;
     OMObjectClass oMObjectClass = syntaxes[(int) syntax].oMObjectClass;
     if (oMObjectClass != null)
     {
         this.propertyEntry.Properties[PropertyManager.OMObjectClass].Value = oMObjectClass.Data;
     }
 }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
 {
     this.syntax = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId = null;
     this.context = context;
     this.schemaEntry = schemaEntry;
     this.propertyEntry = propertyEntry;
     this.commonName = commonName;
     this.ldapDisplayName = ldapDisplayName;
     this.isDefunctOnServer = true;
     this.isDefunct = this.isDefunctOnServer;
     this.isBound = true;
 }
 internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, SearchResult propertyValuesFromServer, DirectoryEntry schemaEntry)
 {
     this.syntax = ~ActiveDirectorySyntax.CaseExactString;
     this.rangeLower = null;
     this.rangeUpper = null;
     this.linkId = null;
     this.context = context;
     this.schemaEntry = schemaEntry;
     this.propertyValuesFromServer = propertyValuesFromServer;
     this.propertiesFromSchemaContainerInitialized = true;
     this.propertyEntry = this.GetSchemaPropertyDirectoryEntry();
     this.commonName = commonName;
     this.ldapDisplayName = (string) this.GetValueFromCache(PropertyManager.LdapDisplayName, true);
     this.isDefunctOnServer = true;
     this.isDefunct = this.isDefunctOnServer;
     this.isBound = true;
 }
		public ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName)
		{
			this.syntax = ActiveDirectorySyntax.CaseIgnoreString | ActiveDirectorySyntax.NumericString | ActiveDirectorySyntax.DirectoryString | ActiveDirectorySyntax.OctetString | ActiveDirectorySyntax.SecurityDescriptor | ActiveDirectorySyntax.Int | ActiveDirectorySyntax.Int64 | ActiveDirectorySyntax.Bool | ActiveDirectorySyntax.Oid | ActiveDirectorySyntax.GeneralizedTime | ActiveDirectorySyntax.UtcTime | ActiveDirectorySyntax.DN | ActiveDirectorySyntax.DNWithBinary | ActiveDirectorySyntax.DNWithString | ActiveDirectorySyntax.Enumeration | ActiveDirectorySyntax.IA5String | ActiveDirectorySyntax.PrintableString | ActiveDirectorySyntax.Sid | ActiveDirectorySyntax.AccessPointDN | ActiveDirectorySyntax.ORName | ActiveDirectorySyntax.PresentationAddress | ActiveDirectorySyntax.ReplicaLink;
			this.rangeLower = null;
			this.rangeUpper = null;
			this.linkId = null;
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer())
					{
						if (ldapDisplayName != null)
						{
							if (ldapDisplayName.Length != 0)
							{
								this.context = new DirectoryContext(context);
								this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.SchemaNamingContext);
								//TODO: REVIEW: URGENT!!:this.schemaEntry.Bind(true);
								this.ldapDisplayName = ldapDisplayName;
								this.commonName = ldapDisplayName;
								this.isBound = false;
								return;
							}
							else
							{
								throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
							}
						}
						else
						{
							throw new ArgumentNullException("ldapDisplayName");
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
        public List <string> TryCustomDecoding(DirectoryAttribute attrib, SearchResultEntry entry, ref bool match, ref bool exclusive, ActiveDirectorySyntax aSyntax = ActiveDirectorySyntax.CaseIgnoreString)
        {
            exclusive = false;

            match = true;

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

            bool isbad = false;

            #region userparamters

            if (attrib.Name.ToLowerInvariant() == "userparameters")
            {
                if (MainBase.UserSettings.DecodeUserParameters)
                {
                    DirectoryAttribute desam = entry.Attributes["sAMAccountName"];

                    string sam = DecodeStringData(desam, ActiveDirectorySyntax.CaseIgnoreString, out isbad, true)[0];

                    DateTime start = DateTime.Now;

                    WtsApi userparams = new WtsApi(ForestBase.CurrentDC, sam);

                    GlobalEventHandler.RaiseSubsequentQuery((long)DateTime.Now.Subtract(start).TotalMilliseconds);

                    ret = userparams.Print();

                    if (!userparams.HasError)
                    {
                        exclusive = true;
                    }
                }
            }

            #endregion

            #region memberof

            else if (attrib.Name.ToLowerInvariant() == "memberof")
            {
                if (MainBase.UserSettings.DecodePrimaryGroupID)
                {
                    try
                    {
                        DirectoryAttribute deprid = entry.Attributes["primaryGroupID"];

                        string pgid = DecodePrimaryGroupId(deprid, true);

                        ret.Add(pgid.Replace("<", "<(primaryGroupID) "));
                    }

                    catch (Exception ex)
                    { ex.ToDummy(); }
                }
            }

            #endregion

            #region primarygroupid

            else if (attrib.Name.ToLowerInvariant() == "primarygroupid")
            {
                try
                {
                    DirectoryAttribute deprid = entry.Attributes["primaryGroupID"];

                    string pgid = DecodePrimaryGroupId(deprid, MainBase.UserSettings.DecodePrimaryGroupID);

                    ret.Add(pgid);

                    exclusive = true;
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            else if (attrib.Name.ToLowerInvariant() == "defaultsecuritydescriptor")
            {
                DirectoryAttribute deprid = entry.Attributes["defaultsecuritydescriptor"];

                ret = DecodeDefaultSD(deprid, MainBase.UserSettings.DecodeDefaultSD);

                exclusive = true;
            }

            #endregion

            #region logonhours

            else if (attrib.Name.ToLowerInvariant() == "logonhours")
            {
                try
                {
                    ret = DecodeLogonHours(attrib);

                    exclusive = true;
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            #endregion

            #region dSaSignature

            else if (attrib.Name.ToLowerInvariant() == "dsasignature")
            {
                try
                {
                    ret = DecodeDsaSignature(attrib);

                    exclusive = true;
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            else if (attrib.Name.ToLowerInvariant() == "schemainfo")
            {
                try
                {
                    Int32 uver = 0;

                    ret = DecodeSchemaInfo(attrib, out uver);

                    exclusive = true;
                }

                catch (Exception ex)
                { ex.ToDummy(); }
            }

            #endregion

            #region tokenGroups  tokenGroupsGlobalAndUniversal tokenGroupsNoGCAcceptable

            else if ((attrib.Name.ToLowerInvariant() == "tokengroups") || (attrib.Name.ToLowerInvariant() == "tokengroupsglobalanduniversal") || (attrib.Name.ToLowerInvariant() == "tokengroupsglobalanduniversal"))
            {
                if (MainBase.UserSettings.ResolveSids)
                {
                    ret.AddRange(DecodeByteData(attrib, ActiveDirectorySyntax.Sid, out isbad, true));

                    exclusive = true;
                }
            }

            #endregion

            #region trust

            else if (attrib.Name.ToLowerInvariant() == "msds-trustforesttrustinfo")
            {
                foreach (byte[] value in attrib.GetValues(typeof(byte[])))
                {
                    ret.AddRange(new ForestTrustInfoDecoder(value).ToString());

                    exclusive = true;
                }
            }

            #endregion

            #region replication

            else if (attrib.Name.ToLowerInvariant() == "repluptodatevector")
            {
                foreach (byte[] value in attrib.GetValues(typeof(byte[])))
                {
                    ret.AddRange(new ReplUpToDateVector().Decode(value));

                    exclusive = true;
                }
            }

            else if (attrib.Name.ToLowerInvariant() == "replpropertymetadata")
            {
                //ActiveDirectoryReplicationMetadata metadata = CurrentDC
            }

            else if (aSyntax == ActiveDirectorySyntax.ReplicaLink)
            {
            }

            #endregion

            else
            {
                match = false;
            }

            return(ret);
        }
		internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, SearchResult propertyValuesFromServer, DirectoryEntry schemaEntry)
		{
			this.syntax = ActiveDirectorySyntax.CaseIgnoreString | ActiveDirectorySyntax.NumericString | ActiveDirectorySyntax.DirectoryString | ActiveDirectorySyntax.OctetString | ActiveDirectorySyntax.SecurityDescriptor | ActiveDirectorySyntax.Int | ActiveDirectorySyntax.Int64 | ActiveDirectorySyntax.Bool | ActiveDirectorySyntax.Oid | ActiveDirectorySyntax.GeneralizedTime | ActiveDirectorySyntax.UtcTime | ActiveDirectorySyntax.DN | ActiveDirectorySyntax.DNWithBinary | ActiveDirectorySyntax.DNWithString | ActiveDirectorySyntax.Enumeration | ActiveDirectorySyntax.IA5String | ActiveDirectorySyntax.PrintableString | ActiveDirectorySyntax.Sid | ActiveDirectorySyntax.AccessPointDN | ActiveDirectorySyntax.ORName | ActiveDirectorySyntax.PresentationAddress | ActiveDirectorySyntax.ReplicaLink;
			this.rangeLower = null;
			this.rangeUpper = null;
			this.linkId = null;
			this.context = context;
			this.schemaEntry = schemaEntry;
			this.propertyValuesFromServer = propertyValuesFromServer;
			this.propertiesFromSchemaContainerInitialized = true;
			this.propertyEntry = this.GetSchemaPropertyDirectoryEntry();
			this.commonName = commonName;
			this.ldapDisplayName = (string)this.GetValueFromCache(PropertyManager.LdapDisplayName, true);
			this.isDefunctOnServer = true;
			this.isDefunct = this.isDefunctOnServer;
			this.isBound = true;
		}
		internal ActiveDirectorySchemaProperty(DirectoryContext context, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
		{
			this.syntax = ActiveDirectorySyntax.CaseIgnoreString | ActiveDirectorySyntax.NumericString | ActiveDirectorySyntax.DirectoryString | ActiveDirectorySyntax.OctetString | ActiveDirectorySyntax.SecurityDescriptor | ActiveDirectorySyntax.Int | ActiveDirectorySyntax.Int64 | ActiveDirectorySyntax.Bool | ActiveDirectorySyntax.Oid | ActiveDirectorySyntax.GeneralizedTime | ActiveDirectorySyntax.UtcTime | ActiveDirectorySyntax.DN | ActiveDirectorySyntax.DNWithBinary | ActiveDirectorySyntax.DNWithString | ActiveDirectorySyntax.Enumeration | ActiveDirectorySyntax.IA5String | ActiveDirectorySyntax.PrintableString | ActiveDirectorySyntax.Sid | ActiveDirectorySyntax.AccessPointDN | ActiveDirectorySyntax.ORName | ActiveDirectorySyntax.PresentationAddress | ActiveDirectorySyntax.ReplicaLink;
			this.rangeLower = null;
			this.rangeUpper = null;
			this.linkId = null;
			this.context = context;
			this.ldapDisplayName = ldapDisplayName;
			this.propertyEntry = propertyEntry;
			this.isDefunctOnServer = false;
			this.isDefunct = this.isDefunctOnServer;
			try
			{
				this.abstractPropertyEntry = DirectoryEntryManager.GetDirectoryEntryInternal(context, string.Concat("LDAP://", context.GetServerName(), "/schema/", ldapDisplayName));
				this.iadsProperty = (NativeComInterfaces.IAdsProperty)this.abstractPropertyEntry.NativeObject;
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				if (cOMException.ErrorCode != -2147463168)
				{
					throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
				}
				else
				{
					throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
				}
			}
			catch (InvalidCastException invalidCastException)
			{
				throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySchemaProperty), ldapDisplayName);
			}
			catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
			{
				object[] name = new object[1];
				name[0] = context.Name;
				throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
			}
			this.isBound = true;
		}
        public List <string> DecodeByteData(DirectoryAttribute attrib, ActiveDirectorySyntax syntax, out bool isBad, bool resolveSid = false, bool rawdata = false)
        {
            List <String> ret = new List <string> {
            };

            isBad = false;

            foreach (byte[] value in attrib.GetValues(typeof(byte[])))
            {
                object val = null;

                try
                {
                    if (syntax == ActiveDirectorySyntax.Sid)
                    {
                        if (MainBase.UserSettings.DecodeSID)
                        {
                            val = new SecurityIdentifier(value, 0);

                            if (MainBase.UserSettings.ResolveSids)
                            {
                                val = String.Format("{0} ({1})", DecodeSID((SecurityIdentifier)val, true), val.ToString());
                            }
                        }

                        else
                        {
                            val = string.Format("(must not decode) {0}", DecodeByteToHex(value));
                        }
                    }

                    else if (syntax == ActiveDirectorySyntax.OctetString)
                    {
                        val = DecodeOctetString(value, MainBase.UserSettings.DecodeGUID, MainBase.UserSettings.DecodeOctetStrings, attrib.Name.ToLowerInvariant().Contains("guid"));
                    }

                    else if (syntax == ActiveDirectorySyntax.ReplicaLink)
                    {
                        val = DecodeOctetString(value, MainBase.UserSettings.DecodeGUID, MainBase.UserSettings.DecodeReplicaLinks, false);
                    }

                    else
                    {
                        val = DecodeByteToHex(value);
                    }

                    ret.Add((rawdata) ? val.ToString() : string.Format("\t\t<{0}>", val.ToString()));
                }

                catch (Exception ex)
                {
                    ex.ToDummy();

                    isBad = true;

                    ret.AddFormatted("\t\t<not decoded>: {0}", DecodeByteToHex(value));
                }
            }

            return(ret);
        }
        public List <string> DecodeSearchResults(List <SearchResultEntry> result, SearchRequestExtender infoStore)
        {
            List <string> ret = new List <string> {
            };

            foreach (SearchResultEntry sre in result)
            {
                ret.AddFormatted("DN: <{0}>", sre.DistinguishedName);

                if (sre.Attributes.Values.Count == 0)
                {
                    ret.Add("\t<no such attribute(s)>");
                }

                else
                {
                    if (infoStore.Attributes == null)
                    {
                        Array.Resize(ref infoStore.Attributes, sre.Attributes.AttributeNames.Count);

                        sre.Attributes.AttributeNames.CopyTo(infoStore.Attributes, 0);
                    }

                    foreach (string attribname in infoStore.Attributes)
                    {
                        List <string> tempret = new List <string> {
                        };

                        bool isempty = false;

                        tempret.AddFormatted("\t<{0}>:", attribname);

                        if (!(sre.Attributes.Contains(attribname)))
                        {
                            tempret.Add("\t\t<not present>");

                            isempty = true;
                        }

                        else
                        {
                            DirectoryAttribute deAttrib = sre.Attributes[attribname];

                            if (deAttrib.Count == 0)
                            {
                                tempret.Add("\t\t<not set>");

                                isempty = true;
                            }

                            else
                            {
                                bool isbad;

                                ActiveDirectorySyntax asyntax = GetAttributeSyntax(attribname, out isbad);

                                if (isbad)
                                {
                                    tempret.AddFormatted("\t\t<UnKnown syntax> {0}", deAttrib.Name);
                                }

                                else
                                {
                                    switch (asyntax)
                                    {
                                    case ActiveDirectorySyntax.OctetString:
                                    case ActiveDirectorySyntax.Sid:

                                        tempret.AddRange(DecodeByteData(deAttrib, asyntax, out isbad));
                                        break;

                                    case ActiveDirectorySyntax.Int64:
                                    case ActiveDirectorySyntax.GeneralizedTime:
                                    case ActiveDirectorySyntax.UtcTime:

                                        string plaind = null;

                                        tempret.AddRange(DecodeInt64Data(deAttrib, asyntax, out isbad, out plaind));
                                        break;


                                    case ActiveDirectorySyntax.SecurityDescriptor:

                                        tempret.AddRange(DecodeSDData(deAttrib, asyntax));
                                        break;

                                    case ActiveDirectorySyntax.Int:

                                        tempret.AddRange(DecodeIntData(deAttrib, asyntax, out isbad));
                                        break;

                                    default:

                                        tempret.AddRange(DecodeStringData(deAttrib, asyntax, out isbad));
                                        break;
                                    }

                                    if (isbad)
                                    {
                                        MarkAttributeAsBad(ForestBase.ForestName, attribname);
                                    }
                                }
                            }
                        }

                        if ((!isempty) || (isempty && !MainBase.UserSettings.IgnoreEmpty))
                        {
                            ret.AddRange(tempret);
                        }
                    }
                }
            }

            if (ForestBase.SchemaCacheIsDirty)
            {
                SaveCache();
            }

            return(ret);
        }
        public ActiveDirectorySyntax GetAttributeSyntax(string name, out bool isBad)
        {
            ActiveDirectorySyntax ret = ActiveDirectorySyntax.CaseIgnoreString;

            bool syntaxfromcache = true;
            bool notfound        = true;
            bool incache         = false;

            isBad = false;

            AttributeSchema attribute = null;;

            if (name.Contains(";"))
            {
                name = name.Substring(0, name.IndexOf(";"));
            }

            try
            {
                if (ForestBase.AttributeCache.ContainsKey(name))
                {
                    attribute = ForestBase.AttributeCache[name];

                    ret             = attribute.Syntax;
                    syntaxfromcache = attribute.SyntaxFromCache;

                    isBad = attribute.UnkownSyntax;

                    notfound = false;
                }

                if ((syntaxfromcache) && (ret == ActiveDirectorySyntax.OctetString))
                {
                    incache = AttributeIsInCache(ForestBase.ForestName, name, out ret, out isBad);

                    if ((incache) || (isBad))
                    {
                        attribute.UpdateSyntax(ret, isBad);

                        return(ret);
                    }

                    else
                    {
                        ActiveDirectorySyntax temp = SyntaxFromLiveSchema(name);

                        attribute.UpdateSyntax(temp);

                        ret = temp;

                        AddAttributeToCache(ForestBase.ForestName, name, ret, false);

                        return(ret);
                    }
                }

                if (notfound)
                {
                }
            }

            catch (Exception ex)
            { ex.ToDummy(); }

            return(ret);
        }
Exemple #31
0
        private void StoreAttributes(List <SearchResultEntry> attributeSchema)
        {
            foreach (SearchResultEntry entry in attributeSchema)
            {
                bool isdefunct = false;

                ActiveDirectorySyntax syntax = ActiveDirectorySyntax.CaseIgnoreString;

                if (entry.Attributes["isDefunct"] != null)
                {
                    string sdef = entry.Attributes["isDefunct"].GetValues(typeof(string))[0].ToString();

                    isdefunct = Boolean.Parse(sdef);
                }

                if (!isdefunct)
                {
                    #region name + syntax

                    string name = entry.Attributes["lDAPDisplayName"][0].ToString();

                    string asyntax = entry.Attributes["attributeSyntax"][0].ToString();

                    int omsyntax = 0;

                    if (Int32.TryParse(entry.Attributes["oMSyntax"][0].ToString(), out omsyntax))
                    {
                        syntax = DecodeLDAPAttributeSyntax(asyntax, omsyntax);
                    }

                    long systemflags = 0;

                    if (entry.Attributes.Contains("systemFlags"))
                    {
                        long.TryParse(entry.Attributes["systemFlags"][0].ToString(), out systemflags);
                    }

                    long linkid = 0;

                    if (entry.Attributes.Contains("linkID"))
                    {
                        long.TryParse(entry.Attributes["linkID"][0].ToString(), out linkid);
                    }



                    bool flags = false;
                    if ((systemflags & 4) == 4)
                    {
                        flags = true;
                    }

                    ForestBase.AttributeCache.Add(name, new AttributeSchema(name, syntax, flags, linkid));

                    ForestBase.CurrentAttributesNode.Add(new XElement(name, syntax.ToString(), new XAttribute("checked", "0"), new XAttribute("constructed", Convert.ToInt32(flags)), new XAttribute("linked", Convert.ToInt32(linkid))));

                    ForestBase.CurrentClassesNode.Elements("All").FirstOrDefault().Add(new XElement("Attribute", name));

                    #endregion

                    #region guids

                    string oid = String.Empty;

                    foreach (byte[] value in entry.Attributes["schemaIDGUID"].GetValues(typeof(byte[])))
                    {
                        oid = new Guid(value).ToString();

                        if (ForestBase.RightsGuids.AddSafe <string, string>(oid, name))
                        {
                            ForestBase.CurrentExtendedRightsNode.Add(new XElement("GUID" + oid.ToUpperInvariant(), name));
                        }
                    }

                    if (entry.Attributes.Contains("attributeSecurityGUID"))
                    {
                        foreach (byte[] value in entry.Attributes["attributeSecurityGUID"].GetValues(typeof(byte[])))
                        {
                            oid = new Guid(value).ToString();

                            if (ForestBase.RightsGuids.AddSafe <string, string>(oid, name))
                            {
                                ForestBase.CurrentExtendedRightsNode.Add(new XElement("GUID" + oid.ToUpperInvariant(), name));
                            }
                        }
                    }

                    #endregion
                }
            }
        }
Exemple #32
0
 public void UpdateSyntax(ActiveDirectorySyntax adSyntax, bool isBad = false)
 {
     Syntax          = adSyntax;
     SyntaxFromCache = false;
     UnkownSyntax    = isBad;
 }
		internal ActiveDirectorySchemaProperty(DirectoryContext context, string commonName, string ldapDisplayName, DirectoryEntry propertyEntry, DirectoryEntry schemaEntry)
		{
			this.syntax = ActiveDirectorySyntax.CaseIgnoreString | ActiveDirectorySyntax.NumericString | ActiveDirectorySyntax.DirectoryString | ActiveDirectorySyntax.OctetString | ActiveDirectorySyntax.SecurityDescriptor | ActiveDirectorySyntax.Int | ActiveDirectorySyntax.Int64 | ActiveDirectorySyntax.Bool | ActiveDirectorySyntax.Oid | ActiveDirectorySyntax.GeneralizedTime | ActiveDirectorySyntax.UtcTime | ActiveDirectorySyntax.DN | ActiveDirectorySyntax.DNWithBinary | ActiveDirectorySyntax.DNWithString | ActiveDirectorySyntax.Enumeration | ActiveDirectorySyntax.IA5String | ActiveDirectorySyntax.PrintableString | ActiveDirectorySyntax.Sid | ActiveDirectorySyntax.AccessPointDN | ActiveDirectorySyntax.ORName | ActiveDirectorySyntax.PresentationAddress | ActiveDirectorySyntax.ReplicaLink;
			this.rangeLower = null;
			this.rangeUpper = null;
			this.linkId = null;
			this.context = context;
			this.schemaEntry = schemaEntry;
			this.propertyEntry = propertyEntry;
			this.commonName = commonName;
			this.ldapDisplayName = ldapDisplayName;
			this.isDefunctOnServer = true;
			this.isDefunct = this.isDefunctOnServer;
			this.isBound = true;
		}