1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-03 13:47:25 +03:00

ldb: Permit desactivation of autocomit for every ldb_xxx_ctrl function

Autobuild-User: Matthieu Patou <mat@samba.org>
Autobuild-Date: Fri Mar 30 11:59:09 CEST 2012 on sn-devel-104
This commit is contained in:
Matthieu Patou 2012-03-30 01:24:07 -07:00 committed by Matthieu Patou
parent 5df1c11539
commit 40a4aea891
8 changed files with 28 additions and 23 deletions

View File

@ -59,6 +59,7 @@ static struct poptOption builtin_popt_options[] = {
{ "relax", 0, POPT_ARG_NONE, NULL, CMDLINE_RELAX, "pass relax control", NULL },
{ "cross-ncs", 0, POPT_ARG_NONE, NULL, 'N', "search across NC boundaries", NULL },
{ "extended-dn", 0, POPT_ARG_NONE, NULL, 'E', "show extended DNs", NULL },
{ "noautocommit", 0, POPT_ARG_NONE, &options.noautocommit, 1, "do not commit after each ldif message", NULL },
{ NULL }
};

View File

@ -44,6 +44,7 @@ struct ldb_cmdline {
const char **controls;
int show_binary;
int tracing;
bool noautocommit;
};
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc,

View File

@ -79,7 +79,7 @@ static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count)
continue;
}
ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls);
ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls, true);
if (ret != LDB_SUCCESS) {
fprintf(stderr, "ERR: %s : \"%s\" on DN %s\n",
ldb_strerror(ret), ldb_errstring(ldb),

View File

@ -41,7 +41,7 @@ static int dn_cmp(struct ldb_message **msg1, struct ldb_message **msg2)
return ldb_dn_compare((*msg1)->dn, (*msg2)->dn);
}
static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls, bool doautocommit)
{
int ret;
unsigned int i, total=0;
@ -55,7 +55,7 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struc
TYPESAFE_QSORT(res->msgs, res->count, dn_cmp);
for (i = 0; i < res->count; i++) {
if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == LDB_SUCCESS) {
if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls, doautocommit) == LDB_SUCCESS) {
total++;
} else {
printf("Failed to delete '%s' - %s\n",
@ -114,9 +114,9 @@ int main(int argc, const char **argv)
return LDB_ERR_OPERATIONS_ERROR;
}
if (options->recursive) {
ret = ldb_delete_recursive(ldb, dn,req_ctrls);
ret = ldb_delete_recursive(ldb, dn,req_ctrls, !options->noautocommit);
} else {
ret = ldb_delete_ctrl(ldb, dn,req_ctrls);
ret = ldb_delete_ctrl(ldb, dn,req_ctrls, !options->noautocommit);
if (ret == LDB_SUCCESS) {
printf("Deleted 1 record\n");
}

View File

@ -81,7 +81,7 @@ static int modify_record(struct ldb_context *ldb,
ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod);
}
if (ldb_modify_ctrl(ldb, mod, req_ctrls) != LDB_SUCCESS) {
if (ldb_modify_ctrl(ldb, mod, req_ctrls, true) != LDB_SUCCESS) {
fprintf(stderr, "failed to modify %s - %s\n",
ldb_dn_get_linearized(msg1->dn), ldb_errstring(ldb));
ret = -1;
@ -139,7 +139,7 @@ static int merge_edits(struct ldb_context *ldb,
if (options->verbose > 0) {
ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]);
}
if (ldb_add_ctrl(ldb, msgs2[i], req_ctrls) != LDB_SUCCESS) {
if (ldb_add_ctrl(ldb, msgs2[i], req_ctrls, true) != LDB_SUCCESS) {
fprintf(stderr, "failed to add %s - %s\n",
ldb_dn_get_linearized(msgs2[i]->dn),
ldb_errstring(ldb));
@ -165,7 +165,7 @@ static int merge_edits(struct ldb_context *ldb,
if (options->verbose > 0) {
ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]);
}
if (ldb_delete_ctrl(ldb, msgs1[i]->dn, req_ctrls) != LDB_SUCCESS) {
if (ldb_delete_ctrl(ldb, msgs1[i]->dn, req_ctrls, true) != LDB_SUCCESS) {
fprintf(stderr, "failed to delete %s - %s\n",
ldb_dn_get_linearized(msgs1[i]->dn),
ldb_errstring(ldb));

View File

@ -49,7 +49,7 @@ static void usage(struct ldb_context *ldb)
/*
process modifies for one file
*/
static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count)
static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count, bool doautocomit)
{
struct ldb_ldif *ldif;
int fun_ret = LDB_SUCCESS, ret;
@ -69,13 +69,13 @@ static int process_file(struct ldb_context *ldb, FILE *f, unsigned int *count)
switch (ldif->changetype) {
case LDB_CHANGETYPE_NONE:
case LDB_CHANGETYPE_ADD:
ret = ldb_add_ctrl(ldb, ldif->msg,req_ctrls);
ret = ldb_add_ctrl(ldb, ldif->msg, req_ctrls, doautocomit);
break;
case LDB_CHANGETYPE_DELETE:
ret = ldb_delete_ctrl(ldb, ldif->msg->dn,req_ctrls);
ret = ldb_delete_ctrl(ldb, ldif->msg->dn, req_ctrls, doautocomit);
break;
case LDB_CHANGETYPE_MODIFY:
ret = ldb_modify_ctrl(ldb, ldif->msg,req_ctrls);
ret = ldb_modify_ctrl(ldb, ldif->msg, req_ctrls, doautocomit);
break;
case LDB_CHANGETYPE_MODRDN:
ret = ldb_ldif_parse_modrdn(ldb, ldif, ldif, &olddn,
@ -133,7 +133,7 @@ int main(int argc, const char **argv)
options = ldb_cmdline_process(ldb, argc, argv, usage);
if (options->argc == 0) {
ret = process_file(ldb, stdin, &count);
ret = process_file(ldb, stdin, &count, !options->noautocommit);
} else {
for (i=0;i<options->argc;i++) {
const char *fname = options->argv[i];
@ -143,7 +143,7 @@ int main(int argc, const char **argv)
perror(fname);
return LDB_ERR_OPERATIONS_ERROR;
}
ret = process_file(ldb, f, &count);
ret = process_file(ldb, f, &count, !options->noautocommit);
fclose(f);
}
}

View File

@ -67,7 +67,7 @@ static int ldb_do_autotransaction(struct ldb_context *ldb,
*/
int ldb_add_ctrl(struct ldb_context *ldb,
const struct ldb_message *message,
struct ldb_control **controls)
struct ldb_control **controls, bool do_transaction)
{
struct ldb_request *req;
int ret;
@ -87,7 +87,8 @@ int ldb_add_ctrl(struct ldb_context *ldb,
if (ret != LDB_SUCCESS) return ret;
/* do request and autostart a transaction */
ret = ldb_do_autotransaction(ldb, req);
if (do_transaction)
ret = ldb_do_autotransaction(ldb, req);
talloc_free(req);
return ret;
@ -97,7 +98,7 @@ int ldb_add_ctrl(struct ldb_context *ldb,
same as ldb_delete but accept control
*/
int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
struct ldb_control **controls)
struct ldb_control **controls, bool do_transaction)
{
struct ldb_request *req;
int ret;
@ -112,7 +113,8 @@ int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
if (ret != LDB_SUCCESS) return ret;
/* do request and autostart a transaction */
ret = ldb_do_autotransaction(ldb, req);
if (do_transaction)
ret = ldb_do_autotransaction(ldb, req);
talloc_free(req);
return ret;
@ -124,7 +126,7 @@ int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
*/
int ldb_modify_ctrl(struct ldb_context *ldb,
const struct ldb_message *message,
struct ldb_control **controls)
struct ldb_control **controls, bool do_transaction)
{
struct ldb_request *req;
int ret;
@ -144,7 +146,8 @@ int ldb_modify_ctrl(struct ldb_context *ldb,
if (ret != LDB_SUCCESS) return ret;
/* do request and autostart a transaction */
ret = ldb_do_autotransaction(ldb, req);
if (do_transaction)
ret = ldb_do_autotransaction(ldb, req);
talloc_free(req);
return ret;

View File

@ -33,12 +33,12 @@
int ldb_add_ctrl(struct ldb_context *ldb,
const struct ldb_message *message,
struct ldb_control **controls);
struct ldb_control **controls, bool do_transaction);
int ldb_delete_ctrl(struct ldb_context *ldb, struct ldb_dn *dn,
struct ldb_control **controls);
struct ldb_control **controls, bool do_transaction);
int ldb_modify_ctrl(struct ldb_context *ldb,
const struct ldb_message *message,
struct ldb_control **controls);
struct ldb_control **controls, bool do_transaction);
int ldb_search_ctrl(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
struct ldb_result **result, struct ldb_dn *base,
enum ldb_scope scope, const char * const *attrs,