1270096Strasz#!/bin/sh
2270096Strasz#
3270096Strasz# $FreeBSD$
4270096Strasz#
5270096Strasz
6270096Strasz# Modify this to suit your needs.  The "$1" is the map name, eg. "auto_master".
7270096Strasz# To debug, simply run this script with map name as the only parameter.  It's
8270096Strasz# supposed to output map contents ("key location" pairs) to standard output.
9270096StraszSEARCHBASE="ou=$1,dc=example,dc=com"
10270096StraszENTRY_ATTRIBUTE="cn"
11270096StraszVALUE_ATTRIBUTE="automountInformation"
12270096Strasz
13270096Strasz/usr/local/bin/ldapsearch -LLL -x -o ldif-wrap=no -b "$SEARCHBASE" "$ENTRY_ATTRIBUTE" "$VALUE_ATTRIBUTE" | awk '
14270096Strasz$1 == "'$ENTRY_ATTRIBUTE':" {
15270096Strasz	key = $2
16270096Strasz}
17270096Strasz
18270096Strasz$1 == "'$VALUE_ATTRIBUTE':" && key {
19270096Strasz	printf "%s%s", key, OFS
20270096Strasz	key = ""
21270096Strasz	for (i=2; i<NF; i++) {
22270096Strasz		printf "%s%s", $(i), OFS
23270096Strasz	}
24270096Strasz	printf "%s%s", $NF, ORS
25270096Strasz}
26270096Strasz
27270096Strasz# Double colon after attribute name means the value is in Base64.
28270096Strasz$1 == "'$VALUE_ATTRIBUTE'::" && key {
29270096Strasz	printf "%s%s", key, OFS
30270096Strasz	key = ""
31270096Strasz	for (i=2; i<NF; i++) {
32270096Strasz		printf "%s%s", $(i), OFS
33270096Strasz	}
34270096Strasz	printf "%s", $NF | "b64decode -rp"
35270096Strasz	close("b64decode -rp")
36270096Strasz	printf "%s", ORS
37270096Strasz}
38270096Strasz'
39