From ae3c30423925960fe70262d1d7e4079b73531c37 Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 3 Jul 2007 22:56:46 +0000 Subject: some security fixes for fluxbox-remote, and a minor change for the gvim fix --- ChangeLog | 7 ++++--- src/CommandParser.cc | 9 +++++---- src/CommandParser.hh | 7 ++++--- src/FbCommandFactory.cc | 19 ++++++++++--------- src/FbCommandFactory.hh | 2 +- src/Screen.cc | 7 ++++--- src/Screen.hh | 2 ++ src/Window.cc | 19 ++++++++++++------- util/fluxbox-remote.cc | 2 +- 9 files changed, 43 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b2423f..7414215 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,9 +3,10 @@ Changes for 1.0.0: *07/07/03: * Avoid some problems with tabbed windows and resize increments (Mark) Window.cc WinClient.cc/hh - * Added utility fluxbox-remote, which takes one argument and has fluxbox - execute it just like in the keys file (Mark) - - e.g. fluxbox-remote "CustomMenu ~/.fluxbox/custommenu" + * Added utility fluxbox-remote, which allows script access to most fluxbox + commands; support must be turned on in the init file with + session.screen.allowRemoteActions; the syntax is, e.g., + fluxbox-remote "CustomMenu ~/.fluxbox/custommenu" (Mark) Screen.cc util/fluxbox-remote.cc util/Makefile.am * Update systemtray and KDE dockapps in slit when background changes (Mark) Screen.cc/hh Systemtray.cc Slit.cc FbTk/FbPixmap.cc/hh diff --git a/src/CommandParser.cc b/src/CommandParser.cc index 95630d0..a1e52e5 100644 --- a/src/CommandParser.cc +++ b/src/CommandParser.cc @@ -62,7 +62,7 @@ CommandParser &CommandParser::instance() { return *s_singleton; } -FbTk::Command *CommandParser::parseLine(const std::string &line) { +FbTk::Command *CommandParser::parseLine(const std::string &line, bool trusted) { // parse arguments and command string command = line; @@ -83,13 +83,14 @@ FbTk::Command *CommandParser::parseLine(const std::string &line) { // we didn't find any matching command in default commands, // so we search in the command creators modules for a // matching command string - return toCommand(command, arguments); + return toCommand(command, arguments, trusted); } -FbTk::Command *CommandParser::toCommand(const std::string &command_str, const std::string &arguments) { +FbTk::Command *CommandParser::toCommand(const std::string &command_str, + const std::string &arguments, bool trusted) { if (m_commandfactorys[command_str] != 0) - return m_commandfactorys[command_str]->stringToCommand(command_str, arguments); + return m_commandfactorys[command_str]->stringToCommand(command_str, arguments, trusted); return 0; } diff --git a/src/CommandParser.hh b/src/CommandParser.hh index 5501345..1bc3094 100644 --- a/src/CommandParser.hh +++ b/src/CommandParser.hh @@ -41,7 +41,8 @@ public: CommandFactory(); virtual ~CommandFactory(); virtual FbTk::Command *stringToCommand(const std::string &command, - const std::string &arguments) = 0; + const std::string &arguments, + bool trusted) = 0; protected: void addCommand(const std::string &value); }; @@ -52,7 +53,7 @@ public: typedef std::map CommandFactoryMap; /// @return parses and returns a command matching the line - FbTk::Command *parseLine(const std::string &line); + FbTk::Command *parseLine(const std::string &line, bool trusted = true); CommandParser(); @@ -70,7 +71,7 @@ private: /// search for a command in our command factory map FbTk::Command *toCommand(const std::string &command, - const std::string &arguments); + const std::string &arguments, bool trusted); CommandFactoryMap m_commandfactorys; ///< a string to factory map diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index 1382c89..0257374 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc @@ -173,12 +173,12 @@ FbCommandFactory::FbCommandFactory() { } FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, - const std::string &arguments) { + const std::string &arguments, bool trusted) { using namespace FbCommands; // // WM commands // - if (command == "restart") + if (command == "restart" && trusted) return new RestartFluxboxCmd(arguments); else if (command == "reconfigure" || command == "reconfig") return new ReconfigureFluxboxCmd(); @@ -190,11 +190,12 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, return new KeyModeCmd(arguments); else if (command == "saverc") return new SaveResources(); - else if (command == "execcommand" || command == "execute" || command == "exec") + else if (command == "execcommand" || command == "execute" || command == "exec") { + if (!trusted) return 0; return new ExecuteCmd(arguments); // execute command on key screen - else if (command == "exit" || command == "quit") + } else if (command == "exit" || command == "quit") return new ExitFluxboxCmd(); - else if (command == "setenv" || command == "export") { + else if ((command == "setenv" || command == "export") && trusted) { string name = arguments; FbTk::StringUtil::removeFirstWhitespace(name); @@ -216,9 +217,9 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, } else if (command == "commanddialog") // run specified fluxbox command return new CommandDialogCmd(); - else if (command == "bindkey") + else if (command == "bindkey" && trusted) return new BindKeyCmd(arguments); - else if (command == "setresourcevalue") { + else if (command == "setresourcevalue" && trusted) { // we need to parse arguments as: // string name = arguments; @@ -517,7 +518,7 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, } c= FbTk::StringUtil::toLower(cmd); - FbTk::Command* fbcmd= stringToCommand(c,a); + FbTk::Command* fbcmd= stringToCommand(c,a,trusted); if (fbcmd) { FbTk::RefCount rfbcmd(fbcmd); macro->add(rfbcmd); @@ -554,7 +555,7 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, } c= FbTk::StringUtil::toLower(cmd); - FbTk::Command* fbcmd= stringToCommand(c,a); + FbTk::Command* fbcmd= stringToCommand(c,a,trusted); if (fbcmd) { FbTk::RefCount rfbcmd(fbcmd); macro->add(rfbcmd); diff --git a/src/FbCommandFactory.hh b/src/FbCommandFactory.hh index dfee559..4b68499 100644 --- a/src/FbCommandFactory.hh +++ b/src/FbCommandFactory.hh @@ -27,7 +27,7 @@ class FbCommandFactory: public CommandFactory { public: FbTk::Command *stringToCommand(const std::string &command, - const std::string &arguments); + const std::string &arguments, bool trusted); private: FbCommandFactory(); diff --git a/src/Screen.cc b/src/Screen.cc index 68f928b..dfa986e 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -326,6 +326,7 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm, altscrname+".overlay.CapStyle"), scroll_action(rm, "", scrname+".windowScrollAction", altscrname+".WindowScrollAction"), scroll_reverse(rm, false, scrname+".windowScrollReverse", altscrname+".WindowScrollReverse"), + allow_remote_actions(rm, false, scrname+".allowRemoteActions", altscrname+".AllowRemoteActions"), max_over_tabs(rm, false, scrname+".tabs.maxOver", altscrname+".Tabs.MaxOver"), default_internal_tabs(rm, true /* TODO: autoconf option? */ , scrname+".tabs.intitlebar", altscrname+".Tabs.InTitlebar") { @@ -785,8 +786,8 @@ void BScreen::update(FbTk::Subject *subj) { void BScreen::propertyNotify(Atom atom) { static Atom fbcmd_atom = XInternAtom(FbTk::App::instance()->display(), - "_FLUXBOX_COMMAND", False); - if (atom == fbcmd_atom) { + "_FLUXBOX_ACTION", False); + if (allowRemoteActions() && atom == fbcmd_atom) { Atom xa_ret_type; int ret_format; unsigned long ret_nitems, ret_bytes_after; @@ -803,7 +804,7 @@ void BScreen::propertyNotify(Atom atom) { &ret_bytes_after, (unsigned char **)&str); } - FbTk::RefCount cmd(CommandParser::instance().parseLine(str)); + FbTk::RefCount cmd(CommandParser::instance().parseLine(str, false)); if (cmd.get()) cmd->execute(); XFree(str); diff --git a/src/Screen.hh b/src/Screen.hh index 7ea6f53..77a5169 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -149,6 +149,7 @@ public: inline const std::string &getScrollAction() const { return *resource.scroll_action; } inline const bool getScrollReverse() const { return *resource.scroll_reverse; } + inline const bool allowRemoteActions() const { return *resource.allow_remote_actions; } inline const bool getDefaultInternalTabs() const { return *resource.default_internal_tabs; } inline const bool getMaxOverTabs() const { return *resource.max_over_tabs; } @@ -582,6 +583,7 @@ private: FbTk::Resource gc_cap_style; FbTk::Resource scroll_action; FbTk::Resource scroll_reverse; + FbTk::Resource allow_remote_actions; FbTk::Resource max_over_tabs; FbTk::Resource default_internal_tabs; diff --git a/src/Window.cc b/src/Window.cc index f6fe225..1bfab7f 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -2564,13 +2564,18 @@ void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { int cx = frame().x(), cy = frame().y(), ignore = 0; unsigned int cw = frame().width(), ch = frame().height(); - // if this is not m_client and m_client has resize_inc, make sure the new - // size would be ok with m_client - if (client != m_client && cr.value_mask & CWWidth && - cr.value_mask & CWHeight && - !m_client->checkSizeHints(cr.width, cr.height)) { - sendConfigureNotify(); - return; + // make sure the new width/height would be ok with all clients, or else they + // could try to resize the window back and forth + if (client != m_client && + cr.value_mask & CWWidth && cr.value_mask & CWHeight) { + ClientList::iterator it = clientList().begin(); + ClientList::iterator it_end = clientList().end(); + for (; it != it_end; ++it) { + if (!m_client->checkSizeHints(cr.width, cr.height)) { + sendConfigureNotify(); + return; + } + } } if (cr.value_mask & CWBorderWidth) diff --git a/util/fluxbox-remote.cc b/util/fluxbox-remote.cc index 67c2193..56ba8ad 100644 --- a/util/fluxbox-remote.cc +++ b/util/fluxbox-remote.cc @@ -40,7 +40,7 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - Atom fbcmd_atom = XInternAtom(disp, "_FLUXBOX_COMMAND", False); + Atom fbcmd_atom = XInternAtom(disp, "_FLUXBOX_ACTION", False); Window root = DefaultRootWindow(disp); char *str = argv[1]; -- cgit v0.11.2