Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
id
auth
Commits
ecceb66d
Commit
ecceb66d
authored
Jan 13, 2018
by
ale
Browse files
Use ldaputil.ParseScope
parent
a439f055
Changes
3
Hide whitespace changes
Inline
Side-by-side
server/ldap.go
View file @
ecceb66d
...
...
@@ -20,7 +20,8 @@ type LDAPServiceConfig struct {
// replaced with the username before performing a query.
SearchBase
string
`yaml:"search_base"`
SearchFilter
string
`yaml:"search_filter"`
Scope
string
`yaml:"scope"`
ScopeStr
string
`yaml:"scope"`
scope
int
// Attrs tells us which LDAP attributes to query to find user
// attributes. It is encoded as a {user_attribute:
...
...
@@ -38,8 +39,13 @@ func (c *LDAPServiceConfig) Valid() error {
if
c
.
SearchFilter
==
""
{
return
errors
.
New
(
"empty search_filter"
)
}
if
c
.
Scope
!=
"base"
&&
c
.
Scope
!=
"one"
&&
c
.
Scope
!=
"sub"
{
return
errors
.
New
(
"unknown scope"
)
c
.
scope
=
ldap
.
ScopeWholeSubtree
if
c
.
ScopeStr
!=
""
{
s
,
err
:=
ldaputil
.
ParseScope
(
c
.
ScopeStr
)
if
err
!=
nil
{
return
err
}
c
.
scope
=
s
}
return
nil
}
...
...
@@ -70,18 +76,9 @@ func (c *LDAPServiceConfig) compile() error {
func
(
c
*
LDAPServiceConfig
)
searchRequest
(
username
string
)
*
ldap
.
SearchRequest
{
filter
:=
strings
.
Replace
(
c
.
SearchFilter
,
"%s"
,
ldap
.
EscapeFilter
(
username
),
-
1
)
var
scope
int
switch
c
.
Scope
{
case
"base"
:
scope
=
ldap
.
ScopeBaseObject
case
"one"
:
scope
=
ldap
.
ScopeSingleLevel
case
"sub"
:
scope
=
ldap
.
ScopeWholeSubtree
}
return
ldap
.
NewSearchRequest
(
c
.
SearchBase
,
scope
,
c
.
scope
,
ldap
.
NeverDerefAliases
,
0
,
0
,
...
...
vendor/git.autistici.org/ai3/go-common/ldap/parse.go
0 → 100644
View file @
ecceb66d
package
ldaputil
import
(
"fmt"
"gopkg.in/ldap.v2"
)
func
ParseScope
(
s
string
)
(
int
,
error
)
{
switch
s
{
case
"base"
:
return
ldap
.
ScopeBaseObject
,
nil
case
"one"
:
return
ldap
.
ScopeSingleLevel
,
nil
case
"sub"
:
return
ldap
.
ScopeWholeSubtree
,
nil
default
:
return
0
,
fmt
.
Errorf
(
"unknown LDAP scope '%s'"
,
s
)
}
}
vendor/vendor.json
View file @
ecceb66d
...
...
@@ -15,10 +15,10 @@
"revisionTime"
:
"2018-01-11T08:21:54Z"
},
{
"checksumSHA1"
:
"
jnfq/QeWcZCebhGuJ+t8nrd8POY
="
,
"checksumSHA1"
:
"
iHObDrZa0HlyzdelqAaGfKNzpiM
="
,
"path"
:
"git.autistici.org/ai3/go-common/ldap"
,
"revision"
:
"
3e38f41af368c36cd5d6642abcf1460cf4c65e78
"
,
"revisionTime"
:
"2018-01-1
1
T0
8:21:54
Z"
"revision"
:
"
a65293114a1adbb45d047a8f9014a307ec0d9051
"
,
"revisionTime"
:
"2018-01-1
2
T0
9:10:27
Z"
},
{
"checksumSHA1"
:
"z1034Bd8fOSLvtOP3VLf65YOQyA="
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment