Skip to content

Commit 86e36b6

Browse files
committed
managerd: Adding a way to retrieve user from stored key
1 parent 60d78c3 commit 86e36b6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: sshproxy-managerd/sshproxy-managerd.go

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"io/ioutil"
1818
"net"
1919
"os"
20+
"regexp"
2021
"strings"
2122
"time"
2223

@@ -203,6 +204,17 @@ func genKey(user, host string) string {
203204
return fmt.Sprintf("%s@%s", user, host)
204205
}
205206

207+
// getUserFromKey returns the user from the key used in the proxiedConnections global variable.
208+
func getUserFromKey(key string) (string, error) {
209+
re := regexp.MustCompile(`^(\w*)@`)
210+
match := re.FindStringSubmatch(key)
211+
if len(match) < 2 {
212+
return "", errors.New("Unable to extract user from given key (" + key + ")")
213+
} else {
214+
return match[1], nil
215+
}
216+
}
217+
206218
// getAlgorithmAndRoutes returns the selection algorithm and a slice with the
207219
// possible destinations from the global configuration for a user connected to
208220
// an hostport and belonging to groups.

0 commit comments

Comments
 (0)