From: Eric S. Raymond Date: Sun, 1 Apr 2012 20:33:26 +0000 (-0400) Subject: Make the code robust against comments and garbage in key lines. X-Git-Tag: 1.8~3 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=40e99de6ac91f4152a8e36203205f53cacf55a9d;p=ssh-installkeys.git Make the code robust against comments and garbage in key lines. --- diff --git a/ssh-installkeys b/ssh-installkeys index 524fb7a..74c602b 100755 --- a/ssh-installkeys +++ b/ssh-installkeys @@ -1961,14 +1961,18 @@ class KeyConfig(ConfigParser.RawConfigParser): keydict = {} for line in authorized.split("\n"): if line: - (keytype, content, keyid) = line.strip().split() - if keyid not in keydict: - keydict[keyid] = [] - keydict[keyid].append(keytype) - self.remove_section(session.host) - self.add_section(session.host) - for (keyid, types) in keydict.items(): - self.set(session.host, keyid, ",".join(types)) + try: + (keytype, content, keyid) = line.strip().split() + if keyid not in keydict: + keydict[keyid] = [] + keydict[keyid].append(keytype) + except ValueError: + print "unexpected format in key line ''." % repr(line) + if keydict: + self.remove_section(session.host) + self.add_section(session.host) + for (keyid, types) in keydict.items(): + self.set(session.host, keyid, ",".join(types)) def forget(self, host): self.remove_section(host)