qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [2/4] qpid-proton git commit: further WIP
Date Thu, 25 May 2017 22:24:01 GMT
further WIP


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

Branch: refs/heads/PROTON-1488
Commit: 52e75d979a98fd67677943da84c496f1490ac99f
Parents: 4894265
Author: Gordon Sim <gsim@redhat.com>
Authored: Wed May 17 20:31:30 2017 +0100
Committer: Gordon Sim <gsim@redhat.com>
Committed: Thu May 25 14:44:45 2017 +0100

----------------------------------------------------------------------
 proton-c/include/proton/proactor.h |  1 +
 proton-c/src/sasl/remote_sasl.c    | 70 ++++++++++++++++++++++++---------
 2 files changed, 53 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/52e75d97/proton-c/include/proton/proactor.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/proactor.h b/proton-c/include/proton/proactor.h
index 5dd16f9..761fb86 100644
--- a/proton-c/include/proton/proactor.h
+++ b/proton-c/include/proton/proactor.h
@@ -286,6 +286,7 @@ PNP_EXTERN pn_proactor_t *pn_event_proactor(pn_event_t *event);
 PNP_EXTERN pn_millis_t pn_proactor_now(void);
 
 PNP_EXTERN void pn_use_remote_authentication_service(const char* address);
+PNP_EXTERN bool pn_is_authentication_service_connection(pn_connection_t* conn);
 
 /**
  * @defgroup proactor_events Events

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/52e75d97/proton-c/src/sasl/remote_sasl.c
----------------------------------------------------------------------
diff --git a/proton-c/src/sasl/remote_sasl.c b/proton-c/src/sasl/remote_sasl.c
index 9ef3484..54a96e5 100644
--- a/proton-c/src/sasl/remote_sasl.c
+++ b/proton-c/src/sasl/remote_sasl.c
@@ -96,6 +96,39 @@ void release_pni_sasl_relay_t(pni_sasl_relay_t* instance)
     }
 }
 
+PN_HANDLE(REMOTE_SASL_CTXT)
+
+bool pn_is_authentication_service_connection(pn_connection_t* conn)
+{
+    if (conn) {
+        pn_record_t *r = pn_connection_attachments(conn);
+        return pn_record_has(r, REMOTE_SASL_CTXT);
+    } else {
+        return false;
+    }
+}
+
+pni_sasl_relay_t* get_sasl_relay_context(pn_connection_t* conn)
+{
+    if (conn) {
+        pn_record_t *r = pn_connection_attachments(conn);
+        if (pn_record_has(r, REMOTE_SASL_CTXT)) {
+            return (pni_sasl_relay_t*) pn_record_get(r, REMOTE_SASL_CTXT);
+        } else {
+            return NULL;
+        }
+    } else {
+        return NULL;
+    }
+}
+
+void set_sasl_relay_context(pn_connection_t* conn, pni_sasl_relay_t* context)
+{
+    pn_record_t *r = pn_connection_attachments(conn);
+    pn_record_def(r, REMOTE_SASL_CTXT, PN_VOID);
+    pn_record_set(r, REMOTE_SASL_CTXT, context);
+}
+
 bool remote_init_server(pn_transport_t* transport)
 {
     pn_connection_t* upstream = pn_transport_connection(transport);
@@ -103,6 +136,7 @@ bool remote_init_server(pn_transport_t* transport)
         if (transport->sasl->impl_context) {
             return true;
         }
+        pn_connection_open(upstream);
         pni_sasl_relay_t* impl = new_pni_sasl_relay_t();
         transport->sasl->impl_context = impl;
         impl->upstream = upstream;
@@ -110,10 +144,8 @@ bool remote_init_server(pn_transport_t* transport)
         if (!proactor) return false;
         impl->downstream = pn_connection();
         pn_connection_set_hostname(impl->downstream, pn_connection_get_hostname(upstream));
-        //do I need to explicitly set up sasl? if so how? need to handle connection_bound?
-        //for now just fake it with dummy user
-        pn_connection_set_user(impl->downstream, "dummy");
-        pn_connection_set_context(impl->downstream, transport->sasl->impl_context);//TODO:
use record?
+        pn_connection_set_user(impl->downstream, "dummy");//force sasl
+        set_sasl_relay_context(impl->downstream, impl);
 
         pn_proactor_connect(proactor, impl->downstream, authentication_service_address);
         return true;
@@ -128,9 +160,15 @@ bool remote_init_client(pn_transport_t* transport)
     //service, need to use the same context as the server side of the
     //connection it is authenticating on behalf of
     pn_connection_t* conn = pn_transport_connection(transport);
-    transport->sasl->impl_context = pn_connection_get_context(conn);
-    ((pni_sasl_relay_t*) transport->sasl->impl_context)->refcount++;
-    return true;
+    pni_sasl_relay_t* impl = get_sasl_relay_context(conn);
+    if (impl) {
+        transport->sasl->impl_context = impl;
+        impl->refcount++;
+        return true;
+    } else {
+        return false;
+        //return pni_init_client(transport);
+    }
 }
 
 bool remote_free(pn_transport_t *transport)
@@ -180,11 +218,9 @@ bool remote_process_mechanisms(pn_transport_t *transport, const char
*mechs)
 {
     pni_sasl_relay_t* impl = (pni_sasl_relay_t*) transport->sasl->impl_context;
     if (impl) {
-        if (impl->upstream_state != DOWNSTREAM_MECHANISMS_RECEIVED) {
-            impl->mechlist = pn_strdup(mechs);
-            impl->upstream_state = DOWNSTREAM_MECHANISMS_RECEIVED;
-            pn_connection_wake(impl->upstream);
-        }
+        impl->mechlist = pn_strdup(mechs);
+        impl->upstream_state = DOWNSTREAM_MECHANISMS_RECEIVED;
+        pn_connection_wake(impl->upstream);
         return true;
     } else {
         return false;
@@ -195,7 +231,7 @@ bool remote_process_mechanisms(pn_transport_t *transport, const char *mechs)
 void remote_process_challenge(pn_transport_t *transport, const pn_bytes_t *recv)
 {
     pni_sasl_relay_t* impl = (pni_sasl_relay_t*) transport->sasl->impl_context;
-    if (impl && impl->upstream_state != DOWNSTREAM_CHALLENGE_RECEIVED) {
+    if (impl) {
         pni_copy_bytes(recv, &(impl->challenge));
         impl->upstream_state = DOWNSTREAM_CHALLENGE_RECEIVED;
         pn_connection_wake(impl->upstream);
@@ -207,11 +243,9 @@ bool remote_process_outcome(pn_transport_t *transport)
 {
     pni_sasl_relay_t* impl = (pni_sasl_relay_t*) transport->sasl->impl_context;
     if (impl) {
-        if (impl->upstream_state != DOWNSTREAM_OUTCOME_RECEIVED) {
-            impl->outcome = transport->sasl->outcome;
-            impl->upstream_state = DOWNSTREAM_OUTCOME_RECEIVED;
-            pn_connection_wake(impl->upstream);
-        }
+        impl->outcome = transport->sasl->outcome;
+        impl->upstream_state = DOWNSTREAM_OUTCOME_RECEIVED;
+        pn_connection_wake(impl->upstream);
         return true;
     } else {
         return false;


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


Mime
View raw message