mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Mcsalgado's change to use shlex.quote instead of pipes.quote (#18534)
* Replace pipes.quote for shlex_quote * More migration of pipes.quote to shlex_quote Note that we cannot yet move module code over. Modules have six-1.4 bundled which does not have shlex_quote. This shouldn't be a problem as the function is still importable from pipes.quote. It's just that this has become an implementation detail that makes us want to import from shlex instead. Once we get rid of the python2.4 dependency we can update to a newer version of bundled six module-side and then we're free to use shlex_quote everywhere.
This commit is contained in:
parent
5d043b65d3
commit
ed00741a01
16 changed files with 62 additions and 63 deletions
|
@ -22,13 +22,13 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import pipes
|
||||
import pwd
|
||||
import random
|
||||
import re
|
||||
import string
|
||||
|
||||
from ansible.compat.six import iteritems, string_types
|
||||
from ansible.compat.six.moves import shlex_quote
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils._text import to_bytes
|
||||
|
@ -467,7 +467,7 @@ class PlayContext(Base):
|
|||
becomecmd = None
|
||||
randbits = ''.join(random.choice(string.ascii_lowercase) for x in range(32))
|
||||
success_key = 'BECOME-SUCCESS-%s' % randbits
|
||||
success_cmd = pipes.quote('echo %s; %s' % (success_key, cmd))
|
||||
success_cmd = shlex_quote('echo %s; %s' % (success_key, cmd))
|
||||
|
||||
if executable:
|
||||
command = '%s -c %s' % (executable, success_cmd)
|
||||
|
@ -496,7 +496,7 @@ class PlayContext(Base):
|
|||
# done for older versions of sudo that do not support the option.
|
||||
#
|
||||
# Passing a quoted compound command to sudo (or sudo -s)
|
||||
# directly doesn't work, so we shellquote it with pipes.quote()
|
||||
# directly doesn't work, so we shellquote it with shlex_quote()
|
||||
# and pass the quoted string to the user's shell.
|
||||
|
||||
# force quick error if password is required but not supplied, should prevent sudo hangs.
|
||||
|
@ -518,7 +518,7 @@ class PlayContext(Base):
|
|||
return bool(b_SU_PROMPT_LOCALIZATIONS_RE.match(b_data))
|
||||
prompt = detect_su_prompt
|
||||
|
||||
becomecmd = '%s %s %s -c %s' % (exe, flags, self.become_user, pipes.quote(command))
|
||||
becomecmd = '%s %s %s -c %s' % (exe, flags, self.become_user, shlex_quote(command))
|
||||
|
||||
elif self.become_method == 'pbrun':
|
||||
|
||||
|
@ -562,7 +562,7 @@ class PlayContext(Base):
|
|||
exe = self.become_exe or 'dzdo'
|
||||
if self.become_pass:
|
||||
prompt = '[dzdo via ansible, key=%s] password: ' % randbits
|
||||
becomecmd = '%s -p %s -u %s %s' % (exe, pipes.quote(prompt), self.become_user, command)
|
||||
becomecmd = '%s -p %s -u %s %s' % (exe, shlex_quote(prompt), self.become_user, command)
|
||||
else:
|
||||
becomecmd = '%s -u %s %s' % (exe, self.become_user, command)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue