Skip to content

Commit f0421fa

Browse files
authored
PHPC-2103: Report loaded crypt_shared version in phpinfo() (#1351)
* Match error message variations between libmongoc 1.23+ and older This typo was corrected in mongodb/mongo-c-driver@1d7229f and will appear in the 1.23.0 release. * PHPC-2103: Report loaded crypt_shared version in phpinfo() * PHPC-2132: Fix pattern for matching phpinfo() values
1 parent 9df0785 commit f0421fa

File tree

8 files changed

+66
-6
lines changed

8 files changed

+66
-6
lines changed

php_phongo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ PHP_MINFO_FUNCTION(mongodb) /* {{{ */
459459
#else /* MONGOCRYPT_ENABLE_CRYPTO */
460460
php_info_print_table_row(2, "libmongocrypt crypto", "disabled");
461461
#endif
462+
463+
{
464+
const char* crypt_shared_version = php_phongo_crypt_shared_version();
465+
466+
if (crypt_shared_version) {
467+
php_info_print_table_row(2, "crypt_shared library version", crypt_shared_version);
468+
} else {
469+
php_info_print_table_row(2, "crypt_shared library version", "unknown");
470+
}
471+
}
472+
462473
#else /* MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION */
463474
php_info_print_table_row(2, "libmongocrypt", "disabled");
464475
#endif

src/LIBMONGOC_VERSION_CURRENT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.22.1
1+
1.11.1-20220829+git623d659f00

src/libmongoc

Submodule libmongoc updated 235 files

src/phongo_client.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,47 @@ typedef struct {
5151
bool is_persistent;
5252
} php_phongo_pclient_t;
5353

54+
static const mongoc_client_t* get_first_pclient_client(HashTable* ht)
55+
{
56+
if (ht) {
57+
php_phongo_pclient_t* pclient = NULL;
58+
59+
zend_hash_internal_pointer_reset(ht);
60+
pclient = zend_hash_get_current_data_ptr(ht);
61+
62+
if (pclient) {
63+
return pclient->client;
64+
}
65+
}
66+
67+
return NULL;
68+
}
69+
70+
/* Returns the version of the crypt_shared library, or NULL if it's unavailable.
71+
* Querying the version requires a mongoc_client_t pointer. Since the shared
72+
* library can only be loaded once, any client will return the same result so we
73+
* consult the first persistent or request-scoped client we can find.
74+
*
75+
* Note: this may incorrectly return NULL if crypt_shared was loaded through a
76+
* mongoc_client_t since destroyed (e.g. single requested-scoped client);
77+
* however, that's the best can do with libmongoc's API. */
78+
const char* php_phongo_crypt_shared_version()
79+
{
80+
const mongoc_client_t* client = NULL;
81+
82+
client = get_first_pclient_client(&MONGODB_G(persistent_clients));
83+
84+
if (!client) {
85+
client = get_first_pclient_client(MONGODB_G(request_clients));
86+
}
87+
88+
if (client) {
89+
return mongoc_client_get_crypt_shared_version(client);
90+
}
91+
92+
return NULL;
93+
}
94+
5495
static mongoc_uri_t* php_phongo_make_uri(const char* uri_string)
5596
{
5697
mongoc_uri_t* uri;

src/phongo_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include "phongo_classes.h"
2323

24+
const char* php_phongo_crypt_shared_version();
25+
2426
void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string, zval* options, zval* driverOptions);
2527

2628
void php_phongo_client_reset_once(php_phongo_manager_t* manager, int pid);

tests/manager/manager-ctor-auto_encryption-002.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ $autoEncryptionOptions = [
1717

1818
create_test_manager(null, [], ['autoEncryption' => $autoEncryptionOptions]);
1919

20+
var_dump(get_module_info('crypt_shared library version'));
21+
2022
?>
2123
===DONE===
2224
<?php exit(0); ?>
23-
--EXPECT--
25+
--EXPECTF--
26+
string(%d) "mongo_crypt%a"
2427
===DONE===

tests/manager/manager-ctor-auto_encryption-error-004.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ foreach ($tests as $autoEncryptionOptions) {
2525
}, MongoDB\Driver\Exception\EncryptionException::class), "\n\n";
2626
}
2727

28+
var_dump(get_module_info('crypt_shared library version'));
29+
2830
?>
2931
===DONE===
3032
<?php exit(0); ?>
31-
--EXPECT--
33+
--EXPECTF--
3234
OK: Got MongoDB\Driver\Exception\EncryptionException
3335
A crypt_shared override path was specified [/not/found], but we failed to open a dynamic library at that location
3436

3537
OK: Got MongoDB\Driver\Exception\EncryptionException
36-
Option 'cryptSharedLibRequired' is 'true', but failed to load the crypt_shared runtime libary
38+
Option 'cryptSharedLibRequired' is 'true', but failed to load the crypt_shared runtime lib%r(r?)%rary
3739

40+
string(7) "unknown"
3841
===DONE===

tests/utils/tools.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function get_module_info($row)
8383
phpinfo(INFO_MODULES);
8484
$info = ob_get_clean();
8585

86-
$pattern = sprintf('/^%s([\w ]+)$/m', preg_quote($row . ' => '));
86+
$pattern = sprintf('/^%s(.*)$/m', preg_quote($row . ' => '));
8787

8888
if (preg_match($pattern, $info, $matches) !== 1) {
8989
return null;

0 commit comments

Comments
 (0)