-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use run_command instead of run_get_output for OSUtil functions #1858
Conversation
@@ -211,8 +199,8 @@ def del_account(self, username): | |||
:param username: | |||
:return: | |||
""" | |||
shellutil.run("> /var/run/utmp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command was just using redirection to create empty files, replaced it with touch
command
Codecov Report
@@ Coverage Diff @@
## develop #1858 +/- ##
===========================================
- Coverage 69.45% 69.43% -0.03%
===========================================
Files 82 82
Lines 11469 11481 +12
Branches 1619 1610 -9
===========================================
+ Hits 7966 7972 +6
- Misses 3166 3171 +5
- Partials 337 338 +1
Continue to review full report at Codecov.
|
"/bin/clish -s -c '" + cmd + "'", log_cmd=log_cmd) | ||
if not ret: | ||
try: | ||
final_command = ["/bin/clish", "-s", "-c", "'{0}'".format(cmd)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this command is opening a new shell, we dont need to tokenise the cmd
variable.
Eg:
shlex.split("/bin/clish -s -c 'set user admin password-hash *LOCK*'")
['/bin/clish', '-s', '-c', 'set user admin password-hash *LOCK*']
@@ -106,7 +106,7 @@ def chpasswd(self, username, password, crypt_id=6, salt_len=10): | |||
if self.is_sys_user(username): | |||
raise OSUtilError(("User {0} is a system user. " | |||
"Will not set passwd.").format(username)) | |||
output = self._run_command_raising_OSUtilError(['echo', '-n', '{0}|encrypt'.format(password)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo -n basically just does not append \n at the end of the string. They were using echo to redirect password to the encrypt command. Passing it through Popen now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM |
Description
Changed the internals of certain OSUtil functions to use shellutil.run_command instead of run_get_output or run() because the former is securer as it doesn't create a new shell during Popen. i.e. shell=False in Popen
Issue #
PR information
Quality of Code and Contribution Guidelines