qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject svn commit: r1302572 - in /qpid/proton/proton-c: include/proton/sasl.h src/proton.c src/sasl/sasl.c
Date Mon, 19 Mar 2012 17:52:49 GMT
Author: rhs
Date: Mon Mar 19 17:52:49 2012
New Revision: 1302572

URL: http://svn.apache.org/viewvc?rev=1302572&view=rev
Log:
added support for anonymous

Modified:
    qpid/proton/proton-c/include/proton/sasl.h
    qpid/proton/proton-c/src/proton.c
    qpid/proton/proton-c/src/sasl/sasl.c

Modified: qpid/proton/proton-c/include/proton/sasl.h
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/include/proton/sasl.h?rev=1302572&r1=1302571&r2=1302572&view=diff
==============================================================================
--- qpid/proton/proton-c/include/proton/sasl.h (original)
+++ qpid/proton/proton-c/include/proton/sasl.h Mon Mar 19 17:52:49 2012
@@ -31,7 +31,7 @@ typedef enum {SASL_NONE=-1, SASL_OK=0, S
               SASL_TEMP=4} pn_sasl_outcome_t;
 
 pn_sasl_t *pn_sasl();
-void pn_sasl_client(pn_sasl_t *sasl, const char *username, const char *password);
+void pn_sasl_client(pn_sasl_t *sasl, const char *mechanism, const char *username, const char
*password);
 void pn_sasl_server(pn_sasl_t *sasl);
 void pn_sasl_auth(pn_sasl_t *sasl, pn_sasl_outcome_t outcome);
 bool pn_sasl_init(pn_sasl_t *sasl);

Modified: qpid/proton/proton-c/src/proton.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/proton.c?rev=1302572&r1=1302571&r2=1302572&view=diff
==============================================================================
--- qpid/proton/proton-c/src/proton.c (original)
+++ qpid/proton/proton-c/src/proton.c Mon Mar 19 17:52:49 2012
@@ -92,7 +92,7 @@ void server_callback(pn_selectable_t *se
   case SASL_NONE:
     {
       const char *mech = pn_sasl_mechanism(sasl);
-      if (mech && !strcmp(mech, "PLAIN")) {
+      if (mech && (!strcmp(mech, "PLAIN") || !strcmp(mech, "ANONYMOUS"))) {
         pn_binary_t *response = pn_sasl_response(sasl);
         char buf[1024];
         pn_format(buf, 1024, pn_from_binary(response));
@@ -221,6 +221,7 @@ struct client_context {
   int recv_count;
   int send_count;
   pn_driver_t *driver;
+  const char *mechanism;
   const char *username;
   const char *password;
   wchar_t hostname[1024];
@@ -233,7 +234,7 @@ void client_callback(pn_selectable_t *se
 
   pn_sasl_t *sasl = pn_selectable_sasl(sel);
   if (!pn_sasl_init(sasl)) {
-    pn_sasl_client(sasl, ctx->username, ctx->password);
+    pn_sasl_client(sasl, ctx->mechanism, ctx->username, ctx->password);
   }
 
   switch (pn_sasl_outcome(sasl)) {
@@ -364,9 +365,10 @@ int main(int argc, char **argv)
 {
   char *url = NULL;
   char *address = "queue";
+  char *mechanism = "ANONYMOUS";
 
   int opt;
-  while ((opt = getopt(argc, argv, "c:a:hX")) != -1)
+  while ((opt = getopt(argc, argv, "c:a:m:hX")) != -1)
   {
     switch (opt) {
     case 'c':
@@ -376,13 +378,18 @@ int main(int argc, char **argv)
     case 'a':
       address = optarg;
       break;
+    case 'm':
+      mechanism = optarg;
+      break;
     case 'X':
       value(argc, argv);
       exit(EXIT_SUCCESS);
     case 'h':
-      printf("Usage: %s [-h] [-c [user[:password]@]host[:port]]\n", argv[0]);
+      printf("Usage: %s [-h] [-c [user[:password]@]host[:port]] [-a <address>] [-m
<sasl-mech>]\n", argv[0]);
       printf("\n");
       printf("    -c    The connect url.\n");
+      printf("    -a    The AMQP address.\n");
+      printf("    -m    The SASL mechanism.\n");
       printf("    -h    Print this help.\n");
       exit(EXIT_SUCCESS);
     default: /* '?' */
@@ -402,6 +409,7 @@ int main(int argc, char **argv)
     struct client_context ctx = {false, 10, 10, drv};
     ctx.username = user;
     ctx.password = pass;
+    ctx.mechanism = mechanism;
     mbstowcs(ctx.hostname, host, 1024);
     mbstowcs(ctx.address, address, 1024);
     if (!pn_connector(drv, host, port, client_callback, &ctx)) pn_fatal("connector failed\n");

Modified: qpid/proton/proton-c/src/sasl/sasl.c
URL: http://svn.apache.org/viewvc/qpid/proton/proton-c/src/sasl/sasl.c?rev=1302572&r1=1302571&r2=1302572&view=diff
==============================================================================
--- qpid/proton/proton-c/src/sasl/sasl.c (original)
+++ qpid/proton/proton-c/src/sasl/sasl.c Mon Mar 19 17:52:49 2012
@@ -91,7 +91,7 @@ pn_binary_t *pn_sasl_response(pn_sasl_t 
   return sasl->response;
 }
 
-void pn_sasl_client(pn_sasl_t *sasl, const char *username, const char *password)
+void pn_sasl_client(pn_sasl_t *sasl, const char *mechanism, const char *username, const char
*password)
 {
   const char *user = username ? username : "";
   const char *pass = password ? password : "";
@@ -106,7 +106,7 @@ void pn_sasl_client(pn_sasl_t *sasl, con
   memmove(iresp + usize + 2, pass, psize);
 
   pn_init_frame(sasl->disp);
-  pn_field(sasl->disp, SASL_INIT_MECHANISM, pn_from_symbol(pn_symbol("PLAIN")));
+  pn_field(sasl->disp, SASL_INIT_MECHANISM, pn_from_symbol(pn_symbol(mechanism)));
   pn_field(sasl->disp, SASL_INIT_INITIAL_RESPONSE, pn_from_binary(pn_binary(iresp, size)));
   pn_post_frame(sasl->disp, 0, SASL_INIT);
   sasl->init = true;
@@ -115,7 +115,8 @@ void pn_sasl_client(pn_sasl_t *sasl, con
 void pn_sasl_server(pn_sasl_t *sasl)
 {
   pn_init_frame(sasl->disp);
-  pn_field(sasl->disp, SASL_MECHANISMS_SASL_SERVER_MECHANISMS, pn_value("@s[s]", "PLAIN"));
+  pn_field(sasl->disp, SASL_MECHANISMS_SASL_SERVER_MECHANISMS,
+           pn_value("@s[ss]", "PLAIN", "ANONYMOUS"));
   pn_post_frame(sasl->disp, 0, SASL_MECHANISMS);
   sasl->init = true;
 }



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


Mime
View raw message