summaryrefslogtreecommitdiff
path: root/src/nshd/hackers_git/db_pam.go
blob: d4df99a843680e8ca6166b30d29a96cbc4cebfc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package hackers_git

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 {
	o.lock.RLock()
	defer o.lock.RUnlock()

	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
	}

	return util.New_PAM_Authentication_List([]p.PAM_Authentication{ret})
}

func (o *Hackers) PAM_Authorization(cred p.Ucred, req p.Request_PAM_Authorization) p.PAM_Authorization_Enumerator {
	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:  "",
	}

	return util.New_PAM_Authorization_List([]p.PAM_Authorization{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

	for i := 0; i < len(sessionid); i++ {
		bigint, err := rand.Int(rand.Reader, alphabet_len)
		if err != nil {
			return util.PAM_SessionOpen_Ø{}
		}
		sessionid[i] = alphabet[bigint.Int64()]
	}

	ret := p.PAM_SessionOpen{SessionID: string(sessionid[:])}

	return util.New_PAM_SessionOpen_List([]p.PAM_SessionOpen{ret})
}

func (o *Hackers) PAM_SessionClose(cred p.Ucred, req p.Request_PAM_SessionClose) p.PAM_SessionClose_Enumerator {
	return util.PAM_SessionClose_Ø{}
}