Files
podman/vendor/github.com/containers/common/pkg/chown/chown.go
dependabot[bot] f46b34ecd2 Bump github.com/containers/common from 0.35.0 to 0.35.3
Bumps [github.com/containers/common](https://github.com/containers/common) from 0.35.0 to 0.35.3.
- [Release notes](https://github.com/containers/common/releases)
- [Commits](https://github.com/containers/common/compare/v0.35.0...v0.35.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-19 15:03:28 +01:00

66 lines
1.3 KiB
Go

package chown
import (
"os"
"os/user"
"path/filepath"
"github.com/containers/storage/pkg/homedir"
)
// DangerousHostPath validates if a host path is dangerous and should not be modified
func DangerousHostPath(path string) (bool, error) {
excludePaths := map[string]bool{
"/": true,
"/bin": true,
"/boot": true,
"/dev": true,
"/etc": true,
"/etc/passwd": true,
"/etc/pki": true,
"/etc/shadow": true,
"/home": true,
"/lib": true,
"/lib64": true,
"/media": true,
"/opt": true,
"/proc": true,
"/root": true,
"/run": true,
"/sbin": true,
"/srv": true,
"/sys": true,
"/tmp": true,
"/usr": true,
"/var": true,
"/var/lib": true,
"/var/log": true,
}
if home := homedir.Get(); home != "" {
excludePaths[home] = true
}
if sudoUser := os.Getenv("SUDO_USER"); sudoUser != "" {
if usr, err := user.Lookup(sudoUser); err == nil {
excludePaths[usr.HomeDir] = true
}
}
absPath, err := filepath.Abs(path)
if err != nil {
return true, err
}
realPath, err := filepath.EvalSymlinks(absPath)
if err != nil {
return true, err
}
if excludePaths[realPath] {
return true, nil
}
return false, nil
}