Skip to content

Commit

Permalink
fix: clean up LDAP retrival
Browse files Browse the repository at this point in the history
  • Loading branch information
alesz committed Nov 6, 2024
1 parent c5486c5 commit bf77d6d
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions osluc.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func searchUser(l *ldap.Conn, cfg map[string]interface{}, username string) bool
0, // Time limit, 0 for no limit
false, // TypesOnly - don't return attribute values, only attribute types
searchFilter, // Search filter
[]string{"dn", "cn", "lastLogon", "accountexpires", "samaccountname", "lastlogontimestamp"}, // Attributes to retrieve //
[]string{"dn", "cn", "samaccountname", "lastlogontimestamp"}, // Attributes to retrieve
nil,
)

Expand All @@ -211,32 +211,18 @@ func searchUser(l *ldap.Conn, cfg map[string]interface{}, username string) bool

for _, entry := range result.Entries {

lastLogon, err := FileTimeToGoTime(entry.GetAttributeValue("lastLogon"))
if err != nil {
slog.Error("Cannot convert FileTime for lastLogon attribute", "error", err)
}

lastLogonTS, err := FileTimeToGoTime(entry.GetAttributeValue("lastLogonTimestamp"))
if err != nil {
slog.Error("Cannot convert FileTime for lastLogonTimestamp attribute", "error", err)
}

accountExpires, err := FileTimeToGoTime(entry.GetAttributeValue("accountExpires"))
if err != nil {
slog.Error("Cannot convert FileTime for accountExpires attribute", "error", err)
}

now := time.Now()
slog.Debug("Attributes",
"DN", entry.DN,
"CN", entry.GetAttributeValue("cn"),
"sAMAccountName", entry.GetAttributeValue("sAMAccountName"),
"lastLogon", lastLogon,
"lastLogonAgo", fmt.Sprintf("%v days", int(now.Sub(lastLogon).Hours()/24)),
"lastLogonTimestamp", lastLogonTS,
"lastLogonTimestampAgo", fmt.Sprintf("%v days", int(now.Sub(lastLogonTS).Hours()/24)),
"accountExpires", accountExpires,
"accountExpiresAgo", fmt.Sprintf("%v days", int(now.Sub(lastLogonTS).Hours()/24)),
)
}
}
Expand Down

0 comments on commit bf77d6d

Please sign in to comment.