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>
static struct ldb_cmdline *ldb_cmdline_process_internal(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *),
static struct ldb_cmdline *ldb_cmdline_process_internal(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *),
bool search)
{
struct ldb_cmdline *ret=NULL;
bool search)
{
struct ldb_cmdline *ret=NULL;
int argc, const char **argv,
void (*usage)(struct ldb_context *))
{
int argc, const char **argv,
void (*usage)(struct ldb_context *))
{
- return ldb_cmdline_process_internal(ldb, argc, argv, usage, true);
+ return ldb_cmdline_process_internal(ldb, argc, argv, usage, true, true);
+}
+
+struct ldb_cmdline *ldb_cmdline_process_edit(struct ldb_context *ldb,
+ int argc, const char **argv,
+ void (*usage)(struct ldb_context *))
+{
+ return ldb_cmdline_process_internal(ldb, argc, argv, usage, false, true);
}
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *))
{
}
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *))
{
- return ldb_cmdline_process_internal(ldb, argc, argv, usage, false);
+ return ldb_cmdline_process_internal(ldb, argc, argv, usage, false, false);
}
/* this function check controls reply and determines if more
}
/* this function check controls reply and determines if more
struct ldb_cmdline *ldb_cmdline_process_search(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *));
struct ldb_cmdline *ldb_cmdline_process_search(struct ldb_context *ldb,
int argc, const char **argv,
void (*usage)(struct ldb_context *));
+struct ldb_cmdline *ldb_cmdline_process_edit(struct ldb_context *ldb,
+ int argc, const char **argv,
+ void (*usage)(struct ldb_context *));
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc,
const char **argv,
void (*usage)(struct ldb_context *));
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc,
const char **argv,
void (*usage)(struct ldb_context *));
return LDB_ERR_OPERATIONS_ERROR;
}
return LDB_ERR_OPERATIONS_ERROR;
}
- options = ldb_cmdline_process(ldb, argc, argv, usage);
+ options = ldb_cmdline_process_edit(ldb, argc, argv, usage);
/* the check for '=' is for compatibility with ldapsearch */
if (options->argc > 0 &&
/* the check for '=' is for compatibility with ldapsearch */
if (options->argc > 0 &&