summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/db_shadow.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/nshd/hackers_git/db_shadow.go')
-rw-r--r--src/nshd/hackers_git/db_shadow.go82
1 files changed, 75 insertions, 7 deletions
diff --git a/src/nshd/hackers_git/db_shadow.go b/src/nshd/hackers_git/db_shadow.go
index 199d89e..08384d9 100644
--- a/src/nshd/hackers_git/db_shadow.go
+++ b/src/nshd/hackers_git/db_shadow.go
@@ -1,16 +1,84 @@
package hackers_git
-import p "nslcd_proto"
+import (
+ p "nslcd_proto"
+ "nslcd_proto/util"
+)
func (o *Hackers) Shadow_ByName(cred p.Ucred, req p.Request_Shadow_ByName) p.Shadow_Enumerator {
o.lock.RLock()
defer o.lock.RUnlock()
- // TODO
- return nil
+
+ if cred.Uid != 0 {
+ return util.Shadow_Ø{}
+ }
+ uid := o.name2uid(string(req))
+ 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})
}
-func (o *Hackers) Shadow_All(cred p.Ucred, req p.Request_Shadow_All) p.Shadow_Enumerator {
+
+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,
+ LastChangeDate: -1,
+ MinDays: -1,
+ MaxDays: -1,
+ WarnDays: -1,
+ InactDays: -1,
+ 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
+}
+
+func (e *allShadowEnumerator) GenericGetNext() (interface{}, error) {
+ return e.GetNext()
+}
+
+func (o *Hackers) newAllShadowEnumerator() *allShadowEnumerator {
o.lock.RLock()
- defer o.lock.RUnlock()
- // TODO
- return nil
+ e := allShadowEnumerator{
+ uids: make([]int32, len(o.users)),
+ backend: o,
+ done: false,
+ }
+ for uid, _ := range o.users {
+ e.uids = append(e.uids, uid)
+ }
+ return &e
+}
+
+func (o *Hackers) Shadow_All(cred p.Ucred, req p.Request_Shadow_All) p.Shadow_Enumerator {
+ if cred.Uid != 0 {
+ return util.Shadow_Ø{}
+ }
+ return o.newAllShadowEnumerator()
}