From 570d3ec125055c0f40447d2ba7439cb959d47d1c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 26 May 2025 16:13:29 +0200 Subject: [PATCH 1/5] Support building with SSPI support under Windows --- config.w32 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/config.w32 b/config.w32 index f18d4d2bf..94a79e23e 100644 --- a/config.w32 +++ b/config.w32 @@ -70,7 +70,7 @@ function MONGODB_ADD_SOURCES(dir, file_list) } ARG_ENABLE("mongodb", "MongoDB support", "no"); -ARG_WITH("mongodb-sasl", "MongoDB: Build against Cyrus-SASL", "yes"); +ARG_WITH("mongodb-sasl", "MongoDB: Build with SASL (cyrus, sspi)", "yes"); ARG_WITH("mongodb-client-side-encryption", "MongoDB: Enable client-side encryption", "yes"); if (PHP_MONGODB != "no") { @@ -232,15 +232,21 @@ if (PHP_MONGODB != "no") { WARNING("mongodb libopenssl support not enabled, libs not found"); } - // TODO: Support building with native GSSAPI (SSPI) on Windows if (PHP_MONGODB_SASL != "no" && CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) && CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB")) { mongoc_opts.MONGOC_ENABLE_SASL = 1; - mongoc_opts.MONGOC_ENABLE_SASL_CYRUS = 1; - // Referenced by _mongoc_cyrus_verifyfile_cb in mongoc-cyrus.c on Windows - ADD_FLAG("CFLAGS_MONGODB", "/D MONGOC_CYRUS_PLUGIN_PATH_PREFIX=NULL"); + if (PHP_MONGODB_SASL == "yes" || PHP_MONGODB_SASL == "cyrus") { + mongoc_opts.MONGOC_ENABLE_SASL_CYRUS = 1; + + // Referenced by _mongoc_cyrus_verifyfile_cb in mongoc-cyrus.c on Windows + ADD_FLAG("CFLAGS_MONGODB", "/D MONGOC_CYRUS_PLUGIN_PATH_PREFIX=NULL"); + } else if (PHP_MONGODB_SASL == "sspi") { + mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; + } else { + WARNING("mongodb sasl support not enabled, unknown value for PHP_MONGODB_SASL: " + PHP_MONGODB_SASL); + } if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) { mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1; From 3752cd6876cfbc75a2ffe2f79d720bebc2f8954d Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 26 May 2025 16:15:49 +0200 Subject: [PATCH 2/5] Remove support for building with Cyrus SASL on Windows --- config.w32 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config.w32 b/config.w32 index 94a79e23e..16f0024be 100644 --- a/config.w32 +++ b/config.w32 @@ -70,7 +70,7 @@ function MONGODB_ADD_SOURCES(dir, file_list) } ARG_ENABLE("mongodb", "MongoDB support", "no"); -ARG_WITH("mongodb-sasl", "MongoDB: Build with SASL (cyrus, sspi)", "yes"); +ARG_WITH("mongodb-sasl", "MongoDB: Build with SSPI SASL", "yes"); ARG_WITH("mongodb-client-side-encryption", "MongoDB: Enable client-side encryption", "yes"); if (PHP_MONGODB != "no") { @@ -237,12 +237,12 @@ if (PHP_MONGODB != "no") { CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB")) { mongoc_opts.MONGOC_ENABLE_SASL = 1; - if (PHP_MONGODB_SASL == "yes" || PHP_MONGODB_SASL == "cyrus") { - mongoc_opts.MONGOC_ENABLE_SASL_CYRUS = 1; + // TODO 3.0: Remove warning on "yes" as it implies "sspi" + if (PHP_MONGODB_SASL == "yes") { + WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI."); + } - // Referenced by _mongoc_cyrus_verifyfile_cb in mongoc-cyrus.c on Windows - ADD_FLAG("CFLAGS_MONGODB", "/D MONGOC_CYRUS_PLUGIN_PATH_PREFIX=NULL"); - } else if (PHP_MONGODB_SASL == "sspi") { + if (PHP_MONGODB_SASL == "yes" || PHP_MONGODB_SASL == "sspi") { mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; } else { WARNING("mongodb sasl support not enabled, unknown value for PHP_MONGODB_SASL: " + PHP_MONGODB_SASL); From b6042eee5b01a45f48a8bef1d639e987fd35e018 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 27 May 2025 13:09:15 +0200 Subject: [PATCH 3/5] Apply feedback from Copilot --- config.w32 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.w32 b/config.w32 index 16f0024be..1cbd7c021 100644 --- a/config.w32 +++ b/config.w32 @@ -70,7 +70,7 @@ function MONGODB_ADD_SOURCES(dir, file_list) } ARG_ENABLE("mongodb", "MongoDB support", "no"); -ARG_WITH("mongodb-sasl", "MongoDB: Build with SSPI SASL", "yes"); +ARG_WITH("mongodb-sasl", "MongoDB: Build with SSPI SASL (valid values: 'yes' (fallback to SSPI), 'sspi', 'no')", "yes"); ARG_WITH("mongodb-client-side-encryption", "MongoDB: Enable client-side encryption", "yes"); if (PHP_MONGODB != "no") { @@ -235,17 +235,17 @@ if (PHP_MONGODB != "no") { if (PHP_MONGODB_SASL != "no" && CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) && CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB")) { - mongoc_opts.MONGOC_ENABLE_SASL = 1; // TODO 3.0: Remove warning on "yes" as it implies "sspi" if (PHP_MONGODB_SASL == "yes") { - WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI."); + WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI; use '--with-mongodb-sasl=sspi' to avoid this warning."); } if (PHP_MONGODB_SASL == "yes" || PHP_MONGODB_SASL == "sspi") { + mongoc_opts.MONGOC_ENABLE_SASL = 1; mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; } else { - WARNING("mongodb sasl support not enabled, unknown value for PHP_MONGODB_SASL: " + PHP_MONGODB_SASL); + WARNING("MongoDB SASL support not enabled, unknown value for PHP_MONGODB_SASL: " + PHP_MONGODB_SASL); } if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) { From f6feb5e7d8302a96deed2bc0abeac013f3b3597a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 2 Jun 2025 09:09:05 +0200 Subject: [PATCH 4/5] Apply code review feedback --- config.w32 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.w32 b/config.w32 index 1cbd7c021..54a10d421 100644 --- a/config.w32 +++ b/config.w32 @@ -245,14 +245,14 @@ if (PHP_MONGODB != "no") { mongoc_opts.MONGOC_ENABLE_SASL = 1; mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; } else { - WARNING("MongoDB SASL support not enabled, unknown value for PHP_MONGODB_SASL: " + PHP_MONGODB_SASL); + ERROR("MongoDB SASL support not enabled, unknown value for --with-mongodb-sasl: " + PHP_MONGODB_SASL); } if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) { mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1; } } else if (PHP_MONGODB_SASL != "no") { - WARNING("mongodb libsasl support not enabled, libs not found"); + ERROR("MongoDB SASL support not enabled, libs not found"); } if (PHP_MONGODB_CLIENT_SIDE_ENCRYPTION != "no" && mongoc_ssl_found) { From 6aac94c8ce34eddeec91d32fdb4c2bfadd6b736f Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 2 Jun 2025 09:18:27 +0200 Subject: [PATCH 5/5] Fix handling of missing SASL libs when relying on default value for with-mongodb-sasl --- config.w32 | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/config.w32 b/config.w32 index 54a10d421..43df7f9cf 100644 --- a/config.w32 +++ b/config.w32 @@ -232,27 +232,33 @@ if (PHP_MONGODB != "no") { WARNING("mongodb libopenssl support not enabled, libs not found"); } - if (PHP_MONGODB_SASL != "no" && - CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) && - CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB")) { - - // TODO 3.0: Remove warning on "yes" as it implies "sspi" - if (PHP_MONGODB_SASL == "yes") { - WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI; use '--with-mongodb-sasl=sspi' to avoid this warning."); - } - - if (PHP_MONGODB_SASL == "yes" || PHP_MONGODB_SASL == "sspi") { - mongoc_opts.MONGOC_ENABLE_SASL = 1; - mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; + has_sasl_libs = CHECK_LIB("libsasl.lib", "mongodb", PHP_MONGODB) && + CHECK_HEADER_ADD_INCLUDE("sasl/sasl.h", "CFLAGS_MONGODB"); + if (PHP_MONGODB_SASL != "no") { + if (has_sasl_libs) { + // TODO 3.0: Remove warning on "yes" as it implies "sspi" + if (PHP_MONGODB_SASL == "yes") { + WARNING("Cyrus SASL support for Windows was removed. Falling back to SSPI; use '--with-mongodb-sasl=sspi' to avoid this warning."); + PHP_MONGODB_SASL = "sspi"; + } + + if (PHP_MONGODB_SASL == "sspi") { + mongoc_opts.MONGOC_ENABLE_SASL = 1; + mongoc_opts.MONGOC_ENABLE_SASL_SSPI = 1; + } else { + ERROR("MongoDB SASL support not enabled, unknown value for --with-mongodb-sasl: " + PHP_MONGODB_SASL); + } + + if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) { + mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1; + } + } else if (PHP_MONGODB_SASL != "yes") { + // If the user explicitly requested SASL support, we error out if the + // necessary libraries are not found. + ERROR("MongoDB SASL support not enabled, libs not found"); } else { - ERROR("MongoDB SASL support not enabled, unknown value for --with-mongodb-sasl: " + PHP_MONGODB_SASL); - } - - if (CHECK_FUNC_IN_HEADER("sasl/sasl.h", "sasl_client_done")) { - mongoc_opts.MONGOC_HAVE_SASL_CLIENT_DONE = 1; + WARNING("MongoDB SASL support not enabled, libs not found"); } - } else if (PHP_MONGODB_SASL != "no") { - ERROR("MongoDB SASL support not enabled, libs not found"); } if (PHP_MONGODB_CLIENT_SIDE_ENCRYPTION != "no" && mongoc_ssl_found) {