Skip to content

Commit 51cdb21

Browse files
authored
PHPC-2367: Add SSPI SASL, drop Cyrus on Windows (#1837)
* Support building with SSPI support under Windows * Remove support for building with Cyrus SASL on Windows * Apply feedback from Copilot * Apply code review feedback * Fix handling of missing SASL libs when relying on default value for with-mongodb-sasl
1 parent 6c715e9 commit 51cdb21

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

config.w32

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function MONGODB_ADD_SOURCES(dir, file_list)
7070
}
7171

7272
ARG_ENABLE("mongodb", "MongoDB support", "no");
73-
ARG_WITH("mongodb-sasl", "MongoDB: Build against Cyrus-SASL", "yes");
73+
ARG_WITH("mongodb-sasl", "MongoDB: Build with SSPI SASL (valid values: 'yes' (fallback to SSPI), 'sspi', 'no')", "yes");
7474
ARG_WITH("mongodb-client-side-encryption", "MongoDB: Enable client-side encryption", "yes");
7575

7676
if (PHP_MONGODB != "no") {
@@ -232,21 +232,33 @@ if (PHP_MONGODB != "no") {
232232
WARNING("mongodb libopenssl support not enabled, libs not found");
233233
}
234234

235-
// TODO: Support building with native GSSAPI (SSPI) on Windows
236-
if (PHP_MONGODB_SASL != "no" &&
237-
CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) &&
238-
CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB")) {
239-
mongoc_opts.MONGOC_ENABLE_SASL = 1;
240-
mongoc_opts.MONGOC_ENABLE_SASL_CYRUS = 1;
241-
242-
// Referenced by _mongoc_cyrus_verifyfile_cb in mongoc-cyrus.c on Windows
243-
ADD_FLAG("CFLAGS_MONGODB", "/D MONGOC_CYRUS_PLUGIN_PATH_PREFIX=NULL");
244-
245-
if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) {
246-
mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1;
235+
has_sasl_libs = CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) &&
236+
CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB");
237+
if (PHP_MONGODB_SASL != "no") {
238+
if (has_sasl_libs) {
239+
// TODO 3.0: Remove warning on "yes" as it implies "sspi"
240+
if (PHP_MONGODB_SASL == "yes") {
241+
WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI; use '--with-mongodb-sasl=sspi' to avoid this warning.");
242+
PHP_MONGODB_SASL = "sspi";
243+
}
244+
245+
if (PHP_MONGODB_SASL == "sspi") {
246+
mongoc_opts.MONGOC_ENABLE_SASL = 1;
247+
mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1;
248+
} else {
249+
ERROR("MongoDB SASL support not enabled, unknown value for --with-mongodb-sasl: " + PHP_MONGODB_SASL);
250+
}
251+
252+
if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) {
253+
mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1;
254+
}
255+
} else if (PHP_MONGODB_SASL != "yes") {
256+
// If the user explicitly requested SASL support, we error out if the
257+
// necessary libraries are not found.
258+
ERROR("MongoDB SASL support not enabled, libs not found");
259+
} else {
260+
WARNING("MongoDB SASL support not enabled, libs not found");
247261
}
248-
} else if (PHP_MONGODB_SASL != "no") {
249-
WARNING("mongodb libsasl support not enabled, libs not found");
250262
}
251263

252264
if (PHP_MONGODB_CLIENT_SIDE_ENCRYPTION != "no" && mongoc_ssl_found) {

0 commit comments

Comments
 (0)