Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
}
control_value.bv_val = ZSTR_VAL(tmpstring);
control_value.bv_len = ZSTR_LEN(tmpstring);
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_PAGEDRESULTS) == 0) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_PAGEDRESULTS)) {
zval* tmp;
int pagesize = 1;
struct berval cookie = { 0L, NULL };
Expand All @@ -442,7 +442,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
if (rc != LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to create paged result control value: %s (%d)", ldap_err2string(rc), rc);
}
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_ASSERT) == 0) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_ASSERT)) {
zval* tmp;
zend_string* assert;
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "filter", sizeof("filter") - 1)) == NULL) {
Expand All @@ -466,7 +466,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
}
zend_string_release(assert);
}
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_VALUESRETURNFILTER) == 0) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_VALUESRETURNFILTER)) {
zval* tmp;
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "filter", sizeof("filter") - 1)) == NULL) {
rc = -1;
Expand All @@ -490,7 +490,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
}
}
}
} else if ((strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_PRE_READ) == 0) || (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_POST_READ) == 0)) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_PRE_READ) || zend_string_equals_literal(control_oid, LDAP_CONTROL_POST_READ)) {
zval* tmp;
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(val), "attrs", sizeof("attrs") - 1)) == NULL) {
rc = -1;
Expand Down Expand Up @@ -542,7 +542,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
}
}
}
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_SORTREQUEST) == 0) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_SORTREQUEST)) {
int num_keys, i;
zval *sortkey, *tmp;

Expand Down Expand Up @@ -599,7 +599,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
if (rc != LDAP_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to create sort control value: %s (%d)", ldap_err2string(rc), rc);
}
} else if (strcmp(ZSTR_VAL(control_oid), LDAP_CONTROL_VLVREQUEST) == 0) {
} else if (zend_string_equals_literal(control_oid, LDAP_CONTROL_VLVREQUEST)) {
zval* tmp;
LDAPVLVInfo vlvInfo;
struct berval attrValue;
Expand Down Expand Up @@ -745,18 +745,17 @@ static void _php_ldap_controls_to_array(LDAP *ld, LDAPControl** ctrls, zval* arr
ldap_controls_free(ctrls);
}

static LDAPControl** _php_ldap_controls_from_array(LDAP *ld, zval* array, uint32_t arg_num)
static LDAPControl** php_ldap_controls_from_array(LDAP *ld, const HashTable *controls, uint32_t arg_num)
{
int ncontrols;
LDAPControl** ctrlp, **ctrls = NULL;
zval* ctrlarray;
int error = 0;

ncontrols = zend_hash_num_elements(Z_ARRVAL_P(array));
ctrls = safe_emalloc((1 + ncontrols), sizeof(*ctrls), 0);
uint32_t num_controls = zend_hash_num_elements(controls);
ctrls = safe_emalloc((1 + num_controls), sizeof(*ctrls), 0);
*ctrls = NULL;
ctrlp = ctrls;
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) {
ZEND_HASH_FOREACH_VAL(controls, ctrlarray) {
if (Z_TYPE_P(ctrlarray) != IS_ARRAY) {
zend_argument_type_error(arg_num, "must contain only arrays, where each array is a control");
error = 1;
Expand Down Expand Up @@ -1145,25 +1144,25 @@ PHP_FUNCTION(ldap_bind)
/* {{{ Bind to LDAP directory */
PHP_FUNCTION(ldap_bind_ext)
{
zval *serverctrls = NULL;
zval *link;
char *ldap_bind_dn = NULL, *ldap_bind_pw = NULL;
size_t ldap_bind_dnlen, ldap_bind_pwlen;
HashTable *server_controls_ht = NULL;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL;
ldap_resultdata *result;
LDAPMessage *ldap_res;
int rc;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|p!p!a!", &link, ldap_link_ce, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &serverctrls) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|p!p!h!", &link, ldap_link_ce, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &server_controls_ht) != SUCCESS) {
RETURN_THROWS();
}

ld = Z_LDAP_LINK_P(link);
VERIFY_LDAP_LINK_CONNECTED(ld);

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 4);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 4);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down Expand Up @@ -1402,12 +1401,13 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in
/* {{{ php_ldap_do_search */
static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
{
zval *link, *attrs = NULL, *serverctrls = NULL;
zval *link, *attrs = NULL;
HashTable *base_dn_ht = NULL;
zend_string *base_dn_str = NULL;
HashTable *filter_ht = NULL;
zend_string *filter_str = NULL;
zend_long attrsonly, sizelimit, timelimit, deref;
HashTable *server_controls_ht = NULL;
char **ldap_attrs = NULL;
ldap_linkdata *ld = NULL;
ldap_resultdata *result;
Expand All @@ -1427,7 +1427,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
Z_PARAM_LONG(sizelimit)
Z_PARAM_LONG(timelimit)
Z_PARAM_LONG(deref)
Z_PARAM_ARRAY_EX(serverctrls, 1, 1)
Z_PARAM_ARRAY_HT_EX(server_controls_ht, 1, 1)
ZEND_PARSE_PARAMETERS_END();

/* Reverse -> fall through */
Expand Down Expand Up @@ -1600,10 +1600,10 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
}
}

if (serverctrls) {
if (server_controls_ht) {
/* We have to parse controls again for each link as they use it */
_php_ldap_controls_free(&lserverctrls);
lserverctrls = _php_ldap_controls_from_array(current_ld->link, serverctrls, 9);
lserverctrls = php_ldap_controls_from_array(current_ld->link, server_controls_ht, 9);
if (lserverctrls == NULL) {
rcs[ldap_link_index] = -1;
// TODO Throw an exception/cleanup?
Expand Down Expand Up @@ -1661,8 +1661,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
goto cleanup;
}

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 9);
if (lserverctrls == NULL) {
ret = 0;
goto cleanup;
Expand Down Expand Up @@ -2193,19 +2193,19 @@ PHP_FUNCTION(ldap_dn2ufn)
/* {{{ php_ldap_do_modify */
static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
{
zval *serverctrls = NULL;
zval *link;
ldap_linkdata *ld;
char *dn;
HashTable *attributes_ht;
HashTable *server_controls_ht = NULL;
LDAPMod **ldap_mods;
LDAPControl **lserverctrls = NULL;
ldap_resultdata *result;
LDAPMessage *ldap_res;
size_t dn_len;
int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oph/|a!", &link, ldap_link_ce, &dn, &dn_len, &attributes_ht, &serverctrls) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oph/|h!", &link, ldap_link_ce, &dn, &dn_len, &attributes_ht, &server_controls_ht) != SUCCESS) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2305,8 +2305,8 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
} ZEND_HASH_FOREACH_END();
ldap_mods[num_attribs] = NULL;

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 4);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 4);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down Expand Up @@ -2446,8 +2446,8 @@ PHP_FUNCTION(ldap_mod_del_ext)
/* {{{ php_ldap_do_delete */
static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
{
zval *serverctrls = NULL;
zval *link;
HashTable *server_controls_ht = NULL;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL;
ldap_resultdata *result;
Expand All @@ -2456,15 +2456,15 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
int rc, msgid;
size_t dn_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op|a!", &link, ldap_link_ce, &dn, &dn_len, &serverctrls) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op|h!", &link, ldap_link_ce, &dn, &dn_len, &server_controls_ht) != SUCCESS) {
RETURN_THROWS();
}

ld = Z_LDAP_LINK_P(link);
VERIFY_LDAP_LINK_CONNECTED(ld);

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 3);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 3);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down Expand Up @@ -2522,11 +2522,11 @@ PHP_FUNCTION(ldap_delete_ext)
/* {{{ Perform multiple modifications as part of one operation */
PHP_FUNCTION(ldap_modify_batch)
{
zval *server_controls_zv = NULL;
zval *link;
char *dn;
size_t dn_len;
HashTable *modifications;
HashTable *server_controls_ht = NULL;
LDAPControl **lserverctrls = NULL;

/*
Expand All @@ -2553,7 +2553,7 @@ PHP_FUNCTION(ldap_modify_batch)
];
*/

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oph/|a!", &link, ldap_link_ce, &dn, &dn_len, &modifications, &server_controls_zv) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oph/|h!", &link, ldap_link_ce, &dn, &dn_len, &modifications, &server_controls_ht) != SUCCESS) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2669,8 +2669,8 @@ PHP_FUNCTION(ldap_modify_batch)
/* validation of modifications array was successful */

/* Check that the LDAP server controls array is valid */
if (server_controls_zv) {
lserverctrls = _php_ldap_controls_from_array(ld->link, server_controls_zv, 4);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 4);
if (lserverctrls == NULL) {
_php_ldap_controls_free(&lserverctrls);
RETURN_FALSE;
Expand Down Expand Up @@ -2846,30 +2846,30 @@ PHP_FUNCTION(ldap_error)
/* {{{ Determine if an entry has a specific value for one of its attributes */
PHP_FUNCTION(ldap_compare)
{
zval *serverctrls = NULL;
zval *link;
char *dn, *attr;
size_t dn_len, attr_len;
HashTable *server_controls_ht = NULL;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL;
int ldap_errno;
struct berval lvalue;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opps|a!",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opps|h!",
&link, ldap_link_ce,
&dn, &dn_len,
&attr, &attr_len,
&lvalue.bv_val, &lvalue.bv_len,
&serverctrls
&server_controls_ht
) != SUCCESS) {
RETURN_THROWS();
}

ld = Z_LDAP_LINK_P(link);
VERIFY_LDAP_LINK_CONNECTED(ld);

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 5);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 5);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down Expand Up @@ -3251,7 +3251,7 @@ PHP_FUNCTION(ldap_set_option)
RETURN_THROWS();
}

ctrls = _php_ldap_controls_from_array(ldap, newval, 3);
ctrls = php_ldap_controls_from_array(ldap, Z_ARRVAL_P(newval), 3);

if (ctrls == NULL) {
RETURN_FALSE;
Expand Down Expand Up @@ -3526,7 +3526,6 @@ PHP_FUNCTION(ldap_parse_reference)
/* {{{ php_ldap_do_rename */
static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
{
zval *serverctrls = NULL;
zval *link;
ldap_linkdata *ld;
LDAPControl **lserverctrls = NULL;
Expand All @@ -3536,8 +3535,9 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
char *dn, *newrdn, *newparent;
size_t dn_len, newrdn_len, newparent_len;
bool deleteoldrdn;
HashTable *server_controls_ht = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opppb|a!", &link, ldap_link_ce, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opppb|h!", &link, ldap_link_ce, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &server_controls_ht) != SUCCESS) {
RETURN_THROWS();
}

Expand All @@ -3549,8 +3549,8 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
}

#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 6);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 6);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down Expand Up @@ -3857,10 +3857,10 @@ PHP_FUNCTION(ldap_8859_to_t61)
/* {{{ Extended operations, Pierangelo Masarati */
#ifdef HAVE_LDAP_EXTENDED_OPERATION_S
static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
zval *serverctrls = NULL;
zval *link, *retdata = NULL, *retoid = NULL;
char *lretoid = NULL;
zend_string *reqoid, *reqdata = NULL;
HashTable *server_controls_ht = NULL;
struct berval lreqdata, *lretdata = NULL;
ldap_linkdata *ld;
ldap_resultdata *result;
Expand All @@ -3875,7 +3875,7 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
}
}

if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|S!a!zz", &link, ldap_link_ce, &reqoid, &reqdata, &serverctrls, &retdata, &retoid) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|S!h!zz", &link, ldap_link_ce, &reqoid, &reqdata, &server_controls_ht, &retdata, &retoid) != SUCCESS) {
RETURN_THROWS();
}

Expand All @@ -3889,8 +3889,8 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
lreqdata.bv_len = 0;
}

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 4);
if (server_controls_ht) {
lserverctrls = php_ldap_controls_from_array(ld->link, server_controls_ht, 4);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
Expand Down