fuse.fuse_python_api = (0, 2)
keys_dir = "/keys"
-
+all_ssh_keys = None
+all_ssh_keys_dict = None
def read_keys():
+ 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)
fcntl.fcntl(fout, fcntl.F_SETFL, out_flags & ~os.O_NONBLOCK)
f = os.fdopen(fout, "r")
- return f.read()
+ all_ssh_keys = f.read()
+ return all_ssh_keys
+
def all_keys():
- keys = read_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()
- try:
- name = fields[2]
- files[name] = line
- except:
+ 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
if offset < slen:
if offset + size > slen:
size = slen - offset
- buf = keys[offset:offset+size]
+ buf = content[offset:offset+size]
else:
buf = ''
return buf