[sysadmin-bin] Revert "Move imports to the top of the file"
- From: Bartłomiej Piotrowski <bpiotrowski src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Revert "Move imports to the top of the file"
- Date: Fri, 27 Nov 2020 10:15:19 +0000 (UTC)
commit 4adc11f9308819442399b3d3917df43d3413569b
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date: Fri Nov 27 11:15:11 2020 +0100
Revert "Move imports to the top of the file"
This reverts commit b91a0454f1604e8c8d54f20436f375ab7da37ea1.
gnome_ldap_utils.py | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/gnome_ldap_utils.py b/gnome_ldap_utils.py
index 34fedf1..5941ab2 100755
--- a/gnome_ldap_utils.py
+++ b/gnome_ldap_utils.py
@@ -1,12 +1,11 @@
#!/usr/bin/python3
-import sys
-
-import ldap
-
class Gnome_ldap_utils:
def __init__(self, LDAP_GROUP_BASE, LDAP_HOST, LDAP_USER_BASE, LDAP_USER, LDAP_PASSWORD,
LDAP_CA_PATH='/etc/ipa/ca.crt'):
+ import ldap
+ import sys
+
self.LDAP_GROUP_BASE = LDAP_GROUP_BASE
self.LDAP_USER_BASE = LDAP_USER_BASE
self.LDAP_USER = LDAP_USER
@@ -24,6 +23,8 @@ class Gnome_ldap_utils:
sys.exit(1)
def get_group_from_ldap(self, group):
+ import ldap.filter
+
filter = ldap.filter.filter_format('(&(objectClass=groupofnames)(cn=%s))', (group, ))
results = self.conn.search_s(self.LDAP_GROUP_BASE, ldap.SCOPE_SUBTREE, filter, ('member', ))
@@ -41,6 +42,8 @@ class Gnome_ldap_utils:
return members
def get_attributes_from_ldap(self, uid, attr, *attrs):
+ import ldap.filter
+
results = []
filter = ldap.filter.filter_format('(uid=%s)', (uid, ))
@@ -78,19 +81,28 @@ class Gnome_ldap_utils:
return people
def replace_ldap_password(self, userid, password):
+ import ldap
+
replace_password = [(ldap.MOD_REPLACE, 'userPassword', password)]
self.conn.modify_s('uid=%s,%s' % (userid, self.LDAP_USER_BASE), replace_password)
def add_user_to_ldap_group(self, userid, group):
+ import ldap
+
add_members = [(ldap.MOD_ADD, 'member', 'uid=%s,%s' % (userid, self.LDAP_USER_BASE))]
self.conn.modify_s('cn=%s,%s' % (group, self.LDAP_GROUP_BASE), add_members)
def remove_user_from_ldap_group(self, userid, group):
+ import ldap
+
uid_query = "uid={},{}".format(userid, self.LDAP_USER_BASE).encode("utf-8")
remove_members = [(ldap.MOD_DELETE, 'member', uid_query)]
self.conn.modify_s('cn=%s,%s' % (group, self.LDAP_GROUP_BASE), remove_members)
def add_or_update_description(self, userid, comment, add=False, update=False):
+ import sys
+ import ldap
+
if add and not update:
update_comment = [(ldap.MOD_ADD, 'description', comment)]
self.conn.modify_s('uid=%s,%s' % (userid, self.LDAP_USER_BASE), update_comment)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]