internal DBDataPermission(DbConnectionOptions connectionOptions)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (connectionOptions != null)
     {
         this._allowBlankPassword = connectionOptions.HasBlankPassword;
         this.AddPermissionEntry(new DBConnectionString(connectionOptions));
     }
 }
 protected DBDataPermission(DBDataPermission permission)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (permission == null)
     {
         throw ADP.ArgumentNull("permissionAttribute");
     }
     this.CopyFrom(permission);
 }
        internal void Intersect(ArrayList entries, NameValuePermission target)
        {
            if (null == target)
            {
                _tree  = null;
                _entry = null;
            }
            else
            {
                if (null != _entry)
                {
                    entries.Remove(_entry);
                    _entry = _entry.Intersect(target._entry);
                    entries.Add(_entry);
                }
                else if (null != target._entry)
                {
                    _entry = target._entry.Intersect(null);
                    entries.Add(_entry);
                }

                if (null != _tree)
                {
                    int count = _tree.Length;
                    for (int i = 0; i < _tree.Length; ++i)
                    {
                        NameValuePermission kvtree = target.CheckKeyForValue(_tree[i]._value);
                        if (null != kvtree)
                        { // does target tree contain our value
                            _tree[i].Intersect(entries, kvtree);
                        }
                        else
                        {
                            _tree[i] = null;
                            --count;
                        }
                    }
                    if (0 == count)
                    {
                        _tree = null;
                    }
                    else if (count < _tree.Length)
                    {
                        NameValuePermission[] kvtree = new NameValuePermission[count];
                        for (int i = 0, j = 0; i < _tree.Length; ++i)
                        {
                            if (null != _tree[i])
                            {
                                kvtree[j++] = _tree[i];
                            }
                        }
                        _tree = kvtree;
                    }
                }
            }
        }
 internal static void AddEntry(NameValuePermission kvtree, ArrayList entries, DBConnectionString entry)
 {
     if (entry.KeyChain != null)
     {
         for (NameValuePair pair = entry.KeyChain; pair != null; pair = pair.Next)
         {
             NameValuePermission permit = kvtree.CheckKeyForValue(pair.Name);
             if (permit == null)
             {
                 permit = new NameValuePermission(pair.Name);
                 kvtree.Add(permit);
             }
             kvtree = permit;
             permit = kvtree.CheckKeyForValue(pair.Value);
             if (permit == null)
             {
                 DBConnectionString str2 = (pair.Next != null) ? null : entry;
                 permit = new NameValuePermission(pair.Value, str2);
                 kvtree.Add(permit);
                 if (str2 != null)
                 {
                     entries.Add(str2);
                 }
             }
             else if (pair.Next == null)
             {
                 if (permit._entry != null)
                 {
                     entries.Remove(permit._entry);
                     permit._entry = permit._entry.Intersect(entry);
                 }
                 else
                 {
                     permit._entry = entry;
                 }
                 entries.Add(permit._entry);
             }
             kvtree = permit;
         }
     }
     else
     {
         DBConnectionString str = kvtree._entry;
         if (str != null)
         {
             entries.Remove(str);
             kvtree._entry = str.Intersect(entry);
         }
         else
         {
             kvtree._entry = entry;
         }
         entries.Add(kvtree._entry);
     }
 }
 /// <include file='doc\DBDataPermission.uex' path='docs/doc[@for="DBDataPermission.Clear"]/*' />
 protected void Clear()   // MDAC 83105
 {
     try {
         lock (this) {
             _keyvaluetree = null;
             _keyvalues    = null;
         }
     }
     catch {
         throw;
     }
 }
Exemple #6
0
 internal void AddPermissionEntry(DBConnectionString entry)
 {
     if (null == _keyvaluetree)
     {
         _keyvaluetree = new NameValuePermission();
     }
     if (null == _keyvalues)
     {
         _keyvalues = new ArrayList();
     }
     NameValuePermission.AddEntry(_keyvaluetree, _keyvalues, entry);
     _isUnrestricted = false; // MDAC 84639
 }
 internal void AddPermissionEntry(DBConnectionString entry)
 {
     if (this._keyvaluetree == null)
     {
         this._keyvaluetree = new NameValuePermission();
     }
     if (this._keyvalues == null)
     {
         this._keyvalues = new ArrayList();
     }
     NameValuePermission.AddEntry(this._keyvaluetree, this._keyvalues, entry);
     this._isUnrestricted = false;
 }
        private void Add(NameValuePermission permit)
        {
            NameValuePermission[] permissionArray2 = this._tree;
            int index = (permissionArray2 != null) ? permissionArray2.Length : 0;

            NameValuePermission[] array = new NameValuePermission[1 + index];
            for (int i = 0; i < (array.Length - 1); i++)
            {
                array[i] = permissionArray2[i];
            }
            array[index] = permit;
            Array.Sort <NameValuePermission>(array);
            this._tree = array;
        }
        static internal void AddEntry(NameValuePermission kvtree, ArrayList entries, DBConnectionString entry) {
            Debug.Assert(null != entry, "null DBConnectionString");

            if (null != entry.KeyChain) {
                for(NameValuePair keychain = entry.KeyChain; null != keychain; keychain = keychain.Next) {
                    NameValuePermission kv;

                    kv = kvtree.CheckKeyForValue(keychain.Name);
                    if (null == kv) {
                        kv = new NameValuePermission(keychain.Name);
                        kvtree.Add(kv); // add directly into live tree
                    }
                    kvtree = kv;

                    kv = kvtree.CheckKeyForValue(keychain.Value);
                    if (null == kv) {
                        DBConnectionString insertValue = ((null != keychain.Next) ? null : entry);
                        kv = new NameValuePermission(keychain.Value, insertValue);
                        kvtree.Add(kv); // add directly into live tree
                        if (null != insertValue) {
                            entries.Add(insertValue);
                        }
                    }
                    else if (null == keychain.Next) { // shorter chain potential
                        if (null != kv._entry) {
                            Debug.Assert(entries.Contains(kv._entry), "entries doesn't contain entry");
                            entries.Remove(kv._entry);
                            kv._entry = kv._entry.Intersect(entry); // union new restrictions into existing tree
                        }
                        else {
                            kv._entry = entry;
                        }
                        entries.Add(kv._entry);
                    }
                    kvtree = kv;
                }
            }
            else { // global restrictions, MDAC 84443
                DBConnectionString kentry = kvtree._entry;
                if (null != kentry) {
                    Debug.Assert(entries.Contains(kentry), "entries doesn't contain entry");
                    entries.Remove(kentry);
                    kvtree._entry = kentry.Intersect(entry);
                }
                else {
                    kvtree._entry = entry;
                }
                entries.Add(kvtree._entry);
            }
        }
 private NameValuePermission(NameValuePermission permit) { // deep-copy
     _value = permit._value;
     _entry = permit._entry;
     _tree = permit._tree;
     if (null != _tree) {
         NameValuePermission[] tree = (_tree.Clone() as NameValuePermission[]);
         for(int i = 0; i < tree.Length; ++i) {
             if (null != tree[i]) { // WebData 98488
                 tree[i] = tree[i].CopyNameValue(); // deep copy
             }
         }
         _tree = tree;
     }
 }
Exemple #11
0
        private void Add(NameValuePermission permit)
        {
            NameValuePermission[] tree = _tree;
            int length = ((null != tree) ? tree.Length : 0);

            NameValuePermission[] newtree = new NameValuePermission[1 + length];
            for (int i = 0; i < newtree.Length - 1; ++i)
            {
                newtree[i] = tree[i];
            }
            newtree[length] = permit;
            Array.Sort(newtree);
            _tree = newtree;
        }
 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;
     }
 }
 protected DBDataPermission(PermissionState state)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (state == PermissionState.Unrestricted)
     {
         this._isUnrestricted = true;
     }
     else
     {
         if (state != PermissionState.None)
         {
             throw ADP.InvalidPermissionState(state);
         }
         this._isUnrestricted = false;
     }
 }
Exemple #14
0
 private NameValuePermission CheckKeyForValue(string keyInQuestion)
 {
     NameValuePermission[] valuetree = _tree; // _tree won't mutate but Add will replace it
     if (null != valuetree)
     {
         for (int i = 0; i < valuetree.Length; ++i)
         {
             NameValuePermission permitValue = valuetree[i];
             if (string.Equals(keyInQuestion, permitValue._value, StringComparison.OrdinalIgnoreCase))
             {
                 return(permitValue);
             }
         }
     }
     return(null);
 }
 protected DBDataPermission(PermissionState state)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (state == PermissionState.Unrestricted)
     {
         this._isUnrestricted = true;
     }
     else
     {
         if (state != PermissionState.None)
         {
             throw ADP.InvalidPermissionState(state);
         }
         this._isUnrestricted = false;
     }
 }
 private void CopyFrom(DBDataPermission permission)
 {
     this._isUnrestricted = permission.IsUnrestricted();
     if (!this._isUnrestricted)
     {
         this._allowBlankPassword = permission.AllowBlankPassword;
         if (permission._keyvalues != null)
         {
             this._keyvalues = (ArrayList)permission._keyvalues.Clone();
             if (permission._keyvaluetree != null)
             {
                 this._keyvaluetree = permission._keyvaluetree.CopyNameValue();
             }
         }
     }
 }
 private NameValuePermission CheckKeyForValue(string keyInQuestion)
 {
     NameValuePermission[] permissionArray = this._tree;
     if (permissionArray != null)
     {
         for (int i = 0; i < permissionArray.Length; i++)
         {
             NameValuePermission permission = permissionArray[i];
             if (string.Equals(keyInQuestion, permission._value, StringComparison.OrdinalIgnoreCase))
             {
                 return(permission);
             }
         }
     }
     return(null);
 }
 protected DBDataPermission(DBDataPermissionAttribute permissionAttribute)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (permissionAttribute == null)
     {
         throw ADP.ArgumentNull("permissionAttribute");
     }
     this._isUnrestricted = permissionAttribute.Unrestricted;
     if (!this._isUnrestricted)
     {
         this._allowBlankPassword = permissionAttribute.AllowBlankPassword;
         if (permissionAttribute.ShouldSerializeConnectionString() || permissionAttribute.ShouldSerializeKeyRestrictions())
         {
             this.Add(permissionAttribute.ConnectionString, permissionAttribute.KeyRestrictions, permissionAttribute.KeyRestrictionBehavior);
         }
     }
 }
 protected DBDataPermission(DBDataPermissionAttribute permissionAttribute)
 {
     this._keyvaluetree = NameValuePermission.Default;
     if (permissionAttribute == null)
     {
         throw ADP.ArgumentNull("permissionAttribute");
     }
     this._isUnrestricted = permissionAttribute.Unrestricted;
     if (!this._isUnrestricted)
     {
         this._allowBlankPassword = permissionAttribute.AllowBlankPassword;
         if (permissionAttribute.ShouldSerializeConnectionString() || permissionAttribute.ShouldSerializeKeyRestrictions())
         {
             this.Add(permissionAttribute.ConnectionString, permissionAttribute.KeyRestrictions, permissionAttribute.KeyRestrictionBehavior);
         }
     }
 }
        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;
     }
 }
Exemple #22
0
 private NameValuePermission(NameValuePermission permit)
 { // deep-copy
     _value = permit._value;
     _entry = permit._entry;
     _tree  = permit._tree;
     if (null != _tree)
     {
         NameValuePermission[] tree = (_tree.Clone() as NameValuePermission[]);
         for (int i = 0; i < tree.Length; ++i)
         {
             if (null != tree[i])
             {                                      // WebData 98488
                 tree[i] = tree[i].CopyNameValue(); // deep copy
             }
         }
         _tree = tree;
     }
 }
        private NameValuePermission CheckKeyForValue(string keyInQuestion)
        {
            NameValuePermission[] valuetree = _tree; // _tree won't mutate but Add will replace it
            if (null != valuetree)
            {
                for (int i = 0; i < valuetree.Length; ++i)
                {
                    NameValuePermission permitValue = valuetree[i];
#if DATAPERMIT
                    Debug.WriteLine("DBDataPermission value: <" + permitValue._value + ">");
#endif
                    if (0 == ADP.DstCompare(keyInQuestion, permitValue._value))
                    {
                        return(permitValue);
                    }
                }
            }
            return(null);
        }
 protected void Clear() { // V1.2.3300, MDAC 83105
     _keyvaluetree = null;
     _keyvalues = null;
 }
Exemple #25
0
        internal static void AddEntry(NameValuePermission kvtree, ArrayList entries, DBConnectionString entry)
        {
            Debug.Assert(null != entry, "null DBConnectionString");

            if (null != entry.KeyChain)
            {
                for (NameValuePair keychain = entry.KeyChain; null != keychain; keychain = keychain.Next)
                {
                    NameValuePermission kv;

                    kv = kvtree.CheckKeyForValue(keychain.Name);
                    if (null == kv)
                    {
                        kv = new NameValuePermission(keychain.Name);
                        kvtree.Add(kv); // add directly into live tree
                    }
                    kvtree = kv;

                    kv = kvtree.CheckKeyForValue(keychain.Value);
                    if (null == kv)
                    {
                        DBConnectionString insertValue = ((null != keychain.Next) ? null : entry);
                        kv = new NameValuePermission(keychain.Value, insertValue);
                        kvtree.Add(kv); // add directly into live tree
                        if (null != insertValue)
                        {
                            entries.Add(insertValue);
                        }
                    }
                    else if (null == keychain.Next)
                    { // shorter chain potential
                        if (null != kv._entry)
                        {
                            Debug.Assert(entries.Contains(kv._entry), "entries doesn't contain entry");
                            entries.Remove(kv._entry);
                            kv._entry = kv._entry.Intersect(entry); // union new restrictions into existing tree
                        }
                        else
                        {
                            kv._entry = entry;
                        }
                        entries.Add(kv._entry);
                    }
                    kvtree = kv;
                }
            }
            else
            { // global restrictions, MDAC 84443
                DBConnectionString kentry = kvtree._entry;
                if (null != kentry)
                {
                    Debug.Assert(entries.Contains(kentry), "entries doesn't contain entry");
                    entries.Remove(kentry);
                    kvtree._entry = kentry.Intersect(entry);
                }
                else
                {
                    kvtree._entry = entry;
                }
                entries.Add(kvtree._entry);
            }
        }
        internal void Intersect(ArrayList entries, NameValuePermission target) {
            if (null == target) {
                _tree = null;
                _entry = null;
            }
            else {
                if (null != _entry) {
                    entries.Remove(_entry);
                    _entry = _entry.Intersect(target._entry);
                    entries.Add(_entry);
                }
                else if (null != target._entry) {
                    _entry = target._entry.Intersect(null);
                    entries.Add(_entry);
                }

                if (null != _tree) {
                    int count = _tree.Length;
                    for(int i = 0; i < _tree.Length; ++i) {
                        NameValuePermission kvtree = target.CheckKeyForValue(_tree[i]._value);
                        if (null != kvtree) { // does target tree contain our value
                            _tree[i].Intersect(entries, kvtree);
                        }
                        else {
                            _tree[i] = null;
                            --count;
                        }
                    }
                    if (0 == count) {
                        _tree = null;
                    }
                    else if (count < _tree.Length) {
                        NameValuePermission[] kvtree = new NameValuePermission[count];
                        for (int i = 0, j = 0; i < _tree.Length; ++i) {
                            if(null != _tree[i]) {
                                kvtree[j++] = _tree[i];
                            }
                        }
                        _tree = kvtree;
                    }
                }
            }
        }
Exemple #27
0
        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)
            {
                hasMatch = parsetable.IsEmpty; // MDAC 86773
                if (!hasMatch)
                {
                    // which key do we follow the key-value chain on
                    for (int i = 0; i < keytree.Length; ++i)
                    {
                        NameValuePermission permitKey = keytree[i];
                        if (null != permitKey)
                        {
                            string keyword = permitKey._value;
#if DEBUG
                            Debug.Assert(null == permitKey._entry, "key member has no restrictions");
#endif
                            if (parsetable.ContainsKey(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;
                                        // adding a break statement is tempting, but wrong
                                        // user can safetly extend their restrictions for current rule to include missing keyword
                                        // i.e. Add("provider=sqloledb;integrated security=sspi", "data provider=", KeyRestrictionBehavior.AllowOnly);
                                        // i.e. Add("data provider=msdatashape;provider=sqloledb;integrated security=sspi", "", KeyRestrictionBehavior.AllowOnly);
                                    }
                                    else
                                    { // failed branch checking
                                        return(false);
                                    }
                                }
                                else
                                { // value doesn't match to expected values - fail here
                                    return(false);
                                }
                            }
                        }
                        // else try next keyword
                    }
                }
                // partial chain match, either leaf-node by shorter chain or fail mid-chain if (null == _restrictions)
            }

            DBConnectionString entry = _entry;
            if (null != entry)
            {
                // also checking !hasMatch is tempting, but wrong
                // user can safetly extend their restrictions for current rule to include missing keyword
                // i.e. Add("provider=sqloledb;integrated security=sspi", "data provider=", KeyRestrictionBehavior.AllowOnly);
                // i.e. Add("provider=sqloledb;", "integrated security=;", KeyRestrictionBehavior.AllowOnly);
                hasMatch = entry.IsSupersetOf(parsetable);
            }

            return(hasMatch); // mid-chain failure
        }
 private void Add(NameValuePermission permit) {
     NameValuePermission[] tree = _tree;
     int length = ((null != tree) ? tree.Length : 0);
     NameValuePermission[] newtree = new NameValuePermission[1+length];
     for(int i = 0; i < newtree.Length-1; ++i) {
         newtree[i] = tree[i];
     }
     newtree[length] = permit;
     Array.Sort(newtree);
     _tree = newtree;
 }
 protected void Clear()
 {
     this._keyvaluetree = null;
     this._keyvalues    = null;
 }
        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)
            {
                hasMatch = parsetable.IsEmpty(); // MDAC 86773

                // 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
        }
 internal void AddPermissionEntry(DBConnectionString entry) {
     if (null == _keyvaluetree) {
         _keyvaluetree = new NameValuePermission();
     }
     if (null == _keyvalues) {
         _keyvalues = new ArrayList();
     }
     NameValuePermission.AddEntry(_keyvaluetree, _keyvalues, entry);
     _isUnrestricted = false; // MDAC 84639
 }
        private void CopyFrom(DBDataPermission permission) {
            _isUnrestricted = permission.IsUnrestricted();
            if (!_isUnrestricted) {
                _allowBlankPassword = permission.AllowBlankPassword;

                if (null != permission._keyvalues) {
                    _keyvalues = (ArrayList) permission._keyvalues.Clone();

                    if (null != permission._keyvaluetree) {
                        _keyvaluetree = permission._keyvaluetree.CopyNameValue();
                    }
                }
            }
        }
 internal void AddPermissionEntry(DBConnectionString entry)
 {
     if (this._keyvaluetree == null)
     {
         this._keyvaluetree = new NameValuePermission();
     }
     if (this._keyvalues == null)
     {
         this._keyvalues = new ArrayList();
     }
     NameValuePermission.AddEntry(this._keyvaluetree, this._keyvalues, entry);
     this._isUnrestricted = false;
 }
Exemple #34
0
 protected void Clear()   // V1.2.3300, MDAC 83105
 {
     _keyvaluetree = null;
     _keyvalues    = null;
 }
 protected void Clear()
 {
     this._keyvaluetree = null;
     this._keyvalues = null;
 }