diff options
Diffstat (limited to 'src/nshd/hackers_git/hackers_parse.go')
-rw-r--r-- | src/nshd/hackers_git/hackers_parse.go | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/nshd/hackers_git/hackers_parse.go b/src/nshd/hackers_git/hackers_parse.go index 8f93432..b0ed91b 100644 --- a/src/nshd/hackers_git/hackers_parse.go +++ b/src/nshd/hackers_git/hackers_parse.go @@ -5,11 +5,23 @@ import ( yaml "gopkg.in/yaml.v2" "io/ioutil" "os" + "path" + "sd_daemon/logger" + "strconv" + "strings" ) func filename2uid(filename string) int32 { - // TODO - return 0 + 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") @@ -96,7 +108,30 @@ func load_user_yaml(filename string) (ret user, err error) { return } -func load_user_password(filename string) string { - // TODO - return "!" +func load_user_password(filename string) (hash string) { + hash = "!" + file, err := os.Open(filename) + if err != nil { + logger.Info("Could not open: %q: %v", filename, err) + return + } + contents, err := ioutil.ReadAll(file) + if err != nil { + logger.Info("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.Info("Invalid password format in file: %q", filename) + } + default: + logger.Info("Invalid password format in file: %q", filename) + } + return } |