ldb: ensure that ldbedit operates like ldbmodify: set DONT_CREATE_DB
authorAndrew Bartlett <abartlet@samba.org>
Sat, 29 Feb 2020 03:03:00 +0000 (16:03 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 2 Mar 2020 02:47:30 +0000 (02:47 +0000)
commitb8aa05525e276fb315e21f78d468e48fa286e6c3
tree697f78787288cfc598f4118fb1c19ec36b8f4625
parent1e72fbdde001cf384ded080ec8304a550440b3a9
ldb: ensure that ldbedit operates like ldbmodify: set DONT_CREATE_DB

ldb* tools, when passed a raw filename assume tdb://

By default, ldb_tdb will call tdb with O_CREAT.

TDB, when passed O_CREAT and a not-tdb file, will wipe the file.

This means that if you run ldbedit <path to mdb-format-ldb file> the file
will be wiped, which is unexpected.  I noticed this while trying to
corrupt a sam.ldb backend file (for testing), but instead I wiped it!

Ideally tdb would not do that, but the behaviour has been this way for
decades.  Ideally ldb would have had a "create db" command, but this
has been the job of ldbadd for over a decade.

So this just blunts the knife for ldbedit.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14302

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
lib/ldb/tools/cmdline.c
lib/ldb/tools/cmdline.h
lib/ldb/tools/ldbedit.c