|
a/Allura/ldap-setup.py |
|
b/Allura/ldap-setup.py |
1 |
#!/usr/bin/env python
|
1 |
#!/usr/bin/env python
|
2 |
import os
|
2 |
import os
|
3 |
import shutil
|
3 |
import shutil
|
4 |
import string
|
4 |
import string
|
|
|
5 |
import logging
|
5 |
from contextlib import contextmanager
|
6 |
from contextlib import contextmanager
|
6 |
from tempfile import mkstemp
|
7 |
from tempfile import mkstemp
|
7 |
from ConfigParser import ConfigParser, NoOptionError
|
8 |
from ConfigParser import ConfigParser, NoOptionError
|
|
|
9 |
|
|
|
10 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
11 |
log = logging.getLogger('ldap-setup')
|
8 |
|
12 |
|
9 |
config = ConfigParser()
|
13 |
config = ConfigParser()
|
10 |
|
14 |
|
11 |
def main():
|
15 |
def main():
|
12 |
config.read('.setup-scm-cache')
|
16 |
config.read('.setup-scm-cache')
|
|
... |
|
... |
44 |
run('pam-auth-update')
|
48 |
run('pam-auth-update')
|
45 |
if get_value('setup ldapscripts', 'y') == 'y':
|
49 |
if get_value('setup ldapscripts', 'y') == 'y':
|
46 |
run('apt-get install ldapscripts')
|
50 |
run('apt-get install ldapscripts')
|
47 |
with tempfile(ldapscripts_conf, locals()) as name:
|
51 |
with tempfile(ldapscripts_conf, locals()) as name:
|
48 |
shutil.copy(name, '/etc/ldapscripts/ldapscripts.conf')
|
52 |
shutil.copy(name, '/etc/ldapscripts/ldapscripts.conf')
|
49 |
print 'writing passwd'
|
53 |
log.info('writing passwd')
|
50 |
with open('/etc/ldapscripts/ldapscripts.passwd', 'w') as fp:
|
54 |
with open('/etc/ldapscripts/ldapscripts.passwd', 'w') as fp:
|
51 |
fp.write(secret)
|
55 |
fp.write(secret)
|
52 |
os.chmod('/etc/ldapscripts/ldapscripts.passwd', 0400)
|
56 |
os.chmod('/etc/ldapscripts/ldapscripts.passwd', 0400)
|
53 |
print 'writing runtime'
|
57 |
log.info('writing runtime')
|
54 |
with open('/usr/share/ldapscripts/runtime.debian', 'w') as fp:
|
58 |
with open('/usr/share/ldapscripts/runtime.debian', 'w') as fp:
|
55 |
fp.write(ldapscripts_debian)
|
59 |
fp.write(ldapscripts_debian)
|
56 |
|
60 |
|
57 |
def get_value(key, default):
|
61 |
def get_value(key, default):
|
58 |
try:
|
62 |
try:
|
|
... |
|
... |
67 |
return value
|
71 |
return value
|
68 |
|
72 |
|
69 |
def run(command):
|
73 |
def run(command):
|
70 |
rc = os.system(command)
|
74 |
rc = os.system(command)
|
71 |
if rc != 0:
|
75 |
if rc != 0:
|
72 |
print 'Error running %s' % command
|
76 |
log.error('Error running %s', command)
|
73 |
assert rc == 0
|
77 |
assert rc == 0
|
74 |
return rc
|
78 |
return rc
|
75 |
|
79 |
|
76 |
@contextmanager
|
80 |
@contextmanager
|
77 |
def tempfile(template, values):
|
81 |
def tempfile(template, values):
|
|
... |
|
... |
249 |
|
253 |
|
250 |
getfield() {
|
254 |
getfield() {
|
251 |
local field="$1"
|
255 |
local field="$1"
|
252 |
local nssconffile='/etc/libnss-ldap.conf'
|
256 |
local nssconffile='/etc/libnss-ldap.conf'
|
253 |
if [ -f "$nssconffile" ];then
|
257 |
if [ -f "$nssconffile" ];then
|
254 |
local value=$(awk "/^\s*$field/ {print \$2}" /etc/libnss-ldap.conf)
|
258 |
local value=$(awk "/^\s*$field/ {print \$2}" /etc/libnss-ldap.conf)
|
255 |
else
|
259 |
else
|
256 |
local value="$2"
|
260 |
local value="$2"
|
257 |
fi
|
261 |
fi
|
258 |
echo ${value:-$2}
|
262 |
echo ${value:-$2}
|
259 |
}
|
263 |
}
|
260 |
|
264 |
|
261 |
getsuffix() {
|
265 |
getsuffix() {
|
|
... |
|
... |
266 |
|
270 |
|
267 |
# LDAP Configuration
|
271 |
# LDAP Configuration
|
268 |
SERVER=$(getfield uri "$(getfield host '')")
|
272 |
SERVER=$(getfield uri "$(getfield host '')")
|
269 |
BINDDN=$(getfield rootbinddn '')
|
273 |
BINDDN=$(getfield rootbinddn '')
|
270 |
if [ -f /etc/libnss-ldap.secret ];then
|
274 |
if [ -f /etc/libnss-ldap.secret ];then
|
271 |
BINDPWDFILE=/etc/libnss-ldap.secret
|
275 |
BINDPWDFILE=/etc/libnss-ldap.secret
|
272 |
elif [ -f /etc/ldap.secret ];then
|
276 |
elif [ -f /etc/ldap.secret ];then
|
273 |
BINDPWDFILE=/etc/ldap.secret
|
277 |
BINDPWDFILE=/etc/ldap.secret
|
274 |
fi
|
278 |
fi
|
275 |
|
279 |
|
276 |
SUFFIX=`getfield base`
|
280 |
SUFFIX=`getfield base`
|
277 |
GSUFFIX=`getsuffix nss_base_group 'ou=Group'`
|
281 |
GSUFFIX=`getsuffix nss_base_group 'ou=Group'`
|
278 |
USUFFIX=`getsuffix nss_base_passwd 'ou=People'`
|
282 |
USUFFIX=`getsuffix nss_base_passwd 'ou=People'`
|