]> jfr.im git - solanum.git/blobdiff - bandb/bandb.c
refuse opers setting an invalidly long k-line reason
[solanum.git] / bandb / bandb.c
index cce310c4bf9d1350a8b8814950ac71cff49a58c4..85487447ab562c9f15977bf7458daa2775718a28 100644 (file)
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: bandb.c 26094 2008-09-19 15:33:46Z androsyn $
  */
 #include "setup.h"
-#include <ratbox_lib.h>
+#include <rb_lib.h>
 #include <stdio.h>
 #include "rsdb.h"
-#include "common.h"
+#include "ircd_defs.h"
 
 
 #define MAXPARA 10
 
+#define COMMIT_INTERVAL 3 /* seconds */
+
 typedef enum
 {
        BANDB_KLINE,
@@ -57,9 +57,17 @@ static const char *bandb_table[LAST_BANDB_TYPE] = {
 
 
 static rb_helper *bandb_helper;
+static int in_transaction;
 
 static void check_schema(void);
 
+static void
+bandb_commit(void *unused)
+{
+       rsdb_transaction(RSDB_TRANS_END);
+       in_transaction = 0;
+}
+
 static void
 parse_ban(bandb_type type, char *parv[], int parc)
 {
@@ -89,6 +97,14 @@ parse_ban(bandb_type type, char *parv[], int parc)
        perm = parv[para++];
        reason = parv[para++];
 
+       if(!in_transaction)
+       {
+               rsdb_transaction(RSDB_TRANS_START);
+               in_transaction = 1;
+               rb_event_addonce("bandb_commit", bandb_commit, NULL,
+                               COMMIT_INTERVAL);
+       }
+
        rsdb_exec(NULL,
                  "INSERT INTO %s (mask1, mask2, oper, time, perm, reason) VALUES('%Q', '%Q', '%Q', %s, %s, '%Q')",
                  bandb_table[type], mask1, mask2 ? mask2 : "", oper, curtime, perm, reason);
@@ -113,6 +129,14 @@ parse_unban(bandb_type type, char *parv[], int parc)
        if(type == BANDB_KLINE)
                mask2 = parv[2];
 
+       if(!in_transaction)
+       {
+               rsdb_transaction(RSDB_TRANS_START);
+               in_transaction = 1;
+               rb_event_addonce("bandb_commit", bandb_commit, NULL,
+                               COMMIT_INTERVAL);
+       }
+
        rsdb_exec(NULL, "DELETE FROM %s WHERE mask1='%Q' AND mask2='%Q'",
                  bandb_table[type], mask1, mask2 ? mask2 : "");
 }
@@ -135,11 +159,11 @@ list_bans(void)
                for(j = 0; j < table.row_count; j++)
                {
                        if(i == BANDB_KLINE)
-                               rb_snprintf(buf, sizeof(buf), "%c %s %s %s :%s",
+                               snprintf(buf, sizeof(buf), "%c %s %s %s :%s",
                                            bandb_letter[i], table.row[j][0],
                                            table.row[j][1], table.row[j][2], table.row[j][3]);
                        else
-                               rb_snprintf(buf, sizeof(buf), "%c %s %s :%s",
+                               snprintf(buf, sizeof(buf), "%c %s %s :%s",
                                            bandb_letter[i], table.row[j][0],
                                            table.row[j][2], table.row[j][3]);
 
@@ -212,24 +236,26 @@ parse_request(rb_helper *helper)
 }
 
 
+static void
+error_cb(rb_helper *helper) __attribute__((noreturn));
+
 static void
 error_cb(rb_helper *helper)
 {
+       if(in_transaction)
+               rsdb_transaction(RSDB_TRANS_END);
        exit(1);
 }
 
-#ifndef WINDOWS
 static void
 dummy_handler(int sig)
 {
        return;
 }
-#endif
 
 static void
-setup_signals()
+setup_signals(void)
 {
-#ifndef WINDOWS
        struct sigaction act;
 
        act.sa_flags = 0;
@@ -252,17 +278,19 @@ setup_signals()
 
        act.sa_handler = dummy_handler;
        sigaction(SIGALRM, &act, 0);
-#endif
 }
 
 
+static void
+db_error_cb(const char *errstr) __attribute__((noreturn));
+
 static void
 db_error_cb(const char *errstr)
 {
        char buf[256];
-       rb_snprintf(buf, sizeof(buf), "! :%s", errstr);
-       rb_helper_write(bandb_helper, buf);
-       rb_sleep(2 << 30, 0);
+       snprintf(buf, sizeof(buf), "! :%s", errstr);
+       rb_helper_write(bandb_helper, "%s", buf);
+       rb_sleep(1 << 30, 0);
        exit(1);
 }
 
@@ -270,14 +298,13 @@ int
 main(int argc, char *argv[])
 {
        setup_signals();
-       bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256, 256);  /* XXX fix me */
+       bandb_helper = rb_helper_child(parse_request, error_cb, NULL, NULL, NULL, 256, 256, 256);       /* XXX fix me */
        if(bandb_helper == NULL)
        {
                fprintf(stderr,
-                       "This is ircd-ratbox bandb.  You aren't supposed to run me directly. Maybe you want bantool?\n");
+                       "This is the solanum bandb for internal ircd use.\n");
                fprintf(stderr,
-                       "However I will print my Id tag $Id: bandb.c 26094 2008-09-19 15:33:46Z androsyn $\n");
-               fprintf(stderr, "Have a nice day\n");
+                       "You aren't supposed to run me directly (did you want solanum-bantool?). Exiting.\n");
                exit(1);
        }
        rsdb_init(db_error_cb);