|
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 |
|
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 |
reset_username = ucr.get('ad/reset/username') |
462 |
reset_password_file = ucr.get('ad/reset/password') |
463 |
reset_password = open(reset_password_file).readline().strip() |
464 |
cmd = ['samba-tool', 'user', 'setpassword', '--username', reset_username, '--password', reset_password, '--filter', filter_format('samaccountname=%s', (username,)), '--newpassword', password, '-H', 'ldap://%s' % ldb_url] |
465 |
process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
466 |
cmd_out, cmd_err = process.communicate() |
467 |
|
468 |
if cmd_out: |
469 |
MODULE.process("STDOUT of {}: {}".format(cmd_out)) |
470 |
if cmd_err: |
471 |
MODULE.process("STDERR of {}: {}".format(cmd_err)) |
472 |
|
473 |
if process.returncode: |
474 |
MODULE.error("admember_set_password(): failed to set password. Return code: %s" % (process.returncode,)) |
475 |
return False |
476 |
return True |
477 |
|
458 |
def udm_set_password(self, username, password): |
478 |
def udm_set_password(self, username, password): |
|
|
479 |
user = self.get_udm_user(username=username, admin=True) |
480 |
if 'synced' in user.get('objectFlag') and ucr.is_true('ad/member'): |
481 |
return self.admember_set_password(username, password) |
459 |
try: |
482 |
try: |
460 |
user = self.get_udm_user(username=username, admin=True) |
|
|
461 |
user["password"] = password |
483 |
user["password"] = password |
462 |
user["pwdChangeNextLogin"] = 0 |
484 |
user["pwdChangeNextLogin"] = 0 |
463 |
user.modify() |
485 |
user.modify() |