summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/db_shadow.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-12 10:35:52 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-12 10:35:52 -0600
commite8199ec88c7ca8107c4fb9238e383a4a9eb981ee (patch)
tree250c514c0cb4ec2b8bd442f4e80e916fb8ad6f2c /src/nshd/hackers_git/db_shadow.go
parentf0302e1ac1a12711a9f49c3d7a62bcdfcaca7eed (diff)
Derp, channels and goroutines are enumerators
Diffstat (limited to 'src/nshd/hackers_git/db_shadow.go')
-rw-r--r--src/nshd/hackers_git/db_shadow.go111
1 files changed, 41 insertions, 70 deletions
diff --git a/src/nshd/hackers_git/db_shadow.go b/src/nshd/hackers_git/db_shadow.go
index fecb9f8..594e7a1 100644
--- a/src/nshd/hackers_git/db_shadow.go
+++ b/src/nshd/hackers_git/db_shadow.go
@@ -1,46 +1,22 @@
package hackers_git
-import (
- p "nslcd_proto"
- "nslcd_proto/util"
-)
+import p "nslcd_proto"
-func (o *Hackers) Shadow_ByName(cred p.Ucred, req p.Request_Shadow_ByName) p.Shadow_Enumerator {
+func (o *Hackers) Shadow_ByName(cred p.Ucred, req p.Request_Shadow_ByName) <-chan p.Shadow {
o.lock.RLock()
- defer o.lock.RUnlock()
+ ret := make(chan p.Shadow)
+ go func() {
+ defer o.lock.RUnlock()
+ defer close(ret)
- if cred.Uid != 0 {
- return util.Shadow_Ø{}
- }
- uid := o.name2uid(req.Name)
- passwd := o.users[uid].passwd
- shadow := p.Shadow{
- Name: passwd.Name,
- PwHash: passwd.PwHash,
- LastChangeDate: -1,
- MinDays: -1,
- MaxDays: -1,
- WarnDays: -1,
- InactDays: -1,
- ExpireDate: -1,
- Flag: -1,
- }
-
- return util.New_Shadow_List([]p.Shadow{shadow})
-}
-
-type allShadowEnumerator struct {
- uids []int32
- backend *Hackers
- done bool
-}
-
-func (e *allShadowEnumerator) GetNext() (*p.Shadow, error) {
- if len(e.uids) > 0 {
- passwd := e.backend.users[e.uids[0]].passwd
- shadow := p.Shadow{
- Name: passwd.Name,
- PwHash: passwd.PwHash,
+ if cred.Uid != 0 {
+ return
+ }
+ uid := o.name2uid(req.Name)
+ user := o.users[uid]
+ ret <- p.Shadow{
+ Name: user.passwd.Name,
+ PwHash: user.passwd.PwHash,
LastChangeDate: -1,
MinDays: -1,
MaxDays: -1,
@@ -49,39 +25,34 @@ func (e *allShadowEnumerator) GetNext() (*p.Shadow, error) {
ExpireDate: -1,
Flag: -1,
}
- e.uids = e.uids[1:]
- return &shadow, nil
- }
- if len(e.uids) == 0 && !e.done {
- e.done = true
- e.backend.lock.RUnlock()
- }
- return nil, nil
+ }()
+ return ret
}
-func (o *allShadowEnumerator) GenericGetNext() (n *interface{}, err error) {
- a, err := o.GetNext()
- if a != nil {
- b := (interface{})(*a)
- n = &b
- }
- return
-}
-
-func (o *Hackers) Shadow_All(cred p.Ucred, req p.Request_Shadow_All) p.Shadow_Enumerator {
- if cred.Uid != 0 {
- return util.Shadow_Ø{}
- }
+func (o *Hackers) Shadow_All(cred p.Ucred, req p.Request_Shadow_All) <-chan p.Shadow {
o.lock.RLock()
- e := allShadowEnumerator{
- uids: make([]int32, len(o.users)),
- backend: o,
- done: false,
- }
- i := uint(0)
- for uid, _ := range o.users {
- e.uids[i] = uid
- i++
- }
- return &e
+ ret := make(chan p.Shadow)
+ go func() {
+ defer o.lock.RUnlock()
+ defer close(ret)
+
+ if cred.Uid != 0 {
+ return
+ }
+
+ for _, user := range o.users {
+ ret <- p.Shadow{
+ Name: user.passwd.Name,
+ PwHash: user.passwd.PwHash,
+ LastChangeDate: -1,
+ MinDays: -1,
+ MaxDays: -1,
+ WarnDays: -1,
+ InactDays: -1,
+ ExpireDate: -1,
+ Flag: -1,
+ }
+ }
+ }()
+ return ret
}