1#!/usr/bin/perl 2 3# Usage: xpostdef postconf.proto >postconf.proto.new 4 5# Update parameter default values in postconf prototype file. 6 7$POSTCONF="postconf"; 8 9# Read all the default parameter values. This also provides us with 10# a list of all the parameters that postconf knows about. 11 12open(POSTCONF, "$POSTCONF -d|") || die "cannot run $POSTCONF -d: !$\n"; 13while(<POSTCONF>) { 14 chop; 15 if (($name, $defval) = split(/\s+=\s+/, $_, 2)) { 16 $defval =~ s/&/\&/g; 17 $defval =~ s/</\</g; 18 $defval =~ s/>/\>/g; 19 $defval =~ s/\s+$//; 20 $defaults{$name} = $defval; 21 } else { 22 die "unexpected $POSTCONF output: $_\n"; 23 } 24} 25close(POSTCONF) || die "$POSTCONF failed: $!\n"; 26 27# Censor out default values that are system or version dependent, or 28# that don't display well. 29 30$censored = <<EOF; 31alias_database 32alias_maps 33command_directory 34command_expansion_filter 35config_directory 36daemon_directory 37default_database_type 38default_rbl_reply 39execution_directory_expansion_filter 40export_environment 41forward_expansion_filter 42forward_path 43html_directory 44import_environment 45mail_release_date 46mail_spool_directory 47mail_version 48mailbox_delivery_lock 49mailq_path 50manpage_directory 51mydomain 52myhostname 53mynetworks 54newaliases_path 55parent_domain_matches_subdomains 56proxy_read_maps 57queue_directory 58readme_directory 59sendmail_path 60smtpd_expansion_filter 61tls_random_source 62virtual_mailbox_lock 63milter_connect_macros 64milter_helo_macros 65milter_mail_macros 66milter_rcpt_macros 67milter_data_macros 68milter_unknown_command_macros 69milter_end_of_data_macros 70EOF 71 72for $name (split(/\s+/, $censored)) { 73 $defaults{$name} = "see \"postconf -d\" output"; 74} 75 76# Process the postconf prototype file, and update default values 77# with output from the postconf command. Leave alone any defaults 78# that postconf didn't know about. This can happen when conditional 79# features have been compile time disabled. 80 81$name = $defval = $text = $line = ""; 82 83while(<>) { 84 if (/^%PARAM/) { 85 86 # Print the updated parameter text. Keep the old default if 87 # postconf doesn't have a suitable one. 88 89 if ($name) { 90 $defval = $defaults{$name} if (defined($defaults{$name})); 91 print "%PARAM $name $defval\n"; 92 } 93 print $text; 94 95 # Reset the parameter name, default, and accumulated text. 96 97 $name = $defval = $text = $line = ""; 98 99 # Accumulate the parameter name and default value. 100 101 do { 102 $_ =~ s/\s+$//; 103 $line .= " " . $_; 104 } while(($_ = <POSTCONF>) && /^../); 105 ($junk, $class, $name, $defval) = split(/\s+/, $line, 4); 106 } else { 107 108 # Accumulate the text in the parameter definition. 109 110 $_ =~ s/\s+$/\n/; 111 $text .= $_; 112 113 } 114} 115 116# Fix the last parameter. 117 118if ($name && $text) { 119 $defval = $defaults{$name} if (defined($defaults{$name})); 120 print "%PARAM $name $defval\n$text"; 121} 122