Browse code

Quote any file paths that we have to use with dd to copy.

This is because we pass the whole dd command string into the shell
that's running on the contained environment rather than running it
directly from python via subprocess without a shell.

Toshio Kuratomi authored on 2015/10/04 10:07:27
Showing 5 changed files
... ...
@@ -22,6 +22,7 @@ __metaclass__ = type
22 22
 import distutils.spawn
23 23
 import os
24 24
 import os.path
25
+import pipes
25 26
 import subprocess
26 27
 import traceback
27 28
 
... ...
@@ -117,7 +118,7 @@ class Connection(ConnectionBase):
117 117
         super(Connection, self).put_file(in_path, out_path)
118 118
         self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.chroot)
119 119
 
120
-        out_path = self._prefix_login_path(out_path)
120
+        out_path = pipes.quote(self._prefix_login_path(out_path))
121 121
         try:
122 122
             with open(in_path, 'rb') as in_file:
123 123
                 try:
... ...
@@ -139,7 +140,7 @@ class Connection(ConnectionBase):
139 139
         super(Connection, self).fetch_file(in_path, out_path)
140 140
         self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.chroot)
141 141
 
142
-        in_path = self._prefix_login_path(in_path)
142
+        in_path = pipes.quote(self._prefix_login_path(in_path))
143 143
         try:
144 144
             p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
145 145
         except OSError:
... ...
@@ -27,6 +27,7 @@ __metaclass__ = type
27 27
 import distutils.spawn
28 28
 import os
29 29
 import os.path
30
+import pipes
30 31
 import subprocess
31 32
 import re
32 33
 
... ...
@@ -154,6 +155,7 @@ class Connection(ConnectionBase):
154 154
             if p.returncode != 0:
155 155
                 raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
156 156
         else:
157
+            out_path = pipes.quote(out_path)
157 158
             # Older docker doesn't have native support for copying files into
158 159
             # running containers, so we use docker exec to implement this
159 160
             executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh'
... ...
@@ -23,6 +23,7 @@ __metaclass__ = type
23 23
 import distutils.spawn
24 24
 import os
25 25
 import os.path
26
+import pipes
26 27
 import subprocess
27 28
 import traceback
28 29
 
... ...
@@ -144,7 +145,7 @@ class Connection(ConnectionBase):
144 144
         super(Connection, self).put_file(in_path, out_path)
145 145
         self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.jail)
146 146
 
147
-        out_path = self._prefix_login_path(out_path)
147
+        out_path = pipes.quote(self._prefix_login_path(out_path))
148 148
         try:
149 149
             with open(in_path, 'rb') as in_file:
150 150
                 try:
... ...
@@ -166,7 +167,7 @@ class Connection(ConnectionBase):
166 166
         super(Connection, self).fetch_file(in_path, out_path)
167 167
         self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.jail)
168 168
 
169
-        in_path = self._prefix_login_path(in_path)
169
+        in_path = pipes.quote(self._prefix_login_path(in_path))
170 170
         try:
171 171
             p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
172 172
         except OSError:
... ...
@@ -23,6 +23,7 @@ __metaclass__ = type
23 23
 import distutils.spawn
24 24
 import os
25 25
 import os.path
26
+import pipes
26 27
 import subprocess
27 28
 
28 29
 from ansible import constants as C
... ...
@@ -116,7 +117,7 @@ class Connection(ConnectionBase):
116 116
         super(Connection, self).put_file(in_path, out_path)
117 117
         self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.lxc)
118 118
 
119
-        out_path = self._prefix_login_path(out_path)
119
+        out_path = pipes.quote(self._prefix_login_path(out_path))
120 120
         try:
121 121
             with open(in_path, 'rb') as in_file:
122 122
                 try:
... ...
@@ -138,7 +139,7 @@ class Connection(ConnectionBase):
138 138
         super(Connection, self).fetch_file(in_path, out_path)
139 139
         self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.lxc)
140 140
 
141
-        in_path = self._prefix_login_path(in_path)
141
+        in_path = pipes.quote(self._prefix_login_path(in_path))
142 142
         try:
143 143
             p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
144 144
         except OSError:
... ...
@@ -24,6 +24,7 @@ __metaclass__ = type
24 24
 import distutils.spawn
25 25
 import os
26 26
 import os.path
27
+import pipes
27 28
 import subprocess
28 29
 import traceback
29 30
 
... ...
@@ -157,7 +158,7 @@ class Connection(ConnectionBase):
157 157
         super(Connection, self).put_file(in_path, out_path)
158 158
         self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.zone)
159 159
 
160
-        out_path = self._prefix_login_path(out_path)
160
+        out_path = pipes.quote(self._prefix_login_path(out_path))
161 161
         try:
162 162
             with open(in_path, 'rb') as in_file:
163 163
                 try:
... ...
@@ -179,7 +180,7 @@ class Connection(ConnectionBase):
179 179
         super(Connection, self).fetch_file(in_path, out_path)
180 180
         self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.zone)
181 181
 
182
-        in_path = self._prefix_login_path(in_path)
182
+        in_path = pipes.quote(self._prefix_login_path(in_path))
183 183
         try:
184 184
             p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE))
185 185
         except OSError: