1 // Don't run this. It doesn't work and if you try to run it you will immediately die.
3 // Copyright (c) 2023 by Art Cancro citadel.org
5 // This program is open source software. Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
13 #include <sys/types.h>
14 #include <sys/socket.h>
22 #include <libcitadel.h>
25 #include "../server/sysdep.h"
26 #include "../server/citadel_defs.h"
27 #include "../server/server.h"
28 #include "../server/citadel_dirs.h"
31 // Wrapper for realloc() that crashes and burns if the call fails.
32 void *reallok(void *ptr, size_t size) {
33 void *p = realloc(ptr, size);
35 fprintf(stderr, "realloc() failed to resize %p to %ld bytes, error: %m\n", ptr, size);
40 #define realloc reallok
43 // Open a database environment
44 DB_ENV *open_dbenv(char *dirname) {
51 int dbversion_major, dbversion_minor, dbversion_patch;
54 "db: open_dbenv() starting\n"
55 "db: Linked zlib: %s\n"
56 "db: Compiled libdb: %s\n"
57 "db: Linked libdb: %s\n",
60 db_version(&dbversion_major, &dbversion_minor, &dbversion_patch)
63 // Create synthetic integer version numbers and compare them.
64 // Never run with a libdb older than the one with which it was compiled.
65 int compiled_db_version = ( (DB_VERSION_MAJOR * 1000000) + (DB_VERSION_MINOR * 1000) + (DB_VERSION_PATCH) );
66 int linked_db_version = ( (dbversion_major * 1000000) + (dbversion_minor * 1000) + (dbversion_patch) );
67 if (compiled_db_version > linked_db_version) {
68 fprintf(stderr, "db: ctdldump is running with a version of libdb older than the one with which it was compiled.\n"
69 "db: This is an invalid configuration. ctdldump will now exit to prevent data loss.");
73 fprintf(stderr, "db: Setting up DB environment\n");
74 ret = db_env_create(&dbenv, 0);
76 fprintf(stderr, "db: db_env_create: %s\n", db_strerror(ret));
77 fprintf(stderr, "db: exit code %d\n", ret);
81 // We want to specify the shared memory buffer pool cachesize, but everything else is the default.
82 ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0);
84 fprintf(stderr, "db: set_cachesize: %s\n", db_strerror(ret));
85 dbenv->close(dbenv, 0);
86 fprintf(stderr, "db: exit code %d\n", ret);
90 if ((ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT))) {
91 fprintf(stderr, "db: set_lk_detect: %s\n", db_strerror(ret));
92 dbenv->close(dbenv, 0);
93 fprintf(stderr, "db: exit code %d\n", ret);
97 flags = DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_INIT_LOG;
98 fprintf(stderr, "db: dbenv open(dir=%s, flags=%d)\n", dirname, flags);
99 ret = dbenv->open(dbenv, dirname, flags, 0);
101 fprintf(stderr, "db: dbenv->open: %s\n", db_strerror(ret));
102 dbenv->close(dbenv, 0);
103 fprintf(stderr, "db: exit code %d\n", ret);
111 void close_dbenv(DB_ENV *dbenv) {
112 int ret = dbenv->close(dbenv, 0);
114 fprintf(stderr, "db: dbenv->close: %s\n", db_strerror(ret));
123 // convert function for a message in msgmain
124 void export_msgmain(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
127 memcpy(&in_msgnum, in_key->data, sizeof(in_msgnum));
128 out_msgnum = (long)in_msgnum;
130 if (in_key->size != 4) {
131 fprintf(stderr, "\033[31m\033[1m *** SOURCE DATABASE IS NOT 32-BIT *** ABORTING *** \033[0m\n");
135 // If the msgnum is negative, we are looking at METADATA
137 struct MetaData_32 *meta32 = (struct MetaData_32 *)in_data->data;
139 // fprintf(stderr, "\033[32m\033[1mMetadata: msgnum=%d , refcount=%d , content_type=\"%s\" , rfc822len=%d\033[0m\n", meta32->meta_msgnum, meta32->meta_refcount, meta32->meta_content_type, meta32->meta_rfc822_length);
141 out_key->size = sizeof(long);
142 out_key->data = realloc(out_key->data, out_key->size);
143 memcpy(out_key->data, &out_msgnum, sizeof(long));
145 out_data->size = sizeof(struct MetaData);
146 out_data->data = realloc(out_data->data, out_data->size);
147 struct MetaData *meta64 = (struct MetaData *)out_data->data;
148 memset(meta64, 0, sizeof(struct MetaData));
149 meta64->meta_msgnum = (long) meta32->meta_msgnum;
150 meta64->meta_refcount = (int) meta32->meta_refcount;
151 strcpy(meta64->meta_content_type, meta32->meta_content_type);
152 meta64->meta_rfc822_length = (long) meta32->meta_rfc822_length;
155 // If the msgnum is positive, we are looking at a MESSAGE
156 else if (in_msgnum > 0) {
157 out_key->size = sizeof(long);
158 out_key->data = realloc(out_key->data, out_key->size);
159 memcpy(out_key->data, &out_msgnum, sizeof(long));
161 // copy the message verbatim
162 out_data->size = in_data->size;
163 out_data->data = realloc(out_data->data, out_data->size);
164 memcpy(out_data->data, in_data->data, out_data->size);
165 // printf("\033[32m\033[1mMessage: %ld\033[0m\n", out_msgnum);
168 // If the msgnum is 0 it's probably not a valid record.
170 // printf("\033[31mmsgmain: message number 0 is impossible, skipping this record\033[0m\n");
175 // convert function for a user record
176 void export_users(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
178 // The key is a string so we can just copy it over
179 out_key->size = in_key->size;
180 out_key->data = realloc(out_key->data, out_key->size);
181 memcpy(out_key->data, in_key->data, in_key->size);
183 struct ctdluser_32 *user32 = (struct ctdluser_32 *)in_data->data;
185 out_data->size = sizeof(struct ctdluser);
186 out_data->data = realloc(out_data->data, out_data->size);
187 struct ctdluser *user64 = (struct ctdluser *)out_data->data;
189 user64->version = (int) user32->version;
190 user64->uid = (uid_t) user32->uid;
191 strcpy(user64->password, user32->password);
192 user64->flags = (unsigned) user32->flags;
193 user64->axlevel = (cit_uint8_t) user32->axlevel;
194 user64->usernum = (long) user32->usernum;
195 user64->lastcall = (time_t) user32->lastcall;
196 user64->USuserpurge = (int) user32->USuserpurge;
197 strcpy(user64->fullname, user32->fullname);
198 user64->msgnum_bio = (long) user32->msgnum_bio;
199 user64->msgnum_pic = (long) user32->msgnum_pic;
200 strcpy(user64->emailaddrs, user32->emailaddrs);
201 user64->msgnum_inboxrules = (long) user32->msgnum_inboxrules;
202 user64->lastproc_inboxrules = (long) user32->lastproc_inboxrules;
204 // printf("\033[32m\033[1mUser: %s\033[0m\n", user64->fullname);
208 // convert function for a room record
209 void export_rooms(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
211 // The key is a string so we can just copy it over
212 out_key->size = in_key->size;
213 out_key->data = realloc(out_key->data, out_key->size);
214 memcpy(out_key->data, in_key->data, in_key->size);
217 struct ctdlroom_32 *room32 = (struct ctdlroom_32 *)in_data->data;
218 out_data->size = sizeof(struct ctdlroom);
219 out_data->data = realloc(out_data->data, out_data->size);
220 struct ctdlroom *room64 = (struct ctdlroom *)out_data->data;
222 strcpy(room64->QRname, room32->QRname);
223 strcpy(room64->QRpasswd, room32->QRpasswd);
224 room64->QRroomaide = (long) room32->QRroomaide;
225 room64->QRhighest = (long) room32->QRhighest;
226 room64->QRgen = (time_t) room32->QRgen;
227 room64->QRflags = (unsigned) room32->QRflags;
228 strcpy(room64->QRdirname, room32->QRdirname);
229 room64->msgnum_info = (long) room32->msgnum_info;
230 room64->QRfloor = (char) room32->QRfloor;
231 room64->QRmtime = (time_t) room32->QRmtime;
232 room64->QRep.expire_mode = (int) room32->QRep.expire_mode;
233 room64->QRep.expire_value = (int) room32->QRep.expire_value;
234 room64->QRnumber = (long) room32->QRnumber;
235 room64->QRorder = (char) room32->QRorder;
236 room64->QRflags2 = (unsigned) room32->QRflags2;
237 room64->QRdefaultview = (int) room32->QRdefaultview;
238 room64->msgnum_pic = (long) room32->msgnum_pic;
240 // printf("\033[32m\033[1mRoom: %s\033[0m\n", room64->QRname);
244 // convert function for a floor record
245 void export_floors(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
247 // the key is an "int", and "int" is 32-bits on both 32 and 64 bit platforms.
248 out_key->size = in_key->size;
249 out_key->data = realloc(out_key->data, out_key->size);
250 memcpy(out_key->data, in_key->data, in_key->size);
253 struct floor_32 *floor32 = (struct floor_32 *)in_data->data;
254 out_data->size = sizeof(struct floor);
255 out_data->data = realloc(out_data->data, out_data->size);
256 struct floor *floor64 = (struct floor *)out_data->data;
258 // these are probably bit-for-bit identical, actually ... but we do it the "right" way anyway
259 floor64->f_flags = (unsigned short) floor32->f_flags;
260 strcpy(floor64->f_name, floor32->f_name);
261 floor64->f_ref_count = (int) floor32->f_ref_count;
262 floor64->f_ep.expire_mode = (int) floor32->f_ep.expire_mode;
263 floor64->f_ep.expire_value = (int) floor32->f_ep.expire_value;
265 // printf("\033[32m\033[1mFloor: %s\033[0m\n", floor64->f_name);
269 // convert function for a msglist or a fulltext index record
270 // (both are indexed by a long and the data is arrays of longs)
271 void export_msglists(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
274 char *table = (which_cdb == CDB_FULLTEXT) ? "FullText" : "Msglist";
276 // records are indexed by a single "long" and contains an array of zero or more "long"s
277 // and remember ... "long" is int32_t on the source system
280 memcpy(&in_roomnum, in_key->data, sizeof(in_roomnum));
281 out_roomnum = (long) in_roomnum;
283 if (in_key->size != 4) {
284 fprintf(stderr, "\033[31m\033[1m *** SOURCE DATABASE IS NOT 32-BIT *** ABORTING *** \033[0m\n");
288 int num_msgs = in_data->size / sizeof(int32_t);
289 // printf("\033[32m\033[1m%s: key %ld (%d messages)\033[0m\n", table, out_roomnum, num_msgs);
291 // the key is a "long"
292 out_key->size = sizeof(out_roomnum);
293 out_key->data = realloc(out_key->data, out_key->size);
294 memcpy(out_key->data, &out_roomnum, sizeof(out_roomnum));
296 // the data is another array, but a wider type
297 out_data->size = sizeof(long) * num_msgs;
298 out_data->data = realloc(out_data->data, out_data->size);
302 for (i=0; i<num_msgs; ++i) {
303 memcpy(&in_msg, (in_data->data + (i * sizeof(int32_t))), sizeof(int32_t));
304 out_msg = (long) in_msg;
305 memcpy((out_data->data + (i * sizeof(long))), &out_msg, sizeof(long));
306 // printf("msg#%ld\n", out_msg);
311 // convert function for a visit record
312 void export_visits(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
315 struct visit_32 *visit32 = (struct visit_32 *)in_data->data;
316 out_data->size = sizeof(struct visit);
317 out_data->data = realloc(out_data->data, out_data->size);
318 struct visit *visit64 = (struct visit *)out_data->data;
320 // the data (zero it out so it will compress well)
321 memset(visit64, 0, sizeof(struct visit));
322 visit64->v_roomnum = (long) visit32->v_roomnum;
323 visit64->v_roomgen = (long) visit32->v_roomgen;
324 visit64->v_usernum = (long) visit32->v_usernum;
325 visit64->v_lastseen = (long) visit32->v_lastseen;
326 visit64->v_flags = (unsigned) visit32->v_flags;
327 strcpy(visit64->v_seen, visit32->v_seen);
328 strcpy(visit64->v_answered, visit32->v_answered);
329 visit64->v_view = (int) visit32->v_view;
331 // printf("\033[32m\033[1mVisit: room %10ld, gen %10ld, user %10ld\033[0m\n", visit64->v_roomnum, visit64->v_roomgen, visit64->v_usernum);
333 // create the key (which is based on the data, so there is no need to convert the old key)
334 out_key->size = sizeof(struct visit_index);
335 out_key->data = realloc(out_key->data, out_key->size);
336 struct visit_index *newvisitindex = (struct visit_index *) out_key->data;
337 newvisitindex->iRoomID = visit64->v_roomnum;
338 newvisitindex->iRoomGen = visit64->v_roomgen;
339 newvisitindex->iUserID = visit64->v_usernum;
343 // convert function for a directory record
344 void export_dir(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
346 // the key is a string
347 out_key->size = in_key->size;
348 out_key->data = realloc(out_key->data, out_key->size + 1);
349 memcpy(out_key->data, in_key->data, in_key->size);
350 char *k = (char *)out_key->data;
351 k[out_key->size] = 0;
353 // the data is also a string
354 out_data->size = in_data->size;
355 out_data->data = realloc(out_data->data, out_data->size + 1);
356 memcpy(out_data->data, in_data->data, in_data->size);
357 char *d = (char *)out_data->data;
358 d[out_data->size] = 0;
360 // please excuse my friend, he isn't null terminated
361 // printf("\033[32m\033[1mDirectory entry: %s -> %s\033[0m\n", (char *)out_key->data, (char *)out_data->data);
365 // convert function for a use table record
366 void export_usetable(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
368 // the key is an int, which is the same size (32 bits) on both 32 and 64 bit systems
369 out_key->size = in_key->size;
370 out_key->data = realloc(out_key->data, out_key->size);
371 memcpy(out_key->data, in_key->data, in_key->size);
373 // the data is a "struct UseTable"
374 struct UseTable_32 *use32 = (struct UseTable_32 *)in_data->data;
375 out_data->size = sizeof(struct UseTable);
376 out_data->data = realloc(out_data->data, out_data->size);
377 memset(out_data->data, 0, out_data->size);
378 struct UseTable *use64 = (struct UseTable *)out_data->data;
381 use64->hash = use32->hash;
382 use64->timestamp = (time_t) use32->timestamp;
384 // printf("\033[32m\033[1muse table: %d , %s\033[0m\n", use64->hash, asctime(localtime(&use64->timestamp)));
388 // convert function for large message texts
389 void export_bigmsgs(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
391 // The key is a packed long
394 memcpy(&in_msgnum, in_key->data, sizeof(in_msgnum));
395 out_msgnum = (long)in_msgnum;
397 if (in_key->size != 4) {
398 fprintf(stderr, "\033[31m\033[1m *** SOURCE DATABASE IS NOT 32-BIT *** ABORTING *** \033[0m\n");
402 out_key->size = sizeof(long);
403 out_key->data = realloc(out_key->data, out_key->size);
404 memcpy(out_key->data, &out_msgnum, sizeof(long));
406 // the data is binary-ish but has no packed integers
407 out_data->size = in_data->size;
408 out_data->data = realloc(out_data->data, out_data->size);
409 memcpy(out_data->data, in_data->data, in_data->size);
411 // printf("\033[32m\033[1mBigmsg %ld , length %d\033[0m\n", out_msgnum, out_data->size);
415 // convert function for EUID Index records
416 void export_euidindex(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
418 // The structure of an euidindex record *key* is:
419 // |----room_number----|----------EUID-------------|
420 // (sizeof long) (actual length of euid)
422 // The structure of an euidindex record *value* is:
423 // |-----msg_number----|----room_number----|----------EUID-------------|
424 // (sizeof long) (sizeof long) (actual length of euid)
426 int32_t in_msgnum = 0;
427 int32_t in_roomnum = 0;
430 long out_roomnum = 0;
432 memcpy(&in_msgnum, in_data->data, sizeof(in_msgnum));
433 memcpy(&in_roomnum, in_data->data+sizeof(int32_t), sizeof(in_msgnum));
434 strcpy(euid, in_data->data+(sizeof(int32_t)*2));
436 out_msgnum = (long) in_msgnum;
437 out_roomnum = (long) in_roomnum;
438 // printf("euidindex: msgnum=%ld, roomnum=%ld, euid=\"%s\"\n", out_msgnum, out_roomnum, euid);
440 out_key->size = sizeof(long) + strlen(euid) + 1;
441 out_key->data = realloc(out_key->data, out_key->size);
442 memcpy(out_key->data, &out_roomnum, sizeof(out_roomnum));
443 strcpy(out_key->data+sizeof(out_roomnum), euid);
445 out_data->size = sizeof(long) + sizeof(long) + strlen(euid) + 1;
446 out_data->data = realloc(out_data->data, out_data->size);
447 memcpy(out_data->data, &out_msgnum, sizeof(out_msgnum));
448 memcpy(out_data->data+sizeof(out_msgnum), &out_roomnum, sizeof(out_roomnum));
449 strcpy(out_data->data+sizeof(out_msgnum)+sizeof(out_roomnum), euid);
455 //printf(" in_key: ");
456 //for (i=0; i<in_key->size; ++i) {
458 //memcpy(&ch, in_key->data+i, 1);
459 //printf("%02X ", (int) ch);
463 //printf(" out_key: ");
464 //for (i=0; i<out_key->size; ++i) {
466 //memcpy(&ch, out_key->data+i, 1);
467 //printf("%02X ", (int) ch);
471 //printf(" in_data: ");
472 //for (i=0; i<in_data->size; ++i) {
474 //memcpy(&ch, in_data->data+i, 1);
475 // printf("%02X ", (int) ch);
479 //printf("out_data: ");
480 //for (i=0; i<out_data->size; ++i) {
482 //memcpy(&ch, out_data->data+i, 1);
483 //printf("%02X ", (int) ch);
491 // convert users-by-number records
492 void export_usersbynumber(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
495 // and remember ... "long" is int32_t on the source system
498 memcpy(&in_usernum, in_key->data, sizeof(in_usernum));
499 out_usernum = (long) in_usernum;
501 if (in_key->size != 4) {
502 fprintf(stderr, "\033[31m\033[1m *** SOURCE DATABASE IS NOT 32-BIT *** ABORTING *** \033[0m\n");
506 out_key->size = sizeof(out_usernum);
507 out_key->data = realloc(out_key->data, out_key->size);
508 memcpy(out_key->data, &out_usernum, sizeof(out_usernum));
511 out_data->size = in_data->size;
512 out_data->data = realloc(out_data->data, out_data->size);
513 memcpy(out_data->data, in_data->data, in_data->size);
515 // printf("usersbynumber: %ld --> %s\n", out_usernum, (char *)out_data->data);
519 // convert function for a config record
520 void export_config(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT *out_data) {
522 // the key is a string
523 out_key->size = in_key->size;
524 out_key->data = realloc(out_key->data, out_key->size + 1);
525 memcpy(out_key->data, in_key->data, in_key->size);
526 char *k = (char *)out_key->data;
527 k[out_key->size] = 0;
529 // the data is a pair of strings
530 out_data->size = in_data->size;
531 out_data->data = realloc(out_data->data, out_data->size + 1);
532 memcpy(out_data->data, in_data->data, in_data->size);
533 char *d = (char *)out_data->data;
534 d[out_data->size] = 0;
536 // please excuse my friend, he isn't null terminated
537 // printf("\033[32m\033[1mConfig entry: %s -> %s\033[0m\n", (char *)out_key->data, (char *)out_data->data+strlen(out_data->data)+1);
542 // For obsolete databases, zero all the output
543 void zero_function(int which_cdb, DBT *in_key, DBT *in_data) {
544 printf("%d: \n", which_cdb);
548 void (*export_functions[])(int which_cdb, DBT *in_key, DBT *in_data) = {
549 zero_function, // CDB_MSGMAIN
550 zero_function, // CDB_USERS
551 zero_function, // CDB_ROOMS
552 zero_function, // CDB_FLOORTAB
553 zero_function, // CDB_MSGLISTS
554 zero_function, // CDB_VISIT
555 zero_function, // CDB_DIRECTORY
556 zero_function, // CDB_USETABLE
557 zero_function, // CDB_BIGMSGS
558 zero_function, // CDB_FULLTEXT
559 zero_function, // CDB_EUIDINDEX
560 zero_function, // CDB_USERSBYNUMBER
561 zero_function, // CDB_UNUSED1 (obsolete)
562 zero_function // CDB_CONFIG
566 void export_table(int which_cdb, DB_ENV *src_dbenv) {
572 // shamelessly swiped from https://docs.oracle.com/database/bdb181/html/programmer_reference/am_cursor.html
575 DBT in_key, in_data, uncomp_data;
576 int num_good_rows = 0;
577 int num_bad_rows = 0;
579 snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
581 // create a database handle for the source table
582 ret = db_create(&src_dbp, src_dbenv, 0);
584 fprintf(stderr, "db: db_create: %s\n", db_strerror(ret));
585 fprintf(stderr, "db: exit code %d\n", ret);
589 // open the file containing the source table
590 ret = src_dbp->open(src_dbp, NULL, dbfilename, NULL, DB_BTREE, 0, 0600);
592 fprintf(stderr, "db: db_open: %s\n", db_strerror(ret));
593 fprintf(stderr, "db: exit code %d\n", ret);
597 // Acquire a cursor to read the source table
598 if ((ret = src_dbp->cursor(src_dbp, NULL, &src_dbcp, 0)) != 0) {
599 fprintf(stderr, "db: db_cursor: %s\n", db_strerror(ret));
600 fprintf(stderr, "db: exit code %d\n", ret);
604 // Zero out these database keys
605 memset(&in_key, 0, sizeof(DBT)); // input
606 memset(&in_data, 0, sizeof(DBT));
607 memset(&uncomp_data, 0, sizeof(DBT)); // decompressed input (the key doesn't change)
609 // Walk through the database, calling convert functions as we go and clearing buffers before each call.
610 while (ret = src_dbcp->get(src_dbcp, &in_key, &in_data, DB_NEXT) == 0) {
612 // If either the key or data are zero length, skip this record
613 if ((in_key.size == 0) || (in_data.size == 0)) {
617 else { // Both key and data are >0 length so we're good to go
619 // Do we need to decompress?
620 static int32_t magic = COMPRESS_MAGIC;
622 if ( (in_data.size >= sizeof(struct CtdlCompressHeader)) && (!memcmp(in_data.data, &magic, sizeof(magic))) ) {
624 // yes, we need to decompress
626 struct CtdlCompressHeader comp;
627 memcpy(&comp, in_data.data, sizeof(struct CtdlCompressHeader));
628 uncomp_data.size = comp.uncompressed_len;
629 uncomp_data.data = realloc(uncomp_data.data, uncomp_data.size);
630 destLen = (uLongf)comp.uncompressed_len;
632 ret = uncompress((Bytef *)uncomp_data.data, (uLongf *)&destLen, (const Bytef *)in_data.data+sizeof(struct CtdlCompressHeader), (uLong)comp.compressed_len);
634 fprintf(stderr, "db: uncompress() error %d\n", ret);
639 // Call the convert function registered to this table
640 export_functions[which_cdb](which_cdb, &in_key, (compressed ? &uncomp_data : &in_data));
642 // Knowing the total number of rows isn't critical to the program. It's just for the user to know.
647 // free any leftover out_data pointers
648 free(uncomp_data.data);
650 // ...and close the database (table)
651 ret = src_dbp->close(src_dbp, 0);
653 fprintf(stderr, "db: db_close: %s\n", db_strerror(ret));
660 int main(int argc, char **argv) {
662 char *src_dir = NULL;
663 char *dst_dir = NULL;
665 static DB_ENV *src_dbenv; // Source DB environment (global)
667 // Parse command line
669 while ((a = getopt(argc, argv, "h:d:y")) != EOF) {
681 fprintf(stderr, "%s: usage: %s -s source_dir -d dest_dir\n", argv[0], argv[0]);
687 fprintf(stderr, "------------------------------------------------------------------------\n");
688 fprintf(stderr, "This utility must be run while the server is OFFLINE. \n");
689 fprintf(stderr, "We \033[1mguarantee\033[0m data corruption if you do not \n");
690 fprintf(stderr, "observe this warning! The source [-s] directory should contain a copy \n");
691 fprintf(stderr, "of the database from your source system. The dump [-d] directory \n");
692 fprintf(stderr, "should be empty and will receive your dump file. \n");
693 fprintf(stderr, "------------------------------------------------------------------------\n");
694 fprintf(stderr, " Source (database) directory: %s\n", src_dir);
695 fprintf(stderr, "------------------------------------------------------------------------\n");
697 if (confirmed == 1) {
698 fprintf(stderr, "You have specified the [-y] flag, so processing will continue.\n");
701 fprintf(stderr, "Please read [ https://www.citadel.org/ctdldump.html ] to learn how to proceed.\n");
705 src_dbenv = open_dbenv(src_dir);
706 for (i = 0; i < MAXCDB; ++i) {
707 export_table(i, src_dbenv);
709 close_dbenv(src_dbenv);