/* * public bool ConnectAll * { * get * { * return m_connect is bool ? (bool) m_connect : false; * } * * set * { * if (m_connect != null) * { * throw new ArgumentException(SR.GetString(SR.net_perm_attrib_multi, "ConnectAll", value), "value"); * } * m_connect = value; * } * } * * public bool AcceptAll * { * get * { * return m_accept is bool ? (bool) m_accept : false; * } * * set * { * if (m_accept != null) * { * throw new ArgumentException(SR.GetString(SR.net_perm_attrib_multi, "AcceptAll", value), "value"); * } * m_accept = value; * } * } */ public override IPermission CreatePermission() { WebPermission perm = null; if (Unrestricted) { perm = new WebPermission(PermissionState.Unrestricted); } else { NetworkAccess access = (NetworkAccess)0; if (m_connect is bool) { if ((bool)m_connect) { access |= NetworkAccess.Connect; } m_connect = null; } if (m_accept is bool) { if ((bool)m_accept) { access |= NetworkAccess.Accept; } m_accept = null; } perm = new WebPermission(access); if (m_accept != null) { if (m_accept is DelayedRegex) { perm.AddAsPattern(NetworkAccess.Accept, (DelayedRegex)m_accept); } else { perm.AddPermission(NetworkAccess.Accept, (string)m_accept); } } if (m_connect != null) { if (m_connect is DelayedRegex) { perm.AddAsPattern(NetworkAccess.Connect, (DelayedRegex)m_connect); } else { perm.AddPermission(NetworkAccess.Connect, (string)m_connect); } } } return(perm); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } WebPermission permission = target as WebPermission; if (permission == null) { throw new ArgumentException(SR.GetString("net_perm_target"), "target"); } if (this.m_noRestriction) { return(permission.Copy()); } if (permission.m_noRestriction) { return(this.Copy()); } WebPermission permission2 = new WebPermission(); if (this.m_UnrestrictedConnect && permission.m_UnrestrictedConnect) { permission2.m_UnrestrictedConnect = true; } else if (this.m_UnrestrictedConnect || permission.m_UnrestrictedConnect) { permission2.m_connectList = (ArrayList)(this.m_UnrestrictedConnect ? permission : this).m_connectList.Clone(); } else { intersectList(this.m_connectList, permission.m_connectList, permission2.m_connectList); } if (this.m_UnrestrictedAccept && permission.m_UnrestrictedAccept) { permission2.m_UnrestrictedAccept = true; } else if (this.m_UnrestrictedAccept || permission.m_UnrestrictedAccept) { permission2.m_acceptList = (ArrayList)(this.m_UnrestrictedAccept ? permission : this).m_acceptList.Clone(); } else { intersectList(this.m_acceptList, permission.m_acceptList, permission2.m_acceptList); } if ((!permission2.m_UnrestrictedConnect && !permission2.m_UnrestrictedAccept) && ((permission2.m_connectList.Count == 0) && (permission2.m_acceptList.Count == 0))) { return(null); } return(permission2); }
// IPermission interface methods /// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.Copy"]/*' /> /// <devdoc> /// <para> /// Creates a copy of a <see cref='System.Net.WebPermission'/> instance. /// </para> /// </devdoc> public override IPermission Copy() { if (m_noRestriction) { return(new WebPermission(true)); } WebPermission wp = new WebPermission(); wp.m_acceptList = (ArrayList)m_acceptList.Clone(); wp.m_connectList = (ArrayList)m_connectList.Clone(); return(wp); }
// IPermission interface methods /// <devdoc> /// <para> /// Creates a copy of a <see cref='System.Net.WebPermission'/> instance. /// </para> /// </devdoc> public override IPermission Copy() { if (m_noRestriction) { return(new WebPermission(true)); } WebPermission wp = new WebPermission((m_UnrestrictedConnect ? NetworkAccess.Connect : (NetworkAccess)0) | (m_UnrestrictedAccept ? NetworkAccess.Accept : (NetworkAccess)0)); wp.m_acceptList = (ArrayList)m_acceptList.Clone(); wp.m_connectList = (ArrayList)m_connectList.Clone(); return(wp); }
/// <summary>Determines whether the current <see cref="T:System.Net.WebPermission" /> is a subset of the specified object.</summary> /// <returns>true if the current instance is a subset of the <paramref name="target" /> parameter; otherwise, false. If the target is null, the method returns true for an empty current permission that is not unrestricted and false otherwise.</returns> /// <param name="target">The <see cref="T:System.Net.WebPermission" /> to compare to the current <see cref="T:System.Net.WebPermission" />. </param> /// <exception cref="T:System.ArgumentException">The target parameter is not an instance of <see cref="T:System.Net.WebPermission" />. </exception> /// <exception cref="T:System.NotSupportedException">The current instance contains a Regex-encoded right and there is not exactly the same right found in the target instance. </exception> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(!this.m_noRestriction && this.m_connectList.Count == 0 && this.m_acceptList.Count == 0); } WebPermission webPermission = target as WebPermission; if (webPermission == null) { throw new ArgumentException("Parameter target must be of type WebPermission"); } return(webPermission.m_noRestriction || (!this.m_noRestriction && ((this.m_acceptList.Count == 0 && this.m_connectList.Count == 0) || ((webPermission.m_acceptList.Count != 0 || webPermission.m_connectList.Count != 0) && this.IsSubsetOf(this.m_connectList, webPermission.m_connectList) && this.IsSubsetOf(this.m_acceptList, webPermission.m_acceptList))))); }
public override IPermission Copy() { WebPermission permission; permission = new WebPermission(m_noRestriction ? PermissionState.Unrestricted : PermissionState.None); // as EndpointPermission's are immutable it's safe to do a shallow copy. permission.m_connectList = (ArrayList) this.m_connectList.Clone(); permission.m_acceptList = (ArrayList)this.m_acceptList.Clone(); return(permission); }
public override IPermission CreatePermission() { WebPermission permission = null; if (base.Unrestricted) { return(new WebPermission(PermissionState.Unrestricted)); } NetworkAccess access = 0; if (this.m_connect is bool) { if ((bool)this.m_connect) { access |= NetworkAccess.Connect; } this.m_connect = null; } if (this.m_accept is bool) { if ((bool)this.m_accept) { access |= NetworkAccess.Accept; } this.m_accept = null; } permission = new WebPermission(access); if (this.m_accept != null) { if (this.m_accept is DelayedRegex) { permission.AddAsPattern(NetworkAccess.Accept, (DelayedRegex)this.m_accept); } else { permission.AddPermission(NetworkAccess.Accept, (string)this.m_accept); } } if (this.m_connect != null) { if (this.m_connect is DelayedRegex) { permission.AddAsPattern(NetworkAccess.Connect, (DelayedRegex)this.m_connect); return(permission); } permission.AddPermission(NetworkAccess.Connect, (string)this.m_connect); } return(permission); }
public override IPermission CreatePermission() { WebPermission permission = null; if (base.Unrestricted) { return new WebPermission(PermissionState.Unrestricted); } NetworkAccess access = 0; if (this.m_connect is bool) { if ((bool) this.m_connect) { access |= NetworkAccess.Connect; } this.m_connect = null; } if (this.m_accept is bool) { if ((bool) this.m_accept) { access |= NetworkAccess.Accept; } this.m_accept = null; } permission = new WebPermission(access); if (this.m_accept != null) { if (this.m_accept is DelayedRegex) { permission.AddAsPattern(NetworkAccess.Accept, (DelayedRegex) this.m_accept); } else { permission.AddPermission(NetworkAccess.Accept, (string) this.m_accept); } } if (this.m_connect != null) { if (this.m_connect is DelayedRegex) { permission.AddAsPattern(NetworkAccess.Connect, (DelayedRegex) this.m_connect); return permission; } permission.AddPermission(NetworkAccess.Connect, (string) this.m_connect); } return permission; }
public DataLayer(ConnectionTypeConstants contype) { Debug.Print("DataLayer Initializing..."); WebPermission wp = new WebPermission(); wp.Demand(); switch (Configuration.DatabaseType.ToUpper().Trim()) { case "": case "MYSQL": qAdapter = new MySQLQueryAdapter(); break; case "SQL": case "SQL SERVER": qAdapter = new SQLServerQueryAdapter(); break; } Debug.Assert(qAdapter != null); // if (Configuration.PurgeLogOnStartup) // { String dbgfile = getDebugOutputFilepath(); if (File.Exists(dbgfile)) File.Delete(dbgfile); //} WriteDebugMessage("--DataLayer Initializing-" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "--"); DatabaseName = Configuration.DatabaseName; try { CurrentConString = buildConnectionString(contype); } catch (frmPasswordPrompt.CredentialsNotGivenException exx) { throw; } Debug.Print("Using ConnectionString:" + CurrentConString); //initialize our Type Manager. String[] lookfolders = new String[] { JobClockConfig.GetExportLibFolder()}; mtypemanager = new MultiTypeManager(lookfolders, new Type[] { typeof(BaseDataExporter) }, null, new Nullcallback(), null, new Assembly[] { Assembly.GetCallingAssembly() }); }
/// <summary>Returns the logical intersection of two <see cref="T:System.Net.WebPermission" /> instances.</summary> /// <returns>A new <see cref="T:System.Net.WebPermission" /> that represents the intersection of the current instance and the <paramref name="target" /> parameter. If the intersection is empty, the method returns null.</returns> /// <param name="target">The <see cref="T:System.Net.WebPermission" /> to compare with the current instance. </param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> is not null or of type <see cref="T:System.Net.WebPermission" /></exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence" /> /// </PermissionSet> public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } WebPermission webPermission = target as WebPermission; if (webPermission == null) { throw new ArgumentException("Argument not of type WebPermission"); } if (this.m_noRestriction) { IPermission result; if (this.IntersectEmpty(webPermission)) { IPermission permission = null; result = permission; } else { result = webPermission.Copy(); } return(result); } if (webPermission.m_noRestriction) { IPermission result2; if (this.IntersectEmpty(this)) { IPermission permission = null; result2 = permission; } else { result2 = this.Copy(); } return(result2); } WebPermission webPermission2 = new WebPermission(PermissionState.None); this.Intersect(this.m_connectList, webPermission.m_connectList, webPermission2.m_connectList); this.Intersect(this.m_acceptList, webPermission.m_acceptList, webPermission2.m_acceptList); return((!this.IntersectEmpty(webPermission2)) ? webPermission2 : null); }
// The union of two web permissions is formed by concatenating // the list of allowed regular expressions. There is no check // for duplicates/overlaps /// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.Union"]/*' /> /// <devdoc> /// <para>Returns the logical union between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Union(IPermission target) { // Pattern suggested by Security engine if (target == null) { return(this.Copy()); } WebPermission other = target as WebPermission; if (other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target)); } if (m_noRestriction || other.m_noRestriction) { return(new WebPermission(true)); } WebPermission result = (WebPermission)other.Copy(); for (int i = 0; i < m_connectList.Count; i++) { Regex uriPattern = m_connectList[i] as Regex; if (uriPattern == null) { result.AddPermission(NetworkAccess.Connect, m_connectList[i].ToString()); } else { result.AddPermission(NetworkAccess.Connect, uriPattern); } } for (int i = 0; i < m_acceptList.Count; i++) { Regex uriPattern = m_acceptList[i] as Regex; if (uriPattern == null) { result.AddPermission(NetworkAccess.Accept, m_acceptList[i].ToString()); } else { result.AddPermission(NetworkAccess.Accept, uriPattern); } } return(result); }
internal string GetConnectionStringFromSharePointList(string reportServerUrl, ICredentials credentials) { //assumption that the connection string to the database is stored as an encrypted value in a list called "Configuration" string webRequestUrl = string.Format("{0}/_api/lists/getbytitle('Configuration')/items/?$select=Title,Value&$filter=startswith(Title,'ConnectionString')", reportServerUrl); var webPermission = new System.Net.WebPermission(NetworkAccess.Connect, webRequestUrl); webPermission.Assert(); var endpointRequest = (HttpWebRequest)HttpWebRequest.Create(webRequestUrl); endpointRequest.Method = "GET"; endpointRequest.Accept = "application/json;odata=verbose"; endpointRequest.Credentials = credentials; var endpointResponse = (HttpWebResponse)endpointRequest.GetResponse(); try { WebResponse webResponse = endpointRequest.GetResponse(); using (Stream webStream = webResponse.GetResponseStream()) { using (StreamReader responseReader = new StreamReader(webStream)) { try { string response = responseReader.ReadToEnd(); var connectionString = ExtractConnectionStringFromJSON(response); return(connectionString); } finally { responseReader.Close(); } } } } catch (Exception e) { throw new InvalidOperationException("Error when: GetFromSharePointConfigurationList:", e); } }
/// <summary>Creates and returns a new instance of the <see cref="T:System.Net.WebPermission" /> class.</summary> /// <returns>A <see cref="T:System.Net.WebPermission" /> corresponding to the security declaration.</returns> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public override IPermission CreatePermission() { if (base.Unrestricted) { return(new WebPermission(PermissionState.Unrestricted)); } WebPermission webPermission = new WebPermission(); if (this.m_accept != null) { webPermission.AddPermission(NetworkAccess.Accept, (WebPermissionInfo)this.m_accept); } if (this.m_connect != null) { webPermission.AddPermission(NetworkAccess.Connect, (WebPermissionInfo)this.m_connect); } return(webPermission); }
public void Serialization () { string result1 = "<IPermission class=\"System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\n" + "version=\"1\">\n" + "<ConnectAccess>\n" + "<URI uri=\"Hello\"/>\n" + "</ConnectAccess>\n" + "</IPermission>\n"; string result2 = "<IPermission class=\"System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\n" + "version=\"1\">\n" + "<AcceptAccess>\n" + "<URI uri=\"Hello\"/>\n" + "</AcceptAccess>\n" + "</IPermission>\n"; WebPermission pp = new WebPermission (NetworkAccess.Connect, "Hello"); Assert.AreEqual (result1, pp.ToXml ().ToString ().Replace ("\r", "")); pp = new WebPermission (NetworkAccess.Accept, "Hello"); Assert.AreEqual (result2, pp.ToXml ().ToString ().Replace ("\r", "")); }
// Create a permission object that corresponds to this attribute. public override IPermission CreatePermission() { if (Unrestricted) { return(new WebPermission (PermissionState.Unrestricted)); } else { WebPermission perm = new WebPermission(); if (accept != null) { perm.AddPermission(NetworkAccess.Accept, accept); } if (connect != null) { perm.AddPermission(NetworkAccess.Connect, connect); } return(perm); } }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(state == PermissionState.None && acceptList.Count == 0 && connectList.Count == 0); } else if (!(target is WebPermission)) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (((WebPermission)target).IsUnrestricted()) { return(true); } else if (IsUnrestricted()) { return(false); } else { WebPermission other = (WebPermission)target; foreach (Object p1 in acceptList) { if (!other.acceptList.Contains(p1)) { return(false); } } foreach (Object p2 in connectList) { if (!other.connectList.Contains(p2)) { return(false); } } return(true); } }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.Intersect"]/*' /> /// <devdoc> /// <para>Returns the logical intersection between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Intersect(IPermission target) { // Pattern suggested by Security engine if (target == null) { return(null); } WebPermission other = target as WebPermission; if (other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target)); } WebPermission result; if (m_noRestriction) { result = (WebPermission)(other.Copy()); } else if (other.m_noRestriction) { result = (WebPermission)(this.Copy()); } else { result = new WebPermission(false); intersectList(m_connectList, other.m_connectList, result.m_connectList); intersectList(m_acceptList, other.m_acceptList, result.m_acceptList); } // return null if resulting permission is restricted and empty if (!result.m_noRestriction && result.m_connectList.Count == 0 && result.m_acceptList.Count == 0) { return(null); } return(result); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(target); } else if (!(target is WebPermission)) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (((WebPermission)target).IsUnrestricted()) { return(Copy()); } else if (IsUnrestricted()) { return(target.Copy()); } else { WebPermission perm = new WebPermission(); WebPermission other = (WebPermission)target; foreach (Object p1 in acceptList) { if (!other.acceptList.Contains(p1)) { perm.acceptList.Add(p1); } } foreach (Object p2 in connectList) { if (!other.connectList.Contains(p2)) { perm.connectList.Add(p2); } } return(perm); } }
/// <summary>Returns the logical union between two instances of the <see cref="T:System.Net.WebPermission" /> class.</summary> /// <returns>A <see cref="T:System.Net.WebPermission" /> that represents the union of the current instance and the <paramref name="target" /> parameter. If either WebPermission is <see cref="F:System.Security.Permissions.PermissionState.Unrestricted" />, the method returns a <see cref="T:System.Net.WebPermission" /> that is <see cref="F:System.Security.Permissions.PermissionState.Unrestricted" />. If the target is null, the method returns a copy of the current <see cref="T:System.Net.WebPermission" />.</returns> /// <param name="target">The <see cref="T:System.Net.WebPermission" /> to combine with the current <see cref="T:System.Net.WebPermission" />. </param> /// <exception cref="T:System.ArgumentException">target is not null or of type <see cref="T:System.Net.WebPermission" />. </exception> public override IPermission Union(IPermission target) { if (target == null) { return(null); } WebPermission webPermission = target as WebPermission; if (webPermission == null) { throw new ArgumentException("Argument not of type WebPermission"); } if (this.m_noRestriction || webPermission.m_noRestriction) { return(new WebPermission(PermissionState.Unrestricted)); } WebPermission webPermission2 = (WebPermission)webPermission.Copy(); webPermission2.m_acceptList.InsertRange(webPermission2.m_acceptList.Count, this.m_acceptList); webPermission2.m_connectList.InsertRange(webPermission2.m_connectList.Count, this.m_connectList); return(webPermission2); }
public override IPermission Union(IPermission target) { if (target == null) { return(Copy()); } else if (!(target is WebPermission)) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if (IsUnrestricted() || ((WebPermission)target).IsUnrestricted()) { return(new WebPermission (PermissionState.Unrestricted)); } else { WebPermission perm = new WebPermission ((WebPermission)target); foreach (Object p1 in acceptList) { if (!perm.acceptList.Contains(p1)) { perm.acceptList.Add(p1); } } foreach (Object p2 in connectList) { if (!perm.connectList.Contains(p2)) { perm.connectList.Add(p2); } } return(perm); } }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermissionAttribute.CreatePermission"]/*' /> public override IPermission CreatePermission() { WebPermission perm = null; if (Unrestricted) { perm = new WebPermission(PermissionState.Unrestricted); } else { perm = new WebPermission(PermissionState.None); if (m_accept != null) { if (m_accept is Regex) { perm.AddPermission(NetworkAccess.Accept, (Regex)m_accept); } else { perm.AddPermission(NetworkAccess.Accept, m_accept.ToString()); } } if (m_connect != null) { if (m_connect is Regex) { perm.AddPermission(NetworkAccess.Connect, (Regex)m_connect); } else { perm.AddPermission(NetworkAccess.Connect, m_connect.ToString()); } } } return(perm); }
//status code initial value set to -1 //You should never get that value. //It should be 200 for succes //204 for succes but empty response //any other return code is an error //408 is a timeout error. public Tuple<String, int> Web_Read(string url, int timeout) { int statusCode = -1; string result = ""; StreamReader reader = null; try { //asking for permission to call the specified url. var permission = new WebPermission(); permission.AddPermission(NetworkAccess.Connect, url); permission.Assert(); WebRequest request = WebRequest.Create(url); request.Timeout = (timeout == 0) ? request.Timeout : timeout; WebResponse response = request.GetResponse(); Stream grs = response.GetResponseStream(); if (grs != null) { reader = new StreamReader(grs); result = reader.ReadToEnd(); } //if the response is empty it will officially return a 204 status code. //This is according to the http specification. if (result.Length < 1) { result = "error"; statusCode = 204; } else { //response code 200: HTTP OK request was made succesfully. statusCode = 200; } } catch (WebException ex) { var resp = (HttpWebResponse)ex.Response; if (resp == null) statusCode = 500; else { //Will parse all .net known http status codes. int.TryParse(resp.StatusCode.ToString(), out statusCode); } result = "error"; } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } finally { // general cleanup if (reader != null) { reader.Close(); //closes the reader and the response stream it was working on at the same time. } } return Tuple.Create(result, statusCode); }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.IsSubsetOf"]/*' /> /// <devdoc> /// <para>Compares two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override bool IsSubsetOf(IPermission target) { // Pattern suggested by security engine if (target == null) { return(m_noRestriction == false && m_connectList.Count == 0 && m_acceptList.Count == 0); } WebPermission other = target as WebPermission; if (other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target)); } if (other.IsUnrestricted()) { return(true); } else if (this.IsUnrestricted()) { return(false); } else if (this.m_acceptList.Count + this.m_connectList.Count == 0) { return(true); } else if (other.m_acceptList.Count + other.m_connectList.Count == 0) { return(false); } // // Besides SPECIAL case, this method is restricted to only final URIs (strings) on // the current object. // The restriction comes from the problem of finding a Regex to be a subset of another Regex // String UriString = null; foreach (object Uri in this.m_acceptList) { UriString = Uri as String; if (UriString == null) { if (isSpecialSubsetCase(Uri.ToString(), other.m_acceptList)) { continue; } throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex)); } if (!isMatchedURI(UriString, other.m_acceptList)) { return(false); } } foreach (object Uri in this.m_connectList) { UriString = Uri as String; if (UriString == null) { if (isSpecialSubsetCase(Uri.ToString(), other.m_connectList)) { continue; } throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex)); } if (!isMatchedURI(UriString, other.m_connectList)) { return(false); } } return(true); }
public override IPermission Intersect(IPermission target) { if (target == null) { return null; } WebPermission permission = target as WebPermission; if (permission == null) { throw new ArgumentException(SR.GetString("net_perm_target"), "target"); } if (this.m_noRestriction) { return permission.Copy(); } if (permission.m_noRestriction) { return this.Copy(); } WebPermission permission2 = new WebPermission(); if (this.m_UnrestrictedConnect && permission.m_UnrestrictedConnect) { permission2.m_UnrestrictedConnect = true; } else if (this.m_UnrestrictedConnect || permission.m_UnrestrictedConnect) { permission2.m_connectList = (ArrayList) (this.m_UnrestrictedConnect ? permission : this).m_connectList.Clone(); } else { intersectList(this.m_connectList, permission.m_connectList, permission2.m_connectList); } if (this.m_UnrestrictedAccept && permission.m_UnrestrictedAccept) { permission2.m_UnrestrictedAccept = true; } else if (this.m_UnrestrictedAccept || permission.m_UnrestrictedAccept) { permission2.m_acceptList = (ArrayList) (this.m_UnrestrictedAccept ? permission : this).m_acceptList.Clone(); } else { intersectList(this.m_acceptList, permission.m_acceptList, permission2.m_acceptList); } if ((!permission2.m_UnrestrictedConnect && !permission2.m_UnrestrictedAccept) && ((permission2.m_connectList.Count == 0) && (permission2.m_acceptList.Count == 0))) { return null; } return permission2; }
public override IPermission Copy () { WebPermission permission; permission = new WebPermission (m_noRestriction ? PermissionState.Unrestricted : PermissionState.None); // as EndpointPermission's are immutable it's safe to do a shallow copy. permission.m_connectList = (ArrayList) this.m_connectList.Clone (); permission.m_acceptList = (ArrayList) this.m_acceptList.Clone (); return permission; }
public override IPermission Intersect(IPermission target) { if(target == null) { return target; } else if(!(target is WebPermission)) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if(((WebPermission)target).IsUnrestricted()) { return Copy(); } else if(IsUnrestricted()) { return target.Copy(); } else { WebPermission perm = new WebPermission(); WebPermission other = (WebPermission)target; foreach(Object p1 in acceptList) { if(!other.acceptList.Contains(p1)) { perm.acceptList.Add(p1); } } foreach(Object p2 in connectList) { if(!other.connectList.Contains(p2)) { perm.connectList.Add(p2); } } return perm; } }
private WebPermission(WebPermission copyFrom) { this.state = copyFrom.state; this.acceptList = (ArrayList)(copyFrom.acceptList.Clone()); this.connectList = (ArrayList)(copyFrom.connectList.Clone()); }
/// <devdoc> /// <para>Returns the logical intersection between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Intersect(IPermission target) { // Pattern suggested by Security engine if (target == null) { return null; } WebPermission other = target as WebPermission; if(other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target), "target"); } if (m_noRestriction) { return other.Copy(); } if (other.m_noRestriction) { return Copy(); } WebPermission result = new WebPermission(); if (m_UnrestrictedConnect && other.m_UnrestrictedConnect) { result.m_UnrestrictedConnect = true; } else if (m_UnrestrictedConnect || other.m_UnrestrictedConnect) { result.m_connectList = (ArrayList) (m_UnrestrictedConnect ? other : this).m_connectList.Clone(); } else { intersectList(m_connectList, other.m_connectList, result.m_connectList); } if (m_UnrestrictedAccept && other.m_UnrestrictedAccept) { result.m_UnrestrictedAccept = true; } else if (m_UnrestrictedAccept || other.m_UnrestrictedAccept) { result.m_acceptList = (ArrayList) (m_UnrestrictedAccept ? other : this).m_acceptList.Clone(); } else { intersectList(m_acceptList, other.m_acceptList, result.m_acceptList); } // return null if resulting permission is restricted and empty if (!result.m_UnrestrictedConnect && !result.m_UnrestrictedAccept && result.m_connectList.Count == 0 && result.m_acceptList.Count == 0) { return null; } return result; }
internal static void EnsureUrlConnectPermission(Uri url) { // WebPermission permission = new WebPermission(NetworkAccess.Connect, url.AbsoluteUri); permission.Demand(); }
// IPermission interface methods /// <devdoc> /// <para> /// Creates a copy of a <see cref='System.Net.WebPermission'/> instance. /// </para> /// </devdoc> public override IPermission Copy() { if (m_noRestriction) { return new WebPermission(true); } WebPermission wp = new WebPermission((m_UnrestrictedConnect ? NetworkAccess.Connect : (NetworkAccess) 0) | (m_UnrestrictedAccept ? NetworkAccess.Accept : (NetworkAccess)0)); wp.m_acceptList = (ArrayList)m_acceptList.Clone(); wp.m_connectList = (ArrayList)m_connectList.Clone(); return wp; }
[SuppressMessage("Microsoft.Security", "CA2103:ReviewImperativeSecurity")] // WebPermission based on URI path, but path isn't gonna change during scope of Demand private void LoadSync() { Debug.Assert((uri == null || !uri.IsFile), "we only load streams"); // first make sure that any possible download ended if (!semaphore.WaitOne(LoadTimeout, false)) { if (copyThread != null) copyThread.Abort(); CleanupStreamData(); throw new TimeoutException(SR.GetString(SR.SoundAPILoadTimedOut)); } // if we have data, then we are done if (streamData != null) return; // setup the http stream if (uri != null && !uri.IsFile && stream == null) { WebPermission webPerm = new WebPermission(NetworkAccess.Connect, uri.AbsolutePath); webPerm.Demand(); WebRequest webRequest = WebRequest.Create(uri); webRequest.Timeout = LoadTimeout; WebResponse webResponse; webResponse = webRequest.GetResponse(); // now get the stream stream = webResponse.GetResponseStream(); } if (stream.CanSeek) { // if we can get data synchronously, then get it LoadStream(true); } else { // the data can't be loaded synchronously // load it async, then wait for it to finish doesLoadAppearSynchronous = true; // to avoid OnFailed call. LoadStream(false); if(!semaphore.WaitOne(LoadTimeout, false)) { if (copyThread != null) copyThread.Abort(); CleanupStreamData(); throw new TimeoutException(SR.GetString(SR.SoundAPILoadTimedOut)); } doesLoadAppearSynchronous = false; if (lastLoadException != null) { throw lastLoadException; } } // we don't need the worker copyThread anymore this.copyThread = null; }
/* public bool ConnectAll { get { return m_connect is bool ? (bool) m_connect : false; } set { if (m_connect != null) { throw new ArgumentException(SR.GetString(SR.net_perm_attrib_multi, "ConnectAll", value), "value"); } m_connect = value; } } public bool AcceptAll { get { return m_accept is bool ? (bool) m_accept : false; } set { if (m_accept != null) { throw new ArgumentException(SR.GetString(SR.net_perm_attrib_multi, "AcceptAll", value), "value"); } m_accept = value; } } */ public override IPermission CreatePermission() { WebPermission perm = null; if (Unrestricted) { perm = new WebPermission( PermissionState.Unrestricted); } else { NetworkAccess access = (NetworkAccess) 0; if (m_connect is bool) { if ((bool) m_connect) { access |= NetworkAccess.Connect; } m_connect = null; } if (m_accept is bool) { if ((bool) m_accept) { access |= NetworkAccess.Accept; } m_accept = null; } perm = new WebPermission(access); if (m_accept != null) { if (m_accept is DelayedRegex) { perm.AddAsPattern(NetworkAccess.Accept, (DelayedRegex)m_accept); } else { perm.AddPermission(NetworkAccess.Accept, (string)m_accept); } } if (m_connect != null) { if (m_connect is DelayedRegex) { perm.AddAsPattern(NetworkAccess.Connect, (DelayedRegex)m_connect); } else { perm.AddPermission(NetworkAccess.Connect, (string)m_connect); } } } return perm; }
private void DoSubmit() { try { using (new WaitCursor()) { if (!ValidateData()) return; m_statusBar.Text = "Submitting bug..."; WebPermission myWebPermission = new WebPermission(PermissionState.Unrestricted); myWebPermission.Demand(); string desc = m_descTextBox.Text; // if the exception was set, append the stack trace if (m_exception != null) { desc += "\n\n-----------------------------------\n"; desc += "Exception:\n"; desc += m_exception.ToString(); } // append versions of all modules desc += "\n\n-----------------------------------\n"; desc += "Modules:\n"; foreach (ProcessModule module in Process.GetCurrentProcess().Modules) { // Get version info FileVersionInfo fileVersionInfo = module.FileVersionInfo; if (fileVersionInfo.FileVersion == "") continue; desc += String.Format("{0} {1}\n", module.ModuleName, fileVersionInfo.FileVersion); } if (m_anonymous) { string dsc = "Reported by: " + m_txtEmail.Text + "\n" + desc; m_bugService.submitBug(m_mappingName, m_titleTextBox.Text, dsc, m_cmbPriority.SelectedIndex); } else { m_bugService.submitBug(m_mappingName, m_userTextBox.Text, m_passwordTextBox.Text, m_titleTextBox.Text, desc, m_cmbPriority.SelectedIndex); } Close(); } } catch(Exception ex) { m_statusBar.Text = "Bug not submitted."; MessageBox.Show("There were errors while submitting this bug\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Tuple<String, int> Web_Read(string url) { int statusCode = 200; string result = ""; WebRequest request = null; WebResponse response = null; StreamReader reader = null; try { //asking for permission to call the specified url. WebPermission permission = new WebPermission(); permission.AddPermission(NetworkAccess.Connect, url); permission.Assert(); request = WebRequest.Create(url); response = request.GetResponse(); reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); } catch (WebException ex) { //Properly handling http errors here if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.NotFound: result = "eror"; statusCode = 404; break; case HttpStatusCode.Forbidden: result = "error"; statusCode = 403; break; case HttpStatusCode.InternalServerError: result = "error"; statusCode = 500; break; } } } catch (Exception) { //placeholder for other sorts of exceptions } finally { // general cleanup if (reader != null) { reader.Close(); //closes the reader and the response stream it was working on at the same time. } if (request != null) { request = null; //not really needed but general cleanup } } return Tuple.Create(result, statusCode); }
private bool IntersectEmpty (WebPermission permission) { return !permission.m_noRestriction && (permission.m_connectList.Count == 0) && (permission.m_acceptList.Count == 0); }
/// <devdoc> /// <para>Compares two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override bool IsSubsetOf(IPermission target) { // Pattern suggested by security engine if (target == null) { return(!m_noRestriction && !m_UnrestrictedConnect && !m_UnrestrictedAccept && m_connectList.Count == 0 && m_acceptList.Count == 0); } WebPermission other = target as WebPermission; if (other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target), "target"); } if (other.m_noRestriction) { return(true); } else if (m_noRestriction) { return(false); } // // Besides SPECIAL case, this method is restricted to only final URIs (strings) on // the current object. // The restriction comes from the problem of finding a Regex to be a subset of another Regex // DelayedRegex regex = null; if (!other.m_UnrestrictedAccept) { if (m_UnrestrictedAccept) { return(false); } else if (m_acceptList.Count != 0) { if (other.m_acceptList.Count == 0) { return(false); } foreach (object obj in this.m_acceptList) { regex = obj as DelayedRegex; if (regex != null) { if (isSpecialSubsetCase(obj.ToString(), other.m_acceptList)) { continue; } throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex)); } if (!isMatchedURI(obj, other.m_acceptList)) { return(false); } } } } if (!other.m_UnrestrictedConnect) { if (m_UnrestrictedConnect) { return(false); } else if (m_connectList.Count != 0) { if (other.m_connectList.Count == 0) { return(false); } foreach (object obj in this.m_connectList) { regex = obj as DelayedRegex; if (regex != null) { if (isSpecialSubsetCase(obj.ToString(), other.m_connectList)) { continue; } throw new NotSupportedException(SR.GetString(SR.net_perm_both_regex)); } if (!isMatchedURI(obj, other.m_connectList)) { return(false); } } } } return(true); }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermissionAttribute.CreatePermission"]/*' /> public override IPermission CreatePermission() { WebPermission perm = null; if (Unrestricted) { perm = new WebPermission( PermissionState.Unrestricted); } else { perm = new WebPermission(PermissionState.None); if (m_accept != null) { if (m_accept is Regex) { perm.AddPermission(NetworkAccess.Accept, (Regex)m_accept); } else { perm.AddPermission(NetworkAccess.Accept, m_accept.ToString()); } } if (m_connect != null) { if (m_connect is Regex) { perm.AddPermission(NetworkAccess.Connect, (Regex)m_connect); } else { perm.AddPermission(NetworkAccess.Connect, m_connect.ToString()); } } } return perm; }
public Tuple<String, int> Web_Read(string url) { int statusCode = 200; string result = ""; StreamReader reader = null; try { //asking for permission to call the specified url. var permission = new WebPermission(); permission.AddPermission(NetworkAccess.Connect, url); permission.Assert(); WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream grs = response.GetResponseStream(); if (grs != null) { reader = new StreamReader(grs); result = reader.ReadToEnd(); } } catch (WebException ex) { //Properly handling http errors here if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse) ex.Response; switch (resp.StatusCode) { case HttpStatusCode.NotFound: result = "eror"; statusCode = 404; break; case HttpStatusCode.Forbidden: result = "error"; statusCode = 403; break; case HttpStatusCode.InternalServerError: result = "error"; statusCode = 500; break; } } } catch (Exception e) { Debug.WriteLine(e); if (Debugger.IsAttached) Debugger.Break(); } finally { // general cleanup if (reader != null) { reader.Close(); //closes the reader and the response stream it was working on at the same time. } } return Tuple.Create(result, statusCode); }
// IPermission interface methods /// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.Copy"]/*' /> /// <devdoc> /// <para> /// Creates a copy of a <see cref='System.Net.WebPermission'/> instance. /// </para> /// </devdoc> public override IPermission Copy() { if (m_noRestriction) { return new WebPermission(true); } WebPermission wp = new WebPermission(); wp.m_acceptList = (ArrayList)m_acceptList.Clone(); wp.m_connectList = (ArrayList)m_connectList.Clone(); return wp; }
public override IPermission Union(IPermission target) { if(target == null) { return Copy(); } else if(!(target is WebPermission)) { throw new ArgumentException(S._("Arg_PermissionMismatch")); } else if(IsUnrestricted() || ((WebPermission)target).IsUnrestricted()) { return new WebPermission (PermissionState.Unrestricted); } else { WebPermission perm = new WebPermission ((WebPermission)target); foreach(Object p1 in acceptList) { if(!perm.acceptList.Contains(p1)) { perm.acceptList.Add(p1); } } foreach(Object p2 in connectList) { if(!perm.connectList.Contains(p2)) { perm.connectList.Add(p2); } } return perm; } }
/// <include file='doc\WebPermission.uex' path='docs/doc[@for="WebPermission.Intersect"]/*' /> /// <devdoc> /// <para>Returns the logical intersection between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Intersect(IPermission target) { // Pattern suggested by Security engine if (target == null) { return null; } WebPermission other = target as WebPermission; if(other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target)); } WebPermission result; if (m_noRestriction) { result = (WebPermission)(other.Copy()); } else if (other.m_noRestriction) { result = (WebPermission)(this.Copy()); } else { result = new WebPermission(false); intersectList(m_connectList, other.m_connectList, result.m_connectList); intersectList(m_acceptList, other.m_acceptList, result.m_acceptList); } // return null if resulting permission is restricted and empty if (!result.m_noRestriction && result.m_connectList.Count == 0 && result.m_acceptList.Count == 0) { return null; } return result; }
private static void GetPermissions() { if (!m_Initialized) { //test RelectionPermission CodeAccessPermission securityTest; try { securityTest = new ReflectionPermission(PermissionState.Unrestricted); securityTest.Demand(); m_ReflectionPermission = true; } catch { //code access security error m_ReflectionPermission = false; } //test WebPermission try { securityTest = new WebPermission(PermissionState.Unrestricted); securityTest.Demand(); m_WebPermission = true; } catch { //code access security error m_WebPermission = false; } //test WebHosting Permission (Full Trust) try { securityTest = new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted); securityTest.Demand(); m_AspNetHostingPermission = true; } catch { //code access security error m_AspNetHostingPermission = false; } m_Initialized = true; //Test for Unmanaged Code permission try { securityTest = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode); securityTest.Demand(); m_UnManagedCodePermission = true; } catch (Exception e) { m_UnManagedCodePermission = false; } } }
// Downloads and compiles the script from a given Uri. // This code can be called by config for a downloaded control, we need to assert. // This code is called holding the lock. private AutoWebProxyState DownloadAndCompile(Uri location) { GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() location:" + ValidationHelper.ToString(location)); AutoWebProxyState newState = AutoWebProxyState.DownloadFailure; WebResponse response = null; TimerThread.Timer timer = null; AutoWebProxyScriptWrapper newScriptInstance = null; // Can't assert this in declarative form (DCR?). This Assert() is needed to be able to create the request to download the proxy script. ExceptionHelper.WebPermissionUnrestricted.Assert(); try { lock (lockObject) { if (aborted) { throw new WebException(NetRes.GetWebStatusString("net_requestaborted", WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled); } request = WebRequest.Create(location); } request.Timeout = Timeout.Infinite; request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default); request.ConnectionGroupName = "__WebProxyScript"; // We have an opportunity here, if caching is disabled AppDomain-wide, to override it with a // custom, trivial cache-provider to get a similar semantic. // // We also want to have a backup caching key in the case when IE has locked an expired script response // if (request.CacheProtocol != null) { GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() Using backup caching."); request.CacheProtocol = new RequestCacheProtocol(backupCache, request.CacheProtocol.Validator); } HttpWebRequest httpWebRequest = request as HttpWebRequest; if (httpWebRequest != null) { httpWebRequest.Accept = "*/*"; httpWebRequest.UserAgent = this.GetType().FullName + "/" + Environment.Version; httpWebRequest.KeepAlive = false; httpWebRequest.Pipelined = false; httpWebRequest.InternalConnectionGroup = true; } else { FtpWebRequest ftpWebRequest = request as FtpWebRequest; if (ftpWebRequest != null) { ftpWebRequest.KeepAlive = false; } } // Use no proxy, default cache - initiate the download. request.Proxy = null; request.Credentials = Engine.Credentials; // Use our own timeout timer so that it can encompass the whole request, not just the headers. if (timerQueue == null) { timerQueue = TimerThread.GetOrCreateQueue(SettingsSectionInternal.Section.DownloadTimeout); } timer = timerQueue.CreateTimer(timerCallback, request); response = request.GetResponse(); // Check Last Modified. DateTime lastModified = DateTime.MinValue; HttpWebResponse httpResponse = response as HttpWebResponse; if (httpResponse != null) { lastModified = httpResponse.LastModified; } else { FtpWebResponse ftpResponse = response as FtpWebResponse; if (ftpResponse != null) { lastModified = ftpResponse.LastModified; } } GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() lastModified:" + lastModified.ToString() + " (script):" + (scriptInstance == null ? "(null)" : scriptInstance.LastModified.ToString())); if (scriptInstance != null && lastModified != DateTime.MinValue && scriptInstance.LastModified == lastModified) { newScriptInstance = scriptInstance; newState = AutoWebProxyState.Completed; } else { string scriptBody = null; byte[] scriptBuffer = null; using (Stream responseStream = response.GetResponseStream()) { SingleItemRequestCache.ReadOnlyStream ros = responseStream as SingleItemRequestCache.ReadOnlyStream; if (ros != null) { scriptBuffer = ros.Buffer; } if (scriptInstance != null && scriptBuffer != null && scriptBuffer == scriptInstance.Buffer) { scriptInstance.LastModified = lastModified; newScriptInstance = scriptInstance; newState = AutoWebProxyState.Completed; GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() Buffer matched - reusing Engine."); } else { using (StreamReader streamReader = new StreamReader(responseStream)) { scriptBody = streamReader.ReadToEnd(); } } } WebResponse tempResponse = response; response = null; tempResponse.Close(); timer.Cancel(); timer = null; if (newState != AutoWebProxyState.Completed) { GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() IsFromCache:" + tempResponse.IsFromCache.ToString() + " scriptInstance:" + ValidationHelper.HashString(scriptInstance)); if (scriptInstance != null && scriptBody == scriptInstance.ScriptBody) { GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() Script matched - using existing Engine."); scriptInstance.LastModified = lastModified; if (scriptBuffer != null) { scriptInstance.Buffer = scriptBuffer; } newScriptInstance = scriptInstance; newState = AutoWebProxyState.Completed; } else { GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() Creating AutoWebProxyScriptWrapper."); newScriptInstance = new AutoWebProxyScriptWrapper(); newScriptInstance.LastModified = lastModified; if (newScriptInstance.Compile(location, scriptBody, scriptBuffer)) { newState = AutoWebProxyState.Completed; } else { newState = AutoWebProxyState.CompilationFailure; } } } } } catch (Exception exception) { if (Logging.On) { Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_script_download_compile_error, exception)); } GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() Download() threw:" + ValidationHelper.ToString(exception)); } finally { if (timer != null) { timer.Cancel(); } // try { if (response != null) { response.Close(); } } finally { WebPermission.RevertAssert(); // The request is not needed anymore. Set it to null, so if Abort() gets called, // after this point, it will result in a no-op. request = null; } } if ((newState == AutoWebProxyState.Completed) && (scriptInstance != newScriptInstance)) { if (scriptInstance != null) { scriptInstance.Close(); } scriptInstance = newScriptInstance; } GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::DownloadAndCompile() retuning newState:" + ValidationHelper.ToString(newState)); return(newState); }
public override IPermission Union(IPermission target) { if (target == null) { return this.Copy(); } WebPermission permission = target as WebPermission; if (permission == null) { throw new ArgumentException(SR.GetString("net_perm_target"), "target"); } if (this.m_noRestriction || permission.m_noRestriction) { return new WebPermission(true); } WebPermission permission2 = new WebPermission(); if (this.m_UnrestrictedConnect || permission.m_UnrestrictedConnect) { permission2.m_UnrestrictedConnect = true; } else { permission2.m_connectList = (ArrayList) permission.m_connectList.Clone(); for (int j = 0; j < this.m_connectList.Count; j++) { DelayedRegex uriRegexPattern = this.m_connectList[j] as DelayedRegex; if (uriRegexPattern == null) { if (this.m_connectList[j] is string) { permission2.AddPermission(NetworkAccess.Connect, (string) this.m_connectList[j]); } else { permission2.AddPermission(NetworkAccess.Connect, (Uri) this.m_connectList[j]); } } else { permission2.AddAsPattern(NetworkAccess.Connect, uriRegexPattern); } } } if (this.m_UnrestrictedAccept || permission.m_UnrestrictedAccept) { permission2.m_UnrestrictedAccept = true; return permission2; } permission2.m_acceptList = (ArrayList) permission.m_acceptList.Clone(); for (int i = 0; i < this.m_acceptList.Count; i++) { DelayedRegex regex2 = this.m_acceptList[i] as DelayedRegex; if (regex2 == null) { if (this.m_acceptList[i] is string) { permission2.AddPermission(NetworkAccess.Accept, (string) this.m_acceptList[i]); } else { permission2.AddPermission(NetworkAccess.Accept, (Uri) this.m_acceptList[i]); } } else { permission2.AddAsPattern(NetworkAccess.Accept, regex2); } } return permission2; }
public override IPermission Intersect (IPermission target) { if (target == null) return null; WebPermission perm = target as WebPermission; if (perm == null) throw new ArgumentException ("Argument not of type WebPermission"); if (m_noRestriction) return IntersectEmpty (perm) ? null : perm.Copy (); if (perm.m_noRestriction) return IntersectEmpty (this) ? null : this.Copy (); WebPermission newperm = new WebPermission (PermissionState.None); Intersect (this.m_connectList, perm.m_connectList, newperm.m_connectList); Intersect (this.m_acceptList, perm.m_acceptList, newperm.m_acceptList); return IntersectEmpty (newperm) ? null : newperm; }
private bool IntersectEmpty(WebPermission permission) { return(!permission.m_noRestriction && (permission.m_connectList.Count == 0) && (permission.m_acceptList.Count == 0)); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return(((!this.m_noRestriction && !this.m_UnrestrictedConnect) && (!this.m_UnrestrictedAccept && (this.m_connectList.Count == 0))) && (this.m_acceptList.Count == 0)); } WebPermission permission = target as WebPermission; if (permission == null) { throw new ArgumentException(SR.GetString("net_perm_target"), "target"); } if (!permission.m_noRestriction) { if (this.m_noRestriction) { return(false); } if (!permission.m_UnrestrictedAccept) { if (this.m_UnrestrictedAccept) { return(false); } if (this.m_acceptList.Count != 0) { if (permission.m_acceptList.Count == 0) { return(false); } foreach (object obj2 in this.m_acceptList) { if (obj2 is DelayedRegex) { if (!isSpecialSubsetCase(obj2.ToString(), permission.m_acceptList)) { throw new NotSupportedException(SR.GetString("net_perm_both_regex")); } } else if (!isMatchedURI(obj2, permission.m_acceptList)) { return(false); } } } } if (!permission.m_UnrestrictedConnect) { if (this.m_UnrestrictedConnect) { return(false); } if (this.m_connectList.Count != 0) { if (permission.m_connectList.Count == 0) { return(false); } foreach (object obj3 in this.m_connectList) { if (obj3 is DelayedRegex) { if (!isSpecialSubsetCase(obj3.ToString(), permission.m_connectList)) { throw new NotSupportedException(SR.GetString("net_perm_both_regex")); } } else if (!isMatchedURI(obj3, permission.m_connectList)) { return(false); } } } } } return(true); }
internal static PermissionSet ExtractAppDomainPermissionSetMinusSiteOfOrigin() { PermissionSet permissionSetAppDomain = AppDomain.CurrentDomain.PermissionSet; // Ensure we remove the FileIO read permission to site of origin. // We choose to use unrestricted here because it does not matter // matter which specific variant of Fileio/Web permission we use // since we are using an overload to check and remove permission // that works on type. There is not a way to remove some // part of a permission, although we could remove this and add // back the delta if the existing permission set had more than the ones // we care about but it is really the path we are targeting here since // that is what causes the delta and hence we are removing it all together. Uri siteOfOrigin = SiteOfOriginContainer.SiteOfOrigin; CodeAccessPermission siteOfOriginReadPermission = null; if (siteOfOrigin.Scheme == Uri.UriSchemeFile) { siteOfOriginReadPermission = new FileIOPermission(PermissionState.Unrestricted); } else if (siteOfOrigin.Scheme == Uri.UriSchemeHttp) { siteOfOriginReadPermission = new WebPermission(PermissionState.Unrestricted); } if (siteOfOriginReadPermission != null) { if (permissionSetAppDomain.GetPermission(siteOfOriginReadPermission.GetType()) != null) { permissionSetAppDomain.RemovePermission(siteOfOriginReadPermission.GetType()); // Failing on a ReadOnlyPermissionSet here? See Dev10.697110. } } return permissionSetAppDomain; }
public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } WebPermission permission = target as WebPermission; if (permission == null) { throw new ArgumentException(SR.GetString("net_perm_target"), "target"); } if (this.m_noRestriction || permission.m_noRestriction) { return(new WebPermission(true)); } WebPermission permission2 = new WebPermission(); if (this.m_UnrestrictedConnect || permission.m_UnrestrictedConnect) { permission2.m_UnrestrictedConnect = true; } else { permission2.m_connectList = (ArrayList)permission.m_connectList.Clone(); for (int j = 0; j < this.m_connectList.Count; j++) { DelayedRegex uriRegexPattern = this.m_connectList[j] as DelayedRegex; if (uriRegexPattern == null) { if (this.m_connectList[j] is string) { permission2.AddPermission(NetworkAccess.Connect, (string)this.m_connectList[j]); } else { permission2.AddPermission(NetworkAccess.Connect, (Uri)this.m_connectList[j]); } } else { permission2.AddAsPattern(NetworkAccess.Connect, uriRegexPattern); } } } if (this.m_UnrestrictedAccept || permission.m_UnrestrictedAccept) { permission2.m_UnrestrictedAccept = true; return(permission2); } permission2.m_acceptList = (ArrayList)permission.m_acceptList.Clone(); for (int i = 0; i < this.m_acceptList.Count; i++) { DelayedRegex regex2 = this.m_acceptList[i] as DelayedRegex; if (regex2 == null) { if (this.m_acceptList[i] is string) { permission2.AddPermission(NetworkAccess.Accept, (string)this.m_acceptList[i]); } else { permission2.AddPermission(NetworkAccess.Accept, (Uri)this.m_acceptList[i]); } } else { permission2.AddAsPattern(NetworkAccess.Accept, regex2); } } return(permission2); }
// Create a permission object that corresponds to this attribute. public override IPermission CreatePermission() { if(Unrestricted) { return new WebPermission (PermissionState.Unrestricted); } else { WebPermission perm = new WebPermission(); if(accept != null) { perm.AddPermission(NetworkAccess.Accept, accept); } if(connect != null) { perm.AddPermission(NetworkAccess.Connect, connect); } return perm; } }
// Methods public override IPermission CreatePermission () { if (this.Unrestricted) return new WebPermission (PermissionState.Unrestricted); WebPermission newPermission = new WebPermission (); if (m_accept != null) { newPermission.AddPermission (NetworkAccess.Accept, (WebPermissionInfo) m_accept); } if (m_connect != null) { newPermission.AddPermission (NetworkAccess.Connect, (WebPermissionInfo) m_connect); } return newPermission; }
// The union of two web permissions is formed by concatenating // the list of allowed regular expressions. There is no check // for duplicates/overlaps /// <devdoc> /// <para>Returns the logical union between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Union(IPermission target) { // Pattern suggested by Security engine if (target==null) { return this.Copy(); } WebPermission other = target as WebPermission; if(other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target), "target"); } if (m_noRestriction || other.m_noRestriction) { return new WebPermission(true); } WebPermission result = new WebPermission(); if (m_UnrestrictedConnect || other.m_UnrestrictedConnect) { result.m_UnrestrictedConnect = true; } else { result.m_connectList = (ArrayList) other.m_connectList.Clone(); for (int i = 0; i < m_connectList.Count; i++) { DelayedRegex uriPattern = m_connectList[i] as DelayedRegex; if(uriPattern == null) if (m_connectList[i] is string) result.AddPermission(NetworkAccess.Connect, (string)m_connectList[i]); else result.AddPermission(NetworkAccess.Connect, (Uri)m_connectList[i]); else result.AddAsPattern(NetworkAccess.Connect, uriPattern); } } if (m_UnrestrictedAccept || other.m_UnrestrictedAccept) { result.m_UnrestrictedAccept = true; } else { result.m_acceptList = (ArrayList) other.m_acceptList.Clone(); for (int i = 0; i < m_acceptList.Count; i++) { DelayedRegex uriPattern = m_acceptList[i] as DelayedRegex; if(uriPattern == null) if (m_acceptList[i] is string) result.AddPermission(NetworkAccess.Accept, (string)m_acceptList[i]); else result.AddPermission(NetworkAccess.Accept, (Uri)m_acceptList[i]); else result.AddAsPattern(NetworkAccess.Accept, uriPattern); } } return result; }
// The union of two web permissions is formed by concatenating // the list of allowed regular expressions. There is no check // for duplicates/overlaps /// <devdoc> /// <para>Returns the logical union between two <see cref='System.Net.WebPermission'/> instances.</para> /// </devdoc> public override IPermission Union(IPermission target) { // Pattern suggested by Security engine if (target == null) { return(this.Copy()); } WebPermission other = target as WebPermission; if (other == null) { throw new ArgumentException(SR.GetString(SR.net_perm_target), "target"); } if (m_noRestriction || other.m_noRestriction) { return(new WebPermission(true)); } WebPermission result = new WebPermission(); if (m_UnrestrictedConnect || other.m_UnrestrictedConnect) { result.m_UnrestrictedConnect = true; } else { result.m_connectList = (ArrayList)other.m_connectList.Clone(); for (int i = 0; i < m_connectList.Count; i++) { DelayedRegex uriPattern = m_connectList[i] as DelayedRegex; if (uriPattern == null) { if (m_connectList[i] is string) { result.AddPermission(NetworkAccess.Connect, (string)m_connectList[i]); } else { result.AddPermission(NetworkAccess.Connect, (Uri)m_connectList[i]); } } else { result.AddAsPattern(NetworkAccess.Connect, uriPattern); } } } if (m_UnrestrictedAccept || other.m_UnrestrictedAccept) { result.m_UnrestrictedAccept = true; } else { result.m_acceptList = (ArrayList)other.m_acceptList.Clone(); for (int i = 0; i < m_acceptList.Count; i++) { DelayedRegex uriPattern = m_acceptList[i] as DelayedRegex; if (uriPattern == null) { if (m_acceptList[i] is string) { result.AddPermission(NetworkAccess.Accept, (string)m_acceptList[i]); } else { result.AddPermission(NetworkAccess.Accept, (Uri)m_acceptList[i]); } } else { result.AddAsPattern(NetworkAccess.Accept, uriPattern); } } } return(result); }