(requiredGID, allowedGroupName string)
| 490 | } |
| 491 | |
| 492 | func ensureGroupIDUnused(requiredGID, allowedGroupName string) error { |
| 493 | existingGroup, err := lookupGroupID(requiredGID) |
| 494 | if err != nil { |
| 495 | var unknownGroupIDError user.UnknownGroupIdError |
| 496 | var unknownGroupError user.UnknownGroupError |
| 497 | if !errors.As(err, &unknownGroupIDError) && !errors.As(err, &unknownGroupError) { |
| 498 | return fmt.Errorf("failed to lookup group id %s -> %w", requiredGID, err) |
| 499 | } |
| 500 | return nil |
| 501 | } |
| 502 | |
| 503 | if existingGroup.Name == allowedGroupName { |
| 504 | return nil |
| 505 | } |
| 506 | |
| 507 | return fmt.Errorf("gid %s is already used by local group %q", requiredGID, existingGroup.Name) |
| 508 | } |
| 509 | |
| 510 | func changeGroupGID(groupName, oldGID, requiredGID string) error { |
| 511 | if err := ensureGroupIDUnused(requiredGID, groupName); err != nil { |
no outgoing calls
no test coverage detected