Esempio n. 1
0
 internal static void SingleScalarFromDirectoryEntry <T>(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName)
 {
     if (properties[suggestedProperty].Count != 0 && properties[suggestedProperty][0] != null)
     {
         p.LoadValueIntoProperty(propertyName, (T)properties[suggestedProperty][0]);
     }
 }
Esempio n. 2
0
        //
        // S.DS (LDAP or WinNT) --> PAPI conversion routines
        //
        static internal void SingleScalarFromDirectoryEntry <T>(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName)
        {
            if (properties[suggestedProperty].Count != 0 && properties[suggestedProperty][0] != null)
            {
                // We're intended to handle single-valued scalar properties
                Debug.Assert(properties[suggestedProperty].Count == 1);
                Debug.Assert(properties[suggestedProperty][0] is T);

                p.LoadValueIntoProperty(propertyName, (T)properties[suggestedProperty][0]);
            }
        }
Esempio n. 3
0
        internal static void AccountControlFromDirectoryEntry(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName, bool testCantChangePassword)
        {
            dSPropertyValueCollection item = properties[suggestedProperty];

            if (item.Count != 0)
            {
                int  num  = (int)item[0];
                bool flag = SDSUtils.StatusFromAccountControl(num, propertyName);
                p.LoadValueIntoProperty(propertyName, flag);
            }
        }
Esempio n. 4
0
        internal static void MultiScalarFromDirectoryEntry <T>(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName)
        {
            dSPropertyValueCollection item = properties[suggestedProperty];
            List <T> ts = new List <T>();

            foreach (object obj in item)
            {
                ts.Add((T)obj);
            }
            p.LoadValueIntoProperty(propertyName, ts);
        }
Esempio n. 5
0
        static internal void MultiScalarFromDirectoryEntry <T>(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName)
        {
            dSPropertyValueCollection values = properties[suggestedProperty];

            List <T> list = new List <T>();

            foreach (object value in values)
            {
                Debug.Assert(value is T);

                list.Add((T)value);
            }

            p.LoadValueIntoProperty(propertyName, list);
        }
Esempio n. 6
0
        static internal void AccountControlFromDirectoryEntry(dSPropertyCollection properties, string suggestedProperty, Principal p, string propertyName, bool testCantChangePassword)
        {
            Debug.Assert(
                (!testCantChangePassword && (String.Equals(suggestedProperty, "userAccountControl", StringComparison.OrdinalIgnoreCase))) ||
                (testCantChangePassword && (String.Equals(suggestedProperty, "UserFlags", StringComparison.OrdinalIgnoreCase)))
                );

            Debug.Assert(!String.Equals(propertyName, PropertyNames.PwdInfoCannotChangePassword, StringComparison.OrdinalIgnoreCase) || testCantChangePassword);

            dSPropertyValueCollection values = properties[suggestedProperty];

            if (values.Count != 0)
            {
                Debug.Assert(values.Count == 1);
                Debug.Assert(values[0] is int);

                int  uacValue = (int)values[0];
                bool flag;

                flag = StatusFromAccountControl(uacValue, propertyName);

                p.LoadValueIntoProperty(propertyName, flag);
            }
        }
Esempio n. 7
0
 protected static void BinaryFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
 {
     SDSUtils.SingleScalarFromDirectoryEntry<byte[]>(properties, suggestedAdProperty, p, propertyName);
 }
Esempio n. 8
0
        protected static void GroupTypeFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            Debug.Assert(String.Compare(suggestedAdProperty, "groupType", StringComparison.OrdinalIgnoreCase) == 0);

            dSPropertyValueCollection values = properties[suggestedAdProperty];

            if (values.Count != 0)
            {
                Debug.Assert(values.Count == 1);
                Debug.Assert(values[0] is int);

                int groupTypeCombined = (int)values[0];

                switch (propertyName)
                {
                    case PropertyNames.GroupIsSecurityGroup:

                        bool isSecurityEnabled = false;

                        // GROUP_TYPE_SECURITY_ENABLED
                        if ((groupTypeCombined & 0x80000000) != 0)
                            isSecurityEnabled = true;

                        // isSecurityEnabled --> group IS enabled
                        p.LoadValueIntoProperty(propertyName, isSecurityEnabled);
                        break;

                    case PropertyNames.GroupGroupScope:

                        GroupScope groupType = GroupScope.Universal;

                        if ((groupTypeCombined & ADGroupScope.Global) != 0) // ADS_GROUP_TYPE_GLOBAL_GROUP
                            groupType = GroupScope.Global;
                        else if ((groupTypeCombined & ADGroupScope.Local) != 0) // ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
                            groupType = GroupScope.Local;
                        else
                            Debug.Assert((groupTypeCombined & ADGroupScope.Universal) != 0); // ADS_GROUP_TYPE_UNIVERSAL_GROUP

                        p.LoadValueIntoProperty(propertyName, groupType);
                        break;

                    default:
                        Debug.Fail("ADStoreCtx.GroupTypeFromLdapConverter: Fell off end looking for " + propertyName);
                        break;
                }
            }
        }
Esempio n. 9
0
        protected static void DateTimeFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName, bool useAcctExpLogic)
        {
            dSPropertyValueCollection values = properties[suggestedAdProperty];

            if (values.Count != 0)
            {
                Debug.Assert(values.Count == 1);

                Int64 filetime;

                if (values[0] is Int64)
                    filetime = (Int64)values[0];
                else
                    filetime = ADUtils.LargeIntToInt64((UnsafeNativeMethods.IADsLargeInteger)values[0]);

                Nullable<DateTime> dt;

                // Filetimes use "0" to mean "no value, except for accountExpires,
                // which uses both "0" and "0x7fffffffffffffff"  to mean "no expiration date"
                if ((!useAcctExpLogic) && (filetime == 0x0))
                    dt = null;
                else if ((useAcctExpLogic) && (filetime == 0x0 || filetime == 0x7fffffffffffffff))
                    dt = null;
                else
                    dt = ADUtils.ADFileTimeToDateTime(filetime);

                p.LoadValueIntoProperty(propertyName, dt);
            }
        }
Esempio n. 10
0
 protected static void AcctExpirFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
 {
     DateTimeFromLdapConverter(properties, suggestedAdProperty, p, propertyName, true);
 }
Esempio n. 11
0
        protected static void LastLogonFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            // W2k DCs support just "lastLogon".  W2k3 DCs also support "lastLogonTimestamp".  The latter is replicated, and
            // preferred over the former.
            if (String.Compare(suggestedAdProperty, "lastLogon", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Is "lastLogonTimestamp" available instead?

                if (properties["lastLogonTimestamp"].Count != 0)
                {
                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "LastLogonFromLdapConverter: found lastLogonTimestamp");

                    // "lastLogonTimestamp" is available.  So ignore "lastLogon" and do nothing.  We'll be called again
                    // when Load() gets to the "lastLogonTimestamp" attribute (or it may already have).
                    return;
                }
            }

            // Either we're processing "lastLogonTimestamp", or there is no "lastLogonTimestamp" and we're processing "lastLogon".
            // Either way, it's handled like a generic date.
            DateTimeFromLdapConverter(properties, suggestedAdProperty, p, propertyName, false);
        }
Esempio n. 12
0
        protected static void ObjectClassFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            dSPropertyValueCollection values = properties[suggestedAdProperty];

            if (values.Count > 0)
            {
                // This is a multivalued attribute and we want the last element.  The most specialized object class...
                Debug.Assert(values[values.Count - 1] is string);
                p.LoadValueIntoProperty(propertyName, (string)values[values.Count - 1]);
            }
        }
        internal override bool MoveNext()
        {
            string str;
            dSPropertyCollection _dSPropertyCollection;
            bool flag = false;

            if (base.MoveNext())
            {
                while (!flag)
                {
                    if (this.current != null)
                    {
                        ADDNConstraintLinkedAttrSet.ConstraintType constraintType = this.constraint;
                        switch (constraintType)
                        {
                        case ADDNConstraintLinkedAttrSet.ConstraintType.ContainerStringMatch:
                        {
                            if (this.current as SearchResult == null)
                            {
                                str = ((DirectoryEntry)this.current).Properties["distinguishedName"].Value.ToString();
                            }
                            else
                            {
                                str = ((SearchResult)this.current).Properties["distinguishedName"][0].ToString();
                            }
                            if (!str.EndsWith((string)this.constraintData, StringComparison.Ordinal))
                            {
                                break;
                            }
                            flag = true;
                            break;
                        }

                        case ADDNConstraintLinkedAttrSet.ConstraintType.ResultValidatorDelegateMatch:
                        {
                            ADDNConstraintLinkedAttrSet.ResultValidator resultValidator = this.constraintData as ADDNConstraintLinkedAttrSet.ResultValidator;
                            if (resultValidator == null)
                            {
                                break;
                            }
                            if (this.current as SearchResult == null)
                            {
                                _dSPropertyCollection = new dSPropertyCollection(((DirectoryEntry)this.current).Properties);
                            }
                            else
                            {
                                _dSPropertyCollection = new dSPropertyCollection(((SearchResult)this.current).Properties);
                            }
                            flag = resultValidator(_dSPropertyCollection);
                            break;
                        }
                        }
                        if (flag || this.MoveNext())
                        {
                            continue;
                        }
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(flag);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 14
0
        internal override void Load(Principal p, string principalPropertyName)
        {
            Debug.Assert(p != null);
            Debug.Assert(p.UnderlyingObject != null);
            Debug.Assert(p.UnderlyingObject is DirectoryEntry);

            dSPropertyCollection props;

            SearchResult sr = (SearchResult)p.UnderlyingSearchObject;
            if (null == sr)
            {
                DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;
                Debug.Assert(de != null);
                Debug.Assert(p.GetUnderlyingObjectType() == typeof(DirectoryEntry));

                props = new dSPropertyCollection(de.Properties);
            }
            else
            {
                props = new dSPropertyCollection(sr.Properties);
            }

            Hashtable propertyMappingTable = (Hashtable)s_propertyMappingTableByPropertyFull[this.MappingTableIndex];

            ArrayList entries = (ArrayList)propertyMappingTable[principalPropertyName];

            // We don't support this property and cannot load it.  To maintain backward compatibility with the old code just return.
            if (entries == null)
                return;

            Debug.Assert(null != entries);

            try
            {
                foreach (PropertyMappingTableEntry entry in entries)
                {
                    if (null != entry.ldapToPapiConverter)
                    {
                        GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADStoreCtx", "Load_PropertyName: loading {0}", entry.propertyName);
                        entry.ldapToPapiConverter(props, entry.suggestedADPropertyName, p, entry.propertyName);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(e);
            }
        }
Esempio n. 15
0
        //
        // Conversion: LDAP --> PAPI
        //
        protected static void SidFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            if (properties["objectSid"].Count > 0)
            {
                byte[] sid = (byte[])properties["objectSid"][0];

                SecurityIdentifier SecurityId = new SecurityIdentifier(sid, 0);

                p.LoadValueIntoProperty(propertyName, (object)SecurityId);
            }
            else
            {
                p.LoadValueIntoProperty(propertyName, null);
            }
        }
Esempio n. 16
0
        protected static void CommaStringFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            Debug.Assert(String.Compare(suggestedAdProperty, "userWorkstations", StringComparison.OrdinalIgnoreCase) == 0);

            // The userWorkstations attribute is odd.  Rather than being a multivalued string attribute, it's a single-valued
            // string of comma-separated values.

            dSPropertyValueCollection values = properties[suggestedAdProperty];

            if (values.Count != 0)
            {
                Debug.Assert(values.Count == 1);
                Debug.Assert(values[0] is string);

                string commaSeparatedValues = (string)values[0];
                string[] individualValues = commaSeparatedValues.Split(new char[] { ',' });

                // ValueCollection<string> is Load'ed from a List<string>
                List<string> list = new List<string>(individualValues.Length);

                foreach (string s in individualValues)
                {
                    list.Add(s);
                }

                p.LoadValueIntoProperty(propertyName, list);
            }
        }
Esempio n. 17
0
        // This function is converting the disabled directory status into the enabled principal property
        // the boolan value needs to be negated
        protected static void AcctDisabledFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            if (properties[suggestedAdProperty].Count > 0)
            {
                // We're intended to handle single-valued scalar properties
                Debug.Assert(properties[suggestedAdProperty].Count == 1);
                Debug.Assert(properties[suggestedAdProperty][0] is bool);

                p.LoadValueIntoProperty(propertyName, !(bool)properties[suggestedAdProperty][0]);
            }
        }
Esempio n. 18
0
 protected static void MultiStringFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
 {
     // ValueCollection<string> is Load'ed from a List<string>
     SDSUtils.MultiScalarFromDirectoryEntry<string>(properties, suggestedAdProperty, p, propertyName);
 }
Esempio n. 19
0
        protected static void GuidFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            Debug.Assert(properties["objectGuid"].Count == 1);

            if (properties["objectGuid"].Count == 1)
            {
                byte[] guid = (byte[])properties["objectGuid"][0];

                Guid g = new Guid(guid);

                p.LoadValueIntoProperty(propertyName, g);
            }
            else
            {
                p.LoadValueIntoProperty(propertyName, null);
            }
        }
Esempio n. 20
0
		internal override bool MoveNext()
		{
			string str;
			dSPropertyCollection _dSPropertyCollection;
			bool flag = false;
			if (base.MoveNext())
			{
				while (!flag)
				{
					if (this.current != null)
					{
						ADDNConstraintLinkedAttrSet.ConstraintType constraintType = this.constraint;
						switch (constraintType)
						{
							case ADDNConstraintLinkedAttrSet.ConstraintType.ContainerStringMatch:
							{
								if (this.current as SearchResult == null)
								{
									str = ((DirectoryEntry)this.current).Properties["distinguishedName"].Value.ToString();
								}
								else
								{
									str = ((SearchResult)this.current).Properties["distinguishedName"][0].ToString();
								}
								if (!str.EndsWith((string)this.constraintData, StringComparison.Ordinal))
								{
									break;
								}
								flag = true;
								break;
							}
							case ADDNConstraintLinkedAttrSet.ConstraintType.ResultValidatorDelegateMatch:
							{
								ADDNConstraintLinkedAttrSet.ResultValidator resultValidator = this.constraintData as ADDNConstraintLinkedAttrSet.ResultValidator;
								if (resultValidator == null)
								{
									break;
								}
								if (this.current as SearchResult == null)
								{
									_dSPropertyCollection = new dSPropertyCollection(((DirectoryEntry)this.current).Properties);
								}
								else
								{
									_dSPropertyCollection = new dSPropertyCollection(((SearchResult)this.current).Properties);
								}
								flag = resultValidator(_dSPropertyCollection);
								break;
							}
						}
						if (flag || this.MoveNext())
						{
							continue;
						}
						return false;
					}
					else
					{
						return false;
					}
				}
				return flag;
			}
			else
			{
				return false;
			}
		}
Esempio n. 21
0
 protected static void CertFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
 {
     // Cert collection is Load'ed via a list of byte[], each representing a cert
     SDSUtils.MultiScalarFromDirectoryEntry<byte[]>(properties, suggestedAdProperty, p, propertyName);
 }
Esempio n. 22
0
        protected static void UACFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
        {
            Debug.Assert(String.Compare(suggestedAdProperty, "userAccountControl", StringComparison.OrdinalIgnoreCase) == 0);

            SDSUtils.AccountControlFromDirectoryEntry(properties, suggestedAdProperty, p, propertyName, false);
        }
Esempio n. 23
0
 protected static void GenericDateTimeFromLdapConverter(dSPropertyCollection properties, string suggestedAdProperty, Principal p, string propertyName)
 {
     DateTimeFromLdapConverter(properties, suggestedAdProperty, p, propertyName, false);
 }
Esempio n. 24
0
        internal override bool MoveNext()
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Entering MoveNext");
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Filter {0}", _constraintData);
            bool   match = false;
            string dn    = "NotSet";

            if (!base.MoveNext())
            {
                return(false);
            }
            else
            {
                while (!match)
                {
                    if (null == this.current)
                    {
                        return(false);
                    }

                    switch (_constraint)
                    {
                    case ConstraintType.ContainerStringMatch:

                        if (this.current is SearchResult)
                        {
                            dn = ((SearchResult)this.current).Properties["distinguishedName"][0].ToString();
                        }
                        else
                        {
                            dn = ((DirectoryEntry)this.current).Properties["distinguishedName"].Value.ToString();
                        }

                        if (dn.EndsWith((string)_constraintData, StringComparison.Ordinal))
                        {
                            match = true;
                        }

                        break;

                    case ConstraintType.ResultValidatorDelegateMatch:
                    {
                        ResultValidator resultValidator = _constraintData as ResultValidator;
                        if (resultValidator != null)
                        {
                            dSPropertyCollection resultPropCollection = null;
                            if (this.current is SearchResult)
                            {
                                resultPropCollection = new dSPropertyCollection(((SearchResult)this.current).Properties);
                            }
                            else
                            {
                                resultPropCollection = new dSPropertyCollection(((DirectoryEntry)this.current).Properties);
                            }
                            match = resultValidator.Invoke(resultPropCollection);
                        }
                        else
                        {
                            Debug.Fail("ADStoreCtx.ADDNConstraintLinkedAttrSet: Invalid constraint data. Expected: object of type ResultValidator");
                        }
                        break;
                    }

                    default:
                        Debug.Fail("ADStoreCtx.ADDNConstraintLinkedAttrSet: fell off end looking for " + _constraint.ToString());
                        break;
                    }

                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Found {0} Match {1}", dn, match.ToString());

                    if (!match)
                    {
                        if (!this.MoveNext())
                        {
                            return(false);
                        }
                    }
                }

                return(match);
            }
        }
        override internal bool MoveNext()
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Entering MoveNext");
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Filter {0}", _constraintData);
            bool match = false;
            string dn = "NotSet";

            if (!base.MoveNext())
                return false;
            else
            {
                while (!match)
                {
                    if (null == this.current)
                        return false;

                    switch (_constraint)
                    {
                        case ConstraintType.ContainerStringMatch:

                            if (this.current is SearchResult)
                                dn = ((SearchResult)this.current).Properties["distinguishedName"][0].ToString();
                            else
                                dn = ((DirectoryEntry)this.current).Properties["distinguishedName"].Value.ToString();

                            if (dn.EndsWith((string)_constraintData, StringComparison.Ordinal))
                                match = true;

                            break;
                        case ConstraintType.ResultValidatorDelegateMatch:
                            {
                                ResultValidator resultValidator = _constraintData as ResultValidator;
                                if (resultValidator != null)
                                {
                                    dSPropertyCollection resultPropCollection = null;
                                    if (this.current is SearchResult)
                                    {
                                        resultPropCollection = new dSPropertyCollection(((SearchResult)this.current).Properties);
                                    }
                                    else
                                    {
                                        resultPropCollection = new dSPropertyCollection(((DirectoryEntry)this.current).Properties);
                                    }
                                    match = resultValidator.Invoke(resultPropCollection);
                                }
                                else
                                {
                                    Debug.Fail("ADStoreCtx.ADDNConstraintLinkedAttrSet: Invalid constraint data. Expected: object of type ResultValidator");
                                }
                                break;
                            }
                        default:
                            Debug.Fail("ADStoreCtx.ADDNConstraintLinkedAttrSet: fell off end looking for " + _constraint.ToString());
                            break;
                    }

                    GlobalDebug.WriteLineIf(GlobalDebug.Info, "ADDNConstraintLinkedAttrSet", "Found {0} Match {1}", dn, match.ToString());

                    if (!match)
                        if (!this.MoveNext())
                            return false;
                }

                return match;
            }
        }