private NameValuePermission(NameValuePermission permit)   // deep-copy
 {
     _value = permit._value;
     _entry = permit._entry;
     _tree  = permit._tree;
     if (null != _tree)
     {
         NameValuePermission[] tree = (_tree.Clone() as NameValuePermission[]);
         int length = tree.Length;
         for (int i = 0; i < length; ++i)
         {
             tree[i] = tree[i].Copy(); // deep copy
         }
         _tree = tree;
     }
 }
        internal bool CheckValueForKeyPermit(DBConnectionString parsetable)
        {
            if (parsetable == null)
            {
                return(false);
            }
            bool isEmpty = false;

            NameValuePermission[] permissionArray = this._tree;
            if (permissionArray != null)
            {
                isEmpty = parsetable.IsEmpty;
                if (!isEmpty)
                {
                    for (int i = 0; i < permissionArray.Length; i++)
                    {
                        NameValuePermission permission = permissionArray[i];
                        if (permission != null)
                        {
                            string keyword = permission._value;
                            if (parsetable.ContainsKey(keyword))
                            {
                                string keyInQuestion            = parsetable[keyword];
                                NameValuePermission permission2 = permission.CheckKeyForValue(keyInQuestion);
                                if ((permission2 != null) && permission2.CheckValueForKeyPermit(parsetable))
                                {
                                    isEmpty = true;
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            DBConnectionString str = this._entry;

            if (str != null)
            {
                isEmpty = str.IsSupersetOf(parsetable);
            }
            return(isEmpty);
        }
 private NameValuePermission(NameValuePermission permit)
 {
     this._value = permit._value;
     this._entry = permit._entry;
     this._tree  = permit._tree;
     if (this._tree != null)
     {
         NameValuePermission[] permissionArray = this._tree.Clone() as NameValuePermission[];
         for (int i = 0; i < permissionArray.Length; i++)
         {
             if (permissionArray[i] != null)
             {
                 permissionArray[i] = permissionArray[i].CopyNameValue();
             }
         }
         this._tree = permissionArray;
     }
 }
Ejemplo n.º 4
0
        /// <include file='doc\OraclePermission.uex' path='docs/doc[@for="OraclePermission.AddWithAllow"]/*' />
        /// <internalonly />
        internal void Add(string connectionString, string restrictions, KeyRestrictionBehavior behavior)
        {
            switch (behavior)
            {
            case KeyRestrictionBehavior.PreventUsage:
            case KeyRestrictionBehavior.AllowOnly:
                break;

            default:
                throw ADP.Argument("value");
            }
            if (null == restrictions)
            {
                restrictions = ADP.StrEmpty;
            }
            DBConnectionString entry = new OracleConnectionString(connectionString, restrictions, behavior);

            if (!entry.ContainsPersistablePassword())
            {
                entry = new DBConnectionString(entry, true);
            }
            AddEntry(entry);
            _isUnrestricted = false; // MDAC 84639
        }
 private NameValuePermission(string value, DBConnectionString entry)
 {
     this._value = value;
     this._entry = entry;
 }
        internal bool CheckValueForKeyPermit(DBConnectionString parsetable)
        {
            if (null == parsetable)
            {
                return(false);
            }

            bool hasMatch = false;

            NameValuePermission[] keytree = _tree; // _tree won't mutate but Add will replace it
            if (null != keytree)
            {
                // which key do we follow the key-value chain on
                for (int i = 0; i < keytree.Length; ++i)
                {
                    NameValuePermission permitKey = keytree[i];
                    string keyword = permitKey._value;
#if DATAPERMIT
                    Debug.WriteLine("DBDataPermission keyword: <" + keyword + ">");
#endif
#if DEBUG
                    Debug.Assert(null == permitKey._entry, "key member has no restrictions");
#endif
                    if (parsetable.Contains(keyword))
                    {
                        string valueInQuestion = (string)parsetable[keyword];

                        // keyword is restricted to certain values
                        NameValuePermission permitValue = permitKey.CheckKeyForValue(valueInQuestion);
                        if (null != permitValue)
                        {
                            //value does match - continue the chain down that branch
                            if (permitValue.CheckValueForKeyPermit(parsetable))
                            {
                                hasMatch = true;
                            }
                            else
                            {
#if DATAPERMIT
                                Debug.WriteLine("DBDataPermission failed branch checking");
#endif
                                return(false);
                            }
                        }
                        else   // value doesn't match to expected values - fail here
                        {
#if DATAPERMIT
                            Debug.WriteLine("DBDataPermission failed to match expected value");
#endif
                            return(false);
                        }
                    }
                    // else try next keyword
                }
                // partial chain match, either leaf-node by shorter chain or fail mid-chain if (null == _restrictions)
            }
#if DATAPERMIT
            else
            {
                Debug.WriteLine("leaf node");
            }
#endif
            DBConnectionString entry = _entry;
            if (null != entry)
            {
                return(entry.IsSubsetOf(parsetable));
            }
#if DATAPERMIT
            Debug.WriteLine("DBDataPermission failed on non-terminal node");
#endif
            return(hasMatch); // mid-chain failure
        }