# -l list all hosts and their status
# -f list all SSH fingerprints
-import time, os, pwd, sys, getopt, ldap, crypt, readline, copy
-from tempfile import mktemp
+import time, os, pwd, sys, getopt, ldap, crypt, readline, copy, subprocess
from os import O_CREAT, O_EXCL, O_WRONLY
from userdir_ldap import *
Attrs[1][Attr].append(NewValue)
print
-def CalcTempFile():
- unique = 0
- while unique == 0:
- name = mktemp()
- try:
- fd = os.open(name, O_CREAT | O_EXCL | O_WRONLY, 0600)
- except OSError:
- continue
- os.close(fd)
- unique = 1
- return name
-
# Main program starts here
User = pwd.getpwuid(os.getuid())[0]
hosts.append(hAttrs[1]['host'][0])
hosts.sort()
- tmpfile = CalcTempFile()
for host in hosts:
for hAttrs in Attrs:
if host == hAttrs[1]['host'][0]:
if 'sshRSAHostKey' in hAttrs[1].keys():
for key in hAttrs[1]['sshRSAHostKey']:
- tmp = open(tmpfile, 'w')
- tmp.write(key + '\n')
- tmp.close()
- fp = os.popen('/usr/bin/ssh-keygen -l -f ' + tmpfile, "r")
- input = fp.readline()
- fp.close()
+ keygen = subprocess.Popen(['/usr/bin/ssh-keygen', '-l', '-f', '-'],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ keygen.stdin.write(key + '\n')
+ keygen.stdin.close()
+ input = keygen.stdout.readline()
+ keygen.wait()
fingerprint = input.split(' ')
print "%s %s root@%s" % (fingerprint[0], fingerprint[1], host)
- os.unlink(tmpfile)
sys.exit(0)
HostDn = "host=" + Host + "," + HostBaseDn