X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FExecutor.hh;h=882792a806660cde23998a71bb5e1c02c3f1f6f8;hb=9e7071473642404359c8b7a88c78fe02f00baf16;hp=86e54be2f6f4496da93c58754e8a7bcb407abfaf;hpb=e879290346fe5242d7df2d70ee552d264081492f;p=senf.git diff --git a/Console/Executor.hh b/Console/Executor.hh index 86e54be..882792a 100644 --- a/Console/Executor.hh +++ b/Console/Executor.hh @@ -66,6 +66,12 @@ namespace console { /// Thrown by built-in 'exit' command struct ExitException {}; + /// Executor policy function + typedef boost::function SecurityPolicy; + + /// Thrown by the SecurityPolicy to silently ignore a command + struct IgnoreCommandException {}; + /////////////////////////////////////////////////////////////////////////// //\/name Structors and default members ///\{ @@ -85,6 +91,8 @@ namespace console { /**< Output will be written to \a output. Same as execute(). */ DirectoryNode & cwd() const; ///< Current working directory + std::string cwdPath() const; ///< Return pathname of current directory + bool skipping() const; ///< \c true, if currently skipping a directory group bool autocd() const; ///< Get current autocd status /**< if autocd is enabled, specifying a directory name as @@ -104,27 +112,54 @@ namespace console { Executor & autocomplete(bool v); ///< Set autocomplete status /**< \see autocomplete() */ + DirectoryNode & chroot() const; ///< Get root node + /**< The root node defaults to senf::console::root(). If + changed, all path references are relative to this node + and objects outside that tree cannot be accessed. */ + Executor & chroot(DirectoryNode & node); ///< chroot into given directory + /**< After this call, all path's are interpreted relative to + \a node and only nodes in the tree rooted at \a node + are accessible via the executor. This value defaults to + senf::console::root(). */ + + Executor & policy(SecurityPolicy policy = SecurityPolicy()); ///< Set security policy + /**< The security policy is called before traversing a node + to validate that access. */ + protected: private: + typedef std::vector Path; + + void exec(std::ostream & output, ParseCommandInfo const & command); + + void cd(ParseCommandInfo::TokensRange dir); + void ls(std::ostream & output, ParseCommandInfo::TokensRange dir); + void pushd(ParseCommandInfo::TokensRange dir); + void popd(); + void exit(); + void help(std::ostream & output, ParseCommandInfo::TokensRange path); + GenericNode & traverseNode(ParseCommandInfo::TokensRange const & path); - GenericNode & traverseCommand(ParseCommandInfo::CommandPathRange const & path); - DirectoryNode & traverseDirectory(ParseCommandInfo::TokensRange const & path); + void traverseDirectory(ParseCommandInfo::TokensRange const & path, + Path & dir); struct InvalidPathException {}; struct InvalidDirectoryException {}; struct InvalidCommandException {}; + + DirectoryNode::ptr root_; + SecurityPolicy policy_; + mutable Path cwd_; + Path oldCwd_; - DirectoryNode::weak_ptr cwd_; - DirectoryNode::weak_ptr oldCwd_; - typedef std::vector DirStack; + typedef std::vector DirStack; DirStack dirstack_; bool autocd_; bool autocomplete_; }; - }} ///////////////////////////////hh.e////////////////////////////////////////