From: Trond Norbye Date: Mon, 13 Sep 2010 06:05:34 +0000 (+0200) Subject: Fixed SASL authentication bits X-Git-Tag: 0.44~2^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=229c01e4aa9162f2f4723214ee4aabc1025f0e6b;p=awesomized%2Flibmemcached Fixed SASL authentication bits --- diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 1f0175f2..c4b263e1 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -536,7 +536,7 @@ memcached_return_t memcached_connect(memcached_server_write_instance_st ptr) case MEMCACHED_CONNECTION_TCP: rc= network_connect(ptr); #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT - if (ptr->fd != INVALID_SOCKET && ptr->root->sasl && ptr->root->sasl->callbacks) + if (ptr->fd != INVALID_SOCKET && ptr->root->sasl.callbacks) { rc= memcached_sasl_authenticate_connection(ptr); if (rc != MEMCACHED_SUCCESS) diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index d5411e86..81895afa 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -92,7 +92,8 @@ static inline bool _memcached_init(memcached_st *self) self->get_key_failure= NULL; self->delete_trigger= NULL; self->callbacks= NULL; - self->sasl= NULL; + self->sasl.callbacks= NULL; + self->sasl.is_allocated= false; return true; } @@ -176,7 +177,7 @@ void memcached_free(memcached_st *ptr) if (ptr->continuum) libmemcached_free(ptr, ptr->continuum); - if (ptr->sasl) + if (ptr->sasl.callbacks) { #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT memcached_destroy_sasl_auth_data(ptr); @@ -273,7 +274,7 @@ memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source) } #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT - if (source->sasl && source->sasl->callbacks) + if (source->sasl.callbacks) { if (memcached_clone_sasl(new_clone, source) != MEMCACHED_SUCCESS) { diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 58f9f673..c099d76e 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -124,7 +124,7 @@ struct memcached_st { memcached_trigger_key_fn get_key_failure; memcached_trigger_delete_key_fn delete_trigger; memcached_callback_st *callbacks; - struct memcached_sasl_st *sasl; + struct memcached_sasl_st sasl; char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE]; struct { bool is_allocated:1; diff --git a/libmemcached/sasl.c b/libmemcached/sasl.c index f2e346a6..bdec4272 100644 --- a/libmemcached/sasl.c +++ b/libmemcached/sasl.c @@ -14,16 +14,13 @@ void memcached_set_sasl_callbacks(memcached_st *ptr, const sasl_callback_t *callbacks) { - ptr->sasl->callbacks= callbacks; - ptr->sasl->is_allocated= false; + ptr->sasl.callbacks= callbacks; + ptr->sasl.is_allocated= false; } const sasl_callback_t *memcached_get_sasl_callbacks(memcached_st *ptr) { - if (ptr->sasl) - return ptr->sasl->callbacks; - - return NULL; + return ptr->sasl.callbacks; } /** @@ -119,7 +116,7 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s sasl_conn_t *conn; int ret= sasl_client_new("memcached", server->hostname, laddr, raddr, - server->root->sasl->callbacks, 0, &conn); + server->root->sasl.callbacks, 0, &conn); if (ret != SASL_OK) { return MEMCACHED_AUTH_PROBLEM; @@ -144,12 +141,12 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s do { /* send the packet */ - struct __write_vector_st vector[]= - { - { .length= sizeof(request.bytes), .buffer= request.bytes }, - { .length= keylen, .buffer= chosenmech }, - { .length= len, .buffer= data } - }; + struct __write_vector_st vector[]= + { + { .length= sizeof(request.bytes), .buffer= request.bytes }, + { .length= keylen, .buffer= chosenmech }, + { .length= len, .buffer= data } + }; if (memcached_io_writev(server, vector, 3, true) == -1) { @@ -221,7 +218,7 @@ memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, const char *password) { if (ptr == NULL || username == NULL || - password == NULL || ptr->sasl != NULL) + password == NULL || ptr->sasl.callbacks != NULL) { return MEMCACHED_FAILURE; } @@ -252,62 +249,52 @@ memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, cb[2].context= secret; cb[3].id= SASL_CB_LIST_END; - ptr->sasl->callbacks= cb; - ptr->sasl->is_allocated= true; + ptr->sasl.callbacks= cb; + ptr->sasl.is_allocated= true; return MEMCACHED_SUCCESS; } memcached_return_t memcached_destroy_sasl_auth_data(memcached_st *ptr) { - if (ptr == NULL || ptr->sasl->callbacks == NULL) + if (ptr == NULL || ptr->sasl.callbacks == NULL) { return MEMCACHED_FAILURE; } - if (ptr->sasl->is_allocated) + if (ptr->sasl.is_allocated) { - libmemcached_free(ptr, ptr->sasl->callbacks[0].context); - libmemcached_free(ptr, ptr->sasl->callbacks[2].context); - libmemcached_free(ptr, (void*)ptr->sasl->callbacks); - ptr->sasl->is_allocated= false; + libmemcached_free(ptr, ptr->sasl.callbacks[0].context); + libmemcached_free(ptr, ptr->sasl.callbacks[2].context); + libmemcached_free(ptr, (void*)ptr->sasl.callbacks); + ptr->sasl.is_allocated= false; } - ptr->sasl->callbacks= NULL; - libmemcached_free(ptr, ptr->sasl); - ptr->sasl= NULL; + ptr->sasl.callbacks= NULL; return MEMCACHED_SUCCESS; } memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st *source) { - if (source->sasl == NULL) + + if (source->sasl.callbacks == NULL) { return MEMCACHED_SUCCESS; } - else - { - clone->sasl= libmemcached_malloc(source, sizeof(struct memcached_sasl_st)); - - if (clone->sasl == NULL) - { - return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - } - } /* Hopefully we are using our own callback mechanisms.. */ - if (source->sasl->callbacks[0].id == SASL_CB_USER && - source->sasl->callbacks[0].proc == get_username && - source->sasl->callbacks[1].id == SASL_CB_AUTHNAME && - source->sasl->callbacks[1].proc == get_username && - source->sasl->callbacks[2].id == SASL_CB_PASS && - source->sasl->callbacks[2].proc == get_password && - source->sasl->callbacks[3].id == SASL_CB_LIST_END) + if (source->sasl.callbacks[0].id == SASL_CB_USER && + source->sasl.callbacks[0].proc == get_username && + source->sasl.callbacks[1].id == SASL_CB_AUTHNAME && + source->sasl.callbacks[1].proc == get_username && + source->sasl.callbacks[2].id == SASL_CB_PASS && + source->sasl.callbacks[2].proc == get_password && + source->sasl.callbacks[3].id == SASL_CB_LIST_END) { - sasl_secret_t *secret= source->sasl->callbacks[2].context; + sasl_secret_t *secret= source->sasl.callbacks[2].context; return memcached_set_sasl_auth_data(clone, - source->sasl->callbacks[0].context, + source->sasl.callbacks[0].context, (const char*)secret->data); } @@ -318,9 +305,9 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st */ size_t total= 0; - while (source->sasl->callbacks[total].id != SASL_CB_LIST_END) + while (source->sasl.callbacks[total].id != SASL_CB_LIST_END) { - switch (source->sasl->callbacks[total].id) + switch (source->sasl.callbacks[total].id) { case SASL_CB_USER: case SASL_CB_AUTHNAME: @@ -339,38 +326,38 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; } - memcpy(cb, source->sasl->callbacks, (total + 1) * sizeof(sasl_callback_t)); + memcpy(cb, source->sasl.callbacks, (total + 1) * sizeof(sasl_callback_t)); /* Now update the context... */ for (size_t x= 0; x < total; ++x) { if (cb[x].id == SASL_CB_USER || cb[x].id == SASL_CB_AUTHNAME) { - cb[x].context= libmemcached_malloc(clone, strlen(source->sasl->callbacks[x].context)); + cb[x].context= libmemcached_malloc(clone, strlen(source->sasl.callbacks[x].context)); if (cb[x].context == NULL) { /* Failed to allocate memory, clean up previously allocated memory */ for (size_t y= 0; y < x; ++y) { - libmemcached_free(clone, clone->sasl->callbacks[y].context); + libmemcached_free(clone, clone->sasl.callbacks[y].context); } libmemcached_free(clone, cb); return MEMCACHED_MEMORY_ALLOCATION_FAILURE; } - strcpy(cb[x].context, source->sasl->callbacks[x].context); + strcpy(cb[x].context, source->sasl.callbacks[x].context); } else { - sasl_secret_t *src = source->sasl->callbacks[x].context; + sasl_secret_t *src = source->sasl.callbacks[x].context; sasl_secret_t *n = libmemcached_malloc(clone, src->len + 1 + sizeof(*n)); if (n == NULL) { /* Failed to allocate memory, clean up previously allocated memory */ for (size_t y= 0; y < x; ++y) { - libmemcached_free(clone, clone->sasl->callbacks[y].context); + libmemcached_free(clone, clone->sasl.callbacks[y].context); } libmemcached_free(clone, cb); @@ -381,8 +368,8 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st } } - clone->sasl->callbacks= cb; - clone->sasl->is_allocated= true; + clone->sasl.callbacks= cb; + clone->sasl.is_allocated= true; return MEMCACHED_SUCCESS; }