aboutsummaryrefslogtreecommitdiff
path: root/modules/private/gitolite/ldap_gitolite.sh
blob: 23cb2bfe736c5b7a20241f7d73392522c6b80f14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
### This snippet is not standalone and must be integrated in the global ldap_authorized_keys.sh
LDAP_GITOLITE_MEMBER="cn=users,cn=gitolite,ou=services,dc=immae,dc=eu"
GITOLITE_SHELL=$(which gitolite-shell)

if [[ $user == gitolite ]]; then
  ldap_search '(&(memberOf='$LDAP_GITOLITE_MEMBER')('$KEY'=*))' $KEY | \
    while read line ;
    do
      if [ ! -z "$line" ]; then
        if [[ $line == dn* ]]; then
          user=$(sed -n 's/.*uid=\([^,]*\).*/\1/p' <<< "$line")
          if [ -n "$user" ]; then
            if [[ $user == "immae" ]] || [[ $user == "denise" ]]; then
              # Capitalize first letter (backward compatibility)
              user=$(sed -r 's/^([a-z])/\U\1/' <<< "$user")
            fi
          else
            # Service fake user
            user=$(sed -n 's/.*cn=\([^,]*\).*/\1/p' <<< "$line")
          fi
        elif [[ $line == $KEY* ]]; then
          key=$(clean_key_line git "$line")
          if [ ! -z "$key" ]; then
            if [[ $key != *$'\n'* ]] && [[ $key == ssh-* ]]; then
              echo -n 'command="'$GITOLITE_SHELL' '$user'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty '
              echo $key
            fi
          fi
        fi
      fi
    done
  exit 0
fi