|
@@ -32,21 +32,21 @@ const (
|
|
|
// mapping ranges in containers.
|
|
|
func AddNamespaceRangesUser(name string) (int, int, error) {
|
|
|
if err := addUser(name); err != nil {
|
|
|
- return -1, -1, fmt.Errorf("Error adding user %q: %v", name, err)
|
|
|
+ return -1, -1, fmt.Errorf("error adding user %q: %v", name, err)
|
|
|
}
|
|
|
|
|
|
// Query the system for the created uid and gid pair
|
|
|
out, err := execCmd("id", name)
|
|
|
if err != nil {
|
|
|
- return -1, -1, fmt.Errorf("Error trying to find uid/gid for new user %q: %v", name, err)
|
|
|
+ return -1, -1, fmt.Errorf("error trying to find uid/gid for new user %q: %v", name, err)
|
|
|
}
|
|
|
matches := idOutRegexp.FindStringSubmatch(strings.TrimSpace(string(out)))
|
|
|
if len(matches) != 3 {
|
|
|
- return -1, -1, fmt.Errorf("Can't find uid, gid from `id` output: %q", string(out))
|
|
|
+ return -1, -1, fmt.Errorf("can't find uid, gid from `id` output: %q", string(out))
|
|
|
}
|
|
|
uid, err := strconv.Atoi(matches[1])
|
|
|
if err != nil {
|
|
|
- return -1, -1, fmt.Errorf("Can't convert found uid (%s) to int: %v", matches[1], err)
|
|
|
+ return -1, -1, fmt.Errorf("can't convert found uid (%s) to int: %v", matches[1], err)
|
|
|
}
|
|
|
gid, err := strconv.Atoi(matches[2])
|
|
|
if err != nil {
|
|
@@ -57,7 +57,7 @@ func AddNamespaceRangesUser(name string) (int, int, error) {
|
|
|
// do not get auto-created ranges in subuid/subgid)
|
|
|
|
|
|
if err := createSubordinateRanges(name); err != nil {
|
|
|
- return -1, -1, fmt.Errorf("Couldn't create subordinate ID ranges: %v", err)
|
|
|
+ return -1, -1, fmt.Errorf("couldn't create subordinate ID ranges: %v", err)
|
|
|
}
|
|
|
return uid, gid, nil
|
|
|
}
|
|
@@ -92,33 +92,33 @@ func createSubordinateRanges(name string) error {
|
|
|
// by the distro tooling
|
|
|
ranges, err := parseSubuid(name)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Error while looking for subuid ranges for user %q: %v", name, err)
|
|
|
+ return fmt.Errorf("error while looking for subuid ranges for user %q: %v", name, err)
|
|
|
}
|
|
|
if len(ranges) == 0 {
|
|
|
// no UID ranges; let's create one
|
|
|
startID, err := findNextUIDRange()
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Can't find available subuid range: %v", err)
|
|
|
+ return fmt.Errorf("can't find available subuid range: %v", err)
|
|
|
}
|
|
|
out, err := execCmd("usermod", "-v", fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1), name)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Unable to add subuid range to user: %q; output: %s, err: %v", name, out, err)
|
|
|
+ return fmt.Errorf("unable to add subuid range to user: %q; output: %s, err: %v", name, out, err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ranges, err = parseSubgid(name)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Error while looking for subgid ranges for user %q: %v", name, err)
|
|
|
+ return fmt.Errorf("error while looking for subgid ranges for user %q: %v", name, err)
|
|
|
}
|
|
|
if len(ranges) == 0 {
|
|
|
// no GID ranges; let's create one
|
|
|
startID, err := findNextGIDRange()
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Can't find available subgid range: %v", err)
|
|
|
+ return fmt.Errorf("can't find available subgid range: %v", err)
|
|
|
}
|
|
|
out, err := execCmd("usermod", "-w", fmt.Sprintf("%d-%d", startID, startID+defaultRangeLen-1), name)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("Unable to add subgid range to user: %q; output: %s, err: %v", name, out, err)
|
|
|
+ return fmt.Errorf("unable to add subgid range to user: %q; output: %s, err: %v", name, out, err)
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
@@ -127,7 +127,7 @@ func createSubordinateRanges(name string) error {
|
|
|
func findNextUIDRange() (int, error) {
|
|
|
ranges, err := parseSubuid("ALL")
|
|
|
if err != nil {
|
|
|
- return -1, fmt.Errorf("Couldn't parse all ranges in /etc/subuid file: %v", err)
|
|
|
+ return -1, fmt.Errorf("couldn't parse all ranges in /etc/subuid file: %v", err)
|
|
|
}
|
|
|
sort.Sort(ranges)
|
|
|
return findNextRangeStart(ranges)
|
|
@@ -136,7 +136,7 @@ func findNextUIDRange() (int, error) {
|
|
|
func findNextGIDRange() (int, error) {
|
|
|
ranges, err := parseSubgid("ALL")
|
|
|
if err != nil {
|
|
|
- return -1, fmt.Errorf("Couldn't parse all ranges in /etc/subgid file: %v", err)
|
|
|
+ return -1, fmt.Errorf("couldn't parse all ranges in /etc/subgid file: %v", err)
|
|
|
}
|
|
|
sort.Sort(ranges)
|
|
|
return findNextRangeStart(ranges)
|