21 #include "ldapoperation.h"
22 #include "kldap_config.h"
26 #include <QtCore/QTime>
29 #ifdef HAVE_SYS_TIME_H
34 #include <sasl/sasl.h>
38 # ifndef HAVE_WINLDAP_H
42 # include <w32-ldap-help.h>
43 # endif // HAVE_WINLDAP_H
48 using namespace KLDAP;
51 static void extractControls(
LdapControls &ctrls, LDAPControl **pctrls );
58 static int kldap_timeout_value(
int msecs,
int elapsed )
64 int timeout = msecs - elapsed;
65 return timeout < 0 ? 0 : timeout;
68 class LdapOperation::LdapOperationPrivate
71 LdapOperationPrivate();
72 ~LdapOperationPrivate();
74 int processResult(
int rescode, LDAPMessage *msg );
75 int bind(
const QByteArray &creds, SASL_Callback_Proc *saslproc,
void *data,
bool async );
87 LdapOperation::LdapOperation()
88 : d( new LdapOperationPrivate )
94 : d( new LdapOperationPrivate )
96 setConnection( conn );
99 LdapOperation::~LdapOperation()
106 d->mConnection = &conn;
111 return *d->mConnection;
116 d->mClientCtrls = ctrls;
121 d->mServerCtrls = ctrls;
126 return d->mClientCtrls;
131 return d->mServerCtrls;
156 return d->mMatchedDn;
161 return d->mReferrals;
166 return d->mServerCred;
169 LdapOperation::LdapOperationPrivate::LdapOperationPrivate()
173 LdapOperation::LdapOperationPrivate::~LdapOperationPrivate()
180 static int kldap_sasl_interact( sasl_interact_t *interact, LdapOperation::SASL_Data *data )
183 for ( ; interact->id != SASL_CB_LIST_END; interact++ ) {
184 switch ( interact->id ) {
185 case SASL_CB_GETREALM:
186 data->creds.fields |= LdapOperation::SASL_Realm;
188 case SASL_CB_AUTHNAME:
189 data->creds.fields |= LdapOperation::SASL_Authname;
192 data->creds.fields |= LdapOperation::SASL_Password;
195 data->creds.fields |= LdapOperation::SASL_Authzid;
200 if ( ( retval = data->proc( data->creds, data->data ) ) ) {
207 while ( interact->id != SASL_CB_LIST_END ) {
209 switch ( interact->id ) {
210 case SASL_CB_GETREALM:
211 value = data->creds.realm;
212 kDebug() <<
"SASL_REALM=" << value;
214 case SASL_CB_AUTHNAME:
215 value = data->creds.authname;
216 kDebug() <<
"SASL_AUTHNAME=" << value;
219 value = data->creds.password;
220 kDebug() <<
"SASL_PASSWD=[hidden]";
223 value = data->creds.authzid;
224 kDebug() <<
"SASL_AUTHZID=" << value;
228 interact->result = NULL;
231 interact->result = strdup( value.
toUtf8() );
232 interact->len = strlen( (
const char *)interact->result );
236 return KLDAP_SUCCESS;
240 int LdapOperation::LdapOperationPrivate::bind(
const QByteArray &creds,
241 SASL_Callback_Proc *saslproc,
242 void *data,
bool async )
244 Q_ASSERT( mConnection );
245 LDAP *ld = (LDAP *) mConnection->handle();
247 server = mConnection->server();
252 #if defined( SASL2_FOUND ) && !defined( HAVE_WINLDAP_H )
253 sasl_conn_t *saslconn = (sasl_conn_t *)mConnection->saslHandle();
254 sasl_interact_t *client_interact = NULL;
255 const char *out = NULL;
257 const char *mechusing = NULL;
258 struct berval ccred, *scred;
268 sasldata.proc = saslproc;
269 sasldata.data = data;
270 sasldata.creds.fields = 0;
271 sasldata.creds.realm = server.
realm();
272 sasldata.creds.authname = server.
user();
273 sasldata.creds.authzid = server.
bindDn();
274 sasldata.creds.password = server.
password();
279 saslresult = sasl_client_start( saslconn, mech.
toLatin1(),
280 &client_interact, &out, &outlen, &mechusing );
282 if ( saslresult == SASL_INTERACT ) {
283 if ( kldap_sasl_interact( client_interact, &sasldata ) != KLDAP_SUCCESS ) {
284 return KLDAP_SASL_ERROR;
287 kDebug() <<
"sasl_client_start mech: "
288 << mechusing <<
" outlen " << outlen
289 <<
" result: " << saslresult;
290 }
while ( saslresult == SASL_INTERACT );
291 if ( saslresult != SASL_CONTINUE && saslresult != SASL_OK ) {
292 return KLDAP_SASL_ERROR;
296 kDebug() <<
"sasl_client_step";
298 saslresult = sasl_client_step( saslconn, sdata.
data(), sdata.
size(),
299 &client_interact, &out, &outlen );
300 if ( saslresult == SASL_INTERACT ) {
301 if ( kldap_sasl_interact( client_interact, &sasldata ) != KLDAP_SUCCESS ) {
302 return KLDAP_SASL_ERROR;
305 }
while ( saslresult == SASL_INTERACT );
306 kDebug() <<
"sasl_client_step result" << saslresult;
307 if ( saslresult != SASL_CONTINUE && saslresult != SASL_OK ) {
308 return KLDAP_SASL_ERROR;
312 ccred.bv_val = (
char*) out;
313 ccred.bv_len = outlen;
316 kDebug() <<
"ldap_sasl_bind";
320 &ccred, 0, 0, &msgid );
324 kDebug() <<
"ldap_sasl_bind msgid" << ret;
326 kDebug() <<
"ldap_sasl_bind_s";
329 &ccred, 0, 0, &scred );
330 kDebug() <<
"ldap_sasl_bind_s ret" << ret;
332 sdata =
QByteArray( scred->bv_val, scred->bv_len );
337 }
while ( !async && ret == KLDAP_SASL_BIND_IN_PROGRESS );
339 kError() <<
"SASL authentication is not available "
340 <<
"(re-compile kldap with cyrus-sasl and OpenLDAP development).";
341 return KLDAP_SASL_ERROR;
350 ccred.bv_val = pass.
data();
351 ccred.bv_len = pass.
size();
352 kDebug() <<
"binding to server, bindname: " << bindname <<
" password: *****";
355 kDebug() <<
"ldap_sasl_bind (simple)";
356 #ifndef HAVE_WINLDAP_H
358 ret = ldap_sasl_bind( ld, bindname.
data(), 0, &ccred, 0, 0, &msgid );
363 ret = ldap_simple_bind( ld, bindname.
data(), pass.
data() );
366 kDebug() <<
"ldap_sasl_bind_s (simple)";
367 #ifndef HAVE_WINLDAP_H
368 ret = ldap_sasl_bind_s( ld, bindname.
data(), 0, &ccred, 0, 0, 0 );
370 ret = ldap_simple_bind_s( ld, bindname.
data(), pass.
data() );
377 int LdapOperation::LdapOperationPrivate::processResult(
int rescode, LDAPMessage *msg )
381 LDAP *ld = (LDAP *) mConnection->handle();
383 kDebug() <<
"rescode: " << rescode;
385 case RES_SEARCH_ENTRY:
391 struct berval **bvals;
394 char *dn = ldap_get_dn( ld, msg );
399 name = ldap_first_attribute( ld, msg, &entry );
400 while ( name != 0 ) {
402 bvals = ldap_get_values_len( ld, msg, name );
405 for (
int i = 0; bvals[i] != 0; i++ ) {
406 char *val = bvals[i]->bv_val;
407 unsigned long len = bvals[i]->bv_len;
410 ldap_value_free_len( bvals );
413 ldap_memfree( name );
416 name = ldap_next_attribute( ld, msg, entry );
418 ber_free( entry, 0 );
419 mObject.setAttributes( attrs );
422 case RES_SEARCH_REFERENCE:
429 struct berval *retdata;
430 retval = ldap_parse_extended_result( ld, msg, &retoid, &retdata, 0 );
431 if ( retval != KLDAP_SUCCESS ) {
435 mExtOid = retoid ?
QByteArray( retoid ) : QByteArray();
436 mExtData = retdata ? QByteArray( retdata->bv_val, retdata->bv_len ) : QByteArray();
437 ldap_memfree( retoid );
438 ber_bvfree( retdata );
443 struct berval *servercred = 0;
444 #ifndef HAVE_WINLDAP_H
446 retval = ldap_parse_sasl_bind_result( ld, msg, &servercred, 0 );
448 retval = KLDAP_SUCCESS;
450 if ( retval != KLDAP_SUCCESS && retval != KLDAP_SASL_BIND_IN_PROGRESS ) {
451 kDebug() <<
"RES_BIND error: " << retval;
455 kDebug() <<
"RES_BIND rescode" << rescode <<
"retval:" << retval;
457 mServerCred = QByteArray( servercred->bv_val, servercred->bv_len );
458 ber_bvfree( servercred );
460 mServerCred = QByteArray();
466 LDAPControl **serverctrls = 0;
467 char *matcheddn = 0, *errmsg = 0;
471 ldap_parse_result( ld, msg, &errcodep, &matcheddn, &errmsg, &referralsp,
473 kDebug() <<
"rescode" << rescode <<
"retval:" << retval
474 <<
"matcheddn:" << matcheddn <<
"errcode:"
475 << errcodep <<
"errmsg:" << errmsg;
476 if ( retval != KLDAP_SUCCESS ) {
482 extractControls( mControls, serverctrls );
483 ldap_controls_free( serverctrls );
487 char **tmp = referralsp;
489 mReferrals.append( QByteArray( *tmp ) );
490 ldap_memfree( *tmp );
493 ldap_memfree( (
char *) referralsp );
498 ldap_memfree( matcheddn );
501 ldap_memfree( errmsg );
511 static void addModOp( LDAPMod ***pmods,
int mod_type,
const QString &attr,
512 const QByteArray *value = 0 )
524 mods = (LDAPMod **)malloc( 2 *
sizeof( LDAPMod * ) );
525 mods[ 0 ] = (LDAPMod *)malloc(
sizeof( LDAPMod ) );
527 memset( mods[ 0 ], 0,
sizeof( LDAPMod ) );
529 while ( mods[ i ] != 0 &&
530 ( strcmp( attr.
toUtf8(), mods[i]->mod_type ) != 0 ||
531 ( mods[ i ]->mod_op & ~LDAP_MOD_BVALUES ) != mod_type ) ) i++;
533 if ( mods[ i ] == 0 ) {
534 mods = (LDAPMod **)realloc( mods, ( i + 2 ) *
sizeof( LDAPMod * ) );
536 kError() <<
"addModOp: realloc";
540 mods[ i ] = (LDAPMod *) malloc(
sizeof( LDAPMod ) );
541 memset( mods[ i ], 0,
sizeof( LDAPMod ) );
545 mods[ i ]->mod_op = mod_type | LDAP_MOD_BVALUES;
546 if ( mods[ i ]->mod_type == 0 ) {
547 mods[ i ]->mod_type = strdup( attr.
toUtf8() );
556 int vallen = value->
size();
558 berval = (BerValue *) malloc(
sizeof( BerValue ) );
559 berval -> bv_len = vallen;
561 berval -> bv_val = (
char *) malloc( vallen );
562 memcpy( berval -> bv_val, value->
data(), vallen );
564 berval -> bv_val = 0;
567 if ( mods[ i ] -> mod_vals.modv_bvals == 0 ) {
568 mods[ i ]->mod_vals.modv_bvals =
569 (BerValue **) malloc(
sizeof( BerValue * ) * 2 );
570 mods[ i ]->mod_vals.modv_bvals[ 0 ] = berval;
571 mods[ i ]->mod_vals.modv_bvals[ 1 ] = 0;
575 while ( mods[ i ]->mod_vals.modv_bvals[ j ] != 0 ) {
578 mods[ i ]->mod_vals.modv_bvals =
579 (BerValue **)realloc( mods[ i ]->mod_vals.modv_bvals,
580 ( j + 2 ) *
sizeof( BerValue * ) );
581 if ( mods[ i ]->mod_vals.modv_bvals == 0 ) {
582 kError() <<
"addModOp: realloc";
586 mods[ i ]->mod_vals.modv_bvals[ j ] = berval;
587 mods[ i ]->mod_vals.modv_bvals[ j+1 ] = 0;
588 kDebug() << j <<
". new bervalue";
592 static void addControlOp( LDAPControl ***pctrls,
const QString &oid,
593 const QByteArray &value,
bool critical )
596 LDAPControl *ctrl = (LDAPControl *) malloc(
sizeof( LDAPControl ) );
600 kDebug() <<
"oid:'" << oid <<
"' val: '" << value <<
"'";
601 int vallen = value.
size();
602 ctrl->ldctl_value.bv_len = vallen;
604 ctrl->ldctl_value.bv_val = (
char *) malloc( vallen );
605 memcpy( ctrl->ldctl_value.bv_val, value.data(), vallen );
607 ctrl->ldctl_value.bv_val = 0;
609 ctrl->ldctl_iscritical = critical;
610 ctrl->ldctl_oid = strdup( oid.
toUtf8() );
615 ctrls = (LDAPControl **)malloc ( 2 *
sizeof( LDAPControl * ) );
619 while ( ctrls[ i ] != 0 ) {
624 (LDAPControl **)realloc( ctrls, ( i + 2 ) *
sizeof( LDAPControl * ) );
630 static void createControls( LDAPControl ***pctrls,
const LdapControls &ctrls )
632 for (
int i = 0; i< ctrls.
count(); ++i ) {
633 addControlOp( pctrls, ctrls[i].oid(), ctrls[i].value(), ctrls[i].critical() );
637 static void extractControls(
LdapControls &ctrls, LDAPControl **pctrls )
643 while ( pctrls[i] ) {
646 control.
setValue( QByteArray( ctrl->ldctl_value.bv_val,
647 ctrl->ldctl_value.bv_len ) );
654 int LdapOperation::bind(
const QByteArray &creds, SASL_Callback_Proc *saslproc,
void *data )
656 return d->bind( creds, saslproc, data,
true );
661 return d->bind( QByteArray(), saslproc, data,
false );
667 Q_ASSERT( d->mConnection );
668 LDAP *ld = (LDAP *) d->mConnection->handle();
673 LDAPControl **serverctrls = 0, **clientctrls = 0;
674 createControls( &serverctrls, d->mServerCtrls );
675 createControls( &serverctrls, d->mClientCtrls );
677 int count = attributes.
count();
679 attrs =
static_cast<char**
>( malloc( ( count + 1 ) *
sizeof(
char * ) ) );
680 for (
int i=0; i<count; i++ ) {
681 attrs[i] = strdup( attributes.
at( i ).toUtf8() );
686 int lscope = LDAP_SCOPE_BASE;
689 lscope = LDAP_SCOPE_BASE;
692 lscope = LDAP_SCOPE_ONELEVEL;
695 lscope = LDAP_SCOPE_SUBTREE;
699 kDebug() <<
"asyncSearch() base=\"" << base.toString()
700 <<
"\" scope=" << (int)scope
701 <<
"filter=\"" << filter
702 <<
"\" attrs=" << attributes;
704 ldap_search_ext( ld, base.toString().toUtf8().data(), lscope,
705 filter.
isEmpty() ? QByteArray(
"objectClass=*" ).data() :
707 attrs, 0, serverctrls, clientctrls, 0,
708 d->mConnection->sizeLimit(), &msgid );
710 ldap_controls_free( serverctrls );
711 ldap_controls_free( clientctrls );
715 for (
int i=0; i<count; i++ ) {
729 Q_ASSERT( d->mConnection );
730 LDAP *ld = (LDAP *) d->mConnection->handle();
735 LDAPControl **serverctrls = 0, **clientctrls = 0;
736 createControls( &serverctrls, d->mServerCtrls );
737 createControls( &serverctrls, d->mClientCtrls );
740 it !=
object.attributes().
end(); ++it ) {
743 addModOp( &lmod, 0, attr, &( *it2 ) );
748 ldap_add_ext( ld,
object.dn().
toString().toUtf8().data(), lmod, serverctrls,
749 clientctrls, &msgid );
751 ldap_controls_free( serverctrls );
752 ldap_controls_free( clientctrls );
753 ldap_mods_free( lmod, 1 );
762 Q_ASSERT( d->mConnection );
763 LDAP *ld = (LDAP *) d->mConnection->handle();
767 LDAPControl **serverctrls = 0, **clientctrls = 0;
768 createControls( &serverctrls, d->mServerCtrls );
769 createControls( &serverctrls, d->mClientCtrls );
772 it !=
object.attributes().
end(); ++it ) {
775 addModOp( &lmod, 0, attr, &( *it2 ) );
780 ldap_add_ext_s( ld,
object.dn().
toString().toUtf8().data(), lmod, serverctrls,
783 ldap_controls_free( serverctrls );
784 ldap_controls_free( clientctrls );
785 ldap_mods_free( lmod, 1 );
791 Q_ASSERT( d->mConnection );
792 LDAP *ld = (LDAP *) d->mConnection->handle();
797 LDAPControl **serverctrls = 0, **clientctrls = 0;
798 createControls( &serverctrls, d->mServerCtrls );
799 createControls( &serverctrls, d->mClientCtrls );
801 for (
int i = 0; i < ops.count(); ++i ) {
802 for (
int j = 0; j < ops[i].values.count(); ++j ) {
803 addModOp( &lmod, 0, ops[i].attr, &ops[i].values[j] );
808 ldap_add_ext( ld, dn.toString().toUtf8().data(), lmod, serverctrls,
809 clientctrls, &msgid );
811 ldap_controls_free( serverctrls );
812 ldap_controls_free( clientctrls );
813 ldap_mods_free( lmod, 1 );
822 Q_ASSERT( d->mConnection );
823 LDAP *ld = (LDAP *) d->mConnection->handle();
827 LDAPControl **serverctrls = 0, **clientctrls = 0;
828 createControls( &serverctrls, d->mServerCtrls );
829 createControls( &serverctrls, d->mClientCtrls );
831 for (
int i = 0; i < ops.count(); ++i ) {
832 for (
int j = 0; j < ops[i].values.count(); ++j ) {
833 addModOp( &lmod, 0, ops[i].attr, &ops[i].values[j] );
836 kDebug() << dn.toString();
838 ldap_add_ext_s( ld, dn.toString().toUtf8().data(), lmod, serverctrls,
841 ldap_controls_free( serverctrls );
842 ldap_controls_free( clientctrls );
843 ldap_mods_free( lmod, 1 );
848 const QString &newSuperior,
bool deleteold )
850 Q_ASSERT( d->mConnection );
851 LDAP *ld = (LDAP *) d->mConnection->handle();
855 LDAPControl **serverctrls = 0, **clientctrls = 0;
856 createControls( &serverctrls, d->mServerCtrls );
857 createControls( &serverctrls, d->mClientCtrls );
859 int retval = ldap_rename( ld, dn.toString().toUtf8().data(), newRdn.
toUtf8().
data(),
861 deleteold, serverctrls, clientctrls, &msgid );
863 ldap_controls_free( serverctrls );
864 ldap_controls_free( clientctrls );
873 const QString &newSuperior,
bool deleteold )
875 Q_ASSERT( d->mConnection );
876 LDAP *ld = (LDAP *) d->mConnection->handle();
878 LDAPControl **serverctrls = 0, **clientctrls = 0;
879 createControls( &serverctrls, d->mServerCtrls );
880 createControls( &serverctrls, d->mClientCtrls );
882 int retval = ldap_rename_s( ld, dn.toString().toUtf8().data(), newRdn.
toUtf8().
data(),
884 deleteold, serverctrls, clientctrls );
886 ldap_controls_free( serverctrls );
887 ldap_controls_free( clientctrls );
894 Q_ASSERT( d->mConnection );
895 LDAP *ld = (LDAP *) d->mConnection->handle();
899 LDAPControl **serverctrls = 0, **clientctrls = 0;
900 createControls( &serverctrls, d->mServerCtrls );
901 createControls( &serverctrls, d->mClientCtrls );
904 ldap_delete_ext( ld, dn.toString().toUtf8().data(), serverctrls, clientctrls, &msgid );
906 ldap_controls_free( serverctrls );
907 ldap_controls_free( clientctrls );
917 Q_ASSERT( d->mConnection );
918 LDAP *ld = (LDAP *) d->mConnection->handle();
920 LDAPControl **serverctrls = 0, **clientctrls = 0;
921 createControls( &serverctrls, d->mServerCtrls );
922 createControls( &serverctrls, d->mClientCtrls );
924 int retval = ldap_delete_ext_s( ld, dn.toString().toUtf8().data(), serverctrls, clientctrls );
926 ldap_controls_free( serverctrls );
927 ldap_controls_free( clientctrls );
934 Q_ASSERT( d->mConnection );
935 LDAP *ld = (LDAP *)d->mConnection->handle();
940 LDAPControl **serverctrls = 0, **clientctrls = 0;
941 createControls( &serverctrls, d->mServerCtrls );
942 createControls( &serverctrls, d->mClientCtrls );
944 for (
int i = 0; i < ops.count(); ++i ) {
946 switch ( ops[i].type ) {
951 mtype = LDAP_MOD_ADD;
954 mtype = LDAP_MOD_REPLACE;
957 mtype = LDAP_MOD_DELETE;
960 addModOp( &lmod, mtype, ops[i].attr, 0 );
961 for (
int j = 0; j < ops[i].values.count(); ++j ) {
962 addModOp( &lmod, mtype, ops[i].attr, &ops[i].values[j] );
967 ldap_modify_ext( ld, dn.toString().toUtf8().data(), lmod, serverctrls, clientctrls, &msgid );
969 ldap_controls_free( serverctrls );
970 ldap_controls_free( clientctrls );
971 ldap_mods_free( lmod, 1 );
980 Q_ASSERT( d->mConnection );
981 LDAP *ld = (LDAP *) d->mConnection->handle();
985 LDAPControl **serverctrls = 0, **clientctrls = 0;
986 createControls( &serverctrls, d->mServerCtrls );
987 createControls( &serverctrls, d->mClientCtrls );
989 for (
int i = 0; i < ops.count(); ++i ) {
991 switch ( ops[i].type ) {
996 mtype = LDAP_MOD_ADD;
999 mtype = LDAP_MOD_REPLACE;
1002 mtype = LDAP_MOD_DELETE;
1005 addModOp( &lmod, mtype, ops[i].attr, 0 );
1006 for (
int j = 0; j < ops[i].values.count(); ++j ) {
1007 addModOp( &lmod, mtype, ops[i].attr, &ops[i].values[j] );
1012 ldap_modify_ext_s( ld, dn.toString().toUtf8().data(), lmod, serverctrls, clientctrls );
1014 ldap_controls_free( serverctrls );
1015 ldap_controls_free( clientctrls );
1016 ldap_mods_free( lmod, 1 );
1022 Q_ASSERT( d->mConnection );
1023 LDAP *ld = (LDAP *) d->mConnection->handle();
1026 LDAPControl **serverctrls = 0, **clientctrls = 0;
1027 createControls( &serverctrls, d->mServerCtrls );
1028 createControls( &serverctrls, d->mClientCtrls );
1030 int vallen = value.
size();
1032 berval = (BerValue *) malloc(
sizeof( BerValue ) );
1033 berval -> bv_val = (
char *) malloc( vallen );
1034 berval -> bv_len = vallen;
1035 memcpy( berval -> bv_val, value.
data(), vallen );
1037 int retval = ldap_compare_ext( ld, dn.toString().toUtf8().data(), attr.
toUtf8().
data(), berval,
1038 serverctrls, clientctrls, &msgid );
1040 ber_bvfree( berval );
1041 ldap_controls_free( serverctrls );
1042 ldap_controls_free( clientctrls );
1044 if ( retval == 0 ) {
1052 Q_ASSERT( d->mConnection );
1053 LDAP *ld = (LDAP *) d->mConnection->handle();
1055 LDAPControl **serverctrls = 0, **clientctrls = 0;
1056 createControls( &serverctrls, d->mServerCtrls );
1057 createControls( &serverctrls, d->mClientCtrls );
1059 int vallen = value.
size();
1061 berval = (BerValue *) malloc(
sizeof( BerValue ) );
1062 berval -> bv_val = (
char *) malloc( vallen );
1063 berval -> bv_len = vallen;
1064 memcpy( berval -> bv_val, value.
data(), vallen );
1066 int retval = ldap_compare_ext_s( ld, dn.toString().toUtf8().data(), attr.
toUtf8().
data(), berval,
1067 serverctrls, clientctrls );
1069 ber_bvfree( berval );
1070 ldap_controls_free( serverctrls );
1071 ldap_controls_free( clientctrls );
1078 Q_ASSERT( d->mConnection );
1079 #if defined(HAVE_LDAP_EXTENDED_OPERATION) && defined(HAVE_LDAP_EXTENDED_OPERATION_PROTOTYPE)
1080 LDAP *ld = (LDAP *) d->mConnection->handle();
1083 LDAPControl **serverctrls = 0, **clientctrls = 0;
1084 createControls( &serverctrls, d->mServerCtrls );
1085 createControls( &serverctrls, d->mClientCtrls );
1087 int vallen = data.
size();
1089 berval = (BerValue *) malloc(
sizeof( BerValue ) );
1090 berval -> bv_val = (
char *) malloc( vallen );
1091 berval -> bv_len = vallen;
1092 memcpy( berval -> bv_val, data.
data(), vallen );
1094 int retval = ldap_extended_operation( ld, oid.
toUtf8().
data(), berval,
1095 serverctrls, clientctrls, &msgid );
1097 ber_bvfree( berval );
1098 ldap_controls_free( serverctrls );
1099 ldap_controls_free( clientctrls );
1101 if ( retval == 0 ) {
1106 kError() <<
"Your LDAP client libraries don't support extended operations.";
1113 #if defined(HAVE_LDAP_EXTENDED_OPERATION) && defined(HAVE_LDAP_EXTENDED_OPERATION_PROTOTYPE)
1114 Q_ASSERT( d->mConnection );
1115 LDAP *ld = (LDAP *) d->mConnection->handle();
1119 LDAPControl **serverctrls = 0, **clientctrls = 0;
1120 createControls( &serverctrls, d->mServerCtrls );
1121 createControls( &serverctrls, d->mClientCtrls );
1123 int vallen = data.
size();
1125 berval = (BerValue *) malloc(
sizeof( BerValue ) );
1126 berval -> bv_val = (
char *) malloc( vallen );
1127 berval -> bv_len = vallen;
1128 memcpy( berval -> bv_val, data.
data(), vallen );
1130 int retval = ldap_extended_operation_s( ld, oid.
toUtf8().
data(), berval,
1131 serverctrls, clientctrls, &retoid, &retdata );
1133 ber_bvfree( berval );
1134 ber_bvfree( retdata );
1136 ldap_controls_free( serverctrls );
1137 ldap_controls_free( clientctrls );
1141 kError() <<
"Your LDAP client libraries don't support extended operations.";
1148 Q_ASSERT( d->mConnection );
1149 LDAP *ld = (LDAP *) d->mConnection->handle();
1151 LDAPControl **serverctrls = 0, **clientctrls = 0;
1152 createControls( &serverctrls, d->mServerCtrls );
1153 createControls( &serverctrls, d->mClientCtrls );
1155 int retval = ldap_abandon_ext( ld,
id, serverctrls, clientctrls );
1157 ldap_controls_free( serverctrls );
1158 ldap_controls_free( clientctrls );
1165 Q_ASSERT( d->mConnection );
1166 LDAP *ld = (LDAP *) d->mConnection->handle();
1179 timeout = kldap_timeout_value( msecs, stopWatch.
elapsed() );
1180 kDebug() <<
"(" <<
id <<
"," << msecs
1181 <<
"): Waiting" << timeout
1182 <<
"msecs for result. Attempt #" << attempt++;
1184 tv.tv_sec = timeout / 1000;
1185 tv.tv_usec = ( timeout % 1000 ) * 1000;
1188 rescode = ldap_result( ld,
id, 0, timeout < 0 ? 0 : &tv, &msg );
1189 if ( rescode == -1 ) {
1193 if ( rescode != 0 ) {
1195 return d->processResult( rescode, msg );
1197 }
while ( msecs == -1 || stopWatch.
elapsed() < msecs );
1206 kError() <<
"LDAP support not compiled";
1212 kError() <<
"LDAP support not compiled";
1219 kError() <<
"LDAP support not compiled";
1225 kError() <<
"LDAP support not compiled";
1231 kError() <<
"LDAP support not compiled";
1237 kError() <<
"LDAP support not compiled";
1243 kError() <<
"LDAP support not compiled";
1248 const QString &newSuperior,
bool deleteold )
1250 kError() <<
"LDAP support not compiled";
1255 const QString &newSuperior,
bool deleteold )
1257 kError() <<
"LDAP support not compiled";
1263 kError() <<
"LDAP support not compiled";
1269 kError() <<
"LDAP support not compiled";
1275 kError() <<
"LDAP support not compiled";
1281 kError() <<
"LDAP support not compiled";
1287 kError() <<
"LDAP support not compiled";
1293 kError() <<
"LDAP support not compiled";
1299 kError() <<
"LDAP support not compiled";
1305 kError() <<
"LDAP support not compiled";
1311 kError() <<
"LDAP support not compiled";
1317 kError() <<
"LDAP support not compiled";
Authenticate via login and password.
QString mech() const
Returns the mech of the LDAP connection.
Azthenticate with the SASL framework.
void setCritical(bool critical)
Sets the control's criticality.
int modify(const LdapDN &dn, const ModOps &ops)
Starts a modify operation on the given DN.
void setConnection(LdapConnection &conn)
Sets the connection object.
int exop_s(const QString &oid, const QByteArray &data)
Performs an extended operation specified with oid and data.
int del(const LdapDN &dn)
Starts a delete operation on the given DN.
QByteArray serverCred() const
Returns the server response for a bind request (result returned RES_BIND).
LdapControls clientControls() const
Returns the client controls (which set by setClientControls()).
LdapObject object() const
Returns the result object if result() returned RES_SEARCH_ENTRY.
All levels below the url's level.
LdapControls serverControls() const
Returns the server controls (which set by setServerControls()).
const T & at(int i) const
LdapControls controls() const
Returns the server controls from the returned ldap message (grabbed by result()). ...
LdapConnection & connection()
Returns the connection object.
int exop(const QString &oid, const QByteArray &data)
Starts an extended operation specified with oid and data.
int bind_s(SASL_Callback_Proc *saslproc=NULL, void *data=NULL)
Binds to the server which specified in the connection object.
int modify_s(const LdapDN &dn, const ModOps &ops)
Performs a modify operation on the given DN.
void setOid(const QString &oid)
Sets the control's OID.
Scope
Describes the scope of the LDAP url.
int rename_s(const LdapDN &dn, const QString &newRdn, const QString &newSuperior, bool deleteold=true)
Performs a modrdn operation on given DN, changing its RDN to newRdn, changing its parent to newSuperi...
int count(const T &value) const
QByteArray extendedData() const
Returns the data from the extended operation response (result returned RES_EXTENDED).
void append(const T &value)
QString fromUtf8(const char *str, int size)
int bind(const QByteArray &creds=QByteArray(), SASL_Callback_Proc *saslproc=NULL, void *data=NULL)
Binds to the server which specified in the connection object.
A class that contains LDAP server connection settings.
int del_s(const LdapDN &dn)
Deletes the given DN.
void setServerControls(const LdapControls &ctrls)
Sets the server controls which will sent with each operation.
int compare(const LdapDN &dn, const QString &attr, const QByteArray &value)
Starts a compare operation on the given DN, compares the specified attribute with the given value...
The level of the url and the one below.
This class represents an LDAP Object.
int add(const LdapObject &object)
Starts an addition operation.
This class represents a connection to an LDAP server.
QByteArray extendedOid() const
Returns the OID of the extended operation response (result returned RES_EXTENDED).
void setValue(const QByteArray &value)
Sets the control's value.
QList< QByteArray > referrals() const
This function returns the referral strings from the parsed message (if any).
Only the same level as the url.
QString password() const
Returns the password of the LDAP connection.
QByteArray toLatin1() const
char * toString(const T &value)
int rename(const LdapDN &dn, const QString &newRdn, const QString &newSuperior, bool deleteold=true)
Starts a modrdn operation on given DN, changing its RDN to newRdn, changing its parent to newSuperior...
void setClientControls(const LdapControls &ctrls)
Sets the client controls which will sent with each operation.
This class represents an LDAP Control.
int waitForResult(int id, int msecs=-1)
Waits for up to msecs milliseconds for a result message from the LDAP server.
int compare_s(const LdapDN &dn, const QString &attr, const QByteArray &value)
Performs a compare operation on the given DN, compares the specified attribute with the given value...
QString bindDn() const
Returns the bindDn of the LDAP connection.
QString fromLatin1(const char *str, int size)
int add_s(const LdapObject &object)
Adds the specified object to the LDAP database.
int search(const LdapDN &base, LdapUrl::Scope scope, const QString &filter, const QStringList &attrs)
Starts a search operation with the given base DN, scope, filter and result attributes.
QString matchedDn() const
The server might supply a matched DN string in the message indicating how much of a name in a request...
QString realm() const
Returns the realm of the LDAP connection.
Auth auth() const
Returns the authentication method of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.
int abandon(int id)
Abandons a long-running operation.
QByteArray toUtf8() const