From b09ba2f9f42c44402d0bd641789af9c04e6d4ee6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 7 Sep 2015 23:58:08 -0600 Subject: clean up --- src/nshd/hackers_git/db_passwd.go | 9 +++------ src/nshd/hackers_git/gid.go | 6 +++--- src/nshd/hackers_git/hackers.go | 2 +- src/nshd/hackers_git/hackers_parse.go | 4 ++-- src/nshd/hackers_git/hackers_watch.go | 6 +++--- src/nshd/hackers_git/set.go | 11 +++++++++++ 6 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 src/nshd/hackers_git/set.go (limited to 'src') diff --git a/src/nshd/hackers_git/db_passwd.go b/src/nshd/hackers_git/db_passwd.go index 2cfaccd..719ff3f 100644 --- a/src/nshd/hackers_git/db_passwd.go +++ b/src/nshd/hackers_git/db_passwd.go @@ -69,19 +69,16 @@ func (o *allPasswdEnumerator) GenericGetNext() (n *interface{}, err error) { return } -func (o *Hackers) newAllPasswdEnumerator() *allPasswdEnumerator { +func (o *Hackers) Passwd_All(cred p.Ucred, req p.Request_Passwd_All) p.Passwd_Enumerator { o.lock.RLock() e := allPasswdEnumerator{ uids: make([]int32, len(o.users)), backend: o, done: false, } + i := uint(0) for uid, _ := range o.users { - e.uids = append(e.uids, uid) + e.uids[i] = uid } return &e } - -func (o *Hackers) Passwd_All(cred p.Ucred, req p.Request_Passwd_All) p.Passwd_Enumerator { - return o.newAllPasswdEnumerator() -} diff --git a/src/nshd/hackers_git/gid.go b/src/nshd/hackers_git/gid.go index ff95309..ee8c10d 100644 --- a/src/nshd/hackers_git/gid.go +++ b/src/nshd/hackers_git/gid.go @@ -11,11 +11,11 @@ func name2gid(name string) int32 { } } -func gid2name(gid int32) string { +func gid2name(gid int32) (string, bool) { gr, err := getgr.ByGid(gid) if gr == nil || err != nil { - return "" + return "", false } else { - return gr.Name + return gr.Name, true } } diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go index 83ef482..f84b110 100644 --- a/src/nshd/hackers_git/hackers.go +++ b/src/nshd/hackers_git/hackers.go @@ -12,7 +12,7 @@ import ( type user struct { passwd nslcd_proto.Passwd - groups map[string]bool + groups []string } type Config struct { diff --git a/src/nshd/hackers_git/hackers_parse.go b/src/nshd/hackers_git/hackers_parse.go index 77b9a13..46c878e 100644 --- a/src/nshd/hackers_git/hackers_parse.go +++ b/src/nshd/hackers_git/hackers_parse.go @@ -77,7 +77,7 @@ func parse_user_yaml(filename string) (ret user, err error) { } if iface, isSet := data["groups"]; !isSet { - ret.groups = make(map[string]bool, 0) + ret.groups = make([]string, 0) } else if ary, isTyp := iface.([]interface{}); !isTyp { errs = append(errs, "\"groups\" is not an array") } else { @@ -93,7 +93,7 @@ func parse_user_yaml(filename string) (ret user, err error) { } } if !e { - ret.groups = groups + ret.groups = set2list(groups) } } } diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index f5029de..8e3834e 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -106,11 +106,11 @@ func (o *Hackers) load_yaml_file(filename string) { o.lock.Lock() defer o.lock.Unlock() if olduser, found := o.users[uid]; found { - for groupname, _ := range olduser.groups { + for _, groupname := range olduser.groups { o.del_user_from_group(olduser.passwd.Name, groupname) } } - for groupname, _ := range user.groups { + for _, groupname := range user.groups { o.add_user_to_group(user.passwd.Name, groupname) } o.users[uid] = user @@ -124,7 +124,7 @@ func (o *Hackers) load_yaml_file(filename string) { o.unwatchHomedir(wd) } if olduser, found := o.users[uid]; found { - for groupname, _ := range olduser.groups { + for _, groupname := range olduser.groups { o.del_user_from_group(olduser.passwd.Name, groupname) } delete(o.users, uid) diff --git a/src/nshd/hackers_git/set.go b/src/nshd/hackers_git/set.go new file mode 100644 index 0000000..9faf0f4 --- /dev/null +++ b/src/nshd/hackers_git/set.go @@ -0,0 +1,11 @@ +package hackers_git + +func set2list(set map[string]bool) []string { + list := make([]string, len(set)) + i := uint(0) + for item, _ := range set { + list[i] = item + i++ + } + return list +} -- cgit v1.2.2