27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 21. Restricted Shells<br />

Disabled commands in restricted shells<br />

Running a script or portion of a script in restricted mode disables certain commands that would<br />

otherwise be available. This is a security measure intended to limit the privileges of the script user and<br />

to minimize possible damage from running the script.<br />

Using cd to change the working directory.<br />

Changing the values of the $PATH, $SHELL, $BASH_ENV, or $ENV environmental variables.<br />

Reading or changing the $SHELLOPTS, shell environmental options.<br />

Output redirection.<br />

Invoking commands containing one or more /'s.<br />

Invoking exec to substitute a different process for the shell.<br />

Various other commands that would enable monkeying with or attempting to subvert the script for an<br />

unintended purpose.<br />

Getting out of restricted mode within the script.<br />

Example 21−1. Running a script in restricted mode<br />

#!/bin/bash<br />

# Starting the script with "#!/bin/bash −r"<br />

# runs entire script in restricted mode.<br />

echo<br />

echo "Changing directory."<br />

cd /usr/local<br />

echo "Now in `pwd`"<br />

echo "Coming back home."<br />

cd<br />

echo "Now in `pwd`"<br />

echo<br />

# Everything up to here in normal, unrestricted mode.<br />

set −r<br />

# set −−restricted has same effect.<br />

echo "==> Now in restricted mode.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!