8#include "ldapoperation.h"
9#include "kldap_config.h"
11#include "ldap_core_debug.h"
13#include <QElapsedTimer>
31#include "w32-ldap-help.h"
37using namespace KLDAPCore;
40static void extractControls(
LdapControls &ctrls, LDAPControl **pctrls);
47static int kldap_timeout_value(
int msecs,
int elapsed)
53 int timeout = msecs - elapsed;
54 return timeout < 0 ? 0 : timeout;
60 LdapOperationPrivate();
61 ~LdapOperationPrivate();
63 int processResult(
int rescode, LDAPMessage *msg);
64 int bind(
const QByteArray &creds, SASL_Callback_Proc *saslproc,
void *data,
bool async);
76LdapOperation::LdapOperation()
77 : d(new LdapOperationPrivate)
79 d->mConnection =
nullptr;
83 : d(new LdapOperationPrivate)
88LdapOperation::~LdapOperation() =
default;
92 d->mConnection = &conn;
97 return *d->mConnection;
102 d->mClientCtrls = ctrls;
107 d->mServerCtrls = ctrls;
112 return d->mClientCtrls;
117 return d->mServerCtrls;
142 return d->mMatchedDn;
147 return d->mReferrals;
152 return d->mServerCred;
155LdapOperation::LdapOperationPrivate::LdapOperationPrivate() =
default;
157LdapOperation::LdapOperationPrivate::~LdapOperationPrivate() =
default;
161static int kldap_sasl_interact(sasl_interact_t *interact, LdapOperation::SASL_Data *data)
164 for (; interact->id != SASL_CB_LIST_END; interact++) {
165 switch (interact->id) {
166 case SASL_CB_GETREALM:
167 data->creds.fields |= LdapOperation::SASL_Realm;
169 case SASL_CB_AUTHNAME:
170 data->creds.fields |= LdapOperation::SASL_Authname;
173 data->creds.fields |= LdapOperation::SASL_Password;
176 data->creds.fields |= LdapOperation::SASL_Authzid;
181 if ((retval = data->proc(data->creds, data->data))) {
188 while (interact->id != SASL_CB_LIST_END) {
190 switch (interact->id) {
191 case SASL_CB_GETREALM:
192 value = data->creds.realm;
193 qCDebug(LDAP_CORE_LOG) <<
"SASL_REALM=" << value;
195 case SASL_CB_AUTHNAME:
196 value = data->creds.authname;
197 qCDebug(LDAP_CORE_LOG) <<
"SASL_AUTHNAME=" << value;
200 value = data->creds.password;
201 qCDebug(LDAP_CORE_LOG) <<
"SASL_PASSWD=[hidden]";
204 value = data->creds.authzid;
205 qCDebug(LDAP_CORE_LOG) <<
"SASL_AUTHZID=" << value;
209 interact->result =
nullptr;
213 interact->len = strlen((
const char *)interact->result);
217 return KLDAP_SUCCESS;
220int LdapOperation::LdapOperationPrivate::bind(
const QByteArray &creds, SASL_Callback_Proc *saslproc,
void *data,
bool async)
222 Q_ASSERT(mConnection);
223 LDAP *ld = (LDAP *)mConnection->
handle();
225 server = mConnection->
server();
229 if (server.
auth() == LdapServer::SASL) {
231 auto saslconn = (sasl_conn_t *)mConnection->
saslHandle();
232 sasl_interact_t *client_interact =
nullptr;
233 const char *out =
nullptr;
235 const char *mechusing =
nullptr;
237 struct berval *scred;
243 mech = QStringLiteral(
"DIGEST-MD5");
247 sasldata.proc = saslproc;
248 sasldata.
data = data;
249 sasldata.creds.fields = 0;
250 sasldata.creds.realm = server.
realm();
251 sasldata.creds.authname = server.
user();
252 sasldata.creds.authzid = server.
bindDn();
253 sasldata.creds.password = server.
password();
258 saslresult = sasl_client_start(saslconn, mech.
toLatin1().
constData(), &client_interact, &out, &outlen, &mechusing);
260 if (saslresult == SASL_INTERACT) {
261 if (kldap_sasl_interact(client_interact, &sasldata) != KLDAP_SUCCESS) {
262 return KLDAP_SASL_ERROR;
265 qCDebug(LDAP_CORE_LOG) <<
"sasl_client_start mech: " << mechusing <<
" outlen " << outlen <<
" result: " << saslresult;
266 }
while (saslresult == SASL_INTERACT);
267 if (saslresult != SASL_CONTINUE && saslresult != SASL_OK) {
268 return KLDAP_SASL_ERROR;
271 qCDebug(LDAP_CORE_LOG) <<
"sasl_client_step";
273 saslresult = sasl_client_step(saslconn, sdata.
data(), sdata.
size(), &client_interact, &out, &outlen);
274 if (saslresult == SASL_INTERACT) {
275 if (kldap_sasl_interact(client_interact, &sasldata) != KLDAP_SUCCESS) {
276 return KLDAP_SASL_ERROR;
279 }
while (saslresult == SASL_INTERACT);
280 qCDebug(LDAP_CORE_LOG) <<
"sasl_client_step result" << saslresult;
281 if (saslresult != SASL_CONTINUE && saslresult != SASL_OK) {
282 return KLDAP_SASL_ERROR;
286 ccred.bv_val = (
char *)out;
287 ccred.bv_len = outlen;
290 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind";
296 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind msgid" << ret;
298 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind_s";
300 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind_s ret" << ret;
302 sdata =
QByteArray(scred->bv_val, scred->bv_len);
307 }
while (!async && ret == KLDAP_SASL_BIND_IN_PROGRESS);
309 qCritical() <<
"SASL authentication is not available "
310 <<
"(re-compile kldap with cyrus-sasl and OpenLDAP development).";
311 return KLDAP_SASL_ERROR;
317 if (server.
auth() == LdapServer::Simple) {
321 ccred.bv_val = pass.
data();
322 ccred.bv_len = pass.
size();
323 qCDebug(LDAP_CORE_LOG) <<
"binding to server, bindname: " << bindname <<
" password: *****";
326 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind (simple)";
329 ret = ldap_sasl_bind(ld, bindname.
data(),
nullptr, &ccred,
nullptr,
nullptr, &msgid);
334 ret = ldap_simple_bind(ld, bindname.
data(), pass.
data());
337 qCDebug(LDAP_CORE_LOG) <<
"ldap_sasl_bind_s (simple)";
339 ret = ldap_sasl_bind_s(ld, bindname.
data(),
nullptr, &ccred,
nullptr,
nullptr,
nullptr);
341 ret = ldap_simple_bind_s(ld, bindname.
data(), pass.
data());
348int LdapOperation::LdapOperationPrivate::processResult(
int rescode, LDAPMessage *msg)
352 LDAP *ld = (LDAP *)mConnection->handle();
354 qCDebug(LDAP_CORE_LOG) <<
"rescode: " << rescode;
356 case RES_SEARCH_ENTRY: {
361 struct berval **bvals;
365 char *dn = ldap_get_dn(ld, msg);
370 name = ldap_first_attribute(ld, msg, &entry);
371 while (name !=
nullptr) {
373 bvals = ldap_get_values_len(ld, msg, name);
375 for (
int i = 0; bvals[i] !=
nullptr; i++) {
376 char *val = bvals[i]->bv_val;
377 unsigned long len = bvals[i]->bv_len;
380 ldap_value_free_len(bvals);
387 name = ldap_next_attribute(ld, msg, entry);
390 mObject.setAttributes(attrs);
393 case RES_SEARCH_REFERENCE:
399 struct berval *retdata;
400 retval = ldap_parse_extended_result(ld, msg, &retoid, &retdata, 0);
401 if (retval != KLDAP_SUCCESS) {
407 ldap_memfree(retoid);
412 struct berval *servercred =
nullptr;
415 retval = ldap_parse_sasl_bind_result(ld, msg, &servercred, 0);
417 retval = KLDAP_SUCCESS;
419 if (retval != KLDAP_SUCCESS && retval != KLDAP_SASL_BIND_IN_PROGRESS) {
420 qCDebug(LDAP_CORE_LOG) <<
"RES_BIND error: " << retval;
424 qCDebug(LDAP_CORE_LOG) <<
"RES_BIND rescode" << rescode <<
"retval:" << retval;
426 mServerCred =
QByteArray(servercred->bv_val, servercred->bv_len);
427 ber_bvfree(servercred);
434 LDAPControl **serverctrls =
nullptr;
435 char *matcheddn =
nullptr;
436 char *errmsg =
nullptr;
439 retval = ldap_parse_result(ld, msg, &errcodep, &matcheddn, &errmsg, &referralsp, &serverctrls, 0);
440 qCDebug(LDAP_CORE_LOG) <<
"rescode" << rescode <<
"retval:" << retval <<
"matcheddn:" << matcheddn <<
"errcode:" << errcodep <<
"errmsg:" << errmsg;
441 if (retval != KLDAP_SUCCESS) {
447 extractControls(mControls, serverctrls);
448 ldap_controls_free(serverctrls);
452 char **tmp = referralsp;
458 ldap_memfree((
char *)referralsp);
463 ldap_memfree(matcheddn);
466 ldap_memfree(errmsg);
476static void addModOp(LDAPMod ***pmods,
int mod_type,
const QString &attr,
const QByteArray *value =
nullptr)
487 if (mods ==
nullptr) {
488 mods = (LDAPMod **)malloc(2 *
sizeof(LDAPMod *));
489 mods[0] = (LDAPMod *)malloc(
sizeof(LDAPMod));
491 memset(mods[0], 0,
sizeof(LDAPMod));
493 while (mods[i] !=
nullptr && (strcmp(attr.
toUtf8().
constData(), mods[i]->mod_type) != 0 || (mods[i]->mod_op & ~LDAP_MOD_BVALUES) != mod_type)) {
497 if (mods[i] ==
nullptr) {
498 mods = (LDAPMod **)realloc(mods, (i + 2) *
sizeof(LDAPMod *));
499 if (mods ==
nullptr) {
500 qCritical() <<
"addModOp: realloc";
503 mods[i + 1] =
nullptr;
504 mods[i] = (LDAPMod *)malloc(
sizeof(LDAPMod));
505 memset(mods[i], 0,
sizeof(LDAPMod));
509 mods[i]->mod_op = mod_type | LDAP_MOD_BVALUES;
510 if (mods[i]->mod_type ==
nullptr) {
516 if (value ==
nullptr) {
520 int vallen = value->
size();
522 berval = (BerValue *)malloc(
sizeof(BerValue));
523 berval->bv_len = vallen;
525 berval->bv_val = (
char *)malloc(vallen);
526 memcpy(berval->bv_val, value->
data(), vallen);
528 berval->bv_val =
nullptr;
531 if (mods[i]->mod_vals.modv_bvals ==
nullptr) {
532 mods[i]->mod_vals.modv_bvals = (BerValue **)malloc(
sizeof(BerValue *) * 2);
533 mods[i]->mod_vals.modv_bvals[0] = berval;
534 mods[i]->mod_vals.modv_bvals[1] =
nullptr;
538 while (mods[i]->mod_vals.modv_bvals[j] !=
nullptr) {
541 mods[i]->mod_vals.modv_bvals = (BerValue **)realloc(mods[i]->mod_vals.modv_bvals, (j + 2) *
sizeof(BerValue *));
542 if (mods[i]->mod_vals.modv_bvals ==
nullptr) {
543 qCritical() <<
"addModOp: realloc";
547 mods[i]->mod_vals.modv_bvals[j] = berval;
548 mods[i]->mod_vals.modv_bvals[j + 1] =
nullptr;
549 qCDebug(LDAP_CORE_LOG) << j <<
". new bervalue";
553static void addControlOp(LDAPControl ***pctrls,
const QString &oid,
const QByteArray &value,
bool critical)
556 auto ctrl = (LDAPControl *)malloc(
sizeof(LDAPControl));
560 qCDebug(LDAP_CORE_LOG) <<
"oid:'" << oid <<
"' val: '" << value <<
"'";
561 int vallen = value.size();
562 ctrl->ldctl_value.bv_len = vallen;
564 ctrl->ldctl_value.bv_val = (
char *)malloc(vallen);
565 memcpy(ctrl->ldctl_value.bv_val, value.data(), vallen);
567 ctrl->ldctl_value.bv_val =
nullptr;
569 ctrl->ldctl_iscritical = critical;
574 if (ctrls ==
nullptr) {
575 ctrls = (LDAPControl **)malloc(2 *
sizeof(LDAPControl *));
579 while (ctrls[i] !=
nullptr) {
582 ctrls[i + 1] =
nullptr;
583 ctrls = (LDAPControl **)realloc(ctrls, (i + 2) *
sizeof(LDAPControl *));
589static void createControls(LDAPControl ***pctrls,
const LdapControls &ctrls)
591 for (
int i = 0; i < ctrls.
count(); ++i) {
592 addControlOp(pctrls, ctrls[i].oid(), ctrls[i].value(), ctrls[i].critical());
596static void extractControls(
LdapControls &ctrls, LDAPControl **pctrls)
602 LDAPControl *ctrl = pctrls[i];
613 return d->bind(creds, saslproc, data,
true);
618 return d->bind(
QByteArray(), saslproc, data,
false);
623 Q_ASSERT(d->mConnection);
624 LDAP *ld = (LDAP *)d->mConnection->handle();
626 char **attrs =
nullptr;
629 LDAPControl **serverctrls =
nullptr;
630 LDAPControl **clientctrls =
nullptr;
631 createControls(&serverctrls, d->mServerCtrls);
632 createControls(&serverctrls, d->mClientCtrls);
634 int count = attributes.
count();
636 attrs =
static_cast<char **
>(malloc((count + 1) *
sizeof(
char *)));
637 for (
int i = 0; i < count; i++) {
638 attrs[i] = strdup(attributes.
at(i).toUtf8().constData());
640 attrs[count] =
nullptr;
643 int lscope = LDAP_SCOPE_BASE;
646 lscope = LDAP_SCOPE_BASE;
649 lscope = LDAP_SCOPE_ONELEVEL;
652 lscope = LDAP_SCOPE_SUBTREE;
656 qCDebug(LDAP_CORE_LOG) <<
"asyncSearch() base=\"" << base.toString() <<
"\" scope=" << (int)scope <<
"filter=\"" << filter <<
"\" attrs=" << attributes;
657 int retval = ldap_search_ext(ld,
666 d->mConnection->sizeLimit(),
669 ldap_controls_free(serverctrls);
670 ldap_controls_free(clientctrls);
674 for (
int i = 0; i < count; i++) {
688 Q_ASSERT(d->mConnection);
689 LDAP *ld = (LDAP *)d->mConnection->handle();
692 LDAPMod **lmod =
nullptr;
694 LDAPControl **serverctrls =
nullptr;
695 LDAPControl **clientctrls =
nullptr;
696 createControls(&serverctrls, d->mServerCtrls);
697 createControls(&serverctrls, d->mClientCtrls);
702 addModOp(&lmod, 0, attr, &(*it2));
706 int retval = ldap_add_ext(ld,
object.dn().
toString().toUtf8().data(), lmod, serverctrls, clientctrls, &msgid);
708 ldap_controls_free(serverctrls);
709 ldap_controls_free(clientctrls);
710 ldap_mods_free(lmod, 1);
719 Q_ASSERT(d->mConnection);
720 LDAP *ld = (LDAP *)d->mConnection->handle();
722 LDAPMod **lmod =
nullptr;
724 LDAPControl **serverctrls =
nullptr;
725 LDAPControl **clientctrls =
nullptr;
726 createControls(&serverctrls, d->mServerCtrls);
727 createControls(&serverctrls, d->mClientCtrls);
732 addModOp(&lmod, 0, attr, &(*it2));
736 int retval = ldap_add_ext_s(ld,
object.dn().
toString().toUtf8().data(), lmod, serverctrls, clientctrls);
738 ldap_controls_free(serverctrls);
739 ldap_controls_free(clientctrls);
740 ldap_mods_free(lmod, 1);
746 Q_ASSERT(d->mConnection);
747 LDAP *ld = (LDAP *)d->mConnection->handle();
750 LDAPMod **lmod =
nullptr;
752 LDAPControl **serverctrls =
nullptr;
753 LDAPControl **clientctrls =
nullptr;
754 createControls(&serverctrls, d->mServerCtrls);
755 createControls(&serverctrls, d->mClientCtrls);
757 for (
int i = 0; i < ops.count(); ++i) {
758 for (
int j = 0; j < ops[i].values.count(); ++j) {
759 addModOp(&lmod, 0, ops[i].attr, &ops[i].values[j]);
763 int retval = ldap_add_ext(ld, dn.toString().
toUtf8().
data(), lmod, serverctrls, clientctrls, &msgid);
765 ldap_controls_free(serverctrls);
766 ldap_controls_free(clientctrls);
767 ldap_mods_free(lmod, 1);
776 Q_ASSERT(d->mConnection);
777 LDAP *ld = (LDAP *)d->mConnection->handle();
779 LDAPMod **lmod =
nullptr;
781 LDAPControl **serverctrls =
nullptr;
782 LDAPControl **clientctrls =
nullptr;
783 createControls(&serverctrls, d->mServerCtrls);
784 createControls(&serverctrls, d->mClientCtrls);
786 for (
int i = 0; i < ops.count(); ++i) {
787 for (
int j = 0; j < ops[i].values.count(); ++j) {
788 addModOp(&lmod, 0, ops[i].attr, &ops[i].values[j]);
791 qCDebug(LDAP_CORE_LOG) << dn.toString();
792 int retval = ldap_add_ext_s(ld, dn.toString().
toUtf8().
data(), lmod, serverctrls, clientctrls);
794 ldap_controls_free(serverctrls);
795 ldap_controls_free(clientctrls);
796 ldap_mods_free(lmod, 1);
802 Q_ASSERT(d->mConnection);
803 LDAP *ld = (LDAP *)d->mConnection->handle();
807 LDAPControl **serverctrls =
nullptr;
808 LDAPControl **clientctrls =
nullptr;
809 createControls(&serverctrls, d->mServerCtrls);
810 createControls(&serverctrls, d->mClientCtrls);
812 int retval = ldap_rename(ld,
821 ldap_controls_free(serverctrls);
822 ldap_controls_free(clientctrls);
832 Q_ASSERT(d->mConnection);
833 LDAP *ld = (LDAP *)d->mConnection->handle();
835 LDAPControl **serverctrls =
nullptr;
836 LDAPControl **clientctrls =
nullptr;
837 createControls(&serverctrls, d->mServerCtrls);
838 createControls(&serverctrls, d->mClientCtrls);
840 int retval = ldap_rename_s(ld,
848 ldap_controls_free(serverctrls);
849 ldap_controls_free(clientctrls);
856 Q_ASSERT(d->mConnection);
857 LDAP *ld = (LDAP *)d->mConnection->handle();
861 LDAPControl **serverctrls =
nullptr;
862 LDAPControl **clientctrls =
nullptr;
863 createControls(&serverctrls, d->mServerCtrls);
864 createControls(&serverctrls, d->mClientCtrls);
866 int retval = ldap_delete_ext(ld, dn.toString().
toUtf8().
data(), serverctrls, clientctrls, &msgid);
868 ldap_controls_free(serverctrls);
869 ldap_controls_free(clientctrls);
879 Q_ASSERT(d->mConnection);
880 LDAP *ld = (LDAP *)d->mConnection->handle();
882 LDAPControl **serverctrls =
nullptr;
883 LDAPControl **clientctrls =
nullptr;
884 createControls(&serverctrls, d->mServerCtrls);
885 createControls(&serverctrls, d->mClientCtrls);
887 int retval = ldap_delete_ext_s(ld, dn.toString().
toUtf8().
data(), serverctrls, clientctrls);
889 ldap_controls_free(serverctrls);
890 ldap_controls_free(clientctrls);
897 Q_ASSERT(d->mConnection);
898 LDAP *ld = (LDAP *)d->mConnection->handle();
901 LDAPMod **lmod =
nullptr;
903 LDAPControl **serverctrls =
nullptr;
904 LDAPControl **clientctrls =
nullptr;
905 createControls(&serverctrls, d->mServerCtrls);
906 createControls(&serverctrls, d->mClientCtrls);
908 for (
int i = 0; i < ops.count(); ++i) {
910 switch (ops[i].type) {
915 mtype = LDAP_MOD_ADD;
918 mtype = LDAP_MOD_REPLACE;
921 mtype = LDAP_MOD_DELETE;
924 addModOp(&lmod, mtype, ops[i].attr,
nullptr);
925 for (
int j = 0; j < ops[i].values.count(); ++j) {
926 addModOp(&lmod, mtype, ops[i].attr, &ops[i].values[j]);
930 int retval = ldap_modify_ext(ld, dn.toString().
toUtf8().
data(), lmod, serverctrls, clientctrls, &msgid);
932 ldap_controls_free(serverctrls);
933 ldap_controls_free(clientctrls);
934 ldap_mods_free(lmod, 1);
943 Q_ASSERT(d->mConnection);
944 LDAP *ld = (LDAP *)d->mConnection->handle();
946 LDAPMod **lmod =
nullptr;
948 LDAPControl **serverctrls =
nullptr;
949 LDAPControl **clientctrls =
nullptr;
950 createControls(&serverctrls, d->mServerCtrls);
951 createControls(&serverctrls, d->mClientCtrls);
953 for (
int i = 0; i < ops.count(); ++i) {
955 switch (ops[i].type) {
960 mtype = LDAP_MOD_ADD;
963 mtype = LDAP_MOD_REPLACE;
966 mtype = LDAP_MOD_DELETE;
969 addModOp(&lmod, mtype, ops[i].attr,
nullptr);
970 for (
int j = 0; j < ops[i].values.count(); ++j) {
971 addModOp(&lmod, mtype, ops[i].attr, &ops[i].values[j]);
975 int retval = ldap_modify_ext_s(ld, dn.toString().
toUtf8().
data(), lmod, serverctrls, clientctrls);
977 ldap_controls_free(serverctrls);
978 ldap_controls_free(clientctrls);
979 ldap_mods_free(lmod, 1);
985 Q_ASSERT(d->mConnection);
986 LDAP *ld = (LDAP *)d->mConnection->handle();
989 LDAPControl **serverctrls =
nullptr;
990 LDAPControl **clientctrls =
nullptr;
991 createControls(&serverctrls, d->mServerCtrls);
992 createControls(&serverctrls, d->mClientCtrls);
994 int vallen = value.
size();
996 berval = (BerValue *)malloc(
sizeof(BerValue));
997 berval->bv_val = (
char *)malloc(vallen);
998 berval->bv_len = vallen;
999 memcpy(berval->bv_val, value.
data(), vallen);
1001 int retval = ldap_compare_ext(ld, dn.toString().
toUtf8().
data(), attr.
toUtf8().
data(), berval, serverctrls, clientctrls, &msgid);
1004 ldap_controls_free(serverctrls);
1005 ldap_controls_free(clientctrls);
1015 Q_ASSERT(d->mConnection);
1016 LDAP *ld = (LDAP *)d->mConnection->handle();
1018 LDAPControl **serverctrls =
nullptr;
1019 LDAPControl **clientctrls =
nullptr;
1020 createControls(&serverctrls, d->mServerCtrls);
1021 createControls(&serverctrls, d->mClientCtrls);
1023 int vallen = value.
size();
1025 berval = (BerValue *)malloc(
sizeof(BerValue));
1026 berval->bv_val = (
char *)malloc(vallen);
1027 berval->bv_len = vallen;
1028 memcpy(berval->bv_val, value.
data(), vallen);
1030 int retval = ldap_compare_ext_s(ld, dn.toString().
toUtf8().
data(), attr.
toUtf8().
data(), berval, serverctrls, clientctrls);
1033 ldap_controls_free(serverctrls);
1034 ldap_controls_free(clientctrls);
1041 Q_ASSERT(d->mConnection);
1042#if HAVE_LDAP_EXTENDED_OPERATION
1043 LDAP *ld = (LDAP *)d->mConnection->handle();
1046 LDAPControl **serverctrls =
nullptr;
1047 LDAPControl **clientctrls =
nullptr;
1048 createControls(&serverctrls, d->mServerCtrls);
1049 createControls(&serverctrls, d->mClientCtrls);
1051 int vallen = data.
size();
1053 berval = (BerValue *)malloc(
sizeof(BerValue));
1054 berval->bv_val = (
char *)malloc(vallen);
1055 berval->bv_len = vallen;
1056 memcpy(berval->bv_val, data.
data(), vallen);
1058 int retval = ldap_extended_operation(ld, oid.
toUtf8().
data(), berval, serverctrls, clientctrls, &msgid);
1061 ldap_controls_free(serverctrls);
1062 ldap_controls_free(clientctrls);
1069 qCritical() <<
"Your LDAP client libraries don't support extended operations.";
1076#if HAVE_LDAP_EXTENDED_OPERATION_S
1077 Q_ASSERT(d->mConnection);
1078 LDAP *ld = (LDAP *)d->mConnection->handle();
1082 LDAPControl **serverctrls =
nullptr;
1083 LDAPControl **clientctrls =
nullptr;
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_s(ld, oid.
toUtf8().
data(), berval, serverctrls, clientctrls, &retoid, &retdata);
1097 ber_bvfree(retdata);
1099 ldap_controls_free(serverctrls);
1100 ldap_controls_free(clientctrls);
1104 qCritical() <<
"Your LDAP client libraries don't support extended operations.";
1111 Q_ASSERT(d->mConnection);
1112 LDAP *ld = (LDAP *)d->mConnection->handle();
1114 LDAPControl **serverctrls =
nullptr;
1115 LDAPControl **clientctrls =
nullptr;
1116 createControls(&serverctrls, d->mServerCtrls);
1117 createControls(&serverctrls, d->mClientCtrls);
1119 int retval = ldap_abandon_ext(ld,
id, serverctrls, clientctrls);
1121 ldap_controls_free(serverctrls);
1122 ldap_controls_free(clientctrls);
1129 Q_ASSERT(d->mConnection);
1130 LDAP *ld = (LDAP *)d->mConnection->handle();
1142 timeout = kldap_timeout_value(msecs, stopWatch.
elapsed());
1143 qCDebug(LDAP_CORE_LOG) <<
"(" <<
id <<
"," << msecs <<
"): Waiting" << timeout <<
"msecs for result. Attempt #" << attempt++;
1145 tv.tv_sec = timeout / 1000;
1146 tv.tv_usec = (timeout % 1000) * 1000;
1149 int rescode = ldap_result(ld,
id, 0, timeout < 0 ?
nullptr : &tv, &msg);
1150 if (rescode == -1) {
1156 return d->processResult(rescode, msg);
1158 }
while (msecs == -1 || stopWatch.
elapsed() < msecs);
1167 qCritical() <<
"LDAP support not compiled";
1173 qCritical() <<
"LDAP support not compiled";
1179 qCritical() <<
"LDAP support not compiled";
1185 qCritical() <<
"LDAP support not compiled";
1191 qCritical() <<
"LDAP support not compiled";
1197 qCritical() <<
"LDAP support not compiled";
1203 qCritical() <<
"LDAP support not compiled";
1209 qCritical() <<
"LDAP support not compiled";
1215 qCritical() <<
"LDAP support not compiled";
1221 qCritical() <<
"LDAP support not compiled";
1227 qCritical() <<
"LDAP support not compiled";
1233 qCritical() <<
"LDAP support not compiled";
1239 qCritical() <<
"LDAP support not compiled";
1245 qCritical() <<
"LDAP support not compiled";
1251 qCritical() <<
"LDAP support not compiled";
1257 qCritical() <<
"LDAP support not compiled";
1263 qCritical() <<
"LDAP support not compiled";
1269 qCritical() <<
"LDAP support not compiled";
1275 qCritical() <<
"LDAP support not compiled";
This class represents a connection to an LDAP server.
const LdapServer & server() const
Returns the connection parameters which was specified with an LDAP Url or a LdapServer structure.
void * saslHandle() const
Returns the opaqe sasl-library specific SASL object.
void * handle() const
Returns the opaqe client-library specific LDAP object.
This class represents an LDAP Control.
void setValue(const QByteArray &value)
Sets the control's value.
void setOid(const QString &oid)
Sets the control's OID.
void setCritical(bool critical)
Sets the control's criticality.
This class represents an LDAP Object.
This class allows sending an ldap operation (search, rename, modify, delete, compare,...
void setClientControls(const LdapControls &ctrls)
Sets the client controls which will sent with each operation.
int bind_s(SASL_Callback_Proc *saslproc=nullptr, void *data=nullptr)
Binds to the server which specified in the connection object.
QByteArray extendedOid() const
Returns the OID of the extended operation response (result returned RES_EXTENDED).
QString matchedDn() const
The server might supply a matched DN string in the message indicating how much of a name in a request...
QList< QByteArray > referrals() const
This function returns the referral strings from the parsed message (if any).
int abandon(int id)
Abandons a long-running operation.
LdapControls clientControls() const
Returns the client controls (which set by setClientControls()).
QByteArray serverCred() const
Returns the server response for a bind request (result returned RES_BIND).
QByteArray extendedData() const
Returns the data from the extended operation response (result returned RES_EXTENDED).
int modify(const LdapDN &dn, const ModOps &ops)
Starts a modify operation on the given DN.
int exop(const QString &oid, const QByteArray &data)
Starts an extended operation specified with oid and data.
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...
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...
void setConnection(LdapConnection &conn)
Sets the connection object.
void setServerControls(const LdapControls &ctrls)
Sets the server controls which will sent with each operation.
int add(const LdapObject &object)
Starts an addition 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.
LdapObject object() const
Returns the result object if result() returned RES_SEARCH_ENTRY.
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.
int del_s(const LdapDN &dn)
Deletes the given DN.
int bind(const QByteArray &creds=QByteArray(), SASL_Callback_Proc *saslproc=nullptr, void *data=nullptr)
Binds to the server which specified in the connection object.
LdapConnection & connection()
Returns the connection object.
int modify_s(const LdapDN &dn, const ModOps &ops)
Performs a modify operation on the given DN.
int del(const LdapDN &dn)
Starts a delete operation on the given DN.
LdapControls controls() const
Returns the server controls from the returned ldap message (grabbed by result()).
LdapControls serverControls() const
Returns the server controls (which set by setServerControls()).
int exop_s(const QString &oid, const QByteArray &data)
Performs an extended operation specified with oid and data.
int waitForResult(int id, int msecs=-1)
Waits for up to msecs milliseconds for a result message from the LDAP server.
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.
A class that contains LDAP server connection settings.
QString realm() const
Returns the realm of the LDAP connection.
QString password() const
Returns the password of the LDAP connection.
QString bindDn() const
Returns the bindDn of the LDAP connection.
QString user() const
Returns the user of the LDAP connection.
Auth auth() const
Returns the authentication method of the LDAP connection.
QString mech() const
Returns the mech of the LDAP connection.
enum { Base, One, Sub } Scope
Describes the scope of the LDAP url.
char * toString(const EngineQuery &query)
QString name(StandardAction id)
const QList< QKeySequence > & begin()
const QList< QKeySequence > & end()
const char * constData() const const
bool isEmpty() const const
qsizetype size() const const
qint64 elapsed() const const
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
qsizetype count() const const
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
bool isEmpty() const const
qsizetype size() const const
QByteArray toLatin1() const const
QByteArray toUtf8() const const
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)