/* * snmp_update_entries_table() * * Updated the mmap'd entries table. The semaphore should * be acquired before you call this. */ static void snmp_update_entries_table() { stats->entries_stats.dsMasterEntries = slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsMasterEntries); stats->entries_stats.dsCopyEntries = slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCopyEntries); stats->entries_stats.dsCacheEntries = slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCacheEntries); stats->entries_stats.dsCacheHits = slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCacheHits); stats->entries_stats.dsSlaveHits = slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsSlaveHits); }
static int _usn_mod_next_usn(LDAPMod ***mods, Slapi_Backend *be) { Slapi_Mods smods = {0}; struct berval *bvals[2]; struct berval usn_berval = {0}; char counter_buf[USN_COUNTER_BUF_LEN]; if (NULL == be->be_usn_counter) { /* USN plugin is not enabled */ return LDAP_UNWILLING_TO_PERFORM; } slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> _usn_mod_next_usn\n"); /* add next USN to the mods; "be" contains the usn counter */ usn_berval.bv_val = counter_buf; PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRIu64, slapi_counter_get_value(be->be_usn_counter)); usn_berval.bv_len = strlen(usn_berval.bv_val); bvals[0] = &usn_berval; bvals[1] = NULL; slapi_mods_init_passin(&smods, *mods); /* bvals is duplicated by ber_bvdup in slapi_mods_add_modbvps */ slapi_mods_add_modbvps(&smods, LDAP_MOD_REPLACE | LDAP_MOD_BVALUES, SLAPI_ATTR_ENTRYUSN, bvals); *mods = slapi_mods_get_ldapmods_passout(&smods); slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- _usn_mod_next_usn\n"); return LDAP_SUCCESS; }
/* * lookup instance names by suffix. * if isexact == 0: returns instances including ones that associates with * its sub suffixes. * e.g., suffix: "o=<suffix>" is given, these are returned: * suffixes: o=<suffix>, ou=<ou>,o=<suffix>, ... * instances: inst of "o=<suffix>", * inst of "ou=<ou>,o=<suffix>", * ... * if isexact != 0: returns an instance that associates with the given suffix * e.g., suffix: "o=<suffix>" is given, these are returned: * suffixes: "o=<suffix>" * instances: inst of "o=<suffix>" * Note: if suffixes */ int slapi_lookup_instance_name_by_suffix(char *suffix, char ***suffixes, char ***instances, int isexact) { Slapi_Backend *be = NULL; struct suffixlist *list; char *cookie = NULL; const char *thisdn; int thisdnlen; int suffixlen; int count; int i; int rval = -1; if (instances == NULL) return rval; PR_ASSERT(suffix); rval = 0; suffixlen = strlen(suffix); cookie = NULL; be = slapi_get_first_backend (&cookie); while (be) { if (NULL == be->be_suffixlist) { be = (backend *)slapi_get_next_backend (cookie); continue; } count = slapi_counter_get_value(be->be_suffixcounter); list = be->be_suffixlist; for (i = 0; list && i < count; i++) { thisdn = slapi_sdn_get_ndn(list->be_suffix); thisdnlen = slapi_sdn_get_ndn_len(list->be_suffix); if (isexact?suffixlen!=thisdnlen:suffixlen>thisdnlen){ list = list->next; continue; } if (isexact?(!slapi_UTF8CASECMP(suffix, (char *)thisdn)): (!slapi_UTF8CASECMP(suffix, (char *)thisdn+thisdnlen-suffixlen))) { charray_add(instances, slapi_ch_strdup(be->be_name)); if (suffixes) charray_add(suffixes, slapi_ch_strdup(thisdn)); } list = list->next; } be = (backend *)slapi_get_next_backend (cookie); } slapi_ch_free((void **)&cookie); return rval; }
int ldbm_instance_delete_instance_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *instance_name; struct ldbminfo *li = (struct ldbminfo *)arg; struct ldbm_instance *inst = NULL; parse_ldbm_instance_entry(entryBefore, &instance_name); inst = ldbm_instance_find_by_name(li, instance_name); if (inst == NULL) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm: instance '%s' does not exist!\n", instance_name, 0, 0); if (returntext) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "No ldbm instance exists with the name '%s'\n", instance_name); } if (returncode) { *returncode = LDAP_UNWILLING_TO_PERFORM; } slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } /* check if some online task is happening */ if ((instance_set_busy(inst) != 0) || (slapi_counter_get_value(inst->inst_ref_count) > 0)) { LDAPDebug(LDAP_DEBUG_ANY, "ldbm: '%s' is in the middle of a task. " "Cancel the task or wait for it to finish, " "then try again.\n", instance_name, 0, 0); if (returntext) { PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "ldbm instance '%s' is in the middle of a " "task. Cancel the task or wait for it to finish, " "then try again.\n", instance_name); } if (returncode) { *returncode = LDAP_UNWILLING_TO_PERFORM; } slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_ERROR; } /* okay, we're gonna delete this database instance. take it offline. */ LDAPDebug(LDAP_DEBUG_ANY, "ldbm: Bringing %s offline...\n", instance_name, 0, 0); slapi_mtn_be_stopping(inst->inst_be); dblayer_instance_close(inst->inst_be); slapi_ch_free((void **)&instance_name); return SLAPI_DSE_CALLBACK_OK; }
static void _usn_add_next_usn(Slapi_Entry *e, Slapi_Backend *be) { struct berval usn_berval = {0}; Slapi_Attr* attr = NULL; if (NULL == be->be_usn_counter) { /* USN plugin is not enabled */ return; } slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> _usn_add_next_usn\n"); /* add next USN to the entry; "be" contains the usn counter */ usn_berval.bv_val = slapi_ch_smprintf("%" NSPRIu64, slapi_counter_get_value(be->be_usn_counter)); usn_berval.bv_len = strlen(usn_berval.bv_val); slapi_entry_attr_find(e, SLAPI_ATTR_ENTRYUSN, &attr); if (NULL == attr) { /* ENTRYUSN does not exist; add it */ Slapi_Value *usn_value = slapi_value_new_berval(&usn_berval); slapi_entry_add_value(e, SLAPI_ATTR_ENTRYUSN, usn_value); slapi_value_free(&usn_value); } else { /* ENTRYUSN exists; replace it */ struct berval *new_bvals[2]; new_bvals[0] = &usn_berval; new_bvals[1] = NULL; slapi_entry_attr_replace(e, SLAPI_ATTR_ENTRYUSN, new_bvals); } slapi_ch_free_string(&usn_berval.bv_val); slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- _usn_add_next_usn\n"); return; }
/* * usn_rootdse_search -- callback for the search on root DSN * add lastusn value per backend * * example: * ldapsearch -b "" -s base "(objectclass=*)" lastusn * dn: * lastusn;userroot: 72 * lastusn;testbackend: 15 */ static int usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter, int *returncode, char *returntext, void *arg) { char *cookie = NULL; Slapi_Backend *be; struct berval *vals[2]; struct berval usn_berval; vals[0] = &usn_berval; vals[1] = NULL; char counter_buf[USN_COUNTER_BUF_LEN]; int attr_len = 64; /* length of lastusn;<backend_name> */ char *attr = (char *)slapi_ch_malloc(attr_len); char *attr_subp = NULL; int isglobal = config_get_entryusn_global(); slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "--> usn_rootdse_search\n"); usn_berval.bv_val = counter_buf; if (isglobal) { /* nsslapd-entryusn-global: on*/ /* root dse shows ... * lastusn: <num> */ PR_snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 1, "%s", USN_LAST_USN); for (be = slapi_get_first_backend(&cookie); be; be = slapi_get_next_backend(cookie)) { if (be->be_usn_counter) { break; } } if (be && be->be_usn_counter) { /* get a next USN counter from be_usn_counter; * then minus 1 from it */ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRI64 "d", slapi_counter_get_value(be->be_usn_counter)-1); usn_berval.bv_len = strlen(usn_berval.bv_val); slapi_entry_attr_replace(e, attr, vals); } } else { /* nsslapd-entryusn-global: off (default) */ /* root dse shows ... * lastusn;<backend>: <num> */ PR_snprintf(attr, USN_LAST_USN_ATTR_CORE_LEN + 2, "%s;", USN_LAST_USN); attr_subp = attr + USN_LAST_USN_ATTR_CORE_LEN + 1; for (be = slapi_get_first_backend(&cookie); be; be = slapi_get_next_backend(cookie)) { if (NULL == be->be_usn_counter) { /* no counter == not a db backend */ continue; } /* get a next USN counter from be_usn_counter; * then minus 1 from it */ PR_snprintf(usn_berval.bv_val, USN_COUNTER_BUF_LEN, "%" NSPRI64 "d", slapi_counter_get_value(be->be_usn_counter)-1); usn_berval.bv_len = strlen(usn_berval.bv_val); if (USN_LAST_USN_ATTR_CORE_LEN+strlen(be->be_name)+2 > attr_len) { attr_len *= 2; attr = (char *)slapi_ch_realloc(attr, attr_len); attr_subp = attr + USN_LAST_USN_ATTR_CORE_LEN; } PR_snprintf(attr_subp, attr_len - USN_LAST_USN_ATTR_CORE_LEN, "%s", be->be_name); slapi_entry_attr_replace(e, attr, vals); } } slapi_ch_free_string(&cookie); slapi_ch_free_string(&attr); slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM, "<-- usn_rootdse_search\n"); return SLAPI_DSE_CALLBACK_OK; }
void snmp_as_entry(Slapi_Entry *e) { add_counter_to_value(e,"AnonymousBinds", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsAnonymousBinds)); add_counter_to_value(e,"UnAuthBinds", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsUnAuthBinds)); add_counter_to_value(e,"SimpleAuthBinds", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSimpleAuthBinds)); add_counter_to_value(e,"StrongAuthBinds", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsStrongAuthBinds)); add_counter_to_value(e,"BindSecurityErrors", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBindSecurityErrors)); add_counter_to_value(e,"InOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsInOps)); add_counter_to_value(e,"ReadOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReadOps)); add_counter_to_value(e,"CompareOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsCompareOps)); add_counter_to_value(e,"AddEntryOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsAddEntryOps)); add_counter_to_value(e,"RemoveEntryOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsRemoveEntryOps)); add_counter_to_value(e,"ModifyEntryOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsModifyEntryOps)); add_counter_to_value(e,"ModifyRDNOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsModifyRDNOps)); add_counter_to_value(e,"ListOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsListOps)); add_counter_to_value(e,"SearchOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSearchOps)); add_counter_to_value(e,"OneLevelSearchOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsOneLevelSearchOps)); add_counter_to_value(e,"WholeSubtreeSearchOps", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsWholeSubtreeSearchOps)); add_counter_to_value(e,"Referrals", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReferrals)); add_counter_to_value(e,"Chainings", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsChainings)); add_counter_to_value(e,"SecurityErrors", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSecurityErrors)); add_counter_to_value(e,"Errors", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsErrors)); add_counter_to_value(e,"Connections", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsConnections)); add_counter_to_value(e,"ConnectionSeq", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsConnectionSeq)); add_counter_to_value(e,"BytesRecv", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBytesRecv)); add_counter_to_value(e,"BytesSent", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBytesSent)); add_counter_to_value(e,"EntriesReturned", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsEntriesReturned)); add_counter_to_value(e,"ReferralsReturned", slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReferralsReturned)); add_counter_to_value(e,"MasterEntries", slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsMasterEntries)); add_counter_to_value(e,"CopyEntries", slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCopyEntries)); add_counter_to_value(e,"CacheEntries", slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCacheEntries)); add_counter_to_value(e,"CacheHits", slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsCacheHits)); add_counter_to_value(e,"SlaveHits", slapi_counter_get_value(g_get_global_snmp_vars()->entries_tbl.dsSlaveHits)); }
/* * snmp_update_ops_table() * * Updates the mmap'd operations table. The semaphore * should be acquired before you call this. */ static void snmp_update_ops_table() { stats->ops_stats.dsAnonymousBinds = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsAnonymousBinds); stats->ops_stats.dsUnAuthBinds = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsUnAuthBinds); stats->ops_stats.dsSimpleAuthBinds = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSimpleAuthBinds); stats->ops_stats.dsStrongAuthBinds = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsStrongAuthBinds); stats->ops_stats.dsBindSecurityErrors = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBindSecurityErrors); stats->ops_stats.dsInOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsInOps); stats->ops_stats.dsReadOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReadOps); stats->ops_stats.dsCompareOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsCompareOps); stats->ops_stats.dsAddEntryOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsAddEntryOps); stats->ops_stats.dsRemoveEntryOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsRemoveEntryOps); stats->ops_stats.dsModifyEntryOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsModifyEntryOps); stats->ops_stats.dsModifyRDNOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsModifyRDNOps); stats->ops_stats.dsListOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsListOps); stats->ops_stats.dsSearchOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSearchOps); stats->ops_stats.dsOneLevelSearchOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsOneLevelSearchOps); stats->ops_stats.dsWholeSubtreeSearchOps = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsWholeSubtreeSearchOps); stats->ops_stats.dsReferrals = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReferrals); stats->ops_stats.dsChainings = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsChainings); stats->ops_stats.dsSecurityErrors = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsSecurityErrors); stats->ops_stats.dsErrors = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsErrors); stats->ops_stats.dsConnections = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsConnections); stats->ops_stats.dsConnectionSeq = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsConnectionSeq); stats->ops_stats.dsBytesRecv = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBytesRecv); stats->ops_stats.dsBytesSent = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsBytesSent); stats->ops_stats.dsEntriesReturned = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsEntriesReturned); stats->ops_stats.dsReferralsReturned = slapi_counter_get_value(g_get_global_snmp_vars()->ops_tbl.dsReferralsReturned); }