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