From b60c8070283ec1b38c7eb8abada2c3337dc5db11 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 20 Aug 2020 23:18:34 +0300 Subject: [PATCH] debugging and some changes --- UserAd_class.py | 1 + importer.py | 17 ++++++++++++++--- zayavka_reader.py | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/UserAd_class.py b/UserAd_class.py index a7f3ff8..ccebb4a 100755 --- a/UserAd_class.py +++ b/UserAd_class.py @@ -57,6 +57,7 @@ class UserAd: self.sam.setpassword("(samAccountName=%s)" % ldb.binary_encode(self.usrName), self.usrPass, False) except Exception as exc: self.sam.transaction_cancel() + print(exc) return exc else: self.sam.transaction_commit() diff --git a/importer.py b/importer.py index 62bdf63..17e1a11 100755 --- a/importer.py +++ b/importer.py @@ -55,16 +55,22 @@ def main(): lp = samba.param.LoadParm() lp.load(samba.param.default_path()) # или lp.load("/etc/samba/smb.conf") sam = SamDB(lp=lp, session_info=system_session()) + expression = "(&(objectCategory=person)(objectClass=user))" + + res = sam.search(base=base, expression=expression, attrs=['*', 'userAccountControl']) + for i in res: + print(str(i['samAccountName'])) res, err = z_reader.mysql_reader(dbconn, sql) - print(res) if err: print(err) exit(0) z_users = z_reader.users_make_zayavka(res) i = 0 for z_user in z_users: + print(z_user, z_users[z_user]) ad_user = UserAd(sam, base, domainName, z_users[z_user]['samAccountName'], z_users[z_user]['usrPass']) if z_users[z_user]['toRemove']: # удаляем, если такой есть + print("removing user") if ad_user.exists: ad_user.remove() dat, err = z_reader.mysql_reader(dbconn, sql_delete % z_users[z_user]['id']) @@ -72,9 +78,14 @@ def main(): print(err) continue if not ad_user.exists: - ad_user.add() + print("make new user") + ad_res = ad_user.add() + if ad_res: + print(ad_res) if z_users[z_user]['pwChange']: # обновляем пароль - ad_user.set_passwd() + ad_res = ad_user.set_passwd() + if ad_res: + print(ad_res) dat, err = z_reader.mysql_reader(dbconn, sql_update_changes % z_users[z_user]['id']) if err: print(err) diff --git a/zayavka_reader.py b/zayavka_reader.py index ddfcfcf..8a810b2 100755 --- a/zayavka_reader.py +++ b/zayavka_reader.py @@ -56,7 +56,6 @@ def users_make_zayavka(users): toremove = True # размечаем группы, в которых должен быть пользователь memberof = [] - print(memberof) if str(i['Otdel']) == 'Users': memberof = ad_groups_users[:] elif str(i['Otdel']) == '1C': @@ -86,8 +85,10 @@ def main(): data, err = mysql_reader(dbconn, sql) if not err: users = users_make_zayavka(data) + x = '' for user in users: print(user, users[user]) + input(x) else: print(err)