f76b81d484e1dc752df60d74b8abffa1e31b61bc
[citadel.git] / citadel / utils / dbnothing.c
1 // This is a test utility for the backend API.  It simply opens and closes the databases.
2 // There is no need for end users to ever run this program.  So don't.  And don't ask.
3 //
4 // Copyright (c) 2024 by Art Cancro citadel.org
5 //
6 // This program is open source software.  Use, duplication, or disclosure
7 // is subject to the terms of the GNU General Public License, version 3.
8
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #include <stdio.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <sys/un.h>
17 #include <netdb.h>
18 #include <string.h>
19 #include <pwd.h>
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <limits.h>
23 #include <syslog.h>
24 #include <libcitadel.h>
25 #include <zlib.h>
26 #include "../server/sysdep.h"
27 #include "../server/citadel_defs.h"
28 #include "../server/server.h"
29 #include "../server/citadel_dirs.h"
30 #include "../server/database.h"
31
32 uid_t ctdluid = 0;
33
34
35 int main(int argc, char **argv) {
36         int i = 0;
37         int confirmed = 0;
38         char *ctdldir = CTDLDIR;
39
40         // display the greeting
41         fprintf(stderr, "\033[44m\033[1m"
42                 "╔════════════════════════════════════════════════════════════════════════╗\n"
43                 "║ dbnothing utility for Citadel                                          ║\n"
44                 "║ Copyright (c) 2023-2024 by citadel.org et al.                          ║\n"
45                 "║ This program is open source software.  Use, duplication, or disclosure ║\n"
46                 "║ is subject to the terms of the GNU General Public license v3.          ║\n"
47                 "╚════════════════════════════════════════════════════════════════════════╝\033[0m\n"
48         );
49
50         // Parse command line
51         int a;
52         while ((a = getopt(argc, argv, "h:y")) != EOF) {
53                 switch (a) {
54                 case 'h':
55                         ctdldir = optarg;
56                         break;
57                 default:
58                         fprintf(stderr, "%s: usage: %s -s citadel_dir [>dumpfile]\n", argv[0], argv[0]);
59                         exit(2);
60                 }
61         }
62
63         if (chdir(ctdldir) != 0) {
64                 fprintf(stderr, "ctdlload: unable to change directory to [%s]: %m", ctdldir);
65                 exit(2);
66         }
67
68         // backend modules use syslog -- redirect to stderr
69         openlog("dbnothing", LOG_PERROR , LOG_DAEMON);
70
71         // initialize the database backend
72         cdb_init_backends();
73         cdb_open_databases();
74
75         // do nothing
76         fprintf(stderr, "\ndbnothing: doing nothing\n\n");
77
78         // close databases
79         cdb_close_databases();
80
81         fprintf(stderr, "dbnothing: \033[32m\033[1mfinished\033[0m\n");
82         exit(0);
83 }