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) { entries.Remove(kv._entry); kv._entry = kv._entry.MergeIntersect(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) { entries.Remove(kentry); kvtree._entry = kentry.MergeIntersect(entry); } else { kvtree._entry = entry; } entries.Add(kvtree._entry); } }
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); } }
internal void Intersect(ArrayList entries, NameValuePermission target) { if (target == null) { this._tree = null; this._entry = null; } else { if (this._entry != null) { entries.Remove(this._entry); this._entry = this._entry.Intersect(target._entry); entries.Add(this._entry); } else if (target._entry != null) { this._entry = target._entry.Intersect(null); entries.Add(this._entry); } if (this._tree != null) { int length = this._tree.Length; for (int i = 0; i < this._tree.Length; i++) { NameValuePermission permission = target.CheckKeyForValue(this._tree[i]._value); if (permission != null) { this._tree[i].Intersect(entries, permission); } else { this._tree[i] = null; length--; } } if (length == 0) { this._tree = null; } else if (length < this._tree.Length) { NameValuePermission[] permissionArray = new NameValuePermission[length]; int index = 0; int num4 = 0; while (index < this._tree.Length) { if (this._tree[index] != null) { permissionArray[num4++] = this._tree[index]; } index++; } this._tree = permissionArray; } } } }
internal void Intersect(ArrayList entries, NameValuePermission target) { if (null == target) { _tree = null; _entry = null; } else { if (null != _entry) { entries.Remove(_entry); _entry = _entry.MergeIntersect(target._entry); entries.Add(_entry); } else if (null != target._entry) { _entry = target._entry.MergeIntersect(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]; } } } } } }
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); }
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 }