X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=ud-gpgsigfetch;h=4bca3cc0acec12d16c29e811c010b330086067a1;hp=ed8d43a1c6d0c694ec82603c2c9622bea81261d9;hb=HEAD;hpb=f7430aaedbfd46a91a9adeb53aaeadd47c5b2f14 diff --git a/ud-gpgsigfetch b/ud-gpgsigfetch index ed8d43a..4bca3cc 100755 --- a/ud-gpgsigfetch +++ b/ud-gpgsigfetch @@ -1,33 +1,16 @@ #!/usr/bin/env python # -*- mode: python -*- -# This script tries to match key fingerprints from a keyring with user -# name in a directory. When an unassigned key is found a heuristic match -# against the keys given cn/sn and the directory is performed to try to get -# a matching. Generally this works about 90% of the time, matching is fairly -# strict. In the event a non-match a fuzzy sounds-alike search is performed -# and the results printed to aide the user. -# -# GPG is automatically invoked with the correct magic special options, -# pass the names of all the valid key rings on the command line. -# -# The output report will list what actions were taken. Keys that are present -# in the directory but not in the key ring will be removed from the -# directory. -import string, re, time, ldap, getopt, sys, pwd, posix; +import re, time, ldap, getopt, sys, pwd, os; from userdir_gpg import *; Output = "extrakeys.gpg"; # Process options -AdminUser = pwd.getpwuid(posix.getuid())[0]; +AdminUser = pwd.getpwuid(os.getuid())[0]; (options, arguments) = getopt.getopt(sys.argv[1:], "o:") for (switch, val) in options: if (switch == '-o'): Output = val - elif (switch == '-m'): - LoadOverride(val); - elif (switch == '-a'): - NoAct = 0; if len(arguments) == 0: print "Give some keyrings to probe"; @@ -37,15 +20,14 @@ if len(arguments) == 0: Args = [GPGPath] + GPGBasicOptions; for x in arguments: Args.append("--keyring"); - if string.find(x,"/") == -1: + if x.find("/") == -1: Args.append("./"+x); else: Args.append(x); +Args.append("--fast-list-mode"); Args.append("--list-sigs"); Args = Args + GPGSearchOptions + [" 2> /dev/null"] -print string.join(Args," ") -#Keys = os.popen(string.join(Args," "),"r"); -Keys = os.popen("cat sigs","r"); +Keys = os.popen(" ".join(Args),"r"); # Loop over the GPG key file HaveKeys = {}; @@ -56,7 +38,7 @@ while(1): if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":"); if len(Split) >= 8 and Split[0] == "pub": HaveKeys[Split[4]] = ""; continue; @@ -70,21 +52,21 @@ Keys.close(); Args = [GPGPath] + GPGBasicOptions; for x in [Output]: Args.append("--keyring"); - if string.find(x,"/") == -1: + if x.find("/") == -1: Args.append("./"+x); else: Args.append(x); OldArgs = Args; Args = Args + GPGSearchOptions + [" 2> /dev/null"] -Keys = os.popen(string.join(Args," "),"r"); +Keys = os.popen(" ".join(Args),"r"); -print "Reading keys from output"; +print "Reading keys from output ring"; while(1): Line = Keys.readline(); if Line == "": break; - Split = string.split(Line,":"); + Split = Line.split(":"); if len(Split) >= 8 and Split[0] == "pub": HaveKeys[Split[4]] = ""; continue; @@ -105,4 +87,11 @@ while (I > 0): OldI = I; I = I - 20; if I < 0: I = 0; - print string.join(Args+KeysToFetch[I:OldI]," ") + print " ".join(Args+KeysToFetch[I:OldI]) + Fetcher = os.popen(" ".join(Args+KeysToFetch[I:OldI]),"r"); + while(1): + Line = Fetcher.readline(); + if Line == "": + break; + print Line; + Fetcher.close();