Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd-ldapd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
uffd-ldapd
Commits
df9a4966
Commit
df9a4966
authored
3 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Add support for postfix objects
parent
ea9aa850
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config.json
+2
-1
2 additions, 1 deletion
config.json
server.py
+57
-0
57 additions, 0 deletions
server.py
with
59 additions
and
1 deletion
config.json
+
2
−
1
View file @
df9a4966
...
...
@@ -4,5 +4,6 @@
"api_baseurl"
:
"http://localhost:5000/api/v1"
,
"api_key"
:
"secretapikey"
,
"listen_addr"
:
"127.0.0.1:3389"
,
"cache_ttl"
:
60
"cache_ttl"
:
60
,
"enable_mail"
:
false
}
This diff is collapsed.
Click to expand it.
server.py
+
57
−
0
View file @
df9a4966
...
...
@@ -145,6 +145,51 @@ class GroupDirectory(SimpleFilterMixin, BaseDirectory):
value
=
str
(
DN
.
from_str
(
value
.
decode
())).
encode
()
return
super
().
filter_equal
(
attribute
,
value
)
class
MailDirectory
(
SimpleFilterMixin
,
BaseDirectory
):
def
__init__
(
self
,
api
,
dn_base
):
self
.
api
=
api
self
.
rdn_attr
=
'
uid
'
self
.
dn_base
=
DN
(
'
ou=postfix
'
)
+
DN
(
dn_base
)
self
.
structuralobjectclass
=
b
'
postfixVirtual
'
self
.
objectclasses
=
[
b
'
top
'
,
b
'
postfixVirtual
'
]
def
generate_result
(
self
,
mail
):
attributes
=
CaseInsensitiveDict
(
structuralObjectClass
=
[
self
.
structuralobjectclass
],
objectClass
=
self
.
objectclasses
,
uid
=
[
encode_attribute
(
mail
[
'
name
'
])],
mailacceptinggeneralid
=
[
encode_attribute
(
address
)
for
address
in
mail
[
'
receive_addresses
'
]],
maildrop
=
[
encode_attribute
(
address
)
for
address
in
mail
[
'
destination_addresses
'
]],
)
dn
=
str
(
DN
(
uid
=
mail
[
'
name
'
])
+
self
.
dn_base
)
return
dn
,
attributes
def
get_best_api_param
(
self
,
expr
):
if
isinstance
(
expr
,
FilterEqual
)
and
expr
.
attribute
.
lower
()
==
'
uid
'
:
return
'
name
'
,
expr
.
value
elif
isinstance
(
expr
,
FilterEqual
)
and
expr
.
attribute
.
lower
()
==
'
mailacceptinggeneralid
'
:
return
'
receive_address
'
,
expr
.
value
elif
isinstance
(
expr
,
FilterEqual
)
and
expr
.
attribute
.
lower
()
==
'
maildrop
'
:
return
'
destination_address
'
,
expr
.
value
if
isinstance
(
expr
,
FilterAnd
):
params
=
dict
([
self
.
get_best_api_param
(
subexpr
)
for
subexpr
in
expr
.
filters
])
for
key
in
[
'
name
'
,
'
receive_address
'
,
'
destination_address
'
]:
if
key
in
params
:
return
key
,
params
[
key
]
return
None
,
None
def
search_fetch
(
self
,
expr
):
if
expr
is
False
:
return
kwargs
=
{}
key
,
value
=
self
.
get_best_api_param
(
expr
)
if
key
is
not
None
:
kwargs
[
key
]
=
value
for
mail
in
self
.
api
.
get
(
'
getmails
'
,
**
kwargs
):
dn
,
obj
=
self
.
generate_result
(
mail
)
if
eval_ldap_filter
(
obj
,
expr
):
yield
dn
,
obj
class
RequestHandler
(
SimpleLDAPRequestHandler
):
subschema
=
RFC2307BIS_SUBSCHEMA
...
...
@@ -154,6 +199,7 @@ class RequestHandler(SimpleLDAPRequestHandler):
static_directory
=
None
user_directory
=
None
group_directory
=
None
mail_directory
=
None
bind_dn
=
None
bind_password
=
None
...
...
@@ -198,12 +244,15 @@ class RequestHandler(SimpleLDAPRequestHandler):
yield
from
self
.
static_directory
.
search
(
baseobj
,
scope
,
filter
)
yield
from
self
.
user_directory
.
search
(
baseobj
,
scope
,
filter
)
yield
from
self
.
group_directory
.
search
(
baseobj
,
scope
,
filter
)
if
self
.
mail_directory
is
not
None
:
yield
from
self
.
mail_directory
.
search
(
baseobj
,
scope
,
filter
)
def
main
(
config
):
dn_base
=
DN
.
from_str
(
config
[
'
dn_base
'
])
api
=
UffdAPI
(
config
[
'
api_baseurl
'
],
config
[
'
api_key
'
],
config
.
get
(
'
cache_ttl
'
,
60
))
user_directory
=
UserDirectory
(
api
,
dn_base
)
group_directory
=
GroupDirectory
(
api
,
dn_base
)
mail_directory
=
MailDirectory
(
api
,
dn_base
)
static_directory
=
StaticDirectory
()
base_attrs
=
{
...
...
@@ -223,6 +272,12 @@ def main(config):
'
objectClass
'
:
[
'
top
'
,
'
organizationalUnit
'
],
'
structuralObjectClass
'
:
[
'
organizationalUnit
'
],
})
if
config
.
get
(
'
enable_mail
'
):
static_directory
.
add
(
DN
(
'
ou=postfix
'
)
+
dn_base
,
{
'
ou
'
:
[
'
postfix
'
],
'
objectClass
'
:
[
'
top
'
,
'
organizationalUnit
'
],
'
structuralObjectClass
'
:
[
'
organizationalUnit
'
],
})
static_directory
.
add
(
DN
(
'
ou=system
'
)
+
dn_base
,
{
'
ou
'
:
[
'
system
'
],
'
objectClass
'
:
[
'
top
'
,
'
organizationalUnit
'
],
...
...
@@ -244,6 +299,8 @@ def main(config):
CustomRequestHandler
.
static_directory
=
static_directory
CustomRequestHandler
.
user_directory
=
user_directory
CustomRequestHandler
.
group_directory
=
group_directory
if
config
.
get
(
'
enable_mail
'
):
CustomRequestHandler
.
mail_directory
=
mail_directory
if
config
[
'
listen_addr
'
].
startswith
(
'
unix:
'
):
socketserver
.
ThreadingUnixStreamServer
(
config
[
'
listen_addr
'
][
5
:],
CustomRequestHandler
).
serve_forever
()
...
...
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