#define LDIF ".ldif"
+#define IX_DNL '{'
+#define IX_DNR '}'
+#ifndef IX_FSL
+#define IX_FSL IX_DNL
+#define IX_FSR IX_DNR
+#endif
+
#define ENTRY_BUFF_INCREMENT 500
static ObjectClass *ldif_oc;
ldif_cf, NULL, NULL, NULL },
{ "directory", "dir", 2, 2, 0, ARG_BERVAL|ARG_OFFSET,
(void *)offsetof(struct ldif_info, li_base_path),
- "( OLcfgAt:1.1 NAME 'dbDirectory' "
+ "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
"DESC 'Directory for database content' "
"EQUALITY caseIgnoreMatch "
"SYNTAX OMsDirectoryString )", NULL, NULL },
};
static ConfigOCs ldifocs[] = {
- { "( OLcfgOc:2.1 "
- "NAME 'ldifConfig' "
+ { "( OLcfgDbOc:2.1 "
+ "NAME 'olcLdifConfig' "
"DESC 'LDIF backend configuration' "
- "AUXILIARY "
- "MAY ( dbDirectory ) )",
+ "SUP olcDatabaseConfig "
+ "MUST ( olcDbDirectory ) )", Cft_Database,
&ldif_oc },
- { NULL, NULL }
+ { NULL, 0, NULL }
};
static int
end = sep;
}
strcpy(ptr, LDIF);
+#if IX_FSL != IX_DNL
+ ptr = res->bv_val;
+ while( ptr=strchr(ptr, IX_DNL) ) {
+ *ptr++ = IX_FSL;
+ ptr = strchr(ptr, IX_DNR);
+ if ( ptr )
+ *ptr++ = IX_FSR;
+ else
+ break;
+ }
+#endif
}
static char * slurp_file(int fd) {
- int entry_buf_size = 40 * ENTRY_BUFF_INCREMENT;
int read_chars_total = 0;
int read_chars = 0;
- int entry_size = 40 * ENTRY_BUFF_INCREMENT;
- char * entry = (char *) malloc(sizeof(char) * 40 * ENTRY_BUFF_INCREMENT);
- char * entry_pos = entry;
+ int entry_size;
+ char * entry;
+ char * entry_pos;
+ struct stat st;
+
+ fstat(fd, &st);
+ entry_size = st.st_size;
+ entry = ch_malloc( entry_size+1 );
+ entry_pos = entry;
while(1) {
- if(entry_size - read_chars_total == 0) {
- entry = (char *) realloc(entry, sizeof(char) * 2 * entry_size);
- entry_size = 2 * entry_size;
- }
read_chars = read(fd, (void *) entry_pos, entry_size - read_chars_total);
if(read_chars == -1) {
SLAP_FREE(entry);
return NULL;
}
- entry_pos += read_chars;
if(read_chars == 0) {
- if(entry_size - read_chars_total > 0)
- entry[read_chars_total] = '\0';
- else {
- entry = (char *) realloc(entry, sizeof(char) * entry_size + 1);
- entry_size = entry_size + 1;
- entry[read_chars_total] = '\0';
- }
+ entry[read_chars_total] = '\0';
break;
}
else {
read_chars_total += read_chars;
+ entry_pos += read_chars;
}
}
return entry;
static int spew_file(int fd, char * spew) {
int written = 0;
- int writeres;
+ int writeres = 0;
int len = strlen(spew);
char * spewptr = spew;
rs = LDAP_UNWILLING_TO_PERFORM;
}
else {
+ struct berval rdn;
+ int tmp;
+
+ /* Only save the RDN onto disk */
+ dnRdn( &e->e_name, &rdn );
+ if ( rdn.bv_len != e->e_name.bv_len ) {
+ e->e_name.bv_val[rdn.bv_len] = '\0';
+ tmp = e->e_name.bv_len;
+ e->e_name.bv_len = rdn.bv_len;
+ rdn.bv_len = tmp;
+ }
+
entry_as_string = entry2str(e, &entry_length);
+
+ /* Restore full DN */
+ if ( rdn.bv_len != e->e_name.bv_len ) {
+ e->e_name.bv_val[e->e_name.bv_len] = ',';
+ e->e_name.bv_len = rdn.bv_len;
+ }
+
if(entry_as_string == NULL) {
rs = LDAP_UNWILLING_TO_PERFORM;
close(openres);
return rs;
}
-static Entry * get_entry_for_fd(int fd) {
+static Entry * get_entry_for_fd(int fd,
+ struct berval *pdn,
+ struct berval *pndn)
+{
char * entry = (char *) slurp_file(fd);
Entry * ldentry = NULL;
}
ldentry = str2entry(entry);
+ if ( ldentry ) {
+ struct berval rdn;
+ rdn = ldentry->e_name;
+ build_new_dn( &ldentry->e_name, pdn, &rdn, NULL );
+ ch_free( rdn.bv_val );
+ rdn = ldentry->e_nname;
+ build_new_dn( &ldentry->e_nname, pndn, &rdn, NULL );
+ ch_free( rdn.bv_val );
+ }
return_value:
if(fd != -1) {
return ldentry;
}
-static Entry * get_entry(struct berval * dn, struct berval * rootdn, struct berval * base_path) {
- struct berval path;
+static Entry * get_entry(Operation *op, struct berval *base_path) {
+ struct berval path, pdn, pndn;
int fd;
- dn2path(dn, rootdn, base_path, &path);
+ dnParent(&op->o_req_dn, &pdn);
+ dnParent(&op->o_req_ndn, &pndn);
+ dn2path(&op->o_req_ndn, op->o_bd->be_nsuffix, base_path, &path);
fd = open(path.bv_val, O_RDONLY);
/* error opening file (mebbe should log error) */
if(fd == -1) {
if(path.bv_val != NULL)
SLAP_FREE(path.bv_val);
- return get_entry_for_fd(fd);
+
+ if ( fd != -1 ) {
+ return get_entry_for_fd(fd, &pdn, &pndn);
+ }
+
+ return NULL;
}
-static void fullpath(struct berval *base, char *name, struct berval *res) {
+static void fullpath(struct berval *base, struct berval *name, struct berval *res) {
char *ptr;
- res->bv_len = strlen(name) + base->bv_len + 1;
+ res->bv_len = name->bv_len + base->bv_len + 1;
res->bv_val = ch_malloc( res->bv_len + 1 );
strcpy(res->bv_val, base->bv_val);
ptr = res->bv_val + base->bv_len;
*ptr++ = LDAP_DIRSEP[0];
- strcpy(ptr, name);
+ strcpy(ptr, name->bv_val);
}
-static Entry ** r_enum_tree(Entry ** entries, int *elen, int *eind,
- struct berval * path, int scope) {
- DIR * dir_of_path = opendir(path->bv_val);
- int fd;
- struct dirent * dir;
- Entry * e;
- struct berval fpath;
+typedef struct bvlist {
+ struct bvlist *next;
+ struct berval bv;
+ struct berval num;
+ unsigned int inum;
+ int off;
+} bvlist;
+
+typedef struct enumCookie {
+ Entry **entries;
+ int elen;
+ int eind;
+ int scope;
+} enumCookie;
+
+static int r_enum_tree(enumCookie *ck, struct berval *path,
+ struct berval *pdn, struct berval *pndn)
+{
+ Entry *e;
+ int fd, rc = LDAP_SUCCESS;
+
+ fd = open( path->bv_val, O_RDONLY );
+ if ( fd < 0 ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "=> ldif_enum_tree: failed to open %s\n",
+ path->bv_val, 0, 0 );
+ return LDAP_NO_SUCH_OBJECT;
+ }
- if(entries == NULL) {
- entries = (Entry **) SLAP_MALLOC(sizeof(Entry *) * ENTRY_BUFF_INCREMENT);
- *elen = ENTRY_BUFF_INCREMENT;
+ if(ck->entries == NULL) {
+ ck->entries = (Entry **) SLAP_MALLOC(sizeof(Entry *) * ENTRY_BUFF_INCREMENT);
+ ck->elen = ENTRY_BUFF_INCREMENT;
}
- if(dir_of_path == NULL) {/* can't open directory */
- perror("failed to open directory");
- return entries;
+
+ e = get_entry_for_fd(fd, pdn, pndn);
+ if ( !e ) {
+ Debug( LDAP_DEBUG_ANY,
+ "=> ldif_enum_tree: failed to read entry for %s\n",
+ path->bv_val, 0, 0 );
+ return LDAP_BUSY;
}
-
- BER_BVZERO(&fpath);
- while(1) {
- if (fpath.bv_val) {
- free(fpath.bv_val);
- fpath.bv_val = NULL;
- }
- dir = readdir(dir_of_path);
- if(dir == NULL) break; /* end of the directory */
- if(dir->d_name[0] == '.') continue; /* skip '.' and '..' */
- if(dir->d_type == DT_UNKNOWN) { /* must stat to determine... */
- struct stat stbuf;
- fullpath( path, dir->d_name, &fpath );
- if (stat(fpath.bv_val, &stbuf)) {
- perror("stat");
- continue;
- }
- if ( S_ISREG(stbuf.st_mode) ) dir->d_type = DT_REG;
- else if ( S_ISDIR(stbuf.st_mode) ) dir->d_type = DT_DIR;
- }
- if(dir->d_type == DT_REG) { /* regular file, read the entry into memory */
- if ( scope == LDAP_SCOPE_ONELEVEL ) continue;
- if(! (*eind < *elen)) { /* grow entries if necessary */
- entries = (Entry **) SLAP_REALLOC(entries, sizeof(Entry *) * (*elen) * 2);
- *elen = *elen * 2;
+ if ( ck->scope == LDAP_SCOPE_BASE || ck->scope == LDAP_SCOPE_SUBTREE ) {
+ if(! (ck->eind < ck->elen)) { /* grow entries if necessary */
+ ck->entries = (Entry **) SLAP_REALLOC(ck->entries, sizeof(Entry *) * (ck->elen) * 2);
+ ck->elen *= 2;
+ }
+
+ ck->entries[ck->eind] = e;
+ ck->eind++;
+ fd = 0;
+ } else {
+ fd = 1;
+ }
+
+ if ( ck->scope != LDAP_SCOPE_BASE ) {
+ DIR * dir_of_path;
+ bvlist *list = NULL, *ptr;
+
+ path->bv_len -= STRLENOF( LDIF );
+ path->bv_val[path->bv_len] = '\0';
+
+ dir_of_path = opendir(path->bv_val);
+ if(dir_of_path == NULL) { /* can't open directory */
+ if ( errno != ENOENT ) {
+ /* it shouldn't be treated as an error
+ * only if the directory doesn't exist */
+ rc = LDAP_BUSY;
+ Debug( LDAP_DEBUG_TRACE,
+ "=> ldif_enum_tree: failed to opendir %s (%d)\n",
+ path->bv_val, errno, 0 );
}
- if ( !fpath.bv_val )
- fullpath( path, dir->d_name, &fpath );
- fd = open( fpath.bv_val, O_RDONLY );
- SLAP_FREE(fpath.bv_val);
- fpath.bv_val = NULL;
- if(fd != -1) {
- e = get_entry_for_fd(fd);
- if(e != NULL) {
- entries[*eind] = e;
- *eind = *eind + 1;
+ goto leave;
+ }
+
+ while(1) {
+ struct berval fname, itmp;
+ struct dirent * dir;
+ bvlist *bvl, *prev;
+
+ dir = readdir(dir_of_path);
+ if(dir == NULL) break; /* end of the directory */
+ fname.bv_len = strlen( dir->d_name );
+ if ( fname.bv_len <= STRLENOF( LDIF ))
+ continue;
+ if ( strcmp( dir->d_name + (fname.bv_len - STRLENOF(LDIF)), LDIF))
+ continue;
+ fname.bv_val = dir->d_name;
+
+ bvl = ch_malloc( sizeof(bvlist) );
+ ber_dupbv( &bvl->bv, &fname );
+ BER_BVZERO( &bvl->num );
+ itmp.bv_val = strchr( bvl->bv.bv_val, IX_FSL );
+ if ( itmp.bv_val ) {
+ char *ptr;
+ itmp.bv_val++;
+ ptr = strchr( itmp.bv_val, IX_FSR );
+ if ( ptr ) {
+ itmp.bv_len = ptr - itmp.bv_val;
+ ber_dupbv( &bvl->num, &itmp );
+ bvl->inum = strtoul( itmp.bv_val, NULL, 0 );
+ itmp.bv_val[0] = '\0';
+ bvl->off = itmp.bv_val - bvl->bv.bv_val;
}
- else
- perror("failed to read entry");
}
- else
- perror("failed to open fd");
+
+ for (ptr = list, prev = (bvlist *)&list; ptr;
+ prev = ptr, ptr = ptr->next) {
+ int cmp = strcmp( bvl->bv.bv_val, ptr->bv.bv_val );
+ if ( !cmp && bvl->num.bv_val )
+ cmp = bvl->inum - ptr->inum;
+ if ( cmp < 0 )
+ break;
+ }
+ prev->next = bvl;
+ bvl->next = ptr;
+
}
- else if(dir->d_type == DT_DIR) {
- if ( scope == LDAP_SCOPE_BASE ) continue;
- if ( !fpath.bv_val )
- fullpath( path, dir->d_name, &fpath );
- entries = r_enum_tree(entries, elen, eind, &fpath,
- scope == LDAP_SCOPE_ONELEVEL ? LDAP_SCOPE_BASE : scope);
+ closedir(dir_of_path);
+
+ if (ck->scope == LDAP_SCOPE_ONELEVEL)
+ ck->scope = LDAP_SCOPE_BASE;
+ else if ( ck->scope == LDAP_SCOPE_SUBORDINATE)
+ ck->scope = LDAP_SCOPE_SUBTREE;
+
+ while ( ( ptr = list ) ) {
+ struct berval fpath;
+
+ list = ptr->next;
+
+ if ( ptr->num.bv_val )
+ AC_MEMCPY( ptr->bv.bv_val + ptr->off, ptr->num.bv_val,
+ ptr->num.bv_len );
+ fullpath( path, &ptr->bv, &fpath );
+ r_enum_tree(ck, &fpath, &e->e_name, &e->e_nname );
+ free(fpath.bv_val);
+ if ( ptr->num.bv_val )
+ free( ptr->num.bv_val );
+ free(ptr->bv.bv_val);
+ free(ptr);
}
}
- closedir(dir_of_path);
- return entries;
+leave:
+ if ( fd ) entry_free( e );
+ return rc;
}
-static Entry ** enum_tree(struct berval * path, int * length, int scope) {
- int index = 0;
- return r_enum_tree(NULL, &index, length, path, scope);
+static int
+enum_tree(
+ BackendDB *be,
+ struct berval *dn,
+ struct berval *ndn,
+ int * length,
+ Entry ***e,
+ int scope )
+{
+ struct ldif_info *ni = (struct ldif_info *) be->be_private;
+ struct berval path;
+ int rc;
+ enumCookie ck = {0};
+ struct berval pdn, pndn;
+
+ assert( e != NULL );
+ *e = NULL;
+
+ ck.scope = scope;
+ dnParent( dn, &pdn );
+ dnParent( ndn, &pndn );
+ dn2path(ndn, &be->be_nsuffix[0], &ni->li_base_path, &path);
+ rc = r_enum_tree(&ck, &path, &pdn, &pndn);
+ *length = ck.eind;
+ *e = ck.entries;
+ return rc;
}
/* Get the parent path plus the LDIF suffix */
SlapReply * rs)
{
char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
- int rc;
- int tempdebug;
+ int rc = LDAP_UNWILLING_TO_PERFORM;
Modification *mods = NULL;
- Attribute *save_attrs;
if (!acl_check_modlist(op, entry, modlist)) {
return LDAP_INSUFFICIENT_ACCESS;
}
- /* save_attrs = entry->e_attrs; Why?
- entry->e_attrs = attrs_dup(entry->e_attrs); */
-
for (; modlist != NULL; modlist = modlist->sml_next) {
mods = &modlist->sml_mod;
rc = modify_add_values(entry, mods,
get_permissiveModify(op),
&rs->sr_text, textbuf,
- textlen);
+ sizeof( textbuf ) );
break;
case LDAP_MOD_DELETE:
rc = modify_delete_values(entry, mods,
get_permissiveModify(op),
&rs->sr_text, textbuf,
- textlen);
+ sizeof( textbuf ) );
break;
rc = modify_replace_values(entry, mods,
get_permissiveModify(op),
&rs->sr_text, textbuf,
- textlen);
+ sizeof( textbuf ) );
break;
case LDAP_MOD_INCREMENT:
rc = modify_add_values(entry, mods,
get_permissiveModify(op),
&rs->sr_text, textbuf,
- textlen);
+ sizeof( textbuf ) );
mods->sm_op = SLAP_MOD_SOFTADD;
if (rc == LDAP_TYPE_OR_VALUE_EXISTS) {
- rc = LDAP_SUCCESS;
+ rc = LDAP_SUCCESS;
}
break;
default:
entry->e_ocflags = 0;
}
/* check that the entry still obeys the schema */
- rc = entry_schema_check(op->o_bd, entry,
- save_attrs, &rs->sr_text,
- textbuf, textlen);
+ rc = entry_schema_check(op->o_bd, entry, NULL,
+ &rs->sr_text, textbuf, sizeof( textbuf ) );
+ }
+ return rc;
+}
+
+int
+ldif_back_referrals( Operation *op, SlapReply *rs )
+{
+ struct ldif_info *ni = NULL;
+ Entry *entry;
+ int rc = LDAP_SUCCESS;
+
+#if 0
+ if ( op->o_tag == LDAP_REQ_SEARCH ) {
+ /* let search take care of itself */
+ return rc;
+ }
+#endif
+
+ if ( get_manageDSAit( op ) ) {
+ /* let op take care of DSA management */
+ return rc;
+ }
+
+ ni = (struct ldif_info *)op->o_bd->be_private;
+ ldap_pvt_thread_mutex_lock( &ni->li_mutex );
+ entry = (Entry *)get_entry( op, &ni->li_base_path );
+
+ /* no object is found for them */
+ if ( entry == NULL ) {
+ struct berval odn = op->o_req_dn;
+ struct berval ondn = op->o_req_ndn;
+
+ struct berval pndn = op->o_req_ndn;
+
+ for ( ; entry == NULL; ) {
+ dnParent( &pndn, &pndn );
+
+ if ( !dnIsSuffix( &pndn, &op->o_bd->be_nsuffix[0] ) ) {
+ break;
+ }
+
+ op->o_req_dn = pndn;
+ op->o_req_ndn = pndn;
+
+ entry = (Entry *)get_entry( op, &ni->li_base_path );
+ }
+
+ ldap_pvt_thread_mutex_unlock( &ni->li_mutex );
+
+ op->o_req_dn = odn;
+ op->o_req_ndn = ondn;
+
+ rc = LDAP_SUCCESS;
+ rs->sr_matched = NULL;
+ if ( entry != NULL ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "ldif_back_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
+ (long) op->o_tag, op->o_req_dn.bv_val, entry->e_name.bv_val );
+
+ if ( is_entry_referral( entry ) ) {
+ rc = LDAP_OTHER;
+ rs->sr_ref = get_entry_referrals( op, entry );
+ if ( rs->sr_ref ) {
+ rs->sr_matched = ber_strdup_x(
+ entry->e_name.bv_val, op->o_tmpmemctx );
+ }
+ }
+
+ entry_free(entry);
+
+ } else if ( default_referral != NULL ) {
+ rc = LDAP_OTHER;
+ rs->sr_ref = referral_rewrite( default_referral,
+ NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+ }
+
+ if ( rs->sr_ref != NULL ) {
+ /* send referrals */
+ rc = rs->sr_err = LDAP_REFERRAL;
+ send_ldap_result( op, rs );
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
+
+ } else if ( rc != LDAP_SUCCESS ) {
+ rs->sr_err = rc;
+ rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
+ send_ldap_result( op, rs );
+ }
+
+ if ( rs->sr_matched ) {
+ op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
+ rs->sr_matched = NULL;
+ }
+
+ return rc;
+ }
+
+ ldap_pvt_thread_mutex_unlock( &ni->li_mutex );
+
+ if ( is_entry_referral( entry ) ) {
+ /* entry is a referral */
+ BerVarray refs = get_entry_referrals( op, entry );
+ rs->sr_ref = referral_rewrite(
+ refs, &entry->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+
+ Debug( LDAP_DEBUG_TRACE,
+ "ldif_back_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
+ (long) op->o_tag, op->o_req_dn.bv_val, entry->e_name.bv_val );
+
+ rs->sr_matched = entry->e_name.bv_val;
+ if ( rs->sr_ref != NULL ) {
+ rc = rs->sr_err = LDAP_REFERRAL;
+ send_ldap_result( op, rs );
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
+
+ } else {
+ send_ldap_error( op, rs, LDAP_OTHER, "bad referral object" );
+ rc = rs->sr_err;
+ }
+
+ rs->sr_matched = NULL;
+ ber_bvarray_free( refs );
+
+ entry_free( entry );
}
+
return rc;
}
ni = (struct ldif_info *) op->o_bd->be_private;
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
- entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
+ entry = (Entry *) get_entry(op, &ni->li_base_path);
/* no object is found for them */
if(entry == NULL) {
if(be_isroot_pw(op)) {
- return_val = LDAP_SUCCESS;
- goto return_result;
- }
- else if(be_root_dn(op->o_bd)) {
- return_val = LDAP_INVALID_CREDENTIALS;
- rs->sr_err = LDAP_INVALID_CREDENTIALS;
- goto return_result;
- }
- else {
- rs->sr_err = LDAP_NO_SUCH_OBJECT;
- return_val = 1;
- goto return_result;
+ rs->sr_err = return_val = LDAP_SUCCESS;
+ } else {
+ rs->sr_err = return_val = LDAP_INVALID_CREDENTIALS;
}
+ goto return_result;
}
/* they don't have userpassword */
Entry ** entries = NULL;
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
- entries = (Entry **) enum_tree(&ni->li_base_path, &numentries, op->ors_scope);
+ rs->sr_err = enum_tree(op->o_bd, &op->o_req_dn, &op->o_req_ndn, &numentries, &entries, op->ors_scope);
+ if ( rs->sr_err == LDAP_SUCCESS ) {
+ for ( i = 0; i < numentries; i++ ) {
+
+
+ /*
+ * if it's a referral, add it to the list of referrals. only do
+ * this for non-base searches, and don't check the filter
+ * explicitly here since it's only a candidate anyway.
+ */
+ if ( !get_manageDSAit( op )
+ && op->oq_search.rs_scope != LDAP_SCOPE_BASE
+ && is_entry_referral( entries[i] ) )
+ {
+ BerVarray erefs = get_entry_referrals( op, entries[i] );
+ rs->sr_ref = referral_rewrite( erefs,
+ &entries[i]->e_name, NULL,
+ op->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
+ ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
+
+ send_search_reference( op, rs );
+
+ ber_bvarray_free( rs->sr_ref );
+ ber_bvarray_free( erefs );
+ rs->sr_ref = NULL;
- if(entries != NULL) {
- for(i=0;i<numentries;i++) {
- if(test_filter(op, entries[i], op->ors_filter) == LDAP_COMPARE_TRUE) {
+ } else if ( test_filter( op, entries[i], op->ors_filter ) == LDAP_COMPARE_TRUE )
+ {
rs->sr_entry = entries[i];
rs->sr_attrs = op->ors_attrs;
rs->sr_flags = REP_ENTRY_MODIFIABLE;
}
entry_free(entries[i]);
}
- SLAP_FREE(entries);
- rs->sr_err = LDAP_SUCCESS;
- ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
- send_ldap_result(op, rs);
- }
- else {
- rs->sr_err = LDAP_BUSY;
- ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
- send_ldap_result(op, rs);
}
+ SLAP_FREE(entries);
+ ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
+ send_ldap_result(op, rs);
- return 0;
+ return rs->sr_err;
}
static int ldif_back_add(Operation *op, SlapReply *rs) {
struct stat stats;
int statres;
char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
rs->sr_err = entry_schema_check(op->o_bd, e,
- NULL, &rs->sr_text, textbuf, textlen);
+ NULL, &rs->sr_text, textbuf, sizeof( textbuf ) );
if ( rs->sr_err != LDAP_SUCCESS ) goto send_res;
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path,
&path);
- entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0],
- &ni->li_base_path);
+ entry = (Entry *) get_entry(op, &ni->li_base_path);
if(entry != NULL) {
rs->sr_err = apply_modify_to_entry(entry, modlst, op, rs);
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path, &path);
- res = unlink(path.bv_val);
+
+ path.bv_val[path.bv_len - STRLENOF(LDIF)] = '\0';
+ res = rmdir(path.bv_val);
+ path.bv_val[path.bv_len - STRLENOF(LDIF)] = '.';
+ if ( res && errno != ENOENT ) {
+ rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
+ } else {
+ res = unlink(path.bv_val);
+ }
if(res == -1) {
if(errno == ENOENT)
return 0;
}
-static int is_leaf_node(struct berval * path) {
- DIR * nonleafnode;
- int path_len = path->bv_len;
- int res;
-
- path->bv_val[path->bv_len - STRLENOF(LDIF)] = '\0';
- nonleafnode = opendir(path->bv_val);
- path->bv_val[path->bv_len - STRLENOF(LDIF)] = '.';
- if(nonleafnode == NULL) {
- res = 1;
- }
- else {
- closedir(nonleafnode);
- res = 0;
- }
- return res;
-}
static int move_entry(Entry * entry, struct berval * ndn,
struct berval * newndn, struct berval * rootdn,
/* some object doesn't exist */
res = LDAP_NO_SUCH_OBJECT;
}
- else if(! is_leaf_node(&path)) { /* entry is not a leaf node */
- res = LDAP_NOT_ALLOWED_ON_NONLEAF;
- }
else { /* do the modrdn */
exists_res = open(newpath.bv_val, O_RDONLY);
if(exists_res == -1 && errno == ENOENT) {
static int ldif_back_modrdn(Operation *op, SlapReply *rs) {
struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
- struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
- struct berval * new_parent_dn = NULL;
- struct berval p_dn, bv = {0, NULL};
+ struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
+ struct berval p_dn, bv = BER_BVNULL;
Entry * entry = NULL;
LDAPRDN new_rdn = NULL;
LDAPRDN old_rdn = NULL;
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
ldap_pvt_thread_mutex_lock(&entry2str_mutex);
- entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
+ entry = (Entry *) get_entry(op, &ni->li_base_path);
/* build the mods to the entry */
if(entry != NULL) {
- if(ldap_bv2rdn(&op->oq_modrdn.rs_newrdn, &new_rdn, (char **)&rs->sr_text,
- LDAP_DN_FORMAT_LDAP)) {
+ if(ldap_bv2rdn(&op->oq_modrdn.rs_newrdn, &new_rdn,
+ (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP)) {
rs->sr_err = LDAP_INVALID_DN_SYNTAX;
}
else if(op->oq_modrdn.rs_deleteoldrdn &&
rs->sr_err = LDAP_OTHER;
}
else { /* got both rdns successfully, ready to build mods */
- if(slap_modrdn2mods(op, rs, entry, old_rdn, new_rdn, &mods) != LDAP_SUCCESS) {
- rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+ if(slap_modrdn2mods(op, rs, entry, old_rdn, new_rdn, &mods)
+ != LDAP_SUCCESS) {
+ rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
}
else { /* built mods successfully */
- /* build new dn, and new ndn for the entry */
- if(op->oq_modrdn.rs_newSup != NULL) /* new superior */
- p_dn = *op->oq_modrdn.rs_newSup;
- else
- p_dn = slap_empty_bv;
- dnParent(&entry->e_name, &p_dn);
- build_new_dn(&new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL);
- dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
- ber_dupbv( &new_ndn, &bv );
- entry->e_name = new_dn;
- entry->e_nname = new_ndn;
-
- /* perform the modifications */
- res = apply_modify_to_entry(entry, mods, op, rs);
- if(res == LDAP_SUCCESS) {
- rs->sr_err = move_entry(entry, &op->o_req_ndn,
- &new_ndn,
- &op->o_bd->be_nsuffix[0],
- &ni->li_base_path);
- }
- else
- rs->sr_err = res;
+ /* build new dn, and new ndn for the entry */
+ if(op->oq_modrdn.rs_newSup != NULL) /* new superior */
+ p_dn = *op->oq_modrdn.rs_newSup;
+ else
+ p_dn = slap_empty_bv;
+ dnParent(&entry->e_name, &p_dn);
+ build_new_dn(&new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL);
+ dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
+ ber_dupbv( &new_ndn, &bv );
+ entry->e_name = new_dn;
+ entry->e_nname = new_ndn;
+
+ /* perform the modifications */
+ res = apply_modify_to_entry(entry, mods, op, rs);
+ if(res == LDAP_SUCCESS) {
+ rs->sr_err = move_entry(entry, &op->o_req_ndn,
+ &new_ndn,
+ &op->o_bd->be_nsuffix[0],
+ &ni->li_base_path);
+ }
+ else
+ rs->sr_err = res;
}
}
}
ldap_pvt_thread_mutex_lock(&ni->li_mutex);
- e = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
+ e = (Entry *) get_entry(op, &ni->li_base_path);
if(e != NULL) {
for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
- a != NULL;
- a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
- {
- rs->sr_err = LDAP_COMPARE_FALSE;
-
- if (value_find_ex(op->oq_compare.rs_ava->aa_desc,
- SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
- SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
- a->a_nvals, &op->oq_compare.rs_ava->aa_value,
- op->o_tmpmemctx ) == 0)
- {
- rs->sr_err = LDAP_COMPARE_TRUE;
- break;
- }
+ a != NULL;
+ a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc )) {
+ rs->sr_err = LDAP_COMPARE_FALSE;
+
+ if (value_find_ex(op->oq_compare.rs_ava->aa_desc,
+ SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
+ SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
+ a->a_nvals, &op->oq_compare.rs_ava->aa_value,
+ op->o_tmpmemctx ) == 0) {
+ rs->sr_err = LDAP_COMPARE_TRUE;
+ break;
}
+ }
}
else {
rs->sr_err = LDAP_NO_SUCH_OBJECT;
static int ldif_tool_entry_close(BackendDB * be) {
struct ldif_info *ni = (struct ldif_info *) be->be_private;
- int i;
- /*if(ni->tool_entries != NULL) {
- for(i=0;i<ni->tool_numentries;i++) {
- SLAP_FREE(ni->tool_entries[i]);
- }*/
+
SLAP_FREE(ni->tool_entries);
return 0;
}
-static ID ldif_tool_entry_first(BackendDB *be) {
+static ID
+ldif_tool_entry_first(BackendDB *be)
+{
struct ldif_info *ni = (struct ldif_info *) be->be_private;
ID id = 1; /* first entry in the array of entries shifted by one */
+
ni->tool_current = 1;
if(ni->tool_entries == NULL || ni->tool_put_entry_flag) {
- ni->tool_entries = (Entry **) enum_tree(&ni->li_base_path, &ni->tool_numentries, LDAP_SCOPE_SUBTREE);
+ (void)enum_tree(be, be->be_suffix, be->be_nsuffix,
+ &ni->tool_numentries, &ni->tool_entries,
+ LDAP_SCOPE_SUBTREE);
ni->tool_put_entry_flag = 0;
}
return id;
}
-static ID ldif_tool_entry_next(BackendDB *be) {
+static ID ldif_tool_entry_next(BackendDB *be)
+{
struct ldif_info *ni = (struct ldif_info *) be->be_private;
ni->tool_current += 1;
if(ni->tool_put_entry_flag) {
- ni->tool_entries = (Entry **) enum_tree(&ni->li_base_path, &ni->tool_numentries, LDAP_SCOPE_SUBTREE);
+ (void)enum_tree(be, be->be_suffix, be->be_nsuffix,
+ &ni->tool_numentries, &ni->tool_entries,
+ LDAP_SCOPE_SUBTREE);
ni->tool_put_entry_flag = 0;
}
if(ni->tool_current > ni->tool_numentries)
static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
struct ldif_info *ni = (struct ldif_info *) be->be_private;
- Attribute *save_attrs;
struct berval dn = e->e_nname;
struct berval leaf_path = BER_BVNULL;
struct stat stats;
int statres;
- char textbuf[SLAP_TEXT_BUFLEN];
- size_t textlen = sizeof textbuf;
int res = LDAP_SUCCESS;
dn2path(&dn, &be->be_nsuffix[0], &ni->li_base_path, &leaf_path);
BackendInfo *bi
)
{
+ static char *controls[] = {
+ LDAP_CONTROL_MANAGEDSAIT,
+ NULL
+ };
int rc;
+ bi->bi_flags |=
+ SLAP_BFLAG_REFERRALS;
+
+ bi->bi_controls = controls;
+
bi->bi_cf_table = ldifcfg;
bi->bi_open = 0;
bi->bi_extended = 0;
- bi->bi_chk_referrals = 0;
+ bi->bi_chk_referrals = ldif_back_referrals;
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
bi->bi_tool_id2entry_get = 0;
bi->bi_tool_entry_modify = 0;
- rc = init_config_attrs( ldifcfg );
+ rc = config_register_schema( ldifcfg, ldifocs );
if ( rc ) return rc;
ldifcfg[0].ad = slap_schema.si_ad_objectClass;
- rc = init_config_ocs( ldifocs );
- return rc;
+ return 0;
}