summaryrefslogtreecommitdiff
path: root/lib/ntdb/tools
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-19 12:43:09 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:07 +0200
commit8fdd20b22f6b27b616b5b3a2285a267ffae0a262 (patch)
tree20bea1533df2bc2df1f854fded4f7770110eecda /lib/ntdb/tools
parenta941b19e5d747a5468b3c10d4a1c95f539c476ac (diff)
downloadsamba-8fdd20b22f6b27b616b5b3a2285a267ffae0a262.tar.gz
samba-8fdd20b22f6b27b616b5b3a2285a267ffae0a262.tar.bz2
samba-8fdd20b22f6b27b616b5b3a2285a267ffae0a262.zip
ntdb: add -h arg to ntdbrestore
Since our default hashsize is 8192 not 131, we look fat when we convert near-empty TDBs. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/tools')
-rw-r--r--lib/ntdb/tools/ntdbrestore.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/ntdb/tools/ntdbrestore.c b/lib/ntdb/tools/ntdbrestore.c
index dad591d562..1df9322e64 100644
--- a/lib/ntdb/tools/ntdbrestore.c
+++ b/lib/ntdb/tools/ntdbrestore.c
@@ -1,5 +1,6 @@
/*
- ntdbrestore -- construct a ntdb from tdbdump output.
+ ntdbrestore -- construct a ntdb from (n)tdbdump output.
+ Copyright (C) Rusty Russell 2012
Copyright (C) Volker Lendecke 2010
Copyright (C) Simon McVittie 2005
@@ -188,11 +189,17 @@ fail:
return ret;
}
-static int restore_ntdb(const char *fname)
+static int restore_ntdb(const char *fname, unsigned int hsize)
{
struct ntdb_context *ntdb;
+ union ntdb_attribute hashsize;
- ntdb = ntdb_open(fname, 0, O_RDWR|O_CREAT|O_EXCL, 0666, NULL);
+ hashsize.base.attr = NTDB_ATTRIBUTE_HASHSIZE;
+ hashsize.base.next = NULL;
+ hashsize.hashsize.size = hsize;
+
+ ntdb = ntdb_open(fname, 0, O_RDWR|O_CREAT|O_EXCL, 0666,
+ hsize ? &hashsize : NULL);
if (!ntdb) {
perror("ntdb_open");
fprintf(stderr, "Failed to open %s\n", fname);
@@ -218,14 +225,27 @@ static int restore_ntdb(const char *fname)
int main(int argc, char *argv[])
{
- char *fname;
+ unsigned int hsize = 0;
+ const char *execname = argv[0];
- if (argc < 2) {
- printf("Usage: %s dbname < tdbdump_output\n", argv[0]);
+ if (argv[1] && strcmp(argv[1], "-h") == 0) {
+ if (argv[2]) {
+ hsize = atoi(argv[2]);
+ }
+ if (hsize == 0) {
+ fprintf(stderr, "-h requires a integer value"
+ " (eg. 128 or 131072)\n");
+ exit(1);
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ if (argc != 2) {
+ printf("Usage: %s [-h <hashsize>] dbname < tdbdump_output\n",
+ execname);
exit(1);
}
- fname = argv[1];
- return restore_ntdb(fname);
+ return restore_ntdb(argv[1], hsize);
}