diff --git a/sshproxy-managerd/sshproxy-managerd.go b/sshproxy-managerd/sshproxy-managerd.go index 47c99f5f..c834d24e 100644 --- a/sshproxy-managerd/sshproxy-managerd.go +++ b/sshproxy-managerd/sshproxy-managerd.go @@ -19,6 +19,7 @@ import ( "net" "os" "os/signal" + "regexp" "strings" "syscall" "time" @@ -222,6 +223,15 @@ func genKey(user, host string) string { return fmt.Sprintf("%s@%s", user, host) } +// getUserFromKey returns the user from the key used in the proxiedConnections global variable. +func getUserFromKey(key string) (string, error) { + match := regexp.MustCompile(`^(\w*)@`).FindStringSubmatch(key) + if len(match) < 2 { + return "", fmt.Errorf("Unable to extract user from given key (%s)", key) + } + return match[1], nil +} + // getAlgorithmAndRoutes returns the selection algorithm and a slice with the // possible destinations from the global configuration for a user connected to // an hostport and belonging to groups.