|
1 |
@!@ |
|
|
2 |
|
1 |
|
|
|
2 |
@!@ |
3 |
import os |
3 |
import os |
|
|
4 |
import os.path |
4 |
import re |
5 |
import re |
5 |
import subprocess |
6 |
from univention.config_registry.handler import run_filter |
6 |
|
7 |
|
7 |
|
8 |
|
8 |
def getRegisteredFiles(): |
9 |
def getRegisteredFiles(): |
Lines 11-28
def getRegisteredFiles():
|
Link Here
|
---|
|
11 |
for f in os.listdir(registeredDirectory): |
12 |
for f in os.listdir(registeredDirectory): |
12 |
for line in open(os.path.join(registeredDirectory, f), 'r').readlines(): |
13 |
for line in open(os.path.join(registeredDirectory, f), 'r').readlines(): |
13 |
if line.startswith('File: '): |
14 |
if line.startswith('File: '): |
14 |
files.append(line.replace('File: ', '').strip()) |
15 |
fn = line.replace('File: ', '').strip() |
|
|
16 |
if fn.startswith('etc/ldap/slapd.conf.d'): |
17 |
files.append(fn) |
15 |
elif line.startswith('Subfile: '): |
18 |
elif line.startswith('Subfile: '): |
16 |
files.append(line.replace('Subfile: ', '').strip()) |
19 |
fn = line.replace('Subfile: ', '').strip() |
|
|
20 |
if fn.startswith('etc/ldap/slapd.conf.d'): |
21 |
files.append(fn) |
17 |
|
22 |
|
18 |
return files |
23 |
return files |
19 |
|
24 |
|
20 |
|
25 |
|
21 |
def isSchemaFileIncluded(schemaFile): |
26 |
def ucr_filter_files(registeredFiles): |
22 |
directoryPath = '/etc/univention/templates/files/etc/ldap/slapd.conf.d/' |
27 |
directoryPath = '/etc/univention/templates/files/etc/ldap/slapd.conf.d/' |
23 |
|
28 |
|
24 |
registeredFiles = getRegisteredFiles() |
29 |
checklist = [] |
25 |
|
|
|
26 |
for f in os.listdir(directoryPath): |
30 |
for f in os.listdir(directoryPath): |
27 |
if f == '25univention-ldap-server_local-schema' or f.startswith('.'): |
31 |
if f == '25univention-ldap-server_local-schema' or f.startswith('.'): |
28 |
continue |
32 |
continue |
Lines 31-51
def isSchemaFileIncluded(schemaFile):
|
Link Here
|
---|
|
31 |
if not 'etc/ldap/slapd.conf.d/%s' % f in registeredFiles: |
35 |
if not 'etc/ldap/slapd.conf.d/%s' % f in registeredFiles: |
32 |
continue |
36 |
continue |
33 |
|
37 |
|
34 |
p1 = subprocess.Popen(["cat", "/etc/univention/templates/files/etc/ldap/slapd.conf.d/%s" % f], stdout=subprocess.PIPE) |
38 |
checklist.append(f) |
35 |
p2 = subprocess.Popen(["ucr", "filter"], stdin=p1.stdout, stdout=subprocess.PIPE) |
39 |
|
36 |
p1.stdout.close() |
40 |
output = "" |
37 |
output = p2.communicate()[0].decode('utf-8', 'replace') |
41 |
if checklist: |
38 |
pattern = re.compile('include.*%s' % schemaFile) |
42 |
for fn in checklist: |
39 |
for line in output.split('\n'): |
43 |
with open('/etc/univention/templates/files/etc/ldap/slapd.conf.d/%s' % (fn,), 'r') as f: |
40 |
if line and pattern.match(line): |
44 |
output += run_filter(f.read(), configRegistry) |
41 |
return True |
45 |
return output |
42 |
|
46 |
|
43 |
return False |
47 |
|
|
|
48 |
def isSchemaFileIncluded(schemaFile, ucr_filtered_output): |
49 |
return re.search('\ninclude.*%s\n' % schemaFile, ucr_filtered_output) is not None |
44 |
|
50 |
|
45 |
|
51 |
|
46 |
if configRegistry.get('ldap/server/type', 'slave') == 'master': |
52 |
if configRegistry.get('ldap/server/type', 'slave') == 'master': |
47 |
if os.path.exists('/var/lib/univention-ldap/local-schema'): |
53 |
if os.path.exists('/var/lib/univention-ldap/local-schema'): |
48 |
for schemaFile in sorted(os.listdir('/var/lib/univention-ldap/local-schema')): |
54 |
|
49 |
if not isSchemaFileIncluded(schemaFile): |
55 |
registeredFiles = getRegisteredFiles() |
|
|
56 |
ucr_filtered_output = ucr_filter_files(registeredFiles) |
57 |
|
58 |
for schemaFile in os.listdir('/var/lib/univention-ldap/local-schema'): |
59 |
if not isSchemaFileIncluded(schemaFile, ucr_filtered_output): |
50 |
print('include /var/lib/univention-ldap/local-schema/%s' % schemaFile) |
60 |
print('include /var/lib/univention-ldap/local-schema/%s' % schemaFile) |
51 |
@!@ |
61 |
@!@ |