-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpathchecker.go
47 lines (38 loc) · 871 Bytes
/
pathchecker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"regexp"
"sort"
"strings"
)
func main() {
env_path := os.Getenv("PATH")
paths := strings.Split(env_path, ":")
sort.Strings(paths)
for _, path := range paths {
var errors []string
stat, err := os.Stat(path)
if err != nil {
fmt.Println(path)
fmt.Println(" - " + err.Error())
continue
}
if !stat.IsDir() {
errors = append(errors, "not a directory")
}
mode := stat.Mode().String()
if matched, _ := regexp.MatchString("d....w", mode); matched {
errors = append(errors, "group writable permissions are too open - "+mode)
}
if matched, _ := regexp.MatchString("d.......w.", mode); matched {
errors = append(errors, "other writable permissions are too open - "+mode)
}
if len(errors) > 0 {
fmt.Println(path)
for _, err := range errors {
fmt.Println(" - " + err)
}
}
}
}