@@ -1485,10 +1485,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1485
1485
1486
1486
/* parallel search? */
1487
1487
if (Z_TYPE_P (link ) == IS_ARRAY ) {
1488
- int i , * rcs ;
1489
- ldap_linkdata * * lds ;
1490
- zval * entry , object ;
1491
-
1492
1488
uint32_t num_links = zend_hash_num_elements (Z_ARRVAL_P (link ));
1493
1489
if (num_links == 0 ) {
1494
1490
zend_argument_must_not_be_empty_error (1 );
@@ -1514,7 +1510,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1514
1510
ret = 0 ;
1515
1511
goto cleanup ;
1516
1512
}
1517
- zend_hash_internal_pointer_reset (base_dn_ht );
1518
1513
} else {
1519
1514
if (zend_str_has_nul_byte (base_dn_str )) {
1520
1515
zend_argument_value_error (2 , "must not contain null bytes" );
@@ -1537,7 +1532,6 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1537
1532
ret = 0 ;
1538
1533
goto cleanup ;
1539
1534
}
1540
- zend_hash_internal_pointer_reset (filter_ht );
1541
1535
} else {
1542
1536
if (zend_str_has_nul_byte (filter_str )) {
1543
1537
zend_argument_value_error (3 , "must not contain null bytes" );
@@ -1547,73 +1541,87 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1547
1541
ldap_filter = zend_string_copy (filter_str );
1548
1542
}
1549
1543
1544
+ int * rcs ;
1545
+ ldap_linkdata * * lds ;
1550
1546
lds = safe_emalloc (num_links , sizeof (ldap_linkdata ), 0 );
1551
1547
rcs = safe_emalloc (num_links , sizeof (* rcs ), 0 );
1552
1548
1553
- zend_hash_internal_pointer_reset (Z_ARRVAL_P (link ));
1554
- for (i = 0 ; i < num_links ; i ++ ) {
1555
- entry = zend_hash_get_current_data (Z_ARRVAL_P (link ));
1556
-
1557
- if (Z_TYPE_P (entry ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (entry ), ldap_link_ce )) {
1558
- zend_argument_value_error (1 , "must only contain objects of type LDAP" );
1549
+ zend_ulong ldap_link_index = 0 ;
1550
+ zval * link_zv = NULL ;
1551
+ ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (link ), ldap_link_index , link_zv ) {
1552
+ if (Z_TYPE_P (link_zv ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (link_zv ), ldap_link_ce )) {
1553
+ zend_argument_value_error (1 , "must be a list of LDAP\\Connection" );
1559
1554
ret = 0 ;
1560
1555
goto cleanup_parallel ;
1561
1556
}
1562
1557
1563
- ld = Z_LDAP_LINK_P (entry );
1564
- if (!ld -> link ) {
1558
+ ldap_linkdata * current_ld = Z_LDAP_LINK_P (link_zv );
1559
+ if (!current_ld -> link ) {
1565
1560
zend_throw_error (NULL , "LDAP connection has already been closed" );
1566
1561
ret = 0 ;
1567
1562
goto cleanup_parallel ;
1568
1563
}
1569
1564
1570
1565
if (num_base_dns != 0 ) { /* base_dn an array? */
1571
- entry = zend_hash_get_current_data (base_dn_ht );
1572
- zend_hash_move_forward (base_dn_ht );
1573
- ldap_base_dn = zval_get_string (entry );
1574
- if (EG (exception )) {
1566
+ zval * base_dn_zv = zend_hash_index_find (base_dn_ht , ldap_link_index );
1567
+ ZEND_ASSERT (base_dn_zv );
1568
+ if (Z_TYPE_P (base_dn_zv ) != IS_STRING ) {
1569
+ zend_argument_type_error (2 , "must be a list of strings, %s given" , zend_zval_value_name (base_dn_zv ));
1570
+ ret = 0 ;
1571
+ goto cleanup_parallel ;
1572
+ }
1573
+ ldap_base_dn = zend_string_copy (Z_STR_P (base_dn_zv ));
1574
+ if (zend_str_has_nul_byte (ldap_base_dn )) {
1575
+ zend_argument_value_error (2 , "must not contain null bytes" );
1575
1576
ret = 0 ;
1576
1577
goto cleanup_parallel ;
1577
1578
}
1578
- // TODO check dn does not have any nul bytes
1579
1579
}
1580
1580
if (num_filters != 0 ) { /* filter an array? */
1581
- entry = zend_hash_get_current_data (filter_ht );
1582
- zend_hash_move_forward (filter_ht );
1583
- ldap_filter = zval_get_string (entry );
1584
- if (EG (exception )) {
1581
+ zval * filter_zv = zend_hash_index_find (filter_ht , ldap_link_index );
1582
+ ZEND_ASSERT (filter_zv );
1583
+ if (Z_TYPE_P (filter_zv ) != IS_STRING ) {
1584
+ zend_argument_type_error (3 , "must be a list of strings, %s given" , zend_zval_value_name (filter_zv ));
1585
+ ret = 0 ;
1586
+ goto cleanup_parallel ;
1587
+ }
1588
+ ldap_filter = zend_string_copy (Z_STR_P (filter_zv ));
1589
+ if (zend_str_has_nul_byte (ldap_filter )) {
1590
+ zend_argument_value_error (3 , "must not contain null bytes" );
1585
1591
ret = 0 ;
1586
1592
goto cleanup_parallel ;
1587
1593
}
1588
- // TODO check filter does not have any nul bytes
1589
1594
}
1590
1595
1591
1596
if (serverctrls ) {
1592
1597
/* We have to parse controls again for each link as they use it */
1593
1598
_php_ldap_controls_free (& lserverctrls );
1594
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 9 );
1599
+ lserverctrls = _php_ldap_controls_from_array (current_ld -> link , serverctrls , 9 );
1595
1600
if (lserverctrls == NULL ) {
1596
- rcs [i ] = -1 ;
1601
+ rcs [ldap_link_index ] = -1 ;
1602
+ // TODO Throw an exception/cleanup?
1597
1603
continue ;
1598
1604
}
1599
1605
}
1600
1606
1601
- php_set_opts (ld -> link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref );
1607
+ php_set_opts (current_ld -> link , ldap_sizelimit , ldap_timelimit , ldap_deref , & old_ldap_sizelimit , & old_ldap_timelimit , & old_ldap_deref );
1602
1608
1603
1609
/* Run the actual search */
1604
- ldap_search_ext (ld -> link , ZSTR_VAL (ldap_base_dn ), scope , ZSTR_VAL (ldap_filter ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & rcs [i ]);
1605
- lds [i ] = ld ;
1606
- zend_hash_move_forward (Z_ARRVAL_P (link ));
1607
- }
1610
+ ldap_search_ext (current_ld -> link , ZSTR_VAL (ldap_base_dn ), scope , ZSTR_VAL (ldap_filter ), ldap_attrs , ldap_attrsonly , lserverctrls , NULL , NULL , ldap_sizelimit , & rcs [ldap_link_index ]);
1611
+ lds [ldap_link_index ] = current_ld ;
1612
+
1613
+ // TODO Reset the options of the link?
1614
+ } ZEND_HASH_FOREACH_END ();
1608
1615
1609
1616
array_init (return_value );
1610
1617
1611
1618
/* Collect results from the searches */
1612
- for (i = 0 ; i < num_links ; i ++ ) {
1619
+ for (uint32_t i = 0 ; i < num_links ; i ++ ) {
1613
1620
if (rcs [i ] != -1 ) {
1614
1621
rcs [i ] = ldap_result (lds [i ]-> link , LDAP_RES_ANY , 1 /* LDAP_MSG_ALL */ , NULL , & ldap_res );
1615
1622
}
1616
1623
if (rcs [i ] != -1 ) {
1624
+ zval object ;
1617
1625
object_init_ex (& object , ldap_result_ce );
1618
1626
result = Z_LDAP_RESULT_P (& object );
1619
1627
result -> result = ldap_res ;
0 commit comments