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
ai3
accountserver
Commits
eb8a0359
Commit
eb8a0359
authored
Nov 17, 2018
by
ale
Browse files
Move some code to the 'util' section
parent
5806a8b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/model.go
View file @
eb8a0359
...
...
@@ -606,35 +606,3 @@ func (tx *backendTX) CanAccessResource(_ context.Context, username string, rsrc
return
owner
==
username
}
}
// Find the uid= in the DN. Return an empty string on failure.
func
ownerFromDN
(
dn
string
)
string
{
parsed
,
err
:=
ldap
.
ParseDN
(
dn
)
if
err
!=
nil
{
return
""
}
// Start looking for uid from the right. The strict
// greater-than clause ignores the first RDN (so that the
// owner of a user is not itself).
for
i
:=
len
(
parsed
.
RDNs
)
-
1
;
i
>
0
;
i
--
{
attr
:=
parsed
.
RDNs
[
i
]
.
Attributes
[
0
]
if
attr
.
Type
==
"uid"
{
return
attr
.
Value
}
}
return
""
}
const
oneDay
=
86400
func
encodeShadowTimestamp
(
t
time
.
Time
)
string
{
d
:=
t
.
UTC
()
.
Unix
()
/
oneDay
return
strconv
.
FormatInt
(
d
,
10
)
}
func
decodeShadowTimestamp
(
s
string
)
(
t
time
.
Time
)
{
if
i
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
64
);
err
==
nil
{
t
=
time
.
Unix
(
i
*
oneDay
,
0
)
.
UTC
()
}
return
}
backend/resources.go
View file @
eb8a0359
...
...
@@ -454,10 +454,6 @@ func (h *databaseResourceHandler) SearchQuery() *queryTemplate {
}
}
func
joinDN
(
parts
...
string
)
string
{
return
strings
.
Join
(
parts
,
","
)
}
func
newDefaultResourceRegistry
(
baseDN
string
)
*
resourceRegistry
{
reg
:=
newResourceRegistry
()
reg
.
register
(
as
.
ResourceTypeEmail
,
&
emailResourceHandler
{
baseDN
:
baseDN
})
...
...
backend/util.go
View file @
eb8a0359
...
...
@@ -2,6 +2,9 @@ package backend
import
(
"os"
"strconv"
"strings"
"time"
"gopkg.in/ldap.v2"
)
...
...
@@ -78,3 +81,42 @@ func isObjectClass(entry *ldap.Entry, class string) bool {
}
return
false
}
// Join some RDNs.
func
joinDN
(
parts
...
string
)
string
{
return
strings
.
Join
(
parts
,
","
)
}
// Find the uid= in the DN. Return an empty string on failure.
func
ownerFromDN
(
dn
string
)
string
{
parsed
,
err
:=
ldap
.
ParseDN
(
dn
)
if
err
!=
nil
{
return
""
}
// Start looking for uid from the right. The strict
// greater-than clause ignores the first RDN (so that the
// owner of a user is not itself).
for
i
:=
len
(
parsed
.
RDNs
)
-
1
;
i
>
0
;
i
--
{
attr
:=
parsed
.
RDNs
[
i
]
.
Attributes
[
0
]
if
attr
.
Type
==
"uid"
{
return
attr
.
Value
}
}
return
""
}
// Functions to encode/decode shadow(5) timestamps (number of days
// since the epoch).
const
oneDay
=
86400
func
encodeShadowTimestamp
(
t
time
.
Time
)
string
{
d
:=
t
.
UTC
()
.
Unix
()
/
oneDay
return
strconv
.
FormatInt
(
d
,
10
)
}
func
decodeShadowTimestamp
(
s
string
)
(
t
time
.
Time
)
{
if
i
,
err
:=
strconv
.
ParseInt
(
s
,
10
,
64
);
err
==
nil
{
t
=
time
.
Unix
(
i
*
oneDay
,
0
)
.
UTC
()
}
return
}
Write
Preview
Supports
Markdown
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