forked from apache/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZOOKEEPER-1112: Add (Cyrus) SASL authentication support to C client l…
…ibrary This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches apache#1 and apache#2 by Tom Klonikowski, at https://reviews.apache.org/r/2252/, but the result has been extensively reworked to follow the semantics of the Java client: * No SASL operations are exposed through the API; * The configuration is provided, and stored, at "handle init time"; * SASL authentication is automatically performed after each (re)connect. It introduces an optional dependency on the Cyrus SASL library, which can either be autodetected (default) or configured using the --without-sasl/--with-sasl[=DIR] flags. TestServerRequireClientSASLAuth.cc has been renamed to TestSASLAuth.cc, and a test has been added which successfully (re)authenticates using the DIGEST-MD5 mechanism. An earlier version of this code has been used to successfully authenticate clients via Kerberos. While cli.c is not modified by this commit, we are planning to submit a subsequent contribution which enables SASL support in that client using the ZOOKEEPER-3599 (use getopt if available) mechanism. Co-authored-by: Tom Klonikowski <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,282 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# - Find Cyrus SASL (sasl.h, libsasl2.so) | ||
# | ||
# This module defines | ||
# CYRUS_SASL_INCLUDE_DIR, directory containing headers | ||
# CYRUS_SASL_SHARED_LIB, path to Cyrus SASL's shared library | ||
# CYRUS_SASL_FOUND, whether Cyrus SASL and its plugins have been found | ||
# | ||
# It also defines the following IMPORTED targets: | ||
# CyrusSASL | ||
# | ||
# Hints: | ||
# Set CYRUS_SASL_ROOT_DIR to the root directory of a Cyrus SASL installation. | ||
# | ||
# The initial version of this file was extracted from | ||
# https://github.com/cloudera/kudu, at the following commit: | ||
# | ||
# commit 9806863e78107505a622b44112a897189d9b3c24 | ||
# Author: Dan Burkert <[email protected]> | ||
# Date: Mon Nov 30 12:15:36 2015 -0800 | ||
# | ||
# Enable C++11 | ||
|
||
find_path(CYRUS_SASL_INCLUDE_DIR sasl/sasl.h HINTS "${CYRUS_SASL_ROOT_DIR}/include") | ||
find_library(CYRUS_SASL_SHARED_LIB sasl2 HINTS "${CYRUS_SASL_ROOT_DIR}/lib") | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(CYRUS_SASL REQUIRED_VARS | ||
CYRUS_SASL_SHARED_LIB CYRUS_SASL_INCLUDE_DIR) | ||
|
||
if(CYRUS_SASL_FOUND) | ||
if(NOT TARGET CyrusSASL) | ||
add_library(CyrusSASL UNKNOWN IMPORTED) | ||
set_target_properties(CyrusSASL PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${CYRUS_SASL_INCLUDE_DIR}" | ||
IMPORTED_LINK_INTERFACE_LANGUAGES "C" | ||
IMPORTED_LOCATION "${CYRUS_SASL_SHARED_LIB}") | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ project(zookeeper VERSION 3.6.0) | |
set(email [email protected]) | ||
set(description "zookeeper C client") | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../tools/cmake/Modules") | ||
|
||
# general options | ||
if(UNIX) | ||
add_compile_options(-Wall -fPIC) | ||
|
@@ -61,6 +63,20 @@ if(WANT_SOCK_CLOEXEC AND HAVE_SOCK_CLOEXEC) | |
set(SOCK_CLOEXEC_ENABLED 1) | ||
endif() | ||
|
||
# Cyrus SASL 2.x | ||
option(WITH_CYRUS_SASL "turn ON/OFF Cyrus SASL 2.x support, or define SASL library location (default: ON)" ON) | ||
message("-- using WITH_CYRUS_SASL=${WITH_CYRUS_SASL}") | ||
if(NOT WITH_CYRUS_SASL STREQUAL "OFF") | ||
if(NOT WITH_CYRUS_SASL STREQUAL "ON") | ||
set(CYRUS_SASL_ROOT_DIR "${WITH_CYRUS_SASL}") | ||
endif() | ||
find_package(CyrusSASL) | ||
if(CYRUS_SASL_FOUND) | ||
message("-- Cyrus SASL 2.x found! will build with SASL support.") | ||
else() | ||
message("-- WARNING: unable to find Cyrus SASL 2.x! will build without SASL support.") | ||
endif() | ||
endif() | ||
|
||
# The function `to_have(in out)` converts a header name like `arpa/inet.h` | ||
# into an Autotools style preprocessor definition `HAVE_ARPA_INET_H`. | ||
|
@@ -171,6 +187,10 @@ else() | |
list(APPEND zookeeper_sources src/st_adaptor.c) | ||
endif() | ||
|
||
if(CYRUS_SASL_FOUND) | ||
list(APPEND zookeeper_sources src/zk_sasl.c) | ||
endif() | ||
|
||
if(WIN32) | ||
list(APPEND zookeeper_sources src/winport.c) | ||
endif() | ||
|
@@ -203,6 +223,11 @@ if(WANT_SYNCAPI AND NOT WIN32) | |
target_link_libraries(zookeeper PUBLIC Threads::Threads) | ||
endif() | ||
|
||
if(CYRUS_SASL_FOUND) | ||
target_compile_definitions(zookeeper PUBLIC HAVE_CYRUS_SASL_H) | ||
target_link_libraries(zookeeper PUBLIC CyrusSASL) | ||
endif() | ||
|
||
# cli executable | ||
add_executable(cli src/cli.c) | ||
target_link_libraries(cli zookeeper) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.