]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/ssh/ldap_authorized_keys.sh
Update Chloé’s website
[perso/Immae/Config/Nix.git] / modules / private / ssh / ldap_authorized_keys.sh
CommitLineData
5566d26d
IB
1#!/usr/bin/env bash
2
3LDAPSEARCH=ldapsearch
4KEY="immaeSshKey"
5LDAP_BIND="cn=ssh,ou=services,dc=immae,dc=eu"
ea7bf00c 6LDAP_PASS=$(cat /etc/ssh/ldap_password)
5566d26d 7LDAP_HOST="ldap.immae.eu"
5566d26d
IB
8LDAP_BASE="dc=immae,dc=eu"
9
10suitable_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
29clean_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
43ldap_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
47ldap_keys() {
48 user=$1;
1b9150a5 49 @snippets@
5566d26d
IB
50}
51
52ldap_keys $@