summaryrefslogtreecommitdiffstats
path: root/sshuttle/sudoers.py
diff options
context:
space:
mode:
Diffstat (limited to 'sshuttle/sudoers.py')
-rw-r--r--sshuttle/sudoers.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/sshuttle/sudoers.py b/sshuttle/sudoers.py
index 3f01e8e..513a858 100644
--- a/sshuttle/sudoers.py
+++ b/sshuttle/sudoers.py
@@ -1,10 +1,13 @@
+"""
+Manage sudoers file
+"""
import os
import sys
import getpass
from uuid import uuid4
from subprocess import Popen, PIPE
-from sshuttle.helpers import log, debug1
from distutils import spawn
+from sshuttle.helpers import log, debug1
path_to_sshuttle = sys.argv[0]
path_to_dist_packages = os.path.dirname(os.path.abspath(__file__))[:-9]
@@ -13,7 +16,7 @@ path_to_dist_packages = os.path.dirname(os.path.abspath(__file__))[:-9]
command_alias = 'SSHUTTLE%(num)s' % {'num': uuid4().hex[-3:].upper()}
# Template for the sudoers file
-template = '''
+TEMPLATE = '''
Cmnd_Alias %(ca)s = /usr/bin/env PYTHONPATH=%(dist_packages)s %(py)s %(path)s *
%(user_name)s ALL=NOPASSWD: %(ca)s
@@ -21,7 +24,8 @@ Cmnd_Alias %(ca)s = /usr/bin/env PYTHONPATH=%(dist_packages)s %(py)s %(path)s *
def build_config(user_name):
- content = template % {
+ """ Build sudoers config """
+ content = TEMPLATE % {
'ca': command_alias,
'dist_packages': path_to_dist_packages,
'py': sys.executable,
@@ -33,6 +37,7 @@ def build_config(user_name):
def save_config(content, file_name):
+ """ Save sudoers config """
process = Popen([
'/usr/bin/sudo',
spawn.find_executable('sudoers-add'),
@@ -47,18 +52,19 @@ def save_config(content, file_name):
if returncode:
log('Failed updating sudoers file.\n')
debug1(streamdata)
- exit(returncode)
+ sys.exit(returncode)
else:
log('Success, sudoers file update.\n')
- exit(0)
+ sys.exit(0)
def sudoers(user_name=None, no_modify=None, file_name=None):
+ """ Update sudoers config """
user_name = user_name or getpass.getuser()
content = build_config(user_name)
if no_modify:
sys.stdout.write(content)
- exit(0)
+ sys.exit(0)
else:
save_config(content, file_name)