X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-generate;h=fd0c53bc842d797bf6a84a9e318ed3b3de37b697;hb=ce24a42e2c97dc6c463805413ff67f70463d0812;hp=2836f5cd1a060ceea910b400f55588d85a80de5f;hpb=341a5e66b972eb95c41f7ced4594a8a5c5e5098b;p=mirror%2Fuserdir-ldap.git diff --git a/ud-generate b/ud-generate index 2836f5c..fd0c53b 100755 --- a/ud-generate +++ b/ud-generate @@ -12,6 +12,7 @@ # Copyright (c) 2008 Luk Claes # Copyright (c) 2008 Thomas Viehmann # Copyright (c) 2009 Stephen Gran +# Copyright (c) 2010 Helmut Grohne # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,6 +31,10 @@ import string, re, time, ldap, getopt, sys, os, pwd, posix, socket, base64, sha, shutil, errno, tarfile, grp from userdir_ldap import * from userdir_exceptions import * +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO global Allowed global CurrentHost @@ -385,7 +390,20 @@ def GenSSHtarballs(userlist, SSHFiles, grouprevmap, target): to.uname = f to.gname = grname to.mode = 0400 - tf.addfile(to, file(os.path.join(GlobalDir, 'userkeys', f))) + + contents = file(os.path.join(GlobalDir, 'userkeys', f)).read() + lines = [] + for line in contents.splitlines(): + if line.startswith("allowed_hosts=") and ' ' in line: + machines, line = line.split('=', 1)[1].split(' ', 1) + if CurrentHost not in machines.split(','): + continue # skip this key + lines.append(line) + if not lines: + continue # no keys for this host + contents = "\n".join(lines) + to.size = len(contents) + tf.addfile(to, StringIO(contents)) tf.close() os.rename(os.path.join(GlobalDir, 'ssh-keys-%s.tar.gz' % CurrentHost), target)