File: postfix-non-bdb-script

package info (click to toggle)
postfix 3.11.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,668 kB
  • sloc: ansic: 143,638; makefile: 19,474; sh: 7,191; perl: 2,855; python: 1,448; awk: 158
file content (237 lines) | stat: -rw-r--r-- 7,827 bytes parent folder | download
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/sh

#++
# NAME
#	postfix-non-bdb 1
# SUMMARY
#	Postfix non-Berkeley-DB migration
# SYNOPSIS
#	\fBpostfix non-bdb\fR \fIsubcommand\fR
# DESCRIPTION
#	The "\fBpostfix non-bdb \fIsubcommand\fR" feature edits main.cf
#	and master.cf, to manage the migration of an existing Postfix
#	configuration that uses Berkeley DB type "hash:" or "btree:"
#	tables (which are no longer supported on some OS distributions),
#	to supported types such as "cdb:" or "lmdb:".
#
#	The following subcommands are available:
# .IP \fBstatus\fR
#	Reports the non-Berkeley-DB migration status, without making
#	any changes.
# .IP \fBdisable\fR
#	Edits main.cf and master.cf, to turn off the \fBenable-redirect\fR
#	and \fBenable-reindex\fR features.
# .sp
#	This will break integration with other software such as
#	mailman versions from before May 2025 when they want to
#	use "postmap hash:/path/to/file", for example, to update a
#	mailman-maintained table.
# .IP "\fBenable-redirect\fR (aliasing)"
#	Edits main.cf and master.cf, to enable redirection (aliasing)
#	from Berkeley DB types "hash" and "btree" to the non-Berkeley-DB
#	types specified with $default_database_type and
#	$default_cache_db_type. Custom redirection may be configured
#	with non_bdb_custom_mapping.
# .sp
#	This configuration will not automatically create non-Berkeley-DB
#	indexed database files. Instead, Postfix programs will log an
#	error as they fail to open an indexed database file, and will
#	leave it to the system administrator to run postmap(1) or
#	postalias(1) to create that file.
# .sp
#	This will fix integration with other software such as mailman
#	versions from before May 2025 when they want to use "postmap
#	hash:/path/to/file", for example, to update a mailman-maintained
#	table.
# .sp
#	This subcommand will not make any changes when
#	default_database_type or default_cache_db_type specify a hash:
#	or btree: type.
# .IP \fBenable-reindex\fR
#	Edits main.cf and master.cf, to implement \fBenable-redirect\fR,
#	and to automatically create a non-Berkeley-DB indexed database
#	file when a daemon program wants to access a file that does not
#	yet exist. This uses the nbdb_reindexd(8) daemon to run postmap(1)
#	or postalias(1) as described in "SECURITY" below.
# .sp
#	This subcommand immediately generates non-Berkeley-DB indexed
#	files for unprivileged command-line programs that cannot send
#	requests to the nbdb_reindexd(8) daemon server. This involves
#	"hash:" and "btree:" tables that are used by postqueue(1) and
#	sendmail(1) as specified in authorized_flush_users and
#	authorized_mailq_users, and by sendmail(1) and postdrop(1)
#	as specified in authorized_submit_users and
#	local_login_sender_maps.
# .sp
#	This subcommand will not make any changes when
#	default_database_type or default_cache_db_type specify a hash:
#	or btree: type.
# .sp
#	\fINOTE: \fBenable-reindex\fI should be used only temporarily
#	to generate most of the non-Berkeley-DB indexed files that Postfix
#	needs. Leaving this enabled may expose the system to
#	privilege-escalation attacks. There are no security
#	concerns for using \fBenable-redirect\fR.
# SECURITY
# .ad
# .fi
#	The nbdb_reindexd(8) daemon automatically generates a
#	non-Berkeley-DB indexed file only if the database pathname matches
#	the directory prefixes specified with
#	non_bdb_migration_allow_root_prefixes (for files that must be
#	owned by root), or with non_bdb_migration_allow_user_prefixes
#	(for files that must be owned by a non-root user). Additional
#	restrictions on file and directory ownership and permissions
#	are documented in nbdb_reindexd(8).
# CONFIGURATION PARAMETERS
# .ad 
# .fi
#	The "\fBpostfix non-bdb \fIsubcommand\fR" feature
#	updates the following configuration parameter:
# .IP "\fBnon_bdb_migration_level (disable)\fR"
#	The non-Berkeley-DB migration service level.
# .PP
#	Other relevant parameters:
# .IP "\fBnon_bdb_custom_mapping (empty)\fR"
#	When non-Berkeley-DB migration is enabled, an optional mapping
#	from a hash: or btree: type to a non-Berkeley-DB type.
# .IP "\fBnon_bdb_migration_allow_root_prefixes (see 'postconf -d non_bdb_migration_allow_root_prefixes' output)\fR"
#	A list of trusted pathname prefixes that must be matched when
#	the non-Berkeley-DB migration service (\fBnbdb_reindexd\fR(8)) needs to
#	run \fBpostmap\fR(1) or \fBpostalias\fR(1) commands with "root" privilege.
# .IP "\fBnon_bdb_migration_allow_user_prefixes (see 'postconf -d non_bdb_migration_allow_user_prefixes' output)\fR"
#	A list of trusted pathname prefixes that must be matched when
#	the non-Berkeley-DB migration service (\fBnbdb_reindexd\fR(8)) needs to
#	run \fBpostmap\fR(1) or \fBpostalias\fR(1) commands with non-root privilege.
# SEE ALSO
#	nbdb_reindexd(8) reindexing service
# README FILES
# .ad
# .fi
#	Use "\fBpostconf readme_directory\fR" or
#	"\fBpostconf html_directory\fR" to locate this information.
# .na
# .nf
#	NON_BERKELEYDB_README, migration guide
# LICENSE
# .ad
# .fi
#	The Secure Mailer license must be distributed with this software.
# HISTORY
#	The "\fBpostfix non-bdb\fR" command was introduced with Postfix
#	version 3.11.
# AUTHOR(S)
#	Wietse Venema
#	porcupine.org
#--

umask 022
SHELL=/bin/sh

case $command_directory in
"") echo This script must be run by the postfix command. 1>&2
    echo Do not run directly. 1>&2 exit 1;; esac

cd $command_directory || {
    # Let's hope there's a "postlog" somewhere on the PATH
    FATAL="postlog -p fatal -t $MAIL_LOGTAG/postfix-tls-script"
    msg="no Postfix command directory '${command_directory}'"
    $FATAL "$msg" || { echo "$msg" >&2; sleep 1; }
    exit 1
}

postconf=$command_directory/postconf
LOGGER="$command_directory/postlog -t $MAIL_LOGTAG/postfix-non-bdb-script"
INFO="$LOGGER -p info"
WARN="$LOGGER -p warn"
ERROR="$LOGGER -p error"
FATAL="$LOGGER -p fatal"

REINDEX_SVC=nbdb_reindex
REINDEX_BIN=nbdb_reindexd

# Helper functions.

reindex_for_non_daemons() {
    # The following tables are needed by unprivileged command-line
    # tools that cannot send requests to the reindexing service unless
    # they are run by root.
    for type_name in `$postconf -h authorized_flush_users \
        authorized_mailq_users authorized_submit_users \
        local_login_sender_maps`; \
    do
        case $type_name in
            hash:*|btree:*)
                $INFO Proactively reindexing $type_name
                postmap $type_name || exit 1;;
        esac
    done
}

validate_redirect_targets() {
    # By default, the Berkeley DB type 'hash' will redirect to
    # $default_database_type, and type 'btree' will redirect to
    # $default_cache_db_type. Require that the targets are not
    # Berkeley DB types.
    for param in default_database_type default_cache_db_type
    do
	eval type="`$postconf -h $param`"
	case $type in
	hash|btree)
	    $FATAL "parameter $param specifies a Berkeley DB type: '$type'"
	    exit 1;;
	esac
    done
}

# Subcommand implementations.

status() {
    $postconf -h non_bdb_migration_level
}

disable_all() {
    $postconf -X non_bdb_migration_level
    $postconf -MX ${REINDEX_SVC}/unix
}

enable_redirect() {
    validate_redirect_targets
    $postconf -MX ${REINDEX_SVC}/unix
    $postconf non_bdb_migration_level=enable-redirect || exit 1
}

enable_reindex() {
    validate_redirect_targets
    reindex_for_non_daemons
    $postconf -M \
	${REINDEX_SVC}/unix="${REINDEX_SVC} unix y n n - 1 ${REINDEX_BIN}" || exit 1
    $postconf non_bdb_migration_level=enable-reindex || exit 1
}

usage() {
    $FATAL "usage: postfix non-bdb status (or enable-redirect, or enable-reindex, or disable)"
    exit 1
}

#
# Parse JCL
#
case $# in
  1) ;;
  *) usage;;
esac

case "$1" in
enable-redirect)
   enable_redirect;;
enable-reindex)
    enable_reindex;;
disable)
    disable_all;;
status)
    status;;
*) usage
esac

exit 0