@@ -8,6 +8,8 @@ import (
9// SearchParent searches for a target file or directory starting from dir
9// SearchParent searches for a target file or directory starting from dir
10// and walking up the directory tree until found or root or home is reached.
10// and walking up the directory tree until found or root or home is reached.
11+// It also checks the ownership of directories to ensure that the search does
12+// not cross ownership boundaries.
11// Returns the full path to the target if found, empty string and false otherwise.
13// Returns the full path to the target if found, empty string and false otherwise.
12// The search includes the starting directory itself.
14// The search includes the starting directory itself.
13func SearchParent(dir, target string) (string, bool) {
15func SearchParent(dir, target string) (string, bool) {
@@ -24,6 +26,10 @@ func SearchParent(dir, target string) (string, bool) {
26 previousParent := absDir
28 previousParent := absDir
29+ previousOwner, err := Owner(previousParent)
29 parent := filepath.Dir(previousParent)
35 parent := filepath.Dir(previousParent)
@@ -31,6 +37,14 @@ func SearchParent(dir, target string) (string, bool) {
31 return "", false
37 return "", false
40+ parentOwner, err := Owner(parent)
44+ if parentOwner != previousOwner {
34 path := filepath.Join(parent, target)
48 path := filepath.Join(parent, target)
35 if _, err := os.Stat(path); err == nil {
49 if _, err := os.Stat(path); err == nil {
36 return path, true
50 return path, true
@@ -39,5 +53,6 @@ func SearchParent(dir, target string) (string, bool) {
41 previousParent = parent
55 previousParent = parent
56+ previousOwner = parentOwner