cvs: php4 /ext/ldap ldap.c
| From: | Jani Taskinen | Date: | Tue, 25 Jul 2000 15:34:28 +0000 |
| Subject: | cvs: php4 /ext/ldap ldap.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-915@lists.php.net to get a copy of this message | ||
sniper Tue Jul 25 08:34:28 2000 EDT
Modified files:
/php4/ext/ldap ldap.c
Log:
@- Fixed a bug in ldap_get_entries() and ldap_get_attributes. (Jani)
Fixes bugs #5433 and #5603.
Index: php4/ext/ldap/ldap.c
diff -u php4/ext/ldap/ldap.c:1.49 php4/ext/ldap/ldap.c:1.50
--- php4/ext/ldap/ldap.c:1.49 Sun Jul 23 14:32:02 2000
+++ php4/ext/ldap/ldap.c Tue Jul 25 08:34:28 2000
@@ -16,12 +16,13 @@
| Eric Warnke <ericw@albany.edu> |
| Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Gerrit Thomson <334647@swin.edu.au> |
+ | Jani Taskinen <sniper@iki.fi> |
| PHP 4.0 updates: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
-/* $Id: ldap.c,v 1.49 2000/07/23 21:32:02 sniper Exp $ */
+/* $Id: ldap.c,v 1.50 2000/07/25 15:34:28 sniper Exp $ */
#define IS_EXT_MODULE
#include "php.h"
@@ -184,7 +185,7 @@
php_info_print_table_start();
php_info_print_table_row(2, "LDAP Support", "enabled" );
- php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 1.49 2000/07/23 21:32:02
sniper Exp $" );
+ php_info_print_table_row(2, "RCS Version", "$Id: ldap.c,v 1.50 2000/07/25 15:34:28
sniper Exp $" );
php_info_print_table_row(2, "Total Links", maxl );
#if HAVE_NSLDAP
@@ -718,7 +719,6 @@
pval *tmp1, *tmp2;
LDAP *ldap;
int num_entries, num_attrib, num_values, i;
- int attr_count, entry_count;
BerElement *ber;
char *attribute;
size_t attr_len;
@@ -736,32 +736,22 @@
if (ldap_result == NULL) RETURN_FALSE;
num_entries = ldap_count_entries(ldap, ldap_result);
+ if (num_entries == 0) RETURN_FALSE;
array_init(return_value);
- add_assoc_long(return_value, "count", num_entries);
-
- if (num_entries == 0) return;
+ num_entries = 0;
ldap_result_entry = ldap_first_entry(ldap, ldap_result);
if (ldap_result_entry == NULL) RETURN_FALSE;
-
- entry_count = 0;
while(ldap_result_entry != NULL) {
- num_attrib = 0;
- attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
- if (attribute == NULL) RETURN_FALSE;
- while (attribute != NULL) {
- num_attrib++;
- attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
- }
-
MAKE_STD_ZVAL(tmp1);
array_init(tmp1);
- attr_count = 0;
+ num_attrib = 0;
attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
+
while (attribute != NULL) {
ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute);
num_values = ldap_count_values(ldap_value);
@@ -769,16 +759,16 @@
MAKE_STD_ZVAL(tmp2);
array_init(tmp2);
add_assoc_long(tmp2, "count", num_values);
- for(i=0; i<num_values; i++) {
+ for(i=0; i < num_values; i++) {
add_index_string(tmp2, i, ldap_value[i], 1);
}
ldap_value_free(ldap_value);
attr_len = strlen(attribute);
zend_hash_update(tmp1->value.ht, php_strtolower(attribute, attr_len), attr_len+1, (void *)
&tmp2, sizeof(pval *), NULL);
- add_index_string(tmp1, attr_count, attribute, 1);
+ add_index_string(tmp1, num_attrib, attribute, 1);
- attr_count++;
+ num_attrib++;
attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
}
@@ -786,13 +776,14 @@
dn = ldap_get_dn(ldap, ldap_result_entry);
add_assoc_string(tmp1, "dn", dn, 1);
- zend_hash_index_update(return_value->value.ht, entry_count, (void *) &tmp1, sizeof(pval
*), NULL);
+ zend_hash_index_update(return_value->value.ht, num_entries, (void *) &tmp1, sizeof(pval
*), NULL);
- entry_count++;
+ num_entries++;
ldap_result_entry = ldap_next_entry(ldap, ldap_result_entry);
}
add_assoc_long(return_value, "count", num_entries);
+
}
/* }}} */
@@ -878,7 +869,7 @@
LDAPMessage *ldap_result_entry;
char *attribute;
char **ldap_value;
- int i, count, num_values, num_attrib;
+ int i, num_values, num_attrib;
BerElement *ber;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &link, &result_entry) == FAILURE) {
@@ -891,17 +882,9 @@
ldap_result_entry = _get_ldap_result_entry(result_entry);
if (ldap_result_entry == NULL) RETURN_FALSE;
+ array_init(return_value);
num_attrib = 0;
- attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
- if (attribute == NULL) RETURN_FALSE;
- while (attribute != NULL) {
- num_attrib++;
- attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
- }
- array_init(return_value);
-
- count=0;
attribute = ldap_first_attribute(ldap, ldap_result_entry, &ber);
while (attribute != NULL) {
ldap_value = ldap_get_values(ldap, ldap_result_entry, attribute);
@@ -916,9 +899,9 @@
ldap_value_free(ldap_value);
zend_hash_update(return_value->value.ht, attribute, strlen(attribute)+1, (void *) &tmp,
sizeof(pval *), NULL);
- add_index_string(return_value, count, attribute, 1);
+ add_index_string(return_value, num_attrib, attribute, 1);
- count++;
+ num_attrib++;
attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
}