|
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
class Instance(Base):
|
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 |
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', 'samaccountname="%s"' % username, --newpassword, password, -H, 'ldap://%s' % ldb_url] |
465 |
cmd_proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
466 |
cmd_out, cmd_err = cmd_proc.communicate() |
467 |
cmd_exit = cmd_proc.wait() |
468 |
|
469 |
if cmd_out: |
470 |
self.log("STDOUT of {}: {}".format(cmd, cmd_out)) |
471 |
if cmd_err: |
472 |
self.log("STDERR of {}: {}".format(cmd, cmd_err)) |
473 |
|
474 |
if cmd_exit == 0: |
475 |
return True |
476 |
else: |
477 |
raise Exception("admember_set_password(): failed to set password. Return code: %s" % cmd_exit) |
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 |
self.admember_set_password(username, password) |
483 |
|
459 |
try: |
484 |
try: |
460 |
user = self.get_udm_user(username=username, admin=True) |
|
|
461 |
user["password"] = password |
485 |
user["password"] = password |
462 |
user["pwdChangeNextLogin"] = 0 |
486 |
user["pwdChangeNextLogin"] = 0 |
463 |
user.modify() |
487 |
user.modify() |