Import upstream 0.7.1
[manu/suphp.git] / src / Application.hpp
index be7ed82..82b8d20 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-    suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
+    suPHP - (c)2002-2008 Sebastian Marsching <sebastian@marsching.com>
 
     This file is part of suPHP.
 
 
     This file is part of suPHP.
 
@@ -39,6 +39,8 @@ enum TargetMode {
 #include "SystemException.hpp"
 #include "SoftException.hpp"
 #include "SecurityException.hpp"
 #include "SystemException.hpp"
 #include "SoftException.hpp"
 #include "SecurityException.hpp"
+#include "UserInfo.hpp"
+#include "GroupInfo.hpp"
 
 namespace suPHP {
     /**
 
 namespace suPHP {
     /**
@@ -47,77 +49,108 @@ namespace suPHP {
      */
     class Application {
     private:
      */
     class Application {
     private:
-       /**
-        * Print message containing version information
-        */
-       void printAboutMessage();
-       
-       /**
-        * Checks wheter process has root privileges
-        * and calling user is webserver user
-        */
-       void checkProcessPermissions(Configuration& config) 
-           throw (SecurityException, LookupException);
-       /**
-        * Checks scriptfile.
-        * Includes check for path, symbollink and permissions
-        */
-       void checkScriptFile(const std::string& scriptFilename, 
-                            const Configuration& config, 
-                            const Environment& environment) const
-           throw (SystemException, SoftException);
-       
-       /**
-        * Changes process permission (user and group).
-        * Uses preprocessor macros to distinguish between modes
-        */
-       void changeProcessPermissions(const std::string& scriptFilename,
-                                     const Configuration& config,
-                                     const Environment& environment) const
-           throw (SystemException, SoftException, SecurityException);
-
-       /**
-        * Prepares the environment before invoking the script
-        */
-       Environment prepareEnvironment(const Environment& sourceEnv,
-                                      const Configuration& config,
-                                      TargetMode mode)
-           throw (KeyNotFoundException);
-
-       /**
-        * Returns interpreter for script being executed
-        */
-       std::string getInterpreter(const Environment& env,
-                                  const Configuration& config)
-           throw (SecurityException);
-       
-       /**
-        * Returns mode interpreter is using
-        */
-       TargetMode getTargetMode(const std::string& interpreter)
-           throw (SecurityException);
-
-       /**
-        * Runs script
-        */
-       void executeScript(const std::string& scriptFilename,
-                          const std::string& interpreter,
-                          TargetMode mode,
-                          const Environment& env,
-                          const Configuration& config) const
-           throw (SoftException);
+        /**
+         * Print message containing version information
+         */
+        void printAboutMessage();
+        
+        /**
+         * Checks wheter process has root privileges
+         * and calling user is webserver user
+         */
+        void checkProcessPermissions(Configuration& config) 
+            throw (SecurityException, LookupException);
+        
+        /**
+         * Checks scriptfile (first stage).
+         * Includes check for VHost docroot, symbollink and permissions.
+         */
+        void checkScriptFileStage1(const std::string& scriptFilename, 
+                             const Configuration& config, 
+                             const Environment& environment) const
+            throw (SystemException, SoftException);
+        
+        /**
+         * Checks scriptfile.
+         * Includes check for paths which might be user specific
+         */
+        void checkScriptFileStage2(const std::string& scriptFilename, 
+                             const Configuration& config, 
+                             const Environment& environment,
+                             const UserInfo& targetUser,
+                             const GroupInfo& targetGroup) const
+            throw (SystemException, SoftException);
+        
+        /**
+         * Determines target user and group that is to be used for script execution.
+         * Uses preprocessor macros to distinguish between modes
+         */
+        void checkProcessPermissions(const std::string& scriptFilename,
+                                      const Configuration& config,
+                                      const Environment& environment,
+                                      UserInfo& targetUser,
+                                      GroupInfo& targetGroup) const
+            throw (SystemException, SoftException, SecurityException);
+        
+        /**
+         * Changes process permission (user and group).
+         * Uses preprocessor macros to distinguish between modes
+         */
+        void changeProcessPermissions(const Configuration& config,
+                                      const UserInfo& targetUser,
+                                      const GroupInfo& targetGroup) const
+            throw (SystemException, SoftException, SecurityException);
+
+        /**
+         * Prepares the environment before invoking the script
+         */
+        Environment prepareEnvironment(const Environment& sourceEnv,
+                                       const Configuration& config,
+                                       TargetMode mode)
+            throw (KeyNotFoundException);
+
+        /**
+         * Returns interpreter for script being executed
+         */
+        std::string getInterpreter(const Environment& env,
+                                   const Configuration& config)
+            throw (SecurityException);
+        
+        /**
+         * Returns mode interpreter is using
+         */
+        TargetMode getTargetMode(const std::string& interpreter)
+            throw (SecurityException);
+
+        /**
+         * Runs script
+         */
+        void executeScript(const std::string& scriptFilename,
+                           const std::string& interpreter,
+                           TargetMode mode,
+                           const Environment& env,
+                           const Configuration& config) const
+            throw (SoftException);
+        
+        /**
+         * Checks ownership and permissions for parent directories
+         */
+        void checkParentDirectories(const File& file,
+                                    const UserInfo& owner,
+                                    const Configuration& config) const
+            throw (SoftException);
 
 
     public:
 
 
     public:
-       /**
-        * Constructer
-        */
-       Application();
-       
-       /**
-        * Function called by the main() function
-        */
-       int run(CommandLine& cmdline, Environment& env);
+        /**
+         * Constructer
+         */
+        Application();
+        
+        /**
+         * Function called by the main() function
+         */
+        int run(CommandLine& cmdline, Environment& env);
     };
 };
 
     };
 };