diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-01 10:41:18 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-01 10:41:18 -0600 |
commit | ee165667d271b29eef70c9726bf6af45778cb470 (patch) | |
tree | 0d8470676f3d8375ff8a701c1b7a8796404d46a4 /src/nshd/hackers_git/hackers_parse.go | |
parent | cdf93b72b06c195410a64925c048fde25910dac2 (diff) |
Finish the hackers.git parser
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 } |