Skip to content

Commit

Permalink
sdk/java: fix guid update (#4299)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangyoupeng authored Dec 29, 2023
1 parent 4f4aca7 commit 5ecf33a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
52 changes: 32 additions & 20 deletions sdk/java/libjfs/guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (m *mapping) lookupUser(name string) uint32 {
id = m.genGuid(name)
}
}
m.usernames[name] = id
m.userIDs[id] = name
logger.Debugf("update user to %s:%d by lookup user", name, id)
m.updateUser(name, id)
return id
}

Expand All @@ -113,8 +113,8 @@ func (m *mapping) lookupGroup(name string) uint32 {
id = uint32(id_)
}
}
m.groups[name] = id
m.groupIDs[id] = name
logger.Debugf("update group to %s:%d by lookup group", name, id)
m.updateGroup(name, id)
return 0
}

Expand All @@ -135,8 +135,8 @@ func (m *mapping) lookupUserID(id uint32) string {
if len(name) > 49 {
name = name[:49]
}
m.usernames[name] = id
m.userIDs[id] = name
logger.Debugf("update user to %s:%d by lookup user id", name, id)
m.updateUser(name, id)
return name
}

Expand All @@ -157,8 +157,8 @@ func (m *mapping) lookupGroupID(id uint32) string {
if len(name) > 49 {
name = name[:49]
}
m.groups[name] = id
m.groupIDs[id] = name
logger.Debugf("update group to %s:%d by lookup group id", name, id)
m.updateGroup(name, id)
return name
}

Expand All @@ -167,19 +167,31 @@ func (m *mapping) update(uids []pwent, gids []pwent, local bool) {
defer m.Unlock()
m.local = local
for _, u := range uids {
oldId := m.usernames[u.name]
oldName := m.userIDs[u.id]
delete(m.userIDs, oldId)
delete(m.usernames, oldName)
m.usernames[u.name] = u.id
m.userIDs[u.id] = u.name
m.updateUser(u.name, u.id)
}
for _, g := range gids {
oldId := m.groups[g.name]
oldName := m.groupIDs[g.id]
delete(m.groupIDs, oldId)
delete(m.groups, oldName)
m.groups[g.name] = g.id
m.groupIDs[g.id] = g.name
m.updateGroup(g.name, g.id)
}
logger.Debugf("users:\n%+v", m.usernames)
logger.Debugf("userids:\n%+v", m.userIDs)
logger.Debugf("groups:\n%+v", m.groups)
logger.Debugf("gorupids:\n%+v", m.groupIDs)
}

func (m *mapping) updateUser(name string, id uint32) {
oldId := m.usernames[name]
oldName := m.userIDs[id]
delete(m.userIDs, oldId)
delete(m.usernames, oldName)
m.usernames[name] = id
m.userIDs[id] = name
}

func (m *mapping) updateGroup(name string, id uint32) {
oldId := m.groups[name]
oldName := m.groupIDs[id]
delete(m.groupIDs, oldId)
delete(m.groups, oldName)
m.groups[name] = id
m.groupIDs[id] = name
}
5 changes: 5 additions & 0 deletions sdk/java/libjfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ func jfs_update_uid_grouping(h uintptr, uidstr *C.char, grouping *C.char) {
}
}
logger.Debugf("Update groups of %s to %s", w.user, strings.Join(groups, ","))
var buffer bytes.Buffer
for _, g := range gids {
buffer.WriteString(fmt.Sprintf("\t%v:%v\n", g.name, g.id))
}
logger.Debugf("Update gids mapping\n %s", buffer.String())
}
w.m.update(uids, gids, false)

Expand Down

0 comments on commit 5ecf33a

Please sign in to comment.