1 /* ldif.c - the ldif backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was originally developed by Eric Stokes for inclusion
18 * in OpenLDAP Software.
23 #include <ac/string.h>
24 #include <sys/types.h>
26 #include <ac/dirent.h>
29 #include <ac/unistd.h>
34 struct berval li_base_path;
36 Entry ** tool_entries;
37 int tool_put_entry_flag;
39 ldap_pvt_thread_mutex_t li_mutex;
44 #define ENTRY_BUFF_INCREMENT 500
47 dn2path(struct berval * dn, struct berval * rootdn, struct berval * base_path)
49 char *result = ch_malloc( dn->bv_len + base_path->bv_len + 2 +
51 char *ptr, *sep, *end;
53 ptr = lutil_strcopy( result, base_path->bv_val );
54 *ptr++ = LDAP_DIRSEP[0];
55 ptr = lutil_strcopy( ptr, rootdn->bv_val );
56 end = dn->bv_val + dn->bv_len - rootdn->bv_len - 1;
57 while ( end > dn->bv_val ) {
58 for (sep = end-1; sep >=dn->bv_val && !DN_SEPARATOR( *sep ); sep--);
59 *ptr++ = LDAP_DIRSEP[0];
60 ptr = lutil_strncopy( ptr, sep+1, end-sep-1 );
67 static char * slurp_file(int fd) {
68 int entry_buf_size = 40 * ENTRY_BUFF_INCREMENT;
69 int read_chars_total = 0;
71 int entry_size = 40 * ENTRY_BUFF_INCREMENT;
72 char * entry = (char *) malloc(sizeof(char) * 40 * ENTRY_BUFF_INCREMENT);
73 char * entry_pos = entry;
76 if(entry_size - read_chars_total == 0) {
77 entry = (char *) realloc(entry, sizeof(char) * 2 * entry_size);
78 entry_size = 2 * entry_size;
80 read_chars = read(fd, (void *) entry_pos, entry_size - read_chars_total);
81 if(read_chars == -1) {
85 entry_pos += read_chars;
87 if(entry_size - read_chars_total > 0)
88 entry[read_chars_total] = '\0';
90 entry = (char *) realloc(entry, sizeof(char) * entry_size + 1);
91 entry_size = entry_size + 1;
92 entry[read_chars_total] = '\0';
97 read_chars_total += read_chars;
103 static int spew_file(int fd, char * spew) {
106 int len = strlen(spew);
107 char * spewptr = spew;
109 while(written < len) {
110 writeres = write(fd, spewptr, len - written);
112 perror("could not spew write");
123 static int spew_entry(Entry * e, char * path) {
128 char * entry_as_string;
130 openres = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
133 rs = LDAP_NO_SUCH_OBJECT;
135 rs = LDAP_UNWILLING_TO_PERFORM;
138 entry_as_string = entry2str(e, &entry_length);
139 if(entry_as_string == NULL) {
140 rs = LDAP_UNWILLING_TO_PERFORM;
144 spew_res = spew_file(openres, entry_as_string);
147 rs = LDAP_UNWILLING_TO_PERFORM;
155 static Entry * get_entry_for_fd(int fd) {
156 char * entry = (char *) slurp_file(fd);
157 Entry * ldentry = NULL;
159 /* error reading file */
164 ldentry = str2entry(entry);
177 static Entry * get_entry(struct berval * dn, struct berval * rootdn, struct berval * base_path) {
178 char * path = (char *) dn2path(dn, rootdn, base_path);
179 int fd = open(path, O_RDONLY);
181 /* error opening file (mebbe should log error) */
183 perror("failed to open file");
191 return get_entry_for_fd(fd);
194 /* takes a base path and a filename and opens that file */
195 static int fd_for_path_components(char * base, char * name) {
198 absolutepath = (char *) SLAP_MALLOC(sizeof(char) *
201 absolutepath[0] = '\0';
202 strcat(absolutepath, base);
203 strcat(absolutepath, LDAP_DIRSEP);
204 strcat(absolutepath, name);
205 fd = open(absolutepath, O_RDONLY);
206 SLAP_FREE(absolutepath);
210 static Entry ** r_enum_tree(Entry ** entries, int *elen, int *eind, char * path) {
211 DIR * dir_of_path = opendir(path);
217 if(entries == NULL) {
218 entries = (Entry **) SLAP_MALLOC(sizeof(Entry *) * ENTRY_BUFF_INCREMENT);
219 *elen = ENTRY_BUFF_INCREMENT;
221 if(dir_of_path == NULL) {/* can't open directory */
222 perror("failed to open directory");
227 dir = readdir(dir_of_path);
228 if(dir == NULL) break; /* end of the directory */
229 if(dir->d_type == DT_REG) { /* regular file, read the entry into memory */
230 if(! (*eind < *elen)) { /* grow entries if necessary */
231 entries = (Entry **) SLAP_REALLOC(entries, sizeof(Entry *) * (*elen) * 2);
234 fd = fd_for_path_components(path, dir->d_name);
236 e = get_entry_for_fd(fd);
242 perror("failed to read entry");
245 perror("failed to open fd");
247 else if(dir->d_type == DT_DIR) {
248 if(! (strcasecmp(dir->d_name, ".") == 0 || strcasecmp(dir->d_name, "..") == 0)) {
249 newpath = (char *) SLAP_MALLOC(sizeof(char) *
250 (strlen(path) + strlen(dir->d_name) + 2));
252 strcat(newpath, path);
253 strcat(newpath, LDAP_DIRSEP);
254 strcat(newpath, dir->d_name);
255 entries = r_enum_tree(entries, elen, eind, newpath);
260 closedir(dir_of_path);
264 static Entry ** enum_tree(struct berval * path, int * length) {
266 return r_enum_tree(NULL, &index, length, path->bv_val);
269 static char * get_parent_path(char * dnpath) {
270 int dnpathlen = strlen(dnpath);
274 for(i = dnpathlen;i>0;i--) /* find the first path seperator */
275 if(dnpath[i] == LDAP_DIRSEP[0])
277 result = ch_malloc( i + 1 );
278 strncpy(result, dnpath, i);
283 static int apply_modify_to_entry(Entry * entry,
284 Modifications * modlist,
288 char textbuf[SLAP_TEXT_BUFLEN];
289 size_t textlen = sizeof textbuf;
292 Modification *mods = NULL;
293 Attribute *save_attrs;
295 if (!acl_check_modlist(op, entry, modlist)) {
296 return LDAP_INSUFFICIENT_ACCESS;
299 /* save_attrs = entry->e_attrs; Why?
300 entry->e_attrs = attrs_dup(entry->e_attrs); */
302 for (; modlist != NULL; modlist = modlist->sml_next) {
303 mods = &modlist->sml_mod;
305 switch (mods->sm_op) {
307 rc = modify_add_values(entry, mods,
308 get_permissiveModify(op),
309 &rs->sr_text, textbuf,
313 case LDAP_MOD_DELETE:
314 rc = modify_delete_values(entry, mods,
315 get_permissiveModify(op),
316 &rs->sr_text, textbuf,
321 case LDAP_MOD_REPLACE:
322 rc = modify_replace_values(entry, mods,
323 get_permissiveModify(op),
324 &rs->sr_text, textbuf,
328 case LDAP_MOD_INCREMENT:
330 case SLAP_MOD_SOFTADD:
331 mods->sm_op = LDAP_MOD_ADD;
332 rc = modify_add_values(entry, mods,
333 get_permissiveModify(op),
334 &rs->sr_text, textbuf,
336 mods->sm_op = SLAP_MOD_SOFTADD;
337 if (rc == LDAP_TYPE_OR_VALUE_EXISTS) {
344 if(rc != LDAP_SUCCESS) break;
347 if(rc == LDAP_SUCCESS) {
348 if ( mods->sm_desc == slap_schema.si_ad_objectClass ) {
349 entry->e_ocflags = 0;
351 /* check that the entry still obeys the schema */
352 rc = entry_schema_check(op->o_bd, entry,
353 save_attrs, &rs->sr_text,
360 ldif_back_bind( Operation *op, SlapReply *rs )
362 struct ldif_info *ni = NULL;
363 Attribute * a = NULL;
364 AttributeDescription *password = slap_schema.si_ad_userPassword;
366 Entry * entry = NULL;
368 ni = (struct ldif_info *) op->o_bd->be_private;
369 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
370 entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
372 /* no object is found for them */
374 if(be_isroot_pw(op)) {
375 return_val = LDAP_SUCCESS;
378 else if(be_root_dn(op->o_bd)) {
379 return_val = LDAP_INVALID_CREDENTIALS;
380 rs->sr_err = LDAP_INVALID_CREDENTIALS;
384 rs->sr_err = LDAP_NO_SUCH_OBJECT;
390 /* they don't have userpassword */
391 if((a = attr_find(entry->e_attrs, password)) == NULL) {
392 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
397 /* authentication actually failed */
398 if(slap_passwd_check(op, entry, a, &op->oq_bind.rb_cred,
399 &rs->sr_text) != 0) {
400 rs->sr_err = LDAP_INVALID_CREDENTIALS;
405 /* let the front-end send success */
410 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
412 send_ldap_result( op, rs );
418 static int ldif_back_search(Operation *op, SlapReply *rs)
420 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
423 Entry ** entries = NULL;
425 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
426 entries = (Entry **) enum_tree(&ni->li_base_path, &numentries);
428 if(entries != NULL) {
429 for(i=0;i<numentries;i++) {
430 if(test_filter(op, entries[i], op->ors_filter) == LDAP_COMPARE_TRUE) {
431 rs->sr_entry = entries[i];
432 rs->sr_attrs = op->ors_attrs;
433 rs->sr_flags = REP_ENTRY_MODIFIABLE;
434 send_search_entry(op, rs);
436 entry_free(entries[i]);
439 rs->sr_err = LDAP_SUCCESS;
440 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
441 send_ldap_result(op, rs);
444 rs->sr_err = LDAP_BUSY;
445 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
446 send_ldap_result(op, rs);
452 static int ldif_back_add(Operation *op, SlapReply *rs) {
453 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
454 Entry * e = op->ora_e;
455 Attribute *save_attrs;
456 struct berval dn = e->e_nname;
457 char * leaf_path = NULL;
459 char * base_ldif = NULL;
462 char textbuf[SLAP_TEXT_BUFLEN];
463 size_t textlen = sizeof textbuf;
465 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
466 ldap_pvt_thread_mutex_lock(&entry2str_mutex);
468 leaf_path = (char *) dn2path(&dn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
470 /* save_attrs = e->e_attrs; why?
471 e->e_attrs = attrs_dup(e->e_attrs);*/
473 if(leaf_path != NULL) {
475 /* build path to container, and path to ldif of container */
476 base = (char *) get_parent_path(leaf_path);
477 base_ldif = (char *) SLAP_MALLOC(sizeof(char) * (strlen(base) + 6));
478 tmp = (char *) lutil_strcopy(base_ldif, base);
479 lutil_strcopy(tmp, LDIF);
481 rs->sr_err = entry_schema_check(op->o_bd, e,
485 if(rs->sr_err == LDAP_SUCCESS) {
486 statres = stat(base, &stats); /* check if container exists */
487 if(statres == -1 && errno == ENOENT) { /* container missing */
488 statres = stat(base_ldif, &stats); /* check for leaf node */
489 if(statres == -1 && errno == ENOENT) {
490 rs->sr_err = LDAP_NO_SUCH_OBJECT; /* parent doesn't exist */
492 else if(statres != -1) { /* create parent */
493 int mkdirres = mkdir(base, 0750);
495 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
499 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
500 }/* container was possibly created, move on to add the entry */
501 if(rs->sr_err == LDAP_SUCCESS) {
502 statres = stat(leaf_path, &stats);
503 if(statres == -1 && errno == ENOENT) {
504 rs->sr_err = (int) spew_entry(e, leaf_path);
506 else /* it already exists */
507 rs->sr_err = LDAP_ALREADY_EXISTS;
512 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
513 ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
515 send_ldap_result(op, rs);
516 if(leaf_path != NULL)
517 SLAP_FREE(leaf_path);
520 if(base_ldif != NULL)
521 SLAP_FREE(base_ldif);
525 static int ldif_back_modify(Operation *op, SlapReply *rs) {
526 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
527 Modifications * modlst = op->orm_modlist;
529 Entry * entry = NULL;
532 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
533 ldap_pvt_thread_mutex_lock(&entry2str_mutex);
534 path = (char *) dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
535 entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
538 rs->sr_err = apply_modify_to_entry(entry, modlst, op, rs);
539 if(rs->sr_err == LDAP_SUCCESS) {
540 spew_res = spew_entry(entry, path);
542 perror("could not output entry");
543 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
548 rs->sr_err = LDAP_NO_SUCH_OBJECT;
556 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
557 ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
558 send_ldap_result(op, rs);
562 static int ldif_back_delete(Operation *op, SlapReply *rs) {
563 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
567 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
568 path = (char *) dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
573 rs->sr_err = LDAP_NO_SUCH_OBJECT;
575 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
578 rs->sr_err = LDAP_SUCCESS;
581 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
582 send_ldap_result(op, rs);
586 static int is_leaf_node(char * path) {
588 int path_len = strlen(path);
589 char * nonleafpath = (char *) SLAP_MALLOC(sizeof(char) * path_len + 1);
592 strncpy(nonleafpath, path, path_len);
593 nonleafpath[path_len - 5] = '\0';
594 nonleafnode = opendir(nonleafpath);
595 if(nonleafnode == NULL) {
599 closedir(nonleafnode);
602 SLAP_FREE(nonleafpath);
606 static int move_entry(Entry * entry, struct berval * ndn,
607 struct berval * newndn, struct berval * rootdn,
608 struct berval * base_path) {
611 char * path = (char *) dn2path(ndn, rootdn, base_path);
612 char * newpath = (char *) dn2path(newndn, rootdn, base_path);
613 int path_len = strlen(path);
615 if((entry == NULL || path == NULL) || newpath == NULL) { /* some object doesn't exist */
616 res = LDAP_NO_SUCH_OBJECT;
618 else if(! is_leaf_node(path)) { /* entry is not a leaf node */
619 res = LDAP_NOT_ALLOWED_ON_NONLEAF;
621 else { /* do the modrdn */
622 exists_res = open(newpath, O_RDONLY);
623 if(exists_res == -1 && errno == ENOENT) {
624 res = spew_entry(entry, newpath);
626 /* if this fails we should log something bad */
632 res = LDAP_NO_SUCH_OBJECT;
634 res = LDAP_UNWILLING_TO_PERFORM;
635 unlink(newpath); /* in case file was created */
638 else if(exists_res) {
639 res = LDAP_ALREADY_EXISTS;
640 int close_res = close(exists_res);
641 if(close_res == -1) {
642 /* log heinous error */
646 res = LDAP_UNWILLING_TO_PERFORM;
657 static int ldif_back_modrdn(Operation *op, SlapReply *rs) {
658 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
659 struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
660 struct berval * new_parent_dn = NULL;
662 Entry * entry = NULL;
663 LDAPRDN new_rdn = NULL;
664 LDAPRDN old_rdn = NULL;
665 Modifications * mods = NULL;
668 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
669 ldap_pvt_thread_mutex_lock(&entry2str_mutex);
670 entry = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
672 /* build the mods to the entry */
674 if(ldap_bv2rdn(&op->oq_modrdn.rs_newrdn, &new_rdn, (char **)&rs->sr_text,
675 LDAP_DN_FORMAT_LDAP)) {
676 rs->sr_err = LDAP_INVALID_DN_SYNTAX;
678 else if(op->oq_modrdn.rs_deleteoldrdn &&
679 ldap_bv2rdn(&op->o_req_dn, &old_rdn, (char **)&rs->sr_text,
680 LDAP_DN_FORMAT_LDAP)) {
681 rs->sr_err = LDAP_OTHER;
683 else { /* got both rdns successfully, ready to build mods */
684 if(slap_modrdn2mods(op, rs, entry, old_rdn, new_rdn, &mods) != LDAP_SUCCESS) {
685 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
687 else { /* built mods successfully */
689 /* build new dn, and new ndn for the entry */
690 if(op->oq_modrdn.rs_newSup != NULL) /* new superior */
691 p_dn = *op->oq_modrdn.rs_newSup;
693 p_dn = slap_empty_bv;
694 dnParent(&entry->e_name, &p_dn);
695 build_new_dn(&new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL);
696 struct berval bv = {0, NULL};
697 dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
698 ber_dupbv( &new_ndn, &bv );
699 entry->e_name = new_dn;
700 entry->e_nname = new_ndn;
702 /* perform the modifications */
703 res = apply_modify_to_entry(entry, mods, op, rs);
704 if(res == LDAP_SUCCESS) {
705 rs->sr_err = move_entry(entry, &op->o_req_ndn,
707 &op->o_bd->be_nsuffix[0],
715 else /* entry was null */
716 rs->sr_err = LDAP_NO_SUCH_OBJECT;
721 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
722 ldap_pvt_thread_mutex_unlock(&entry2str_mutex);
723 send_ldap_result(op, rs);
727 static int ldif_back_compare(Operation *op, SlapReply *rs) {
728 struct ldif_info *ni = (struct ldif_info *) op->o_bd->be_private;
732 ldap_pvt_thread_mutex_lock(&ni->li_mutex);
734 e = (Entry *) get_entry(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path);
736 for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
738 a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ))
740 rs->sr_err = LDAP_COMPARE_FALSE;
742 if (value_find_ex(op->oq_compare.rs_ava->aa_desc,
743 SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
744 SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
745 a->a_nvals, &op->oq_compare.rs_ava->aa_value,
746 op->o_tmpmemctx ) == 0)
748 rs->sr_err = LDAP_COMPARE_TRUE;
754 rs->sr_err = LDAP_NO_SUCH_OBJECT;
759 ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
760 send_ldap_result(op, rs);
764 static int ldif_tool_entry_open(BackendDB * be, int mode) {
765 struct ldif_info *ni = (struct ldif_info *) be->be_private;
766 ni->tool_entries = NULL;
767 ni->tool_numentries = 0;
768 ni->tool_current = 0;
769 ni->tool_put_entry_flag = 0;
773 static int ldif_tool_entry_close(BackendDB * be) {
774 struct ldif_info *ni = (struct ldif_info *) be->be_private;
776 /*if(ni->tool_entries != NULL) {
777 for(i=0;i<ni->tool_numentries;i++) {
778 SLAP_FREE(ni->tool_entries[i]);
780 SLAP_FREE(ni->tool_entries);
784 static ID ldif_tool_entry_first(BackendDB *be) {
785 struct ldif_info *ni = (struct ldif_info *) be->be_private;
786 ID id = 1; /* first entry in the array of entries shifted by one */
787 ni->tool_current = 1;
788 if(ni->tool_entries == NULL || ni->tool_put_entry_flag) {
789 ni->tool_entries = (Entry **) enum_tree(&ni->li_base_path, &ni->tool_numentries);
790 ni->tool_put_entry_flag = 0;
795 static ID ldif_tool_entry_next(BackendDB *be) {
796 struct ldif_info *ni = (struct ldif_info *) be->be_private;
797 ni->tool_current += 1;
798 if(ni->tool_put_entry_flag) {
799 ni->tool_entries = (Entry **) enum_tree(&ni->li_base_path, &ni->tool_numentries);
800 ni->tool_put_entry_flag = 0;
802 if(ni->tool_current > ni->tool_numentries)
805 return ni->tool_current;
808 static Entry * ldif_tool_entry_get(BackendDB * be, ID id) {
809 struct ldif_info *ni = (struct ldif_info *) be->be_private;
812 if(id > ni->tool_numentries || id < 1)
815 e = ni->tool_entries[id - 1];
816 ni->tool_entries[id - 1] = NULL;
821 static ID ldif_tool_entry_put(BackendDB * be, Entry * e, struct berval *text) {
822 struct ldif_info *ni = (struct ldif_info *) be->be_private;
823 Attribute *save_attrs;
824 struct berval dn = e->e_nname;
825 char * leaf_path = NULL;
827 char * base_ldif = NULL;
830 char textbuf[SLAP_TEXT_BUFLEN];
831 size_t textlen = sizeof textbuf;
832 int res = LDAP_SUCCESS;
834 leaf_path = (char *) dn2path(&dn, &be->be_nsuffix[0], &ni->li_base_path);
836 /* save_attrs = e->e_attrs; why?
837 e->e_attrs = attrs_dup(e->e_attrs);*/
839 if(leaf_path != NULL) {
841 /* build path to container, and path to ldif of container */
842 base = (char *) get_parent_path(leaf_path);
843 base_ldif = (char *) SLAP_MALLOC(sizeof(char) * (strlen(base) + 6));
844 tmp = (char *) lutil_strcopy(base_ldif, base);
845 lutil_strcopy(tmp, LDIF);
847 statres = stat(base, &stats); /* check if container exists */
848 if(statres == -1 && errno == ENOENT) { /* container missing */
849 statres = stat(base_ldif, &stats); /* check for leaf node */
850 if(statres == -1 && errno == ENOENT) {
851 res = LDAP_NO_SUCH_OBJECT; /* parent doesn't exist */
853 else if(statres != -1) { /* create parent */
854 int mkdirres = mkdir(base, 0750);
856 res = LDAP_UNWILLING_TO_PERFORM;
860 res = LDAP_UNWILLING_TO_PERFORM;
861 }/* container was possibly created, move on to add the entry */
862 if(res == LDAP_SUCCESS) {
863 statres = stat(leaf_path, &stats);
864 if(statres == -1 && errno == ENOENT) {
865 res = (int) spew_entry(e, leaf_path);
867 else /* it already exists */
868 res = LDAP_ALREADY_EXISTS;
872 if(leaf_path != NULL)
873 SLAP_FREE(leaf_path);
876 if(base_ldif != NULL)
877 SLAP_FREE(base_ldif);
878 if(res == LDAP_SUCCESS) {
879 ni->tool_put_entry_flag = 1;
894 struct ldif_info *ni = (struct ldif_info *) be->be_private;
896 if ( strcasecmp( argv[0], "directory" ) == 0 ) {
899 "%s: line %d: missing <path> in \"directory <path>\" line\n",
903 ber_str2bv(argv[1], 0, 1, &ni->li_base_path);
905 return SLAP_CONF_UNKNOWN;
912 ldif_back_db_init( BackendDB *be )
914 struct ldif_info *ni;
916 ni = ch_calloc( 1, sizeof(struct ldif_info) );
918 ldap_pvt_thread_mutex_init(&ni->li_mutex);
923 ldif_back_db_destroy(
927 struct ldif_info *ni = be->be_private;
928 ldap_pvt_thread_mutex_destroy(&ni->li_mutex);
929 free( be->be_private );
938 struct ldif_info *ni = (struct ldif_info *) be->be_private;
939 if( BER_BVISEMPTY(&ni->li_base_path)) {/* missing base path */
940 fprintf(stderr, "missing base path for back-ldif\n");
947 ldif_back_initialize(
956 bi->bi_db_init = ldif_back_db_init;
957 bi->bi_db_config = ldif_back_db_config;
958 bi->bi_db_open = ldif_back_db_open;
960 bi->bi_db_destroy = ldif_back_db_destroy;
962 bi->bi_op_bind = ldif_back_bind;
963 bi->bi_op_unbind = 0;
964 bi->bi_op_search = ldif_back_search;
965 bi->bi_op_compare = ldif_back_compare;
966 bi->bi_op_modify = ldif_back_modify;
967 bi->bi_op_modrdn = ldif_back_modrdn;
968 bi->bi_op_add = ldif_back_add;
969 bi->bi_op_delete = ldif_back_delete;
970 bi->bi_op_abandon = 0;
974 bi->bi_chk_referrals = 0;
976 bi->bi_connection_init = 0;
977 bi->bi_connection_destroy = 0;
979 bi->bi_tool_entry_open = ldif_tool_entry_open;
980 bi->bi_tool_entry_close = ldif_tool_entry_close;
981 bi->bi_tool_entry_first = ldif_tool_entry_first;
982 bi->bi_tool_entry_next = ldif_tool_entry_next;
983 bi->bi_tool_entry_get = ldif_tool_entry_get;
984 bi->bi_tool_entry_put = ldif_tool_entry_put;
985 bi->bi_tool_entry_reindex = 0;
986 bi->bi_tool_sync = 0;
988 bi->bi_tool_dn2id_get = 0;
989 bi->bi_tool_id2entry_get = 0;
990 bi->bi_tool_entry_modify = 0;