src/server/worker/api_server.go
func lookupDockerUser(userArg string) (_ *user.User, retErr error) {
	userParts := strings.Split(userArg, ":")
	userOrUID := userParts[0]
	groupOrGID := ""
	if len(userParts) > 1 {
		groupOrGID = userParts[1]
	}
	passwd, err := os.Open("/etc/passwd")
	if err != nil {
		return nil, err
	}
	defer func() {
		if err := passwd.Close(); err != nil && retErr == nil {
			retErr = err
		}
	}()
	scanner := bufio.NewScanner(passwd)
	for scanner.Scan() {
		parts := strings.Split(scanner.Text(), ":")
		if parts[0] == userOrUID || parts[2] == userOrUID {
			result := &user.User{
				Username: parts[0],
				Uid:      parts[2],
				Gid:      parts[3],
				Name:     parts[4],
				HomeDir:  parts[5],
			}
			if groupOrGID != "" {
				if parts[0] == userOrUID {
					// groupOrGid is a group
					group, err := lookupGroup(groupOrGID)
					if err != nil {
						return nil, err
					}
					result.Gid = group.Gid
				} else {
					// groupOrGid is a gid
					result.Gid = groupOrGID
				}
			}
			return result, nil
		}
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	return nil, fmt.Errorf("user %s not found", userArg)
}
func lookupDockerUser(userArg string) (_ *user.User, retErr error) {
	userParts := strings.Split(userArg, ":")
	userOrUID := userParts[0]
	groupOrGID := ""
	if len(userParts) > 1 {
		groupOrGID = userParts[1]
	}
	passwd, err := os.Open("/etc/passwd")
	if err != nil {
		return nil, err
	}
	defer func() {
		if err := passwd.Close(); err != nil && retErr == nil {
			retErr = err
		}
	}()
	scanner := bufio.NewScanner(passwd)
	for scanner.Scan() {
		parts := strings.Split(scanner.Text(), ":")
		if parts[0] == userOrUID || parts[2] == userOrUID {
			result := &user.User{
				Username: parts[0],
				Uid:      parts[2],
				Gid:      parts[3],
				Name:     parts[4],
				HomeDir:  parts[5],
			}
			if groupOrGID != "" {
				if parts[0] == userOrUID {
					// groupOrGid is a group
					group, err := lookupGroup(groupOrGID)
					if err != nil {
						return nil, err
					}
					result.Gid = group.Gid
				} else {
					// groupOrGid is a gid
					result.Gid = groupOrGID
				}
			}
			return result, nil
		}
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	return nil, fmt.Errorf("user %s not found", userArg)
}
func lookupDockerUser ( userArg string ) ( _ * user . User , retErr error ) { userParts := strings . Split ( userArg , " " ) userOrUID := userParts [ 0 ] groupOrGID := " " if len ( userParts ) > 1 { groupOrGID = userParts [ 1 ] } passwd , err := os . Open ( " " ) if err != nil { return nil , err } defer func ( ) { if err := passwd . Close ( ) ; err != nil && retErr == nil { retErr = err } } ( ) scanner := bufio . NewScanner ( passwd ) for scanner . Scan ( ) { parts := strings . Split ( scanner . Text ( ) , " " ) if parts [ 0 ] == userOrUID || parts [ 2 ] == userOrUID { result := & user . User { Username : parts [ 0 ] , Uid : parts [ 2 ] , Gid : parts [ 3 ] , Name : parts [ 4 ] , HomeDir : parts [ 5 ] , } if groupOrGID != " " { if parts [ 0 ] == userOrUID { // groupOrGid is a group group , err := lookupGroup ( groupOrGID ) if err != nil { return nil , err } result . Gid = group . Gid } else { // groupOrGid is a gid result . Gid = groupOrGID } } return result , nil } } if err := scanner . Err ( ) ; err != nil { log . Fatal ( err ) } return nil , fmt . Errorf ( " " , userArg ) }
// lookupDockerUser looks up users given the argument to a Dockerfile USER directive.
// According to Docker's docs this directive looks like:
// USER <user>[:<group>] or
// USER <UID>[:<GID>]
lookupDockerUser looks up users given the argument to a Dockerfile USER directive . According to Docker s docs this directive looks like : USER <user > [ : <group > ] or USER <UID > [ : <GID > ]