]>
Commit | Line | Data |
---|---|---|
5566d26d IB |
1 | #!/usr/bin/env bash |
2 | ||
3 | LDAPSEARCH=ldapsearch | |
4 | KEY="immaeSshKey" | |
5 | LDAP_BIND="cn=ssh,ou=services,dc=immae,dc=eu" | |
ea7bf00c | 6 | LDAP_PASS=$(cat /etc/ssh/ldap_password) |
5566d26d | 7 | LDAP_HOST="ldap.immae.eu" |
5566d26d IB |
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() { | |
bad8f8d3 | 44 | $LDAPSEARCH -h $LDAP_HOST -ZZ -b $LDAP_BASE -D $LDAP_BIND -w "$LDAP_PASS" -x -o ldif-wrap=no -LLL "$@" |
5566d26d IB |
45 | } |
46 | ||
47 | ldap_keys() { | |
48 | user=$1; | |
1b9150a5 | 49 | @snippets@ |
5566d26d IB |
50 | } |
51 | ||
52 | ldap_keys $@ |