2
#-----------------------------------------------------------------------------
4
# $Sendmail: update_db,v @sm_version@ @sm_date@ @sm_time@ cowboy Exp $
6
# Update Sendmail databases for Debian
8
# Copyright (c) 1998-@SM_CPYRT@ Richard Nelson. All Rights Reserved.
11
# * assumes makemap dbtype /etc/mail/database < /etc/mail/database
14
# * changes made herein *must* be reflected in
15
# parse_mc,update_mk,update_db,debian.m4
16
# * multiple db options not supported
17
# * userdb can also have multiple databases and then a forward!
18
# * need sendmail stop/start
20
#-----------------------------------------------------------------------------
23
# List of db files/features/etc
24
db_files="databases Makefile crontab QUEUE_GROUP sendmail.cf submit.cf \
25
confCR_FILE confCT_FILE confCW_FILE confUSERDB_SPEC \
26
access_db authinfo bitdomain domaintable \
27
genericstable mailertable uucpdomain \
28
use_cw_file use_ct_file virtusertable ALIAS_FILE";
30
# Path to other sendmail helpers
31
if [ -x ./update_sendmail ]; then
33
elif [ -x $(dirname $0)/update_sendmail ]; then
34
sm_path=$(dirname $0);
36
sm_path=@datadir@/sendmail;
38
# Bring in sendmail.conf for the network definitions
39
if [ ! -f @sysconfdir@/mail/sendmail.conf ]; then
40
if [ -x $sm_path/update_conf ]; then
44
if [ -f @sysconfdir@/mail/sendmail.conf ]; then
45
. @sysconfdir@/mail/sendmail.conf;
47
if [ "$HANDS_OFF" != 'No' ]; then
51
# control amount of output
54
# flag used to ensure only one newaliases command is run
57
# flag used to indicate a dataset has been moved, may need another update
67
#-------------------------------------------------------------
68
# Initial update of sendmail.mc/databases
69
#-------------------------------------------------------------
71
if [ $verbosity -gt 1 ]; then
74
# Sigh... I wish this was in Perl...
75
$sm_path/parse_mc || true;
78
#-------------------------------------------------------------
79
# Handle found databases
80
#-------------------------------------------------------------
82
if [ $verbosity -gt 1 ]; then
83
echo "is_found: $dbfeat - $dbname";
89
if [ -f @sysconfdir@/mail/aliases ] & [ ! -f /etc/aliases ]; then
90
echo "Moving @sysconfdir@/mail/aliases to /etc/aliases";
91
mv @sysconfdir@/mail/aliases /etc/aliases;
92
ln -sf ../aliases @sysconfdir@/mail/aliases;
96
if [ ! -f @datadir@/sendmail/cf/feature/msp.m4 ]; then
97
rm -f @sysconfdir@/mail/submit.cf 2>/dev/null;
98
rm -f @sysconfdir@/mail/submit.cf.errors 2>/dev/null;
107
#-------------------------------------------------------------
108
# Handle missing databases:
109
# moving /etc/xxx to /etc/mail/xxx
110
# rename /etc/mail/xxx to /etc/mail/yyy
111
#-------------------------------------------------------------
115
echo "Moving $1 to $dbname.";
117
chown root:smmsp $dbname;
119
if [ -f $1.db ]; then
120
mv -f /etc/$1.db $dbname.db;
122
if [ -f $1.pag ]; then
123
mv -f /etc/$1.pag $dbname.pag;
125
if [ -f $1.dir ]; then
126
mv -f /etc/$1.dir $dbname.dir;
131
echo "$1 is a link, move it to $dbname";
132
if [ "$dbopts" = "-o" ]; then
133
missing_opt=`expr $missing_opt + 1`;
135
missing_rqd=`expr $missing_rqd + 1`;
145
if [ -f @sysconfdir@/mail/$1 ]; then
146
echo "Renaming @sysconfdir@/mail/$1 to $dbname.";
147
mv @sysconfdir@/mail/$1 $dbname;
148
chown root:smmsp $dbname;
159
if [ $verbosity -gt 1 ]; then
160
echo "is_not_found: $dbfeat - $dbname";
167
use_cw_file|confCW_FILE)
168
if move_file /etc/local-host-names; then
170
elif rename_file sendmail.cw; then
172
elif move_file /etc/sendmail.cw; then
175
missing_cre=`expr $missing_cre + 1`;
176
echo "Warning: $dbfeat source" \
177
"file not found: $dbname";
178
echo " it was created";
179
echo "localhost" > $dbname;
180
echo `hostname -f` >> $dbname;
181
chown root:smmsp $dbname;
185
use_ct_file|confCT_FILE)
186
if move_file /etc/trusted-users; then
188
elif rename_file sendmail.ct; then
190
elif move_file /etc/sendmail.ct; then
193
missing_cre=`expr $missing_cre + 1`;
194
echo "Warning: $dbfeat source" \
195
"file not found: $dbname";
196
echo " it was created";
198
chown root:smmsp $dbname;
203
if move_file /etc/sendmail.hf; then
205
elif rename_file sendmail.hf; then
208
echo "Error: $dbfeat source file not found: $dbname";
209
missing_rqd=`expr $missing_rqd + 1`;
214
if [ -e /etc/$dbsname ]; then
215
echo "Linking /etc/$dbsname to $dbname";
216
ln -sf ../$dbsname $dbname;
217
if [ -f /etc/$dbsname.db ]; then
218
mv /etc/$dbsname.db @sysconfdir@/mail;
220
if [ -f /etc/$dbsname.pag ]; then
221
mv /etc/$dbsname.pag @sysconfdir@/mail;
223
if [ -f /etc/$dbsname.dir ]; then
224
mv /etc/$dbsname.dir @sysconfdir@/mail;
226
elif [ "$dbopts" = "-o" ]; then
227
echo "Informational: $dbfeat source" \
228
"file not found: $dbname";
229
missing_opt=`expr $missing_opt + 1`;
232
echo "Error: $dbfeat source file not found: $dbname";
233
missing_rqd=`expr $missing_rqd + 1`;
238
mcfile=$(echo "$dbsname" | sed -e 's/\..*//')
239
if move_file /etc/$dbsname; then
240
if [ -f @sysconfdir@/${mcfile}.cf ]; then
241
mv -f @sysconfdir@/${mcfile}.cf @sysconfdir@/mail/;
243
elif [ "$mcfile" = "sendmail" ]; then
244
cp @datadir@/sendmail/cf/debian/sendmail.mc \
246
chown root:smmsp $dbname;
248
elif [ "$mcfile" = "submit" ]; then
249
cp @datadir@/sendmail/cf/debian/submit.mc \
251
chown root:smmsp $dbname;
253
elif [ "$dbopts" = "-o" ]; then
254
echo "Informational: $dbfeat source" \
255
"file not found: $dbname";
256
missing_opt=`expr $missing_opt + 1`;
259
echo "Error: $dbfeat source file not found: $dbname";
260
missing_rqd=`expr $missing_rqd + 1`;
265
echo "Warning: $dbfeat source" \
266
"file not found: $dbname";
267
echo " it was created";
269
chown root:smmsp $dbname;
273
if [ -x $sm_path/update_conf ]; then
274
$sm_path/update_conf;
278
missing_cre=`expr $missing_cre + 1`;
279
echo "Warning: $dbfeat source" \
280
"file not found: $dbname";
281
echo " it was created";
282
cp @datadir@/sendmail/examples/db/access \
284
chown root:root $dbname;
288
if move_file /etc/$dbsname; then
290
elif [ "$dbopts" = "-o" ]; then
293
missing_cre=`expr $missing_cre + 1`;
294
echo "Warning: $dbfeat source" \
295
"file not found: $dbname";
296
echo " it was created";
298
chown root:smmsp $dbname;
305
#-------------------------------------------------------------
306
# Handle empty databases
307
#-------------------------------------------------------------
309
if [ $verbosity -gt 1 ]; then
310
echo "is_empty: $dbfeat - $dbname";
312
if [ $process -eq 1 ]; then
313
if [ "$dbtype" != "-" ]; then
323
cp @datadir@/sendmail/examples/db/access \
325
chown root:root $dbname;
329
echo "Informational: $dbfeat file empty: $dbname";
330
if [ "$dbopts" = "-o" ]; then
338
#-------------------------------------------------------------
339
# Handle no data (exists, but is only comments) databases
340
#-------------------------------------------------------------
342
if [ $verbosity -gt 1 ]; then
343
echo "is_comments: $dbfeat - $dbname";
345
if [ $process -eq 1 ] && [ -s "$dbname" ]; then
346
if [ "$dbtype" != "-" ]; then
356
echo "Informational: $dbfeat no data: $dbname";
357
if [ "$dbopts" = "-o" ]; then
365
#-------------------------------------------------------------
366
# Handle normal databases (exists, has data)
367
#-------------------------------------------------------------
369
if [ $verbosity -gt 1 ]; then
370
echo "is_normal: $dbfeat - $dbname";
373
# Make sure sensitive databases are *not* generally readable
374
if [ "$dbsname" = "authinfo" ] \
375
|| [ "$dbsname" = "access" ]; then
376
chmod go-rwx $dbname;
379
if [ $process -eq 1 ] && [ $max_rc -eq 0 ]; then
385
$sm_path/parse_mc || true;
388
$sm_path/update_conf || true;
391
$sm_path/update_mk || true;
394
echo "Updating $dbname...";
395
@sbindir@/makemap -d $dbtype $dbname.new.db < $dbname;
396
chown root:smmsp $dbname.new.db;
397
chmod 0644 $dbname.new.db;
398
mv -f $dbname.new.db $dbname.db;
401
echo "Updating $dbname...";
402
@sbindir@/makemap $dbtype $dbname.new.db < $dbname;
403
if [ "$dbsname" = "authinfo" ] \
404
|| [ "$dbsname" = "access" ]; then
405
chown smmta:smmsp $dbname.new.db;
406
chmod 0640 $dbname.new.db;
408
chown root:smmsp $dbname.new.db;
409
chmod 0640 $dbname.new.db;
411
mv -f $dbname.new.db $dbname.db;
414
echo "Updating $dbname...";
415
if [ $newaliases_run -eq 0 ]; then
417
@libexecdir@/newaliases || true;
419
if [ -f $dbname.db ]; then
420
chown smmta:smmsp $dbname.db;
421
chmod 0640 $dbname.db;
425
mcfile=$(echo "$dbsname" | sed -e 's/\..*//');
426
echo "Creating @sysconfdir@/mail/${mcfile}.cf...";
427
rm -f @sysconfdir@/mail/${mcfile}.cf.errors;
428
m4 @sysconfdir@/mail/${mcfile}.mc \
429
> @sysconfdir@/mail/${mcfile}.cf.new \
430
2> @sysconfdir@/mail/${mcfile}.cf.errors || true;
431
echo "### @sysconfdir@/mail/${mcfile}.mc ###" \
432
>> @sysconfdir@/mail/${mcfile}.cf.new;
433
sed -e 's/^/# /' @sysconfdir@/mail/${mcfile}.mc \
434
>> @sysconfdir@/mail/${mcfile}.cf.new;
435
chown root:smmsp @sysconfdir@/mail/${mcfile}.cf.new;
436
chmod 0644 @sysconfdir@/mail/${mcfile}.cf.new;
437
if [ ! -s @sysconfdir@/mail/${mcfile}.cf.errors ]; then
438
rm -f @sysconfdir@/mail/${mcfile}.cf.errors;
440
chown root:smmsp @sysconfdir@/mail/${mcfile}.cf.errors;
441
cat @sysconfdir@/mail/${mcfile}.cf.errors;
445
# Can't tell if the errors are fatal or not ;-{
446
mv -f @sysconfdir@/mail/${mcfile}.cf.new \
447
@sysconfdir@/mail/${mcfile}.cf;
450
echo "$dbtype map not done herein";
456
#-------------------------------------------------------------
458
#-------------------------------------------------------------
460
if [ $verbosity -gt 1 ]; then
466
# status report if not for single database
468
echo "Checking {sendmail,submit}.mc and related databases...";
475
for file in $db_files; do \
476
line=$(grep -Ee "^[[:space:]]*$file" \
477
@sysconfdir@/mail/databases || true);
478
while ([ "$line" != "" ]); do
479
str=$(echo "$line" | cut -d "
481
line=$(echo "$line" | cut -d "
484
# Strip line back into four pieces: feature, type, opts, name
485
dbfeat=$(echo "$str" | cut -d ":" -f 1);
486
dbtype=$(echo "$str" | cut -d ":" -f 2);
487
dbopts=$(echo "$str" | cut -d ":" -f 3);
488
dbname=$(echo "$str" | cut -d ":" -f 4);
489
dbregx=$(echo "$str" | cut -d ":" -f 5);
490
if [ $(dirname "$dbname") = "@sysconfdir@/mail" ]; then
491
dbsname=$(basename "$dbname");
492
elif [ $(dirname "$dbname") = "@sysconfdir@" ]; then
493
dbsname=$(basename "$dbname");
497
if [ "$dbopts" = "-" ]; then
500
if [ "$dbregx" = "-" ]; then
504
# Check to see if we're doing one, or all
505
if [ ! -z "$1" ]; then
506
if [ "$1" = "$dbfeat" ] \
507
|| [ "$1" = "$dbname" ] \
508
|| [ "$1" = "$dbsname" ]; then
515
# Check for special database types
518
if [ $verbosity -gt 0 ]; then
519
echo "Skipping $dbname...";
524
if [ ! -x @libexecdir@/makemap ]; then
525
echo "Delaying $dbname...";
530
if [ ! -x @libexecdir@/newaliases ]; then
531
echo "Delaying $dbname...";
539
# Kluge for aliases...
540
if [ "$dbname" = "ldap" ]; then
545
if [ $verbosity -gt 0 ]; then
546
echo "Processing $dbname...";
549
# Check for database existance
550
if [ -f "$dbname" ] || [ -d "$dbname" ]; then
556
# Skip the rest for directories
557
if [ ! -d "$dbname" ]; then
559
# Check for something in database
560
if [ ! -s "$dbname" ]; then
564
# Check for real data (not just comments)
565
if [ $process -eq 1 ]; then
566
if ! grep -qEe "^[[:space:]]*[^$\#]" $dbname; then
571
# Finally, assume a normal file...
581
if [ $changed -ne 0 ]; then
583
echo "Informational: Some changes were made to file locations";
584
echo " Make sure sendmail.cf is rebuilt";
585
if [ $max_rc -lt 1 ]; then
589
if [ $missing_opt -ne 0 ]; then
591
echo "Informational: $missing_opt optional database(s) sources";
592
echo " were not found, please investigate.";
594
if [ $missing_cre -ne 0 ]; then
596
echo "Warning: $missing_cre database(s) sources";
597
echo " were not found, (but were created)";
598
echo " please investigate.";
600
if [ $missing_rqd -ne 0 ]; then
602
echo "Error: $missing_rqd required database(s) sources";
603
echo " were not found, correct this before starting sendmail!";
604
if [ $max_rc -lt 2 ]; then
608
if [ $missing_opt -ne 0 ] || [ $missing_rqd -ne 0 ]; then
610
echo "$0 assumes that databases, and their source datasets";
611
echo "have the same base name (not counting the .db). If this is not";
612
echo "true, $0 can not rebuild your databases to make sure";
613
echo "they will work with the newer sendmail. You will have to do this";
614
echo "yourself - before starting sendmail.";
617
if [ $m4_errors -ne 0 ]; then
619
echo "Warning: These messages were issued while creating sendmail.cf";
620
echo " make sure they are benign before starting sendmail!";
622
if [ -f @sysconfdir@/mail/sendmail.cf.errors ]; then
623
echo "Errors in generating sendmail.cf";
624
cat @sysconfdir@/mail/sendmail.cf.errors;
626
if [ -f @sysconfdir@/mail/submit.cf.errors ]; then
627
echo "Errors in generating submit.cf";
628
cat @sysconfdir@/mail/submit.cf.errors;
631
if [ $max_rc -lt 2 ]; then