forked from empear-analytics/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
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 is a "respin" of apache#1054, which I withdrew due to some annoying shortcomings. This changeset allows C clients to use SASL to authenticate with the ZooKeeper server. It is loosely based on patches #1 and #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, or -DWITH_CYRUS_SASL for CMake/Windows. `TestServerRequireClientSASLAuth.cc` has been renamed to `TestSASLAuth.cc`, and a test has been added which successfully (re)authenticates using the `DIGEST-MD5` mechanism. The code has also been used to successfully authenticate clients via `GSSAPI`/Kerberos. This commit also adds SASL support to the `cli.c` client. Co-authored-by: Tom Klonikowski <klonik_tinformatik.haw-hamburg.de> Author: Damien Diederen <[email protected]> Reviewers: Mate Szalay-Beko <[email protected]>, Norbert Kalmar <[email protected]> Closes apache#1134 from ztzg/ZOOKEEPER-1112-c-client-sasl-support-v2
- Loading branch information
1 parent
bd89558
commit f1063b3
Showing
20 changed files
with
1,509 additions
and
155 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
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
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.7.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,3 +333,53 @@ | |
* copied and put under another distribution licence | ||
* [including the GNU Public Licence.] | ||
*/ | ||
|
||
=========================================================================================== | ||
=== The following part contains the license for the Cyrus SASL 2.x library === | ||
=== used for optional SASL support === | ||
=========================================================================================== | ||
|
||
/* CMU libsasl | ||
* Tim Martin | ||
* Rob Earhart | ||
* Rob Siemborski | ||
*/ | ||
/* | ||
* Copyright (c) 1998-2003 Carnegie Mellon University. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* | ||
* 3. The name "Carnegie Mellon University" must not be used to | ||
* endorse or promote products derived from this software without | ||
* prior written permission. For permission or any other legal | ||
* details, please contact | ||
* Office of Technology Transfer | ||
* Carnegie Mellon University | ||
* 5000 Forbes Avenue | ||
* Pittsburgh, PA 15213-3890 | ||
* (412) 268-4387, fax: (412) 268-7395 | ||
* [email protected] | ||
* | ||
* 4. Redistributions of any form whatsoever must retain the following | ||
* acknowledgment: | ||
* "This product includes software developed by Computing Services | ||
* at Carnegie Mellon University (http://www.cmu.edu/computing/)." | ||
* | ||
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO | ||
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE | ||
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN | ||
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | ||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ |
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.