Skip to content

Commit 15a3eca

Browse files
author
Côme Chilliet
committed
Change $controls parameter to default to null in ext/ldap
It appeared that not passing $controls and passing [] caused different behaviors, when not passing it the controls set through ldap_set_option would be used, when passing [] they would not. So, this parameter is now nullable and defaults to null to have a consistent behavior.
1 parent b270081 commit 15a3eca

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

ext/ldap/ldap.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ PHP_FUNCTION(ldap_bind_ext)
11751175
LDAPMessage *ldap_res;
11761176
int rc;
11771177

1178-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!a", &link, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &serverctrls) != SUCCESS) {
1178+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|s!s!a!", &link, &ldap_bind_dn, &ldap_bind_dnlen, &ldap_bind_pw, &ldap_bind_pwlen, &serverctrls) != SUCCESS) {
11791179
RETURN_THROWS();
11801180
}
11811181

@@ -1446,7 +1446,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14461446
Z_PARAM_LONG(sizelimit)
14471447
Z_PARAM_LONG(timelimit)
14481448
Z_PARAM_LONG(deref)
1449-
Z_PARAM_ARRAY_EX(serverctrls, 0, 1)
1449+
Z_PARAM_ARRAY_EX(serverctrls, 1, 1)
14501450
ZEND_PARSE_PARAMETERS_END();
14511451

14521452
/* Reverse -> fall through */
@@ -1557,7 +1557,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
15571557
}
15581558
}
15591559

1560-
if (argcount > 8) {
1560+
if (serverctrls) {
15611561
/* We have to parse controls again for each link as they use it */
15621562
_php_ldap_controls_free(&lserverctrls);
15631563
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9);
@@ -1610,7 +1610,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16101610
}
16111611
ldap_filter = zend_string_copy(filter_str);
16121612

1613-
if (argcount > 8) {
1613+
if (serverctrls) {
16141614
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 9);
16151615
if (lserverctrls == NULL) {
16161616
ret = 0;
@@ -2183,7 +2183,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
21832183
zend_ulong index;
21842184
int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
21852185

2186-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a", &link, &dn, &dn_len, &entry, &serverctrls) != SUCCESS) {
2186+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a!", &link, &dn, &dn_len, &entry, &serverctrls) != SUCCESS) {
21872187
RETURN_THROWS();
21882188
}
21892189

@@ -2414,7 +2414,7 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
24142414
int rc, msgid;
24152415
size_t dn_len;
24162416

2417-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|a", &link, &dn, &dn_len, &serverctrls) != SUCCESS) {
2417+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|a!", &link, &dn, &dn_len, &serverctrls) != SUCCESS) {
24182418
RETURN_THROWS();
24192419
}
24202420

@@ -2557,7 +2557,7 @@ PHP_FUNCTION(ldap_modify_batch)
25572557
);
25582558
*/
25592559

2560-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a", &link, &dn, &dn_len, &mods, &serverctrls) != SUCCESS) {
2560+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsa/|a!", &link, &dn, &dn_len, &mods, &serverctrls) != SUCCESS) {
25612561
RETURN_THROWS();
25622562
}
25632563

@@ -2897,7 +2897,7 @@ PHP_FUNCTION(ldap_compare)
28972897
int errno;
28982898
struct berval lvalue;
28992899

2900-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss|a", &link, &dn, &dn_len, &attr, &attr_len, &value, &value_len, &serverctrls) != SUCCESS) {
2900+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsss|a!", &link, &dn, &dn_len, &attr, &attr_len, &value, &value_len, &serverctrls) != SUCCESS) {
29012901
RETURN_THROWS();
29022902
}
29032903

@@ -3565,7 +3565,7 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
35653565
size_t dn_len, newrdn_len, newparent_len;
35663566
zend_bool deleteoldrdn;
35673567

3568-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb|a", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls) != SUCCESS) {
3568+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsssb|a!", &link, &dn, &dn_len, &newrdn, &newrdn_len, &newparent, &newparent_len, &deleteoldrdn, &serverctrls) != SUCCESS) {
35693569
RETURN_THROWS();
35703570
}
35713571

ext/ldap/ldap.stub.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function ldap_bind($ldap, ?string $dn = null, ?string $password = null): bool {}
2626
* @param resource $ldap
2727
* @return resource|false
2828
*/
29-
function ldap_bind_ext($ldap, ?string $dn = null, ?string $password = null, array $controls = []) {}
29+
function ldap_bind_ext($ldap, ?string $dn = null, ?string $password = null, ?array $controls = null) {}
3030

3131
#ifdef HAVE_LDAP_SASL
3232
/** @param resource $ldap */
@@ -37,19 +37,19 @@ function ldap_sasl_bind($ldap, ?string $dn = null, ?string $password = null, ?st
3737
* @param resource|array $ldap
3838
* @return resource|false
3939
*/
40-
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
40+
function ldap_read($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {}
4141

4242
/**
4343
* @param resource|array $ldap
4444
* @return resource|false
4545
*/
46-
function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
46+
function ldap_list($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {}
4747

4848
/**
4949
* @param resource|array $ldap
5050
* @return resource|false
5151
*/
52-
function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $controls = []) {}
52+
function ldap_search($ldap, array|string $base, array|string $filter, array $attributes = [], int $attributes_only = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, ?array $controls = null) {}
5353

5454
/** @param resource $ldap */
5555
function ldap_free_result($ldap): bool {}
@@ -123,58 +123,58 @@ function ldap_explode_dn(string $dn, int $with_attrib): array|false {}
123123
function ldap_dn2ufn(string $dn): string|false {}
124124

125125
/** @param resource $ldap */
126-
function ldap_add($ldap, string $dn, array $entry, array $controls = []): bool {}
126+
function ldap_add($ldap, string $dn, array $entry, ?array $controls = null): bool {}
127127

128128
/**
129129
* @param resource $ldap
130130
* @return resource|false
131131
*/
132-
function ldap_add_ext($ldap, string $dn, array $entry, array $controls = []) {}
132+
function ldap_add_ext($ldap, string $dn, array $entry, ?array $controls = null) {}
133133

134134
/** @param resource $ldap */
135-
function ldap_delete($ldap, string $dn, array $controls = []): bool {}
135+
function ldap_delete($ldap, string $dn, ?array $controls = null): bool {}
136136

137137
/**
138138
* @param resource $ldap
139139
* @return resource|false
140140
*/
141-
function ldap_delete_ext($ldap, string $dn, array $controls = []) {}
141+
function ldap_delete_ext($ldap, string $dn, ?array $controls = null) {}
142142

143143
/** @param resource $ldap */
144-
function ldap_modify_batch($ldap, string $dn, array $modifications_info, array $controls = []): bool {}
144+
function ldap_modify_batch($ldap, string $dn, array $modifications_info, ?array $controls = null): bool {}
145145

146146
/** @param resource $ldap */
147-
function ldap_mod_add($ldap, string $dn, array $entry, array $controls = []): bool {}
147+
function ldap_mod_add($ldap, string $dn, array $entry, ?array $controls = null): bool {}
148148

149149
/**
150150
* @param resource $ldap
151151
* @return resource|false
152152
*/
153-
function ldap_mod_add_ext($ldap, string $dn, array $entry, array $controls = []) {}
153+
function ldap_mod_add_ext($ldap, string $dn, array $entry, ?array $controls = null) {}
154154

155155
/** @param resource $ldap */
156-
function ldap_mod_replace($ldap, string $dn, array $entry, array $controls = []): bool {}
156+
function ldap_mod_replace($ldap, string $dn, array $entry, ?array $controls = null): bool {}
157157

158158
/**
159159
* @param resource $ldap
160160
* @alias ldap_mod_replace
161161
*/
162-
function ldap_modify($ldap, string $dn, array $entry, array $controls = []): bool {}
162+
function ldap_modify($ldap, string $dn, array $entry, ?array $controls = null): bool {}
163163

164164
/**
165165
* @param resource $ldap
166166
* @return resource|false
167167
*/
168-
function ldap_mod_replace_ext($ldap, string $dn, array $entry, array $controls = []) {}
168+
function ldap_mod_replace_ext($ldap, string $dn, array $entry, ?array $controls = null) {}
169169

170170
/** @param resource $ldap */
171-
function ldap_mod_del($ldap, string $dn, array $entry, array $controls = []): bool {}
171+
function ldap_mod_del($ldap, string $dn, array $entry, ?array $controls = null): bool {}
172172

173173
/**
174174
* @param resource $ldap
175175
* @return resource|false
176176
*/
177-
function ldap_mod_del_ext($ldap, string $dn, array $entry, array $controls = []) {}
177+
function ldap_mod_del_ext($ldap, string $dn, array $entry, ?array $controls = null) {}
178178

179179
/** @param resource $ldap */
180180
function ldap_errno($ldap): int {}
@@ -185,17 +185,17 @@ function ldap_error($ldap): string {}
185185
function ldap_err2str(int $errno): string {}
186186

187187
/** @param resource $ldap */
188-
function ldap_compare($ldap, string $dn, string $attribute, string $value, array $controls = []): bool|int {}
188+
function ldap_compare($ldap, string $dn, string $attribute, string $value, ?array $controls = null): bool|int {}
189189

190190
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
191191
/** @param resource $ldap */
192-
function ldap_rename($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, array $controls = []): bool {}
192+
function ldap_rename($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, ?array $controls = null): bool {}
193193

194194
/**
195195
* @param resource $ldap
196196
* @return resource|false
197197
*/
198-
function ldap_rename_ext($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, array $controls = []) {}
198+
function ldap_rename_ext($ldap, string $dn, string $new_rdn, string $new_parent, bool $delete_old_rdn, ?array $controls = null) {}
199199

200200

201201
/**
@@ -279,7 +279,7 @@ function ldap_8859_to_t61(string $value): string|false {}
279279
* @param string $response_oid
280280
* @return resource|bool
281281
*/
282-
function ldap_exop($ldap, string $request_oid, ?string $request_data = null, ?array $controls = [], &$response_data = UNKNOWN, &$response_oid = null) {}
282+
function ldap_exop($ldap, string $request_oid, ?string $request_data = null, ?array $controls = NULL, &$response_data = UNKNOWN, &$response_oid = null) {}
283283
#endif
284284

285285
#ifdef HAVE_LDAP_PASSWD

ext/ldap/ldap_arginfo.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0c02f5e91a47e9664c8c41332bf8040e93592753 */
2+
* Stub hash: 980ee25422e1b026259d63e7a61adea699751b86 */
33

44
#if defined(HAVE_ORALDAP)
55
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
@@ -34,7 +34,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_bind_ext, 0, 0, 1)
3434
ZEND_ARG_INFO(0, ldap)
3535
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, dn, IS_STRING, 1, "null")
3636
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
37-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
37+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
3838
ZEND_END_ARG_INFO()
3939

4040
#if defined(HAVE_LDAP_SASL)
@@ -59,7 +59,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_read, 0, 0, 3)
5959
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sizelimit, IS_LONG, 0, "-1")
6060
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timelimit, IS_LONG, 0, "-1")
6161
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, deref, IS_LONG, 0, "LDAP_DEREF_NEVER")
62-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
62+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
6363
ZEND_END_ARG_INFO()
6464

6565
#define arginfo_ldap_list arginfo_ldap_read
@@ -120,33 +120,33 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_add, 0, 3, _IS_BOOL, 0)
120120
ZEND_ARG_INFO(0, ldap)
121121
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
122122
ZEND_ARG_TYPE_INFO(0, entry, IS_ARRAY, 0)
123-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
123+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
124124
ZEND_END_ARG_INFO()
125125

126126
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_add_ext, 0, 0, 3)
127127
ZEND_ARG_INFO(0, ldap)
128128
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
129129
ZEND_ARG_TYPE_INFO(0, entry, IS_ARRAY, 0)
130-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
130+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
131131
ZEND_END_ARG_INFO()
132132

133133
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_delete, 0, 2, _IS_BOOL, 0)
134134
ZEND_ARG_INFO(0, ldap)
135135
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
136-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
136+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
137137
ZEND_END_ARG_INFO()
138138

139139
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_delete_ext, 0, 0, 2)
140140
ZEND_ARG_INFO(0, ldap)
141141
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
142-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
142+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
143143
ZEND_END_ARG_INFO()
144144

145145
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_modify_batch, 0, 3, _IS_BOOL, 0)
146146
ZEND_ARG_INFO(0, ldap)
147147
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
148148
ZEND_ARG_TYPE_INFO(0, modifications_info, IS_ARRAY, 0)
149-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
149+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
150150
ZEND_END_ARG_INFO()
151151

152152
#define arginfo_ldap_mod_add arginfo_ldap_add
@@ -180,7 +180,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ldap_compare, 0, 4, MAY_BE_BOOL|
180180
ZEND_ARG_TYPE_INFO(0, dn, IS_STRING, 0)
181181
ZEND_ARG_TYPE_INFO(0, attribute, IS_STRING, 0)
182182
ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0)
183-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
183+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
184184
ZEND_END_ARG_INFO()
185185

186186
#if (LDAP_API_VERSION > 2000) || defined(HAVE_ORALDAP)
@@ -190,7 +190,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_rename, 0, 5, _IS_BOOL, 0)
190190
ZEND_ARG_TYPE_INFO(0, new_rdn, IS_STRING, 0)
191191
ZEND_ARG_TYPE_INFO(0, new_parent, IS_STRING, 0)
192192
ZEND_ARG_TYPE_INFO(0, delete_old_rdn, _IS_BOOL, 0)
193-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
193+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
194194
ZEND_END_ARG_INFO()
195195
#endif
196196

@@ -201,7 +201,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_rename_ext, 0, 0, 5)
201201
ZEND_ARG_TYPE_INFO(0, new_rdn, IS_STRING, 0)
202202
ZEND_ARG_TYPE_INFO(0, new_parent, IS_STRING, 0)
203203
ZEND_ARG_TYPE_INFO(0, delete_old_rdn, _IS_BOOL, 0)
204-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 0, "[]")
204+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "null")
205205
ZEND_END_ARG_INFO()
206206
#endif
207207

@@ -296,7 +296,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_exop, 0, 0, 2)
296296
ZEND_ARG_INFO(0, ldap)
297297
ZEND_ARG_TYPE_INFO(0, request_oid, IS_STRING, 0)
298298
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, request_data, IS_STRING, 1, "null")
299-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "[]")
299+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, controls, IS_ARRAY, 1, "NULL")
300300
ZEND_ARG_INFO(1, response_data)
301301
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, response_oid, "null")
302302
ZEND_END_ARG_INFO()

0 commit comments

Comments
 (0)