-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
41 lines (33 loc) · 1.03 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ldap
import (
"fmt"
"strconv"
"time"
)
func parseObjectEnabled(userAccountControl string) (bool, error) {
raw, err := strconv.ParseInt(userAccountControl, 10, 32)
if err != nil {
return false, err
}
// https://docs.microsoft.com/en-us/windows/win32/adschema/a-useraccountcontrol
// 2 (0x2) - ACCOUNTDISABLE
// The user account is disabled.
if raw&2 != 0 {
return false, nil
}
return true, nil
}
// convertAccountExpires converts the time.Time to the accountExpires value.
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-adls/acdfe32c-ce53-4073-b9b4-40d1130038dc
func convertAccountExpires(target *time.Time) string {
if target == nil {
return fmt.Sprintf("%d", accountExpiresNever)
}
remaining := target.Sub(accountExpiresBase)
/*
This value represents the number of 100-nanosecond intervals since January 1, 1601 (UTC).
A value of 0 or 0x7FFFFFFFFFFFFFFF (9223372036854775807) indicates that the account never expires.
*/
ns := remaining.Nanoseconds() / 100
return fmt.Sprintf("%d", ns)
}