summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-08-05 10:58:49 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-08-05 10:58:49 -0400
commitc9f196ccf3408f8717d42b5ab725b85c31b27dfa (patch)
tree66e7d0abfc3cc05c3feb31a1890bfc5055db4228 /src
parent2ab42e12ee398ae34534baa9721b3a951a8f4121 (diff)
downloadbcfg2-c9f196ccf3408f8717d42b5ab725b85c31b27dfa.tar.gz
bcfg2-c9f196ccf3408f8717d42b5ab725b85c31b27dfa.tar.bz2
bcfg2-c9f196ccf3408f8717d42b5ab725b85c31b27dfa.zip
fixed more unescaped shell commands
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Plugins/Cfg.py16
-rw-r--r--src/lib/Server/Plugins/SSHbase.py21
2 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index 23ba0a745..8a212c819 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -11,6 +11,7 @@ import re
import stat
import sys
import tempfile
+from subprocess import Popen, PIPE
import Bcfg2.Server.Plugin
@@ -62,16 +63,15 @@ def process_delta(data, delta):
basefile.write(data)
basefile.close()
os.close(basehandle)
- dhandle, dname = tempfile.mkstemp()
- dfile = open(dname, 'w')
- dfile.write(delta.data)
- dfile.close()
- os.close(dhandle)
- ret = os.system("patch -uf %s < %s > /dev/null 2>&1" \
- % (basefile.name, dfile.name))
+
+ cmd = ["patch", "-u", "-f", basefile.name]
+ patch = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+ stderr = patch.communicate(input=delta.data)[1]
+ ret = patch.wait()
output = open(basefile.name, 'r').read()
- [os.unlink(fname) for fname in [basefile.name, dfile.name]]
+ os.unlink(basefile.name)
if ret >> 8 != 0:
+ logger.error("Error applying diff %s: %s" % (delta.name, stderr))
raise Bcfg2.Server.Plugin.PluginExecutionError('delta', delta)
return output
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index 5e6acd39d..3ea2cb959 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -267,16 +267,27 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
"H_%s" % client])
tempdir = tempfile.mkdtemp()
temploc = "%s/%s" % (tempdir, hostkey)
- cmd = 'ssh-keygen -q -f %s -N "" -t %s -C root@%s < /dev/null'
- os.system(cmd % (temploc, keytype, client))
- shutil.copy(temploc, fileloc)
- shutil.copy("%s.pub" % temploc, publoc)
+ cmd = ["ssh-keygen", "-q", "-f", temploc, "-N", "",
+ "-t", keytype, "-C", "root@%s" % client]
+ proc = Popen(cmd, stdout=PIPE, stdin=PIPE)
+ proc.communicate()
+ proc.wait()
+
+ try:
+ shutil.copy(temploc, fileloc)
+ shutil.copy("%s.pub" % temploc, publoc)
+ except IOError:
+ err = sys.exc_info()[1]
+ self.logger.error("Temporary SSH keys not found: %s" % err)
+
try:
os.unlink(temploc)
os.unlink("%s.pub" % temploc)
os.rmdir(tempdir)
except OSError:
- self.logger.error("Failed to unlink temporary ssh keys")
+ err = sys.exc_info()[1]
+ self.logger.error("Failed to unlink temporary ssh keys: %s"
+ % err)
def AcceptChoices(self, _, metadata):
return [Bcfg2.Server.Plugin.Specificity(hostname=metadata.hostname)]