From 0e0907734c12eb0b70659be15ffd8c161402e6db Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Jun 2016 14:35:35 -0400 Subject: move things src/parabola_hackers{/nslcd_backend,} --- .../nslcd_backend/hackers_parse.go | 135 --------------------- 1 file changed, 135 deletions(-) (limited to 'src/parabola_hackers/nslcd_backend/hackers_parse.go') diff --git a/src/parabola_hackers/nslcd_backend/hackers_parse.go b/src/parabola_hackers/nslcd_backend/hackers_parse.go index b18fdf8..e6d31c8 100644 --- a/src/parabola_hackers/nslcd_backend/hackers_parse.go +++ b/src/parabola_hackers/nslcd_backend/hackers_parse.go @@ -17,13 +17,9 @@ package hackers_nslcd_backend import ( - "fmt" yaml "gopkg.in/yaml.v2" "io/ioutil" - "lukeshu.com/git/go/libsystemd.git/sd_daemon/logger" "os" - "os/exec" - "strings" ) var usersGid = name2gid("users") @@ -40,134 +36,3 @@ func parse_config(filename string) (cfg config, err error) { err = yaml.Unmarshal(contents, &cfg) return } - -func parse_users(yaml_cat string) (users map[int32]user, err error) { - contents, err := exec.Command(yaml_cat).Output() - if err != nil { - return - } - - var _data interface{} - err = yaml.Unmarshal(contents, &_data) - if err != nil { - return - } - - data, isMap := _data.(map[interface{}]interface{}) - errs := []string{} - if !isMap { - errs = append(errs, "root node is not a map") - } else { - users = make(map[int32]user, len(data)) - for _uid, _user := range data { - uid, isInt := _uid.(int) - if !isInt { - errs = append(errs, fmt.Sprintf("UID is not an int: %T ( %#v )", _uid, _uid)) - continue - } - user, _err := parse_user(_user) - if _err != nil { - errs = append(errs, fmt.Sprintf("Could not parse data for UID %d: %v", uid, _err)) - continue - } - user.passwd.UID = int32(uid) - logger.Debug("hackers.git: -> User %d(%s) parsed", user.passwd.UID, user.passwd.Name) - users[user.passwd.UID] = user - } - } - if len(errs) > 0 { - users = nil - err = &yaml.TypeError{Errors: errs} - } - return -} - -func parse_user(_data interface{}) (ret user, err error) { - data, isMap := _data.(map[interface{}]interface{}) - errs := []string{} - if !isMap { - errs = append(errs, "root node is not a map") - } else { - if iface, isSet := data["username"]; !isSet { - errs = append(errs, "\"username\" is not set") - } else if str, isTyp := iface.(string); !isTyp { - errs = append(errs, "\"username\" is not a string") - } else { - ret.passwd.Name = str - ret.passwd.HomeDir = "/home/" + str - } - - if iface, isSet := data["fullname"]; !isSet { - errs = append(errs, "\"fullname\" is not set") - } else if str, isTyp := iface.(string); !isTyp { - errs = append(errs, "\"fullname\" is not a string") - } else { - ret.passwd.GECOS = str - } - - if iface, isSet := data["shell"]; !isSet { - errs = append(errs, "\"shell\" is not set") - } else if str, isTyp := iface.(string); !isTyp { - errs = append(errs, "\"shell\" is not a string") - } else { - ret.passwd.Shell = str - } - - if iface, isSet := data["groups"]; !isSet { - ret.groups = make([]string, 0) - } else if ary, isTyp := iface.([]interface{}); !isTyp { - errs = append(errs, "\"groups\" is not an array") - } else { - groups := make(map[string]bool, len(ary)) - e := false - for _, iface := range ary { - if str, isTyp := iface.(string); !isTyp { - errs = append(errs, "\"group\" item is not an array") - e = true - break - } else { - groups[str] = true - } - } - if !e { - ret.groups = set2list(groups) - } - } - } - if len(errs) > 0 { - err = &yaml.TypeError{Errors: errs} - } - - ret.passwd.PwHash = parse_user_password(ret.passwd.HomeDir + "/.password") - ret.passwd.GID = usersGid - - return -} - -func parse_user_password(filename string) (hash string) { - hash = "!" - file, err := os.Open(filename) - if err != nil { - logger.Debug("hackers.git: %v", err) - return - } - contents, err := ioutil.ReadAll(file) - if err != nil { - logger.Debug("hackers.git: Error while reading: %q: %v", filename, err) - return - } - lines := strings.Split(string(contents), "\n") - switch len(lines) { - case 1: - hash = lines[0] - case 2: - if lines[1] == "" { - hash = lines[0] - } else { - logger.Debug("hackers.git: Invalid password format in file: %q", filename) - } - default: - logger.Debug("hackers.git: Invalid password format in file: %q", filename) - } - return -} -- cgit v1.2.3-54-g00ecf