X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-generate;h=b48cdc3af31cf7852f721e5a148cc895497c6b30;hb=88a19a6e47a1c577474311d016ae5d26a72a4029;hp=8a4588c76f78f126cd400f441deac51783771de7;hpb=a9ebb6f2afbf0fbc0e94ab73726dedb6a8ae5d75;p=mirror%2Fuserdir-ldap.git diff --git a/ud-generate b/ud-generate index 8a4588c..b48cdc3 100755 --- a/ud-generate +++ b/ud-generate @@ -7,6 +7,7 @@ # Copyright (c) 2004-2005,7 Joey Schulze # Copyright (c) 2001-2007 Ryan Murray # Copyright (c) 2008 Peter Palfrader +# Copyright (c) 2008 Andreas Barth # Copyright (c) 2008 Mark Hymers # # This program is free software; you can redistribute it and/or modify @@ -767,8 +768,26 @@ def GenBSMTP(l,File,HomePrefix): raise; Done(File,F,None); +# cache IP adresses +HostToIPCache = {} +def HostToIP(Host): + global HostToIPCache + if not Host in HostToIPCache: + IPAdressesT = None + try: + IPAdressesT = list(set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)])) + except socket.gaierror, (code): + if code[0] != -2: raise + IPAdresses = [] + for addr in IPAdressesT: + if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]] + else: IPAdresses += [addr[1]] + HostToIPCache[Host] = IPAdresses + return HostToIPCache[Host] + + # Generate the ssh known hosts file -def GenSSHKnown(l,File): +def GenSSHKnown(l,File,mode=None): F = None; try: OldMask = os.umask(0022); @@ -788,19 +807,12 @@ def GenSSHKnown(l,File): SHost = Host.find(".") if SHost != None: HostNames += [Host[0:SHost]] - IPAdressesT = None - IPAdresses = [] - # get IP adresses back as "proto adress" to distinguish between v4 and v6 - try: - IPAdressesT = set([ (a[0],a[4][0]) for a in socket.getaddrinfo(Host, None)]) - except: - if code[0] != -2: raise - for addr in IPAdressesT: - if addr[0] == socket.AF_INET: IPAdresses += [addr[1], "::ffff:"+addr[1]] - else: IPAdresses += [addr[1]] - for I in x[1]["sshRSAHostKey"]: - Line = "%s %s" %(",".join(HostNames + IPAdresses), I); + if mode and mode == 'authorized_keys': + #Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,from="%s" %s' % (Host, ",".join(HNames + HostToIP(Host)), I) + Line = 'command="rsync --server --sender -pr . /var/cache/userdir-ldap/hosts/%s",no-port-forwarding,no-X11-forwarding,no-agent-forwarding %s' % (Host,I) + else: + Line = "%s %s" %(",".join(HostNames + HostToIP(Host)), I); Line = Sanitize(Line) + "\n"; F.write(Line); # Oops, something unspeakable happened. @@ -889,6 +901,7 @@ GenMarkers(l,GlobalDir+"markers"); GenPrivate(l,GlobalDir+"debian-private"); GenDisabledAccounts(l,GlobalDir+"disabled-accounts"); GenSSHKnown(l,GlobalDir+"ssh_known_hosts"); +#GenSSHKnown(l,GlobalDir+"authorized_keys", 'authorized_keys'); GenHosts(l,GlobalDir+"debianhosts"); GenMailDisable(l,GlobalDir+"mail-disable"); GenMailBool(l,GlobalDir+"mail-greylist","mailGreylisting");