[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Problems in LDAPControl handling
Hello all.
My name is Salvador and this is my first post to the list.
I know that the C API documentation in the 2.x series its incomplete, so
for my proyect I'm using both the (expired) c-api draft and the sources as
a reference.
While reading controls.c I found what IMHO is a bug in ldap_create_control
and a potential problem in ldap_control_dup (both undocumented yet but
very useful):
First the bug:
ldap_control_create returns LDAP_PARAM_ERROR when ber == NULL, a
BUG in my opinion because it is perfectly valid to create a control
without a controlValue.
BTW, ldap_control_create depends on ber_flatten that allows ber==NULL, so
I suggest:
- if ( requestOID == NULL || ber == NULL || ctrlp == NULL ) {
+ if ( requestOID == NULL || ctrlp == NULL ) {
Now the problem:
In the draft, in 11.3 "Working With Controls" i can read:
ldctl_value The data associated with the control (if any). To
specify a zero-length value, set ldctl_value.bv_len to
zero and ldctl_value.bv_val to a zero-length string.
To indicate that no data is associated with the con-
trol, set ldctl_value.bv_val to NULL.
So we have two diferent cases with bv_len == 0, that makes sense to
me because in the ASN1 a controlValue is defined as OCTECT STRING OPTIONAL
so
'bv_len == 0, bv_val == NULL' eq "no controlValue"
and
'bv_len == 0, bv_val == ""' supplies a empty but existent controlValue.
But in ldap_control_dup i read:
if( c->ldctl_value.bv_len > 0 ) {
...
} else {
new->ldctl_value.bv_len = 0;
new->ldctl_value.bv_val = NULL;
}
That turns a control with a "zero length" controlValue into a control
without it.
As commented above, ldap_control_create uses ber_flatten to initialize a
new control and ber_flatten with ber == NULL creates an empty berval
(bv_len == 0, bv_val == NULL) but with ber != NULL it allocates memory
(one byte, for the char(\0)) even in the case len == 0.
I don't know if in reallity can be a ldap control with diferent
semantics for the two cases, so I'm asking you for some expert advise.
Best Regards, and please forgive my poor English.
Salvador Ortiz