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