]> jfr.im git - solanum.git/blobdiff - bandb/bantool.c
global masktrace doesn't need to be an operspy action
[solanum.git] / bandb / bantool.c
index 4cd53bd73c140f2a80d40a60c9112b1006acd953..5563a4a921af2ef2b97cbf73da72c524c291f0cb 100644 (file)
 #include <time.h>
 
 #include "stdinc.h"
-#include "common.h"
 #include "rsdb.h"
 
 #define EmptyString(x) ((x == NULL) || (*(x) == '\0'))
-#define CheckEmpty(x) EmptyString(x) ? "" : x
 
 #define BT_VERSION "0.4.1"
 
@@ -93,16 +91,16 @@ struct counter
 /* flags set by command line options */
 struct flags
 {
-       int none;
-       int export;
-       int import;
-       int verify;
-       int vacuum;
-       int pretend;
-       int verbose;
-       int wipe;
-       int dupes_ok;
-} flag = {YES, NO, NO, NO, NO, NO, NO, NO, NO};
+       bool none;
+       bool export;
+       bool import;
+       bool verify;
+       bool vacuum;
+       bool pretend;
+       bool verbose;
+       bool wipe;
+       bool dupes_ok;
+} flag = {true, false, false, false, false, false, false, false, false};
 /* *INDENT-ON* */
 
 static int table_has_rows(const char *table);
@@ -120,7 +118,7 @@ static void db_reclaim_slack(void);
 static void export_config(const char *conf, int id);
 static void import_config(const char *conf, int id);
 static void check_schema(void);
-static void print_help(int i_exit);
+static void print_help(int i_exit) __attribute__((noreturn));
 static void wipe_schema(void);
 static void drop_dupes(const char *user, const char *host, const char *t);
 
@@ -145,32 +143,32 @@ main(int argc, char *argv[])
                        print_help(EXIT_SUCCESS);
                        break;
                case 'i':
-                       flag.none = NO;
-                       flag.import = YES;
+                       flag.none = false;
+                       flag.import = true;
                        break;
                case 'e':
-                       flag.none = NO;
-                       flag.export = YES;
+                       flag.none = false;
+                       flag.export = true;
                        break;
                case 'u':
-                       flag.none = NO;
-                       flag.verify = YES;
+                       flag.none = false;
+                       flag.verify = true;
                        break;
                case 's':
-                       flag.none = NO;
-                       flag.vacuum = YES;
+                       flag.none = false;
+                       flag.vacuum = true;
                        break;
                case 'p':
-                       flag.pretend = YES;
+                       flag.pretend = true;
                        break;
                case 'v':
-                       flag.verbose = YES;
+                       flag.verbose = true;
                        break;
                case 'w':
-                       flag.wipe = YES;
+                       flag.wipe = true;
                        break;
                case 'd':
-                       flag.dupes_ok = YES;
+                       flag.dupes_ok = true;
                        break;
                default:        /* '?' */
                        print_help(EXIT_FAILURE);
@@ -198,9 +196,9 @@ main(int argc, char *argv[])
                rb_strlcpy(etc, ETCPATH, sizeof(ETCPATH));
 
        fprintf(stdout,
-               "* charybdis bantool v.%s\n", BT_VERSION);
+               "* solanum bantool v.%s\n", BT_VERSION);
 
-       if(flag.pretend == NO)
+       if(flag.pretend == false)
        {
                if(rsdb_init(db_error_cb) == -1)
                {
@@ -214,7 +212,7 @@ main(int argc, char *argv[])
 
                if(flag.import && flag.wipe)
                {
-                       flag.dupes_ok = YES;    /* dont check for dupes if we are wiping the db clean */
+                       flag.dupes_ok = true;   /* dont check for dupes if we are wiping the db clean */
                        for(i = 0; i < 3; i++)
                                fprintf(stdout,
                                        "* WARNING: YOU ARE ABOUT TO WIPE YOUR DATABASE!\n");
@@ -226,16 +224,19 @@ main(int argc, char *argv[])
                        wipe_schema();
                }
        }
-       if(flag.verbose && flag.dupes_ok == YES)
+       if(flag.verbose && flag.dupes_ok == true)
                fprintf(stdout, "* Allowing duplicate bans...\n");
 
        /* checking for our files to import or export */
        for(i = 0; i < LAST_BANDB_TYPE; i++)
        {
-               snprintf(conf, sizeof(conf), "%s/%s.conf%s",
-                           etc, bandb_table[i], bandb_suffix[i]);
+               if (snprintf(conf, sizeof(conf), "%s/%s.conf%s",
+                           etc, bandb_table[i], bandb_suffix[i]) >= sizeof(conf)) {
+                       fprintf(stderr, "* Error: Config filename too long\n");
+                       exit(EXIT_FAILURE);
+               }
 
-               if(flag.import && flag.pretend == NO)
+               if(flag.import && flag.pretend == false)
                        rsdb_transaction(RSDB_TRANS_START);
 
                if(flag.import)
@@ -244,7 +245,7 @@ main(int argc, char *argv[])
                if(flag.export)
                        export_config(conf, i);
 
-               if(flag.import && flag.pretend == NO)
+               if(flag.import && flag.pretend == false)
                        rsdb_transaction(RSDB_TRANS_END);
        }
 
@@ -497,9 +498,9 @@ import_config(const char *conf, int id)
                else
                        snprintf(newreason, sizeof(newreason), "%s", f_reason);
 
-               if(flag.pretend == NO)
+               if(flag.pretend == false)
                {
-                       if(flag.dupes_ok == NO)
+                       if(flag.dupes_ok == false)
                                drop_dupes(f_mask1, f_mask2, bandb_table[id]);
 
                        rsdb_exec(NULL,
@@ -742,7 +743,7 @@ check_schema(void)
                NULL
        };
 
-       for(i = 0; i < LAST_BANDB_TYPE; i++)
+       for(i = 0; i < LAST_BANDB_TYPE; i += 2 /* skip over _PERM */)
        {
                if(!table_exists(bandb_table[i]))
                {
@@ -769,8 +770,6 @@ check_schema(void)
                                          columns[j], type);
                        }
                }
-
-               i++;            /* skip over .perm */
        }
 }
 
@@ -808,17 +807,16 @@ table_has_rows(const char *dbtab)
 }
 
 /**
- * completly wipes out an existing ban.db of all entries.
+ * completely wipes out an existing ban.db of all entries.
  */
 static void
 wipe_schema(void)
 {
        int i;
        rsdb_transaction(RSDB_TRANS_START);
-       for(i = 0; i < LAST_BANDB_TYPE; i++)
+       for(i = 0; i < LAST_BANDB_TYPE; i += 2 /* double increment to skip over _PERM */)
        {
                rsdb_exec(NULL, "DROP TABLE %s", bandb_table[i]);
-               i++;            /* double increment to skip over .perm */
        }
        rsdb_transaction(RSDB_TRANS_END);
 
@@ -866,7 +864,7 @@ bt_smalldate(const char *string)
 void
 print_help(int i_exit)
 {
-       fprintf(stderr, "bantool v.%s - the charybdis database tool.\n", BT_VERSION);
+       fprintf(stderr, "bantool v.%s - the solanum database tool.\n", BT_VERSION);
        fprintf(stderr, "Copyright (C) 2008 Daniel J Reidy <dubkat@gmail.com>\n");
        fprintf(stderr, "This program is distributed in the hope that it will be useful,\n"
                "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
@@ -882,15 +880,15 @@ print_help(int i_exit)
        fprintf(stderr, "       -s : Reclaim empty slack space the database may be taking up.\n");
        fprintf(stderr, "       -u : Update the database tables to support any new features.\n");
        fprintf(stderr,
-               "            This is automaticlly done if you are importing or exporting\n");
+               "            This is automatically done if you are importing or exporting\n");
        fprintf(stderr, "            but should be run whenever you upgrade the ircd.\n");
        fprintf(stderr,
                "       -p : pretend, checks for the configs, and parses them, then tells you some data...\n");
        fprintf(stderr, "            but does not touch your database.\n");
        fprintf(stderr,
                "       -v : Be verbose... and it *is* very verbose! (intended for debugging)\n");
-       fprintf(stderr, "       -d : Enable checking for redunant entries.\n");
-       fprintf(stderr, "       -w : Completly wipe your database clean. May be used with -i \n");
+       fprintf(stderr, "       -d : Enable checking for redundant entries.\n");
+       fprintf(stderr, "       -w : Completely wipe your database clean. May be used with -i \n");
        fprintf(stderr,
                "     path : An optional directory containing old ratbox configs for import, or export.\n");
        fprintf(stderr, "            If not specified, it looks in PREFIX/etc.\n");