Skip to content

Commit 73f9709

Browse files
committed
change from feedback
1 parent cb8e659 commit 73f9709

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

ext/ldap/ldap.c

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -984,62 +984,59 @@ PHP_FUNCTION(ldap_connect)
984984
RETURN_FALSE;
985985
}
986986

987-
object_init_ex(return_value, ldap_link_ce);
988-
ld = Z_LDAP_LINK_P(return_value);
989-
990-
{
991-
int rc = LDAP_SUCCESS;
992-
char *url = host;
993-
if (url && !ldap_is_ldap_url(url)) {
994-
size_t urllen = hostlen + sizeof( "ldap://:65535" );
995987

996-
if (port <= 0 || port > 65535) {
997-
zval_ptr_dtor(return_value);
998-
zend_argument_value_error(2, "must be between 1 and 65535");
999-
RETURN_THROWS();
1000-
}
988+
int rc = LDAP_SUCCESS;
989+
char *url = host;
990+
if (url && !ldap_is_ldap_url(url)) {
991+
size_t urllen = hostlen + sizeof( "ldap://:65535" );
1001992

1002-
url = emalloc(urllen);
1003-
snprintf( url, urllen, "ldap://%s:" ZEND_LONG_FMT, host, port );
993+
if (port <= 0 || port > 65535) {
994+
zend_argument_value_error(2, "must be between 1 and 65535");
995+
RETURN_THROWS();
1004996
}
1005997

998+
url = emalloc(urllen);
999+
snprintf( url, urllen, "ldap://%s:" ZEND_LONG_FMT, host, port );
1000+
}
1001+
10061002
#ifdef LDAP_OPT_X_TLS_NEWCTX
1007-
if (LDAPG(tls_newctx) && url && !strncmp(url, "ldaps:", 6)) {
1008-
int val = 0;
1003+
if (LDAPG(tls_newctx) && url && !strncmp(url, "ldaps:", 6)) {
1004+
int val = 0;
10091005

1010-
/* ensure all pending TLS options are applied in a new context */
1011-
if (ldap_set_option(NULL, LDAP_OPT_X_TLS_NEWCTX, &val) != LDAP_OPT_SUCCESS) {
1012-
zval_ptr_dtor(return_value);
1013-
php_error_docref(NULL, E_WARNING, "Could not create new security context");
1014-
RETURN_FALSE;
1015-
}
1016-
LDAPG(tls_newctx) = false;
1006+
/* ensure all pending TLS options are applied in a new context */
1007+
if (ldap_set_option(NULL, LDAP_OPT_X_TLS_NEWCTX, &val) != LDAP_OPT_SUCCESS) {
1008+
zval_ptr_dtor(return_value);
1009+
php_error_docref(NULL, E_WARNING, "Could not create new security context");
1010+
RETURN_FALSE;
10171011
}
1012+
LDAPG(tls_newctx) = false;
1013+
}
10181014
#endif
1015+
object_init_ex(return_value, ldap_link_ce);
1016+
ld = Z_LDAP_LINK_P(return_value);
10191017

10201018
#ifdef LDAP_API_FEATURE_X_OPENLDAP
1021-
/* ldap_init() is deprecated, use ldap_initialize() instead.
1022-
*/
1023-
rc = ldap_initialize(&ldap, url);
1019+
/* ldap_init() is deprecated, use ldap_initialize() instead.
1020+
*/
1021+
rc = ldap_initialize(&ldap, url);
10241022
#else /* ! LDAP_API_FEATURE_X_OPENLDAP */
1025-
/* ldap_init does not support URLs.
1026-
* We must try the original host and port information.
1027-
*/
1028-
ldap = ldap_init(host, port);
1029-
if (ldap == NULL) {
1030-
zval_ptr_dtor(return_value);
1031-
php_error_docref(NULL, E_WARNING, "Could not create session handle");
1032-
RETURN_FALSE;
1033-
}
1023+
/* ldap_init does not support URLs.
1024+
* We must try the original host and port information.
1025+
*/
1026+
ldap = ldap_init(host, port);
1027+
if (ldap == NULL) {
1028+
zval_ptr_dtor(return_value);
1029+
php_error_docref(NULL, E_WARNING, "Could not create session handle");
1030+
RETURN_FALSE;
1031+
}
10341032
#endif /* ! LDAP_API_FEATURE_X_OPENLDAP */
1035-
if (url != host) {
1036-
efree(url);
1037-
}
1038-
if (rc != LDAP_SUCCESS) {
1039-
zval_ptr_dtor(return_value);
1040-
php_error_docref(NULL, E_WARNING, "Could not create session handle: %s", ldap_err2string(rc));
1041-
RETURN_FALSE;
1042-
}
1033+
if (url != host) {
1034+
efree(url);
1035+
}
1036+
if (rc != LDAP_SUCCESS) {
1037+
zval_ptr_dtor(return_value);
1038+
php_error_docref(NULL, E_WARNING, "Could not create session handle: %s", ldap_err2string(rc));
1039+
RETURN_FALSE;
10431040
}
10441041

10451042
if (ldap == NULL) {

0 commit comments

Comments
 (0)