]> jfr.im git - solanum.git/blobdiff - bandb/bantool.c
callerid: actually the guard should be for source_p
[solanum.git] / bandb / bantool.c
index a3af93cc8fe6d5d5c704c2014dc12f5edd223d07..2c385f024b29cf911f28b463766d2a1ab1f9dc19 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"
 
@@ -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);
 
@@ -232,8 +230,11 @@ main(int argc, char *argv[])
        /* 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 == false)
                        rsdb_transaction(RSDB_TRANS_START);
@@ -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 */
        }
 }
 
@@ -815,10 +814,9 @@ 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);