Hi,

this is a little patch to add a 'Allow RootCommand' option in the Config
menu. It is saved on a per-screen basis, in ~/.blackboxrc.

The ugly thing is that it is not yet i18n-ed, because I don't know how to
do that (will improve this patch as soon as I learn it, and if others like
it).

I thought this idea might be useful: some people might use other
background managers, or might like to disable rootcommands for security
reasons.  Please feel free to either ignore it or make it better, it works
for me.

Bye,
Wilbert

-- 
Wilbert Berendsen (http://www.xs4all.nl/~wbsoft/)
http://www.stoppoliceware.org/ http://digitalspeech.org/
diff -urN blackbox-orig/src/Configmenu.cc blackbox/src/Configmenu.cc
--- blackbox-orig/src/Configmenu.cc     Fri May 24 23:49:18 2002
+++ blackbox/src/Configmenu.cc  Sun May 26 18:27:32 2002
@@ -53,6 +53,10 @@
               "Focus New Windows"), 4);
   insert(i18n(ConfigmenuSet, ConfigmenuFocusLast,
               "Focus Last Window on Workspace"), 5);
+  insert( /* don't know how to handle i18n new strings
+          i18n(ConfigmenuSet, ConfigmenuAllowRootCmd,
+              "Allow RootCommand") */
+              "Allow RootCommand", 6);
   update();
 
   setItemSelected(2, getScreen()->getImageControl()->doDither());
@@ -60,6 +64,8 @@
   setItemSelected(4, getScreen()->doFullMax());
   setItemSelected(5, getScreen()->doFocusNew());
   setItemSelected(6, getScreen()->doFocusLast());
+  setItemSelected(7, getScreen()->doAllowRootCmd());
+
 }
 
 Configmenu::~Configmenu(void) {
@@ -113,6 +119,12 @@
     setItemSelected(index, getScreen()->doFocusLast());
     break;
   }
+  
+  case 6: { // allow root command
+    getScreen()->saveAllowRootCmd((! getScreen()->doAllowRootCmd()));
+    setItemSelected(index, getScreen()->doAllowRootCmd());
+  }
+  
   } // switch
 }
 
diff -urN blackbox-orig/src/Screen.cc blackbox/src/Screen.cc
--- blackbox-orig/src/Screen.cc Sat May 25 10:06:03 2002
+++ blackbox/src/Screen.cc      Sun May 26 18:36:54 2002
@@ -689,7 +689,8 @@
     resource.frame_width = uint_value;
   }
 
-  if (XrmGetResource(resource.stylerc, "rootCommand", "RootCommand",
+  if ( this->doAllowRootCmd() &&
+      XrmGetResource(resource.stylerc, "rootCommand", "RootCommand",
                      &value_type, &value)) {
     bexec(value.addr, displayString());
   }
diff -urN blackbox-orig/src/Screen.hh blackbox/src/Screen.hh
--- blackbox-orig/src/Screen.hh Fri May 24 23:49:23 2002
+++ blackbox/src/Screen.hh      Sun May 26 18:26:32 2002
@@ -149,7 +149,7 @@
 
     bool toolbar_on_top, toolbar_auto_hide, sloppy_focus, auto_raise,
       auto_edge_balance, image_dither, ordered_dither, opaque_move, full_max,
-      focus_new, focus_last, click_raise;
+      focus_new, focus_last, allow_rootcmd, click_raise;
     BColor border_color;
     XrmDatabase stylerc;
 
@@ -223,6 +223,7 @@
   inline bool doFullMax(void) const { return resource.full_max; }
   inline bool doFocusNew(void) const { return resource.focus_new; }
   inline bool doFocusLast(void) const { return resource.focus_last; }
+  inline bool doAllowRootCmd(void) const { return resource.allow_rootcmd; }
 
   inline const GC &getOpGC(void) const { return opGC; }
 
@@ -301,6 +302,7 @@
   inline void saveFullMax(bool f) { resource.full_max = f; }
   inline void saveFocusNew(bool f) { resource.focus_new = f; }
   inline void saveFocusLast(bool f) { resource.focus_last = f; }
+  inline void saveAllowRootCmd(bool f) { resource.allow_rootcmd = f; }
   inline void iconUpdate(void) { iconmenu->update(); }
 
 #ifdef    HAVE_STRFTIME
diff -urN blackbox-orig/src/blackbox.cc blackbox/src/blackbox.cc
--- blackbox-orig/src/blackbox.cc       Fri May 24 23:49:33 2002
+++ blackbox/src/blackbox.cc    Sun May 26 18:39:43 2002
@@ -1055,6 +1055,9 @@
             ((screen->doFocusLast()) ? "True" : "False"));
     XrmPutLineResource(&new_blackboxrc, rc_string);
 
+    sprintf(rc_string, "session.screen%d.allowRootCommand: %s", screen_number,
+            ((screen->doAllowRootCmd()) ? "True" : "False"));
+
     sprintf(rc_string, "session.screen%d.rowPlacementDirection: %s",
             screen_number,
             ((screen->getRowPlacementDirection() == BScreen::LeftRight) ?
@@ -1273,12 +1276,21 @@
   }
 
   sprintf(name_lookup,  "session.screen%d.focusLastWindow", screen_number);
-  sprintf(class_lookup, "Session.Screen%d.focusLastWindow", screen_number);
+  sprintf(class_lookup, "Session.Screen%d.FocusLastWindow", screen_number);
   screen->saveFocusLast(False);
   if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
                      &value) &&
       ! strncasecmp(value.addr, "true", value.size)) {
     screen->saveFocusLast(True);
+  }
+  
+  sprintf(name_lookup,  "session.screen%d.allowRootCommand", screen_number);
+  sprintf(class_lookup, "Session.Screen%d.AllowRootCommand", screen_number);
+  screen->saveAllowRootCmd(False);
+  if (XrmGetResource(database, name_lookup, class_lookup, &value_type,
+                     &value) &&
+      ! strncasecmp(value.addr, "true", value.size)) {
+    screen->saveAllowRootCmd(True);
   }
 
   sprintf(name_lookup,  "session.screen%d.rowPlacementDirection",

Reply via email to