diff options
author | Andrew Cady <d@jerkface.net> | 2019-07-23 02:15:37 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-07-23 04:00:23 -0400 |
commit | 9cca9ddd4dce9d481a3ab9594d8cf8f74cde6677 (patch) | |
tree | 2d646e90a763d28e96e5a737914a884dcb09779c | |
parent | 9139c1e74f19832e070323af2afd673dd482e365 (diff) |
use authorized_keys.d to set $user to the basename
-rwxr-xr-x | hooks/post-receive | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/hooks/post-receive b/hooks/post-receive index 4e85b42..67e7610 100755 --- a/hooks/post-receive +++ b/hooks/post-receive | |||
@@ -4,5 +4,34 @@ then | |||
4 | GIT_WORK_TREE=. git checkout -f master -- hooks/post-receive | 4 | GIT_WORK_TREE=. git checkout -f master -- hooks/post-receive |
5 | DID_SELF_UPDATE=y exec hooks/post-receive | 5 | DID_SELF_UPDATE=y exec hooks/post-receive |
6 | fi | 6 | fi |
7 | exec >&2 | ||
7 | 8 | ||
8 | echo 'Hello, world!' >&2 | 9 | GIT_WORK_TREE=. git checkout -f master -- authorized_keys.d/\* |
10 | |||
11 | if [ "$SSH_USER_AUTH" ] && [ -f "$SSH_USER_AUTH" ] | ||
12 | then | ||
13 | read authtype keytype keyval < "$SSH_USER_AUTH" | ||
14 | [ "$authtype" = publickey ] || exit | ||
15 | |||
16 | user= | ||
17 | for keyname in authorized_keys.d/* | ||
18 | do | ||
19 | while read a b _ | ||
20 | do | ||
21 | case "$a $b" in | ||
22 | "$keytype $keyval") | ||
23 | user=${keyname#authorized_keys.d/} | ||
24 | break | ||
25 | ;; | ||
26 | esac | ||
27 | done < "$keyname" | ||
28 | done | ||
29 | |||
30 | if [ "$user" ] | ||
31 | then | ||
32 | echo "user=$user" | ||
33 | fi | ||
34 | |||
35 | else | ||
36 | echo "\$SSH_USER_AUTH missing. Try putting 'ExposeAuthInfo yes' in /etc/ssh/sshd_config" | ||
37 | fi | ||