Mariners
Mariners

Reputation: 509

How to restrict a particular command in bash?

I have bash-3.2.tar.gz I have all the tools needed to compile the bash. Now I need to restrict a command in the compiled bash binary, e.g. I want to restrict the command "kill" in the compiled bash binary. How to achieve this?

Thanks in advance.

Upvotes: 0

Views: 277

Answers (2)

Mariners
Mariners

Reputation: 509

I patched the bash package builtin kill.def to make it restricted:

--- builtins/kill.def.old       2016-09-14 14:13:49.058437000 +0530
+++ builtins/kill.def   2016-09-14 14:16:00.467550000 +0530
@@ -48,6 +48,7 @@
 #include "../bashintl.h"

 #include "../shell.h"
+#include "../flags.h"
 #include "../trap.h"
 #include "../jobs.h"
 #include "common.h"
@@ -79,6 +80,14 @@
   pid_t pid;
   intmax_t pid_value;

+#if defined (RESTRICTED_SHELL)
+  if (restricted)
+    {
+      sh_restricted ((char *)NULL);
+      return (EXECUTION_FAILURE);
+    }
+#endif /* RESTRICTED_SHELL */
+
   if (list == 0)
     {
       builtin_usage ();

Upvotes: 0

larsks
larsks

Reputation: 312038

It's not clear exactly what you're trying to do, so here are a few thoughts.

You can remove a command from bash before compiling it by editing the DEFSRC and OFILES variables in the builtins/Makefile.in (before running configure).

You can disable a built in command using the enable command. For example, running enable -n kill would disable the builtin kill command, so that running kill would instead look for a file named kill in your $PATH.

Upvotes: 5

Related Questions