From: Eric S. Raymond Date: Thu, 18 Apr 2013 17:04:42 +0000 (-0400) Subject: Allow use of new-style config location. X-Git-Tag: 1.8^0 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=f68c5ea4013311f72c5e8122383807f950b06efc;p=ssh-installkeys.git Allow use of new-style config location. --- diff --git a/NEWS b/NEWS index d80ad1d..95fb3a1 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ NEWS file for project ssh-installkeys +1.8 @ 2013-04-18: + Program can now use new-style config-file location ~/.config/ssh-installkeys + 1.7 @ 2012-03-26: Remote installations are now recorded if your create ~/.ssh-installkeys. Code now bails out gracefully on host key changes or broken ptys. diff --git a/ssh-installkeys b/ssh-installkeys index 6ed1e45..5426ee6 100755 --- a/ssh-installkeys +++ b/ssh-installkeys @@ -1870,7 +1870,7 @@ def split_command_line(command_line): # ############################################################################### -version = 1.7 +version = 1.8 class ssh_session: "Session with extra state including the password to be used." @@ -1948,14 +1948,19 @@ class KeyConfig(ConfigParser.RawConfigParser): "Store our state about remote keys." def __init__(self): ConfigParser.RawConfigParser.__init__(self) - self.have_config = os.path.exists(KeyConfig.configfile()) - self.read(KeyConfig.configfile()) - @staticmethod - def configfile(): - return os.path.expanduser('~/.ssh-installkeys') + newstyle = os.path.expanduser('~/.config/ssh-installkeys') + oldstyle = os.path.expanduser('~/.ssh-installkeys') + if os.path.exists(newstyle): + self.configfile = newstyle + elif os.path.exists(oldstyle): + self.configfile = oldstyle + else: + self.configfile = None + if self.configfile: + self.read(self.configfile) def save(self): - if self.have_config: - self.write(open(KeyConfig.configfile(), "w")) + if self.configfile: + self.write(open(self.configfile, "w")) def remember(self, session): authorized = session.ssh("cat $HOME/.ssh/authorized_keys") keydict = {} @@ -2012,7 +2017,11 @@ def forcefile(session, fn, command, checkonly=False): if __name__ == '__main__': # Process options - (options, arguments) = getopt.getopt(sys.argv[1:], "cdhvp:") + try: + (options, arguments) = getopt.getopt(sys.argv[1:], "cdhvp:") + except getopt.GetoptError, e: + print e + sys.exit(1) check = 0 verbose = 0 delete = 0 @@ -2128,6 +2137,7 @@ if __name__ == '__main__': pass except RuntimeError: sys.exit(-1) + # It's all over now... os.remove(keyfile) config.save() diff --git a/ssh-installkeys.xml b/ssh-installkeys.xml index 55a0c41..fdf4f85 100644 --- a/ssh-installkeys.xml +++ b/ssh-installkeys.xml @@ -50,12 +50,13 @@ user@host syntax to force the remote username. Recording remote key locations -If the file ~/.ssh/installkeys exists, -places where you install keys will be recorded in it. This record will -also be updated when you use the check option, so you can use -that option to check sites where you may have previously installed -keys and add them to the list. Entries are removed when you -delete remote keys. +If either of the files +~/.config/ssh/installkeys or +~/.ssh/installkeys exists, places where you +install keys will be recorded in it. This record will also be updated +when you use the check option, so you can use that option to check +sites where you may have previously installed keys and add them to the +list. Entries are removed when you delete remote keys. Beware that if your account is cracked, this record will offer the intruder a menu of other systems to attack, escalating security