about summary refs log tree commit
diff options
context:
space:
mode:
authorivan baktsheev <dot.and.thing@gmail.com>2014-02-18 22:47:43 +0300
committerivan baktsheev <dot.and.thing@gmail.com>2014-02-18 22:47:43 +0300
commitfdcacd730e5e9fabe084f343a2d58e036745610e (patch)
tree65de769b697196f096d8c83d35ce190214f9a18d
parentb76af9289d4542cf2b9e1f3c2de0baf0ba8bae09 (diff)
downloadperl-libnet-fdcacd730e5e9fabe084f343a2d58e036745610e.tar.gz
Authen::SASL fixes
1) pass debug flag to Authen::SASL, so we can see errors
2) when auth method unavailable (for example, GSSAPI error "No credentials cache file found; output token sz:"), then fallback to another supported method
-rw-r--r--Net/SMTP.pm25
1 files changed, 20 insertions, 5 deletions
diff --git a/Net/SMTP.pm b/Net/SMTP.pm
index 705b5c5..cf5e3c1 100644
--- a/Net/SMTP.pm
+++ b/Net/SMTP.pm
@@ -138,14 +138,29 @@ sub auth {
         user     => $username,
         pass     => $password,
         authname => $username,
-      }
+      },
+      debug => $self->debug
     );
   }
 
-  # We should probably allow the user to pass the host, but I don't
-  # currently know and SASL mechanisms that are used by smtp that need it
-  my $client = $sasl->client_new('smtp', ${*$self}{'net_smtp_host'}, 0);
-  my $str    = $client->client_start;
+  my $client;
+  my $str;
+  do {
+    if ($client) {
+      # $client mechanism failed, so we need to exclude this mechanism from list
+      my $failed_mech = $client->mechanism;
+      $self->debug_text ("Auth mechanism failed: $failed_mech")
+        if $self->debug;
+      $mechanisms =~ s/(?:\s|^)$failed_mech(?:\s|$)//;
+    }
+    $sasl->mechanism ($mechanisms);
+    
+    # We should probably allow the user to pass the host, but I don't
+    # currently know and SASL mechanisms that are used by smtp that need it
+
+    $client = $sasl->client_new('smtp', ${*$self}{'net_smtp_host'}, 0);
+    $str    = $client->client_start;
+  } while (!defined $str);
 
   # We don't support sasl mechanisms that encrypt the socket traffic.
   # todo that we would really need to change the ISA hierarchy