diff --git a/sshproxy-managerd/sshproxy-managerd.go b/sshproxy-managerd/sshproxy-managerd.go index 3dae1920..c96f7c7f 100644 --- a/sshproxy-managerd/sshproxy-managerd.go +++ b/sshproxy-managerd/sshproxy-managerd.go @@ -17,6 +17,7 @@ import ( "io/ioutil" "net" "os" + "regexp" "strings" "time" @@ -203,6 +204,17 @@ 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) { + re := regexp.MustCompile(`^(\w*)@`) + match := re.FindStringSubmatch(key) + if len(match) < 2 { + return "", errors.New("Unable to extract user from given key (" + key + ")") + } else { + 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.