Lines Matching defs:adh

474 	adutils_host_t	*adh;
479 for (adh = host_head; adh != NULL; adh = adh->next) {
480 (void) pthread_mutex_lock(&adh->lock);
481 if (adh->ref == 0 && adh->idletime != 0 &&
482 adh->idletime + ADCONN_TIME < now) {
483 if (adh->ld) {
484 (void) ldap_unbind(adh->ld);
485 adh->ld = NULL;
486 adh->idletime = 0;
487 adh->ref = 0;
490 (void) pthread_mutex_unlock(&adh->lock);
581 open_conn(adutils_host_t *adh, int timeoutsecs)
587 if (adh == NULL)
590 (void) pthread_mutex_lock(&adh->lock);
592 if (!adh->dead && adh->ld != NULL)
596 if (adh->ld != NULL) {
597 (void) ldap_unbind(adh->ld);
598 adh->ld = NULL;
600 adh->num_requests = 0;
602 atomic_inc_64(&adh->generation);
605 adh->ld = ldap_init(adh->host, adh->port);
606 if (adh->ld == NULL) {
608 "%s port %d failed. (%s)", adh->host,
609 adh->port, strerror(errno));
613 (void) ldap_set_option(adh->ld, LDAP_OPT_PROTOCOL_VERSION, &ldversion);
614 (void) ldap_set_option(adh->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
615 (void) ldap_set_option(adh->ld, LDAP_OPT_TIMELIMIT, &zero);
616 (void) ldap_set_option(adh->ld, LDAP_OPT_SIZELIMIT, &zero);
617 (void) ldap_set_option(adh->ld, LDAP_X_OPT_CONNECT_TIMEOUT, &timeoutms);
618 (void) ldap_set_option(adh->ld, LDAP_OPT_RESTART, LDAP_OPT_ON);
620 rc = adutils_set_thread_functions(adh->ld);
623 (void) ldap_unbind(adh->ld);
624 adh->ld = NULL;
628 rc = ldap_sasl_interactive_bind_s(adh->ld, "" /* binddn */,
629 adh->saslmech, NULL, NULL, adh->saslflags, &saslcallback,
633 (void) ldap_unbind(adh->ld);
634 adh->ld = NULL;
636 "%s port %d failed. (%s)", adh->host, adh->port,
642 adh->host, adh->port);
645 if (adh->ld != NULL) {
646 atomic_inc_32(&adh->ref);
647 adh->idletime = time(NULL);
648 adh->dead = 0;
649 (void) pthread_mutex_unlock(&adh->lock);
653 (void) pthread_mutex_unlock(&adh->lock);
665 adutils_host_t *adh = NULL;
686 for (adh = host_head, tries = 0; adh != NULL; adh = adh->next) {
687 if (adh->owner == ad)
703 adh = ad->last_adh;
712 if (adh != NULL && adh->owner == ad && adh->ld != NULL &&
713 !adh->dead)
715 if (adh == NULL || (adh = adh->next) == NULL)
716 adh = host_head;
717 if (adh->owner == ad)
721 ad->last_adh = adh;
725 if (open_conn(adh, timeoutsecs))
726 return (adh);
742 release_conn(adutils_host_t *adh)
746 (void) pthread_mutex_lock(&adh->lock);
747 if (atomic_dec_32_nv(&adh->ref) == 0) {
748 if (adh->owner == NULL)
750 adh->idletime = time(NULL);
752 (void) pthread_mutex_unlock(&adh->lock);
757 delete_ds(NULL, adh->host, adh->port);
959 adutils_host_t *adh = NULL;
965 adh = get_conn(ad);
966 if (adh == NULL)
975 new_state->qadh = adh;
977 new_state->qadh_gen = adh->generation;
1000 msgid2query(adutils_host_t *adh, int msgid,
1009 if (p->qadh != adh || adh->generation != p->qadh_gen)
1137 make_entry(adutils_q_t *q, adutils_host_t *adh, LDAPMessage *search_res,
1151 if ((dn = ldap_get_dn(adh->ld, search_res)) == NULL)
1174 for (attr = ldap_first_attribute(adh->ld, search_res, &ber);
1176 attr = ldap_next_attribute(adh->ld, search_res, ber)) {
1203 for (attr = ldap_first_attribute(adh->ld, search_res, &ber), i = 1;
1206 attr = ldap_next_attribute(adh->ld, search_res, ber)) {
1213 ldap_get_values_len(adh->ld, search_res, attr);
1239 strvalues = ldap_get_values(adh->ld, search_res, attr);
1270 add_entry(adutils_host_t *adh, adutils_q_t *q, LDAPMessage *search_res)
1276 ret = make_entry(q, adh, search_res, &entry);
1317 get_adobject_batch(adutils_host_t *adh, struct timeval *timeout)
1325 (void) pthread_mutex_lock(&adh->lock);
1326 if (adh->dead || adh->num_requests == 0) {
1327 ret = (adh->dead) ? -1 : -2;
1328 (void) pthread_mutex_unlock(&adh->lock);
1333 rc = ldap_result(adh->ld, LDAP_RES_ANY, 0, timeout, &res);
1336 adh->dead = 1;
1338 if (rc == LDAP_RES_SEARCH_RESULT && adh->num_requests > 0)
1339 adh->num_requests--;
1340 if (adh->dead) {
1341 num = adh->num_requests;
1342 (void) pthread_mutex_unlock(&adh->lock);
1351 if (msgid2query(adh, msgid, &query_state, &qid)) {
1358 adh->ld, &res, rc, qid,
1360 (void) pthread_mutex_unlock(&adh->lock);
1371 (void) pthread_mutex_unlock(&adh->lock);
1379 num = adh->num_requests;
1380 (void) pthread_mutex_unlock(&adh->lock);
1392 if (msgid2query(adh, msgid, &query_state, &qid)) {
1399 adh->ld, &res, rc, qid,
1401 (void) pthread_mutex_unlock(&adh->lock);
1409 rc = add_entry(adh, que, res);
1410 (void) pthread_mutex_unlock(&adh->lock);
1421 num = adh->num_requests;
1422 (void) pthread_mutex_unlock(&adh->lock);
1439 (void) pthread_mutex_unlock(&adh->lock);
1446 (void) pthread_mutex_unlock(&adh->lock);