forked from p15670423/monkey
Fix DUO116 warnings in monkey/infection_monkey/utils/linux/users.py
This commit is contained in:
parent
c0fdc9561f
commit
6b467fd20b
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from infection_monkey.utils.auto_new_user import AutoNewUser
|
from infection_monkey.utils.auto_new_user import AutoNewUser
|
||||||
|
@ -42,18 +43,16 @@ class AutoNewLinuxUser(AutoNewUser):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Trying to add {} with commands {}".format(self.username, str(commands_to_add_user))
|
"Trying to add {} with commands {}".format(self.username, str(commands_to_add_user))
|
||||||
)
|
)
|
||||||
_ = subprocess.check_output(
|
_ = subprocess.check_output(commands_to_add_user, stderr=subprocess.STDOUT)
|
||||||
" ".join(commands_to_add_user), stderr=subprocess.STDOUT, shell=True
|
|
||||||
)
|
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self # No initialization/logging on needed in Linux
|
return self # No initialization/logging on needed in Linux
|
||||||
|
|
||||||
def run_as(self, command):
|
def run_as(self, command):
|
||||||
command_as_new_user = "sudo -u {username} {command}".format(
|
command_as_new_user = shlex.split(
|
||||||
username=self.username, command=command
|
"sudo -u {username} {command}".format(username=self.username, command=command)
|
||||||
)
|
)
|
||||||
return subprocess.call(command_as_new_user, shell=True)
|
return subprocess.call(command_as_new_user)
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
# delete the user.
|
# delete the user.
|
||||||
|
@ -63,6 +62,4 @@ class AutoNewLinuxUser(AutoNewUser):
|
||||||
self.username, str(commands_to_delete_user)
|
self.username, str(commands_to_delete_user)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
_ = subprocess.check_output(
|
_ = subprocess.check_output(commands_to_delete_user, stderr=subprocess.STDOUT)
|
||||||
" ".join(commands_to_delete_user), stderr=subprocess.STDOUT, shell=True
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue