2 # Update the list of TCP ports Sendmail uses
4 require './sendmail-lib.pl';
5 require './features-lib.pl';
8 &error_setup($text{'ports_err'});
9 $access{'ports'} || &error($text{'ports_ecannot'});
11 # Parse and validate inputs
13 if (!$in{'ports_def'}) {
14 for($i=0; defined($name=$in{"name_$i"}); $i++) {
17 $name =~ /^[a-z0-9\_]+$/i || &error(&text('ports_ename', $i+1));
18 $done{$name}++ && &error(&text('ports_eclash', $i+1));
19 @opts = ( "Name=$name" );
22 if (!$in{"addr_${i}_def"}) {
23 &check_ipaddress($in{"addr_$i"}) ||
24 &check_ip6address($in{"addr_$i"}) ||
25 &error(&text('ports_eaddr', $i+1));
26 push(@opts, "Address=".$in{"addr_$i"});
30 if ($in{"family_${i}"}) {
31 push(@opts, "Family=".$in{"family_${i}"});
35 if (!$in{"port_${i}_def"}) {
36 $in{"port_$i"} =~ /^\d+$/ && $in{"port_$i"} > 0 &&
37 $in{"port_$i"} < 65536 ||
38 getservbyname($in{"port_$i"}, "tcp") ||
39 &error(&text('ports_eport', $i+1));
40 push(@opts, "Port=".$in{"port_$i"});
44 @mods = split(/\0/, $in{"mod_$i"});
46 push(@opts, "Modifiers=".join("", @mods));
50 push(@opts, split(/,/, $in{"other_$i"}));
51 push(@ports, join(",", @opts));
56 &lock_file($config{'sendmail_cf'});
57 $conf = &get_sendmailcf();
58 @oldlist = map { $_->[0] } &find_options("DaemonPortOptions", $conf);
59 @newlist = map { { 'type' => 'O',
60 'values' => [ " DaemonPortOptions=$_" ] } } @ports;
61 &save_directives($conf, \@oldlist, \@newlist);
62 &flush_file_lines($config{'sendmail_cf'});
63 &unlock_file($config{'sendmail_cf'});
65 # Update .mc file too, if we have one
66 if ($features_access) {
67 @features = &list_features();
69 &lock_file($config{'sendmail_mc'});
70 @dpa = grep { $_->{'type'} == 0 &&
71 $_->{'text'} =~ /^DAEMON_OPTIONS/ } @features;
72 for($i=0; $i<@dpa || $i<@ports; $i++) {
73 if ($dpa[$i] && $ports[$i]) {
76 "DAEMON_OPTIONS(`$ports[$i]')";
77 &modify_feature($dpa[$i]);
79 elsif ($dpa[$i] && !$ports[$i]) {
80 # No longer needed .. delete
81 &delete_feature($dpa[$i]);
83 elsif (!$dpa[$i] && $ports[$i]) {
86 'text' => "DAEMON_OPTIONS(`$ports[$i]')" };
90 &unlock_file($config{'sendmail_mc'});