Skip to content

Commit

Permalink
Parses output from ldd to copy /bin/sh + deps
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed May 20, 2014
1 parent 1229d33 commit 17e76a7
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions reprozip/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tempfile
import os
import platform
import re
import sqlite3
import subprocess

Expand Down Expand Up @@ -191,18 +192,27 @@ def create_chroot(args):
tar.getmembers())
tar.extractall(root, members)

# Copies additional files
# FIXME : This is because we need /bin/sh
for d in ('/bin', '/lib/i386-linux-gnu'):
path = root
for c in d.split('/')[1:]:
path = os.path.join(path, c)
if not os.path.isdir(path):
os.mkdir(path)
for f in ('/bin/sh', '/lib/ld-linux.so.2', '/lib/i386-linux-gnu/libc.so.6'):
dest = os.path.join(root, f.lstrip('/'))
if not os.path.exists(dest):
# Copies /bin/sh + dependencies
fmt = re.compile(r'^\t(?:[^ ]+ => )?([^ ]+) \([x0-9a-z]+\)$')
p = subprocess.Popen(['ldd', '/bin/sh'], stdout=subprocess.PIPE)
try:
for l in p.stdout:
l = l.decode('ascii')
m = fmt.match(l)
f = m.group(1)
if not os.path.exists(f):
continue
dest = f
if dest[0] == '/':
dest = dest[1:]
dest = os.path.join(root, dest)
makedir(os.path.dirname(dest))
shutil.copy(f, dest)
finally:
p.wait()
assert p.returncode == 0
makedir(os.path.join(root, 'bin'))
shutil.copy('/bin/sh', os.path.join(root, 'bin/sh'))

# Makes sure all the directories used as working directories exist
# (they already do if files from them are used, but empty directories do
Expand Down

0 comments on commit 17e76a7

Please sign in to comment.