예제 #1
0
		internal ADPropertyValueCollection ConvertFromRawAsString(DirectoryAttribute property)
		{
			if (property == null || property.Count == 0)
			{
				return null;
			}
			else
			{
				ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection(property.GetValues(typeof(string)));
				return aDPropertyValueCollection;
			}
		}
        //
        // This function goes through each of the object class values for the container to determine
        // whether the object class is one of the possible superiors of the user object
        //
        private bool ContainerIsSuperiorOfUser(DirectoryAttribute objectClass)
        {
            ArrayList possibleSuperiorsList = new ArrayList();

            //
            // first get a list of all the classes from which the user class is derived
            //
            DirectoryEntry de = new DirectoryEntry(GetADsPath("schema") + "/user", GetUsername(), GetPassword(), AuthenticationTypes);
            ArrayList classesList = new ArrayList();
            bool derivedFromlistEmpty = false;
            object value = null;

            try
            {
                value = de.InvokeGet("DerivedFrom");
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int) 0x8000500D))
                {
                    derivedFromlistEmpty = true;
                }
                else
                    throw;
            }

            if (!derivedFromlistEmpty)
            {
                if (value is ICollection)
                {
                    classesList.AddRange((ICollection) value);
                }
                else
                {
                    // single value
                    classesList.Add((string) value);
                }
            }

            //
            // we will use this list to create a filter of all the classSchema objects that we need to determine the recursive list
            // of "possibleSecuperiors". We need to add the user class also.
            //
            classesList.Add("user");

            //
            // Now search under the schema naming context for all these classes and get the "possSuperiors" and "systemPossSuperiors" attributes
            //
            DirectoryEntry schemaNC = new DirectoryEntry(GetADsPath((string) rootdse.Properties["schemaNamingContext"].Value), GetUsername(), GetPassword(), AuthenticationTypes);
            DirectorySearcher searcher = new DirectorySearcher(schemaNC);

            searcher.Filter = "(&(objectClass=classSchema)(|";
            foreach(string supClass in classesList)
                searcher.Filter += "(ldapDisplayName=" + supClass + ")";
            searcher.Filter += "))";

            searcher.SearchScope = System.DirectoryServices.SearchScope.OneLevel;
            searcher.PropertiesToLoad.Add("possSuperiors");
            searcher.PropertiesToLoad.Add("systemPossSuperiors");

            SearchResultCollection resCol = searcher.FindAll();

            try
            {
                foreach (SearchResult res in resCol)
                {
                    possibleSuperiorsList.AddRange(res.Properties["possSuperiors"]);
                    possibleSuperiorsList.AddRange(res.Properties["systemPossSuperiors"]);
                }
            }
            finally
            {
                resCol.Dispose();
            }

            //
            // Now we have the list of all the possible superiors, check if the objectClass that was specified as a parameter
            // to this function is one of these values, if so, return true else false
            //
            foreach (string objectClassValue in objectClass.GetValues(typeof(string)))
            {
                if (possibleSuperiorsList.Contains(objectClassValue))
                    return true;
            }

            return false;
        }
예제 #3
0
		internal ADPropertyValueCollection ConvertFromRaw(DirectoryAttribute property)
		{
			string str = null;
			int num = 0;
			this.Init();
			if (property == null || property.Count == 0)
			{
				return null;
			}
			else
			{
				ADPropertyValueCollection aDPropertyValueCollection = new ADPropertyValueCollection();
				ADObjectSearcher.ContainsRangeRetrievalTag(property.Name, out str, out num);
				ADAttributeSyntax propertyType = this._adSchema.GetPropertyType(str);
				string[] values = null;
				byte[][] numArray = null;
				ADAttributeSyntax aDAttributeSyntax = propertyType;
				switch (aDAttributeSyntax)
				{
					case ADAttributeSyntax.DirectoryString:
					case ADAttributeSyntax.DN:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
					case ADAttributeSyntax.OctetString:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
						break;
					}
					case ADAttributeSyntax.SecurityDescriptor:
					{
						numArray = (byte[][])property.GetValues(typeof(byte[]));
						byte[][] numArray1 = numArray;
						for (int i = 0; i < (int)numArray1.Length; i++)
						{
							byte[] numArray2 = numArray1[i];
							ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();
							activeDirectorySecurity.SetSecurityDescriptorBinaryForm(numArray2);
							aDPropertyValueCollection.Add(activeDirectorySecurity);
						}
						break;
					}
					case ADAttributeSyntax.Int:
					case ADAttributeSyntax.Enumeration:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays = values;
						for (int j = 0; j < (int)strArrays.Length; j++)
						{
							string str1 = strArrays[j];
							aDPropertyValueCollection.Add(int.Parse(str1, NumberFormatInfo.InvariantInfo));
						}
						break;
					}
					case ADAttributeSyntax.Int64:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays1 = values;
						for (int k = 0; k < (int)strArrays1.Length; k++)
						{
							string str2 = strArrays1[k];
							aDPropertyValueCollection.Add(long.Parse(str2, NumberFormatInfo.InvariantInfo));
						}
						break;
					}
					case ADAttributeSyntax.Bool:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays2 = values;
						for (int l = 0; l < (int)strArrays2.Length; l++)
						{
							string str3 = strArrays2[l];
							if (string.Compare(str3, "TRUE", StringComparison.OrdinalIgnoreCase) != 0)
							{
								aDPropertyValueCollection.Add(false);
							}
							else
							{
								aDPropertyValueCollection.Add(true);
							}
						}
						break;
					}
					case ADAttributeSyntax.Oid:
					case ADAttributeSyntax.DNWithBinary:
					case ADAttributeSyntax.DNWithString:
					case ADAttributeSyntax.IA5String:
					case ADAttributeSyntax.PrintableString:
					{
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
					case ADAttributeSyntax.GeneralizedTime:
					case ADAttributeSyntax.UtcTime:
					{
						values = (string[])property.GetValues(typeof(string));
						string[] strArrays3 = values;
						for (int m = 0; m < (int)strArrays3.Length; m++)
						{
							string str4 = strArrays3[m];
							aDPropertyValueCollection.Add(ADTypeConverter.ParseDateTimeValue(str4, propertyType));
						}
						break;
					}
					case ADAttributeSyntax.Sid:
					{
						numArray = (byte[][])property.GetValues(typeof(byte[]));
						byte[][] numArray3 = numArray;
						for (int n = 0; n < (int)numArray3.Length; n++)
						{
							byte[] numArray4 = numArray3[n];
							aDPropertyValueCollection.Add(new SecurityIdentifier(numArray4, 0));
						}
						break;
					}
					default:
					{
						if (aDAttributeSyntax == ADAttributeSyntax.ReplicaLink)
						{
							aDPropertyValueCollection.AddRange(property.GetValues(typeof(byte[])));
							break;
						}
						aDPropertyValueCollection.AddRange(property.GetValues(typeof(string)));
						break;
					}
				}
				return aDPropertyValueCollection;
			}
		}