summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/db_pam.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/nshd/hackers_git/db_pam.go')
-rw-r--r--src/nshd/hackers_git/db_pam.go104
1 files changed, 57 insertions, 47 deletions
diff --git a/src/nshd/hackers_git/db_pam.go b/src/nshd/hackers_git/db_pam.go
index d4df99a..126c403 100644
--- a/src/nshd/hackers_git/db_pam.go
+++ b/src/nshd/hackers_git/db_pam.go
@@ -4,70 +4,80 @@ import (
"crypto/rand"
"math/big"
p "nslcd_proto"
- "nslcd_proto/util"
)
-func (o *Hackers) PAM_Authentication(cred p.Ucred, req p.Request_PAM_Authentication) p.PAM_Authentication_Enumerator {
+func (o *Hackers) PAM_Authentication(cred p.Ucred, req p.Request_PAM_Authentication) <-chan p.PAM_Authentication {
o.lock.RLock()
- defer o.lock.RUnlock()
+ ret := make(chan p.PAM_Authentication)
+ go func() {
+ defer o.lock.RUnlock()
+ defer close(ret)
- uid := o.name2uid(req.UserName)
- if uid < 0 {
- return util.PAM_Authentication_Ø{}
- }
-
- user := o.users[uid]
- ret := p.PAM_Authentication{
- AuthenticationResult: p.NSLCD_PAM_AUTH_ERR,
- UserName: "",
- AuthorizationResult: p.NSLCD_PAM_AUTH_ERR,
- AuthorizationError: "",
- }
- if check_password(req.Password, user.passwd.PwHash) {
- ret.AuthenticationResult = p.NSLCD_PAM_SUCCESS
- ret.AuthorizationResult = ret.AuthenticationResult
- ret.UserName = user.passwd.Name
- }
+ uid := o.name2uid(req.UserName)
+ if uid < 0 {
+ return
+ }
- return util.New_PAM_Authentication_List([]p.PAM_Authentication{ret})
+ user := o.users[uid]
+ obj := p.PAM_Authentication{
+ AuthenticationResult: p.NSLCD_PAM_AUTH_ERR,
+ UserName: "",
+ AuthorizationResult: p.NSLCD_PAM_AUTH_ERR,
+ AuthorizationError: "",
+ }
+ if check_password(req.Password, user.passwd.PwHash) {
+ obj.AuthenticationResult = p.NSLCD_PAM_SUCCESS
+ obj.AuthorizationResult = obj.AuthenticationResult
+ obj.UserName = user.passwd.Name
+ }
+ ret <- obj
+ }()
+ return ret
}
-func (o *Hackers) PAM_Authorization(cred p.Ucred, req p.Request_PAM_Authorization) p.PAM_Authorization_Enumerator {
+func (o *Hackers) PAM_Authorization(cred p.Ucred, req p.Request_PAM_Authorization) <-chan p.PAM_Authorization {
o.lock.RLock()
- defer o.lock.RUnlock()
-
- uid := o.name2uid(req.UserName)
- if uid < 0 {
- return util.PAM_Authorization_Ø{}
- }
- ret := p.PAM_Authorization{
- Result: p.NSLCD_PAM_SUCCESS,
- Error: "",
- }
+ ret := make(chan p.PAM_Authorization)
+ go func() {
+ defer o.lock.RUnlock()
+ defer close(ret)
- return util.New_PAM_Authorization_List([]p.PAM_Authorization{ret})
+ uid := o.name2uid(req.UserName)
+ if uid < 0 {
+ return
+ }
+ ret <- p.PAM_Authorization{
+ Result: p.NSLCD_PAM_SUCCESS,
+ Error: "",
+ }
+ }()
+ return ret
}
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890"
var alphabet_len = big.NewInt(int64(len(alphabet)))
-func (o *Hackers) PAM_SessionOpen(cred p.Ucred, req p.Request_PAM_SessionOpen) p.PAM_SessionOpen_Enumerator {
- var sessionid [24]byte
+func (o *Hackers) PAM_SessionOpen(cred p.Ucred, req p.Request_PAM_SessionOpen) <-chan p.PAM_SessionOpen {
+ ret := make(chan p.PAM_SessionOpen)
+ go func() {
+ defer close(ret)
- for i := 0; i < len(sessionid); i++ {
- bigint, err := rand.Int(rand.Reader, alphabet_len)
- if err != nil {
- return util.PAM_SessionOpen_Ø{}
+ var sessionid [24]byte
+ for i := 0; i < len(sessionid); i++ {
+ bigint, err := rand.Int(rand.Reader, alphabet_len)
+ if err != nil {
+ return
+ }
+ sessionid[i] = alphabet[bigint.Int64()]
}
- sessionid[i] = alphabet[bigint.Int64()]
- }
-
- ret := p.PAM_SessionOpen{SessionID: string(sessionid[:])}
-
- return util.New_PAM_SessionOpen_List([]p.PAM_SessionOpen{ret})
+ ret <- p.PAM_SessionOpen{SessionID: string(sessionid[:])}
+ }()
+ return ret
}
-func (o *Hackers) PAM_SessionClose(cred p.Ucred, req p.Request_PAM_SessionClose) p.PAM_SessionClose_Enumerator {
- return util.PAM_SessionClose_Ø{}
+func (o *Hackers) PAM_SessionClose(cred p.Ucred, req p.Request_PAM_SessionClose) <-chan p.PAM_SessionClose {
+ ret := make(chan p.PAM_SessionClose)
+ go close(ret)
+ return ret
}