void ldap_connection_kill(struct ldap_connection *conn) { if (conn->io != NULL) io_remove_closed(&(conn->io)); if (conn->to_disconnect != NULL) timeout_remove(&(conn->to_disconnect)); if (conn->to_reconnect != NULL) timeout_remove(&(conn->to_reconnect)); if (conn->request_queue) { unsigned int n = aqueue_count(conn->request_queue); for (unsigned int i = 0; i < n; i++) { struct ldap_op_queue_entry *const *reqp = array_idx(&(conn->request_array), aqueue_idx(conn->request_queue, i)); if ((*reqp)->msgid > -1) ldap_abandon_ext(conn->conn, (*reqp)->msgid, NULL, NULL); (*reqp)->msgid = -1; } } if (conn->conn != NULL) { ldap_destroy(conn->conn); ldap_memfree(conn->scred); } conn->conn = NULL; conn->state = LDAP_STATE_DISCONNECT; }
static void openldap_uv_lua__destory(openldap_uv_lua_handle_t *ldap) { if(ldap->ldap) { ldap_destroy(ldap->ldap); ldap->ldap = 0; } if(ldap->url) { ldap_memfree(ldap->url); ldap->url = 0; } }
static void * do_onerwthread( void *arg ) { int i, j, thisconn; LDAP **mlds, *ld; char thrstr[BUFSIZ]; char dn[256], uids[32], cns[32], *base; LDAPMod *attrp[5], attrs[4]; char *oc_vals[] = { "top", "OpenLDAPperson", NULL }; char *cn_vals[] = { NULL, NULL }; char *sn_vals[] = { NULL, NULL }; char *uid_vals[] = { NULL, NULL }; int ret; int adds = 0; int dels = 0; int rc, refcnt = 0; int idx = (ldap_pvt_thread_t *)arg - rtid; mlds = (LDAP **) calloc( sizeof(LDAP *), noconns); if (mlds == NULL) { thread_error( idx, "Memory error: thread calloc for noconns" ); exit( EXIT_FAILURE ); } snprintf(uids, sizeof(uids), "rwtest%04d", idx); snprintf(cns, sizeof(cns), "rwtest%04d", idx); /* add setup */ for (i = 0; i < 4; i++) { attrp[i] = &attrs[i]; attrs[i].mod_op = 0; } attrp[4] = NULL; attrs[0].mod_type = "objectClass"; attrs[0].mod_values = oc_vals; attrs[1].mod_type = "cn"; attrs[1].mod_values = cn_vals; cn_vals[0] = &cns[0]; attrs[2].mod_type = "sn"; attrs[2].mod_values = sn_vals; sn_vals[0] = &cns[0]; attrs[3].mod_type = "uid"; attrs[3].mod_values = uid_vals; uid_vals[0] = &uids[0]; for ( j = 0; j < outerloops; j++ ) { for(i = 0; i < noconns; i++) { mlds[i] = ldap_dup(lds[i]); if (mlds[i] == NULL) { thread_error( idx, "ldap_dup error" ); } } rc = ldap_get_option(mlds[0], LDAP_OPT_SESSION_REFCNT, &refcnt); snprintf(thrstr, BUFSIZ, "RW Thread conns: %d refcnt: %d (rc = %d)", noconns, refcnt, rc); thread_verbose(idx, thrstr); thisconn = (idx + j) % noconns; if (thisconn < 0 || thisconn >= noconns) thisconn = 0; if (mlds[thisconn] == NULL) { thread_error( idx, "(failed to dup)"); tester_perror( "ldap_dup", "(failed to dup)" ); exit( EXIT_FAILURE ); } snprintf(thrstr, BUFSIZ, "START RW Thread using conn %d", thisconn); thread_verbose(idx, thrstr); ld = mlds[thisconn]; if (entry != NULL) base = entry; else base = DEFAULT_BASE; snprintf(dn, 256, "cn=%s,%s", cns, base); adds = 0; dels = 0; for (i = 0; i < loops; i++) { ret = ldap_add_ext_s(ld, dn, &attrp[0], NULL, NULL); if (ret == LDAP_SUCCESS) { adds++; ret = ldap_delete_ext_s(ld, dn, NULL, NULL); if (ret == LDAP_SUCCESS) { dels++; rt_pass[idx]++; } else { thread_output(idx, ldap_err2string(ret)); rt_fail[idx]++; } } else { thread_output(idx, ldap_err2string(ret)); rt_fail[idx]++; } } snprintf(thrstr, BUFSIZ, "INNER STOP RW Thread using conn %d (%d/%d)", thisconn, adds, dels); thread_verbose(idx, thrstr); for(i = 0; i < noconns; i++) { (void) ldap_destroy(mlds[i]); mlds[i] = NULL; } } free( mlds ); return( NULL ); }
static void * do_onethread( void *arg ) { int i, j, thisconn; LDAP **mlds; char thrstr[BUFSIZ]; int rc, refcnt = 0; int idx = (ldap_pvt_thread_t *)arg - rtid; mlds = (LDAP **) calloc( sizeof(LDAP *), noconns); if (mlds == NULL) { thread_error( idx, "Memory error: thread calloc for noconns" ); exit( EXIT_FAILURE ); } for ( j = 0; j < outerloops; j++ ) { for(i = 0; i < noconns; i++) { mlds[i] = ldap_dup(lds[i]); if (mlds[i] == NULL) { thread_error( idx, "ldap_dup error" ); } } rc = ldap_get_option(mlds[0], LDAP_OPT_SESSION_REFCNT, &refcnt); snprintf(thrstr, BUFSIZ, "RO Thread conns: %d refcnt: %d (rc = %d)", noconns, refcnt, rc); thread_verbose(idx, thrstr); thisconn = (idx + j) % noconns; if (thisconn < 0 || thisconn >= noconns) thisconn = 0; if (mlds[thisconn] == NULL) { thread_error( idx, "(failed to dup)"); tester_perror( "ldap_dup", "(failed to dup)" ); exit( EXIT_FAILURE ); } snprintf(thrstr, BUFSIZ, "Using conn %d", thisconn); thread_verbose(idx, thrstr); if ( filter != NULL ) { if (strchr(filter, '[')) do_random2( mlds[thisconn], entry, filter, attrs, noattrs, nobind, loops, retries, delay, force, chaserefs, idx ); else do_random( mlds[thisconn], entry, filter, attrs, noattrs, nobind, loops, retries, delay, force, chaserefs, idx ); } else { do_read( mlds[thisconn], entry, attrs, noattrs, nobind, loops, retries, delay, force, chaserefs, idx ); } for(i = 0; i < noconns; i++) { (void) ldap_destroy(mlds[i]); mlds[i] = NULL; } } free( mlds ); return( NULL ); }