diff --git a/.gitignore b/.gitignore index 6df556723..565c36408 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ acinclude.m4 aclocal.m4 autom4te.cache -build +/build config.guess config.h config.h.in @@ -49,7 +49,7 @@ php.ini !.github/ !tests/utils/*.php !.travis.yml -!.travis.scripts/* +!.travis.scripts/ !scripts diff --git a/.travis.scripts/before_install.sh b/.travis.scripts/before_install.sh new file mode 100755 index 000000000..9feb7ea5a --- /dev/null +++ b/.travis.scripts/before_install.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +if [ "${TRAVIS_OS_NAME}" = "linux" ]; then + # https://github.com/eddyxu/cpp-coveralls#linux + pip install --user cpp-coveralls +fi + +if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + brew update + brew upgrade + + brew tap homebrew/homebrew-php + brew install "${PHP_VERSION}" + + # http://brewformulas.org/Lcov + brew install lcov + + # https://github.com/eddyxu/cpp-coveralls#os-x + brew install pyenv + eval "$(pyenv init -)" + pyenv install 2.7.6 + pyenv global 2.7.6 + pyenv rehash + pip install cpp-coveralls + pyenv rehash +fi diff --git a/.travis.scripts/before_script.sh b/.travis.scripts/before_script.sh new file mode 100755 index 000000000..a9555b40a --- /dev/null +++ b/.travis.scripts/before_script.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +CONFIGURE_OPTS="--enable-developer-flags --enable-coverage" + +if [ -n "${SSL_VERSION}" ]; then + CONFIGURE_OPTS="${CONFIGURE_OPTS} --with-mongodb-ssl=${SSL_VERSION}" +fi + +phpize +./configure ${CONFIGURE_OPTS} +make all -j4 +make install + +# Add the extension to php.ini +echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` + +# Predefine the test server +echo '{"STANDALONE": "mongodb:\/\/127.0.0.1:27017"}' > /tmp/PHONGO-SERVERS.json diff --git a/.travis.scripts/compile.sh b/.travis.scripts/compile.sh deleted file mode 100755 index ccc49f29b..000000000 --- a/.travis.scripts/compile.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -trap abort_on_failure ERR - -LCOV_VERSION=1.11 - - -abort_on_failure () { - echo "Last command failed, exising" - exit 42; -} - -build_lcov() { - mkdir tmp-lcov - pushd tmp-lcov - wget -O lcov.tar.gz http://downloads.sourceforge.net/ltp/lcov-${LCOV_VERSION}.tar.gz - tar zxf lcov.tar.gz --strip-components=1 - sudo make install - popd -} -build_lcov - -phpize -./configure --enable-developer-flags --enable-coverage -make all -j4 -sudo make install -echo "Use the most-up-to-date run-tests.. old ones like 5.3 don't report failure exit codes" -wget -O run-tests.php https://raw.githubusercontent.com/php/php-src/master/run-tests.php - - - -rm -rf tmp-lcov tmp # coveralls may pick it up and lie about our coverage - -echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` - -MONGO=`which mongo` -mongod --version -ls $MONGO* -pwd - - -# Predefine the test server -echo '{"STANDALONE": "mongodb:\/\/127.0.0.1:27017"}' > /tmp/PHONGO-SERVERS.json diff --git a/.travis.scripts/debug-core.sh b/.travis.scripts/debug-core.sh index ed167cf93..4e9026652 100755 --- a/.travis.scripts/debug-core.sh +++ b/.travis.scripts/debug-core.sh @@ -1,5 +1,10 @@ #!/bin/sh -PHP=/home/travis/.phpenv/versions/`php -r 'echo PHP_VERSION;'`/bin/php -echo "backtrace full" | gdb $PHP $1 +if [ "${TRAVIS_OS_NAME}" != "osx" ]; then + # https://www.ics.uci.edu/~pattis/common/handouts/macmingweclipse/allexperimental/mac-gdb-install.html + echo "Cannot debug core files on macOS: ${1}" + exit 1 +fi +PHP_BINARY=`which php` +gdb -batch -ex "bt full" -ex "quit" "${PHP_BINARY}" "${1}" diff --git a/.travis.scripts/debug-diff.sh b/.travis.scripts/debug-diff.sh new file mode 100755 index 000000000..e20009c33 --- /dev/null +++ b/.travis.scripts/debug-diff.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +EXP=`echo $1 | sed 's/.diff$/.exp/'` +OUT=`echo $1 | sed 's/.diff$/.out/'` +SEP="--------------------------------------------------------------------------------" + +echo $EXP +echo $SEP +cat $EXP; echo +echo $SEP; echo + +echo $OUT +echo $SEP +cat $OUT; echo +echo $SEP; echo diff --git a/.travis.scripts/debug-script.sh b/.travis.scripts/debug-script.sh deleted file mode 100755 index 9f66723ba..000000000 --- a/.travis.scripts/debug-script.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -EXP=`echo $1 | sed 's/diff/exp/'` -OUT=`echo $1 | sed 's/diff/out/'` - -echo "FILE $1" - -echo $EXP -echo "======" -cat $EXP -echo "======" - -echo $OUT -echo "======" -cat $OUT -echo "======" - -echo - diff --git a/.travis.yml b/.travis.yml index d203b29ec..69e4007db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,33 @@ language: php -php: - - 7.2 - - 7.1 - - 7.0 - - 5.6 - - 5.5 + +addons: + apt: + packages: + - gdb + - lcov + +matrix: + include: + - os: linux + dist: trusty + sudo: false + php: 5.5 + - os: linux + dist: trusty + sudo: false + php: 5.6 + - os: linux + dist: trusty + sudo: false + php: 7.0 + - os: linux + dist: trusty + sudo: false + php: 7.1 + - os: linux + dist: trusty + sudo: false + php: 7.2 services: - mongodb @@ -13,24 +36,15 @@ env: global: - TEST_PHP_ARGS="-q -s output.txt -g XFAIL,FAIL,BORK,WARN,LEAK,SKIP -x --show-diff" - REPORT_EXIT_STATUS=1 - - MONGODB_ORCHESTRATION="http://localhost:8889" - - MONGODB_ORCHESTRATION_REPO="git+git://github.com/mongodb/mongo-orchestration@master" - - MONGODB_ORCHESTRATION_PRESETS_ROOT=`pwd` - - secure: "Dofd9NvXIKEat1PMiia3RQgNsJLaKtzZRf9rM4MsqFaBQPbJmVWPANJkayJPcK+l8pLxHyzzH7WqxML+SlBhBTHdJB++1woXxoVwm+sDdwSye6e+eXc3/zRUxb7zyItBZcvVp2tIJpx5kXJb+CoUQakbfWEQQFk4xrOF0R56+8Y=" - - secure: "pfGVPucvgcgcefhtzAVeejlpOtn4TnAqJSTM8mJkBl36KdU9P7hMuD3czQ4drWgzZ373/VT5UVhLu/HNsdbW0YBTeqPKJ4YNjqVVLytI8xT7y2Lw9l+I7o93j98TMgAoo8nVRmp/E4D6yutbKK1eddrcmf899R1iJbw8v8d1Ht8=" before_install: - - sudo pip install --upgrade cpp-coveralls - - sudo pip install ${MONGODB_ORCHESTRATION_REPO} - - sudo apt-get update - - sudo apt-get install gdb valgrind - - sudo apt-get install cdbs debhelper build-essential python-lxml + - .travis.scripts/before_install.sh - php -r 'if ( ! ($f = php_ini_loaded_file())) { $f = PHP_CONFIG_FILE_PATH . "/php.ini"; } file_put_contents($f, "variables_order=EGPCS\n", FILE_APPEND); $a = file($f, FILE_IGNORE_NEW_LINES); var_dump($a[count($a)-1]);' before_script: - ulimit -a - ulimit -c unlimited || true - - "./.travis.scripts/compile.sh" + - .travis.scripts/before_script.sh script: - make test @@ -39,5 +53,5 @@ after_success: - make coveralls after_failure: - - find . -name \*core\* -exec ./.travis.scripts/debug-core.sh {} \; - - find . -name \*diff -exec ./.travis.scripts/debug-script.sh {} \; + - find . -name 'core*' -exec .travis.scripts/debug-core.sh {} \; + - find . -name '*.diff' -exec .travis.scripts/debug-diff.sh {} \; diff --git a/config.m4 b/config.m4 index 2c95209a4..d90743625 100644 --- a/config.m4 +++ b/config.m4 @@ -1,10 +1,8 @@ dnl config.m4 for extension mongodb -PHP_ARG_ENABLE(mongodb, whether to enable mongodb support, -[ --enable-mongodb Enable mongodb support]) -PHP_ARG_WITH(openssl-dir, OpenSSL dir for mongodb, -[ --with-openssl-dir[=DIR] openssl install prefix], yes, no) -PHP_ARG_WITH(system-ciphers, whether to use system default cipher list instead of hardcoded value, -[ --with-system-ciphers OPENSSL: Use system default cipher list instead of hardcoded value], no, no) +PHP_ARG_ENABLE([mongodb], + [whether to enable MongoDB support], + [AC_HELP_STRING([--enable-mongodb], + [Enable MongoDB support])]) dnl borrowed from libmongoc configure.ac dnl AS_VAR_COPY is available in AC 2.64 and on, but we only require 2.60. @@ -83,7 +81,7 @@ AC_DEFUN([PHP_BSON_CLOCK], fi ]) -if test "$MONGODB" != "no"; then +if test "$PHP_MONGODB" != "no"; then AC_MSG_CHECKING([Check for supported PHP versions]) PHP_MONGODB_FOUND_VERSION=`${PHP_CONFIG} --version` PHP_MONGODB_FOUND_VERNUM=`echo "${PHP_MONGODB_FOUND_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 100 + [$]2) * 100 + [$]3;}'` @@ -92,8 +90,12 @@ if test "$MONGODB" != "no"; then AC_MSG_ERROR([not supported. Need a PHP version >= 5.5.0 (found $PHP_MONGODB_FOUND_VERSION)]) fi - PHP_ARG_ENABLE(developer-flags, whether to enable developer build flags, - [ --enable-developer-flags Enable developer flags],, no) + PHP_ARG_ENABLE([developer-flags], + [whether to enable developer build flags], + [AC_HELP_STRING([--enable-developer-flags], + [MongoDB: Enable developer flags [default=no]])], + [no], + [no]) if test "$PHP_DEVELOPER_FLAGS" = "yes"; then dnl Warn about functions which might be candidates for format attributes @@ -144,8 +146,12 @@ if test "$MONGODB" != "no"; then fi - PHP_ARG_ENABLE(coverage, whether to enable code coverage, - [ --enable-coverage Enable developer code coverage information],, no) + PHP_ARG_ENABLE([coverage], + [whether to enable code coverage], + [AC_HELP_STRING([--enable-coverage], + [MongoDB: Enable developer code coverage information [default=no]])], + [no], + [no]) if test "$PHP_COVERAGE" = "yes"; then PHP_CHECK_GCC_ARG(-fprofile-arcs, COVERAGE_CFLAGS="$COVERAGE_CFLAGS -fprofile-arcs") @@ -220,13 +226,21 @@ if test "$MONGODB" != "no"; then src/MongoDB/Monitoring/functions.c \ " - PHP_ARG_WITH(libbson, whether to use system libbson, - [ --with-libbson Use system libbson], no, no) - PHP_ARG_WITH(libmongoc, whether to use system libmongoc, - [ --with-libmongoc Use system libmongoc], no, no) + PHP_ARG_WITH([libbson], + [whether to use system libbson], + [AS_HELP_STRING([--with-libbson=@<:@yes/no@:>@], + [MongoDB: Use system libbson [default=no]])], + [no], + [no]) + PHP_ARG_WITH([libmongoc], + [whether to use system libmongoc], + [AS_HELP_STRING([--with-libmongoc=@<:@yes/no@:>@], + [MongoDB: Use system libmongoc [default=no]])], + [no], + [no]) if test "$PHP_LIBBSON" != "no"; then - if test "$PHP_LIBMONGOC" == "no"; then + if test "$PHP_LIBMONGOC" = "no"; then AC_MSG_ERROR(Cannot use system libbson and bundled libmongoc) fi @@ -264,7 +278,7 @@ if test "$MONGODB" != "no"; then AC_MSG_RESULT(...) if test "$PHP_LIBMONGOC" != "no"; then - if test "$PHP_LIBBSON" == "no"; then + if test "$PHP_LIBBSON" = "no"; then AC_MSG_ERROR(Cannot use system libmongoc and bundled libbson) fi @@ -297,20 +311,10 @@ if test "$MONGODB" != "no"; then PHP_ADD_SOURCES_X(PHP_EXT_DIR(mongodb)[src/libmongoc/src/mongoc], $PHP_MONGODB_MONGOC_SOURCES, $PHP_MONGODB_MONGOC_CFLAGS, shared_objects_mongodb, yes) - AC_SUBST(MONGOC_ENABLE_CRYPTO, 0) - AC_SUBST(MONGOC_ENABLE_SSL, 0) - AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 0) - AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 0) - AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 0) + m4_include(scripts/build/autotools/m4/pkg.m4) - PHP_SETUP_OPENSSL(MONGODB_SHARED_LIBADD, [ - AC_SUBST(MONGOC_ENABLE_CRYPTO, 1) - AC_SUBST(MONGOC_ENABLE_SSL, 1) - AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1) - AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 1) - - AC_CHECK_DECLS([ASN1_STRING_get0_data], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 1)], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 0)], [[#include ]]) - ]) + m4_include(scripts/build/autotools/CheckHost.m4) + m4_include(scripts/build/autotools/CheckSSL.m4) if test "$PHP_SYSTEM_CIPHERS" != "no"; then AC_SUBST(MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE, 1) @@ -318,23 +322,12 @@ if test "$MONGODB" != "no"; then AC_SUBST(MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE, 0) fi - dnl TODO: Support building with Secure Transport on OSX - AC_SUBST(MONGOC_ENABLE_SSL_SECURE_TRANSPORT, 0) - AC_SUBST(MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO, 0) - - dnl Secure Channel only applies to Windows - AC_SUBST(MONGOC_ENABLE_SSL_SECURE_CHANNEL, 0) - AC_SUBST(MONGOC_ENABLE_CRYPTO_CNG, 0) - - AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 0) - AC_SUBST(MONGOC_NO_AUTOMATIC_GLOBALS, 1) AC_CHECK_TYPE([socklen_t], [AC_SUBST(MONGOC_HAVE_SOCKLEN, 1)], [AC_SUBST(MONGOC_HAVE_SOCKLEN, 0)], [#include ]) with_snappy=auto with_zlib=auto - m4_include(src/libmongoc/build/autotools/m4/pkg.m4) m4_include(src/libmongoc/build/autotools/CheckSnappy.m4) m4_include(src/libmongoc/build/autotools/CheckZlib.m4) @@ -350,8 +343,12 @@ if test "$MONGODB" != "no"; then fi - PHP_ARG_WITH(mongodb-sasl, for Cyrus SASL support, - [ --with-mongodb-sasl[=DIR] mongodb: Include Cyrus SASL support], auto, no) + PHP_ARG_WITH([mongodb-sasl], + [for Cyrus SASL support], + [AC_HELP_STRING([--with-mongodb-sasl=@<:@auto/no/DIR@:>@], + [MongoDB: Cyrus SASL support [default=auto]])], + [auto], + [no]) AC_SUBST(MONGOC_ENABLE_SASL, 0) AC_SUBST(MONGOC_HAVE_SASL_CLIENT_DONE, 0) @@ -434,7 +431,7 @@ if test "$MONGODB" != "no"; then PHP_ADD_BUILD_DIR([$ext_builddir/src/MongoDB/Exception/]) PHP_ADD_BUILD_DIR([$ext_builddir/src/MongoDB/Monitoring/]) PHP_ADD_BUILD_DIR([$ext_builddir/src/contrib/]) - if test "$PHP_LIBMONGOC" == "no"; then + if test "$PHP_LIBMONGOC" = "no"; then PHP_ADD_INCLUDE([$ext_srcdir/src/libmongoc/src/mongoc/]) PHP_ADD_BUILD_DIR([$ext_builddir/src/libmongoc/src/mongoc/]) if test "x$with_zlib" = "xbundled"; then @@ -442,7 +439,7 @@ if test "$MONGODB" != "no"; then PHP_ADD_BUILD_DIR([$ext_srcdir/src/libmongoc/src/zlib-1.2.11/]) fi fi - if test "$PHP_LIBBSON" == "no"; then + if test "$PHP_LIBBSON" = "no"; then m4_include(src/libbson/build/autotools/CheckAtomics.m4) m4_include(src/libbson/build/autotools/FindDependencies.m4) m4_include(src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4) @@ -485,7 +482,7 @@ if test "$MONGODB" != "no"; then AC_SUBST(BSON_HAVE_SNPRINTF, 0) fi - if test "$PHP_LIBMONGOC" == "no"; then + if test "$PHP_LIBMONGOC" = "no"; then backup_srcdir=${srcdir} srcdir=${srcdir}/src/libmongoc/ m4_include(src/libmongoc/build/autotools/Versions.m4) @@ -502,7 +499,7 @@ if test "$MONGODB" != "no"; then AC_OUTPUT($srcdir/src/libmongoc/src/zlib-1.2.11/zconf.h) fi fi - if test "$PHP_LIBBSON" == "no"; then + if test "$PHP_LIBBSON" = "no"; then backup_srcdir=${srcdir} srcdir=${srcdir}/src/libbson/ m4_include(src/libbson/build/autotools/Versions.m4) diff --git a/scripts/build/autotools/CheckHost.m4 b/scripts/build/autotools/CheckHost.m4 new file mode 100644 index 000000000..a5b7fa835 --- /dev/null +++ b/scripts/build/autotools/CheckHost.m4 @@ -0,0 +1,54 @@ +AC_CANONICAL_HOST + +os_win32=no +os_netbsd=no +os_freebsd=no +os_openbsd=no +os_hpux=no +os_linux=no +os_solaris=no +os_darwin=no +os_gnu=no + +case "$host" in + *-mingw*|*-*-cygwin*) + os_win32=yes + TARGET_OS=windows + ;; + *-*-*netbsd*) + os_netbsd=yes + ARGET_OS=unix + ;; + *-*-*freebsd*) + os_freebsd=yes + TARGET_OS=unix + ;; + *-*-*openbsd*) + os_openbsd=yes + TARGET_OS=unix + ;; + *-*-hpux*) + os_hpux=yes + TARGET_OS=unix + ;; + *-*-linux*) + os_linux=yes + os_gnu=yes + TARGET_OS=unix + ;; + *-*-solaris*) + os_solaris=yes + TARGET_OS=unix + ;; + *-*-darwin*) + os_darwin=yes + TARGET_OS=unix + ;; + gnu*|k*bsd*-gnu*) + os_gnu=yes + TARGET_OS=unix + ;; + *) + AC_MSG_WARN([*** Please add $host to configure.ac checks!]) + ;; +esac diff --git a/scripts/build/autotools/CheckSSL.m4 b/scripts/build/autotools/CheckSSL.m4 new file mode 100644 index 000000000..e45bdd94c --- /dev/null +++ b/scripts/build/autotools/CheckSSL.m4 @@ -0,0 +1,218 @@ +PHP_ARG_WITH([mongodb-ssl], + [whether to enable crypto and TLS], + [AS_HELP_STRING([--with-mongodb-ssl=@<:@auto/no/openssl/libressl/darwin@:>@], + [MongoDB: Enable TLS connections and SCRAM-SHA-1 authentication [default=auto]])], + [auto], + [no]) + +PHP_ARG_WITH([openssl-dir], + [deprecated option for OpenSSL library path], + [AC_HELP_STRING([--with-openssl-dir=@<:@auto/DIR@:>@], + [MongoDB: OpenSSL library path (deprecated for pkg-config) [default=auto]])], + [auto], + [no]) + +AS_IF([test "$PHP_MONGODB_SSL" = "openssl" -o "$PHP_MONGODB_SSL" = "auto"],[ + found_openssl="no" + + PKG_CHECK_MODULES([PHP_MONGODB_SSL],[openssl],[ + PHP_EVAL_INCLINE([$PHP_MONGODB_SSL_CFLAGS]) + PHP_EVAL_LIBLINE([$PHP_MONGODB_SSL_LIBS],[MONGODB_SHARED_LIBADD]) + PHP_MONGODB_SSL="openssl" + found_openssl="yes" + + old_CFLAGS="$CFLAGS" + CFLAGS="$PHP_MONGODB_SSL_CFLAGS $CFLAGS" + + AC_CHECK_DECLS([ASN1_STRING_get0_data], + [have_ASN1_STRING_get0_data="yes"], + [have_ASN1_STRING_get0_data="no"], + [[#include ]]) + + CFLAGS="$old_CFLAGS" + ],[ + unset OPENSSL_INCDIR + unset OPENSSL_LIBDIR + + dnl Use a list of directories from PHP_SETUP_OPENSSL by default. + dnl Support documented "auto" and older, undocumented "yes" options + if test "$PHP_OPENSSL_DIR" = "auto" -o "$PHP_OPENSSL_DIR" = "yes"; then + PHP_OPENSSL_DIR="/usr/local/ssl /usr/local /usr /usr/local/openssl" + fi + + for i in $PHP_OPENSSL_DIR; do + if test -r $i/include/openssl/evp.h; then + OPENSSL_INCDIR="$i/include" + fi + if test -r $i/$PHP_LIBDIR/libssl.a -o -r $i/$PHP_LIBDIR/libssl.$SHLIB_SUFFIX_NAME; then + OPENSSL_LIBDIR="$i/$PHP_LIBDIR" + fi + test -n "$OPENSSL_INCDIR" && test -n "$OPENSSL_LIBDIR" && break + done + + if test -n "$OPENSSL_LIBDIR"; then + OPENSSL_LIBDIR_LDFLAG="-L$OPENSSL_LIBDIR" + fi + + PHP_CHECK_LIBRARY([crypto], + [EVP_DigestInit_ex], + [have_crypto_lib="yes"], + [have_crypto_lib="no"], + [$OPENSSL_LIBDIR_LDFLAG]) + PHP_CHECK_LIBRARY([ssl], + [SSL_library_init], + [have_ssl_lib="yes"], + [have_ssl_lib="no"], + [$OPENSSL_LIBDIR_LDFLAG -lcrypto]) + + if test "$have_ssl_lib" = "yes" -a "$have_crypto_lib" = "yes"; then + PHP_ADD_LIBRARY([ssl],,[MONGODB_SHARED_LIBADD]) + PHP_ADD_LIBRARY([crypto],,[MONGODB_SHARED_LIBADD]) + + if test -n "$OPENSSL_LIBDIR"; then + PHP_ADD_LIBPATH([$OPENSSL_LIBDIR],[MONGODB_SHARED_LIBADD]) + fi + + if test -n "$OPENSSL_INCDIR"; then + PHP_ADD_INCLUDE($OPENSSL_INCDIR) + fi + + old_CFLAGS="$CFLAGS" + CFLAGS="-I$OPENSSL_INCDIR $CFLAGS" + + AC_CHECK_DECLS([ASN1_STRING_get0_data], + [have_ASN1_STRING_get0_data="yes"], + [have_ASN1_STRING_get0_data="no"], + [[#include ]]) + + CFLAGS="$old_CFLAGS" + + PHP_MONGODB_SSL="openssl" + found_openssl="yes" + fi + ]) + + if test "$PHP_MONGODB_SSL" = "openssl" -a "$found_openssl" != "yes"; then + AC_MSG_ERROR([OpenSSL libraries and development headers could not be found]) + fi +]) + +AS_IF([test "$PHP_MONGODB_SSL" = "libressl" -o "$PHP_MONGODB_SSL" = "auto"],[ + found_libressl="no" + + PKG_CHECK_MODULES([PHP_MONGODB_SSL],[libtls libcrypto],[ + PHP_EVAL_INCLINE([$PHP_MONGODB_SSL_CFLAGS]) + PHP_EVAL_LIBLINE([$PHP_MONGODB_SSL_LIBS],[MONGODB_SHARED_LIBADD]) + PHP_MONGODB_SSL="libressl" + found_libressl="yes" + ],[ + PHP_CHECK_LIBRARY([crypto], + [EVP_DigestInit_ex], + [have_crypto_lib="yes"], + [have_crypto_lib="no"]) + PHP_CHECK_LIBRARY([tls], + [tls_init], + [have_ssl_lib="yes"], + [have_ssl_lib="no"], + [-lcrypto]) + + if test "$have_ssl_lib" = "yes" -a "$have_crypto_lib" = "yes"; then + PHP_ADD_LIBRARY([tls],,[MONGODB_SHARED_LIBADD]) + PHP_ADD_LIBRARY([crypto],,[MONGODB_SHARED_LIBADD]) + PHP_MONGODB_SSL="libressl" + found_libressl="yes" + fi + ]) + + if test "$PHP_MONGODB_SSL" = "libressl" -a "$found_libressl" != "yes"; then + AC_MSG_ERROR([LibreSSL libraries and development headers could not be found]) + fi +]) + +AS_IF([test "$PHP_MONGODB_SSL" = "darwin" -o \( "$PHP_MONGODB_SSL" = "auto" -a "$os_darwin" = "yes" \)],[ + if test "$os_darwin" = "no"; then + AC_MSG_ERROR([Darwin SSL is only supported on macOS]) + fi + dnl PHP_FRAMEWORKS is only used for SAPI builds, so use MONGODB_SHARED_LIBADD for shared builds + if test "$ext_shared" = "yes"; then + MONGODB_SHARED_LIBADD="-framework Security -framework CoreFoundation $MONGODB_SHARED_LIBADD" + else + PHP_ADD_FRAMEWORK([Security]) + PHP_ADD_FRAMEWORK([CoreFoundation]) + fi + PHP_MONGODB_SSL="darwin" +]) + +AS_IF([test "$PHP_MONGODB_SSL" = "auto"],[ + PHP_MONGODB_SSL="no" +]) + +AC_MSG_CHECKING([which TLS library to use]) +AC_MSG_RESULT([$PHP_MONGODB_SSL]) + +dnl Disable Windows SSL and crypto +AC_SUBST(MONGOC_ENABLE_SSL_SECURE_CHANNEL, 0) +AC_SUBST(MONGOC_ENABLE_CRYPTO_CNG, 0) + +if test "$PHP_MONGODB_SSL" = "openssl" -o "$PHP_MONGODB_SSL" = "libressl" -o "$PHP_MONGODB_SSL" = "darwin"; then + AC_SUBST(MONGOC_ENABLE_SSL, 1) + AC_SUBST(MONGOC_ENABLE_CRYPTO, 1) + if test "$PHP_MONGODB_SSL" = "darwin"; then + AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_SECURE_TRANSPORT, 1) + AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO, 1) + elif test "$PHP_MONGODB_SSL" = "openssl"; then + AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 1) + AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_SECURE_TRANSPORT, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1) + AC_SUBST(MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO, 0) + elif test "$PHP_MONGODB_SSL" = "libressl"; then + AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 1) + AC_SUBST(MONGOC_ENABLE_SSL_SECURE_TRANSPORT, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1) + AC_SUBST(MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO, 0) + fi +else + AC_SUBST(MONGOC_ENABLE_SSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 0) + AC_SUBST(MONGOC_ENABLE_SSL_SECURE_TRANSPORT, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 0) + AC_SUBST(MONGOC_ENABLE_CRYPTO_COMMON_CRYPTO, 0) +fi + +if test "x$have_ASN1_STRING_get0_data" = "xyes"; then + AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 1) +else + AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 0) +fi + +PHP_ARG_ENABLE([mongodb-crypto-system-profile], + [whether to use system crypto profile], + [AC_HELP_STRING([--enable-mongodb-crypto-system-profile], + [MongoDB: Use system crypto profile (OpenSSL only) [default=no]])], + [no], + [no]) + +PHP_ARG_WITH([system-ciphers], + [deprecated option for whether to use system crypto profile], + AC_HELP_STRING([--enable-system-ciphers], + [MongoDB: whether to use system crypto profile (deprecated for --enable-mongodb-crypto-system-profile) [default=no]]), + [no], + [no]) + +dnl Also consider the deprecated --enable-system-ciphers option +if test "$PHP_MONGODB_CRYPTO_SYSTEM_PROFILE" = "yes" -o "$PHP_SYSTEM_CIPHERS" = "yes"; then + if test "$PHP_MONGODB_SSL" = "openssl"; then + AC_SUBST(MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE, 1) + else + AC_MSG_ERROR([System crypto profile is only available with OpenSSL]) + fi +else + AC_SUBST(MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE, 0) +fi diff --git a/scripts/build/autotools/m4/pkg.m4 b/scripts/build/autotools/m4/pkg.m4 new file mode 100644 index 000000000..f26f84c9a --- /dev/null +++ b/scripts/build/autotools/m4/pkg.m4 @@ -0,0 +1,199 @@ +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- +# serial 1 (pkg-config-0.24) +# +# Copyright © 2004 Scott James Remnant . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# PKG_PROG_PKG_CONFIG([MIN-VERSION]) +# ---------------------------------- +AC_DEFUN([PKG_PROG_PKG_CONFIG], +[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) +m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$]) +m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$]) +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility]) +AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path]) +AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path]) + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=m4_default([$1], [0.9.0]) + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + PKG_CONFIG="" + fi +fi[]dnl +])# PKG_PROG_PKG_CONFIG + +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# Check to see whether a particular set of modules exists. Similar +# to PKG_CHECK_MODULES(), but does not set variables or print errors. +# +# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +# only at the first occurence in configure.ac, so if the first place +# it's called might be skipped (such as if it is within an "if", you +# have to call PKG_CHECK_EXISTS manually +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_EXISTS], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test -n "$PKG_CONFIG" && \ + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then + m4_default([$2], [:]) +m4_ifvaln([$3], [else + $3])dnl +fi]) + +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) +# --------------------------------------------- +m4_define([_PKG_CONFIG], +[if test -n "$$1"; then + pkg_cv_[]$1="$$1" + elif test -n "$PKG_CONFIG"; then + PKG_CHECK_EXISTS([$3], + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes ], + [pkg_failed=yes]) + else + pkg_failed=untried +fi[]dnl +])# _PKG_CONFIG + +# _PKG_SHORT_ERRORS_SUPPORTED +# ----------------------------- +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi[]dnl +])# _PKG_SHORT_ERRORS_SUPPORTED + + +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# +# +# Note that if there is a possibility the first call to +# PKG_CHECK_MODULES might not happen, you should be sure to include an +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac +# +# +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_MODULES], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl + +pkg_failed=no +AC_MSG_CHECKING([for $1]) + +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) +_PKG_CONFIG([$1][_LIBS], [libs], [$2]) + +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS +and $1[]_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details.]) + +if test $pkg_failed = yes; then + AC_MSG_RESULT([no]) + _PKG_SHORT_ERRORS_SUPPORTED + if test $_pkg_short_errors_supported = yes; then + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1` + else + $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD + + m4_default([$4], [AC_MSG_ERROR( +[Package requirements ($2) were not met: + +$$1_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +_PKG_TEXT])[]dnl + ]) +elif test $pkg_failed = untried; then + AC_MSG_RESULT([no]) + m4_default([$4], [AC_MSG_FAILURE( +[The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +_PKG_TEXT + +To get pkg-config, see .])[]dnl + ]) +else + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS + AC_MSG_RESULT([yes]) + $3 +fi[]dnl +])# PKG_CHECK_MODULES + + +# PKG_INSTALLDIR(DIRECTORY) +# ------------------------- +# Substitutes the variable pkgconfigdir as the location where a module +# should install pkg-config .pc files. By default the directory is +# $libdir/pkgconfig, but the default can be changed by passing +# DIRECTORY. The user can override through the --with-pkgconfigdir +# parameter. +AC_DEFUN([PKG_INSTALLDIR], +[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])]) +m4_pushdef([pkg_description], + [pkg-config installation directory @<:@]pkg_default[@:>@]) +AC_ARG_WITH([pkgconfigdir], + [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],, + [with_pkgconfigdir=]pkg_default) +AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) +m4_popdef([pkg_default]) +m4_popdef([pkg_description]) +]) dnl PKG_INSTALLDIR + + +# PKG_NOARCH_INSTALLDIR(DIRECTORY) +# ------------------------- +# Substitutes the variable noarch_pkgconfigdir as the location where a +# module should install arch-independent pkg-config .pc files. By +# default the directory is $datadir/pkgconfig, but the default can be +# changed by passing DIRECTORY. The user can override through the +# --with-noarch-pkgconfigdir parameter. +AC_DEFUN([PKG_NOARCH_INSTALLDIR], +[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])]) +m4_pushdef([pkg_description], + [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@]) +AC_ARG_WITH([noarch-pkgconfigdir], + [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],, + [with_noarch_pkgconfigdir=]pkg_default) +AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir]) +m4_popdef([pkg_default]) +m4_popdef([pkg_description]) +]) dnl PKG_NOARCH_INSTALLDIR diff --git a/tests/connect/standalone-x509-extract_username-001.phpt b/tests/connect/standalone-x509-extract_username-001.phpt index d5502e7fc..25901fcab 100644 --- a/tests/connect/standalone-x509-extract_username-001.phpt +++ b/tests/connect/standalone-x509-extract_username-001.phpt @@ -2,6 +2,7 @@ Connect to MongoDB with SSL and X509 auth and username retrieved from cert --SKIPIF-- + --FILE-- + --FILE-- ')); + + if (preg_match($pattern, $info, $matches) !== 1) { + exit('skip Could not determine SSL library'); + } + + if (!in_array($matches[1], $libs)) { + exit('skip Needs SSL library ' . implode(', ', $libs) . ', but found ' . $matches[1]); + } +} + function CLEANUP($uri, $dbname = DATABASE_NAME, $collname = COLLECTION_NAME) { try { $manager = new MongoDB\Driver\Manager($uri);