mirror of
https://github.com/containers/podman.git
synced 2025-11-13 01:29:06 +08:00
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>
66 lines
1.3 KiB
Go
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
|
|
}
|