Add downstreamConn.clientName
This commit is contained in:
parent
5a8adc93fe
commit
b7e442670d
@ -72,6 +72,7 @@ type downstreamConn struct {
|
|||||||
username string
|
username string
|
||||||
rawUsername string
|
rawUsername string
|
||||||
networkName string
|
networkName string
|
||||||
|
clientName string
|
||||||
realname string
|
realname string
|
||||||
hostname string
|
hostname string
|
||||||
password string // empty after authentication
|
password string // empty after authentication
|
||||||
@ -574,19 +575,26 @@ func sanityCheckServer(addr string) error {
|
|||||||
return conn.Close()
|
return conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshalUsername(rawUsername string) (username, network string) {
|
func unmarshalUsername(rawUsername string) (username, client, network string) {
|
||||||
username = rawUsername
|
username = rawUsername
|
||||||
if i := strings.LastIndexAny(username, "/@"); i >= 0 {
|
|
||||||
network = username[i+1:]
|
i := strings.IndexAny(username, "/@")
|
||||||
|
j := strings.LastIndexAny(username, "/@")
|
||||||
|
if i >= 0 {
|
||||||
|
username = rawUsername[:i]
|
||||||
}
|
}
|
||||||
if i := strings.IndexAny(username, "/@"); i >= 0 {
|
if j >= 0 {
|
||||||
username = username[:i]
|
network = rawUsername[j+1:]
|
||||||
}
|
}
|
||||||
return username, network
|
if i >= 0 && j >= 0 && i < j {
|
||||||
|
client = rawUsername[i+1 : j]
|
||||||
|
}
|
||||||
|
|
||||||
|
return username, client, network
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *downstreamConn) authenticate(username, password string) error {
|
func (dc *downstreamConn) authenticate(username, password string) error {
|
||||||
username, networkName := unmarshalUsername(username)
|
username, clientName, networkName := unmarshalUsername(username)
|
||||||
|
|
||||||
u, err := dc.srv.db.GetUser(username)
|
u, err := dc.srv.db.GetUser(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -605,6 +613,7 @@ func (dc *downstreamConn) authenticate(username, password string) error {
|
|||||||
dc.logger.Printf("failed authentication for %q: user not active", username)
|
dc.logger.Printf("failed authentication for %q: user not active", username)
|
||||||
return errAuthFailed
|
return errAuthFailed
|
||||||
}
|
}
|
||||||
|
dc.clientName = clientName
|
||||||
dc.networkName = networkName
|
dc.networkName = networkName
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -622,8 +631,8 @@ func (dc *downstreamConn) register() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if dc.networkName == "" {
|
if dc.clientName == "" && dc.networkName == "" {
|
||||||
_, dc.networkName = unmarshalUsername(dc.rawUsername)
|
_, dc.clientName, dc.networkName = unmarshalUsername(dc.rawUsername)
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.registered = true
|
dc.registered = true
|
||||||
|
Loading…
Reference in New Issue
Block a user