/* * 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; }
static int convert_to_string(Slapi_DN *dn, void *arg) { struct list_to_string_data *data = (struct list_to_string_data *)arg; int newlen = slapi_sdn_get_ndn_len(dn) + strlen(data->delimiter) + 1; if (data->string) { newlen += strlen(data->string); data->string = slapi_ch_realloc(data->string, newlen); } else { data->string = slapi_ch_calloc(1, newlen); } strcat(data->string, slapi_sdn_get_dn(dn)); strcat(data->string, data->delimiter); return 1; }
int value_dn_normalize_value(Slapi_Value *value) { Slapi_DN *sdn = NULL; int rc = 0; if (NULL == value) { return rc; } sdn = slapi_sdn_new_dn_passin(value->bv.bv_val); if (slapi_sdn_get_dn(sdn)) { value->bv.bv_val = slapi_ch_strdup(slapi_sdn_get_dn(sdn)); value->bv.bv_len = slapi_sdn_get_ndn_len(sdn); slapi_sdn_free(&sdn); slapi_value_set_flags(value, SLAPI_ATTR_FLAG_NORMALIZED_CES); } else { rc = 1; slapi_ch_free((void **)&sdn); /* free just Slapi_DN */ } return rc; }
/* * Write this record to the log file */ void writeintegritylog(Slapi_PBlock *pb, char *logfilename, Slapi_DN *sdn, char *newrdn, Slapi_DN *newsuperior, Slapi_DN *requestorsdn) { PRFileDesc *prfd; char buffer[MAX_LINE]; int len_to_write = 0; int rc; const char *requestordn = NULL; const char *newsuperiordn = NULL; size_t reqdn_len = 0; /* * Use this lock to protect file data when update integrity is occuring. * If betxn is enabled, this mutex is ignored; transaction itself takes * the role. */ referint_lock(); if (( prfd = PR_Open( logfilename, PR_WRONLY | PR_CREATE_FILE | PR_APPEND, REFERINT_DEFAULT_FILE_MODE )) == NULL ) { slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM, "referint_postop could not write integrity log \"%s\" " SLAPI_COMPONENT_NAME_NSPR " %d (%s)\n", logfilename, PR_GetError(), slapd_pr_strerror(PR_GetError()) ); PR_Unlock(referint_mutex); referint_unlock(); return; } /* * Make sure we have enough room in our buffer before trying to write it. * add length of dn + 5(three tabs, a newline, and terminating \0) */ len_to_write = slapi_sdn_get_ndn_len(sdn) + 5; if(newrdn == NULL){ /* add the length of "NULL" */ len_to_write += 4; } else { /* add the length of the newrdn */ len_to_write += strlen(newrdn); } newsuperiordn = slapi_sdn_get_dn(newsuperior); if(NULL == newsuperiordn) { /* add the length of "NULL" */ len_to_write += 4; } else { /* add the length of the newsuperior */ len_to_write += slapi_sdn_get_ndn_len(newsuperior); } slapi_pblock_get(pb, SLAPI_REQUESTOR_DN, &requestordn); if (requestorsdn && (requestordn = slapi_sdn_get_udn(requestorsdn)) && (reqdn_len = strlen(requestordn))) { len_to_write += reqdn_len; } else { len_to_write += 4; /* "NULL" */ } if(len_to_write > MAX_LINE ){ slapi_log_error( SLAPI_LOG_FATAL, REFERINT_PLUGIN_SUBSYSTEM, "referint_postop could not write integrity log:" " line length exceeded. It will not be able" " to update references to this entry.\n"); } else { PR_snprintf(buffer, MAX_LINE, "%s\t%s\t%s\t%s\t\n", slapi_sdn_get_dn(sdn), (newrdn != NULL) ? newrdn : "NULL", (newsuperiordn != NULL) ? newsuperiordn : "NULL", requestordn ? requestordn : "NULL"); if (PR_Write(prfd,buffer,strlen(buffer)) < 0){ slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM, " writeintegritylog: PR_Write failed : The disk" " may be full or the file is unwritable :: NSPR error - %d\n", PR_GetError()); } } /* If file descriptor is closed successfully, PR_SUCCESS */ rc = PR_Close(prfd); if (rc != PR_SUCCESS){ slapi_log_error(SLAPI_LOG_FATAL,REFERINT_PLUGIN_SUBSYSTEM, " writeintegritylog: failed to close the file descriptor prfd; NSPR error - %d\n", PR_GetError()); } referint_unlock(); }