Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-ldapserver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uffd
python-ldapserver
Commits
ef49012d
Commit
ef49012d
authored
3 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up wildcard imports in directory.py
parent
73b4b32b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#7059
passed
3 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ldapserver/directory.py
+26
-26
26 additions, 26 deletions
src/ldapserver/directory.py
with
26 additions
and
26 deletions
src/ldapserver/directory.py
+
26
−
26
View file @
ef49012d
from
.util
import
encode_attribute
,
AttributeDict
from
.dn
import
DN
from
.
ldap
import
*
from
.
import
ldap
class
BaseDirectory
:
'''
Base class for LDAP directories
'''
...
...
@@ -34,15 +34,15 @@ class FilterMixin:
def
search_filter
(
self
,
expr
):
'''
'''
if
isinstance
(
expr
,
FilterAnd
):
if
isinstance
(
expr
,
ldap
.
FilterAnd
):
return
self
.
filter_and
(
*
[
self
.
search_filter
(
subexpr
)
for
subexpr
in
expr
.
filters
])
elif
isinstance
(
expr
,
FilterOr
):
elif
isinstance
(
expr
,
ldap
.
FilterOr
):
return
self
.
filter_or
(
*
[
self
.
search_filter
(
subexpr
)
for
subexpr
in
expr
.
filters
])
elif
isinstance
(
expr
,
FilterNot
):
elif
isinstance
(
expr
,
ldap
.
FilterNot
):
return
self
.
filter_not
(
self
.
search_filter
(
expr
.
filter
))
elif
isinstance
(
expr
,
FilterEqual
):
elif
isinstance
(
expr
,
ldap
.
FilterEqual
):
return
self
.
filter_equal
(
expr
.
attribute
.
lower
(),
expr
.
value
)
elif
isinstance
(
expr
,
FilterPresent
):
elif
isinstance
(
expr
,
ldap
.
FilterPresent
):
return
self
.
filter_present
(
expr
.
attribute
.
lower
())
else
:
return
False
...
...
@@ -122,33 +122,33 @@ class SimpleFilterMixin(FilterMixin):
def
filter_present
(
self
,
attribute
):
if
attribute
in
[
'
objectclass
'
,
'
structuralobjectclass
'
,
'
subschemasubentry
'
]:
return
True
return
FilterPresent
(
attribute
)
return
ldap
.
FilterPresent
(
attribute
)
def
filter_equal
(
self
,
attribute
,
value
):
if
attribute
==
'
objectclass
'
:
return
value
.
lower
()
in
[
s
.
lower
()
for
s
in
self
.
objectclasses
]
elif
attribute
==
'
structuralobjectclass
'
:
return
value
.
lower
()
==
self
.
structuralobjectclass
.
lower
()
return
FilterEqual
(
attribute
,
value
)
return
ldap
.
FilterEqual
(
attribute
,
value
)
def
_filter_and
(
self
,
*
subresults
):
return
FilterAnd
(
subresults
)
return
ldap
.
FilterAnd
(
subresults
)
def
_filter_or
(
self
,
*
subresults
):
return
FilterOr
(
subresults
)
return
ldap
.
FilterOr
(
subresults
)
def
_filter_not
(
self
,
subresult
):
return
FilterNot
(
subresult
)
return
ldap
.
FilterNot
(
subresult
)
def
filter_dn
(
self
,
base
,
scope
):
base
=
DN
(
base
)
if
scope
==
SearchScope
.
baseObject
:
if
scope
==
ldap
.
SearchScope
.
baseObject
:
if
base
[
1
:]
!=
self
.
dn_base
or
len
(
base
[
0
])
!=
1
or
base
[
0
][
0
].
attribute
!=
self
.
rdn_attr
:
return
False
return
self
.
filter_equal
(
self
.
rdn_attr
,
base
[
0
][
0
].
value
)
elif
scope
==
SearchScope
.
singleLevel
:
elif
scope
==
ldap
.
SearchScope
.
singleLevel
:
return
base
==
self
.
dn_base
elif
scope
==
SearchScope
.
wholeSubtree
:
elif
scope
==
ldap
.
SearchScope
.
wholeSubtree
:
if
self
.
dn_base
.
in_subtree_of
(
base
):
return
True
if
base
[
1
:]
!=
self
.
dn_base
or
len
(
base
[
0
])
!=
1
or
base
[
0
][
0
].
attribute
!=
self
.
rdn_attr
:
...
...
@@ -159,9 +159,9 @@ class SimpleFilterMixin(FilterMixin):
class
RootDSE
(
BaseDirectory
,
AttributeDict
):
def
search
(
self
,
baseobj
,
scope
,
filter
):
if
baseobj
or
scope
!=
SearchScope
.
baseObject
:
if
baseobj
or
scope
!=
ldap
.
SearchScope
.
baseObject
:
return
[]
if
not
isinstance
(
filter
,
FilterPresent
)
or
filter
.
attribute
.
lower
()
!=
'
objectclass
'
:
if
not
isinstance
(
filter
,
ldap
.
FilterPresent
)
or
filter
.
attribute
.
lower
()
!=
'
objectclass
'
:
return
[]
attrs
=
{}
for
name
,
values
in
self
.
items
():
...
...
@@ -195,9 +195,9 @@ class Subschema(BaseDirectory, AttributeDict):
self
[
'
attributeTypes
'
]
=
list
(
attributetypes
)
def
search
(
self
,
baseobj
,
scope
,
filter
):
if
DN
(
baseobj
)
!=
self
.
dn
or
scope
!=
SearchScope
.
baseObject
:
if
DN
(
baseobj
)
!=
self
.
dn
or
scope
!=
ldap
.
SearchScope
.
baseObject
:
return
[]
if
not
isinstance
(
filter
,
FilterEqual
):
if
not
isinstance
(
filter
,
ldap
.
FilterEqual
):
return
[]
if
filter
.
attribute
.
lower
()
!=
'
objectclass
'
or
filter
.
value
.
lower
()
!=
b
'
subschema
'
:
return
[]
...
...
@@ -209,21 +209,21 @@ def eval_ldap_filter(obj, expr):
return
True
elif
expr
is
False
:
return
False
elif
isinstance
(
expr
,
FilterAnd
):
elif
isinstance
(
expr
,
ldap
.
FilterAnd
):
for
subexpr
in
expr
.
filters
:
if
not
eval_ldap_filter
(
obj
,
subexpr
):
return
False
return
True
elif
isinstance
(
expr
,
FilterOr
):
elif
isinstance
(
expr
,
ldap
.
FilterOr
):
for
subexpr
in
expr
.
filters
:
if
eval_ldap_filter
(
obj
,
subexpr
):
return
True
return
False
elif
isinstance
(
expr
,
FilterNot
):
elif
isinstance
(
expr
,
ldap
.
FilterNot
):
return
not
eval_ldap_filter
(
obj
,
expr
.
filter
)
elif
isinstance
(
expr
,
FilterEqual
):
elif
isinstance
(
expr
,
ldap
.
FilterEqual
):
return
expr
.
value
in
obj
.
get
(
expr
.
attribute
,
[])
elif
isinstance
(
expr
,
FilterPresent
):
elif
isinstance
(
expr
,
ldap
.
FilterPresent
):
return
bool
(
obj
.
get
(
expr
.
attribute
,
[]))
else
:
return
False
...
...
@@ -241,13 +241,13 @@ class StaticDirectory(BaseDirectory):
def
search
(
self
,
baseobj
,
scope
,
filter
):
baseobj
=
DN
(
baseobj
)
for
dn
,
attributes
in
self
.
objects
.
items
():
if
scope
==
SearchScope
.
baseObject
:
if
scope
==
ldap
.
SearchScope
.
baseObject
:
if
baseobj
!=
dn
:
continue
elif
scope
==
SearchScope
.
singleLevel
:
elif
scope
==
ldap
.
SearchScope
.
singleLevel
:
if
not
dn
.
is_direct_child_of
(
baseobj
):
continue
elif
scope
==
SearchScope
.
wholeSubtree
:
elif
scope
==
ldap
.
SearchScope
.
wholeSubtree
:
if
not
dn
.
in_subtree_of
(
baseobj
):
continue
else
:
...
...
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