Lines Matching refs:lc

442 exclusiveLC(__nis_ldap_conn_t *lc) {
446 if (lc == 0)
449 stat = mutex_trylock(&lc->mutex);
450 if (stat == EBUSY && lc->owner != me)
451 mutex_lock(&lc->mutex);
453 lc->owner = me;
458 assertExclusive(__nis_ldap_conn_t *lc) {
462 if (lc == 0)
465 stat = mutex_trylock(&lc->mutex);
468 mutex_unlock(&lc->mutex);
473 if (stat != EBUSY || lc->owner != me)
480 releaseLC(__nis_ldap_conn_t *lc) {
483 if (lc == 0 || lc->owner != me)
486 lc->owner = 0;
487 (void) mutex_unlock(&lc->mutex);
491 incrementRC(__nis_ldap_conn_t *lc) {
492 if (lc == 0)
495 (void) mutex_lock(&lc->rcMutex);
496 lc->refCount++;
497 (void) mutex_unlock(&lc->rcMutex);
501 decrementRC(__nis_ldap_conn_t *lc) {
502 if (lc == 0)
505 (void) mutex_lock(&lc->rcMutex);
506 if (lc->refCount > 0)
507 lc->refCount--;
508 (void) mutex_unlock(&lc->rcMutex);
615 * Free 'lc' and all related memory. Caller must hold the exclusive lock.
620 freeCon(__nis_ldap_conn_t *lc) {
622 if (!assertExclusive(lc))
625 incrementRC(lc);
628 if (lc->onList || lc->refCount != 1 || lc->isBound) {
629 lc->doDel++;
630 decrementRC(lc);
634 sfree(lc->sp);
635 sfree(lc->who);
636 sfree(lc->cred);
640 free(lc);
652 disconnectCon(__nis_ldap_conn_t *lc) {
656 if (lc == 0)
659 if (!assertExclusive(lc))
662 if (lc->doDis) {
665 incrementRC(lc);
667 if (lc->refCount != 1) {
672 decrementRC(lc);
676 stat = ldap_unbind_s(lc->ld);
678 lc->ld = 0;
679 lc->isBound = 0;
680 lc->doDis = 0;
682 lc->simplePage = 0;
683 lc->vlv = 0;
690 decrementRC(lc);
693 if (lc->doDel) {
694 if (LDAP_UNAVAILABLE == freeCon(lc))
704 * lc The connection
714 controlSupported(__nis_ldap_conn_t *lc, char **ctrl, bool_t *supported) {
724 stat = ldap_search_st(lc->ld, "", LDAP_SCOPE_BASE, "(objectclass=*)",
725 attr, 0, &lc->searchTimeout, &res);
729 myself, NIL(lc->sp), ldap_err2string(stat));
733 e = ldap_first_entry(lc->ld, res);
735 a = ldap_first_attribute(lc->ld, e, &ber);
737 val = ldap_get_values(lc->ld, e, a);
749 myself, NIL(lc->sp));
763 myself, NIL(lc->sp), NIL(*ctrl),
779 * Connect the LDAP connection 'lc'. Caller must have acquired the 'mutex',
786 connectCon(__nis_ldap_conn_t *lc, int check_ctrl) {
794 if (lc == 0)
797 if (!assertExclusive(lc))
800 incrementRC(lc);
801 if (lc->refCount != 1) {
806 decrementRC(lc);
812 if (lc->ld != 0) {
814 lc->doDis++;
815 decrementRC(lc);
817 stat = disconnectCon(lc);
820 incrementRC(lc);
821 if (lc->refCount != 1 || lc->ld != 0) {
822 decrementRC(lc);
823 return (lc->ld != 0) ? LDAP_SUCCESS :
826 } else if (tp.tv_sec < lc->retryTime) {
828 decrementRC(lc);
833 lc->retryTime = tp.tv_sec + ldapConnAttemptRetryTimeout;
835 lc->ld = ldapInit(lc->sp, lc->port, proxyInfo.tls_method != no_tls);
836 if (lc->ld == 0) {
837 decrementRC(lc);
841 stat = lc->status = ldapBind(&lc->ld, lc->who, lc->cred, lc->method,
842 lc->bindTimeout);
843 if (lc->status == LDAP_SUCCESS) {
844 lc->isBound = 1;
845 lc->retryTime = 0;
847 (void) controlSupported(lc, ctrl, supported);
848 lc->simplePage = supported[0];
849 lc->vlv = supported[1];
850 lc->batchFrom = 50000;
854 decrementRC(lc);
864 __nis_ldap_conn_t *lc;
885 for (lc = ldapCon; lc != 0; lc = lc->next) {
886 exclusiveLC(lc);
887 if (!lc->isBound) {
888 *stat = connectCon(lc, 1);
893 myself, NIL(lc->sp),
895 releaseLC(lc);
899 } else if (lc->doDis || lc->doDel) {
900 *stat = disconnectCon(lc);
902 releaseLC(lc);
905 incrementRC(lc);
906 releaseLC(lc);
912 return (lc);
917 releaseCon(__nis_ldap_conn_t *lc, int status) {
920 if (lc == 0)
923 exclusiveLC(lc);
925 lc->status = status;
927 decrementRC(lc);
929 if (lc->doDis)
930 stat = disconnectCon(lc);
935 releaseLC(lc);
940 __nis_ldap_conn_t *lc;
947 lc = am(myself, sizeof (*lc));
948 if (lc == 0)
951 (void) mutex_init(&lc->mutex, 0, 0);
952 (void) mutex_init(&lc->rcMutex, 0, 0);
954 /* If we need to delete 'lc', freeCon() wants the mutex held */
955 exclusiveLC(lc);
957 lc->sp = sdup(myself, T, sp);
958 if (lc->sp == 0) {
959 (void) freeCon(lc);
963 if ((r = strchr(lc->sp, ']')) != 0) {
970 r = strchr(lc->sp, ':');
980 lc->who = sdup(myself, T, who);
981 if (lc->who == 0) {
982 (void) freeCon(lc);
988 lc->cred = sdup(myself, T, cred);
989 if (lc->cred == 0) {
990 (void) freeCon(lc);
995 lc->method = method;
996 lc->port = port;
998 lc->bindTimeout = proxyInfo.bind_timeout;
999 lc->searchTimeout = proxyInfo.search_timeout;
1000 lc->modifyTimeout = proxyInfo.modify_timeout;
1001 lc->addTimeout = proxyInfo.add_timeout;
1002 lc->deleteTimeout = proxyInfo.delete_timeout;
1006 releaseLC(lc);
1008 return (lc);
1014 __nis_ldap_conn_t *lc, *tmp;
1051 lc = createCon(s, who, cred, method, 0);
1052 if (lc == 0) {
1057 lc->onList = 1;
1059 ldapCon = lc;
1064 tmp->next = lc;
1077 is_same_connection(__nis_ldap_conn_t *lc, LDAPURLDesc *ludpp)
1079 return (strcasecmp(ludpp->lud_host, lc->sp) == 0 &&
1080 ludpp->lud_port == lc->port);
1088 __nis_ldap_conn_t *lc = NULL;
1094 for (lc = list; lc != 0; lc = lc->next) {
1095 exclusiveLC(lc);
1096 if (is_same_connection(lc, ludpp)) {
1097 if (!lc->isBound) {
1098 *stat = connectCon(lc, 1);
1100 releaseLC(lc);
1103 } else if (lc->doDis || lc->doDel) {
1104 (void) disconnectCon(lc);
1105 releaseLC(lc);
1108 incrementRC(lc);
1109 releaseLC(lc);
1112 releaseLC(lc);
1114 return (lc);
1120 __nis_ldap_conn_t *lc = NULL;
1164 lc = find_connection_from_list(ldapReferralCon, ludpp, stat);
1165 if (lc == NULL)
1166 lc = find_connection_from_list(ldapCon, ludpp, stat);
1168 if (lc != NULL) {
1170 return (lc);
1191 lc = createCon(ludpp->lud_host, proxyInfo.proxy_dn,
1195 if (lc == 0) {
1205 lc->onList = 1;
1207 ldapReferralCon = lc;
1212 tmp->next = lc;
1214 lc = find_connection_from_list(ldapReferralCon, ludpp, stat);
1216 if (lc != NULL)
1220 if (lc == NULL) {
1226 return (lc);
1235 __nis_ldap_conn_t *lc, *newlc;
1256 for (lc = ldapCon; lc != 0; lc = lc->next) {
1257 exclusiveLC(lc);
1259 if (lc->isBound && (lc->doDis || lc->doDel)) {
1260 *stat = disconnectCon(lc);
1262 releaseLC(lc);
1272 newlc = createCon(lc->sp, lc->who, lc->cred,
1273 lc->method, lc->port);
1275 releaseLC(lc);
1278 if (lc->ld != 0) {
1279 newlc->simplePage = lc->simplePage;
1280 newlc->vlv = lc->vlv;
1281 newlc->batchFrom = lc->batchFrom;
1283 releaseLC(lc);
1304 lc = newlc;
1305 } else if (!lc->isBound) {
1306 *stat = connectCon(lc, 1);
1311 myself, NIL(lc->sp),
1313 releaseLC(lc);
1319 incrementRC(lc);
1320 releaseLC(lc);
1326 return (lc);
1351 __nis_ldap_conn_t *lc;
1379 if ((lc = findYPCon(ls, ldapStat)) == 0) {
1384 if ((lc = findCon(ldapStat)) == 0) {
1395 if (doIndex && lc->vlv) {
1406 stat = ldap_create_sort_control(lc->ld, sortKeyList, 1,
1410 vList.ldvlist_after_count = lc->batchFrom - 1;
1416 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &stat);
1428 if (doIndex && !doVLV && lc->simplePage) {
1454 tv = lc->searchTimeout;
1465 stat = ldap_create_virtuallist_control(lc->ld,
1468 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
1481 stat = ldap_search_ext_s(lc->ld, ls->base,
1489 stat = ldap_create_page_control(lc->ld,
1490 lc->batchFrom, spCookie, 0, &ctrls[0]);
1494 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
1505 stat = ldap_search_ext_s(lc->ld, ls->base,
1510 stat = ldap_search_st(lc->ld, ls->base, ls->scope,
1515 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &stat);
1518 lc->doDis++;
1519 releaseCon(lc, stat);
1520 lc = (yp2ldap)?findYPCon(ls, ldapStat):
1522 if (lc == 0) {
1531 (void) ldap_parse_result(lc->ld, msg, NULL, NULL, NULL,
1536 releaseCon(lc, stat);
1537 lc = findReferralCon(referralsp, &stat);
1539 if (lc == NULL) {
1577 myself, NIL(lc->sp));
1582 lc->ld, NIL(ls->base), ls->scope);
1592 numEntries = ldap_count_entries(lc->ld, msg);
1613 for (m = ldap_first_entry(lc->ld, msg); m != 0;
1614 m = ldap_next_entry(lc->ld, m), numVals++) {
1625 nm = ldap_get_dn(lc->ld, m);
1636 for (nm = ldap_first_attribute(lc->ld, m, &ber);
1638 nm = ldap_next_attribute(lc->ld, m, ber)) {
1642 val = ldap_get_values_len(lc->ld, m, nm);
1681 stat = ldap_parse_result(lc->ld, msg, &lprEc, 0, 0, 0,
1684 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
1698 stat = ldap_parse_virtuallist_control(lc->ld,
1702 index = targetPosP + lc->batchFrom;
1712 stat = ldap_parse_result(lc->ld, msg, &lprEc, 0, 0, 0,
1715 ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
1732 stat = ldap_parse_page_control(lc->ld,
1789 if (NULL != lc) {
1792 lc->doDis++;
1793 lc->doDel++;
1794 releaseCon(lc, stat);
1795 releaseLC(lc);
1798 releaseCon(lc, stat);
2043 ldapModifyObjectClass(__nis_ldap_conn_t **lc, char *dn,
2154 msgid = ldap_modify((*lc)->ld, dn, mods);
2156 tv = (*lc)->modifyTimeout;
2157 stat = ldap_result((*lc)->ld, msgid, 0, &tv, &msg);
2161 (void) ldap_get_option((*lc)->ld,
2164 stat = ldap_parse_result((*lc)->ld, msg, &lderr, NULL,
2168 stat = ldap_result2error((*lc)->ld, msg, 0);
2171 (void) ldap_get_option((*lc)->ld, LDAP_OPT_ERROR_NUMBER,
2176 releaseCon(*lc, stat);
2180 *lc = findReferralCon(referralsp, &stat);
2183 if (*lc == NULL)
2185 msgid = ldap_modify((*lc)->ld, dn, mods);
2187 (void) ldap_get_option((*lc)->ld,
2191 stat = ldap_result((*lc)->ld, msgid, 0, &tv, &msg);
2195 (void) ldap_get_option((*lc)->ld,
2198 stat = ldap_parse_result((*lc)->ld, msg, &lderr,
2226 __nis_ldap_conn_t *lc;
2237 if ((lc = findCon(&stat)) == 0)
2243 msgid = ldap_delete(lc->ld, dn);
2245 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2249 tv = lc->deleteTimeout;
2250 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2255 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2258 stat = ldap_parse_result(lc->ld, msg, &lderr, NULL,
2265 releaseCon(lc, stat);
2269 lc = findReferralCon(referralsp, &stat);
2271 if (lc == NULL)
2273 msgid = ldap_delete(lc->ld, dn);
2275 (void) ldap_get_option(lc->ld,
2279 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2283 (void) ldap_get_option(lc->ld,
2286 stat = ldap_parse_result(lc->ld, msg, &lderr,
2297 stat = ldapAdd(dn, rv, objClassAttrs, lc);
2298 lc = NULL;
2301 if ((lc = findCon(&stat)) == 0)
2315 msgid = ldap_modify(lc->ld, dn, mods);
2317 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2321 tv = lc->modifyTimeout;
2322 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2326 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2329 stat = ldap_parse_result(lc->ld, msg, &lderr, NULL,
2336 releaseCon(lc, stat);
2340 lc = findReferralCon(referralsp, &stat);
2343 if (lc == NULL)
2345 msgid = ldap_modify(lc->ld, dn, mods);
2347 (void) ldap_get_option(lc->ld,
2351 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2355 (void) ldap_get_option(lc->ld,
2358 stat = ldap_parse_result(lc->ld, msg, &lderr,
2376 stat = ldapModifyObjectClass(&lc, dn, rv,
2480 stat = ldapAdd(dn, rv, objClassAttrs, lc);
2481 lc = NULL;
2492 lc != NULL ? lc->ld : 0,
2493 lc != NULL ? NIL(lc->sp) : "nil",
2497 releaseCon(lc, stat);
2510 * If 'lc' is non-NULL, we use that connection; otherwise, we find
2523 __nis_ldap_conn_t *lc = lcv;
2529 releaseCon(lc, LDAP_SUCCESS);
2533 if (lc == 0) {
2534 if ((lc = findCon(&stat)) == 0)
2550 msgid = ldap_add(lc->ld, dn, mods);
2552 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &stat);
2555 tv = lc->addTimeout;
2556 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2560 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER, &stat);
2562 stat = ldap_parse_result(lc->ld, msg, &lderr, NULL, NULL,
2569 releaseCon(lc, stat);
2573 lc = findReferralCon(referralsp, &stat);
2575 if (lc == NULL)
2577 msgid = ldap_add(lc->ld, dn, mods);
2579 (void) ldap_get_option(lc->ld,
2583 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2587 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2590 stat = ldap_parse_result(lc->ld, msg, &lderr, NULL,
2601 lc != NULL ? lc->ld : 0,
2602 lc != NULL ? NIL(lc->sp) : "nil",
2606 releaseCon(lc, stat);
2621 __nis_ldap_conn_t *lc;
2637 if ((lc = findCon(&stat)) == 0)
2642 releaseCon(lc, LDAP_SUCCESS);
2660 stat = ldap_rename(lc->ld, oldDn, rdn, NULL, 1, NULL, NULL, &msgid);
2663 tv = lc->modifyTimeout;
2664 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2668 (void) ldap_get_option(lc->ld,
2671 stat = ldap_parse_result(lc->ld, msg, &lderr, NULL,
2675 stat = ldap_result2error(lc->ld, msg, 0);
2678 (void) ldap_get_option(lc->ld, LDAP_OPT_ERROR_NUMBER,
2683 releaseCon(lc, stat);
2687 lc = findReferralCon(referralsp, &stat);
2690 if (lc == NULL)
2692 msgid = ldap_rename(lc->ld, oldDn, rdn, NULL, 1, NULL, NULL,
2695 (void) ldap_get_option(lc->ld,
2699 stat = ldap_result(lc->ld, msgid, 0, &tv, &msg);
2703 (void) ldap_get_option(lc->ld,
2706 stat = ldap_parse_result(lc->ld, msg, &lderr,
2719 myself, lc == NULL ? 0: lc->ld, NIL(oldDn), NIL(rdn),
2723 myself, lc == NULL ? 0: lc->ld, NIL(oldDn), NIL(rdn),
2736 releaseCon(lc, stat);