1 /* ldif.c - the ldif backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2008 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>
35 Entry **entries; /* collected by bi_tool_entry_first() */
36 ID elen; /* length of entries[] array */
37 ID ecount; /* number of entries */
38 ID ecurrent; /* bi_tool_entry_next() position */
39 # define ENTRY_BUFF_INCREMENT 500 /* initial entries[] length */
42 /* Per-database data */
44 struct berval li_base_path; /* database directory */
45 struct ldif_tool li_tool; /* for slap tools */
46 ldap_pvt_thread_rdwr_t li_rdwr; /* no other I/O when writing */
50 #define mkdir(a,b) mkdir(a)
51 #define move_file(from, to) (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING))
53 #define move_file(from, to) rename(from, to)
55 #define move_dir(from, to) rename(from, to)
59 #define LDIF_FILETYPE_SEP '.' /* LDIF[0] */
62 * Unsafe/translated characters in the filesystem.
64 * LDIF_UNSAFE_CHAR(c) returns true if the character c is not to be used
65 * in relative filenames, except it should accept '\\', '{' and '}' even
66 * if unsafe. The value should be a constant expression.
68 * If '\\' is unsafe, #define LDIF_ESCAPE_CHAR as a safe character.
69 * If '{' and '}' are unsafe, #define IX_FSL/IX_FSR as safe characters.
70 * (Not digits, '-' or '+'. IX_FSL == IX_FSR is allowed.)
72 * Characters are escaped as LDIF_ESCAPE_CHAR followed by two hex digits,
73 * except '\\' is replaced with LDIF_ESCAPE_CHAR and {} with IX_FS[LR].
74 * Also some LDIF special chars are hex-escaped.
76 * Thus an LDIF filename is a valid normalized RDN (or suffix DN)
77 * followed by ".ldif", except with '\\' replaced with LDIF_ESCAPE_CHAR.
83 * Unix/MacOSX version. ':' vs '/' can cause confusion on MacOSX so we
84 * escape both. We escape them on Unix so both OS variants get the same
87 #define LDIF_ESCAPE_CHAR '\\'
88 #define LDIF_UNSAFE_CHAR(c) ((c) == '/' || (c) == ':')
92 /* Windows version - Microsoft's list of unsafe characters, except '\\' */
93 #define LDIF_ESCAPE_CHAR '^' /* Not '\\' (unsafe on Windows) */
94 #define LDIF_UNSAFE_CHAR(c) \
95 ((c) == '/' || (c) == ':' || \
96 (c) == '<' || (c) == '>' || (c) == '"' || \
97 (c) == '|' || (c) == '?' || (c) == '*')
102 * Left and Right "{num}" prefix to ordered RDNs ("olcDatabase={1}bdb").
103 * IX_DN* are for LDAP RDNs, IX_FS* for their .ldif filenames.
108 #define IX_FSL IX_DNL
109 #define IX_FSR IX_DNR
113 * Test for unsafe chars, as well as chars handled specially by back-ldif:
114 * - If the escape char is not '\\', it must itself be escaped. Otherwise
115 * '\\' and the escape char would map to the same character.
116 * - Escape the '.' in ".ldif", so the directory for an RDN that actually
117 * ends with ".ldif" can not conflict with a file of the same name. And
118 * since some OSes/programs choke on multiple '.'s, escape all of them.
119 * - If '{' and '}' are translated to some other characters, those
120 * characters must in turn be escaped when they occur in an RDN.
122 #ifndef LDIF_NEED_ESCAPE
123 #define LDIF_NEED_ESCAPE(c) \
124 ((LDIF_UNSAFE_CHAR(c)) || \
125 LDIF_MAYBE_UNSAFE(c, LDIF_ESCAPE_CHAR) || \
126 LDIF_MAYBE_UNSAFE(c, LDIF_FILETYPE_SEP) || \
127 LDIF_MAYBE_UNSAFE(c, IX_FSL) || \
128 (IX_FSR != IX_FSL && LDIF_MAYBE_UNSAFE(c, IX_FSR)))
131 * Helper macro for LDIF_NEED_ESCAPE(): Treat character x as unsafe if
132 * back-ldif does not already treat is specially.
134 #define LDIF_MAYBE_UNSAFE(c, x) \
135 (!(LDIF_UNSAFE_CHAR(x) || (x) == '\\' || (x) == IX_DNL || (x) == IX_DNR) \
138 /* Collect other "safe char" tests here, until someone needs a fix. */
140 eq_unsafe = LDIF_UNSAFE_CHAR('='),
141 safe_filenames = STRLENOF("" LDAP_DIRSEP "") == 1 && !(
142 LDIF_UNSAFE_CHAR('-') || /* for "{-1}frontend" in bconfig.c */
143 LDIF_UNSAFE_CHAR(LDIF_ESCAPE_CHAR) ||
144 LDIF_UNSAFE_CHAR(IX_FSL) || LDIF_UNSAFE_CHAR(IX_FSR))
146 /* Sanity check: Try to force a compilation error if !safe_filenames */
148 int assert_safe_filenames : safe_filenames ? 2 : -2;
149 } assert_safe_filenames[safe_filenames ? 2 : -2];
152 static ConfigTable ldifcfg[] = {
153 { "directory", "dir", 2, 2, 0, ARG_BERVAL|ARG_OFFSET,
154 (void *)offsetof(struct ldif_info, li_base_path),
155 "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
156 "DESC 'Directory for database content' "
157 "EQUALITY caseIgnoreMatch "
158 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
159 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
160 NULL, NULL, NULL, NULL }
163 static ConfigOCs ldifocs[] = {
165 "NAME 'olcLdifConfig' "
166 "DESC 'LDIF backend configuration' "
167 "SUP olcDatabaseConfig "
168 "MUST ( olcDbDirectory ) )", Cft_Database, ldifcfg },
174 * Handle file/directory names.
177 /* Set *res = LDIF filename path for the normalized DN */
179 dn2path( BackendDB *be, struct berval *dn, struct berval *res )
181 struct ldif_info *li = (struct ldif_info *) be->be_private;
182 struct berval *suffixdn = &be->be_nsuffix[0];
183 const char *start, *end, *next, *p;
186 static const char hex[] = "0123456789ABCDEF";
188 assert( dn != NULL );
189 assert( !BER_BVISNULL( dn ) );
190 assert( suffixdn != NULL );
191 assert( !BER_BVISNULL( suffixdn ) );
192 assert( dnIsSuffix( dn, suffixdn ) );
195 end = start + dn->bv_len;
197 /* Room for dir, dirsep, dn, LDIF, "\hexpair"-escaping of unsafe chars */
198 len = li->li_base_path.bv_len + dn->bv_len + (1 + STRLENOF( LDIF ));
199 for ( p = start; p < end; ) {
201 if ( LDIF_NEED_ESCAPE( ch ) )
204 res->bv_val = ch_malloc( len + 1 );
206 ptr = lutil_strcopy( res->bv_val, li->li_base_path.bv_val );
207 for ( next = end - suffixdn->bv_len; end > start; end = next ) {
208 /* Set p = start of DN component, next = &',' or start of DN */
209 while ( (p = next) > start ) {
211 if ( DN_SEPARATOR( *next ) )
214 /* Append <dirsep> <p..end-1: RDN or database-suffix> */
215 for ( *ptr++ = LDAP_DIRSEP[0]; p < end; *ptr++ = ch ) {
217 if ( LDIF_ESCAPE_CHAR != '\\' && ch == '\\' ) {
218 ch = LDIF_ESCAPE_CHAR;
219 } else if ( IX_FSL != IX_DNL && ch == IX_DNL ) {
221 } else if ( IX_FSR != IX_DNR && ch == IX_DNR ) {
223 } else if ( LDIF_NEED_ESCAPE( ch ) ) {
224 *ptr++ = LDIF_ESCAPE_CHAR;
225 *ptr++ = hex[(ch & 0xFFU) >> 4];
226 ch = hex[ch & 0x0FU];
230 ptr = lutil_strcopy( ptr, LDIF );
231 res->bv_len = ptr - res->bv_val;
233 assert( res->bv_len <= len );
237 * *dest = dupbv(<dir + LDAP_DIRSEP>), plus room for <more>-sized filename.
238 * Return pointer past the dirname.
241 fullpath_alloc( struct berval *dest, const struct berval *dir, ber_len_t more )
243 char *s = SLAP_MALLOC( dir->bv_len + more + 2 );
248 Debug( LDAP_DEBUG_ANY, "back-ldif: out of memory\n", 0, 0, 0 );
250 s = lutil_strcopy( dest->bv_val, dir->bv_val );
251 *s++ = LDAP_DIRSEP[0];
253 dest->bv_len = s - dest->bv_val;
259 * Append filename to fullpath_alloc() dirname or replace previous filename.
260 * dir_end = fullpath_alloc() return value.
262 #define FILL_PATH(fpath, dir_end, filename) \
263 ((fpath)->bv_len = lutil_strcopy(dir_end, filename) - (fpath)->bv_val)
266 /* .ldif entry filename length <-> subtree dirname length. */
267 #define ldif2dir_len(bv) ((bv).bv_len -= STRLENOF(LDIF))
268 #define dir2ldif_len(bv) ((bv).bv_len += STRLENOF(LDIF))
269 /* .ldif entry filename <-> subtree dirname, both with dirname length. */
270 #define ldif2dir_name(bv) ((bv).bv_val[(bv).bv_len] = '\0')
271 #define dir2ldif_name(bv) ((bv).bv_val[(bv).bv_len] = LDIF_FILETYPE_SEP)
273 /* Get the parent directory path, plus the LDIF suffix overwritten by a \0. */
275 get_parent_path( struct berval *dnpath, struct berval *res )
277 ber_len_t i = dnpath->bv_len;
279 while ( i > 0 && dnpath->bv_val[ --i ] != LDAP_DIRSEP[0] ) ;
283 res->bv_val = SLAP_MALLOC( i + 1 + STRLENOF(LDIF) );
284 if ( res->bv_val == NULL )
286 AC_MEMCPY( res->bv_val, dnpath->bv_val, i );
289 strcpy( res->bv_val + i, LDIF );
290 res->bv_val[i] = '\0';
294 /* Make temporary filename pattern for mkstemp() based on dnpath. */
296 ldif_tempname( const struct berval *dnpath )
298 static const char suffix[] = ".XXXXXX";
299 ber_len_t len = dnpath->bv_len - STRLENOF( LDIF );
300 char *name = SLAP_MALLOC( len + sizeof( suffix ) );
302 if ( name != NULL ) {
303 AC_MEMCPY( name, dnpath->bv_val, len );
304 strcpy( name + len, suffix );
310 * Read a file, or stat() it if datap == NULL. Allocate and fill *datap.
311 * Return LDAP_SUCCESS, LDAP_NO_SUCH_OBJECT (no such file), or another error.
314 ldif_read_file( const char *path, char **datap )
317 int res = -1; /* 0:success, <0:error, >0:file too big/growing. */
319 char *data = NULL, *ptr;
321 if ( datap == NULL ) {
322 res = stat( path, &st );
325 fd = open( path, O_RDONLY );
327 if ( fstat( fd, &st ) == 0 ) {
328 if ( st.st_size > INT_MAX - 2 ) {
331 len = st.st_size + 1; /* +1 detects file size > st.st_size */
332 *datap = data = ptr = SLAP_MALLOC( len + 1 );
334 while ( len && (res = read( fd, ptr, len )) ) {
338 } else if ( errno != EINTR ) {
346 if ( close( fd ) < 0 )
352 Debug( LDAP_DEBUG_TRACE, "ldif_read_file: %s: \"%s\"\n",
353 datap ? "read entry file" : "entry file exists", path, 0 );
356 if ( res < 0 && errno == ENOENT ) {
357 Debug( LDAP_DEBUG_TRACE, "ldif_read_file: "
358 "no entry file \"%s\"\n", path, 0, 0 );
359 rc = LDAP_NO_SUCH_OBJECT;
361 const char *msg = res < 0 ? STRERROR( errno ) : "bad stat() size";
362 Debug( LDAP_DEBUG_ANY, "ldif_read_file: %s for \"%s\"\n",
373 * return nonnegative for success or -1 for error
374 * do not return numbers less than -1
377 spew_file( int fd, const char *spew, int len, int *save_errno )
382 writeres = write(fd, spew, len);
385 if (*save_errno != EINTR)
396 /* Write an entry LDIF file. Create parentdir first if non-NULL. */
401 const struct berval *path,
402 const char *parentdir,
405 int rc = LDAP_OTHER, res, save_errno = 0;
406 int fd, entry_length;
407 char *entry_as_string, *tmpfname;
410 return SLAPD_ABANDON;
412 if ( parentdir != NULL && mkdir( parentdir, 0750 ) < 0 ) {
414 Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s \"%s\": %s\n",
415 "cannot create parent directory",
416 parentdir, STRERROR( save_errno ) );
417 *text = "internal error (cannot create parent directory)";
421 tmpfname = ldif_tempname( path );
422 fd = tmpfname == NULL ? -1 : mkstemp( tmpfname );
425 Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s for \"%s\": %s\n",
426 "cannot create file", e->e_dn, STRERROR( save_errno ) );
427 *text = "internal error (cannot create file)";
430 ber_len_t dn_len = e->e_name.bv_len;
433 /* Only save the RDN onto disk */
434 dnRdn( &e->e_name, &rdn );
435 if ( rdn.bv_len != dn_len ) {
436 e->e_name.bv_val[rdn.bv_len] = '\0';
437 e->e_name.bv_len = rdn.bv_len;
441 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
442 entry_as_string = entry2str( e, &entry_length );
443 if ( entry_as_string != NULL )
444 res = spew_file( fd, entry_as_string, entry_length, &save_errno );
445 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
447 /* Restore full DN */
448 if ( rdn.bv_len != dn_len ) {
449 e->e_name.bv_val[rdn.bv_len] = ',';
450 e->e_name.bv_len = dn_len;
453 if ( close( fd ) < 0 && res >= 0 ) {
459 if ( move_file( tmpfname, path->bv_val ) == 0 ) {
460 Debug( LDAP_DEBUG_TRACE, "ldif_write_entry: "
461 "wrote entry \"%s\"\n", e->e_name.bv_val, 0, 0 );
465 Debug( LDAP_DEBUG_ANY, "ldif_write_entry: "
466 "could not put entry file for \"%s\" in place: %s\n",
467 e->e_name.bv_val, STRERROR( save_errno ), 0 );
468 *text = "internal error (could not put entry file in place)";
470 } else if ( res == -1 ) {
471 Debug( LDAP_DEBUG_ANY, "ldif_write_entry: %s \"%s\": %s\n",
472 "write error to", tmpfname, STRERROR( save_errno ) );
473 *text = "internal error (write error to entry file)";
476 if ( rc != LDAP_SUCCESS ) {
482 SLAP_FREE( tmpfname );
487 * Read the entry at path, or if entryp==NULL just see if it exists.
488 * pdn and pndn are the parent's DN and normalized DN, or both NULL.
489 * Return an LDAP result code.
502 char *entry_as_string;
505 /* TODO: Does slapd prevent Abandon of Bind as per rfc4511?
506 * If so we need not check for LDAP_REQ_BIND here.
508 if ( op->o_abandon && op->o_tag != LDAP_REQ_BIND )
509 return SLAPD_ABANDON;
511 rc = ldif_read_file( path, entryp ? &entry_as_string : NULL );
515 if ( entryp == NULL )
517 *entryp = entry = str2entry( entry_as_string );
518 SLAP_FREE( entry_as_string );
519 if ( entry == NULL ) {
522 *text = "internal error (cannot parse some entry file)";
525 if ( pdn == NULL || BER_BVISEMPTY( pdn ) )
527 /* Append parent DN to DN from LDIF file */
529 build_new_dn( &entry->e_name, pdn, &rdn, NULL );
530 SLAP_FREE( rdn.bv_val );
531 rdn = entry->e_nname;
532 build_new_dn( &entry->e_nname, pndn, &rdn, NULL );
533 SLAP_FREE( rdn.bv_val );
539 ? "internal error (cannot read some entry file)"
540 : "internal error (cannot stat some entry file)";
548 * Read the operation's entry, or if entryp==NULL just see if it exists.
549 * Return an LDAP result code. May set *text to a message on failure.
550 * If pathp is non-NULL, set it to the entry filename on success.
556 struct berval *pathp,
560 struct berval path, pdn, pndn;
562 dnParent(&op->o_req_dn, &pdn);
563 dnParent(&op->o_req_ndn, &pndn);
564 dn2path( op->o_bd, &op->o_req_ndn, &path );
565 rc = ldif_read_entry( op, path.bv_val, &pdn, &pndn, entryp, text );
567 if ( rc == LDAP_SUCCESS && pathp != NULL ) {
570 SLAP_FREE(path.bv_val);
577 * RDN-named directory entry, with special handling of "attr={num}val" RDNs.
578 * For sorting, filename "attr=val.ldif" is truncated to "attr="val\0ldif",
579 * and filename "attr={num}val.ldif" to "attr={\0um}val.ldif".
580 * Does not sort escaped chars correctly, would need to un-escape them.
582 typedef struct bvlist {
584 char *trunc; /* filename was truncated here */
585 int inum; /* num from "attr={num}" in filename, or INT_MIN */
586 char savech; /* original char at *trunc */
587 char fname; /* variable length array BVL_NAME(bvl) = &fname */
588 # define BVL_NAME(bvl) ((char *) (bvl) + offsetof(bvlist, fname))
589 # define BVL_SIZE(namelen) (sizeof(bvlist) + (namelen))
593 ldif_send_entry( Operation *op, SlapReply *rs, Entry *e, int scope )
595 int rc = LDAP_SUCCESS;
597 if ( scope == LDAP_SCOPE_BASE || scope == LDAP_SCOPE_SUBTREE ) {
599 /* Save the entry for tool mode */
600 struct ldif_tool *tl =
601 &((struct ldif_info *) op->o_bd->be_private)->li_tool;
603 if ( tl->ecount >= tl->elen ) {
604 /* Allocate/grow entries */
605 ID elen = tl->elen ? tl->elen * 2 : ENTRY_BUFF_INCREMENT;
606 Entry **entries = (Entry **) SLAP_REALLOC( tl->entries,
607 sizeof(Entry *) * elen );
608 if ( entries == NULL ) {
609 Debug( LDAP_DEBUG_ANY,
610 "ldif_send_entry: out of memory\n", 0, 0, 0 );
615 tl->entries = entries;
617 tl->entries[tl->ecount++] = e;
621 else if ( !get_manageDSAit( op ) && is_entry_referral( e ) ) {
622 /* Send a continuation reference.
623 * (ldif_back_referrals() handles baseobject referrals.)
624 * Don't check the filter since it's only a candidate.
626 BerVarray refs = get_entry_referrals( op, e );
627 rs->sr_ref = referral_rewrite( refs, &e->e_name, NULL, scope );
629 rc = send_search_reference( op, rs );
630 ber_bvarray_free( rs->sr_ref );
631 ber_bvarray_free( refs );
636 else if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) {
638 rs->sr_attrs = op->ors_attrs;
639 rs->sr_flags = REP_ENTRY_MODIFIABLE;
640 rc = send_search_entry( op, rs );
650 /* Read LDIF directory <path> into <listp>. Set *fname_maxlenp. */
655 const struct berval *path,
657 ber_len_t *fname_maxlenp )
659 int rc = LDAP_SUCCESS;
665 dir_of_path = opendir( path->bv_val );
666 if ( dir_of_path == NULL ) {
667 int save_errno = errno;
668 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
669 int is_rootDSE = (path->bv_len == li->li_base_path.bv_len);
671 /* Absent directory is OK (leaf entry), except the database dir */
672 if ( is_rootDSE || save_errno != ENOENT ) {
673 Debug( LDAP_DEBUG_ANY,
674 "=> ldif_search_entry: failed to opendir \"%s\": %s\n",
675 path->bv_val, STRERROR( save_errno ), 0 );
679 save_errno != ENOENT ? "internal error (bad directory)"
680 : !is_rootDSE ? "internal error (missing directory)"
681 : "internal error (database directory does not exist)";
689 while ( (dir = readdir( dir_of_path )) != NULL ) {
692 char *trunc, *idxp, *endp, *endp2;
694 fname_len = strlen( dir->d_name );
695 if ( fname_len < STRLENOF( "x=" LDIF )) /* min filename size */
697 if ( strcmp( dir->d_name + fname_len - STRLENOF(LDIF), LDIF ))
700 if ( *fname_maxlenp < fname_len )
701 *fname_maxlenp = fname_len;
703 bvl = SLAP_MALLOC( BVL_SIZE( fname_len ) );
709 strcpy( BVL_NAME( bvl ), dir->d_name );
711 /* Make it sortable by ("attr=val" or <preceding {num}, num>) */
712 trunc = BVL_NAME( bvl ) + fname_len - STRLENOF( LDIF );
713 if ( (idxp = strchr( BVL_NAME( bvl ) + 2, IX_FSL )) != NULL &&
714 (endp = strchr( ++idxp, IX_FSR )) != NULL && endp > idxp &&
715 (eq_unsafe || idxp[-2] == '=' || endp + 1 == trunc) )
717 /* attr={n}val or bconfig.c's "pseudo-indexed" attr=val{n} */
718 bvl->inum = strtol( idxp, &endp2, 10 );
719 if ( endp2 == endp ) {
727 bvl->savech = *trunc;
730 for ( prev = listp; (ptr = *prev) != NULL; prev = &ptr->next ) {
731 int cmp = strcmp( BVL_NAME( bvl ), BVL_NAME( ptr ));
732 if ( cmp < 0 || (cmp == 0 && bvl->inum < ptr->inum) )
739 if ( closedir( dir_of_path ) < 0 ) {
743 rs->sr_text = "internal error (bad directory)";
745 if ( rc != LDAP_SUCCESS ) {
746 Debug( LDAP_DEBUG_ANY, "ldif_search_entry: %s \"%s\": %s\n",
747 "error reading directory", path->bv_val,
748 STRERROR( save_errno ) );
756 * Send an entry, recursively search its children, and free or save it.
757 * Return an LDAP result code. Parameters:
758 * op, rs operation and reply. rs == NULL for slap tools.
759 * e entry to search, or NULL for rootDSE.
760 * scope scope for the part of the search from this entry.
761 * path LDIF filename -- bv_len and non-directory part are overwritten.
769 struct berval *path )
771 int rc = LDAP_SUCCESS;
772 struct berval dn = BER_BVC( "" ), ndn = BER_BVC( "" );
774 if ( scope != LDAP_SCOPE_BASE && e != NULL ) {
775 /* Copy DN/NDN since we send the entry with REP_ENTRY_MODIFIABLE,
776 * which bconfig.c seems to need. (TODO: see config_rename_one.)
778 if ( ber_dupbv( &dn, &e->e_name ) == NULL ||
779 ber_dupbv( &ndn, &e->e_nname ) == NULL )
781 Debug( LDAP_DEBUG_ANY,
782 "ldif_search_entry: out of memory\n", 0, 0, 0 );
788 /* Send the entry if appropriate, and free or save it */
790 rc = ldif_send_entry( op, rs, e, scope );
792 /* Search the children */
793 if ( scope != LDAP_SCOPE_BASE && rc == LDAP_SUCCESS ) {
795 struct berval fpath; /* becomes child pathname */
796 char *dir_end; /* will point past dirname in fpath */
798 ldif2dir_len( *path );
799 ldif2dir_name( *path );
800 rc = ldif_readdir( op, rs, path, &list, &fpath.bv_len );
802 if ( list != NULL ) {
803 const char **text = rs == NULL ? NULL : &rs->sr_text;
805 if ( scope == LDAP_SCOPE_ONELEVEL )
806 scope = LDAP_SCOPE_BASE;
807 else if ( scope == LDAP_SCOPE_SUBORDINATE )
808 scope = LDAP_SCOPE_SUBTREE;
810 /* Allocate fpath and fill in directory part */
811 dir_end = fullpath_alloc( &fpath, path, fpath.bv_len );
812 if ( dir_end == NULL )
818 if ( rc == LDAP_SUCCESS ) {
819 *ptr->trunc = ptr->savech;
820 FILL_PATH( &fpath, dir_end, BVL_NAME( ptr ));
822 rc = ldif_read_entry( op, fpath.bv_val, &dn, &ndn,
826 rc = ldif_search_entry( op, rs, e, scope, &fpath );
828 case LDAP_NO_SUCH_OBJECT:
829 /* Only the search baseDN may produce noSuchObject. */
832 rs->sr_text = "internal error "
833 "(did someone just remove an entry file?)";
834 Debug( LDAP_DEBUG_ANY, "ldif_search_entry: "
835 "file listed in parent directory does not exist: "
836 "\"%s\"\n", fpath.bv_val, 0, 0 );
843 } while ( list != NULL );
845 if ( !BER_BVISNULL( &fpath ) )
846 SLAP_FREE( fpath.bv_val );
851 if ( !BER_BVISEMPTY( &dn ) )
852 ber_memfree( dn.bv_val );
853 if ( !BER_BVISEMPTY( &ndn ) )
854 ber_memfree( ndn.bv_val );
859 search_tree( Operation *op, SlapReply *rs )
861 int rc = LDAP_SUCCESS;
864 struct berval pdn, pndn;
866 dn2path( op->o_bd, &op->o_req_ndn, &path );
867 if ( !BER_BVISEMPTY( &op->o_req_ndn ) ) {
868 /* Read baseObject */
869 dnParent( &op->o_req_dn, &pdn );
870 dnParent( &op->o_req_ndn, &pndn );
871 rc = ldif_read_entry( op, path.bv_val, &pdn, &pndn, &e,
872 rs == NULL ? NULL : &rs->sr_text );
874 if ( rc == LDAP_SUCCESS )
875 rc = ldif_search_entry( op, rs, e, op->ors_scope, &path );
877 ch_free( path.bv_val );
883 * Prepare to create or rename an entry:
884 * Check that the entry does not already exist.
885 * Check that the parent entry exists and can have subordinates,
886 * unless need_dir is NULL or adding the suffix entry.
888 * Return an LDAP result code. May set *text to a message on failure.
889 * If success, set *dnpath to LDIF entry path and *need_dir to
890 * (directory must be created ? dirname : NULL).
896 struct berval *dnpath,
900 BackendDB *be = op->o_bd;
901 struct ldif_info *li = (struct ldif_info *) be->be_private;
902 struct berval *ndn = &e->e_nname;
903 struct berval ppath = BER_BVNULL;
905 Entry *parent = NULL;
906 int rc = LDAP_SUCCESS;
909 return SLAPD_ABANDON;
911 dn2path( be, ndn, dnpath );
913 if ( stat( dnpath->bv_val, &st ) == 0 ) { /* entry .ldif file */
914 rc = LDAP_ALREADY_EXISTS;
916 } else if ( errno != ENOENT ) {
917 Debug( LDAP_DEBUG_ANY,
918 "ldif_prepare_create: cannot stat \"%s\": %s\n",
919 dnpath->bv_val, STRERROR( errno ), 0 );
921 *text = "internal error (cannot check entry file)";
923 } else if ( need_dir != NULL ) {
925 rc = get_parent_path( dnpath, &ppath );
926 /* If parent dir exists, so does parent .ldif:
927 * The directory gets created after and removed before the .ldif.
928 * Except with the database directory, which has no matching entry.
930 if ( rc == LDAP_SUCCESS && stat( ppath.bv_val, &st ) < 0 ) {
931 rc = errno == ENOENT && ppath.bv_len > li->li_base_path.bv_len
932 ? LDAP_NO_SUCH_OBJECT : LDAP_OTHER;
935 case LDAP_NO_SUCH_OBJECT:
936 /* No parent dir, check parent .ldif */
937 dir2ldif_name( ppath );
938 rc = ldif_read_entry( op, ppath.bv_val, NULL, NULL,
939 (op->o_tag != LDAP_REQ_ADD || get_manageDSAit( op )
944 /* Check that parent is not a referral, unless
945 * ldif_back_referrals() already checked.
947 if ( parent != NULL ) {
948 int is_ref = is_entry_referral( parent );
949 entry_free( parent );
951 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
952 *text = op->o_tag == LDAP_REQ_MODDN
953 ? "newSuperior is a referral object"
954 : "parent is a referral object";
958 /* Must create parent directory. */
959 ldif2dir_name( ppath );
960 *need_dir = ppath.bv_val;
962 case LDAP_NO_SUCH_OBJECT:
963 *text = op->o_tag == LDAP_REQ_MODDN
964 ? "newSuperior object does not exist"
965 : "parent does not exist";
970 Debug( LDAP_DEBUG_ANY,
971 "ldif_prepare_create: cannot stat \"%s\" parent dir: %s\n",
972 ndn->bv_val, STRERROR( errno ), 0 );
973 *text = "internal error (cannot stat parent dir)";
976 if ( *need_dir == NULL && ppath.bv_val != NULL )
977 SLAP_FREE( ppath.bv_val );
980 if ( rc != LDAP_SUCCESS ) {
981 SLAP_FREE( dnpath->bv_val );
982 BER_BVZERO( dnpath );
987 static int apply_modify_to_entry(Entry * entry,
988 Modifications * modlist,
992 char textbuf[SLAP_TEXT_BUFLEN];
993 int rc = modlist ? LDAP_UNWILLING_TO_PERFORM : LDAP_SUCCESS;
997 if (!acl_check_modlist(op, entry, modlist)) {
998 return LDAP_INSUFFICIENT_ACCESS;
1001 for (; modlist != NULL; modlist = modlist->sml_next) {
1002 mods = &modlist->sml_mod;
1004 if ( mods->sm_desc == slap_schema.si_ad_objectClass ) {
1007 switch (mods->sm_op) {
1009 rc = modify_add_values(entry, mods,
1010 get_permissiveModify(op),
1011 &rs->sr_text, textbuf,
1012 sizeof( textbuf ) );
1015 case LDAP_MOD_DELETE:
1016 rc = modify_delete_values(entry, mods,
1017 get_permissiveModify(op),
1018 &rs->sr_text, textbuf,
1019 sizeof( textbuf ) );
1022 case LDAP_MOD_REPLACE:
1023 rc = modify_replace_values(entry, mods,
1024 get_permissiveModify(op),
1025 &rs->sr_text, textbuf,
1026 sizeof( textbuf ) );
1029 case LDAP_MOD_INCREMENT:
1030 rc = modify_increment_values( entry,
1031 mods, get_permissiveModify(op),
1032 &rs->sr_text, textbuf,
1033 sizeof( textbuf ) );
1036 case SLAP_MOD_SOFTADD:
1037 mods->sm_op = LDAP_MOD_ADD;
1038 rc = modify_add_values(entry, mods,
1039 get_permissiveModify(op),
1040 &rs->sr_text, textbuf,
1041 sizeof( textbuf ) );
1042 mods->sm_op = SLAP_MOD_SOFTADD;
1043 if (rc == LDAP_TYPE_OR_VALUE_EXISTS) {
1048 if(rc != LDAP_SUCCESS) break;
1051 if ( rc == LDAP_SUCCESS ) {
1052 rs->sr_text = NULL; /* Needed at least with SLAP_MOD_SOFTADD */
1054 entry->e_ocflags = 0;
1056 /* check that the entry still obeys the schema */
1057 rc = entry_schema_check( op, entry, NULL, 0, 0,
1058 &rs->sr_text, textbuf, sizeof( textbuf ) );
1066 ldif_back_referrals( Operation *op, SlapReply *rs )
1068 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1069 struct berval path, dn = op->o_req_dn, ndn = op->o_req_ndn;
1070 ber_len_t min_dnlen;
1071 Entry *entry = NULL, **entryp;
1075 min_dnlen = op->o_bd->be_nsuffix[0].bv_len;
1076 if ( min_dnlen == 0 ) {
1077 /* Catch root DSE (empty DN), it is not a referral */
1079 if ( BER_BVISEMPTY( &ndn ) )
1080 return LDAP_SUCCESS;
1083 entryp = get_manageDSAit( op ) ? NULL : &entry;
1084 dn2path( op->o_bd, &ndn, &path );
1085 ldap_pvt_thread_rdwr_rlock( &li->li_rdwr );
1088 dnParent( &dn, &dn );
1089 dnParent( &ndn, &ndn );
1090 rc = ldif_read_entry( op, path.bv_val, &dn, &ndn,
1091 entryp, &rs->sr_text );
1092 if ( rc != LDAP_NO_SUCH_OBJECT )
1096 if ( ndn.bv_len < min_dnlen )
1098 (void) get_parent_path( &path, NULL );
1099 dir2ldif_name( path );
1103 ldap_pvt_thread_rdwr_runlock( &li->li_rdwr );
1104 SLAP_FREE( path.bv_val );
1106 if ( entry != NULL ) {
1107 if ( is_entry_referral( entry ) ) {
1108 Debug( LDAP_DEBUG_TRACE,
1109 "ldif_back_referrals: tag=%lu target=\"%s\" matched=\"%s\"\n",
1110 (unsigned long) op->o_tag, op->o_req_dn.bv_val, entry->e_dn );
1112 ref = get_entry_referrals( op, entry );
1113 rs->sr_ref = referral_rewrite( ref, &entry->e_name, &op->o_req_dn,
1114 op->o_tag == LDAP_REQ_SEARCH ?
1115 op->ors_scope : LDAP_SCOPE_DEFAULT );
1116 ber_bvarray_free( ref );
1118 if ( rs->sr_ref != NULL ) {
1120 rc = rs->sr_err = LDAP_REFERRAL;
1121 rs->sr_matched = entry->e_dn;
1122 send_ldap_result( op, rs );
1123 ber_bvarray_free( rs->sr_ref );
1127 rs->sr_text = "bad referral object";
1129 rs->sr_matched = NULL;
1132 entry_free( entry );
1139 /* LDAP operations */
1142 ldif_back_bind( Operation *op, SlapReply *rs )
1144 struct ldif_info *li;
1146 AttributeDescription *password = slap_schema.si_ad_userPassword;
1148 Entry *entry = NULL;
1150 switch ( be_rootdn_bind( op, rs ) ) {
1151 case SLAP_CB_CONTINUE:
1155 /* in case of success, front end will send result;
1156 * otherwise, be_rootdn_bind() did */
1160 li = (struct ldif_info *) op->o_bd->be_private;
1161 ldap_pvt_thread_rdwr_rlock(&li->li_rdwr);
1162 return_val = get_entry(op, &entry, NULL, NULL);
1164 /* no object is found for them */
1165 if(return_val != LDAP_SUCCESS) {
1166 rs->sr_err = return_val = LDAP_INVALID_CREDENTIALS;
1170 /* they don't have userpassword */
1171 if((a = attr_find(entry->e_attrs, password)) == NULL) {
1172 rs->sr_err = LDAP_INAPPROPRIATE_AUTH;
1177 /* authentication actually failed */
1178 if(slap_passwd_check(op, entry, a, &op->oq_bind.rb_cred,
1179 &rs->sr_text) != 0) {
1180 rs->sr_err = LDAP_INVALID_CREDENTIALS;
1185 /* let the front-end send success */
1190 ldap_pvt_thread_rdwr_runlock(&li->li_rdwr);
1192 send_ldap_result( op, rs );
1198 static int ldif_back_search(Operation *op, SlapReply *rs)
1200 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1202 ldap_pvt_thread_rdwr_rlock(&li->li_rdwr);
1203 rs->sr_err = search_tree( op, rs );
1204 ldap_pvt_thread_rdwr_runlock(&li->li_rdwr);
1205 send_ldap_result(op, rs);
1210 static int ldif_back_add(Operation *op, SlapReply *rs) {
1211 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1212 Entry * e = op->ora_e;
1215 char textbuf[SLAP_TEXT_BUFLEN];
1218 Debug( LDAP_DEBUG_TRACE, "ldif_back_add: \"%s\"\n", e->e_dn, 0, 0 );
1220 rc = entry_schema_check( op, e, NULL, 0, 1,
1221 &rs->sr_text, textbuf, sizeof( textbuf ) );
1222 if ( rc != LDAP_SUCCESS )
1225 rc = slap_add_opattrs( op, &rs->sr_text, textbuf, sizeof( textbuf ), 1 );
1226 if ( rc != LDAP_SUCCESS )
1229 ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
1231 rc = ldif_prepare_create( op, e, &path, &parentdir, &rs->sr_text );
1232 if ( rc == LDAP_SUCCESS ) {
1233 rc = ldif_write_entry( op, e, &path, parentdir, &rs->sr_text );
1234 SLAP_FREE( path.bv_val );
1235 if ( parentdir != NULL )
1236 SLAP_FREE( parentdir );
1239 ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
1243 Debug( LDAP_DEBUG_TRACE, "ldif_back_add: err: %d text: %s\n",
1244 rc, rs->sr_text ? rs->sr_text : "", 0 );
1245 send_ldap_result(op, rs);
1246 slap_graduate_commit_csn( op );
1250 static int ldif_back_modify(Operation *op, SlapReply *rs) {
1251 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1252 Modifications * modlst = op->orm_modlist;
1257 slap_mods_opattrs( op, &op->orm_modlist, 1 );
1259 ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
1261 rc = get_entry( op, &entry, &path, &rs->sr_text );
1262 if ( rc == LDAP_SUCCESS ) {
1263 rc = apply_modify_to_entry( entry, modlst, op, rs );
1264 if ( rc == LDAP_SUCCESS ) {
1265 rc = ldif_write_entry( op, entry, &path, NULL, &rs->sr_text );
1268 entry_free( entry );
1269 SLAP_FREE( path.bv_val );
1272 ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
1275 send_ldap_result( op, rs );
1276 slap_graduate_commit_csn( op );
1281 ldif_back_delete( Operation *op, SlapReply *rs )
1283 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1285 int rc = LDAP_SUCCESS;
1287 if ( BER_BVISEMPTY( &op->o_csn )) {
1289 char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
1291 csn.bv_val = csnbuf;
1292 csn.bv_len = sizeof( csnbuf );
1293 slap_get_csn( op, &csn, 1 );
1296 ldap_pvt_thread_rdwr_wlock(&li->li_rdwr);
1297 if ( op->o_abandon ) {
1302 dn2path( op->o_bd, &op->o_req_ndn, &path );
1303 ldif2dir_len( path );
1304 ldif2dir_name( path );
1305 if ( rmdir( path.bv_val ) < 0 ) {
1308 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
1311 /* is leaf, go on */
1315 rs->sr_text = "internal error (cannot delete subtree directory)";
1320 if ( rc == LDAP_SUCCESS ) {
1321 dir2ldif_name( path );
1322 if ( unlink( path.bv_val ) < 0 ) {
1323 rc = LDAP_NO_SUCH_OBJECT;
1324 if ( errno != ENOENT ) {
1326 rs->sr_text = "internal error (cannot delete entry file)";
1331 if ( rc == LDAP_OTHER ) {
1332 Debug( LDAP_DEBUG_ANY, "ldif_back_delete: %s \"%s\": %s\n",
1333 "cannot delete", path.bv_val, STRERROR( errno ) );
1336 SLAP_FREE(path.bv_val);
1338 ldap_pvt_thread_rdwr_wunlock(&li->li_rdwr);
1340 send_ldap_result( op, rs );
1341 slap_graduate_commit_csn( op );
1350 struct berval *oldpath,
1353 struct berval newpath;
1354 char *parentdir = NULL, *trash;
1357 rc = ldif_prepare_create( op, entry, &newpath,
1358 op->orr_newSup ? &parentdir : NULL, text );
1360 if ( rc == LDAP_SUCCESS ) {
1361 rc = ldif_write_entry( op, entry, &newpath, parentdir, text );
1362 if ( rc == LDAP_SUCCESS ) {
1363 trash = oldpath->bv_val; /* will be .ldif file to delete */
1364 ldif2dir_len( newpath );
1365 ldif2dir_len( *oldpath );
1366 /* Move subdir before deleting old entry,
1367 * so .ldif always exists if subdir does.
1369 ldif2dir_name( newpath );
1370 ldif2dir_name( *oldpath );
1371 rename_res = move_dir( oldpath->bv_val, newpath.bv_val );
1372 if ( rename_res != 0 && errno != ENOENT ) {
1374 *text = "internal error (cannot move this subtree)";
1375 trash = newpath.bv_val;
1378 /* Delete old entry, or if error undo change */
1380 dir2ldif_name( newpath );
1381 dir2ldif_name( *oldpath );
1382 if ( unlink( trash ) == 0 )
1384 if ( rc == LDAP_SUCCESS ) {
1385 /* Prepare to undo change and return failure */
1387 *text = "internal error (cannot move this entry)";
1388 trash = newpath.bv_val;
1389 if ( rename_res != 0 )
1391 /* First move subdirectory back */
1392 ldif2dir_name( newpath );
1393 ldif2dir_name( *oldpath );
1394 if ( move_dir( newpath.bv_val, oldpath->bv_val ) == 0 )
1397 *text = "added new but couldn't delete old entry!";
1401 if ( rc != LDAP_SUCCESS ) {
1403 snprintf( s, sizeof s, "%s (%s)", *text, STRERROR( errno ));
1404 Debug( LDAP_DEBUG_ANY,
1405 "ldif_move_entry: %s: \"%s\" -> \"%s\"\n",
1406 s, op->o_req_dn.bv_val, entry->e_dn );
1410 SLAP_FREE( newpath.bv_val );
1411 if ( parentdir != NULL )
1412 SLAP_FREE( parentdir );
1419 ldif_back_modrdn(Operation *op, SlapReply *rs)
1421 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1422 struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
1423 struct berval p_dn, old_path;
1427 slap_mods_opattrs( op, &op->orr_modlist, 1 );
1429 ldap_pvt_thread_rdwr_wlock( &li->li_rdwr );
1431 rc = get_entry( op, &entry, &old_path, &rs->sr_text );
1432 if ( rc == LDAP_SUCCESS ) {
1433 /* build new dn, and new ndn for the entry */
1434 if ( op->oq_modrdn.rs_newSup != NULL ) {
1435 p_dn = *op->oq_modrdn.rs_newSup;
1437 dnParent( &entry->e_name, &p_dn );
1439 build_new_dn( &new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL );
1440 dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
1441 ber_memfree_x( entry->e_name.bv_val, NULL );
1442 ber_memfree_x( entry->e_nname.bv_val, NULL );
1443 entry->e_name = new_dn;
1444 entry->e_nname = new_ndn;
1446 /* perform the modifications */
1447 rc = apply_modify_to_entry( entry, op->orr_modlist, op, rs );
1448 if ( rc == LDAP_SUCCESS )
1449 rc = ldif_move_entry( op, entry, &old_path, &rs->sr_text );
1451 entry_free( entry );
1452 SLAP_FREE( old_path.bv_val );
1455 ldap_pvt_thread_rdwr_wunlock( &li->li_rdwr );
1457 send_ldap_result( op, rs );
1458 slap_graduate_commit_csn( op );
1463 /* Return LDAP_SUCCESS IFF we retrieve the specified entry. */
1465 ldif_back_entry_get(
1469 AttributeDescription *at,
1473 struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
1474 struct berval op_dn = op->o_req_dn, op_ndn = op->o_req_ndn;
1477 assert( ndn != NULL );
1478 assert( !BER_BVISNULL( ndn ) );
1480 ldap_pvt_thread_rdwr_rlock( &li->li_rdwr );
1481 op->o_req_dn = *ndn;
1482 op->o_req_ndn = *ndn;
1483 rc = get_entry( op, e, NULL, NULL );
1484 op->o_req_dn = op_dn;
1485 op->o_req_ndn = op_ndn;
1486 ldap_pvt_thread_rdwr_runlock( &li->li_rdwr );
1488 if ( rc == LDAP_SUCCESS && oc && !is_entry_objectclass_or_sub( *e, oc ) ) {
1489 rc = LDAP_NO_SUCH_ATTRIBUTE;
1500 static int ldif_tool_entry_open(BackendDB *be, int mode) {
1501 struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool;
1507 static int ldif_tool_entry_close(BackendDB * be) {
1508 struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool;
1509 Entry **entries = tl->entries;
1512 for ( i = tl->ecount; i--; )
1514 entry_free( entries[i] );
1515 SLAP_FREE( entries );
1517 tl->ecount = tl->elen = 0;
1521 static ID ldif_tool_entry_next(BackendDB *be)
1523 struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool;
1525 if ( tl->ecurrent >= tl->ecount )
1528 return ++tl->ecurrent;
1532 ldif_tool_entry_first(BackendDB *be)
1534 struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool;
1536 if ( tl->entries == NULL ) {
1540 op.o_req_dn = *be->be_suffix;
1541 op.o_req_ndn = *be->be_nsuffix;
1542 op.ors_scope = LDAP_SCOPE_SUBTREE;
1543 if ( search_tree( &op, NULL ) != LDAP_SUCCESS ) {
1544 tl->ecurrent = tl->ecount; /* fail ldif_tool_entry_next() */
1545 return 0; /* fail ldif_tool_entry_get() */
1548 return ldif_tool_entry_next( be );
1551 static Entry * ldif_tool_entry_get(BackendDB * be, ID id) {
1552 struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool;
1556 if ( id < tl->ecount ) {
1557 e = tl->entries[id];
1558 tl->entries[id] = NULL;
1564 ldif_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
1567 const char *errmsg = NULL;
1573 rc = ldif_prepare_create( &op, e, &path, &parentdir, &errmsg );
1574 if ( rc == LDAP_SUCCESS ) {
1575 rc = ldif_write_entry( &op, e, &path, parentdir, &errmsg );
1577 SLAP_FREE( path.bv_val );
1578 if ( parentdir != NULL )
1579 SLAP_FREE( parentdir );
1580 if ( rc == LDAP_SUCCESS )
1584 if ( errmsg == NULL && rc != LDAP_OTHER )
1585 errmsg = ldap_err2string( rc );
1586 if ( errmsg != NULL )
1587 snprintf( text->bv_val, text->bv_len, "%s", errmsg );
1595 ldif_back_db_init( BackendDB *be, ConfigReply *cr )
1597 struct ldif_info *li;
1599 li = ch_calloc( 1, sizeof(struct ldif_info) );
1600 be->be_private = li;
1601 be->be_cf_ocs = ldifocs;
1602 ldap_pvt_thread_rdwr_init(&li->li_rdwr);
1603 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_ONE_SUFFIX;
1608 ldif_back_db_destroy( Backend *be, ConfigReply *cr )
1610 struct ldif_info *li = be->be_private;
1612 ch_free(li->li_base_path.bv_val);
1613 ldap_pvt_thread_rdwr_destroy(&li->li_rdwr);
1614 free( be->be_private );
1619 ldif_back_db_open( Backend *be, ConfigReply *cr)
1621 struct ldif_info *li = (struct ldif_info *) be->be_private;
1622 if( BER_BVISEMPTY(&li->li_base_path)) {/* missing base path */
1623 Debug( LDAP_DEBUG_ANY, "missing base path for back-ldif\n", 0, 0, 0);
1630 ldif_back_initialize(
1634 static char *controls[] = {
1635 LDAP_CONTROL_MANAGEDSAIT,
1641 SLAP_BFLAG_INCREMENT |
1642 SLAP_BFLAG_REFERRALS;
1644 bi->bi_controls = controls;
1651 bi->bi_db_init = ldif_back_db_init;
1652 bi->bi_db_config = config_generic_wrapper;
1653 bi->bi_db_open = ldif_back_db_open;
1654 bi->bi_db_close = 0;
1655 bi->bi_db_destroy = ldif_back_db_destroy;
1657 bi->bi_op_bind = ldif_back_bind;
1658 bi->bi_op_unbind = 0;
1659 bi->bi_op_search = ldif_back_search;
1660 bi->bi_op_compare = 0;
1661 bi->bi_op_modify = ldif_back_modify;
1662 bi->bi_op_modrdn = ldif_back_modrdn;
1663 bi->bi_op_add = ldif_back_add;
1664 bi->bi_op_delete = ldif_back_delete;
1665 bi->bi_op_abandon = 0;
1667 bi->bi_extended = 0;
1669 bi->bi_chk_referrals = ldif_back_referrals;
1671 bi->bi_connection_init = 0;
1672 bi->bi_connection_destroy = 0;
1674 bi->bi_entry_get_rw = ldif_back_entry_get;
1676 #if 0 /* NOTE: uncomment to completely disable access control */
1677 bi->bi_access_allowed = slap_access_always_allowed;
1680 bi->bi_tool_entry_open = ldif_tool_entry_open;
1681 bi->bi_tool_entry_close = ldif_tool_entry_close;
1682 bi->bi_tool_entry_first = ldif_tool_entry_first;
1683 bi->bi_tool_entry_next = ldif_tool_entry_next;
1684 bi->bi_tool_entry_get = ldif_tool_entry_get;
1685 bi->bi_tool_entry_put = ldif_tool_entry_put;
1686 bi->bi_tool_entry_reindex = 0;
1687 bi->bi_tool_sync = 0;
1689 bi->bi_tool_dn2id_get = 0;
1690 bi->bi_tool_entry_modify = 0;
1692 bi->bi_cf_ocs = ldifocs;
1694 rc = config_register_schema( ldifcfg, ldifocs );
1695 if ( rc ) return rc;