summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/hackers_parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/nshd/hackers_git/hackers_parse.go')
-rw-r--r--src/nshd/hackers_git/hackers_parse.go67
1 files changed, 44 insertions, 23 deletions
diff --git a/src/nshd/hackers_git/hackers_parse.go b/src/nshd/hackers_git/hackers_parse.go
index d5370eb..9dcfcc7 100644
--- a/src/nshd/hackers_git/hackers_parse.go
+++ b/src/nshd/hackers_git/hackers_parse.go
@@ -27,33 +27,13 @@ import (
"io/ioutil"
"lukeshu.com/git/go/libsystemd.git/sd_daemon/logger"
"os"
- "path"
- "strconv"
+ "os/exec"
"strings"
)
-func filename2uid(filename string) int32 {
- basename := path.Base(filename)
- parts := strings.SplitN(basename, ".", 2)
- if len(parts) != 2 || parts[1] != "yml" {
- return -1
- }
- uid, err := strconv.ParseInt(parts[0], 10, 32)
- if err != nil {
- return -1
- }
- return int32(uid)
-}
-
var usersGid = name2gid("users")
-func parse_user_yaml(filename string) (ret user, err error) {
- ret.passwd.UID = filename2uid(filename)
-
- if ret.passwd.UID < 0 {
- err = fmt.Errorf("Invalid user filename: %q", filename)
- return
- }
+func parse_config(filename string) (cfg config, err error) {
file, err := os.Open(filename)
if err != nil {
return
@@ -62,11 +42,52 @@ func parse_user_yaml(filename string) (ret user, err error) {
if err != nil {
return
}
+ 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 {
@@ -122,7 +143,7 @@ func parse_user_yaml(filename string) (ret user, err error) {
err = &yaml.TypeError{Errors: errs}
}
- ret.passwd.PwHash = "!"
+ ret.passwd.PwHash = parse_user_password(ret.passwd.HomeDir + "/.password")
ret.passwd.GID = usersGid
return