Author: vlendec Date: 2007-05-29 18:04:38 +0000 (Tue, 29 May 2007) New Revision: 23220
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23220 Log: Add traverse_read to dbwrap Modified: branches/SAMBA_3_0/source/include/dbwrap.h branches/SAMBA_3_0/source/lib/dbwrap_file.c branches/SAMBA_3_0/source/lib/dbwrap_tdb.c branches/SAMBA_3_0/source/smbd/session.c branches/SAMBA_3_0_26/source/include/dbwrap.h branches/SAMBA_3_0_26/source/lib/dbwrap_file.c branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c branches/SAMBA_3_0_26/source/smbd/session.c Changeset: Modified: branches/SAMBA_3_0/source/include/dbwrap.h =================================================================== --- branches/SAMBA_3_0/source/include/dbwrap.h 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0/source/include/dbwrap.h 2007-05-29 18:04:38 UTC (rev 23220) @@ -38,6 +38,10 @@ int (*f)(struct db_record *db, void *private_data), void *private_data); + int (*traverse_read)(struct db_context *db, + int (*f)(struct db_record *db, + void *private_data), + void *private_data); int (*get_seqnum)(struct db_context *db); void *private_data; }; Modified: branches/SAMBA_3_0/source/lib/dbwrap_file.c =================================================================== --- branches/SAMBA_3_0/source/lib/dbwrap_file.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0/source/lib/dbwrap_file.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -367,6 +367,7 @@ result->private_data = ctx; result->fetch_locked = db_file_fetch_locked; result->traverse = db_file_traverse; + result->traverse_read = db_file_traverse; ctx->locked_record = NULL; if (!(ctx->dirname = talloc_strdup(ctx, name))) { Modified: branches/SAMBA_3_0/source/lib/dbwrap_tdb.c =================================================================== --- branches/SAMBA_3_0/source/lib/dbwrap_tdb.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0/source/lib/dbwrap_tdb.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -174,6 +174,46 @@ return tdb_traverse(db_ctx->tdb, db_tdb_traverse_func, &ctx); } +static NTSTATUS db_tdb_store_deny(struct db_record *rec, TDB_DATA data, int flag) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static NTSTATUS db_tdb_delete_deny(struct db_record *rec) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static int db_tdb_traverse_read_func(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) +{ + struct db_tdb_traverse_ctx *ctx = + (struct db_tdb_traverse_ctx *)private_data; + struct db_record rec; + + rec.key = kbuf; + rec.value = dbuf; + rec.store = db_tdb_store_deny; + rec.delete_rec = db_tdb_delete_deny; + rec.private_data = ctx->db->private_data; + + return ctx->f(&rec, ctx->private_data); +} + +static int db_tdb_traverse_read(struct db_context *db, + int (*f)(struct db_record *rec, void *private_data), + void *private_data) +{ + struct db_tdb_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb_ctx); + struct db_tdb_traverse_ctx ctx; + + ctx.db = db; + ctx.f = f; + ctx.private_data = private_data; + return tdb_traverse_read(db_ctx->tdb, db_tdb_traverse_read_func, &ctx); +} + static int db_tdb_get_seqnum(struct db_context *db) { @@ -222,6 +262,7 @@ talloc_set_destructor(db_tdb, db_tdb_ctx_destr); result->fetch_locked = db_tdb_fetch_locked; result->traverse = db_tdb_traverse; + result->traverse_read = db_tdb_traverse_read; result->get_seqnum = db_tdb_get_seqnum; return result; Modified: branches/SAMBA_3_0/source/smbd/session.c =================================================================== --- branches/SAMBA_3_0/source/smbd/session.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0/source/smbd/session.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -275,7 +275,7 @@ return False; } - ctx->traverse(ctx, fn, private_data); + ctx->traverse_read(ctx, fn, private_data); return True; } Modified: branches/SAMBA_3_0_26/source/include/dbwrap.h =================================================================== --- branches/SAMBA_3_0_26/source/include/dbwrap.h 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0_26/source/include/dbwrap.h 2007-05-29 18:04:38 UTC (rev 23220) @@ -38,6 +38,10 @@ int (*f)(struct db_record *db, void *private_data), void *private_data); + int (*traverse_read)(struct db_context *db, + int (*f)(struct db_record *db, + void *private_data), + void *private_data); int (*get_seqnum)(struct db_context *db); void *private_data; }; Modified: branches/SAMBA_3_0_26/source/lib/dbwrap_file.c =================================================================== --- branches/SAMBA_3_0_26/source/lib/dbwrap_file.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0_26/source/lib/dbwrap_file.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -367,6 +367,7 @@ result->private_data = ctx; result->fetch_locked = db_file_fetch_locked; result->traverse = db_file_traverse; + result->traverse_read = db_file_traverse; ctx->locked_record = NULL; if (!(ctx->dirname = talloc_strdup(ctx, name))) { Modified: branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c =================================================================== --- branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0_26/source/lib/dbwrap_tdb.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -172,6 +172,46 @@ return tdb_traverse(db_ctx->tdb, db_tdb_traverse_func, &ctx); } +static NTSTATUS db_tdb_store_deny(struct db_record *rec, TDB_DATA data, int flag) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static NTSTATUS db_tdb_delete_deny(struct db_record *rec) +{ + return NT_STATUS_MEDIA_WRITE_PROTECTED; +} + +static int db_tdb_traverse_read_func(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) +{ + struct db_tdb_traverse_ctx *ctx = + (struct db_tdb_traverse_ctx *)private_data; + struct db_record rec; + + rec.key = kbuf; + rec.value = dbuf; + rec.store = db_tdb_store_deny; + rec.delete_rec = db_tdb_delete_deny; + rec.private_data = ctx->db->private_data; + + return ctx->f(&rec, ctx->private_data); +} + +static int db_tdb_traverse_read(struct db_context *db, + int (*f)(struct db_record *rec, void *private_data), + void *private_data) +{ + struct db_tdb_ctx *db_ctx = + talloc_get_type_abort(db->private_data, struct db_tdb_ctx); + struct db_tdb_traverse_ctx ctx; + + ctx.db = db; + ctx.f = f; + ctx.private_data = private_data; + return tdb_traverse_read(db_ctx->tdb, db_tdb_traverse_read_func, &ctx); +} + static int db_tdb_get_seqnum(struct db_context *db) { @@ -220,6 +260,7 @@ talloc_set_destructor(db_tdb, db_tdb_ctx_destr); result->fetch_locked = db_tdb_fetch_locked; result->traverse = db_tdb_traverse; + result->traverse_read = db_tdb_traverse_read; result->get_seqnum = db_tdb_get_seqnum; return result; Modified: branches/SAMBA_3_0_26/source/smbd/session.c =================================================================== --- branches/SAMBA_3_0_26/source/smbd/session.c 2007-05-29 17:57:52 UTC (rev 23219) +++ branches/SAMBA_3_0_26/source/smbd/session.c 2007-05-29 18:04:38 UTC (rev 23220) @@ -272,7 +272,7 @@ return False; } - ctx->traverse(ctx, fn, private_data); + ctx->traverse_read(ctx, fn, private_data); return True; }