From 51194cbf42fe718b9d6f7fae905e0905d7db18a8 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 22 Mar 2022 23:49:54 +0100 Subject: [PATCH] outposts/ldap: use backend group num_pk Signed-off-by: Jens Langhammer --- internal/outpost/ldap/search/memory/memory.go | 2 +- internal/outpost/ldap/utils.go | 19 +------------------ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/internal/outpost/ldap/search/memory/memory.go b/internal/outpost/ldap/search/memory/memory.go index 1b5142c92..496e40bb7 100644 --- a/internal/outpost/ldap/search/memory/memory.go +++ b/internal/outpost/ldap/search/memory/memory.go @@ -140,7 +140,7 @@ func (ms *MemorySearcher) Search(req *search.Request) (ldap.ServerSearchResult, for _, u := range g.UsersObj { if flags.UserPk == u.Pk { //TODO: Is there a better way to clone this object? - fg := api.NewGroup(g.Pk, g.Name, g.Parent, g.ParentName, []int32{flags.UserPk}, []api.GroupMember{u}) + fg := api.NewGroup(g.Pk, g.NumPk, g.Name, g.Parent, g.ParentName, []int32{flags.UserPk}, []api.GroupMember{u}) fg.SetAttributes(*g.Attributes) fg.SetIsSuperuser(*g.IsSuperuser) groups = append(groups, group.FromAPIGroup(*fg, ms.si)) diff --git a/internal/outpost/ldap/utils.go b/internal/outpost/ldap/utils.go index c791aa5ea..6dbf0723b 100644 --- a/internal/outpost/ldap/utils.go +++ b/internal/outpost/ldap/utils.go @@ -2,9 +2,7 @@ package ldap import ( "fmt" - "math/big" "strconv" - "strings" "goauthentik.io/api/v3" ) @@ -54,20 +52,5 @@ func (pi *ProviderInstance) GetGidNumber(group api.Group) string { return gidNumber } - return strconv.FormatInt(int64(pi.gidStartNumber+pi.GetRIDForGroup(group.Pk)), 10) -} - -func (pi *ProviderInstance) GetRIDForGroup(uid string) int32 { - var i big.Int - i.SetString(strings.Replace(uid, "-", "", -1), 16) - intStr := i.String() - - // Get the last 5 characters/digits of the int-version of the UUID - gid, err := strconv.Atoi(intStr[len(intStr)-5:]) - - if err != nil { - panic(err) - } - - return int32(gid) + return strconv.FormatInt(int64(pi.gidStartNumber+group.NumPk), 10) }