2 * Samba Unix/Linux SMB client library
4 * Copyright (C) Gregor Beck 2011
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @brief Check the idmap database.
22 * @author Gregor Beck <gb@sernet.de>
26 #include "net_idmap_check.h"
28 #include "system/filesys.h"
29 #include "dbwrap/dbwrap.h"
30 #include "dbwrap/dbwrap_open.h"
31 #include "dbwrap/dbwrap_rbt.h"
33 #include "../libcli/security/dom_sid.h"
39 static int traverse_commit(struct db_record *diff_rec, void* data);
40 static int traverse_check(struct db_record *rec, void* data);
42 static char* interact_edit(TALLOC_CTX* mem_ctx, const char* str);
43 static int interact_prompt(const char* msg, const char* accept, char def);
45 /* TDB_DATA *******************************************************************/
46 static char* print_data(TALLOC_CTX* mem_ctx, TDB_DATA d);
47 static TDB_DATA parse_data(TALLOC_CTX* mem_ctx, const char** ptr);
48 static TDB_DATA talloc_copy(TALLOC_CTX* mem_ctx, TDB_DATA data);
49 static bool is_empty(TDB_DATA data) {
50 return (data.dsize == 0) || (data.dptr == NULL);
53 /* record *********************************************************************/
57 DT_SID, DT_UID, DT_GID,
58 DT_HWM, DT_VER, DT_SEQ,
62 enum DT key_type, val_type;
68 static struct record* parse_record(TALLOC_CTX* ctx, TDB_DATA key, TDB_DATA val);
69 static struct record* reverse_record(struct record* rec);
71 static bool is_invalid(const struct record* r) {
72 return (r->key_type == DT_INV) || (r->val_type == DT_INV);
75 static bool is_map(const struct record* r) {
76 return (r->key_type == DT_SID)
77 || (r->key_type == DT_UID) || (r->key_type == DT_GID);
80 /* action *********************************************************************/
82 typedef struct check_action {
92 struct check_actions {
93 check_action invalid_record;
94 check_action missing_reverse;
95 check_action invalid_mapping;
96 check_action invalid_edit;
97 check_action record_exists;
98 check_action no_version;
99 check_action wrong_version;
100 check_action invalid_hwm;
102 check_action valid_mapping;
103 check_action valid_other;
104 check_action invalid_diff;
107 static struct check_actions
108 check_actions_init(const struct check_options* opts) {
109 struct check_actions ret = {
110 .invalid_record = (check_action) {
111 .name = "Invalid record",
112 .prompt = "[e]dit/[d]elete/[D]elete all"
113 "/[s]kip/[S]kip all",
115 .default_action = 'e',
118 .missing_reverse = (check_action) {
119 .name = "Missing reverse mapping for",
120 .prompt = "[f]ix/[F]ix all/[e]dit/[d]elete/[D]elete all"
121 "/[s]kip/[S]kip all",
123 .default_action = 'f',
126 .invalid_mapping = (check_action) {
127 .fmt = "%1$s: %2$s -> %3$s\n(%4$s <- %3$s)\n",
128 .name = "Invalid mapping",
129 .prompt = "[e]dit/[d]elete/[D]elete all"
130 "/[s]kip/[S]kip all",
132 .default_action = 'd',
135 .invalid_edit = (check_action) {
136 .name = "Invalid record",
137 .prompt = "[e]dit/[d]elete/[D]elete all"
138 "/[s]kip/[S]kip all",
140 .default_action = 'e',
143 .record_exists = (check_action) {
144 .fmt = "%1$s: %2$s\n-%4$s\n+%3$s\n",
145 .name = "Record exists",
146 .prompt = "[o]verwrite/[O]verwrite all/[e]dit"
147 "/[d]elete/[D]elete all/[s]kip/[S]kip all",
149 .default_action = 'o',
152 .no_version = (check_action) {
153 .prompt = "[f]ix/[s]kip/[a]bort",
155 .default_action = 'f',
157 .wrong_version = (check_action) {
158 .prompt = "[f]ix/[s]kip/[a]bort",
160 .default_action = 'a',
162 .invalid_hwm = (check_action) {
163 .prompt = "[f]ix/[s]kip",
165 .default_action = 'f',
167 .commit = (check_action) {
168 .prompt = "[c]ommit/[l]ist/[s]kip",
170 .default_action = 'l',
173 .valid_mapping = (check_action) {
174 .fmt = "%1$s: %2$s <-> %3$s\n",
177 .verbose = opts->verbose,
179 .valid_other = (check_action) {
182 .verbose = opts->verbose,
184 .invalid_diff = (check_action) {
185 .prompt = "[s]kip/[S]kip all/[c]ommit/[C]ommit all"
188 .default_action = 's',
193 ret.invalid_record.auto_action = 's';
194 ret.missing_reverse.auto_action = 's';
195 ret.invalid_mapping.auto_action = 's';
196 ret.no_version.auto_action = 's';
197 ret.wrong_version.auto_action = 's';
198 ret.invalid_hwm.auto_action = 's';
199 ret.commit.auto_action = 's';
202 if (opts->automatic) {
203 ret.invalid_record.auto_action = 'd'; /* delete */
204 ret.missing_reverse.auto_action = 'f'; /* fix */
205 ret.invalid_mapping.auto_action = 'd'; /* delete */
206 ret.no_version.auto_action = 'f'; /* fix */
207 ret.wrong_version.auto_action = 'a'; /* abort */
208 ret.invalid_hwm.auto_action = 'f'; /* fix */
209 ret.commit.auto_action = 'c'; /* commit */
210 ret.invalid_diff.auto_action = 'a'; /* abort */
212 ret.wrong_version.auto_action = 'f'; /* fix */
213 ret.invalid_diff.auto_action = 'c'; /* commit */
217 ret.invalid_diff.auto_action = 'c'; /* commit */
218 /* ret.commit.auto_action = 'c';*/ /* commit */
224 static char get_action(struct check_action* a, struct record* r, TDB_DATA* v) {
226 if (a->verbose && (r != NULL)) {
228 d_printf("%s: %s ", a->name, print_data(r, r->key));
230 d_printf("-> %s\n", print_data(r, r->val));
231 } else if (r->key_type == DT_HWM ||
232 r->key_type == DT_VER ||
233 r->key_type == DT_SEQ)
235 d_printf(": %ld\n", r->id);
240 d_printf(a->fmt, a->name,
241 print_data(r, r->key),
242 print_data(r, r->val),
243 (v ? print_data(r, *v) : ""));
247 if (a->auto_action != '\0') {
248 return a->auto_action;
251 ret = interact_prompt(a->prompt, a->answers, a->default_action);
255 a->auto_action = ret;
257 a->default_action = ret;
261 /* *************************************************************************/
267 static TDB_DATA pack_diff(TDB_DATA_diff* diff) {
269 .dptr = (uint8_t *)diff,
270 .dsize = sizeof(TDB_DATA_diff),
274 static TDB_DATA_diff unpack_diff(TDB_DATA data) {
275 assert(data.dsize == sizeof(TDB_DATA_diff));
276 return *(TDB_DATA_diff*)data.dptr;
279 #define DEBUG_DIFF(LEV,MEM,MSG,KEY,OLD,NEW) \
280 DEBUG(LEV, ("%s: %s\n", MSG, print_data(MEM, KEY))); \
281 if (!is_empty(OLD)) { \
282 DEBUGADD(LEV, ("-%s\n", print_data(MEM, OLD))); \
284 if (!is_empty(NEW)) { \
285 DEBUGADD(LEV, ("+%s\n", print_data(MEM, NEW))); \
292 struct db_context *db;
293 struct db_context *diff;
294 struct check_actions action;
299 unsigned n_invalid_record;
300 unsigned n_missing_reverse;
301 unsigned n_invalid_mappping;
305 struct check_options opts;
309 static void adjust_hwm(struct check_ctx* ctx, const struct record* r);
311 static int add_record(struct check_ctx* ctx, TDB_DATA key, TDB_DATA value)
315 TALLOC_CTX* mem = talloc_new(ctx->diff);
317 struct db_record *rec = dbwrap_fetch_locked(ctx->diff, mem, key);
323 recvalue = dbwrap_record_get_value(rec);
325 if (recvalue.dptr == 0) { /* first entry */
326 status = dbwrap_fetch(ctx->db, ctx->diff, key, &diff.oval);
327 if (!NT_STATUS_IS_OK(status)) {
328 diff.oval = tdb_null;
331 diff = unpack_diff(recvalue);
332 talloc_free(diff.nval.dptr);
334 diff.nval = talloc_copy(ctx->diff, value);
336 DEBUG_DIFF(2, mem, "TDB DIFF", key, diff.oval, diff.nval);
338 status = dbwrap_record_store(rec, pack_diff(&diff), 0);
342 if (!NT_STATUS_IS_OK(status)) {
343 DEBUG(0, ("could not store record %s\n", nt_errstr(status)));
350 static int del_record(struct check_ctx* ctx, TDB_DATA key) {
351 return add_record(ctx, key, tdb_null);
355 fetch_record(struct check_ctx* ctx, TALLOC_CTX* mem_ctx, TDB_DATA key)
360 status = dbwrap_fetch(ctx->diff, mem_ctx, key, &tmp);
361 if (!NT_STATUS_IS_OK(status)) {
362 DEBUG(0, ("Out of memory!\n"));
365 if (tmp.dptr != NULL) {
366 TDB_DATA_diff diff = unpack_diff(tmp);
367 TDB_DATA ret = talloc_copy(mem_ctx, diff.nval);
368 talloc_free(tmp.dptr);
372 status = dbwrap_fetch(ctx->db, mem_ctx, key, &tmp);
373 if (!NT_STATUS_IS_OK(status)) {
374 DEBUG(0, ("Out of memory!\n"));
381 static void edit_record(struct record* r) {
382 TALLOC_CTX* mem = talloc_new(r);
383 cbuf* ost = cbuf_new(mem);
388 cbuf_printf(ost, "%s %s\n",
389 print_data(mem, r->key), print_data(mem, r->val));
390 str = interact_edit(mem, cbuf_gets(ost, 0));
391 key = parse_data(mem, &str);
392 val = parse_data(mem, &str);
393 nr = parse_record(talloc_parent(r), key, val);
400 static bool check_version(struct check_ctx* ctx) {
401 static const char* key = "IDMAP_VERSION";
405 struct check_actions* act = &ctx->action;
407 status = dbwrap_fetch_uint32(ctx->db, key, &version);
408 if (!NT_STATUS_IS_OK(status)) {
409 d_printf("No version number, assume 2\n");
410 action = get_action(&act->no_version, NULL, NULL);
411 } else if (version != 2) {
412 d_printf("Wrong version number %d, should be 2\n", version);
413 action = get_action(&act->wrong_version, NULL, NULL);
419 SIVAL(&version, 0, 2);
420 add_record(ctx, string_term_tdb_data(key),
421 make_tdb_data((uint8_t *)&version, sizeof(uint32_t)));
431 static void check_hwm(struct check_ctx* ctx, const char* key, uint32_t target) {
435 struct check_actions* act = &ctx->action;
437 status = dbwrap_fetch_uint32(ctx->db, key, &hwm);
438 if (!NT_STATUS_IS_OK(status)) {
439 d_printf("No %s should be %d\n", key, target);
440 action = get_action(&act->invalid_hwm, NULL, NULL);
441 } else if (target < hwm) {
442 d_printf("Invalid %s %d: should be %d\n", key, hwm, target);
443 action = get_action(&act->invalid_hwm, NULL, NULL);
446 SIVAL(&hwm, 0, target);
447 add_record(ctx, string_term_tdb_data(key),
448 make_tdb_data((uint8_t *)&hwm, sizeof(uint32_t)));
452 int traverse_check(struct db_record *rec, void* data) {
453 struct check_ctx* ctx = (struct check_ctx*)data;
454 struct check_actions* act = &ctx->action;
455 TALLOC_CTX* mem = talloc_new(ctx->diff);
461 key = dbwrap_record_get_key(rec);
462 value = dbwrap_record_get_value(rec);
464 r = parse_record(mem, key, value);
467 action = get_action(&act->invalid_record, r, NULL);
468 ctx->n_invalid_record++;
469 } else if (is_map(r)) {
470 TDB_DATA back = fetch_record(ctx, mem, r->val);
471 if (back.dptr == NULL) {
472 action = get_action(&act->missing_reverse, r, NULL);
473 ctx->n_missing_reverse++;
474 } else if (!tdb_data_equal(r->key, back)) {
475 action = get_action(&act->invalid_mapping, r, &back);
476 ctx->n_invalid_mappping++;
478 if (r->key_type == DT_SID) {
479 action = get_action(&act->valid_mapping, r, NULL);
482 action = get_action(&act->valid_mapping, NULL,
488 action = get_action(&act->valid_other, r, NULL);
496 case 'd': /* delete */
497 del_record(ctx, key);
499 case 'f': /* add reverse mapping */
500 add_record(ctx, value, key);
506 action = get_action(&act->invalid_edit, r,NULL);
509 if (!tdb_data_equal(key, r->key)) {
510 TDB_DATA oval = fetch_record(ctx, mem, r->key);
511 if (!is_empty(oval) &&
512 !tdb_data_equal(oval, r->val))
514 action = get_action(&act->record_exists,
522 TDB_DATA okey = fetch_record(ctx, mem, r->val);
523 if (!is_empty(okey) &&
524 !tdb_data_equal(okey, r->key))
526 action = get_action(&act->record_exists,
532 case 'o': /* overwrite */
534 if (!tdb_data_equal(key, r->key)) {
535 del_record(ctx, key);
537 add_record(ctx, r->key, r->val);
539 add_record(ctx, r->val, r->key);
550 /******************************************************************************/
552 void adjust_hwm(struct check_ctx* ctx, const struct record* r) {
553 enum DT type = (r->key_type == DT_SID) ? r->val_type : r->key_type;
554 if (type == DT_UID) {
555 ctx->uid_hwm = MAX(ctx->uid_hwm, r->id);
556 } else if (type == DT_GID) {
557 ctx->gid_hwm = MAX(ctx->gid_hwm, r->id);
561 TDB_DATA talloc_copy(TALLOC_CTX* mem_ctx, TDB_DATA data) {
563 .dptr = (uint8_t *)talloc_size(mem_ctx, data.dsize+1),
566 if (ret.dptr == NULL) {
569 memcpy(ret.dptr, data.dptr, data.dsize);
570 ret.dptr[ret.dsize] = '\0';
575 static bool is_cstr(TDB_DATA str) {
576 return !is_empty(str) && str.dptr[str.dsize-1] == '\0';
579 static bool parse_sid (TDB_DATA str, enum DT* type, struct dom_sid* sid) {
581 const char* s = (const char*)str.dptr;
582 if ((s[0] == 'S') && string_to_sid(&tmp, s)) {
590 static bool parse_xid(TDB_DATA str, enum DT* type, unsigned long* id) {
593 if (sscanf((const char*)str.dptr, "%cID %lu%c", &c, &tmp, &t) == 2) {
598 } else if (c == 'G') {
609 parse_record(TALLOC_CTX* mem_ctx, TDB_DATA key, TDB_DATA val)
611 struct record* ret = talloc_zero(mem_ctx, struct record);
613 DEBUG(0, ("Out of memory.\n"));
616 ret->key = talloc_copy(ret, key);
617 ret->val = talloc_copy(ret, val);
618 if ((ret->key.dptr == NULL && key.dptr != NULL) ||
619 (ret->val.dptr == NULL && val.dptr != NULL))
622 DEBUG(0, ("Out of memory.\n"));
625 assert((ret->key_type == DT_INV) && (ret->val_type == DT_INV));
630 if (parse_sid(key, &ret->key_type, &ret->sid)) {
631 parse_xid(val, &ret->val_type, &ret->id);
632 } else if (parse_xid(key, &ret->key_type, &ret->id)) {
634 parse_sid(val, &ret->val_type, &ret->sid);
636 } else if (strcmp((const char*)key.dptr, "USER HWM") == 0) {
637 ret->key_type = DT_HWM;
638 if (val.dsize == 4) {
639 ret->id = IVAL(val.dptr,0);
640 ret->val_type = DT_UID;
642 } else if (strcmp((const char*)key.dptr, "GROUP HWM") == 0) {
643 ret->key_type = DT_HWM;
644 if (val.dsize == 4) {
645 ret->id = IVAL(val.dptr,0);
646 ret->val_type = DT_GID;
648 } else if (strcmp((const char*)key.dptr, "IDMAP_VERSION") == 0) {
649 ret->key_type = DT_VER;
650 if (val.dsize == 4) {
651 ret->id = IVAL(val.dptr,0);
652 ret->val_type = DT_VER;
654 } else if (strcmp((const char*)key.dptr, "__db_sequence_number__") == 0) {
655 ret->key_type = DT_SEQ;
656 if (val.dsize == 8) {
657 ret->id = *(uint64_t*)val.dptr;
658 ret->val_type = DT_SEQ;
665 struct record* reverse_record(struct record* in)
667 return parse_record(talloc_parent(in), in->val, in->key);
671 /******************************************************************************/
673 int interact_prompt(const char* msg, const char* acc, char def) {
674 struct termios old_tio, new_tio;
677 tcgetattr(STDIN_FILENO, &old_tio);
679 new_tio.c_lflag &=(~ICANON & ~ECHO);
680 tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
683 d_printf("%s? [%c]\n", msg, def);
690 else if (strchr(acc, tolower(c)) != NULL) {
693 d_printf("Invalid input '%c'\n", c);
695 tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
699 char* print_data(TALLOC_CTX* mem_ctx, TDB_DATA d)
703 cbuf* ost = cbuf_new(mem_ctx);
704 int len = cbuf_print_quoted(ost, (const char*)d.dptr, d.dsize);
706 cbuf_swapptr(ost, &ret, 0);
707 talloc_steal(mem_ctx, ret);
712 return talloc_strdup(mem_ctx, "<NULL>");
716 TDB_DATA parse_data(TALLOC_CTX* mem_ctx, const char** ptr) {
717 cbuf* ost = cbuf_new(mem_ctx);
718 TDB_DATA ret = tdb_null;
720 if (srprs_quoted(ptr, ost)) {
721 ret.dsize = cbuf_getpos(ost);
722 ret.dptr = (uint8_t *)talloc_steal(mem_ctx, cbuf_gets(ost,0));
728 static const char* get_editor(void) {
729 static const char* editor = NULL;
730 if (editor == NULL) {
731 editor = getenv("VISUAL");
732 if (editor == NULL) {
733 editor = getenv("EDITOR");
735 if (editor == NULL) {
742 char* interact_edit(TALLOC_CTX* mem_ctx, const char* str) {
743 char fname[] = "/tmp/net_idmap_check.XXXXXX";
748 int fd = mkstemp(fname);
750 DEBUG(0, ("failed to mkstemp %s: %s\n", fname,
755 file = fdopen(fd, "w");
757 DEBUG(0, ("failed to open %s for writing: %s\n", fname,
764 fprintf(file, "%s", str);
767 snprintf(buf, sizeof(buf), "%s %s\n", get_editor(), fname);
768 if (system(buf) != 0) {
769 DEBUG(0, ("failed to start editor %s: %s\n", buf,
775 file = fopen(fname, "r");
777 DEBUG(0, ("failed to open %s for reading: %s\n", fname,
782 while ( fgets(buf, sizeof(buf), file) ) {
783 ret = talloc_strdup_append(ret, buf);
788 return talloc_steal(mem_ctx, ret);
792 static int traverse_print_diff(struct db_record *rec, void* data) {
793 struct check_ctx* ctx = (struct check_ctx*)data;
797 TALLOC_CTX* mem = talloc_new(ctx->diff);
799 key = dbwrap_record_get_key(rec);
800 value = dbwrap_record_get_value(rec);
801 diff = unpack_diff(value);
803 DEBUG_DIFF(0, mem, "DIFF", key, diff.oval, diff.nval);
810 static int traverse_commit(struct db_record *diff_rec, void* data) {
811 struct check_ctx* ctx = (struct check_ctx*)data;
816 TALLOC_CTX* mem = talloc_new(ctx->diff);
819 struct check_actions* act = &ctx->action;
820 struct db_record* rec;
822 key = dbwrap_record_get_key(diff_rec);
823 diff_value = dbwrap_record_get_value(diff_rec);
824 diff = unpack_diff(diff_value);
826 rec = dbwrap_fetch_locked(ctx->db, mem, key);
831 value = dbwrap_record_get_value(rec);
833 if (!tdb_data_equal(value, diff.oval)) {
836 d_printf("Warning: record has changed: %s\n"
837 "expected: %s got %s\n", print_data(mem, key),
838 print_data(mem, diff.oval),
839 print_data(mem, value));
841 action = get_action(&act->invalid_diff, NULL, NULL);
845 } else if (action == 'a') {
850 DEBUG_DIFF(0, mem, "Commit", key, diff.oval, diff.nval);
852 if (is_empty(diff.nval)) {
853 status = dbwrap_record_delete(rec);
855 status = dbwrap_record_store(rec, diff.nval, 0);
858 if (!NT_STATUS_IS_OK(status)) {
859 DEBUG(0, ("could not store record %s\n", nt_errstr(status)));
860 if (!ctx->opts.force) {
870 static struct check_ctx*
871 check_init(TALLOC_CTX* mem_ctx, const struct check_options* o)
873 struct check_ctx* ctx = talloc_zero(mem_ctx, struct check_ctx);
875 DEBUG(0, (_("No memory\n")));
879 ctx->diff = db_open_rbt(ctx);
880 if (ctx->diff == NULL) {
882 DEBUG(0, (_("No memory\n")));
886 ctx->action = check_actions_init(o);
891 static bool check_open_db(struct check_ctx* ctx, const char* name, int oflags)
894 d_fprintf(stderr, _("Error: name == NULL in check_open_db().\n"));
898 if (ctx->db != NULL) {
899 if ((ctx->oflags == oflags) && (strcmp(ctx->name, name))) {
902 TALLOC_FREE(ctx->db);
906 ctx->db = db_open(ctx, name, 0, TDB_DEFAULT, oflags, 0);
907 if (ctx->db == NULL) {
909 _("Could not open idmap db (%s) for writing: %s\n"),
910 name, strerror(errno));
914 if (ctx->name != name) {
915 TALLOC_FREE(ctx->name);
916 ctx->name = talloc_strdup(ctx, name);
919 ctx->oflags = oflags;
923 static bool check_do_checks(struct check_ctx* ctx)
927 if (!check_version(ctx)) {
931 status = dbwrap_traverse(ctx->db, traverse_check, ctx, NULL);
933 if (!NT_STATUS_IS_OK(status)) {
934 DEBUG(0, ("failed to traverse %s\n", ctx->name));
938 check_hwm(ctx, "USER HWM", ctx->uid_hwm + 1);
939 check_hwm(ctx, "GROUP HWM", ctx->gid_hwm + 1);
944 static void check_summary(const struct check_ctx* ctx)
946 d_printf("uid hwm: %d\ngid hwm: %d\n", ctx->uid_hwm, ctx->gid_hwm);
947 d_printf("mappings: %d\nother: %d\n", ctx->n_map, ctx->n_other);
948 d_printf("invalid records: %d\nmissing links: %d\ninvalid links: %d\n",
949 ctx->n_invalid_record, ctx->n_missing_reverse,
950 ctx->n_invalid_mappping);
951 d_printf("%u changes:\n", ctx->n_diff);
954 static bool check_transaction_start(struct check_ctx* ctx) {
955 return (dbwrap_transaction_start(ctx->db) == 0);
958 static bool check_transaction_commit(struct check_ctx* ctx) {
959 return (dbwrap_transaction_commit(ctx->db) == 0);
962 static bool check_transaction_cancel(struct check_ctx* ctx) {
963 return (dbwrap_transaction_cancel(ctx->db) == 0);
967 static void check_diff_list(struct check_ctx* ctx) {
968 NTSTATUS status = dbwrap_traverse(ctx->diff, traverse_print_diff, ctx, NULL);
970 if (!NT_STATUS_IS_OK(status)) {
971 DEBUG(0, ("failed to traverse diff\n"));
976 static bool check_commit(struct check_ctx* ctx)
978 struct check_actions* act = &ctx->action;
980 NTSTATUS status = NT_STATUS_OK;
984 if (ctx->n_diff == 0) {
988 while ((action = get_action(&act->commit, NULL, NULL)) == 'l') {
989 check_diff_list(ctx);
994 assert(action == 'c');
996 if (!check_open_db(ctx, ctx->name, O_RDWR)) {
1000 if (!check_transaction_start(ctx)) {
1004 status = dbwrap_traverse(ctx->diff, traverse_commit, ctx, NULL);
1006 if (!NT_STATUS_IS_OK(status)) {
1007 check_transaction_cancel(ctx);
1010 if (ctx->opts.test) { /*get_action? */
1011 return check_transaction_cancel(ctx);
1013 return check_transaction_commit(ctx);
1017 int net_idmap_check_db(const char* db, const struct check_options* o)
1020 TALLOC_CTX* mem_ctx = talloc_stackframe();
1021 struct check_ctx* ctx = check_init(mem_ctx, o);
1023 if (!o->automatic && !isatty(STDIN_FILENO)) {
1024 DEBUG(0, ("Interactive use needs tty, use --auto\n"));
1028 if (check_open_db(ctx, db, O_RDWR)
1029 && check_transaction_start(ctx))
1031 if ( check_do_checks(ctx)
1032 && check_commit(ctx)
1033 && check_transaction_commit(ctx))
1037 check_transaction_cancel(ctx);
1041 if (check_open_db(ctx, db, O_RDONLY)
1042 && check_do_checks(ctx)
1043 && check_commit(ctx))
1049 talloc_free(mem_ctx);
1054 /*Local Variables:*/