-/*
+/*
Unix SMB/CIFS implementation.
low level tdb backup and restore utility
Copyright (C) Andrew Tridgell 2002
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
{
va_list ap;
-
+
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
}
/* open the old tdb */
- tdb = tdb_open_ex(old_name, 0, 0,
+ tdb = tdb_open_ex(old_name, 0, 0,
O_RDWR, 0, &log_ctx, NULL);
if (!tdb) {
printf("Failed to open %s\n", old_name);
/* create the new tdb */
unlink(tmp_name);
- tdb_new = tdb_open_ex(tmp_name,
- hash_size ? hash_size : tdb_hash_size(tdb),
- TDB_DEFAULT,
- O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777,
+ tdb_new = tdb_open_ex(tmp_name,
+ hash_size ? hash_size : tdb_hash_size(tdb),
+ TDB_DEFAULT,
+ O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777,
&log_ctx, NULL);
if (!tdb_new) {
perror(tmp_name);
/* close the new tdb and re-open read-only */
tdb_close(tdb_new);
- tdb_new = tdb_open_ex(tmp_name,
+ tdb_new = tdb_open_ex(tmp_name,
0,
- TDB_DEFAULT,
+ TDB_DEFAULT,
O_RDONLY, 0,
&log_ctx, NULL);
if (!tdb_new) {
free(tmp_name);
return 1;
}
-
+
/* traverse the new tdb to confirm */
count2 = tdb_traverse(tdb_new, test_fn, NULL);
if (count2 != count1) {
int count = -1;
/* open the tdb */
- tdb = tdb_open_ex(fname, 0, 0,
+ tdb = tdb_open_ex(fname, 0, 0,
O_RDONLY, 0, &log_ctx, NULL);
/* traverse the tdb, then close it */
printf(" -v verify mode (restore if corrupt)\n");
printf(" -n hashsize set the new hash size for the backup\n");
}
-
int main(int argc, char *argv[])
{
-/*
+/*
Unix SMB/CIFS implementation.
simple tdb dump util
Copyright (C) Andrew Tridgell 2001
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
TDB_CONTEXT *tdb;
TDB_DATA key, value;
struct tdb_logging_context logfn = { log_stderr };
-
+
tdb = tdb_open_ex(fname, 0, 0, O_RDONLY, 0, &logfn, NULL);
if (!tdb) {
printf("Failed to open %s\n", fname);
static double _end_timer(void)
{
gettimeofday(&tp2,NULL);
- return((tp2.tv_sec - tp1.tv_sec) +
+ return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...)
{
va_list ap;
-
+
va_start(ap, format);
vfprintf(stdout, format, ap);
va_end(ap);
char keys[5][2];
char tdata[] = "test";
TDB_DATA key, data;
-
+
for (i = 0; i < 5; i++) {
snprintf(keys[i],2, "%d", i);
key.dptr = keys[i];
key.dsize = 2;
-
+
data.dptr = tdata;
data.dsize = 4;
-
+
if (tdb_store(db, key, data, TDB_REPLACE) != 0) {
fatal("tdb_store failed");
}
db = tdb_open(test_tdb, 0, TDB_CLEAR_IF_FIRST,
O_RDWR | O_CREAT | O_TRUNC, 0600);
- gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST,
+ gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST,
0600, NULL);
if (!db || !gdbm) {
-/*
+/*
Unix SMB/CIFS implementation.
Samba database functions
Copyright (C) Andrew Tridgell 1999-2000
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
static double _end_timer(void)
{
gettimeofday(&tp2,NULL);
- return((tp2.tv_sec - tp1.tv_sec) +
+ return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
printf("%02X ",(int)((unsigned char)buf[i]));
i++;
if (i%8 == 0) printf(" ");
- if (i%16 == 0) {
+ if (i%16 == 0) {
print_asc(&buf[i-16],8); printf(" ");
print_asc(&buf[i-8],8); printf("\n");
if (i<len) printf("[%03X] ",i);
}
if (i%16) {
int n;
-
+
n = 16 - (i%16);
printf(" ");
if (n>8) printf(" ");
while (n--) printf(" ");
-
+
n = i%16;
if (n > 8) n = 8;
print_asc(&buf[i-(i%16)],n); printf(" ");
n = (i%16) - n;
- if (n>0) print_asc(&buf[i-n],n);
- printf("\n");
+ if (n>0) print_asc(&buf[i-n],n);
+ printf("\n");
}
}
terror("fetch failed");
return;
}
-
+
print_rec(tdb, key, dbuf, NULL);
-
+
free( dbuf.dptr );
-
+
return;
}
terror("fetch failed");
return;
}
-
+
print_rec(tdb, key, dbuf, NULL);
-
+
dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
if ( !dst_tdb ) {
terror("unable to open destination tdb");
return;
}
-
+
if (tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) != 0) {
terror("failed to move record");
}
else
printf("record moved\n");
-
+
tdb_close( dst_tdb );
-
+
return;
}
{
TDB_DATA dbuf;
*pkey = tdb_firstkey(the_tdb);
-
+
dbuf = tdb_fetch(the_tdb, *pkey);
if (!dbuf.dptr) terror("fetch failed");
else {
{
TDB_DATA dbuf;
*pkey = tdb_nextkey(the_tdb, *pkey);
-
+
dbuf = tdb_fetch(the_tdb, *pkey);
- if (!dbuf.dptr)
+ if (!dbuf.dptr)
terror("fetch failed");
else
print_rec(the_tdb, *pkey, dbuf, NULL);
/* this tests tdb by doing lots of ops from several simultaneous
- writers - that stresses the locking code.
+ writers - that stresses the locking code.
*/
#include "replace.h"
system(ptr);
free(ptr);
}
-#endif
+#endif
}
static void fatal(const char *why)