Fix listing unowned profile and fallback

This commit is contained in:
Theodor S. Midtlien
2026-09-21 15:56:06 +02:00
parent f8944699dd
commit e5c1b21fd3
+17 -13
View File
@@ -162,21 +162,25 @@ func printProfiles(tw *tabwriter.Writer, header []string, profiles []*proto.Prof
row = append(row, profilemanager.ID(profile.Id).ShortID()) row = append(row, profilemanager.ID(profile.Id).ShortID())
} }
row = append(row, profilemanager.StripCtrlChars(profile.Name), marker) row = append(row, profilemanager.StripCtrlChars(profile.Name), marker)
if profileListShowOwner { if !profileListShowOwner {
// An unowned profile is reachable by a privileged caller alone, so fmt.Fprintln(tw, strings.Join(row, "\t"))
// say so rather than leaving the column blank. continue
owner := "unowned" }
if len(profile.Owners) > 0 {
owner = profilemanager.StripCtrlChars(profile.Owners[0]) var owner string
if _, exists := ownerCache[owner]; !exists { if len(profile.Owners) > 0 {
ownerUsername, err := resolveOwnerUsername(owner) owner = profilemanager.StripCtrlChars(profile.Owners[0])
if err != nil { if _, exists := ownerCache[owner]; !exists {
return err ownerUsername, err := resolveOwnerUsername(owner)
} if err != nil {
ownerCache[owner] = ownerUsername // Lookup fail and we fallback to principal: uid:<uid> or sid:<sid>
ownerUsername = owner
} }
ownerCache[owner] = ownerUsername
} }
row = append(row, ownerCache[owner]) row = append(row, profilemanager.StripCtrlChars(ownerCache[owner]))
} else {
row = append(row, "unowned")
} }
fmt.Fprintln(tw, strings.Join(row, "\t")) fmt.Fprintln(tw, strings.Join(row, "\t"))
} }