1
0
Fork 0

First public import

This commit is contained in:
Daniele Tricoli 2008-11-26 03:14:04 +00:00
parent 64c3c7eca5
commit 73e6d81908
1 changed files with 62 additions and 0 deletions

62
wrapsu.py Normal file
View File

@ -0,0 +1,62 @@
#!/usr/bin/env python
#
# wrapsu.py
# A *very* simple wrapper for the 'su' command
#
# http://mornie.org/code/browser/misc/wrapsu.py
#
# (c) Copyright 2008 Daniele Tricoli aka Eriol <eriol@mornie.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##
#
# This simple script was born at the end of november 2008 from a discussion
# with Luca Canali and Davide Prina
import getpass
import pexpect
import os
import sys
SU_PATH = os.path.join('/', 'bin', 'su')
DEFAULT_MESSAGE = 'What is the password? Insert here: '
ENV_MESSAGE = os.getenv('WRAPSU_MESSAGE')
# If you set WRAPSU_MESSAGE in your environ it will be used instead
# of DEFAULT_MESSAGE
PASSWORD_MESSAGE = ENV_MESSAGE if ENV_MESSAGE else DEFAULT_MESSAGE
def main(args):
args = ' '.join(args)
command = SU_PATH + ' ' + args
password = getpass.getpass(PASSWORD_MESSAGE)
child = pexpect.spawn(command)
child.expect ('Password: ')
child.sendline(password)
child.interact()
os._exit(0)
if __name__ == '__main__':
try:
main(sys.argv[1:])
except TypeError:
print ''
os._exit(0)
except KeyboardInterrupt:
os._exit(0)
except Exception:
os._exit(1)