|
|
|
@ -2,7 +2,11 @@ package oz
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"syscall"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
@ -36,8 +40,15 @@ func NewDefaultConfig() *Config {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
|
|
|
bs, err := ioutil.ReadFile(path)
|
|
|
|
|
func LoadConfig(cpath string) (*Config, error) {
|
|
|
|
|
if _, err := os.Stat(cpath); os.IsNotExist(err) {
|
|
|
|
|
return nil,err
|
|
|
|
|
}
|
|
|
|
|
if err := checkConfigPermissions(cpath); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bs, err := ioutil.ReadFile(cpath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
@ -47,3 +58,27 @@ func LoadConfig(path string) (*Config, error) {
|
|
|
|
|
}
|
|
|
|
|
return c, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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!", fpath)
|
|
|
|
|
}
|
|
|
|
|
if (fstat.Mode().Perm() & syscall.S_IWGRP) != 0 && fstat.Sys().(*syscall.Stat_t).Gid != 0 {
|
|
|
|
|
return fmt.Errorf("writable by someone else than root!", err)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|