int main(int argc, char *argv[]) { char *fname, *keyname=NULL; bool emergency = false; int c; if (argc < 2) { printf("Usage: tdbdump <fname>\n"); exit(1); } while ((c = getopt( argc, argv, "hk:e")) != -1) { switch (c) { case 'h': usage(); exit( 0); case 'k': keyname = optarg; break; case 'e': emergency = true; break; default: usage(); exit( 1); } } fname = argv[optind]; return dump_tdb(fname, keyname, emergency); }
int main(int argc, char *argv[]) { bool emergency = false; int c, rc; char *fname; struct ldb_dn *dn = NULL; ldb = ldb_init(NULL, NULL); if (ldb == NULL) { fprintf(stderr, "ldb: ldb_init failed()"); exit(1); } rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_PRECONNECT); if (rc != LDB_SUCCESS) { fprintf(stderr, "ldb: failed to run preconnect hooks (needed to get Samba LDIF handlers): %s\n", ldb_strerror(rc)); exit(1); } if (argc < 2) { printf("Usage: ldbdump <fname>\n"); exit(1); } while ((c = getopt( argc, argv, "hd:ec")) != -1) { switch (c) { case 'h': usage(); exit( 0); case 'd': dn = ldb_dn_new(ldb, ldb, optarg); if (!dn) { fprintf(stderr, "ldb failed to parse %s as a DN\n", optarg); exit(1); } break; case 'e': emergency = true; break; case 'i': show_index = true; break; case 'c': validate_contents = true; break; default: usage(); exit( 1); } } fname = argv[optind]; return dump_tdb(fname, dn, emergency); }
int main(int argc, char *argv[]) { char *fname; if (argc < 2) { printf("Usage: tdbdump <fname>\n"); exit(1); } fname = argv[1]; return dump_tdb(fname); }
static int test_tbegin_tdb(void) { long rc; local_tdb.format = 0; if ((rc = __TM_begin(&local_tdb)) == 0) { rc = __TM_end(); if (rc != 0) { return 100 * rc + 1; } if (local_tdb.format != 0) { dump_tdb(&local_tdb); return 100 * local_tdb.format + 2; } } else { return 100 * rc + 3; } local_tdb.format = 0; if ((rc = __TM_begin(&local_tdb)) == 0) { __TM_named_abort(1); return 4; } else { if (rc != 3) { return 100 * rc + 5; } if (local_tdb.format != 1) { dump_tdb(&local_tdb); return 100 * local_tdb.format + 6; } } local_tdb256.format = 0; if ((rc = __TM_begin(&local_tdb256)) == 0) { rc = __TM_end(); if (rc != 0) { return 1100 * rc + 1; } if (local_tdb256.format != 0) { dump_tdb(&local_tdb256); return 1100 * local_tdb256.format + 2; } } else { return 1100 * rc + 3; } #if 1 /*!!!does not work*/ local_tdb256.format = 0; if ((rc = __TM_begin(&local_tdb256)) == 0) { __TM_named_abort(1); return 2004; } else { if (rc != 3) { return 2100 * rc + 5; } if (local_tdb256.format != 1) { dump_tdb(&local_tdb256); return 2100 * local_tdb256.format + 6; } } #endif return 0; }
static int check_abort_code_in_tdb(struct __htm_tdb *tdb, uint64_t abort_code) { long expect_rc; long rc; if (abort_code != 0) { long addr; addr = __TM_failure_address(&local_tdb); if (addr != DEFAULT_ABORT_ADDRESS) { return 11; } } { long long tdb_abort_code; tdb_abort_code = __TM_failure_code(tdb); if ((uint64_t)tdb_abort_code != abort_code) { fprintf( stderr, "tm_ac %" PRIu64 ", ac %" PRIu64 ", tdb_ac %" PRIu64 "\n", (uint64_t)tdb_abort_code, abort_code, (uint64_t)tdb->abort_code); return 10; } } expect_rc = (abort_code >= 256) ? 1 : 0; rc = __TM_is_user_abort(tdb); if (rc != expect_rc) { fprintf(stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 1; } { unsigned char code; code = 0xffu; rc = __TM_is_named_user_abort(tdb, &code); if (rc != expect_rc) { fprintf( stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 2; } if (expect_rc == 1 && code != abort_code - 256) { return 3; } } if (abort_code > (uint64_t)num_abort_classes) { abort_code = (uint64_t)num_abort_classes; } expect_rc = (abort_classes[abort_code] == ABORT_T_ILLEGAL) ? 1 : 0; rc = __TM_is_illegal(tdb); if (rc != expect_rc) { dump_tdb(tdb); fprintf(stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 4; } expect_rc = (abort_classes[abort_code] == ABORT_T_FOOTPRINT_EXCEEDED) ? 1 : 0; rc = __TM_is_footprint_exceeded(tdb); if (rc != expect_rc) { dump_tdb(tdb); fprintf(stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 5; } expect_rc = (abort_classes[abort_code] == ABORT_T_NESTED_TOO_DEEP) ? 1 : 0; rc = __TM_is_nested_too_deep(tdb); if (rc != expect_rc) { dump_tdb(tdb); fprintf(stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 6; } expect_rc = (abort_classes[abort_code] == ABORT_T_CONFLICT) ? 1 : 0; rc = __TM_is_conflict(tdb); if (rc != expect_rc) { dump_tdb(tdb); fprintf(stderr, "rc %ld, expect_rc %ld\n", rc, expect_rc); return 7; } return 0; }
static int dump_lmdb(const char *fname, struct ldb_dn *dn, bool emergency) { int ret; struct MDB_env *env = NULL; struct MDB_txn *txn = NULL; MDB_dbi dbi; struct MDB_cursor *cursor = NULL; struct MDB_val key; struct MDB_val data; ret = mdb_env_create(&env); if (ret != 0) { fprintf(stderr, "Could not create MDB environment: (%d) %s\n", ret, mdb_strerror(ret)); goto close_env; } ret = mdb_env_open(env, fname, MDB_NOSUBDIR|MDB_NOTLS|MDB_RDONLY, 0600); if (ret != 0) { fprintf(stderr, "Could not open environment for %s: (%d) %s\n", fname, ret, mdb_strerror(ret)); goto close_env; } ret = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn); if (ret != 0) { fprintf(stderr, "Could not start transaction: (%d) %s\n", ret, mdb_strerror(ret)); goto close_env; } ret = mdb_dbi_open(txn, NULL, 0, &dbi); if (ret != 0) { fprintf(stderr, "Could not open database: (%d) %s\n", ret, mdb_strerror(ret)); goto close_txn; } ret = mdb_cursor_open(txn, dbi, &cursor); if (ret != 0) { fprintf(stderr, "Could not open cursor: (%d) %s\n", ret, mdb_strerror(ret)); goto close_txn; } ret = mdb_cursor_get(cursor, &key, &data, MDB_FIRST); if (ret != 0 && ret != MDB_NOTFOUND) { fprintf(stderr, "Could not find first record: (%d) %s\n", ret, mdb_strerror(ret)); goto close_cursor; } while (ret != MDB_NOTFOUND) { struct TDB_DATA tkey = { .dptr = key.mv_data, .dsize = key.mv_size }; struct TDB_DATA tdata = { .dptr = data.mv_data, .dsize = data.mv_size }; traverse_fn(NULL, tkey, tdata, dn); ret = mdb_cursor_get(cursor, &key, &data, MDB_NEXT); if (ret != 0 && ret != MDB_NOTFOUND) { fprintf(stderr, "Could not read next record: (%d) %s\n", ret, mdb_strerror(ret)); goto close_cursor; } } ret = 0; close_cursor: mdb_cursor_close(cursor); close_txn: mdb_txn_commit(txn); close_env: mdb_env_close(env); if (ret != 0) { return 1; } return 0; } #else static int dump_lmdb(const char *fname, struct ldb_dn *dn, bool emergency) { /* not built with lmdb support */ return 1; } #endif /* #ifdef HAVE_LMDB */ static void usage( void) { printf( "Usage: ldbdump [options] <filename>\n\n"); printf( " -h this help message\n"); printf( " -d DN dumps DN only\n"); printf( " -e emergency dump, for corrupt databases\n"); printf( " -i include index and @BASEINFO records in dump\n"); printf( " -c validate contents of the records\n"); } int main(int argc, char *argv[]) { bool emergency = false; int c, rc; char *fname; struct ldb_dn *dn = NULL; ldb = ldb_init(NULL, NULL); if (ldb == NULL) { fprintf(stderr, "ldb: ldb_init failed()"); exit(1); } rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_PRECONNECT); if (rc != LDB_SUCCESS) { fprintf(stderr, "ldb: failed to run preconnect hooks (needed to get Samba LDIF handlers): %s\n", ldb_strerror(rc)); exit(1); } if (argc < 2) { printf("Usage: ldbdump <fname>\n"); exit(1); } while ((c = getopt( argc, argv, "hd:eic")) != -1) { switch (c) { case 'h': usage(); exit( 0); case 'd': dn = ldb_dn_new(ldb, ldb, optarg); if (!dn) { fprintf(stderr, "ldb failed to parse %s as a DN\n", optarg); exit(1); } break; case 'e': emergency = true; break; case 'i': show_index = true; break; case 'c': validate_contents = true; break; default: usage(); exit( 1); } } fname = argv[optind]; rc = dump_lmdb(fname, dn, emergency); if (rc != 0) { rc = dump_tdb(fname, dn, emergency); if (rc != 0) { fprintf(stderr, "Failed to open %s\n", fname); return 1; } } return 0; }