Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
python
Commits
c69fb372
Commit
c69fb372
authored
6 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Use fast ldap search
parent
53f1ddf9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin/check-home-permissions.py
+16
-12
16 additions, 12 deletions
bin/check-home-permissions.py
lib/isg/dphysldap.py
+19
-0
19 additions, 0 deletions
lib/isg/dphysldap.py
with
35 additions
and
12 deletions
bin/check-home-permissions.py
+
16
−
12
View file @
c69fb372
...
...
@@ -66,28 +66,32 @@ class Home(object):
def
search_ldap
():
ldap
=
dphysldap
.
Ldap
()
ldap_users
=
dphysldap
.
Users
(
ldap
,
[
'
uid
'
,
'
uidNumber
'
,
'
gidNumber
'
,
'
homeDirectory
'
,
'
blocked
'
])
entries
=
dphysldap
.
Entries
(
ldap
,
[
'
cn
'
,
'
nisMapEntry
'
])
people
=
'
ou=people,dc=phys,dc=ethz,dc=ch
'
auto_home
=
'
nisMapName=auto.home,ou=automount,dc=phys,dc=ethz,dc=ch
'
ldap_users
.
search
(
'
*
'
)
ldap
.
search
(
'
(objectClass=posixAccount)
'
,
search_base
=
people
,
attributes
=
[
'
uid
'
,
'
blocked
'
,
'
homeDirectory
'
])
ldap_users
=
ldap
.
response
for
user
in
ldap_users
:
user_attrs
=
{}
user_attrs
[
'
homeDirectory
'
]
=
user
[
'
homeDirectory
'
]
[
0
]
if
user
[
'
blocked
'
]:
user_attrs
[
'
blocked
'
]
=
user
[
'
blocked
'
]
[
0
]
user_attrs
[
'
homeDirectory
'
]
=
user
[
'
attributes
'
][
'
homeDirectory
'
]
if
user
[
'
attributes
'
][
'
blocked
'
]:
user_attrs
[
'
blocked
'
]
=
user
[
'
attributes
'
][
'
blocked
'
]
else
:
no_blocked
.
append
(
user
[
'
uid
'
][
0
])
no_blocked
.
append
(
user
[
'
attributes
'
][
'
uid
'
][
0
])
user_attrs
[
'
blocked
'
]
=
'
no
'
users
[
user
[
'
uid
'
][
0
]]
=
user_attrs
users
[
user
[
'
attributes
'
][
'
uid
'
][
0
]]
=
user_attrs
entries
.
search
(
'
cn: *, nisMapEntry: phd-home*
'
,
[
'
nisObject
'
],
base
=
auto_home
)
ldap
.
search
(
'
(&(objectClass=nisObject)(cn=*)(nisMapEntry=phd-home*))
'
,
search_base
=
auto_home
,
attributes
=
[
'
cn
'
,
'
nisMapEntry
'
])
entries
=
ldap
.
response
for
entry
in
entries
:
nis_homes
[
entry
[
'
cn
'
][
0
]]
=
entry
[
'
nisMapEntry
'
]
[
0
]
nis_homes
[
entry
[
'
attributes
'
][
'
cn
'
][
0
]]
=
entry
[
'
attributes
'
][
'
nisMapEntry
'
]
entries
.
search
(
'
cn: *, nisMapEntry: != phd-home*
'
,
[
'
nisObject
'
],
base
=
auto_home
)
ldap
.
search
(
'
(&(objectClass=nisObject)(cn=*)(!(nisMapEntry=phd-home*)))
'
,
search_base
=
auto_home
,
attributes
=
[
'
cn
'
,
'
nisMapEntry
'
])
entries
=
ldap
.
response
for
entry
in
entries
:
nis_shares
[
entry
[
'
cn
'
][
0
]]
=
entry
[
'
nisMapEntry
'
]
[
0
]
nis_shares
[
entry
[
'
attributes
'
][
'
cn
'
][
0
]]
=
entry
[
'
attributes
'
][
'
nisMapEntry
'
]
def
check_homes
(
top
):
...
...
This diff is collapsed.
Click to expand it.
lib/isg/dphysldap.py
+
19
−
0
View file @
c69fb372
...
...
@@ -241,6 +241,25 @@ class Ldap(object):
entries
=
self
.
get_entries
(
obj
=
self
.
obj_group
,
query
=
query
,
attributes
=
attributes
)
return
[
Group
(
e
)
for
e
in
entries
]
def
search
(
self
,
search_filter
,
search_base
=
None
,
search_scope
=
ldap3
.
SUBTREE
,
attributes
=
[
ldap3
.
ALL_ATTRIBUTES
,
ldap3
.
ALL_OPERATIONAL_ATTRIBUTES
]):
"""
LDAP search operation
"""
if
not
search_base
:
search_base
=
self
.
base
response
=
self
.
connection
.
search
(
search_base
,
search_filter
,
search_scope
=
search_scope
,
attributes
=
attributes
)
return
response
@property
def
response
(
self
):
"""
Get search operation response
"""
return
self
.
connection
.
response
class
Entries
(
list
):
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment