From: Ondrej Kuznik Date: Thu, 19 Apr 2012 13:29:57 +0000 (+0200) Subject: ITS#7212 slapmodify support for back-ldif X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8e19583bc20bbbe84a321e28fe353756833d6424;p=openldap ITS#7212 slapmodify support for back-ldif --- diff --git a/servers/slapd/back-ldif/ldif.c b/servers/slapd/back-ldif/ldif.c index 1f37649af5..f4671a4ac3 100644 --- a/servers/slapd/back-ldif/ldif.c +++ b/servers/slapd/back-ldif/ldif.c @@ -759,6 +759,7 @@ ldif_send_entry( Operation *op, SlapReply *rs, Entry *e, int scope ) tl->entries = entries; } tl->entries[tl->ecount++] = e; + e->e_id = tl->ecount; return rc; } @@ -1706,6 +1707,30 @@ ldif_back_entry_get( return rc; } +static int +ldif_back_entry_release_rw ( + Operation *op, + Entry *e, + int rw ) +{ + ID id = e->e_id; + + /* only tool mode assigns valid IDs */ + if ( id != 0 && id != NOID ) + { + struct ldif_tool *tl = &((struct ldif_info *) op->o_bd->be_private)->li_tool; + + id--; + + assert( id < tl->ecount ); + assert( e == tl->entries[id] ); + tl->entries[id] = NULL; + } + + entry_free( e ); + return 0; +} + /* Slap tools */ @@ -1786,6 +1811,23 @@ ldif_tool_entry_first_x( BackendDB *be, struct berval *base, int scope, Filter * return ldif_tool_entry_next( be ); } +static ID +ldif_tool_dn2id_get( BackendDB *be, struct berval *dn ) +{ + struct ldif_tool *tl = &((struct ldif_info *) be->be_private)->li_tool; + + Operation op = {0}; + + op.o_bd = be; + op.o_req_dn = *dn; + op.o_req_ndn = *dn; + op.ors_scope = LDAP_SCOPE_BASE; + if ( search_tree( &op, NULL ) != LDAP_SUCCESS ) { + return NOID; + } + return tl->ecount; +} + static Entry * ldif_tool_entry_get( BackendDB *be, ID id ) { @@ -1795,7 +1837,6 @@ ldif_tool_entry_get( BackendDB *be, ID id ) --id; if ( id < tl->ecount ) { e = tl->entries[id]; - tl->entries[id] = NULL; } return e; } @@ -1828,6 +1869,28 @@ ldif_tool_entry_put( BackendDB *be, Entry *e, struct berval *text ) return NOID; } +static ID +ldif_tool_entry_modify( BackendDB *be, Entry *e, struct berval *text ) +{ + int rc; + const char *errmsg = NULL; + struct berval path; + Operation op = {0}; + + op.o_bd = be; + ndn2path( &op, &e->e_nname, &path, 0 ); + rc = ldif_write_entry( &op, e, &path, NULL, &errmsg ); + SLAP_FREE( path.bv_val ); + if ( rc == LDAP_SUCCESS ) + return 1; + + if ( errmsg == NULL && rc != LDAP_OTHER ) + errmsg = ldap_err2string( rc ); + if ( errmsg != NULL ) + snprintf( text->bv_val, text->bv_len, "%s", errmsg ); + return NOID; +} + /* Setup */ @@ -1912,6 +1975,7 @@ ldif_back_initialize( BackendInfo *bi ) bi->bi_connection_destroy = 0; bi->bi_entry_get_rw = ldif_back_entry_get; + bi->bi_entry_release_rw = ldif_back_entry_release_rw; #if 0 /* NOTE: uncomment to completely disable access control */ bi->bi_access_allowed = slap_access_always_allowed; @@ -1922,14 +1986,13 @@ ldif_back_initialize( BackendInfo *bi ) bi->bi_tool_entry_first = backend_tool_entry_first; bi->bi_tool_entry_first_x = ldif_tool_entry_first_x; bi->bi_tool_entry_next = ldif_tool_entry_next; + bi->bi_tool_dn2id_get = ldif_tool_dn2id_get; bi->bi_tool_entry_get = ldif_tool_entry_get; bi->bi_tool_entry_put = ldif_tool_entry_put; + bi->bi_tool_entry_modify = ldif_tool_entry_modify; bi->bi_tool_entry_reindex = 0; bi->bi_tool_sync = 0; - bi->bi_tool_dn2id_get = 0; - bi->bi_tool_entry_modify = 0; - bi->bi_cf_ocs = ldifocs; rc = config_register_schema( ldifcfg, ldifocs );