Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
270be6a6
Commit
270be6a6
authored
Jun 23, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix exec_command to not use a shell
parent
a1a7d6c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
lib/ansible/plugins/connections/chroot.py
+10
-4
lib/ansible/plugins/connections/jail.py
+9
-3
lib/ansible/plugins/connections/zone.py
+9
-3
No files found.
lib/ansible/plugins/connections/chroot.py
View file @
270be6a6
...
...
@@ -22,9 +22,11 @@ __metaclass__ = type
import
distutils.spawn
import
traceback
import
os
import
shlex
import
subprocess
from
ansible
import
errors
from
ansible
import
utils
from
ansible.utils.unicode
import
to_bytes
from
ansible.callbacks
import
vvv
import
ansible.constants
as
C
...
...
@@ -70,7 +72,11 @@ class Connection(object):
if
executable
:
local_cmd
=
[
self
.
chroot_cmd
,
self
.
chroot
,
executable
,
'-c'
,
cmd
]
else
:
local_cmd
=
'
%
s "
%
s"
%
s'
%
(
self
.
chroot_cmd
,
self
.
chroot
,
cmd
)
# Prev to python2.7.3, shlex couldn't handle unicode type strings
cmd
=
to_bytes
(
cmd
)
cmd
=
shlex
.
split
(
cmd
)
local_cmd
=
[
self
.
chroot_cmd
,
self
.
chroot
]
local_cmd
+=
cmd
return
local_cmd
def
_buffered_exec_command
(
self
,
cmd
,
tmp_path
,
become_user
=
None
,
sudoable
=
False
,
executable
=
'/bin/sh'
,
in_data
=
None
,
stdin
=
subprocess
.
PIPE
):
...
...
@@ -88,11 +94,11 @@ class Connection(object):
if
in_data
:
raise
errors
.
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
# We enter
chroot as root so we ignore privlege escalation
?
# We enter
zone as root so we ignore privilege escalation (probably need to fix in case we have to become a specific used [ex: postgres admin])
?
local_cmd
=
self
.
_generate_cmd
(
executable
,
cmd
)
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
chroot
)
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
isinstance
(
local_cmd
,
basestring
)
,
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
False
,
cwd
=
self
.
runner
.
basedir
,
stdin
=
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
...
...
@@ -136,7 +142,7 @@ class Connection(object):
try
:
p
=
self
.
_buffered_exec_command
(
'dd if=
%
s bs=
%
s'
%
(
in_path
,
BUFSIZE
),
None
)
except
OSError
:
raise
errors
.
AnsibleError
(
"chroot connection requires dd command in the
jail
"
)
raise
errors
.
AnsibleError
(
"chroot connection requires dd command in the
chroot
"
)
with
open
(
out_path
,
'wb+'
)
as
out_file
:
try
:
...
...
lib/ansible/plugins/connections/jail.py
View file @
270be6a6
...
...
@@ -23,8 +23,10 @@ __metaclass__ = type
import
distutils.spawn
import
traceback
import
os
import
shlex
import
subprocess
from
ansible
import
errors
from
ansible.utils.unicode
import
to_bytes
from
ansible.callbacks
import
vvv
import
ansible.constants
as
C
...
...
@@ -92,7 +94,11 @@ class Connection(object):
if
executable
:
local_cmd
=
[
self
.
jexec_cmd
,
self
.
jail
,
executable
,
'-c'
,
cmd
]
else
:
local_cmd
=
'
%
s "
%
s"
%
s'
%
(
self
.
jexec_cmd
,
self
.
jail
,
cmd
)
# Prev to python2.7.3, shlex couldn't handle unicode type strings
cmd
=
to_bytes
(
cmd
)
cmd
=
shlex
.
split
(
cmd
)
local_cmd
=
[
self
.
jexec_cmd
,
self
.
jail
]
local_cmd
+=
cmd
return
local_cmd
def
_buffered_exec_command
(
self
,
cmd
,
tmp_path
,
become_user
=
None
,
sudoable
=
False
,
executable
=
'/bin/sh'
,
in_data
=
None
,
stdin
=
subprocess
.
PIPE
):
...
...
@@ -110,11 +116,11 @@ class Connection(object):
if
in_data
:
raise
errors
.
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
#
Ignores privilege escalation
#
We enter zone as root so we ignore privilege escalation (probably need to fix in case we have to become a specific used [ex: postgres admin])?
local_cmd
=
self
.
_generate_cmd
(
executable
,
cmd
)
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
jail
)
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
isinstance
(
local_cmd
,
basestring
)
,
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
False
,
cwd
=
self
.
runner
.
basedir
,
stdin
=
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
...
...
lib/ansible/plugins/connections/zone.py
View file @
270be6a6
...
...
@@ -24,8 +24,10 @@ __metaclass__ = type
import
distutils.spawn
import
traceback
import
os
import
shlex
import
subprocess
from
ansible
import
errors
from
ansible.utils.unicode
import
to_bytes
from
ansible.callbacks
import
vvv
import
ansible.constants
as
C
...
...
@@ -101,7 +103,11 @@ class Connection(object):
### TODO: Why was "-c" removed from here? (vs jail.py)
local_cmd
=
[
self
.
zlogin_cmd
,
self
.
zone
,
executable
,
cmd
]
else
:
local_cmd
=
'
%
s "
%
s"
%
s'
%
(
self
.
zlogin_cmd
,
self
.
zone
,
cmd
)
# Prev to python2.7.3, shlex couldn't handle unicode type strings
cmd
=
to_bytes
(
cmd
)
cmd
=
shlex
.
split
(
cmd
)
local_cmd
=
[
self
.
zlogin_cmd
,
self
.
zone
]
local_cmd
+=
cmd
return
local_cmd
def
_buffered_exec_command
(
self
,
cmd
,
tmp_path
,
become_user
=
None
,
sudoable
=
False
,
executable
=
None
,
in_data
=
None
,
stdin
=
subprocess
.
PIPE
):
...
...
@@ -119,11 +125,11 @@ class Connection(object):
if
in_data
:
raise
errors
.
AnsibleError
(
"Internal Error: this module does not support optimized module pipelining"
)
# We
happily ignore privilege escalation
# We
enter zone as root so we ignore privilege escalation (probably need to fix in case we have to become a specific used [ex: postgres admin])?
local_cmd
=
self
.
_generate_cmd
(
executable
,
cmd
)
vvv
(
"EXEC
%
s"
%
(
local_cmd
),
host
=
self
.
zone
)
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
isinstance
(
local_cmd
,
basestring
)
,
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
False
,
cwd
=
self
.
runner
.
basedir
,
stdin
=
stdin
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment