Browse Source

debugging and some changes

master
root 4 years ago
parent
commit
b60c807028
3 changed files with 17 additions and 4 deletions
  1. +1
    -0
      UserAd_class.py
  2. +14
    -3
      importer.py
  3. +2
    -1
      zayavka_reader.py

+ 1
- 0
UserAd_class.py View File

@ -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()


+ 14
- 3
importer.py View File

@ -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)


+ 2
- 1
zayavka_reader.py View File

@ -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)


Loading…
Cancel
Save

Powered by TurnKey Linux.