]> jfr.im git - solanum.git/blobdiff - bandb/bantool.c
Add exempt logic for open proxies
[solanum.git] / bandb / bantool.c
index c858edbfb7f57c85865f05dbb3d7a388ed35556f..e89fa5b9e4931ab1352c41647c33113c4ca37948 100644 (file)
@@ -22,9 +22,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $
- *
- *
  * The following server admins have either contributed various configs to test against,
  * or helped with debugging and feature requests. Many thanks to them.
  * stevoo / efnet.port80.se
  *
  */
 
-#define _XOPEN_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 
 #include "stdinc.h"
-#include "common.h"
 #include "rsdb.h"
 
 #define EmptyString(x) ((x == NULL) || (*(x) == '\0'))
@@ -97,16 +92,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);
@@ -129,7 +124,7 @@ static void wipe_schema(void);
 static void drop_dupes(const char *user, const char *host, const char *t);
 
 /**
- *  swing your pants 
+ *  swing your pants
  */
 int
 main(int argc, char *argv[])
@@ -149,32 +144,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);
@@ -202,10 +197,9 @@ main(int argc, char *argv[])
                rb_strlcpy(etc, ETCPATH, sizeof(ETCPATH));
 
        fprintf(stdout,
-               "* ircd-ratbox bantool v.%s ($Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $)\n",
-               BT_VERSION);
+               "* charybdis bantool v.%s\n", BT_VERSION);
 
-       if(flag.pretend == NO)
+       if(flag.pretend == false)
        {
                if(rsdb_init(db_error_cb) == -1)
                {
@@ -219,7 +213,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");
@@ -231,16 +225,16 @@ 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++)
        {
-               rb_snprintf(conf, sizeof(conf), "%s/%s.conf%s",
+               snprintf(conf, sizeof(conf), "%s/%s.conf%s",
                            etc, bandb_table[i], bandb_suffix[i]);
 
-               if(flag.import && flag.pretend == NO)
+               if(flag.import && flag.pretend == false)
                        rsdb_transaction(RSDB_TRANS_START);
 
                if(flag.import)
@@ -249,17 +243,17 @@ 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);
        }
 
        if(flag.import)
        {
                if(count.error && flag.verbose)
-                       fprintf(stderr, "* I was unable to locate %i config files to import.\n",
+                       fprintf(stderr, "* I was unable to locate %u config files to import.\n",
                                count.error);
 
-               fprintf(stdout, "* Import Stats: Klines: %i, Dlines: %i, Xlines: %i, Resvs: %i \n",
+               fprintf(stdout, "* Import Stats: Klines: %u, Dlines: %u, Xlines: %u, Resvs: %u \n",
                        count.klines, count.dlines, count.xlines, count.resvs);
 
                fprintf(stdout,
@@ -298,11 +292,11 @@ export_config(const char *conf, int id)
                return;
 
        if(strstr(conf, ".perm") != 0)
-               rb_snprintf(sql, sizeof(sql),
+               snprintf(sql, sizeof(sql),
                            "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 1 ORDER BY time",
                            bandb_table[id]);
        else
-               rb_snprintf(sql, sizeof(sql),
+               snprintf(sql, sizeof(sql),
                            "SELECT DISTINCT mask1,mask2,reason,oper,time FROM %s WHERE perm = 0 ORDER BY time",
                            bandb_table[id]);
 
@@ -331,7 +325,7 @@ export_config(const char *conf, int id)
                {
                case BANDB_DLINE:
                case BANDB_DLINE_PERM:
-                       rb_snprintf(buf, sizeof(buf),
+                       snprintf(buf, sizeof(buf),
                                    "\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n",
                                    table.row[j][mask1],
                                    mangle_reason(table.row[j][reason]),
@@ -341,7 +335,7 @@ export_config(const char *conf, int id)
 
                case BANDB_XLINE:
                case BANDB_XLINE_PERM:
-                       rb_snprintf(buf, sizeof(buf),
+                       snprintf(buf, sizeof(buf),
                                    "\"%s\",\"0\",\"%s\",\"%s\",%s\n",
                                    escape_quotes(table.row[j][mask1]),
                                    mangle_reason(table.row[j][reason]),
@@ -350,7 +344,7 @@ export_config(const char *conf, int id)
 
                case BANDB_RESV:
                case BANDB_RESV_PERM:
-                       rb_snprintf(buf, sizeof(buf),
+                       snprintf(buf, sizeof(buf),
                                    "\"%s\",\"%s\",\"%s\",%s\n",
                                    table.row[j][mask1],
                                    mangle_reason(table.row[j][reason]),
@@ -359,7 +353,7 @@ export_config(const char *conf, int id)
 
 
                default:        /* Klines */
-                       rb_snprintf(buf, sizeof(buf),
+                       snprintf(buf, sizeof(buf),
                                    "\"%s\",\"%s\",\"%s\",\"\",\"%s\",\"%s\",%s\n",
                                    table.row[j][mask1], table.row[j][mask2],
                                    mangle_reason(table.row[j][reason]),
@@ -390,12 +384,12 @@ import_config(const char *conf, int id)
        int i = 0;
 
        char f_perm = 0;
-       char *f_mask1 = NULL;
-       char *f_mask2 = NULL;
-       char *f_oper = NULL;
-       char *f_time = NULL;
-       char *f_reason = NULL;
-       char *f_oreason = NULL;
+       const char *f_mask1 = NULL;
+       const char *f_mask2 = NULL;
+       const char *f_oper = NULL;
+       const char *f_time = NULL;
+       const char *f_reason = NULL;
+       const char *f_oreason = NULL;
        char newreason[REASONLEN];
 
        if(flag.verbose)
@@ -480,6 +474,8 @@ import_config(const char *conf, int id)
 
                f_oper = getfield(NULL);
                f_time = strip_quotes(f_oper + strlen(f_oper) + 2);
+               if(EmptyString(f_oper))
+                       f_oper = "unknown";
 
                /* meh */
                if(id == BANDB_KLINE || id == BANDB_KLINE_PERM)
@@ -496,13 +492,13 @@ import_config(const char *conf, int id)
 
                /* append operreason_field to reason_field */
                if(!EmptyString(f_oreason))
-                       rb_snprintf(newreason, sizeof(newreason), "%s | %s", f_reason, f_oreason);
+                       snprintf(newreason, sizeof(newreason), "%s | %s", f_reason, f_oreason);
                else
-                       rb_snprintf(newreason, sizeof(newreason), "%s", f_reason);
+                       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,
@@ -541,6 +537,8 @@ import_config(const char *conf, int id)
        if(flag.verbose)
                fprintf(stdout, "%*s\n", strlen(bandb_suffix[id]) > 0 ? 10 : 15, "imported.");
 
+       fclose(fd);
+
        return;
 }
 
@@ -856,7 +854,7 @@ bt_smalldate(const char *string)
        lt = gmtime(&t);
        if(lt == NULL)
                return NULL;
-       rb_snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
+       snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d",
                    lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min);
        return buf;
 }
@@ -867,9 +865,8 @@ bt_smalldate(const char *string)
 void
 print_help(int i_exit)
 {
-       fprintf(stderr, "bantool v.%s - the ircd-ratbox database tool.\n", BT_VERSION);
+       fprintf(stderr, "bantool v.%s - the charybdis database tool.\n", BT_VERSION);
        fprintf(stderr, "Copyright (C) 2008 Daniel J Reidy <dubkat@gmail.com>\n");
-       fprintf(stderr, "$Id: bantool.c 26164 2008-10-26 19:52:43Z androsyn $\n\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"
                "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"