qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astitc...@apache.org
Subject [4/4] qpid-proton git commit: PROTON-1589: [C++ binding] Stop reconnect attempts on authorization failure
Date Tue, 20 Mar 2018 08:02:23 GMT
PROTON-1589: [C++ binding] Stop reconnect attempts on authorization failure


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/95776152
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/95776152
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/95776152

Branch: refs/heads/master
Commit: 95776152d50e856ed75f093c560b8e09006e7262
Parents: dfa23e3
Author: Andrew Stitcher <astitcher@apache.org>
Authored: Fri Mar 16 18:19:42 2018 -0400
Committer: Andrew Stitcher <astitcher@apache.org>
Committed: Tue Mar 20 03:29:58 2018 -0400

----------------------------------------------------------------------
 .../bindings/cpp/src/proactor_container_impl.cpp  |  8 ++++++--
 proton-c/src/sasl/cyrus_sasl.c                    | 18 ++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/95776152/proton-c/bindings/cpp/src/proactor_container_impl.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proactor_container_impl.cpp b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
index c5f46ed..f865a16 100644
--- a/proton-c/bindings/cpp/src/proactor_container_impl.cpp
+++ b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
@@ -310,10 +310,14 @@ bool container::impl::setup_reconnect(pn_connection_t* pnc) {
 
     const reconnect_options::impl& roi = *rc->reconnect_options_->impl_;
 
+    pn_transport_t* t = pn_connection_transport(pnc);
+    pn_condition_t* condition = pn_transport_condition(t);
+
+    // If we failed to authenticate then don't reconnect any more and just fail
+    if ( !strcmp(pn_condition_get_name(condition), "amqp:unauthorized-access") ) return false;
+
     // If too many reconnect attempts just fail
     if ( roi.max_attempts != 0 && rc->retries_ >= roi.max_attempts) {
-        pn_transport_t* t = pn_connection_transport(pnc);
-        pn_condition_t* condition = pn_transport_condition(t);
         pn_condition_format(condition, "proton:io", "Too many reconnect attempts (%d)", rc->retries_);
         return false;
     }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/95776152/proton-c/src/sasl/cyrus_sasl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/sasl/cyrus_sasl.c b/proton-c/src/sasl/cyrus_sasl.c
index ab6eba6..c589fab 100644
--- a/proton-c/src/sasl/cyrus_sasl.c
+++ b/proton-c/src/sasl/cyrus_sasl.c
@@ -92,18 +92,28 @@ const pnx_sasl_implementation * const cyrus_sasl_impl = &sasl_impl;
 
 static const char *amqp_service = "amqp";
 
-static bool pni_check_sasl_result(sasl_conn_t *conn, int r, pn_transport_t *logger)
+static inline bool pni_check_result(sasl_conn_t *conn, int r, pn_transport_t *logger, const
char* condition_name)
 {
     if (r==SASL_OK) return true;
 
     const char* err = conn ? sasl_errdetail(conn) : sasl_errstring(r, NULL, NULL);
     pnx_sasl_logf(logger, "sasl error: %s", err);
     pn_condition_t* c = pn_transport_condition(logger);
-    pn_condition_set_name(c, "proton:io:sasl_error");
+    pn_condition_set_name(c, condition_name);
     pn_condition_set_description(c, err);
     return false;
 }
 
+static bool pni_check_io_result(sasl_conn_t *conn, int r, pn_transport_t *logger)
+{
+    return pni_check_result(conn, r, logger, "proton:io:sasl_error");
+}
+
+static bool pni_check_sasl_result(sasl_conn_t *conn, int r, pn_transport_t *logger)
+{
+    return pni_check_result(conn, r, logger, "amqp:unauthorized-access");
+}
+
 // Cyrus wrappers
 static void pni_cyrus_interact(pn_transport_t *transport, sasl_interact_t *interact)
 {
@@ -565,7 +575,7 @@ ssize_t cyrus_sasl_encode(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t
*
   unsigned int outlen;
   int r = sasl_encode(cyrus_conn, in.start, in.size, &output, &outlen);
   if (outlen==0) return 0;
-  if ( pni_check_sasl_result(cyrus_conn, r, transport) ) {
+  if ( pni_check_io_result(cyrus_conn, r, transport) ) {
     *out = pn_bytes(outlen, output);
     return outlen;
   }
@@ -580,7 +590,7 @@ ssize_t cyrus_sasl_decode(pn_transport_t *transport, pn_bytes_t in, pn_bytes_t
*
   unsigned int outlen;
   int r = sasl_decode(cyrus_conn, in.start, in.size, &output, &outlen);
   if (outlen==0) return 0;
-  if ( pni_check_sasl_result(cyrus_conn, r, transport) ) {
+  if ( pni_check_io_result(cyrus_conn, r, transport) ) {
     *out = pn_bytes(outlen, output);
     return outlen;
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message