]> granicus.if.org Git - php/commitdiff
Added support for controls to ldap_get_option
authorCôme Chilliet <mcmic@php.net>
Tue, 4 Jul 2017 15:08:57 +0000 (17:08 +0200)
committerCôme Chilliet <mcmic@php.net>
Wed, 5 Jul 2017 14:41:52 +0000 (16:41 +0200)
ext/ldap/ldap.c

index 8e0b908417dcf4fe9c228d101780c6cc87753927..8263e70cf1fcb38bd0f2ca2e9c7cc5902ed1bdfe 100644 (file)
@@ -2129,6 +2129,8 @@ PHP_FUNCTION(ldap_sort)
 PHP_FUNCTION(ldap_get_option)
 {
        zval *link, *retval;
+       zval tmp1;
+       int num_entries;
        ldap_linkdata *ld;
        zend_long option;
 
@@ -2273,9 +2275,37 @@ PHP_FUNCTION(ldap_get_option)
                        ZVAL_STRING(retval, val);
                        ldap_memfree(val);
                } break;
-/* options not implemented
        case LDAP_OPT_SERVER_CONTROLS:
        case LDAP_OPT_CLIENT_CONTROLS:
+               {
+                       LDAPControl **ctrls = NULL, **ctrlp;
+
+                       if (ldap_get_option(ld->link, option, &ctrls) || ctrls == NULL) {
+                               if (ctrls) {
+                                       ldap_memfree(ctrls);
+                               }
+                               RETURN_FALSE;
+                       }
+
+                       zval_ptr_dtor(retval);
+                       array_init(retval);
+                       num_entries = 0;
+                       ctrlp = ctrls;
+                       while (*ctrlp != NULL)
+                       {
+                               array_init(&tmp1);
+                               add_assoc_string(&tmp1, "oid", (*ctrlp)->ldctl_oid);
+                               add_assoc_bool(&tmp1, "iscritical", ((*ctrlp)->ldctl_iscritical != 0));
+                               if ((*ctrlp)->ldctl_value.bv_len) {
+                                       add_assoc_stringl(&tmp1, "value", (*ctrlp)->ldctl_value.bv_val, (*ctrlp)->ldctl_value.bv_len);
+                               }
+                               zend_hash_index_update(Z_ARRVAL_P(retval), num_entries, &tmp1);
+                               num_entries++;
+                               ctrlp++;
+                       }
+                       ldap_controls_free(ctrls);
+               } break;
+/* options not implemented
        case LDAP_OPT_API_INFO:
        case LDAP_OPT_API_FEATURE_INFO:
 */