5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
+ "net"
8
9
"reflect"
9
10
"time"
10
11
@@ -15,6 +16,7 @@ import (
15
16
type AuthRadius struct {
16
17
Addr string `json:"addr"`
17
18
Secret string `json:"secret"`
19
+ Nasip string `json:"nasip"`
18
20
}
19
21
20
22
func init () {
@@ -57,8 +59,22 @@ func (auth AuthRadius) checkUser(name, pwd string, g *Group) error {
57
59
}
58
60
// radius认证时,设置超时3秒
59
61
packet := radius .New (radius .CodeAccessRequest , []byte (auth .Secret ))
60
- rfc2865 .UserName_SetString (packet , name )
61
- rfc2865 .UserPassword_SetString (packet , pwd )
62
+ err = rfc2865 .UserName_SetString (packet , name )
63
+ if err != nil {
64
+ return fmt .Errorf ("%s %s" , name , "Radius set name 出现错误" )
65
+ }
66
+ err = rfc2865 .UserPassword_SetString (packet , pwd )
67
+ if err != nil {
68
+ return fmt .Errorf ("%s %s" , name , "Radius set pwd 出现错误" )
69
+ }
70
+ if auth .Nasip != "" {
71
+ nasip := net .ParseIP (auth .Nasip )
72
+ err = rfc2865 .NASIPAddress_Set (packet , nasip )
73
+ if err != nil {
74
+ return fmt .Errorf ("%s %s" , name , "Radius set nasip 出现错误" )
75
+ }
76
+ }
77
+
62
78
ctx , done := context .WithTimeout (context .Background (), 3 * time .Second )
63
79
defer done ()
64
80
response , err := radius .Exchange (ctx , packet , auth .Addr )
0 commit comments