Skip to content

Commit dbd7a38

Browse files
committed
Process missing libldap options
1 parent c4efbda commit dbd7a38

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

Lib/ldap/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class Str(Constant):
244244
Int('OPT_SIZELIMIT'),
245245
Int('OPT_TIMELIMIT'),
246246
Int('OPT_REFERRALS', optional=True),
247+
Int('OPT_RESULT_CODE'),
247248
Int('OPT_ERROR_NUMBER'),
248249
Int('OPT_RESTART'),
249250
Int('OPT_PROTOCOL_VERSION'),
@@ -261,6 +262,7 @@ class Str(Constant):
261262
Int('OPT_TIMEOUT'),
262263
Int('OPT_REFHOPLIMIT'),
263264
Int('OPT_NETWORK_TIMEOUT'),
265+
Int('OPT_TCP_USER_TIMEOUT', optional=True),
264266
Int('OPT_URI'),
265267

266268
Int('OPT_DEFBASE', optional=True),
@@ -299,6 +301,7 @@ class Str(Constant):
299301
TLSInt('OPT_X_TLS_PACKAGE', optional=True),
300302

301303
# Added in OpenLDAP 2.4.52
304+
TLSInt('OPT_X_TLS_ECNAME', optional=True),
302305
TLSInt('OPT_X_TLS_REQUIRE_SAN', optional=True),
303306

304307
# Added in OpenLDAP 2.5

Modules/constants_generated.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ add_int(OPT_TIMELIMIT);
173173
add_int(OPT_REFERRALS);
174174
#endif
175175

176+
add_int(OPT_RESULT_CODE);
176177
add_int(OPT_ERROR_NUMBER);
177178
add_int(OPT_RESTART);
178179
add_int(OPT_PROTOCOL_VERSION);
@@ -188,6 +189,11 @@ add_int(OPT_DEBUG_LEVEL);
188189
add_int(OPT_TIMEOUT);
189190
add_int(OPT_REFHOPLIMIT);
190191
add_int(OPT_NETWORK_TIMEOUT);
192+
193+
#if defined(LDAP_OPT_TCP_USER_TIMEOUT)
194+
add_int(OPT_TCP_USER_TIMEOUT);
195+
#endif
196+
191197
add_int(OPT_URI);
192198

193199
#if defined(LDAP_OPT_DEFBASE)
@@ -259,6 +265,11 @@ add_int(OPT_X_TLS_PACKAGE);
259265
#endif
260266

261267

268+
#if defined(LDAP_OPT_X_TLS_ECNAME)
269+
add_int(OPT_X_TLS_ECNAME);
270+
#endif
271+
272+
262273
#if defined(LDAP_OPT_X_TLS_REQUIRE_SAN)
263274
add_int(OPT_X_TLS_REQUIRE_SAN);
264275
#endif

Modules/options.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
4141
{
4242
int res;
4343
int intval;
44+
unsigned int uintval;
4445
double doubleval;
4546
char *strval;
4647
struct timeval tv;
@@ -57,6 +58,7 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
5758
switch (option) {
5859
case LDAP_OPT_API_INFO:
5960
case LDAP_OPT_API_FEATURE_INFO:
61+
case LDAP_OPT_DESC:
6062
#ifdef HAVE_SASL
6163
case LDAP_OPT_X_SASL_SSF:
6264
#endif
@@ -116,10 +118,19 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
116118
ptr = &intval;
117119
break;
118120

121+
#ifdef LDAP_OPT_TCP_USER_TIMEOUT
122+
case LDAP_OPT_TCP_USER_TIMEOUT:
123+
#endif
124+
if (!PyArg_Parse(value, "I:set_option", &uintval))
125+
return 0;
126+
ptr = &uintval;
127+
break;
128+
119129
#ifdef HAVE_SASL
120130
case LDAP_OPT_X_SASL_SSF_MIN:
121131
case LDAP_OPT_X_SASL_SSF_MAX:
122132
case LDAP_OPT_X_SASL_SSF_EXTERNAL:
133+
case LDAP_OPT_X_SASL_MAXBUFSIZE:
123134
if (!PyArg_Parse(value, "k:set_option", &blen))
124135
return 0;
125136
ptr = &blen;
@@ -144,9 +155,15 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
144155
#ifdef LDAP_OPT_X_TLS_CRLFILE
145156
case LDAP_OPT_X_TLS_CRLFILE:
146157
#endif
158+
#ifdef LDAP_OPT_X_TLS_ECNAME
159+
case LDAP_OPT_X_TLS_ECNAME:
160+
#endif
147161
#endif
148162
#ifdef HAVE_SASL
149163
case LDAP_OPT_X_SASL_SECPROPS:
164+
#endif
165+
#ifdef LDAP_OPT_SOCKET_BIND_ADDRESSES
166+
case LDAP_OPT_SOCKET_BIND_ADDRESSES:
150167
#endif
151168
/* String valued options */
152169
if (!PyArg_Parse(value, "s:set_option", &strval))
@@ -187,8 +204,8 @@ LDAP_set_option(LDAPObject *self, int option, PyObject *value)
187204
}
188205
else {
189206
PyErr_Format(PyExc_ValueError,
190-
"timeout must be >= 0 or -1/None for infinity, got %d",
191-
option);
207+
"timeout must be >= 0 or -1/None for infinity, got %f",
208+
doubleval);
192209
return 0;
193210
}
194211
break;
@@ -254,6 +271,7 @@ LDAP_get_option(LDAPObject *self, int option)
254271
{
255272
int res;
256273
int intval;
274+
unsigned int uintval;
257275
struct timeval *tv;
258276
LDAPAPIInfo apiinfo;
259277
LDAPControl **lcs;
@@ -268,6 +286,7 @@ LDAP_get_option(LDAPObject *self, int option)
268286

269287
switch (option) {
270288
#ifdef HAVE_SASL
289+
case LDAP_OPT_X_SASL_SECPROPS:
271290
case LDAP_OPT_X_SASL_SSF_EXTERNAL:
272291
/* Write-only options */
273292
PyErr_SetString(PyExc_ValueError, "write-only option");
@@ -350,10 +369,20 @@ LDAP_get_option(LDAPObject *self, int option)
350369
return option_error(res, "ldap_get_option");
351370
return PyInt_FromLong(intval);
352371

372+
#ifdef LDAP_OPT_TCP_USER_TIMEOUT
373+
case LDAP_OPT_TCP_USER_TIMEOUT:
374+
#endif
375+
/* unsigned int options */
376+
res = LDAP_int_get_option(self, option, &uintval);
377+
if (res != LDAP_OPT_SUCCESS)
378+
return option_error(res, "ldap_get_option");
379+
return PyLong_FromUnsignedLong(uintval);
380+
353381
#ifdef HAVE_SASL
354382
case LDAP_OPT_X_SASL_SSF:
355383
case LDAP_OPT_X_SASL_SSF_MIN:
356384
case LDAP_OPT_X_SASL_SSF_MAX:
385+
case LDAP_OPT_X_SASL_MAXBUFSIZE:
357386
/* ber_len_t options (unsigned long)*/
358387
res = LDAP_int_get_option(self, option, &blen);
359388
if (res != LDAP_OPT_SUCCESS)
@@ -388,16 +417,21 @@ LDAP_get_option(LDAPObject *self, int option)
388417
#ifdef LDAP_OPT_X_TLS_PACKAGE
389418
case LDAP_OPT_X_TLS_PACKAGE:
390419
#endif
420+
#ifdef LDAP_OPT_X_TLS_ECNAME
421+
case LDAP_OPT_X_TLS_ECNAME:
422+
#endif
391423
#endif
392424
#ifdef HAVE_SASL
393-
case LDAP_OPT_X_SASL_SECPROPS:
394425
case LDAP_OPT_X_SASL_MECH:
395426
case LDAP_OPT_X_SASL_REALM:
396427
case LDAP_OPT_X_SASL_AUTHCID:
397428
case LDAP_OPT_X_SASL_AUTHZID:
398429
#ifdef LDAP_OPT_X_SASL_USERNAME
399430
case LDAP_OPT_X_SASL_USERNAME:
400431
#endif
432+
#endif
433+
#ifdef LDAP_OPT_SOCKET_BIND_ADDRESSES
434+
case LDAP_OPT_SOCKET_BIND_ADDRESSES:
401435
#endif
402436
/* String-valued options */
403437
res = LDAP_int_get_option(self, option, &strval);

0 commit comments

Comments
 (0)