mpaperno / spampd

SpamPD - Spam Proxy Daemon. A spam-filtering SMTP/LMTP proxy server using SpamAssassin in Perl. Since 2002.
GNU General Public License v3.0
34 stars 9 forks source link

syntax error at /usr/sbin/spampd line 1386, near "}{" #30

Closed realsimix closed 3 years ago

realsimix commented 3 years ago

Hi,

I've tried to update my spampd packages to 2.60 but got this error on RHEL7:

spampd: syntax error at /usr/sbin/spampd line 1386, near "}{"
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1387.
spampd: Global symbol "$k" requires explicit package name at /usr/sbin/spampd line 1388.
spampd: Global symbol "$k" requires explicit package name at /usr/sbin/spampd line 1388.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1389.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1389.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1389.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1390.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1390.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1390.
spampd: Global symbol "$k" requires explicit package name at /usr/sbin/spampd line 1391.
spampd: Global symbol "$v" requires explicit package name at /usr/sbin/spampd line 1391.
spampd: Global symbol "$exit" requires explicit package name at /usr/sbin/spampd line 1394.
spampd: Global symbol "$exit" requires explicit package name at /usr/sbin/spampd line 1394.
spampd: syntax error at /usr/sbin/spampd line 1395, near "}"
spampd: /usr/sbin/spampd has too many errors.

Commenting out the offending lines makes it start up:

--- /usr/sbin/spampd.orig   2021-07-28 17:00:23.000000000 +0200
+++ /usr/sbin/spampd    2021-07-29 12:25:18.402015655 +0200
@@ -1382,14 +1382,14 @@
   print "# Configuration options for ".ref($self)." v".$self->VERSION." with ".$type." values.\n";
   print "# This format is suitable as a configuration file. Just remove\n".
         "# the '#' marks (comment characters) and change values as needed.\n\n" if $exit > -1;
-  for my $k (sort keys %{$opts}) {
-    my $v = %{$opts}{$k};
-    next if ref($v) !~ /SCALAR|REF/;
-    $k = $1 if $k =~ /([\w-]+).*/;
-    $v = defined(${$v}) ? ${$v} : "(undefined)";
-    $v = join(":", @{$v}) if ref($v) eq 'ARRAY';
-    printf("# %-24s %s\n", $k, $v);
-  }
+#  for my $k (sort keys %{$opts}) {
+#    my $v = %{$opts}{$k};
+#    next if ref($v) !~ /SCALAR|REF/;
+#    $k = $1 if $k =~ /([\w-]+).*/;
+#    $v = defined(${$v}) ? ${$v} : "(undefined)";
+#    $v = join(":", @{$v}) if ref($v) eq 'ARRAY';
+#    printf("# %-24s %s\n", $k, $v);
+#  }

Maybe this is because perl is too old (perl-5.16.3)? Do you have an idea how to make this work here?

Thank you from a long time spampd user, Simon

realsimix commented 3 years ago

Here is a second issue which I worked around by commenting out:

Error in option spec: "hh|??:s"
Error in option spec: "hhh|???:s"
Error in option spec: "hhhh|????|man:s"
realsimix commented 3 years ago

And this one also:

Name "Data::Dumper::Sparseseen" used only once: possible typo at /usr/sbin/spampd line 1429.
Name "Data::Dumper::Quotekeys" used only once: possible typo at /usr/sbin/spampd line 1428.
Name "Data::Dumper::Sortkeys" used only once: possible typo at /usr/sbin/spampd line 1429.
Name "Data::Dumper::Bless" used only once: possible typo at /usr/sbin/spampd line 1428.
mpaperno commented 3 years ago

Hi Simon!

For the first one, please try replacing line 1386 with:

    my $v = $opts->{$k};

Not sure why I even used the other more obscure syntax in the first place.

Indeed, 5.16 is a bit dated... (though not as dated as spampd) :-) 5.28.1 is what I was mostly testing with... which is from 2018.

Error in option spec: "hh|??:s"

This is coming from Getopt::Long? If so I can only guess it's a version thing... since it's a Perl standard package. Not sure if you can update that separately... but in any case commenting those out won't hurt anything. I'd be curious if there was some version of those which worked (or what actually causes the error).

Name "Data::Dumper::Sparseseen" used only once: possible typo at /usr/sbin/spampd line 1429.

Is that an error or warning? I do vaguely remember those settings gave me some grief, but I'm not getting any errors or warnings now. I'll check their docs for clues. IIRC this should only affect the --show option... maybe there's an alternative for dumping arbitrary data objects.

Thanks for trying it and reporting! -Max

realsimix commented 3 years ago

Hi Maxim,

Thanks for the quick reply.

For the first one, please try replacing line 1386 with:

    my $v = $opts->{$k};

Not sure why I even used the other more obscure syntax in the first place.

It works well this way!

Indeed, 5.16 is a bit dated... (though not as dated as spampd) :-) 5.28.1 is what I was mostly testing with... which is from 2018.

Error in option spec: "hh|??:s"

On one of my test hosts it looks like it doesn't like multiple ?? in the definition. Simply removing them seems to do it:

'help|h|?:s' => sub { $self->usage(0, 1, $[1]); }, 'hh:s' => sub { $self->usage(0, 2, $[1]); }, 'hhh:s' => sub { $self->usage(0, 3, $[1]); }, 'hhhh|man:s' => sub { $self->usage(0, 4, $[1]); }, 'version|vers' => sub { $self->version(); },

Name "Data::Dumper::Sparseseen" used only once: possible typo at /usr/sbin/spampd line 1429.

Is that an error or warning? I do vaguely remember those settings gave me

Tested it on two hosts and on the older one, it send these errors to STDERR when starting up.

Is there a way to silence the 4 messages created on lines 1428+1429? Sorry I don't know perl enough but I thought analog to doing the commands in a shell with added 2> /dev/null.

Thanks, Simon

mpaperno commented 3 years ago

It works well this way!

Cool! I've got that queued up for an update.

On one of my test hosts it looks like it doesn't like multiple ?? in the definition.

Interesting... I guess I could just remove that syntax. Or make it Perl version dependent? It's always the small stuff!

Is there a way to silence the 4 messages created on lines 1428+1429?

I'm not sure... probably but I probably need to recreate it. I wish I could remember better now what my issue with those variables was before. I'm not even sure where exactly the messages are coming from at the moment.

But just to clarify, it runs OK, "just" with those annoying messages to stderr? And they appear even when not using any of the --show options?

Thanks! -Max

realsimix commented 3 years ago

It works well this way!

Cool! I've got that queued up for an update.

On one of my test hosts it looks like it doesn't like multiple ?? in the definition.

Interesting... I guess I could just remove that syntax. Or make it Perl version dependent? It's always the small stuff!

Is there a way to silence the 4 messages created on lines 1428+1429?

I'm not sure... probably but I probably need to recreate it. I wish I could remember better now what my issue with those variables was before. I'm not even sure where exactly the messages are coming from at the moment.

But just to clarify, it runs OK, "just" with those annoying messages to stderr? And they appear even when not using any of the --show options?

The output seems to be limited to older versions while newer versions don't show them anymore. And yes, those messages appear on startup without any --show option. Spmapd seems to start normally I didn't actually test with messages going trough.

Simon

realsimix commented 3 years ago

But just to clarify, it runs OK, "just" with those annoying messages to stderr? And they appear even when not using any of the --show options?

Without knowing what I do exactly I've changed it like this: use Data::Dumper; $Data::Dumper::Quotekeys = 0; $Data::Dumper::Bless = ''; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Sparseseen = 1;

Now I only get this line: Name "Data::Dumper::Sparseseen" used only once: possible typo at ./spampd line 1431.

And it seems to be because Sparseseen is not know to this Dumper version.

I have no idea why the require vs. use matters :)

Simon

mpaperno commented 3 years ago

Hi Simon, does it help to just add no warnings 'once';?

        use Data::Dumper;
        no warnings 'once';
        $Data::Dumper::Quotekeys = 0;
        $Data::Dumper::Bless = '';
        $Data::Dumper::Sortkeys = 1;
        $Data::Dumper::Sparseseen = 1;
        print("\n". Data::Dumper->Dump(\@dumps, \@dnames) ."\n");

I couldn't find any mention or record of Sparseseen being added anytime in the last decade, but there's plenty of references to those bogus warnings.

mpaperno commented 3 years ago

On one of my test hosts it looks like it doesn't like multiple ?? in the definition. Simply removing them seems to do it:

Could you try replacing from line 574 with the following?

  if (!$self->is_reloading()) {
    my ($q2, $q3, $q4) = ("|??", "|???", "|????");
    $q2 = $q3 = $q4 = "" if ($Getopt::Long::VERSION < 2.5);
    %options = (
      %options,
      'show=s@'           => \$spd_p->{show_dbg},
      'help|h|?:s'        => sub { $self->usage(0, 1, $_[1]); },
      'hh'.$q2.':s'       => sub { $self->usage(0, 2, $_[1]); },
      'hhh'.$q3.':s'      => sub { $self->usage(0, 3, $_[1]); },
      'hhhh'.$q4.'|man:s' => sub { $self->usage(0, 4, $_[1]); },
      'version|vers'      => sub { $self->version(); },
    );
  }

The version number is a bit of a guess but that's what I have installed and I know it works. I only see one relevant commit on this matter (https://github.com/sciurius/perl-Getopt-Long/commit/0a8e3149046f7e3e8f39d1be191a3e980a28065a) but looks like it didn't make it until v2.51, so I'm not sure why it works with my v2.50.

Thanks!

realsimix commented 3 years ago

Hi Maxim,

The no warnings 'once'; seems to do the trick. I've changed it back to require again because I think that was better:

        require Data::Dumper;
        no warnings 'once';
        $Data::Dumper::Quotekeys = 0;
        $Data::Dumper::Bless = '';
        $Data::Dumper::Sortkeys = 1;
        $Data::Dumper::Sparseseen = 1;
        print("\n". Data::Dumper->Dump(\@dumps, \@dnames) ."\n");

For the other issue with --??, it still doesn't work.

-?, --?, -h, --h, -hh, --hh, -hhh, --hhh they all work

-??, --?? -???... they don't work

Thanks, Simon

realsimix commented 3 years ago

My current patch for the -?? issue looks like this:

@@ -574,9 +574,9 @@ sub initial_options_map {
       %options,
       'show=s@'         => \$spd_p->{show_dbg},
       'help|h|?:s'      => sub { $self->usage(0, 1, $_[1]); },
-      'hh|??:s'         => sub { $self->usage(0, 2, $_[1]); },
-      'hhh|???:s'       => sub { $self->usage(0, 3, $_[1]); },
-      'hhhh|????|man:s' => sub { $self->usage(0, 4, $_[1]); },
+      'hh:s'            => sub { $self->usage(0, 2, $_[1]); },
+      'hhh:s'           => sub { $self->usage(0, 3, $_[1]); },
+      'hhhh|man:s'      => sub { $self->usage(0, 4, $_[1]); },
       'version|vers'    => sub { $self->version(); },
     );
   }
@@ -1595,9 +1594,9 @@ Options:
   --log-rules-hit or -rh     Log the names of each matched SA test per mail.
   --debug or -d [<areas>]    Controls extra debug logging.

-  --help | -h | -?   [txt]   Show basic command-line usage.
-          -hh | -??  [txt]   Show short option descriptions (this text).
-         -hhh | -??? [txt]   Show usage summary and full option descriptions.
+  --help | -h | -? [txt]     Show basic command-line usage.
+          -hh      [txt]     Show short option descriptions (this text).
+         -hhh      [txt]     Show usage summary and full option descriptions.
   --man [html|txt]           Show full docs a man page or HTML/plain text.
   --show defaults|<thing>    Print default option values or <thing> and exit.
   --version                  Print version information and exit.
mpaperno commented 3 years ago

Hi Simon,

Great on the silenced warnings, another one solved. Agreed about require and thanks for confirming that works.

My current patch for the -?? issue looks like this:

That's what my patch also does, essentially (removes the multi-? marks), except based on which Getopt::Long version it's running with. So...

For the other issue with --??, it still doesn't work.

If that means those options don't do anything on the command line, that would be correct (same as your patch). As long as the program runs w/out errors.

Unfortunately I don't know how to update the POD docs (and help text) dynamically as well! Probably not reasonably possible.

I'm actually trying to recreate the issue with ? marks and can't... trying different old Perls.. Could you run the following for me on one of the affected systems and tell me what the version number is?

perl -MGetopt::Long -e 'print $Getopt::Long::VERSION ."\n";'

Thanks, -Max

mpaperno commented 3 years ago

perl -MGetopt::Long -e 'print $Getopt::Long::VERSION ."\n";'

Never mind... narrowed it down to v2.38... 2.39 works and sure enough there's a 10 yr old change there. https://github.com/sciurius/perl-Getopt-Long/commit/ba1194f817cf909b89e1610984378a4b4b09d6a2