From: Julien Cristau Date: Fri, 11 Oct 2019 15:44:33 +0000 (+0200) Subject: ud-host: use subprocess.Popen instead of os.popen. X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=commitdiff_plain;h=49298c2ec7ae6138e986ff74ea8b0ed86755990c ud-host: use subprocess.Popen instead of os.popen. --- diff --git a/debian/changelog b/debian/changelog index 936ed15..6982cc3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -23,6 +23,7 @@ userdir-ldap (0.3.97) UNRELEASED; urgency=medium * Delete unmaintained/gpgwrapper. 8 years of non-maintenance ought to be enough. * Delete ud-emailmatcher. Looks broken and unused. * ud-mailgate: use subprocess.Popen instead of os.popen. + * ud-host: use subprocess.Popen instead of os.popen. -- Peter Palfrader Sat, 06 Apr 2019 22:04:34 +0200 diff --git a/ud-host b/ud-host index 30d6c36..79a9bd1 100755 --- a/ud-host +++ b/ud-host @@ -33,8 +33,7 @@ # -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 * @@ -213,18 +212,6 @@ def MultiChangeAttr(Attrs,Attr): 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] @@ -285,21 +272,19 @@ elif FingerPrints == 1: 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