diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-08-29 23:19:55 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-08-29 23:19:55 -0600 |
commit | 3bca4faef65f9ba97abad49505e10c675894c559 (patch) | |
tree | 4f067137658d0e1e2e676be64b12a9d85ea23dd5 /src/nshd/hackers_git/hackers_parse.go | |
parent | 5fd4b54f3a833bdfabf067c4abafa56c11e02ab1 (diff) |
stuff
Diffstat (limited to 'src/nshd/hackers_git/hackers_parse.go')
-rw-r--r-- | src/nshd/hackers_git/hackers_parse.go | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/nshd/hackers_git/hackers_parse.go b/src/nshd/hackers_git/hackers_parse.go index efc30a5..5152b55 100644 --- a/src/nshd/hackers_git/hackers_parse.go +++ b/src/nshd/hackers_git/hackers_parse.go @@ -1,13 +1,50 @@ package hackers_git import ( - _ "gopkg.in/yaml.v2" + "fmt" + yaml "gopkg.in/yaml.v2" + "io/ioutil" "nslcd_proto" + "os" ) -func load_user_yaml(filename string) (nslcd_proto.Passwd, error) { +type yaml_user struct { + username string + fullname string + shell string + groups []string +} + +func filename2uid(filename string) int32 { // TODO - return nslcd_proto.Passwd{}, nil + return 0 +} + +func load_user_yaml(filename string) (ret nslcd_proto.Passwd, err error) { + ret.UID = filename2uid(filename) + if ret.UID < 0 { + err = fmt.Errorf("Invalid user filename: %q", filename) + return + } + file, err := os.Open(filename) + if err != nil { + return + } + contents, err := ioutil.ReadAll(file) + if err != nil { + return + } + var user yaml_user + err = yaml.Unmarshal(contents, &user) + + ret.Name = user.username + ret.Password = "x" + ret.GID = name2gid("users") + ret.GECOS = user.fullname + ret.HomeDir = "/home/" + ret.Name + ret.Shell = user.shell + + return } func load_user_password(filename string) string { |