Re: 'becomes' script
Jonathan Hogg <[email protected]> Mon, 10 Jun 2002 22:55:57 +0100
| Newsgroups | gmane.comp.sysutils.ark.devel |
|---|---|
| Organization | One Good Idea Ltd. |
| Message-ID | <B92ADEFD.C204%[email protected]> |
On 10/6/2002 20:55, Will Partain wrote (in an accidentally off-list thread
caused by me):
>> [On the gripping hand, perhaps you could just use Python as the remote
>> interpreter and throw a short script at it that changes gid/uid and then
>> invokes sh with a literal string as input. becomes is so simple that there's
>> no particular need for it to be separate.]
>
> I like this idea, actually... I think. We start either
>
> ssh remote sudo python
>
> or just 'ssh remote python', send through all of the
> preliminaries (including user/group setting), then send
> through a last "line" of
>
> os.execl('/bin/sh','/bin/sh','-c',"""<the code>""")
>
> and you'll tell me how to escape <the code> so it doesn't
> ever no-matter-what have """ in it :-)
Aha. My plan here was to use os.popen rather than os.execl then pump in a
literal string as input. So on the sending side you'd build a script
something like:
pyscript = """import os,sys
os.setgid( %d )
os.setuid( %d )
sh = os.popen( '%s', 'w', 0 )
sh.write( '''%s''' )
if sh.close() is not None:
sys.exit( 1 )
""" % ( gid, uid, shcmd, shscript )
then you'd throw this at 'ssh remote sudo python'.
The inspiration for this was realising that the whole of your becomes script
would fit in one ssh-compressed eth packet, so the whole shenanigans of
installing it seemed overkill.
Jonathan
--
jonathan hogg, one good idea ltd, 131 queen margaret dr., glasgow g20 8pd
http://www.onegoodidea.com/ tel:+44-(0)7976-614338 fax:+44-(0)7970-537451