summaryrefslogtreecommitdiffstats
path: root/etc/autofs/include_ldap
blob: 58970c06a4493caf94b631f0a9c8a95a9346a2b5 (plain)
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
34
35
36
37
38
#!/bin/sh
#
# $FreeBSD$
#

# Modify this to suit your needs.  The "$1" is the map name, eg. "auto_master".
# To debug, simply run this script with map name as the only parameter.  It's
# supposed to output map contents ("key location" pairs) to standard output.
SEARCHBASE="ou=$1,dc=example,dc=com"
ENTRY_ATTRIBUTE="cn"
VALUE_ATTRIBUTE="automountInformation"

/usr/local/bin/ldapsearch -LLL -x -o ldif-wrap=no -b "$SEARCHBASE" "$ENTRY_ATTRIBUTE" "$VALUE_ATTRIBUTE" | awk '
$1 == "'$ENTRY_ATTRIBUTE':" {
	key = $2
}

$1 == "'$VALUE_ATTRIBUTE':" && key {
	printf "%s%s", key, OFS
	key = ""
	for (i=2; i<NF; i++) {
		printf "%s%s", $(i), OFS
	}
	printf "%s%s", $NF, ORS
}

# Double colon after attribute name means the value is in Base64.
$1 == "'$VALUE_ATTRIBUTE'::" && key {
	printf "%s%s", key, OFS
	key = ""
	for (i=2; i<NF; i++) {
		printf "%s%s", $(i), OFS
	}
	printf "%s", $NF | "b64decode -rp"
	close("b64decode -rp")
	printf "%s", ORS
}
'
OpenPOWER on IntegriCloud