Lines Matching refs:adh

475 	adutils_host_t	*adh;  in adutils_reap_idle_connections()  local
480 for (adh = host_head; adh != NULL; adh = adh->next) { in adutils_reap_idle_connections()
481 (void) pthread_mutex_lock(&adh->lock); in adutils_reap_idle_connections()
482 if (adh->ref == 0 && adh->idletime != 0 && in adutils_reap_idle_connections()
483 adh->idletime + ADCONN_TIME < now) { in adutils_reap_idle_connections()
484 if (adh->ld) { in adutils_reap_idle_connections()
485 (void) ldap_unbind(adh->ld); in adutils_reap_idle_connections()
486 adh->ld = NULL; in adutils_reap_idle_connections()
487 adh->idletime = 0; in adutils_reap_idle_connections()
488 adh->ref = 0; in adutils_reap_idle_connections()
491 (void) pthread_mutex_unlock(&adh->lock); in adutils_reap_idle_connections()
582 open_conn(adutils_host_t *adh, int timeoutsecs) in open_conn() argument
588 if (adh == NULL) in open_conn()
591 (void) pthread_mutex_lock(&adh->lock); in open_conn()
593 if (!adh->dead && adh->ld != NULL) in open_conn()
597 if (adh->ld != NULL) { in open_conn()
598 (void) ldap_unbind(adh->ld); in open_conn()
599 adh->ld = NULL; in open_conn()
601 adh->num_requests = 0; in open_conn()
603 atomic_inc_64(&adh->generation); in open_conn()
606 adh->ld = ldap_init(adh->host, adh->port); in open_conn()
607 if (adh->ld == NULL) { in open_conn()
609 "%s port %d failed. (%s)", adh->host, in open_conn()
610 adh->port, strerror(errno)); in open_conn()
614 (void) ldap_set_option(adh->ld, LDAP_OPT_PROTOCOL_VERSION, &ldversion); in open_conn()
615 (void) ldap_set_option(adh->ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF); in open_conn()
616 (void) ldap_set_option(adh->ld, LDAP_OPT_TIMELIMIT, &zero); in open_conn()
617 (void) ldap_set_option(adh->ld, LDAP_OPT_SIZELIMIT, &zero); in open_conn()
618 (void) ldap_set_option(adh->ld, LDAP_X_OPT_CONNECT_TIMEOUT, &timeoutms); in open_conn()
619 (void) ldap_set_option(adh->ld, LDAP_OPT_RESTART, LDAP_OPT_ON); in open_conn()
621 rc = adutils_set_thread_functions(adh->ld); in open_conn()
624 (void) ldap_unbind(adh->ld); in open_conn()
625 adh->ld = NULL; in open_conn()
629 rc = ldap_sasl_interactive_bind_s(adh->ld, "" /* binddn */, in open_conn()
630 adh->saslmech, NULL, NULL, adh->saslflags, &saslcallback, in open_conn()
635 "%s port %d failed. (%s)", adh->host, adh->port, in open_conn()
637 ldap_perror(adh->ld, adh->host); in open_conn()
638 (void) ldap_unbind(adh->ld); in open_conn()
639 adh->ld = NULL; in open_conn()
644 adh->host, adh->port); in open_conn()
647 if (adh->ld != NULL) { in open_conn()
648 atomic_inc_32(&adh->ref); in open_conn()
649 adh->idletime = time(NULL); in open_conn()
650 adh->dead = 0; in open_conn()
651 (void) pthread_mutex_unlock(&adh->lock); in open_conn()
655 (void) pthread_mutex_unlock(&adh->lock); in open_conn()
667 adutils_host_t *adh = NULL; in get_conn() local
688 for (adh = host_head, tries = 0; adh != NULL; adh = adh->next) { in get_conn()
689 if (adh->owner == ad) in get_conn()
705 adh = ad->last_adh; in get_conn()
714 if (adh != NULL && adh->owner == ad && adh->ld != NULL && in get_conn()
715 !adh->dead) in get_conn()
717 if (adh == NULL || (adh = adh->next) == NULL) in get_conn()
718 adh = host_head; in get_conn()
719 if (adh->owner == ad) in get_conn()
723 ad->last_adh = adh; in get_conn()
727 if (open_conn(adh, timeoutsecs)) in get_conn()
728 return (adh); in get_conn()
744 release_conn(adutils_host_t *adh) in release_conn() argument
748 (void) pthread_mutex_lock(&adh->lock); in release_conn()
749 if (atomic_dec_32_nv(&adh->ref) == 0) { in release_conn()
750 if (adh->owner == NULL) in release_conn()
752 adh->idletime = time(NULL); in release_conn()
754 (void) pthread_mutex_unlock(&adh->lock); in release_conn()
759 delete_ds(NULL, adh->host, adh->port); in release_conn()
961 adutils_host_t *adh = NULL; in adutils_lookup_batch_start() local
967 adh = get_conn(ad); in adutils_lookup_batch_start()
968 if (adh == NULL) in adutils_lookup_batch_start()
977 new_state->qadh = adh; in adutils_lookup_batch_start()
979 new_state->qadh_gen = adh->generation; in adutils_lookup_batch_start()
1002 msgid2query(adutils_host_t *adh, int msgid, in msgid2query() argument
1011 if (p->qadh != adh || adh->generation != p->qadh_gen) in msgid2query()
1139 make_entry(adutils_q_t *q, adutils_host_t *adh, LDAPMessage *search_res, in make_entry() argument
1153 if ((dn = ldap_get_dn(adh->ld, search_res)) == NULL) in make_entry()
1176 for (attr = ldap_first_attribute(adh->ld, search_res, &ber); in make_entry()
1178 attr = ldap_next_attribute(adh->ld, search_res, ber)) { in make_entry()
1205 for (attr = ldap_first_attribute(adh->ld, search_res, &ber), i = 1; in make_entry()
1208 attr = ldap_next_attribute(adh->ld, search_res, ber)) { in make_entry()
1215 ldap_get_values_len(adh->ld, search_res, attr); in make_entry()
1241 strvalues = ldap_get_values(adh->ld, search_res, attr); in make_entry()
1272 add_entry(adutils_host_t *adh, adutils_q_t *q, LDAPMessage *search_res) in add_entry() argument
1278 ret = make_entry(q, adh, search_res, &entry); in add_entry()
1319 get_adobject_batch(adutils_host_t *adh, struct timeval *timeout) in get_adobject_batch() argument
1327 (void) pthread_mutex_lock(&adh->lock); in get_adobject_batch()
1328 if (adh->dead || adh->num_requests == 0) { in get_adobject_batch()
1329 ret = (adh->dead) ? -1 : -2; in get_adobject_batch()
1330 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1335 rc = ldap_result(adh->ld, LDAP_RES_ANY, 0, timeout, &res); in get_adobject_batch()
1338 adh->dead = 1; in get_adobject_batch()
1340 if (rc == LDAP_RES_SEARCH_RESULT && adh->num_requests > 0) in get_adobject_batch()
1341 adh->num_requests--; in get_adobject_batch()
1342 if (adh->dead) { in get_adobject_batch()
1343 num = adh->num_requests; in get_adobject_batch()
1344 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1353 if (msgid2query(adh, msgid, &query_state, &qid)) { in get_adobject_batch()
1360 adh->ld, &res, rc, qid, in get_adobject_batch()
1362 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1373 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1381 num = adh->num_requests; in get_adobject_batch()
1382 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1394 if (msgid2query(adh, msgid, &query_state, &qid)) { in get_adobject_batch()
1401 adh->ld, &res, rc, qid, in get_adobject_batch()
1403 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1411 rc = add_entry(adh, que, res); in get_adobject_batch()
1412 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1423 num = adh->num_requests; in get_adobject_batch()
1424 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1441 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()
1448 (void) pthread_mutex_unlock(&adh->lock); in get_adobject_batch()