summaryrefslogtreecommitdiffstats
path: root/contrib/utils/ldap_groups.sh
blob: 01bf5ee77c1c4880659a7e1fa72c56c3bef3e092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

# author: damien.nozay@gmail.com

# Given a username,
# Provides a space-separated list of groups that the user is a member of.
#
# see http://gitolite.com/gitolite/conf.html#ldap
# GROUPLIST_PGM => /path/to/ldap_groups.sh

ldap_groups() {
    username=$1;
    # this relies on openldap / pam_ldap to be configured properly on your
    # system. my system allows anonymous search.
    echo $(
        ldapsearch -x -LLL "(&(objectClass=posixGroup)(memberUid=${username}))" cn \
        | grep "^cn" \
        | cut -d' ' -f2
    );
}

ldap_groups $@