/// <devdoc>
        /// Gets the appropriate mapped path for the DataFile.
        /// </devdoc>
        private string GetPhysicalDataFilePath()
        {
            string filename = DataFile;

            if (filename.Length == 0)
            {
                return(null);
            }
            if (!System.Web.Util.UrlPath.IsAbsolutePhysicalPath(filename))
            {
                // Root relative path
                if (DesignMode)
                {
                    // This exception should never be thrown - the designer always maps paths
                    // before using the runtime control.
                    throw new NotSupportedException(SR.GetString(SR.AccessDataSource_DesignTimeRelativePathsNotSupported, ID));
                }
                filename = Context.Request.MapPath(filename, AppRelativeTemplateSourceDirectory, true);
            }

            HttpRuntime.CheckFilePermission(filename, true);

            // We also need to check for path discovery permissions for the
            // file since the page developer will be able to see the physical
            // path in the ConnectionString property.
            if (!HttpRuntime.HasPathDiscoveryPermission(filename))
            {
                throw new HttpException(SR.GetString(SR.AccessDataSource_NoPathDiscoveryPermission, HttpRuntime.GetSafePath(filename), ID));
            }
            return(filename);
        }
Exemple #2
0
        public void Save()
        {
            if (!this.IsModifiable)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("XmlDataSource_SaveNotAllowed", new object[] { this.ID }));
            }
            string writeableDataFile = this.WriteableDataFile;

            HttpRuntime.CheckFilePermission(writeableDataFile, true);
            this.GetXmlDocument().Save(writeableDataFile);
        }
        /// <devdoc>
        /// Saves the XML data to disk.
        /// </devdoc>
        public void Save()
        {
            if (!IsModifiable)
            {
                throw new InvalidOperationException(SR.GetString(SR.XmlDataSource_SaveNotAllowed, ID));
            }

            string writeableDataFile = WriteableDataFile;

            Debug.Assert(!String.IsNullOrEmpty(writeableDataFile), "Did not expect WriteableDataFile to be empty in Save()");

            // Check for write permissions
            HttpRuntime.CheckFilePermission(writeableDataFile, true);

            // Save the document
            GetXmlDocument().Save(writeableDataFile);
        }
Exemple #4
0
        private string GetPhysicalDataFilePath()
        {
            string dataFile = this.DataFile;

            if (dataFile.Length == 0)
            {
                return(null);
            }
            if (!UrlPath.IsAbsolutePhysicalPath(dataFile))
            {
                if (base.DesignMode)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("AccessDataSource_DesignTimeRelativePathsNotSupported", new object[] { this.ID }));
                }
                dataFile = this.Context.Request.MapPath(dataFile, base.AppRelativeTemplateSourceDirectory, true);
            }
            HttpRuntime.CheckFilePermission(dataFile, true);
            if (!HttpRuntime.HasPathDiscoveryPermission(dataFile))
            {
                throw new HttpException(System.Web.SR.GetString("AccessDataSource_NoPathDiscoveryPermission", new object[] { HttpRuntime.GetSafePath(dataFile), this.ID }));
            }
            return(dataFile);
        }
 private void InitApp()
 {
     try
     {
         using (new ApplicationImpersonationContext())
         {
             if (this._InitAppDone)
             {
                 if (DateTime.Now > this._LastUpdateCacheDate.AddMinutes((double)this.CacheRefreshInterval))
                 {
                     this._LastUpdateCacheDate = DateTime.Now;
                     this.CallMethod(this._ObjAzAuthorizationStoreClass, "UpdateCache", null);
                 }
             }
             else
             {
                 lock (this)
                 {
                     if (!this._InitAppDone)
                     {
                         if (this._ConnectionString.ToLower(CultureInfo.InvariantCulture).StartsWith("msxml://", StringComparison.Ordinal))
                         {
                             if (this._ConnectionString.Contains("/~/"))
                             {
                                 string newValue = null;
                                 if (HostingEnvironment.IsHosted)
                                 {
                                     newValue = HttpRuntime.AppDomainAppPath;
                                 }
                                 else
                                 {
                                     Process       currentProcess = Process.GetCurrentProcess();
                                     ProcessModule module         = (currentProcess != null) ? currentProcess.MainModule : null;
                                     string        str2           = (module != null) ? module.FileName : null;
                                     if (str2 != null)
                                     {
                                         newValue = Path.GetDirectoryName(str2);
                                     }
                                     if ((newValue == null) || (newValue.Length < 1))
                                     {
                                         newValue = Environment.CurrentDirectory;
                                     }
                                 }
                                 newValue = newValue.Replace('\\', '/');
                                 this._ConnectionString = this._ConnectionString.Replace("~", newValue);
                             }
                             string path = this._ConnectionString.Substring("msxml://".Length).Replace('/', '\\');
                             if (HostingEnvironment.IsHosted)
                             {
                                 HttpRuntime.CheckFilePermission(path, false);
                             }
                             if (!System.Web.Util.FileUtil.FileExists(path))
                             {
                                 throw new FileNotFoundException(System.Web.SR.GetString("AuthStore_policy_file_not_found", new object[] { HttpRuntime.GetSafePath(path) }));
                             }
                             this._XmlFileName = path;
                         }
                         Type type = null;
                         try
                         {
                             this._NewAuthInterface = true;
                             type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);
                             if (type == null)
                             {
                                 type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);
                             }
                             if (type == null)
                             {
                                 this._NewAuthInterface = false;
                                 type = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", true);
                             }
                         }
                         catch (FileNotFoundException exception)
                         {
                             HttpContext current = HttpContext.Current;
                             if (current == null)
                             {
                                 throw new ProviderException(System.Web.SR.GetString("AuthStoreNotInstalled_Title"), exception);
                             }
                             current.Response.Clear();
                             current.Response.StatusCode = 500;
                             current.Response.Write(AuthStoreErrorFormatter.GetErrorText());
                             current.Response.End();
                         }
                         if (HostingEnvironment.IsHosted && (this._XmlFileName != null))
                         {
                             InternalSecurityPermissions.Unrestricted.Assert();
                         }
                         this._ObjAzAuthorizationStoreClass = Activator.CreateInstance(type);
                         object[] objArray3 = new object[3];
                         objArray3[0] = 0;
                         objArray3[1] = this._ConnectionString;
                         object[] args = objArray3;
                         this.CallMethod(this._ObjAzAuthorizationStoreClass, "Initialize", args);
                         args = new object[] { this._AppName, null };
                         if (this._NewAuthInterface)
                         {
                             this._ObjAzApplication = this.CallMethod(this._ObjAzAuthorizationStoreClass, "OpenApplication2", args);
                         }
                         else
                         {
                             this._ObjAzApplication = this.CallMethod(this._ObjAzAuthorizationStoreClass, "OpenApplication", args);
                         }
                         if (this._ObjAzApplication == null)
                         {
                             throw new ProviderException(System.Web.SR.GetString("AuthStore_Application_not_found"));
                         }
                         this._ObjAzScope = null;
                         if (!string.IsNullOrEmpty(this._ScopeName))
                         {
                             args[0]          = this._ScopeName;
                             args[1]          = null;
                             this._ObjAzScope = this.CallMethod(this._ObjAzApplication, "OpenScope", args);
                             if (this._ObjAzScope == null)
                             {
                                 throw new ProviderException(System.Web.SR.GetString("AuthStore_Scope_not_found"));
                             }
                         }
                         this._LastUpdateCacheDate = DateTime.Now;
                         this._InitAppDone         = true;
                     }
                 }
             }
         }
     }
     catch
     {
         throw;
     }
 }
Exemple #6
0
        private static CachedRawResponse Convert(OutputCacheEntry oce)
        {
            ArrayList headers = null;

            if (oce.HeaderElements != null && oce.HeaderElements.Count > 0)
            {
                headers = new ArrayList(oce.HeaderElements.Count);
                for (int i = 0; i < oce.HeaderElements.Count; i++)
                {
                    HttpResponseHeader h = new HttpResponseHeader(oce.HeaderElements[i].Name, oce.HeaderElements[i].Value);
                    headers.Add(h);
                }
            }

            ArrayList buffers = null;

            if (oce.ResponseElements != null && oce.ResponseElements.Count > 0)
            {
                buffers = new ArrayList(oce.ResponseElements.Count);
                for (int i = 0; i < oce.ResponseElements.Count; i++)
                {
                    ResponseElement      re   = oce.ResponseElements[i];
                    IHttpResponseElement elem = null;
                    if (re is FileResponseElement)
                    {
                        HttpContext       context     = HttpContext.Current;
                        HttpWorkerRequest wr          = (context != null) ? context.WorkerRequest : null;
                        bool supportsLongTransmitFile = (wr != null && wr.SupportsLongTransmitFile);
                        bool isImpersonating          = ((context != null && context.IsClientImpersonationConfigured) || HttpRuntime.IsOnUNCShareInternal);
                        FileResponseElement fre       = (FileResponseElement)re;

                        // DevDiv #21203: Need to verify permission to access the requested file since handled by native code.
                        HttpRuntime.CheckFilePermission(fre.Path);

                        elem = new HttpFileResponseElement(fre.Path, fre.Offset, fre.Length, isImpersonating, supportsLongTransmitFile);
                    }
                    else if (re is MemoryResponseElement)
                    {
                        MemoryResponseElement mre = (MemoryResponseElement)re;
                        int size = System.Convert.ToInt32(mre.Length);
                        elem = new HttpResponseBufferElement(mre.Buffer, size);
                    }
                    else if (re is SubstitutionResponseElement)
                    {
                        SubstitutionResponseElement sre = (SubstitutionResponseElement)re;
                        elem = new HttpSubstBlockResponseElement(sre.Callback);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                    buffers.Add(elem);
                }
            }
            else
            {
                buffers = new ArrayList();
            }

            HttpRawResponse   rawResponse       = new HttpRawResponse(oce.StatusCode, oce.StatusDescription, headers, buffers, false /*hasSubstBlocks*/);
            CachedRawResponse cachedRawResponse = new CachedRawResponse(rawResponse, oce.Settings, oce.KernelCacheUrl, oce.CachedVaryId);

            return(cachedRawResponse);
        }
Exemple #7
0
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////
        private void InitApp()
        {
            try {
                using (new ApplicationImpersonationContext()) {
                    if (_InitAppDone)
                    {
                        if (DateTime.Now > _LastUpdateCacheDate.AddMinutes(CacheRefreshInterval))
                        {
                            _LastUpdateCacheDate = DateTime.Now;
                            CallMethod(_ObjAzAuthorizationStoreClass, "UpdateCache", null);
                        }
                        return;
                    }
                    lock (this) {
                        if (_InitAppDone)
                        {
                            return;
                        }
                        if (_ConnectionString.ToLower(CultureInfo.InvariantCulture).StartsWith("msxml://", StringComparison.Ordinal))
                        {
                            if (_ConnectionString.Contains("/~/"))
                            {
                                string appPath = null;
                                if (HostingEnvironment.IsHosted)
                                {
                                    appPath = HttpRuntime.AppDomainAppPath;
                                }
                                else
                                {
    #if !FEATURE_PAL // FEATURE_PAL does not enable the ProcessModule class
                                    Process       p       = Process.GetCurrentProcess();
                                    ProcessModule pm      = (p != null ? p.MainModule : null);
                                    string        exeName = (pm != null ? pm.FileName : null);
                                    if (exeName != null)
                                    {
                                        appPath = System.IO.Path.GetDirectoryName(exeName);
                                    }
    #endif // !FEATURE_PAL
                                    if (appPath == null || appPath.Length < 1)
                                    {
                                        appPath = Environment.CurrentDirectory;
                                    }
                                }
                                appPath           = appPath.Replace('\\', '/');
                                _ConnectionString = _ConnectionString.Replace("~", appPath);
                            }
                            string fileName = _ConnectionString.Substring("msxml://".Length).Replace('/', '\\');

                            if (HostingEnvironment.IsHosted)
                            {
                                HttpRuntime.CheckFilePermission(fileName, false);
                            }

                            if (!FileUtil.FileExists(fileName))
                            {
                                throw new FileNotFoundException(SR.GetString(SR.AuthStore_policy_file_not_found,
                                                                             HttpRuntime.GetSafePath(fileName)));
                            }

                            _XmlFileName = fileName;
                        }

                        Type typeAzAuthorizationStoreClass = null;
                        try {
                            _NewAuthInterface             = true;
                            typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                         false /*throwOnError*/);
                            if (typeAzAuthorizationStoreClass == null)
                            {
                                typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                             false /*throwOnError*/);
                            }
                            if (typeAzAuthorizationStoreClass == null)
                            {
                                _NewAuthInterface             = false;
                                typeAzAuthorizationStoreClass = Type.GetType("Microsoft.Interop.Security.AzRoles.AzAuthorizationStoreClass, Microsoft.Interop.Security.AzRoles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
                                                                             true /*throwOnError*/);
                            }
                        }
                        catch (FileNotFoundException e) {
                            HttpContext context = HttpContext.Current;
                            if (context == null)
                            {
                                throw new ProviderException(SR.GetString(SR.AuthStoreNotInstalled_Title), e);
                            }

                            context.Response.Clear();
                            context.Response.StatusCode = 500;
                            context.Response.Write(AuthStoreErrorFormatter.GetErrorText());
                            context.Response.End();
                        }

                        if (HostingEnvironment.IsHosted && _XmlFileName != null)
                        {
                            InternalSecurityPermissions.Unrestricted.Assert();
                        }

                        _ObjAzAuthorizationStoreClass = Activator.CreateInstance(typeAzAuthorizationStoreClass);
                        object[] args = new object[] { 0, _ConnectionString, null };

                        CallMethod(_ObjAzAuthorizationStoreClass, "Initialize", args);

                        args    = new object[2];
                        args[0] = _AppName;
                        args[1] = null;
                        if (_NewAuthInterface)
                        {
                            _ObjAzApplication = CallMethod(_ObjAzAuthorizationStoreClass, "OpenApplication2", args);
                        }
                        else
                        {
                            _ObjAzApplication = CallMethod(_ObjAzAuthorizationStoreClass, "OpenApplication", args);
                        }
                        if (_ObjAzApplication == null)
                        {
                            throw new ProviderException(SR.GetString(SR.AuthStore_Application_not_found));
                        }
                        _ObjAzScope = null;
                        if (!string.IsNullOrEmpty(_ScopeName))
                        {
                            args[0]     = _ScopeName;
                            args[1]     = null;
                            _ObjAzScope = CallMethod(_ObjAzApplication, "OpenScope", args);
                            if (_ObjAzScope == null)
                            {
                                throw new ProviderException(SR.GetString(SR.AuthStore_Scope_not_found));
                            }
                        }
                        _LastUpdateCacheDate = DateTime.Now;
                        _InitAppDone         = true;
                    }
                }
            } catch {
                throw;
            }
        }