Fixes for su on freebsd

Addresses multiple issues when using su on freebsd including
* su prompt differs between platforms, so turned that check into a
  regex comparison instead of a simple string comparison
* not using '-c' after su causes problems, so added that for all
  platforms
* fixed quoting issues due to multiple uses of '-c' introduced by
  the above fix

Fixes #7503
Fixes #7507
This commit is contained in:
James Cammarata
2014-05-23 10:06:09 -05:00
parent 10414145b2
commit 1e672a0fec
4 changed files with 20 additions and 6 deletions

View File

@@ -17,6 +17,7 @@
#
import os
import re
import subprocess
import shlex
import pipes
@@ -268,6 +269,7 @@ class Connection(object):
if su and su_user:
sudocmd, prompt, success_key = utils.make_su_cmd(su_user, executable, cmd)
prompt_re = re.compile(prompt)
ssh_cmd.append(sudocmd)
elif not self.runner.sudo or not sudoable:
prompt = None
@@ -308,7 +310,12 @@ class Connection(object):
sudo_output = ''
sudo_errput = ''
while not sudo_output.endswith(prompt) and success_key not in sudo_output:
while True:
if success_key in sudo_output or \
(self.runner.sudo_pass and sudo_output.endswith(prompt)) or \
(self.runner.su_pass and prompt_re.match(sudo_output)):
break
rfd, wfd, efd = select.select([p.stdout, p.stderr], [],
[p.stdout], self.runner.timeout)
if p.stderr in rfd: