+ global all_ssh_keys
+ if all_ssh_keys:
+ return all_ssh_keys
+
+ fin = os.open("/vsys/publickeys.in", os.O_NONBLOCK | os.O_WRONLY)
+ fout = os.open("/vsys/publickeys.out", os.O_NONBLOCK | os.O_RDONLY)
+
+ in_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
+ out_flags = fcntl.fcntl(fin, fcntl.F_GETFL)
+
+ res = select.select([fout], [], [])
+
+ fcntl.fcntl(fin, fcntl.F_SETFL, in_flags & ~os.O_NONBLOCK)
+ fcntl.fcntl(fout, fcntl.F_SETFL, out_flags & ~os.O_NONBLOCK)
+
+ f = os.fdopen(fout, "r")
+ all_ssh_keys = f.read()
+ return all_ssh_keys
+
+
+def all_keys():
+ global all_ssh_keys_dict
+ if all_ssh_keys_dict:
+ return all_ssh_keys_dict
+
+ keys = read_keys()
+ files = {}
+ num = 0
+ for line in keys.split('\n'):
+ line = line.strip()
+ if not line: continue
+
+ filename = ""
+ in_key = False
+ in_name = False
+ fields = line.split()
+ for f in fields:
+ f = f.strip()
+ if f.startswith("ssh-"):
+ in_key = True
+ continue
+ elif in_key:
+ in_name = True
+ in_key = False
+ continue
+ elif in_name:
+ if filename:
+ filename = "%s_%s" % (filename, f)
+ else:
+ filename = f
+
+ if not filename:
+ num += 1
+ files["unnamed_key%d" % num] = line
+ else:
+ files[filename] = "%s\n" % line
+
+ return files