[PATCH] samba-tool: Easily edit a users object in AD

Rowland Penny rpenny at samba.org
Sat Jul 1 17:08:10 UTC 2017


On Sat, 1 Jul 2017 13:27:07 +1200
Douglas Bagnall <douglas.bagnall at catalyst.net.nz> wrote:

> On 01/07/17 00:43, Rowland Penny via samba-technical wrote:
> > On Wed, 28 Jun 2017 12:27:53 +0300
> > Alexander Bokovoy <ab at samba.org> wrote:
> > 
> >> On ke, 28 kesä 2017, Andrew Bartlett via samba-technical wrote:
> 
> >>> You replace the EDITOR with a script that modifies the object's
> >>> LDIF.
> >> Yes, something like
> >> EDITOR="sed -i -e 's/attribute: foo/attribute: bar/'"
> >>
> > 
> > OK, this doesn't work, but if I create a dummy editor script, it
> > does.
> 
> Yes, that isn't going to work because you are calling the editor
> using a list, exactly like so
> 
>        call([editor, t_file.name])
> 
> which is interpreted as an exec-style argument list, meaning it will
> look for an editor called "sed -i -e ...", not one called "sed".  In
> this case it is probably mostly safe to change it to
> 
>        call("%s %s" % (editor, t_file.name), shell=True)
> 
> which will use a shell to split the string.
> 
> > This is what I came up with:
> > 
> > #!/bin/sh
> > user_ldif="$1"
> > SED=$(which sed)
> > $SED -i -e \'s/userAccountControl: 512/userAccountControl: 514/\'
> > $user_ldif
> > 
> > If I create the above script as /tmp/editor.sh, make it executable
> > and then pass it to 'samba-tool user USER' with
> > '--editor=/tmp/editor.sh' it works.
> > 
> > Problem is, how do I either get the python test script to create the
> > bash script and then use it, or how do I create the bash script
> > somewhere in the source (if so where?) and then get the python test
> > script to use it ?
> 
> Why not use tempfile.NamedTemporaryFile() again? and
> subprocess.call()?
> 
> Douglas
> 
> > 
> > Rowland
> > 
> 

I have tried what Douglas suggested, but I am getting nowhere, I do not
want to alter the 'samba-tool user edit', I just want to get a python
test script to run it and hopefully pass.

edit.py uses an editor and a human intervention to work, I can automate
this with a simple bash script. What I cannot do is to get a python test
script to fully automate this.

I think if I was to create the bash script in the source code it
would work, but where would be the best place to put it ? and how
would I obtain the path to it ?

Rowland
  



More information about the samba-technical mailing list