forked from p15670423/monkey
Agent: Add timeouts to utils/linux/users.py
This commit is contained in:
parent
2e389cc87e
commit
885a871be8
|
@ -3,6 +3,7 @@ import logging
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
|
||||||
from infection_monkey.utils.auto_new_user import AutoNewUser
|
from infection_monkey.utils.auto_new_user import AutoNewUser
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -43,7 +44,9 @@ 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(commands_to_add_user, stderr=subprocess.STDOUT)
|
_ = subprocess.check_output(
|
||||||
|
commands_to_add_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT
|
||||||
|
)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self # No initialization/logging on needed in Linux
|
return self # No initialization/logging on needed in Linux
|
||||||
|
@ -52,7 +55,7 @@ class AutoNewLinuxUser(AutoNewUser):
|
||||||
command_as_new_user = shlex.split(
|
command_as_new_user = shlex.split(
|
||||||
"sudo -u {username} {command}".format(username=self.username, command=command)
|
"sudo -u {username} {command}".format(username=self.username, command=command)
|
||||||
)
|
)
|
||||||
return subprocess.call(command_as_new_user)
|
return subprocess.call(command_as_new_user, timeout=SHORT_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
def __exit__(self, _exc_type, value, traceback):
|
def __exit__(self, _exc_type, value, traceback):
|
||||||
# delete the user.
|
# delete the user.
|
||||||
|
@ -62,4 +65,6 @@ class AutoNewLinuxUser(AutoNewUser):
|
||||||
self.username, str(commands_to_delete_user)
|
self.username, str(commands_to_delete_user)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
_ = subprocess.check_output(commands_to_delete_user, stderr=subprocess.STDOUT)
|
_ = subprocess.check_output(
|
||||||
|
commands_to_delete_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue