diff --git a/bridge/bridge.go b/bridge/bridge.go index 3247dd8f..0b613ab9 100755 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -488,6 +488,7 @@ loop: tl.Password = t.Password tl.LocalPath = t.LocalPath tl.StripPre = t.StripPre + tl.MultiUser = t.MultiUser if !client.HasTunnel(tl) { if err := file.GetDb().NewTask(tl); err != nil { logs.Notice("Add task error ", err.Error()) diff --git a/lib/config/config.go b/lib/config/config.go index 9ab4b6c5..47290bed 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -240,15 +240,14 @@ func dealTunnel(s string) *file.Tunnel { case "strip_pre": t.StripPre = item[1] case "multi_user": - // TODO add test with multi user config file - t.Client.Cnf.MultiUser = true + t.MultiUser = new(file.MultiUser) if b, err := common.ReadAllFromFile(item[1]); err != nil { panic(err) } else { if content, err := common.ParseStr(string(b)); err != nil { panic(err) } else { - t.Client.Cnf.MultiUserMap = dealMultiUser(content) + t.MultiUser.UserMap = dealMultiUser(content) } } } diff --git a/lib/file/obj.go b/lib/file/obj.go index 22159685..424b727e 100644 --- a/lib/file/obj.go +++ b/lib/file/obj.go @@ -25,12 +25,10 @@ func (s *Flow) Add(in, out int64) { } type Config struct { - U string - P string - Compress bool - Crypt bool - MultiUser bool // enable multi user authentication. - MultiUserMap map[string]string // multi user and pwd + U string + P string + Compress bool + Crypt bool } type Client struct { @@ -142,6 +140,7 @@ type Tunnel struct { LocalPath string StripPre string Target *Target + MultiUser *MultiUser Health sync.RWMutex } @@ -186,6 +185,10 @@ type Target struct { sync.RWMutex } +type MultiUser struct { + UserMap map[string]string // multi user and pwd +} + func (s *Target) GetRandomTarget() (string, error) { if s.TargetArr == nil { s.TargetArr = strings.Split(s.TargetStr, "\n") diff --git a/server/proxy/socks5.go b/server/proxy/socks5.go index d6c6ec6a..a195693c 100755 --- a/server/proxy/socks5.go +++ b/server/proxy/socks5.go @@ -199,7 +199,7 @@ func (s *Sock5ModeServer) handleConn(c net.Conn) { c.Close() return } - if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.Client.Cnf.MultiUser && len(s.task.Client.Cnf.MultiUserMap) > 0) { + if (s.task.Client.Cnf.U != "" && s.task.Client.Cnf.P != "") || (s.task.MultiUser != nil && len(s.task.MultiUser.UserMap) > 0) { buf[1] = UserPassAuth c.Write(buf) if err := s.Auth(c); err != nil { @@ -238,11 +238,11 @@ func (s *Sock5ModeServer) Auth(c net.Conn) error { } var U, P string - if s.task.Client.Cnf.MultiUser { + if s.task.MultiUser != nil { // enable multi user auth U = string(user) var ok bool - P, ok = s.task.Client.Cnf.MultiUserMap[U] + P, ok = s.task.MultiUser.UserMap[U] if !ok { return errors.New("验证不通过") }