Skip to content

Commit

Permalink
ZOOKEEPER-3951: C Client: Fix compilation with SASL disabled
Browse files Browse the repository at this point in the history
The `sasl_client` field doesn't exist when configured without SASL.  Use an accessor outside of the blocks already guarded by `HAVE_CYRUS_SASL_H`.

(Reported by [Parag](https://issues.apache.org/jira/browse/ZOOKEEPER-3951).)

Author: Damien Diederen <dd@crosstwine.com>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Mate Szalay-Beko <symat@apache.org>

Closes apache#1477 from ztzg/ZOOKEEPER-3951-no-sasl-compilation
  • Loading branch information
ztzg authored and RokLenarcic committed Aug 31, 2022
1 parent 5fd5aae commit 1140f44
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions zookeeper-client/zookeeper-client-c/src/zookeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ static void zookeeper_set_sock_noblock(zhandle_t *, socket_t);
static void zookeeper_set_sock_timeout(zhandle_t *, socket_t, int);
static socket_t zookeeper_connect(zhandle_t *, struct sockaddr_storage *, socket_t);

/*
* return 1 if zh has a SASL client configured, 0 otherwise.
*/
static int has_sasl_client(zhandle_t* zh)
{
#ifdef HAVE_CYRUS_SASL_H
return zh->sasl_client != NULL;
#else /* !HAVE_CYRUS_SASL_H */
return 0;
#endif /* HAVE_CYRUS_SASL_H */
}

/*
* return 1 if zh has a SASL client performing authentication, 0 otherwise.
*/
Expand Down Expand Up @@ -2846,7 +2858,7 @@ static void finalize_session_establishment(zhandle_t *zh) {
zh->input_buffer = 0; // just in case the watcher calls zookeeper_process() again
PROCESS_SESSION_EVENT(zh, zh->state);

if (zh->sasl_client) {
if (has_sasl_client(zh)) {
/* some packets might have been delayed during SASL negotiaton. */
adaptor_send_queue(zh, 0);
}
Expand Down Expand Up @@ -5077,7 +5089,7 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
// negotiation is planned. (Such packets would be queued in
// front of SASL packets, which is forbidden, and SASL
// completion is followed by a 'send_auth_info' anyway.)
(zh->state == ZOO_ASSOCIATING_STATE && !zh->sasl_client)) {
(zh->state == ZOO_ASSOCIATING_STATE && !has_sasl_client(zh))) {
return send_last_auth_info(zh);
}

Expand Down

0 comments on commit 1140f44

Please sign in to comment.