Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Luca (strifel)
uffd
Commits
ec4849bf
Verified
Commit
ec4849bf
authored
4 years ago
by
nd
Browse files
Options
Downloads
Patches
Plain Diff
do not use ldap3 rdns escaping
parent
6e7947d3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
uffd/ldap/__init__.py
+1
-1
1 addition, 1 deletion
uffd/ldap/__init__.py
uffd/ldap/ldap.py
+18
-5
18 additions, 5 deletions
uffd/ldap/ldap.py
uffd/user/models.py
+1
-6
1 addition, 6 deletions
uffd/user/models.py
with
20 additions
and
12 deletions
uffd/ldap/__init__.py
+
1
−
1
View file @
ec4849bf
from
.ldap
import
bp
as
ldap_bp
from
.ldap
import
get_conn
,
user_conn
,
escape_filter_chars
,
uid_to_dn
,
loginname_to_dn
,
get_next_uid
from
.ldap
import
get_conn
,
user_conn
,
escape_filter_chars
,
uid_to_dn
,
loginname_to_dn
,
get_next_uid
,
loginname_is_safe
bp
=
[
ldap_bp
]
This diff is collapsed.
Click to expand it.
uffd/ldap/ldap.py
+
18
−
5
View file @
ec4849bf
import
string
from
flask
import
Blueprint
,
current_app
from
ldap3.utils.conv
import
escape_filter_chars
from
ldap3.utils.dn
import
escape_rdn
from
ldap3.core.exceptions
import
LDAPBindError
from
ldap3
import
Server
,
Connection
,
ALL
,
ALL_ATTRIBUTES
,
ALL_OPERATIONAL_ATTRIBUTES
...
...
@@ -17,9 +18,11 @@ def fix_connection(conn):
def
service_conn
():
server
=
Server
(
current_app
.
config
[
"
LDAP_SERVICE_URL
"
],
get_info
=
ALL
)
return
Connection
(
server
,
current_app
.
config
[
"
LDAP_SERVICE_BIND_DN
"
],
current_app
.
config
[
"
LDAP_SERVICE_BIND_PASSWORD
"
],
auto_bind
=
True
)
return
fix_connection
(
Connection
(
server
,
current_app
.
config
[
"
LDAP_SERVICE_BIND_DN
"
],
current_app
.
config
[
"
LDAP_SERVICE_BIND_PASSWORD
"
],
auto_bind
=
True
)
)
def
user_conn
(
loginname
,
password
):
if
not
loginname_is_safe
(
loginname
):
return
False
server
=
Server
(
current_app
.
config
[
"
LDAP_SERVICE_URL
"
],
get_info
=
ALL
)
try
:
return
fix_connection
(
Connection
(
server
,
loginname_to_dn
(
loginname
),
password
,
auto_bind
=
True
))
...
...
@@ -27,8 +30,7 @@ def user_conn(loginname, password):
return
False
def
get_conn
():
conn
=
service_conn
()
return
fix_connection
(
conn
)
return
service_conn
()
def
uid_to_dn
(
uid
):
conn
=
get_conn
()
...
...
@@ -38,7 +40,18 @@ def uid_to_dn(uid):
return
conn
.
entries
[
0
].
entry_dn
def
loginname_to_dn
(
loginname
):
return
'
uid={},{}
'
.
format
(
escape_rdn
(
loginname
),
current_app
.
config
[
"
LDAP_BASE_USER
"
])
if
loginname_is_safe
(
loginname
):
return
'
uid={},{}
'
.
format
(
loginname
,
current_app
.
config
[
"
LDAP_BASE_USER
"
])
else
:
raise
Exception
(
'
unsafe login name
'
)
def
loginname_is_safe
(
value
):
if
len
(
value
)
>
32
or
len
(
value
)
<
1
:
return
False
for
char
in
value
:
if
not
char
in
string
.
ascii_lowercase
+
string
.
digits
+
'
_
'
:
return
False
return
True
def
get_next_uid
():
conn
=
get_conn
()
...
...
This diff is collapsed.
Click to expand it.
uffd/user/models.py
+
1
−
6
View file @
ec4849bf
import
string
from
ldap3
import
MODIFY_REPLACE
,
HASHED_SALTED_SHA512
from
ldap3.utils.hashed
import
hashed
from
flask
import
current_app
...
...
@@ -90,11 +88,8 @@ class User():
return
False
def
set_loginname
(
self
,
value
):
if
len
(
value
)
>
32
or
len
(
value
)
<
1
:
if
not
ldap
.
loginname_is_safe
(
value
):
return
False
for
char
in
value
:
if
not
char
in
string
.
ascii_lowercase
+
string
.
digits
+
'
_
'
:
return
False
self
.
loginname
=
value
return
True
...
...
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