Skip to content

Commit 96dd6ed

Browse files
committed
CDRIVER-299 Add native GSSAPI (SSPI) support on Windows
1 parent bcb0dfc commit 96dd6ed

13 files changed

+1322
-245
lines changed

CMakeLists.txt

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ set (ENABLE_SSL AUTO CACHE STRING
99
case-sensitive. The default is \"AUTO\". Note\ that SCRAM-SHA-1 is
1010
required for authenticating to MongoDB 3.0 and later.")
1111

12-
option(ENABLE_SASL "Use Cyrus SASL library for Kerberos." ON)
12+
set (ENABLE_SASL AUTO CACHE STRING
13+
"Enable SASL authentication (Kerberos).\ Options are \"CYRUS\" to use Cyrus
14+
SASL, \"SSPI\" to use Windows Native SSPI, \"AUTO\",\ or \"OFF\". These
15+
options are case-sensitive.")
1316
option(ENABLE_TESTS "Build MongoDB C Driver tests." ON)
1417
option(ENABLE_EXAMPLES "Build MongoDB C Driver examples." ON)
1518
option(ENABLE_AUTOMATIC_INIT_AND_CLEANUP "Enable automatic init and cleanup (GCC only)" ON)
@@ -118,15 +121,35 @@ if (ENABLE_CRYPTO_SYSTEM_PROFILE)
118121
endif ()
119122
endif ()
120123

121-
if (ENABLE_SASL)
122-
include(FindSASL2)
123-
endif ()
124-
if (ENABLE_SASL AND SASL2_FOUND)
125-
set (MONGOC_ENABLE_SASL 1)
124+
if (NOT (ENABLE_SASL STREQUAL CYRUS
125+
OR ENABLE_SASL STREQUAL SSPI
126+
OR ENABLE_SASL STREQUAL AUTO
127+
OR ENABLE_SASL STREQUAL OFF))
128+
message (FATAL_ERROR
129+
"ENABLE_SASL option must be CYRUS, SSPI, AUTO, or OFF")
130+
endif()
131+
132+
set (MONGOC_HAVE_SASL_CLIENT_DONE 0)
133+
if (NOT ENABLE_SASL STREQUAL OFF)
134+
if (ENABLE_SASL STREQUAL AUTO OR ENABLE_SASL STREQUAL CYRUS)
135+
include(FindSASL2)
136+
endif()
137+
138+
if (SASL2_FOUND)
139+
set (MONGOC_ENABLE_SASL 1)
140+
set (MONGOC_ENABLE_SASL_CYRUS 1)
141+
set (MONGOC_ENABLE_SASL_SSPI 0)
142+
else ((ENABLE_SASL STREQUAL SSPI OR ENABLE_SASL STREQUAL AUTO) AND WIN32)
143+
set (MONGOC_ENABLE_SASL 1)
144+
set (MONGOC_ENABLE_SASL_CYRUS 0)
145+
set (MONGOC_ENABLE_SASL_SSPI 1)
146+
endif ()
126147
else ()
127-
set (MONGOC_HAVE_SASL_CLIENT_DONE 0)
128148
set (MONGOC_ENABLE_SASL 0)
129-
endif ()
149+
set (MONGOC_ENABLE_SASL_CYRUS 0)
150+
set (MONGOC_ENABLE_SASL_SSPI 0)
151+
endif()
152+
130153

131154
if (ENABLE_AUTOMATIC_INIT_AND_CLEANUP)
132155
set (MONGOC_NO_AUTOMATIC_GLOBALS 0)
@@ -380,9 +403,18 @@ endif () # ENABLE_SSL
380403

381404

382405
if (MONGOC_ENABLE_SASL)
383-
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-sasl.c)
384-
set(LIBS ${LIBS} ${SASL2_LIBRARY})
385-
include_directories(${SASL2_INCLUDE_DIR})
406+
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-cluster-sasl.c)
407+
if (MONGOC_ENABLE_SASL_CYRUS)
408+
message (STATUS "Compiling against Cyrus SASL")
409+
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-sasl.c)
410+
set (LIBS ${LIBS} ${SASL2_LIBRARY})
411+
include_directories(${SASL2_INCLUDE_DIR})
412+
elseif (MONGOC_ENABLE_SASL_SSPI)
413+
message (STATUS "Compiling against Windows SSPI")
414+
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-cluster-sspi.c)
415+
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-sspi.c)
416+
set (LIBS ${LIBS} secur32.lib crypt32.lib Shlwapi.lib)
417+
endif()
386418
endif()
387419

388420
add_library(mongoc_shared SHARED ${SOURCES} ${HEADERS})

build/autotools/CheckSasl.m4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ AC_SUBST(SASL_LIBS)
5454
dnl Let mongoc-config.h.in know about SASL status.
5555
if test "$sasl_mode" != "no" ; then
5656
AC_SUBST(MONGOC_ENABLE_SASL, 1)
57+
AC_SUBST(MONGOC_ENABLE_SASL_CYRUS, 1)
58+
AC_SUBST(MONGOC_ENABLE_SASL_SSPI, 0)
5759

5860
AC_CHECK_LIB([sasl2],[sasl_client_done],
5961
[have_sasl_client_done=yes],
@@ -67,5 +69,7 @@ if test "$sasl_mode" != "no" ; then
6769

6870
else
6971
AC_SUBST(MONGOC_ENABLE_SASL, 0)
72+
AC_SUBST(MONGOC_ENABLE_SASL_CYRUS, 0)
73+
AC_SUBST(MONGOC_ENABLE_SASL_SSPI, 0)
7074
AC_SUBST(MONGOC_HAVE_SASL_CLIENT_DONE, 0)
7175
fi

src/mongoc/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ NOINST_H_FILES = \
6969
src/mongoc/mongoc-client-pool-private.h \
7070
src/mongoc/mongoc-client-private.h \
7171
src/mongoc/mongoc-cluster-private.h \
72+
src/mongoc/mongoc-cluster-sasl-private.h \
73+
src/mongoc/mongoc-cluster-sspi-private.h \
7274
src/mongoc/mongoc-collection-private.h \
7375
src/mongoc/mongoc-counters-private.h \
7476
src/mongoc/mongoc-cursor-array-private.h \
@@ -99,6 +101,7 @@ NOINST_H_FILES = \
99101
src/mongoc/mongoc-read-prefs-private.h \
100102
src/mongoc/mongoc-rpc-private.h \
101103
src/mongoc/mongoc-sasl-private.h \
104+
src/mongoc/mongoc-sspi-private.h \
102105
src/mongoc/mongoc-scram-private.h \
103106
src/mongoc/mongoc-server-description-private.h \
104107
src/mongoc/mongoc-server-stream-private.h \
@@ -253,6 +256,7 @@ endif
253256
endif
254257

255258
if ENABLE_SASL
259+
MONGOC_SOURCES_SHARED += src/mongoc/mongoc-cluster-sasl.c
256260
MONGOC_SOURCES_SHARED += src/mongoc/mongoc-sasl.c
257261
endif
258262

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2017 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef MONGOC_CLUSTER_SASL_PRIVATE_H
18+
#define MONGOC_CLUSTER_SASL_PRIVATE_H
19+
20+
#if !defined(MONGOC_COMPILATION)
21+
#error "Only <mongoc.h> can be included directly."
22+
#endif
23+
24+
#include "mongoc-config.h"
25+
#include "mongoc-cluster-private.h"
26+
#include <bson.h>
27+
28+
bool
29+
_mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
30+
mongoc_stream_t *stream,
31+
const char *hostname,
32+
bson_error_t *error);
33+
bool
34+
_mongoc_cluster_get_canonicalized_name (mongoc_cluster_t *cluster, /* IN */
35+
mongoc_stream_t *node_stream, /* IN */
36+
char *name, /* OUT */
37+
size_t namelen, /* IN */
38+
bson_error_t *error); /* OUT */
39+
#endif /* MONGOC_CLUSTER_SASL_PRIVATE_H */

0 commit comments

Comments
 (0)