go.mod: runc v1.0.1
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
		
							
								
								
									
										92
									
								
								vendor/github.com/opencontainers/runc/libcontainer/user/user.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										92
									
								
								vendor/github.com/opencontainers/runc/libcontainer/user/user.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -2,6 +2,7 @@ package user
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
@@ -55,11 +56,11 @@ type IDMap struct {
 | 
			
		||||
	Count    int64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func parseLine(line string, v ...interface{}) {
 | 
			
		||||
	parseParts(strings.Split(line, ":"), v...)
 | 
			
		||||
func parseLine(line []byte, v ...interface{}) {
 | 
			
		||||
	parseParts(bytes.Split(line, []byte(":")), v...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func parseParts(parts []string, v ...interface{}) {
 | 
			
		||||
func parseParts(parts [][]byte, v ...interface{}) {
 | 
			
		||||
	if len(parts) == 0 {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@@ -75,16 +76,16 @@ func parseParts(parts []string, v ...interface{}) {
 | 
			
		||||
		// This is legit.
 | 
			
		||||
		switch e := v[i].(type) {
 | 
			
		||||
		case *string:
 | 
			
		||||
			*e = p
 | 
			
		||||
			*e = string(p)
 | 
			
		||||
		case *int:
 | 
			
		||||
			// "numbers", with conversion errors ignored because of some misbehaving configuration files.
 | 
			
		||||
			*e, _ = strconv.Atoi(p)
 | 
			
		||||
			*e, _ = strconv.Atoi(string(p))
 | 
			
		||||
		case *int64:
 | 
			
		||||
			*e, _ = strconv.ParseInt(p, 10, 64)
 | 
			
		||||
			*e, _ = strconv.ParseInt(string(p), 10, 64)
 | 
			
		||||
		case *[]string:
 | 
			
		||||
			// Comma-separated lists.
 | 
			
		||||
			if p != "" {
 | 
			
		||||
				*e = strings.Split(p, ",")
 | 
			
		||||
			if len(p) != 0 {
 | 
			
		||||
				*e = strings.Split(string(p), ",")
 | 
			
		||||
			} else {
 | 
			
		||||
				*e = []string{}
 | 
			
		||||
			}
 | 
			
		||||
@@ -128,8 +129,8 @@ func ParsePasswdFilter(r io.Reader, filter func(User) bool) ([]User, error) {
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	for s.Scan() {
 | 
			
		||||
		line := strings.TrimSpace(s.Text())
 | 
			
		||||
		if line == "" {
 | 
			
		||||
		line := bytes.TrimSpace(s.Bytes())
 | 
			
		||||
		if len(line) == 0 {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -179,15 +180,53 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) {
 | 
			
		||||
	if r == nil {
 | 
			
		||||
		return nil, fmt.Errorf("nil source for group-formatted data")
 | 
			
		||||
	}
 | 
			
		||||
	rd := bufio.NewReader(r)
 | 
			
		||||
	out := []Group{}
 | 
			
		||||
 | 
			
		||||
	var (
 | 
			
		||||
		s   = bufio.NewScanner(r)
 | 
			
		||||
		out = []Group{}
 | 
			
		||||
	)
 | 
			
		||||
	// Read the file line-by-line.
 | 
			
		||||
	for {
 | 
			
		||||
		var (
 | 
			
		||||
			isPrefix  bool
 | 
			
		||||
			wholeLine []byte
 | 
			
		||||
			err       error
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
	for s.Scan() {
 | 
			
		||||
		text := s.Text()
 | 
			
		||||
		if text == "" {
 | 
			
		||||
		// Read the next line. We do so in chunks (as much as reader's
 | 
			
		||||
		// buffer is able to keep), check if we read enough columns
 | 
			
		||||
		// already on each step and store final result in wholeLine.
 | 
			
		||||
		for {
 | 
			
		||||
			var line []byte
 | 
			
		||||
			line, isPrefix, err = rd.ReadLine()
 | 
			
		||||
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				// We should return no error if EOF is reached
 | 
			
		||||
				// without a match.
 | 
			
		||||
				if err == io.EOF { //nolint:errorlint // comparison with io.EOF is legit, https://github.com/polyfloyd/go-errorlint/pull/12
 | 
			
		||||
					err = nil
 | 
			
		||||
				}
 | 
			
		||||
				return out, err
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// Simple common case: line is short enough to fit in a
 | 
			
		||||
			// single reader's buffer.
 | 
			
		||||
			if !isPrefix && len(wholeLine) == 0 {
 | 
			
		||||
				wholeLine = line
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			wholeLine = append(wholeLine, line...)
 | 
			
		||||
 | 
			
		||||
			// Check if we read the whole line already.
 | 
			
		||||
			if !isPrefix {
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// There's no spec for /etc/passwd or /etc/group, but we try to follow
 | 
			
		||||
		// the same rules as the glibc parser, which allows comments and blank
 | 
			
		||||
		// space at the beginning of a line.
 | 
			
		||||
		wholeLine = bytes.TrimSpace(wholeLine)
 | 
			
		||||
		if len(wholeLine) == 0 || wholeLine[0] == '#' {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -197,17 +236,12 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) {
 | 
			
		||||
		//  root:x:0:root
 | 
			
		||||
		//  adm:x:4:root,adm,daemon
 | 
			
		||||
		p := Group{}
 | 
			
		||||
		parseLine(text, &p.Name, &p.Pass, &p.Gid, &p.List)
 | 
			
		||||
		parseLine(wholeLine, &p.Name, &p.Pass, &p.Gid, &p.List)
 | 
			
		||||
 | 
			
		||||
		if filter == nil || filter(p) {
 | 
			
		||||
			out = append(out, p)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if err := s.Err(); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return out, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ExecUser struct {
 | 
			
		||||
@@ -278,7 +312,7 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) (
 | 
			
		||||
 | 
			
		||||
	// Allow for userArg to have either "user" syntax, or optionally "user:group" syntax
 | 
			
		||||
	var userArg, groupArg string
 | 
			
		||||
	parseLine(userSpec, &userArg, &groupArg)
 | 
			
		||||
	parseLine([]byte(userSpec), &userArg, &groupArg)
 | 
			
		||||
 | 
			
		||||
	// Convert userArg and groupArg to be numeric, so we don't have to execute
 | 
			
		||||
	// Atoi *twice* for each iteration over lines.
 | 
			
		||||
@@ -496,8 +530,8 @@ func ParseSubIDFilter(r io.Reader, filter func(SubID) bool) ([]SubID, error) {
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	for s.Scan() {
 | 
			
		||||
		line := strings.TrimSpace(s.Text())
 | 
			
		||||
		if line == "" {
 | 
			
		||||
		line := bytes.TrimSpace(s.Bytes())
 | 
			
		||||
		if len(line) == 0 {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -549,14 +583,14 @@ func ParseIDMapFilter(r io.Reader, filter func(IDMap) bool) ([]IDMap, error) {
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	for s.Scan() {
 | 
			
		||||
		line := strings.TrimSpace(s.Text())
 | 
			
		||||
		if line == "" {
 | 
			
		||||
		line := bytes.TrimSpace(s.Bytes())
 | 
			
		||||
		if len(line) == 0 {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// see: man 7 user_namespaces
 | 
			
		||||
		p := IDMap{}
 | 
			
		||||
		parseParts(strings.Fields(line), &p.ID, &p.ParentID, &p.Count)
 | 
			
		||||
		parseParts(bytes.Fields(line), &p.ID, &p.ParentID, &p.Count)
 | 
			
		||||
 | 
			
		||||
		if filter == nil || filter(p) {
 | 
			
		||||
			out = append(out, p)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user