Skip to content

Commit

Permalink
Check uid and refuse to run as root.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Carpenter committed Jul 9, 2015
1 parent d3277da commit 8800858
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ def update(operation, verbose=None, upgrade=False, offline=False):

def main(argv=sys.argv):
'''Script entry point.'''

# Refuse to run as root
if not getattr(os, 'getuid', lambda: -1)():
sys.stderr.write('%s: error: refusing to run as root to prevent '
'potential damage.\n' % os.path.basename(argv[0]))
sys.exit(77)

# Unfortunately, many dependencies are not yet available in Python3.
if sys.version_info[:2] != (2, 7):
sys.stderr.write('error: Python 2.7 is required\n')
Expand All @@ -275,7 +282,6 @@ def main(argv=sys.argv):
this script or in the directory given by the --envdir option.
Subsequent invocations of this script should use the Python
executable installed in the virtual environment.'''

)
verbose = parser.add_mutually_exclusive_group()
verbose.add_argument(
Expand Down
6 changes: 6 additions & 0 deletions volttron/platform/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,12 @@ def priority(value):


def main(argv=sys.argv):
# Refuse to run as root
if not getattr(os, 'getuid', lambda: -1)():
sys.stderr.write('%s: error: refusing to run as root to prevent '
'potential damage.\n' % os.path.basename(argv[0]))
sys.exit(77)

volttron_home = config.expandall(
os.environ.get('VOLTTRON_HOME', '~/.volttron'))
os.environ['VOLTTRON_HOME'] = volttron_home
Expand Down
6 changes: 6 additions & 0 deletions volttron/platform/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ def setup_agent(self, sender, **kwargs):


def main(argv=sys.argv):
# Refuse to run as root
if not getattr(os, 'getuid', lambda: -1)():
sys.stderr.write('%s: error: refusing to run as root to prevent '
'potential damage.\n' % os.path.basename(argv[0]))
sys.exit(77)

volttron_home = config.expandall(
os.environ.get('VOLTTRON_HOME', '~/.volttron'))
os.environ['VOLTTRON_HOME'] = volttron_home
Expand Down

0 comments on commit 8800858

Please sign in to comment.