mirror of
https://github.com/containers/podman.git
synced 2025-06-27 05:26:50 +08:00
rootless: Merge rootless.go back into rootless_linux.go
The files were split apart by b96be3af (changes to allow for darwin compilation, 2018-06-20, #1015), but the C import and two functions left in rootless.go are all Linux-specific as well. This commit moves all of the pre-b96be3af rootless.go into rootless_linux.go, just adding the '// +build linux' header (b96be3af also scrambled the + in that header) and keeping the new GetRootlessUID from a1545fe6 (rootless: add function to retrieve the original UID, 2018-07-05, #1048). Signed-off-by: W. Trevor King <wking@tremily.us> Closes: #1034 Approved by: baude
This commit is contained in:

committed by
Atomic Bot

parent
4b54a471a4
commit
83968de28c
@ -1,43 +0,0 @@
|
|||||||
package rootless
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/containers/storage/pkg/idtools"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
extern int reexec_in_user_namespace(int ready);
|
|
||||||
extern int reexec_in_user_namespace_wait(int pid);
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
func runInUser() error {
|
|
||||||
os.Setenv("_LIBPOD_USERNS_CONFIGURED", "done")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func tryMappingTool(tool string, pid int, hostID int, mappings []idtools.IDMap) error {
|
|
||||||
path, err := exec.LookPath(tool)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
appendTriplet := func(l []string, a, b, c int) []string {
|
|
||||||
return append(l, fmt.Sprintf("%d", a), fmt.Sprintf("%d", b), fmt.Sprintf("%d", c))
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []string{path, fmt.Sprintf("%d", pid)}
|
|
||||||
args = appendTriplet(args, 0, hostID, 1)
|
|
||||||
if mappings != nil {
|
|
||||||
for _, i := range mappings {
|
|
||||||
args = appendTriplet(args, i.ContainerID+1, i.HostID, i.Size)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd := exec.Cmd{
|
|
||||||
Path: path,
|
|
||||||
Args: args,
|
|
||||||
}
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
// build +linux
|
// +build linux
|
||||||
|
|
||||||
package rootless
|
package rootless
|
||||||
|
|
||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
gosignal "os/signal"
|
gosignal "os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -22,6 +23,11 @@ extern int reexec_in_user_namespace_wait(int pid);
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
func runInUser() error {
|
||||||
|
os.Setenv("_LIBPOD_USERNS_CONFIGURED", "done")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// IsRootless tells us if we are running in rootless mode
|
// IsRootless tells us if we are running in rootless mode
|
||||||
func IsRootless() bool {
|
func IsRootless() bool {
|
||||||
return os.Getuid() != 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != ""
|
return os.Getuid() != 0 || os.Getenv("_LIBPOD_USERNS_CONFIGURED") != ""
|
||||||
@ -37,6 +43,30 @@ func GetRootlessUID() int {
|
|||||||
return os.Getuid()
|
return os.Getuid()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tryMappingTool(tool string, pid int, hostID int, mappings []idtools.IDMap) error {
|
||||||
|
path, err := exec.LookPath(tool)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
appendTriplet := func(l []string, a, b, c int) []string {
|
||||||
|
return append(l, fmt.Sprintf("%d", a), fmt.Sprintf("%d", b), fmt.Sprintf("%d", c))
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{path, fmt.Sprintf("%d", pid)}
|
||||||
|
args = appendTriplet(args, 0, hostID, 1)
|
||||||
|
if mappings != nil {
|
||||||
|
for _, i := range mappings {
|
||||||
|
args = appendTriplet(args, i.ContainerID+1, i.HostID, i.Size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd := exec.Cmd{
|
||||||
|
Path: path,
|
||||||
|
Args: args,
|
||||||
|
}
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
// BecomeRootInUserNS re-exec podman in a new userNS
|
// BecomeRootInUserNS re-exec podman in a new userNS
|
||||||
func BecomeRootInUserNS() (bool, error) {
|
func BecomeRootInUserNS() (bool, error) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user