|
Lines 40-46
import tempfile
Link Here
|
| 40 |
import glob |
40 |
import glob |
| 41 |
import subprocess |
41 |
import subprocess |
| 42 |
import traceback |
42 |
import traceback |
| 43 |
import ast |
|
|
| 44 |
import urllib |
43 |
import urllib |
| 45 |
import filecmp |
44 |
import filecmp |
| 46 |
|
45 |
|
|
Lines 54-59
import paramiko
Link Here
|
| 54 |
# univention |
53 |
# univention |
| 55 |
#from univention.lib import escape_value |
54 |
#from univention.lib import escape_value |
| 56 |
from univention.lib.package_manager import PackageManager |
55 |
from univention.lib.package_manager import PackageManager |
|
|
56 |
from univention.lib.umc_connection import UMCConnection |
| 57 |
from univention.management.console.modules import Base |
57 |
from univention.management.console.modules import Base |
| 58 |
from univention.management.console.log import MODULE |
58 |
from univention.management.console.log import MODULE |
| 59 |
from univention.management.console.config import ucr |
59 |
from univention.management.console.config import ucr |
|
Lines 119-125
def get_ssh_connection(username, password, host):
Link Here
|
| 119 |
def move_slave_into_ou(master, username, password, ou, slave): |
119 |
def move_slave_into_ou(master, username, password, ou, slave): |
| 120 |
'''Make sure that the slave object exists in the right OU.''' |
120 |
'''Make sure that the slave object exists in the right OU.''' |
| 121 |
MODULE.info('Trying to move the slave entry in the right OU structure...''') |
121 |
MODULE.info('Trying to move the slave entry in the right OU structure...''') |
| 122 |
result = umc(username, password, master, ['schoolwizards/schools/move_dc', '-o', 'schooldc=%s' % slave , '-o', 'schoolou=%s' % ou, '-f', 'schoolwizards/schools']) |
122 |
result = umc(username, password, master, path='schoolwizards/schools/move_dc', options={'schooldc': slave , 'schoolou': ou}, flavor='schoolwizards/schools') |
| 123 |
if not result.get('success'): |
123 |
if not result.get('success'): |
| 124 |
MODULE.warn('Could not successfully move the slave DC into its correct OU structure:\n%s' % result.get('message')) |
124 |
MODULE.warn('Could not successfully move the slave DC into its correct OU structure:\n%s' % result.get('message')) |
| 125 |
return False |
125 |
return False |
|
Lines 200-233
def get_master_dns_lookup():
Link Here
|
| 200 |
|
200 |
|
| 201 |
regUMCResult = re.compile(r'.*^\s*RESULT\s*:\s*(?P<result>.*)', re.MULTILINE | re.DOTALL) |
201 |
regUMCResult = re.compile(r'.*^\s*RESULT\s*:\s*(?P<result>.*)', re.MULTILINE | re.DOTALL) |
| 202 |
|
202 |
|
| 203 |
def umc(username, password, master, options = [], requestType='command'): |
203 |
def umc(username, password, master, requestType='command', path='', options=None, flavor=None): |
| 204 |
with tempfile.NamedTemporaryFile() as passwordFile: |
204 |
connection = UMCConnection(master, username, password, error_handler=MODULE.warn) |
| 205 |
# write password to temp file |
205 |
MODULE.info('Executing on %r: %r %r flavor=%r options=%r' % (master, requestType, path, flavor, options)) |
| 206 |
passwordFile.write('%s' % password) |
206 |
return connection.request(path or '', options, flavor, command=requestType) |
| 207 |
passwordFile.flush() |
|
|
| 208 |
|
| 209 |
# UMC call |
| 210 |
cmd = ['/usr/sbin/umc-%s' % requestType, '-U', username, '-y', passwordFile.name, '-s', master] |
| 211 |
cmd += options |
| 212 |
MODULE.info('Executing: %s' % ' '.join(cmd)) |
| 213 |
process = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 214 |
stdout, stderr = process.communicate() |
| 215 |
|
| 216 |
# parse output |
| 217 |
match = regUMCResult.match(stdout) |
| 218 |
|
| 219 |
# check for errors |
| 220 |
if process.returncode != 0 or not match: |
| 221 |
# error case... should not happen |
| 222 |
MODULE.error('Failed to launch UMC query: %s\n%s%s' % (cmd, stderr, stdout)) |
| 223 |
raise RuntimeError(_('Cannot connect to UMC server %s.') % master) |
| 224 |
|
| 225 |
# parse the result and filter for exact matches (UMC search for '*pattern*') |
| 226 |
return ast.literal_eval(match.groupdict().get('result')) |
| 227 |
|
207 |
|
| 228 |
def get_user_dn(username, password, master): |
208 |
def get_user_dn(username, password, master): |
| 229 |
"""Get the LDAP DN for the given username.""" |
209 |
"""Get the LDAP DN for the given username.""" |
| 230 |
result = umc(username, password, master, ['-f', 'users/user', 'udm/query', '-o', 'objectProperty=username', '-o', 'objectPropertyValue=%s' % username ]) |
210 |
result = umc(username, password, master, flavor='users/user', path='udm/query', options={"objectProperty": "username", "objectPropertyValue": username}) |
| 231 |
result = [ ientry for ientry in result if ientry.get('username') == username ] |
211 |
result = [ ientry for ientry in result if ientry.get('username') == username ] |
| 232 |
if not result: |
212 |
if not result: |
| 233 |
return None |
213 |
return None |
|
Lines 258-274
def create_ou_remote(master, username, password, ou, display_name, educational_s
Link Here
|
| 258 |
opts = [{'object' : {'name' : ou, 'display_name' : display_name, 'dc_name' : educational_slave}}] |
238 |
opts = [{'object' : {'name' : ou, 'display_name' : display_name, 'dc_name' : educational_slave}}] |
| 259 |
if administrative_slave: |
239 |
if administrative_slave: |
| 260 |
opts[0]['object']['dc_name_administrative'] = administrative_slave |
240 |
opts[0]['object']['dc_name_administrative'] = administrative_slave |
| 261 |
umc(username, password, master, ['schoolwizards/schools/create', '-e', '-o', repr(opts), '-f', 'schoolwizards/schools']) |
241 |
umc(username, password, master, path='schoolwizards/schools/create', options=opts, flavor='schoolwizards/schools') |
| 262 |
except RuntimeError: |
242 |
except RuntimeError: |
| 263 |
return False |
243 |
return False |
| 264 |
return True |
244 |
return True |
| 265 |
|
245 |
|
| 266 |
def get_ucr_master(username, password, master, *ucrVariables): |
246 |
def get_ucr_master(username, password, master, *ucrVariables): |
| 267 |
'''Read the LDAP base from the master system via UMC.''' |
247 |
'''Read the LDAP base from the master system via UMC.''' |
| 268 |
options = ['ucr', '-l'] |
248 |
return umc(username, password, master, 'get', path='ucr', options=list(ucrVariables)) |
| 269 |
for ivar in ucrVariables: |
|
|
| 270 |
options += ['-o', ivar] |
| 271 |
return umc(username, password, master, options, 'get') |
| 272 |
|
249 |
|
| 273 |
def restoreOrigCertificate(certOrigFile): |
250 |
def restoreOrigCertificate(certOrigFile): |
| 274 |
# try to restore the original certificate file |
251 |
# try to restore the original certificate file |