GladL33
GladL33

Reputation: 53

How do I only allow certain commands to be run in my shell?

Im currently writing my own shell in C. It isn't anything big. It's only has a few built-in commands like one of my commands is ifc and would do the same thing as the ifconfig command on a normal shell. But I want to restrict my shell from being able to call other commands that are not specified in my shell.

For example. I made the ifc command to replace ifconfig but ifconfig is still callable from my shell even though it isn't build in.

Is this possible to do and how would it be done?

Upvotes: 0

Views: 562

Answers (1)

fghj
fghj

Reputation: 9404

  1. The most simple way - just allow certain commands in your shell.
  2. You can build shared library and with LD_PRELOAD, attach it to your shell, this library catches all calls like execl and allow/disallow it based on you rules. Like firewall, but for calling programs.
  3. Another way is to modify Linux kernel that checks if current process is your shell, then do not exec something.
  4. You can write policy for your shell SELinux or AppArmor to do things like (2)

Upvotes: 1

Related Questions