]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env bash | |
2 | ||
3 | LDAPSEARCH=ldapsearch | |
4 | KEY="immaeSshKey" | |
5 | LDAP_BIND="cn=ssh,ou=services,dc=immae,dc=eu" | |
6 | LDAP_PASS=$(cat /etc/ssh/ldap_password) | |
7 | LDAP_HOST="ldap.immae.eu" | |
8 | LDAP_BASE="dc=immae,dc=eu" | |
9 | ||
10 | suitable_for() { | |
11 | type_for="$1" | |
12 | key="$2" | |
13 | ||
14 | if [[ $key != *$'\n'* ]] && [[ $key == ssh-* ]]; then | |
15 | echo "$key" | |
16 | else | |
17 | key_type=$(cut -d " " -f 1 <<< "$key") | |
18 | ||
19 | if grep -q "\b-$type_for\b" <<< "$key_type"; then | |
20 | echo "" | |
21 | elif grep -q "\b$type_for\b" <<< "$key_type"; then | |
22 | echo $(sed -e "s/^[^ ]* //g" <<< "$key") | |
23 | else | |
24 | echo "" | |
25 | fi | |
26 | fi | |
27 | } | |
28 | ||
29 | clean_key_line() { | |
30 | type_for="$1" | |
31 | line="$2" | |
32 | ||
33 | if [[ "$line" == $KEY::* ]]; then | |
34 | # base64 keys should't happen, unless wrong copy-pasting | |
35 | key="" | |
36 | else | |
37 | key=$(sed -e "s/^$KEY: *//" -e "s/ *$//" <<< "$line") | |
38 | fi | |
39 | ||
40 | suitable_for "$type_for" "$key" | |
41 | } | |
42 | ||
43 | ldap_search() { | |
44 | $LDAPSEARCH -h $LDAP_HOST -ZZ -b $LDAP_BASE -D $LDAP_BIND -w "$LDAP_PASS" -x -o ldif-wrap=no -LLL "$@" | |
45 | } | |
46 | ||
47 | ldap_keys() { | |
48 | user=$1; | |
49 | @snippets@ | |
50 | } | |
51 | ||
52 | ldap_keys $@ |