Skip to content

Commit

Permalink
Updated alias handler check code
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika committed Jun 29, 2022
1 parent f0ed644 commit 2680eff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sshmuxer/aliashandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func handleAliasListener(check *channelForwardMsg, stringPort string, requestMessages string, listenerHolder *utils.ListenerHolder, state *utils.State, sshConn *utils.SSHConnection) (*utils.AliasHolder, *url.URL, string, string, error) {
validAlias, aH := utils.GetOpenAlias(check.Addr, stringPort, state, sshConn)

if !strings.HasPrefix(validAlias, check.Addr) && viper.GetBool("force-requested-aliases") {
if !strings.HasPrefix(validAlias, check.Addr) && viper.GetBool("force-requested-aliases") || validAlias == "" {
return nil, nil, "", "", fmt.Errorf("error assigning requested alias to tunnel")
}

Expand Down
2 changes: 2 additions & 0 deletions sshmuxer/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *utils.SSHConnection,
log.Println("Error unmarshaling remote forward payload:", err)
}

check.Addr = strings.ToLower(check.Addr)

bindPort := check.Rport
stringPort := strconv.FormatUint(uint64(bindPort), 10)

Expand Down
6 changes: 5 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection
if viper.GetBool("force-requested-aliases") {
extra = ""

bindErr = fmt.Errorf("unable to bind requested port")
bindErr = fmt.Errorf("unable to bind requested alias")
}

sshConn.SendMessage(aurora.Sprintf("The alias %s is unavailable.%s", aurora.Red(alias), extra), true)
Expand Down Expand Up @@ -960,6 +960,10 @@ func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection
for checkAlias(alias) {
}

if bindErr != nil {
return "", nil
}

return alias, aH
}

Expand Down

0 comments on commit 2680eff

Please sign in to comment.