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 12 open(POSTCONF, "$POSTCONF -d|") || die "cannot run $POSTCONF -d: !$\n"; 13 while(<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 } 25 close(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; 31 alias_database 32 alias_maps 33 command_directory 34 command_expansion_filter 35 config_directory 36 daemon_directory 37 default_database_type 38 default_rbl_reply 39 execution_directory_expansion_filter 40 export_environment 41 forward_expansion_filter 42 forward_path 43 html_directory 44 import_environment 45 mail_release_date 46 mail_spool_directory 47 mail_version 48 mailbox_delivery_lock 49 mailq_path 50 manpage_directory 51 mydomain 52 myhostname 53 mynetworks 54 newaliases_path 55 parent_domain_matches_subdomains 56 proxy_read_maps 57 queue_directory 58 readme_directory 59 sendmail_path 60 smtpd_expansion_filter 61 tls_random_source 62 virtual_mailbox_lock 63 milter_connect_macros 64 milter_helo_macros 65 milter_mail_macros 66 milter_rcpt_macros 67 milter_data_macros 68 milter_unknown_command_macros 69 milter_end_of_data_macros 70 EOF 71 72 for $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 83 while(<>) { 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 118 if ($name && $text) { 119 $defval = $defaults{$name} if (defined($defaults{$name})); 120 print "%PARAM $name $defval\n$text"; 121 } 122