The net-snmp-cert utility script currently does wildcard matching on any input
when searching for certificates. e.g. 'joe' would match 'joe', 'joel' and 'joe
bob'. With this patch (from Joe Marzot, who wrote the script) will only return
'joe', an require a wildcard to be specified to get additional matches. I
think, however, it will return the wildcard result if no exact match is found.
At any rate, the important part, to me, is that if an exact match exists, no
other certs will be returned.
Index: net-snmp-cert
===================================================================
--- net-snmp-cert       (revision 19354)
+++ net-snmp-cert       (working copy)
@@ -925,15 +925,20 @@
 
   NetSNMP::Cert::dprint("find_certs(4):${dir}:$targ:$cwd\n", $opts);
 
+  my $wild;
+  $targ =~ s/\./\\\./g; # do shell style globbing w/ regex (sort of)
+  $wild++ if $targ =~ s/\*/\.\*/g; # do shell style globbing w/ regex (sort of)
+  $wild++ if $targ =~ s/\?/\.\?/g; # do shell style globbing w/ regex (sort of)
+
   my @certs;
-  my $glob = "$dir/$targ";
-  foreach (<$dir/*>) {
-    NetSNMP::Cert::dprint("checking($dir:$targ): $_\n", $opts);
+  foreach (sort {::basename($a, @NetSNMP::Cert::CRTSUFFIXES) cmp
+                ::basename($b, @NetSNMP::Cert::CRTSUFFIXES)} <$dir/*>) {
+    NetSNMP::Cert::dprint("checking($dir:$targ:$wild): $_\n", $opts);
     next unless /^$dir\/$targ(.*$suffix_regex)?$/;
-    # return exact match if not wantarray()
-    return $_ if (not wantarray()) and /^$dir\/$targ($suffix_regex)?$/;
     NetSNMP::Cert::dprint("pushing: $_\n", $opts);
     push(@certs, $_);
+    # return exact match
+    last if ((not $wild) and /^$dir\/$targ($suffix_regex)?$/);
   }
 
   return (wantarray ? @certs : $certs[0]);
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to