diff --git a/tsshbatch.py b/tsshbatch.py index f47b5eb..ef7c742 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -17,7 +17,7 @@ PROGNAME = "tsshbatch.py" BASENAME = PROGNAME.split(".py")[0] PROGENV = BASENAME.upper() -CVSID = "$Id: tsshbatch.py,v 1.147 2013/10/23 02:25:24 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.148 2013/10/23 02:44:46 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" @@ -71,6 +71,7 @@ SUDO = 'sudo' SUDOPROMPT = 'READINGSUDOPW' SUDOARGS = '-S -p %s' % SUDOPROMPT +SUDOPWHINT = ' (Default: Login Password)' TRAILER = ": " USAGE = \ PROGVER + "\n" +\ @@ -203,7 +204,7 @@ # End of 'HostFileTransfer()' -def HostCommands(host, user, pw, commands): +def HostCommands(host, user, pw, sudopw, commands): ssh = paramiko.SSHClient() @@ -240,7 +241,7 @@ # If doing a sudo command, send the password if command.startswith(SUDO + " "): - stdin.write("%s\n" % pw) + stdin.write("%s\n" % sudopw) stdin.flush() # If all we see on stderr at this point is our original @@ -472,19 +473,26 @@ elif command: Commands = [command,] -# If user want 'sudo' execution, they MUST provide a password because -# key exchange-based authentication is not part of sudo. If the -# password has not been set by some other means (interactive, command -# line or environment variable), ask for it here. +# If user want 'sudo' execution, they MUST provide a password +# regardkess if how they intially authenticate to the system. +# This allows the user to have a different password (or a key) for +# logging in than for promoting privlege. -SUDOPW = False +# If the user did use password authentication to initially +# authenticate, it's used as the default in the sudo password +# dialog below. + +hint = "" +if PWORD: + hint = SUDOPWHINT + +SUDOPW = "" for command in Commands: - if command.startswith(SUDO + " ") and not PWORD: - SUDOPW = True + if command.startswith(SUDO + " "): + SUDOPW = getpass.getpass(pSUDO + hint) + if PWORD and not SUDOPW: + SUDOPW = PWORD -if SUDOPW: - PWORD = getpass.getpass(pSUDO) - # Iterate over the list of hosts, executing any file transfers and # commands. Accomodate commenting out hosts in a list. @@ -500,4 +508,4 @@ HostFileTransfer(host, UNAME, PWORD, Put_Transfer_List, GET=False) if Commands: - HostCommands(host, UNAME, PWORD, Commands) + HostCommands(host, UNAME, PWORD, SUDOPW, Commands)