Skip to content

Commit

Permalink
commands: Add AddUserSubGroupRange and AddUserSubUserRange
Browse files Browse the repository at this point in the history
To write /etc/sub{g,u}id files.
  • Loading branch information
joebonrichie committed May 28, 2024
1 parent 9ab0f4b commit d3601e8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ func AddGroup(root, groupName string, groupID int) error {
return ChrootExec(root, cmd)
}

// AddUserSubUserRange will write /etc/subuid with a subordinate UID range for a user
func AddUserSubUserRange(root, userName string, rangeMin, rangeMax int) error {
cmd := fmt.Sprintf("/usr/sbin/usermod --add-subuids %d-%d \"%s\"", rangeMin, rangeMax, userName)
return ChrootExec(root, cmd)
}

// AddUserSubUserRange will write /etc/subgid with a subordinate GID range for a user
func AddUserSubGroupRange(root, userName string, rangeMin, rangeMax int) error {
cmd := fmt.Sprintf("/usr/sbin/usermod --add-subgids %d-%d \"%s\"", rangeMin, rangeMax, userName)
return ChrootExec(root, cmd)
}

// AddUser will chroot into the given root and add a user
func AddUser(root, userName, gecos, home, shell string, uid, gid int) error {
cmd := fmt.Sprintf("/usr/sbin/useradd -m -d \"%s\" -s \"%s\" -u %d -g %d \"%s\" -c \"%s\"",
Expand Down

0 comments on commit d3601e8

Please sign in to comment.