summaryrefslogtreecommitdiff
path: root/debian/local/update_ldap
blob: 4b6abc774dfe23f94d5f86f1fc4aeacb5885daa6 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh -e
#-----------------------------------------------------------------------------
#
# $Sendmail: update_ldap,v 8.14.4 2010-10-16 19:38:59 cowboy Exp $
#
# Sendmail support for LDAP
#
# Copyright (c) 2000-2010 Richard Nelson.  All Rights Reserved.
#
# Notes: supports local umich-ldap and openldap v1/v2 servers
#
#-----------------------------------------------------------------------------
set -e

#
# Flag to determine if this is an install or update
NEW=0;

#
# Flag to determine if any local LDAP server was found
FOUND=0;

#
# Path to LDAP server schema directory
LDAP_PATH=;
SCHEMA_PATH=;
SCHEMA_NAME=;
LDAP_VERSION=;

# Path to other sendmail helpers
if [ -x ./update_sendmail ]; then
	sm_path='.';
elif [ -x $(dirname $0)/update_sendmail ]; then
	sm_path=$(dirname $0);
else
	sm_path=/usr/share/sendmail;
	fi;
# Bring in sendmail.conf for the network definitions
if [ ! -f /etc/mail/sendmail.conf ]; then
	if [ -x $sm_path/update_conf ]; then
		$sm_path/update_conf;
		fi;
	fi; 
if [ -f /etc/mail/sendmail.conf ]; then
	. /etc/mail/sendmail.conf;
	fi;
if [ "$HANDS_OFF" != 'No' ]; then
	exit 0;
	fi;

install_schema () {
#
# Install sendmail.schema in the appropriate place
#
if [ ! -z "$SCHEMA_PATH" ]; then
	if [ -f "${LDAP_PATH}/slapd.conf" ]; then
		FOUND=1;
		if [ ! -e "${SCHEMA_PATH}/sendmail.schema" ]; then
			NEW=1;
			fi;
		cp -p /usr/share/sendmail/examples/ldap/$SCHEMA_NAME \
			$SCHEMA_PATH/sendmail.schema;
		chmod 0644 $SCHEMA_PATH/sendmail.schema;
		chown root:root $SCHEMA_PATH/sendmail.schema;
		fi;
	fi;
	};

#
# Check if OpenLDAP (2.0.x) is installed
if [ -d /etc/ldap ]; then
	LDAP_VERSION="$LDAP_VERSION OpenLDAP V2";
	LDAP_PATH='/etc/ldap';
	SCHEMA_PATH="${LDAP_PATH}/schema";
	SCHEMA_NAME=sendmail.schema.v2;
	install_schema;
	fi;

#
# Check if OpenLDAP (1.x.x) is installed
if [ -d /etc/openldap ]; then
	LDAP_VERSION="$LDAP_VERSION OpenLDAP V1";
	LDAP_PATH='/etc/openldap';
	SCHEMA_PATH="${LDAP_PATH}";
	SCHEMA_NAME=sendmail.schema.v1;
	install_schema;
	fi;

#
# Check if UMich-LDAP (3.3) is installed
if [ -d /etc/umich-ldap ]; then
	LDAP_VERSION="$LDAP_VERSION UMich-LDAP V3";
	LDAP_PATH='/etc/umich-ldap';
	SCHEMA_PATH="${LDAP_PATH}";
	SCHEMA_NAME=sendmail.schema.v1;
	install_schema;
	fi;

#
# Tell them about the new wizbang features...
if [ $NEW -eq 0 ]; then
	:;
else
	echo " ";
	echo "Creating/Updating $LDAP_VERSION information...";
	echo " ";
	echo "$SCHEMA_PATH/sendmail.schema has been installed";
	fi;

if [ $FOUND -eq 0 ] && [ $NEW -eq 1 ]; then
	cat <<-EOT

	No local LDAP server was located (tried openldap v2/v1, umich-ldap).

	If you wish to use sendmail and LDAP, you'll need to make sure your
	server has the requisite schema setup.

	You can find the schema (old and new) in the following places:
	  * $SCHEMA_PATH/sendmail.schema for the version of LDAP you
		currently have installed (if any)
	  * /usr/share/sendmail/examples/ldap/sendmail.schema.<v>
		where <v> is
			<v1> for older schema (sendmail.{o,a}t.conf) format
			<v2> for newer schema (sendmail.schema) format

	If you later install a local LDAP server, be sure to re-run $0.
	EOT
elif [ $FOUND -eq 1 ] && [ $NEW -eq 1 ]; then
	cat <<-EOT

	You have a local $LDAP_VERSION server! Depending upon how (and if)
	you wish to use LDAP with sendmail, you'll want to check your
	slapd.conf file and possibly include these files:
	  * $SCHEMA_PATH/sendmail.schema   <- alias and other map support
	  * $SCHEMA_PATH/misc.schema	   <- OpenLDAP V2 ldap-mail-routing

	If you later change your local LDAP server, be sure to re-run $0.
	EOT
	fi;