summaryrefslogtreecommitdiffstats
path: root/debian/slapd.postinst
blob: 301572be95164fd7d65f1d4931b75131397f2de9 (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
#! /bin/sh 

set -e

. /usr/share/debconf/confmodule

# This will be replaced with debian/slapd.scripts-common which includes
# various helper functions and $OLD_VERSION and $SLAPD_CONF
#SCRIPTSCOMMON#

postinst_initial_configuration() {					# {{{
# Configure slapd for the first time (when first installed)
# Usage: postinst_initial_configuration

	if manual_configuration_wanted; then
		echo "  Omitting slapd configuration as requested." >&2
	else
		crypt_admin_pass
		create_new_configuration
	fi
}

# }}}
postinst_upgrade_configuration() {					# {{{
# Handle upgrading slapd from some older version
# Usage: postinst_upgrade_configuration

	# Better back up the config file in any case
	backup_config_once

	# Check if the database format has changed.
	if database_format_changed; then

		# During upgrading we have to load the old data
		move_incompatible_databases_away
		if ! load_databases; then
			return 1
		fi
	fi

	# Update permissions of all database directories and /var/run/slapd
	update_databases_permissions
	update_permissions /var/run/slapd

	# Versions prior to 2.4.7-1 could create a slapd.conf that wasn't
	# readable by the openldap user.
	update_permissions "${SLAPD_CONF}"
}

# }}}
# Ignore the init script failure and just calls "true".  This is
# useful when we don't want the failure to interrupt an upgrade
# operation if there's been a failure to upgrade the configuration.
ignore_init_failure() {							# {{{
	if [ "$MODE" = "configure" ] && [ "$FAILED_TO_UPGRADE_CONFIGURATION" -eq 1 ]; then
		true
	fi
}
# }}}

# Create a new user.  Don't create the user, however, if the local
# administrator has already customized slapd to run as a different user.
if [ "$MODE" = "configure" ] || [ "$MODE" = "reconfigure" ] ; then
	if [ "openldap" = "$SLAPD_USER" ] ; then
		create_new_user
	fi
fi

# Initialize the FAILED_TO_UPGRADE_CONFIGURATION variable to 0.  This
# variable will be set if/when there is a failure during the attempt
# to upgrade the existing configuration.  It is useful to determine
# e.g. whether we should ignore the init script failure that will
# likely happen in these scenarios.
FAILED_TO_UPGRADE_CONFIGURATION=0

# Configuration.
if is_initial_configuration "$@"; then
	postinst_initial_configuration
else
	if ! postinst_upgrade_configuration; then
		# An error occurred while attempting to upgrade the
		# current configuration.  This can mean many things,
		# but usually it means that the user is using an
		# unsupported backend.
		#
		# We need to:
		#
		# - Set the FAILED_TO_UPGRADE_CONFIGURATION to 1, in
		#   order to signal that there has been a problem
		#   while upgrading the configuration and the
		#   subsequent slapd init startup failure should not
		#   interefere with a possible dist-upgrade operation
		#   (see the "ignore_init_failure" function).
		#
		# - Display a critical notice to the user letting
		#   him/her know that manual action must be taken
		#   before the slapd can be started again.
		#
		# Note that the slapd service will fail to start after
		# this, but that should be gracefully handled by
		# dh_installinit's --error-handler option.
		FAILED_TO_UPGRADE_CONFIGURATION=1
		db_input critical slapd/postinst_error || true
		db_go || true
	fi
fi

db_stop || true

#DEBHELPER#

exit 0

# vim: set sw=8 foldmethod=marker: