[Samba] samba-tool user syncpasswords crashes with python3
Heinz Hölzl
heinz.hoelzl at gvcc.net
Mon Oct 7 09:52:14 UTC 2019
I think, i found the error:
in /usr/local/samba/lib/python3.6/site-packages/samba/netcmd/user.py on
line 2001:
...snip
def run_sync_command(dn, ldif):
log_msg("Call Popen[%s] for %s\n" % (self.sync_command,
dn))
sync_command_p = Popen(self.sync_command,
stdin=PIPE,
stdout=PIPE,
stderr=STDOUT)
res = sync_command_p.poll()
assert res is None
input = "%s" % (ldif)
reply = sync_command_p.communicate(input)[0]
...snip
input and ldif are Strings, but the type of input in
Popen.communicate(input) must by bytes.
The python3.6 documentation :
coroutine communicate(input=None)
Interact with process: Send data to stdin. Read data from stdout and
stderr, until end-of-file is reached. Wait for process to terminate.
The optional input argument should be data to be sent to the child
process, or None, if no data should be sent to the child. The type of
input must be bytes.
https://docs.python.org/3.6/library/asyncio-subprocess.html
so, converting input to bytes and replay to string solves the problem.
#reply = sync_command_p.communicate(input)[0]
reply = sync_command_p.communicate(input.encode())[0].decode()
Am Freitag, den 04.10.2019, 21:45 +0100 schrieb Rowland penny via
samba:
> On 04/10/2019 15:28, Heinz Hölzl via samba wrote:
> > the script works...
>
> The script may work when you run it manually, but the error samba-
> tool
> throws is this:
>
> ERROR(<class 'TypeError'>): uncaught exception - memoryview: a
> bytes-like object is required, not 'str'
>
> If you examine the error, samba-tool runs your script with this:
>
> File
> "/usr/local/samba/lib/python3.6/site-packages/samba/netcmd/user.py",
> line 2001, in run_sync_command
> reply = bytes(sync_command_p.communicate(input)[0], encoding =
> 'utf-8')
>
> After that 'subprocess.py' is called and the error seems to coming
> from
> there. Samba doesn't import all of 'subprocess', it only does this:
> from
> subprocess import Popen, PIPE, STDOUT, check_call, CalledProcessError
>
> The error output goes on to do this:
>
> File "/usr/lib/python3.6/subprocess.py", line 863, in communicate
> stdout, stderr = self._communicate(input, endtime, timeout)
> File "/usr/lib/python3.6/subprocess.py", line 1519, in
> _communicate
> input_view = memoryview(self._input)
>
> And it is 'memoryview' that throws the error and it looks like it is
> something in subprocess.py that is wrong, or something in your
> script.
> Samba, as far as I can see, does not use 'memoryview' directly.
>
> Rowland
>
>
>
>
More information about the samba
mailing list