outposts/ldap: use backend group num_pk

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-03-22 23:49:54 +01:00
parent 4d5a619cc0
commit 51194cbf42
2 changed files with 2 additions and 19 deletions

View file

@ -140,7 +140,7 @@ func (ms *MemorySearcher) Search(req *search.Request) (ldap.ServerSearchResult,
for _, u := range g.UsersObj { for _, u := range g.UsersObj {
if flags.UserPk == u.Pk { if flags.UserPk == u.Pk {
//TODO: Is there a better way to clone this object? //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.SetAttributes(*g.Attributes)
fg.SetIsSuperuser(*g.IsSuperuser) fg.SetIsSuperuser(*g.IsSuperuser)
groups = append(groups, group.FromAPIGroup(*fg, ms.si)) groups = append(groups, group.FromAPIGroup(*fg, ms.si))

View file

@ -2,9 +2,7 @@ package ldap
import ( import (
"fmt" "fmt"
"math/big"
"strconv" "strconv"
"strings"
"goauthentik.io/api/v3" "goauthentik.io/api/v3"
) )
@ -54,20 +52,5 @@ func (pi *ProviderInstance) GetGidNumber(group api.Group) string {
return gidNumber return gidNumber
} }
return strconv.FormatInt(int64(pi.gidStartNumber+pi.GetRIDForGroup(group.Pk)), 10) return strconv.FormatInt(int64(pi.gidStartNumber+group.NumPk), 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)
} }