|
35 |
import univention.config_registry as confreg |
35 |
import univention.config_registry as confreg |
36 |
from optparse import OptionParser |
36 |
from optparse import OptionParser |
37 |
|
37 |
|
38 |
def get_policy(host_dn, verbose=False): |
38 |
def get_policy(host_dn, verbose=False, server=None): |
39 |
"""Retriev policy for host_dn.""" |
39 |
"""Retriev policy for host_dn.""" |
40 |
set_list = {} |
40 |
set_list = {} |
41 |
|
41 |
|
42 |
# get policy result |
42 |
# get policy result |
43 |
if verbose: |
43 |
if verbose: |
44 |
print >> sys.stderr, 'Retrieving policy for %s...' % (host_dn,) |
44 |
print >> sys.stderr, 'Retrieving policy for %s...' % (host_dn,) |
45 |
cmd = ('univention_policy_result', |
45 |
cmd = ['univention_policy_result'] |
46 |
'-D', host_dn, |
46 |
cmd += ['-D', host_dn] |
47 |
'-y', '/etc/machine.secret', |
47 |
cmd += ['-y', '/etc/machine.secret'] |
48 |
host_dn) |
48 |
if server: |
|
|
49 |
cmd += ['-h', server] |
50 |
cmd += [host_dn] |
49 |
proc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) |
51 |
proc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) |
50 |
for line in proc.stdout: |
52 |
for line in proc.stdout: |
51 |
line = line.rstrip('\n') |
53 |
line = line.rstrip('\n') |
|
81 |
parser.add_option('-v', '--verbose', |
83 |
parser.add_option('-v', '--verbose', |
82 |
dest='verbose', action='store_true', |
84 |
dest='verbose', action='store_true', |
83 |
help='print verbose information') |
85 |
help='print verbose information') |
|
|
86 |
parser.add_option('-l', '--ldap-server', dest='server', help='connect to this ldap host') |
84 |
options, args = parser.parse_args() |
87 |
options, args = parser.parse_args() |
85 |
|
88 |
|
86 |
if 'UNIVENTION_BASECONF' in os.environ: |
89 |
if 'UNIVENTION_BASECONF' in os.environ: |
|
110 |
ucr_ldap = confreg.ConfigRegistry(filename=confregfn) |
113 |
ucr_ldap = confreg.ConfigRegistry(filename=confregfn) |
111 |
ucr_ldap.load() |
114 |
ucr_ldap.load() |
112 |
|
115 |
|
113 |
set_list = get_policy(host_dn, options.verbose) |
116 |
set_list = get_policy(host_dn, options.verbose, options.server) |
114 |
if set_list: |
117 |
if set_list: |
115 |
new_set_list = [] |
118 |
new_set_list = [] |
116 |
for key, value in set_list.items(): |
119 |
for key, value in set_list.items(): |