Skip to content
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

pkg/cri: remove useless code #2721

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cri/stream/httpstream/spdy/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ type connection struct {
newStreamHandler httpstream.NewStreamHandler
}

// NewClientConnection creates a new SPDY client connection.
func NewClientConnection(conn net.Conn) (httpstream.Connection, error) {
spdyConn, err := spdystream.NewConnection(conn, false)
if err != nil {
defer conn.Close()
return nil, err
}

return newConnection(spdyConn, httpstream.NoOpNewStreamHandler), nil
}

// NewServerConnection creates a new SPDY server connection. newStreamHandler
// will be invoked when the server receives a newly created stream from the
// client.
Expand Down
151 changes: 0 additions & 151 deletions pkg/exec/exec.go

This file was deleted.

106 changes: 1 addition & 105 deletions pkg/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

Expand All @@ -27,24 +26,8 @@ var (

type filterFunc func(line, str string, idInt int, idErr error) (uint32, bool)

// uidParser defines lines in /etc/passwd, eg: root:x:0:0:root:/root:/bin/bash.
type uidParser struct {
user string
placeholder string
uid int
gid int
}

// gidParser defines lines in /etc/group, eg: root:x:0:.
type gidParser struct {
group string
placeholder string
gid int
}

// Get accepts user and group slice, return valid uid, gid and additional gids.
// Through Get is a interface returns all user informations runtime-spec need,
// GetUser, GetIntegerID, GetAdditionalGids still can be used independently.
// Through Get is a interface returns all user informations runtime-spec need.
func Get(passwdPath, groupPath, username string, groups []string) (uint32, uint32, []uint32, error) {
logrus.Debugf("get users, passwd path: (%s), group path: (%s), username: (%s), groups: (%v)",
passwdPath, groupPath, username, groups)
Expand Down Expand Up @@ -86,93 +69,6 @@ func Get(passwdPath, groupPath, username string, groups []string) (uint32, uint3
return uid, gid, additionalGids, nil
}

// GetUser accepts user string like <uid|username>:<gid|groupname>, and transfers them to format valid uid:gid.
// user format example:
// user
// uid
// uid:gid
// user:group
// uid:group
// user:gid
func GetUser(passwdPath, groupPath, user string) (uint32, uint32, error) {
if user == "" {
// if user is null, return 0 value as root user
return 0, 0, nil
}

var (
uidStr, gidStr string
uid, gid uint32
err error
)

ParseString(user, &uidStr, &gidStr)

// get uid from /etc/passwd
uid, err = ParseID(filepath.Join(passwdPath, PasswdFile), uidStr, func(line, str string, idInt int, idErr error) (uint32, bool) {
var up uidParser
ParseString(line, &up.user, &up.placeholder, &up.uid)
if (idErr == nil && idInt == up.uid) || str == up.user {
return uint32(up.uid), true
}
return 0, false
})
if err != nil {
// if uidStr is a integer, treat it as valid uid
integer, e := strconv.Atoi(uidStr)
if e != nil {
return 0, 0, err
}
uid = uint32(integer)
}

// if gidStr is null, then get gid from /etc/passwd
if len(gidStr) == 0 {
gid, err = ParseID(filepath.Join(passwdPath, PasswdFile), uidStr, func(line, str string, idInt int, idErr error) (uint32, bool) {
var up uidParser
ParseString(line, &up.user, &up.placeholder, &up.uid, &up.gid)
if (idErr == nil && idInt == up.uid) || str == up.user {
return uint32(up.gid), true
}
return 0, false
})
} else {
gid, err = ParseID(filepath.Join(groupPath, GroupFile), gidStr, func(line, str string, idInt int, idErr error) (uint32, bool) {
var gp gidParser
ParseString(line, &gp.group, &gp.placeholder, &gp.gid)
if (idErr == nil && idInt == gp.gid) || str == gp.group {
return uint32(gp.gid), true
}
return 0, false
})
}
if err != nil {
// if gidStr is a integer, treat it as valid gid
integer, e := strconv.Atoi(gidStr)
if e != nil {
return 0, 0, err
}
gid = uint32(integer)
}

return uid, gid, nil
}

// GetIntegerID only parser user format uid:gid, cause container rootfs is not created
// by contianerd now, can not change user to id, only support user id >= 1000
// TODO(huamin.thm): removed later
func GetIntegerID(user string) (uint32, uint32) {
if user == "" {
// return default user root
return 0, 0
}

// if uid gid can not be parsed successfully, return default user root
var uid, gid int
ParseString(user, &uid, &gid)
return uint32(uid), uint32(gid)
}

// GetAdditionalGids parse supplementary gids from slice groups.
func GetAdditionalGids(groups []string) []uint32 {
var additionalGids []uint32
Expand Down