Fixed uid resolving in bindlists

master
xSmurf 10 years ago
parent 9462c3584a
commit cb0e5b8fea

@ -5,7 +5,6 @@ import (
"os" "os"
"os/user" "os/user"
"path" "path"
"strconv"
"strings" "strings"
"syscall" "syscall"
@ -25,7 +24,6 @@ type Filesystem struct {
base string base string
root string root string
xpra string xpra string
userID string
noDefaults bool noDefaults bool
noSysAndProc bool noSysAndProc bool
fullDevices bool fullDevices bool
@ -117,7 +115,6 @@ func NewFilesystem(name string, user *user.User, basePath string, log *logging.L
fs.base = path.Join(basePath, name) fs.base = path.Join(basePath, name)
fs.root = path.Join(fs.base, "rootfs") fs.root = path.Join(fs.base, "rootfs")
fs.user = user fs.user = user
fs.userID = strconv.Itoa(os.Getuid())
return fs return fs
} }

@ -20,6 +20,7 @@ func (fs *Filesystem) resolveVars(p string) (string, error) {
const pathVar = "${PATH}/" const pathVar = "${PATH}/"
const homeVar = "${HOME}" const homeVar = "${HOME}"
const uidVar = "${UID}" const uidVar = "${UID}"
const userVar = "${USER}"
switch { switch {
case strings.HasPrefix(p, pathVar): case strings.HasPrefix(p, pathVar):
@ -32,8 +33,11 @@ func (fs *Filesystem) resolveVars(p string) (string, error) {
case strings.HasPrefix(p, homeVar): case strings.HasPrefix(p, homeVar):
return path.Join(fs.user.HomeDir, p[len(homeVar):]), nil return path.Join(fs.user.HomeDir, p[len(homeVar):]), nil
case strings.HasPrefix(p, uidVar): case strings.Contains(p, uidVar):
return strings.Replace(p, uidVar, fs.userID, -1), nil return strings.Replace(p, uidVar, fs.user.Uid, -1), nil
case strings.Contains(p, userVar):
return strings.Replace(p, userVar, fs.user.Username, -1), nil
} }
return p, nil return p, nil
} }

Loading…
Cancel
Save