mirror of https://github.com/xSmurf/oz.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
677 B
33 lines
677 B
10 years ago
|
package oz
|
||
|
|
||
|
import(
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"path"
|
||
|
"syscall"
|
||
|
)
|
||
|
|
||
|
func checkConfigPermissions(fpath string) error {
|
||
|
pd := path.Dir(fpath)
|
||
|
for _, fp := range []string{pd, fpath} {
|
||
|
if err := checkPathRootPermissions(fp); err != nil {
|
||
|
return fmt.Errorf("file `%s` is %s", fp, err)
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func checkPathRootPermissions(fpath string) error {
|
||
|
fstat, err := os.Stat(fpath)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if (fstat.Mode().Perm() & syscall.S_IWOTH) != 0 {
|
||
|
return fmt.Errorf("writable by everyone!")
|
||
|
}
|
||
|
if (fstat.Mode().Perm()&syscall.S_IWGRP) != 0 && fstat.Sys().(*syscall.Stat_t).Gid != 0 {
|
||
|
return fmt.Errorf("writable by someone else than root!")
|
||
|
}
|
||
|
return nil
|
||
|
}
|