View | Details | Raw Unified | Return to bug 44867 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-self-service/umc/python/passwordreset/__init__.py (-1 / +24 lines)
 Lines 39-44    Link Here 
39
from functools import wraps
39
from functools import wraps
40
from ldap.filter import filter_format
40
from ldap.filter import filter_format
41
import pylibmc
41
import pylibmc
42
import subprocess
42
43
43
from univention.lib.i18n import Translation
44
from univention.lib.i18n import Translation
44
from univention.lib.umc import Client, HTTPError, ConnectionError, Unauthorized
45
from univention.lib.umc import Client, HTTPError, ConnectionError, Unauthorized
 Lines 455-463   def set_contact_data(self, dn, email, mobile): Link Here 
455
			MODULE.error("set_contact_data(): {}".format(traceback.format_exc()))
456
			MODULE.error("set_contact_data(): {}".format(traceback.format_exc()))
456
			raise
457
			raise
457
458
459
	def admember_set_password(self, username, password):
460
		ldb_url = ucr.get('connector/ad/ldap/host')
461
		ldb_url = 'ldaps://%s' % (ldb_url,) if ucr.is_true('connector/ad/ldap/ldaps') else 'ldap://%s' % (ldb_url,)
462
		reset_username = ucr.get('ad/reset/username')
463
		reset_password_file = ucr.get('ad/reset/password')
464
		reset_password = open(reset_password_file).readline().strip()
465
		cmd = ['samba-tool', 'user', 'setpassword', '--username', reset_username, '--password', reset_password, '--filter', filter_format('samaccountname=%s', (username,)), '--newpassword', password, '-H', ldb_url]
466
		process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
467
		cmd_out, cmd_err = process.communicate()
468
469
		if cmd_out:
470
			MODULE.process("STDOUT: {}".format(cmd_out))
471
		if cmd_err:
472
			MODULE.process("STDERR: {}".format(cmd_err))
473
474
		if process.returncode:
475
			MODULE.error("admember_set_password(): failed to set password. Return code: %s" % (process.returncode,))
476
			return False
477
		return True
478
458
	def udm_set_password(self, username, password):
479
	def udm_set_password(self, username, password):
480
		user = self.get_udm_user(username=username, admin=True)
481
		if 'synced' in user.get('objectFlag') and ucr.is_true('ad/member'):
482
			return self.admember_set_password(username, password)
459
		try:
483
		try:
460
			user = self.get_udm_user(username=username, admin=True)
461
			user["password"] = password
484
			user["password"] = password
462
			user["pwdChangeNextLogin"] = 0
485
			user["pwdChangeNextLogin"] = 0
463
			user.modify()
486
			user.modify()

Return to bug 44867