Skip to content

Commit

Permalink
returns trace.BadParameter error when adding group with invalid name
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktate committed Aug 29, 2024
1 parent ce82959 commit b30f5d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/srv/usermgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func (u *HostUserManagement) createGroupIfNotExist(group string) error {
if trace.IsAlreadyExists(err) {
return nil
}
return trace.Wrap(err)
return trace.Errorf("while creating group %q %w", group, err)
}

// isUnknownGroupError returns whether the error from LookupGroup is an unknown group error.
Expand Down
10 changes: 10 additions & 0 deletions lib/utils/host/hostusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

// man GROUPADD(8), exit codes section
const GroupExistExit = 9
const GroupInvalidArg = 3

// man USERADD(8), exit codes section
const UserExistExit = 9
Expand All @@ -56,6 +57,15 @@ func GroupAdd(groupname string, gid string) (exitCode int, err error) {
if cmd.ProcessState.ExitCode() == GroupExistExit {
return cmd.ProcessState.ExitCode(), trace.AlreadyExists("group already exists")
}

if cmd.ProcessState.ExitCode() == GroupInvalidArg {
errMsg := "bad parameter"
if strings.Contains(string(output), "not a valid group name") {
errMsg = "invalid group name"
}
return cmd.ProcessState.ExitCode(), trace.BadParameter(errMsg)
}

return cmd.ProcessState.ExitCode(), trace.Wrap(err)
}

Expand Down

0 comments on commit b30f5d2

Please sign in to comment.