-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schema: added non-unique parameter to PasswdUser #985
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -514,6 +514,9 @@ | |
}, | ||
"shell": { | ||
"type": ["string", "null"] | ||
}, | ||
"nonUnique": { | ||
"type": ["boolean", "null"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a similar field to |
||
} | ||
}, | ||
"required": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
package files | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"path/filepath" | ||
|
||
|
@@ -77,6 +78,23 @@ func (s *stage) createPasswd(config types.Config) error { | |
return nil | ||
} | ||
|
||
func userUIDConflict(a types.PasswdUser, list []types.PasswdUser) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something, but I don't think this function is necessary, since |
||
if a.UID == nil { | ||
return nil | ||
} | ||
|
||
for _, b := range list { | ||
if b.UID == nil || a.Name == b.Name { | ||
continue | ||
} | ||
|
||
if uint64(*b.UID) == uint64(*a.UID) && ((*b.NonUnique) == false || (*a.NonUnique) == false) { | ||
return errors.New(fmt.Sprintf("conflicting uid from user: %s with uid: %d", b.Name, *b.UID)) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// createUsers creates the users as described in config.Passwd.Users. | ||
func (s stage) createUsers(config types.Config) error { | ||
if len(config.Passwd.Users) == 0 { | ||
|
@@ -86,6 +104,11 @@ func (s stage) createUsers(config types.Config) error { | |
defer s.Logger.PopPrefix() | ||
|
||
for _, u := range config.Passwd.Users { | ||
if err := userUIDConflict(u, config.Passwd.Users); err != nil { | ||
return fmt.Errorf("failed to create user %q: %v", | ||
u.Name, err) | ||
} | ||
|
||
if err := s.EnsureUser(u); err != nil { | ||
return fmt.Errorf("failed to create user %q: %v", | ||
u.Name, err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,8 @@ func (u Util) EnsureUser(c types.PasswdUser) error { | |
strconv.FormatUint(uint64(*c.UID), 10)) | ||
} | ||
|
||
args = appendIfTrue(args, c.NonUnique, "--non-unique") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a config specifies two users with the same UID, and one of them specifies |
||
|
||
args = appendIfStringSet(args, "--comment", c.Gecos) | ||
args = appendIfStringSet(args, "--gid", c.PrimaryGroup) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name
nonUnique
follows the existing pattern of naming fields afteruseradd
options. But I'm wondering if the name is too unclear in this case, since it doesn't mention UIDs.