From 30c759fdd642bfa8b8bee93039a6ef62a08ee70c Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Sun, 15 Nov 2015 13:34:03 +0200 Subject: [PATCH] samba-tool: replace use of os.popen The netcmd/domain.py module uses os.popen() on user-supplied parameters. This opens up the way to code injection. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11601 Signed-off-by: Uri Simchoni Reviewed-by: Alexander Bokovoy --- python/samba/netcmd/domain.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index f0710f2..4d54db9 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -31,6 +31,7 @@ import ctypes import random import tempfile import logging +import subprocess from getpass import getpass from samba.net import Net, LIBNET_JOIN_AUTOMATIC import samba.ntacls @@ -85,9 +86,16 @@ from samba.provision.common import ( ) def get_testparm_var(testparm, smbconf, varname): - cmd = "%s -s -l --parameter-name='%s' %s 2>/dev/null" % (testparm, varname, smbconf) - output = os.popen(cmd, 'r').readline() - return output.strip() + errfile = open(os.devnull, 'w') + p = subprocess.Popen([testparm, '-s', '-l', + '--parameter-name=%s' % varname, smbconf], + stdout=subprocess.PIPE, stderr=errfile) + (out,err) = p.communicate() + errfile.close() + lines = out.split('\n') + if lines: + return lines[0].strip() + return "" try: import samba.dckeytab -- 2.4.3