Use re instead of shlex.split to find executable

shlex.split will strip quotes and it might not even be sh at this point.
This commit is contained in:
Daniel Hokka Zakrisson 2013-01-09 14:13:53 +01:00
parent 910667152c
commit 92ad206b84

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import shlex import re
import ansible.constants as C import ansible.constants as C
from ansible import utils from ansible import utils
@ -30,13 +30,13 @@ class ActionModule(object):
def run(self, conn, tmp, module_name, module_args, inject): def run(self, conn, tmp, module_name, module_args, inject):
executable = None executable = None
args = [] # From library/command, keep in sync
for arg in shlex.split(module_args.encode("utf-8")): r = re.compile(r'(^|\s)(executable)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)\s|$)')
if arg.startswith('executable='): for m in r.finditer(module_args):
executable = arg.split('=', 1)[1] v = m.group(4).replace("\\", "")
else: if m.group(2) == "executable":
args.append(arg) executable = v
module_args = ' '.join(args) module_args = r.sub("", module_args)
return ReturnData(conn=conn, return ReturnData(conn=conn,
result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable) result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable)