]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/opserv.c
Minor typo in previous commit where returning 0 when it should have been 1 from opser...
[irc/evilnet/x3.git] / src / opserv.c
index e3aacab5a6565bb2eecb6ea88a2b4a076a8bd012..ced02ef569cc677b3131bb3d49fd8dfee8cbb0b2 100644 (file)
@@ -216,6 +216,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_WHOIS_CHANNELS",   "Channels     : %s" },
     { "OSMSG_WHOIS_HIDECHANS",  "Channel list omitted for your sanity." },
     { "OSMSG_WHOIS_VERSION",    "Version      : %s" },  
+    { "OSMSG_WHOIS_SSLFP",      "SSL f/print  : %s" },
     { "OSMSG_WHOIS_MARK",       "Mark         : %s" },  
     { "OSMSG_WHOIS_NO_NOTICE",  "No_notices   : %s" },
     { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." },
@@ -305,8 +306,8 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
     { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
     { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
-    { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, lastmod %s, expires %s): %s" },
-    { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, lastmod %s, expires %s): %s" },
+    { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
+    { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
     { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
     { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
     { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
@@ -585,7 +586,9 @@ typedef enum {
     REACT_SVSJOIN,
     REACT_SVSPART,
     REACT_VERSION,
-    REACT_MARK
+    REACT_MARK,
+    REACT_NOTICEUSER,
+    REACT_MSGUSER
 } opserv_alert_reaction;
 
 struct opserv_user_alert {
@@ -1304,7 +1307,7 @@ opserv_block(struct userNode *target, char *src_handle, char *reason, unsigned l
                  "G-line requested by %s.", src_handle);
     if (!duration)
         duration = opserv_conf.block_gline_duration;
-    return gline_add(src_handle, mask, duration, reason, now, now, 1, silent ? 1 : 0);
+    return gline_add(src_handle, mask, duration, reason, now, 1, silent ? 1 : 0);
 }
 
 static MODCMD_FUNC(cmd_block)
@@ -1376,7 +1379,7 @@ static MODCMD_FUNC(cmd_gline)
         reply("MSG_INVALID_DURATION", argv[2]);
         return 0;
     }
-    gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, now, 1, 0);
+    gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, 1, 0);
     reply("OSMSG_GLINE_ISSUED", gline->target);
     return 1;
 }
@@ -1506,7 +1509,7 @@ opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned lo
         snprintf(reason, MAXLEN, "Shun requested by %s.", src_handle);
     }
     if (!duration) duration = opserv_conf.block_shun_duration;
-    return shun_add(src_handle, mask, duration, reason, now, now, 1);
+    return shun_add(src_handle, mask, duration, reason, now, 1);
 }
 
 static MODCMD_FUNC(cmd_sblock)
@@ -1578,7 +1581,7 @@ static MODCMD_FUNC(cmd_shun)
         reply("MSG_INVALID_DURATION", argv[2]);
         return 0;
     }
-    shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, now, 1);
+    shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, 1);
     reply("OSMSG_SHUN_ISSUED", shun->target);
     return 1;
 }
@@ -2167,31 +2170,17 @@ static MODCMD_FUNC(cmd_whois)
     if(target->version_reply) {
         reply("OSMSG_WHOIS_VERSION", target->version_reply);
     }
+    if(target->sslfp) {
+        reply("OSMSG_WHOIS_SSLFP", target->sslfp);
+    }
     if(target->mark) {
         reply("OSMSG_WHOIS_MARK", target->mark);
     }
     reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO");
   
     if (target->modes) {
-        bpos = 0;
+        bpos = irc_user_modes(target, buffer, sizeof(buffer));
 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
-        if (IsInvisible(target)) buffer[bpos++] = 'i';
-        if (IsWallOp(target)) buffer[bpos++] = 'w';
-        if (IsOper(target)) buffer[bpos++] = 'o';
-        if (IsGlobal(target)) buffer[bpos++] = 'g';
-
-        // sethost - reed/apples
-        // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
-        if (IsSetHost(target)) buffer[bpos++] = 'h';
-
-        if (IsService(target)) buffer[bpos++] = 'k';
-        if (IsDeaf(target)) buffer[bpos++] = 'd';
-        if (target->handle_info) buffer[bpos++] = 'r';
-        if (IsHiddenHost(target)) buffer[bpos++] = 'x';
-       if (IsBotM(target)) buffer[bpos++] = 'B';
-       if (IsHideChans(target)) buffer[bpos++] = 'n';
-       if (IsHideIdle(target)) buffer[bpos++] = 'I';
-       if (IsXtraOp(target)) buffer[bpos++] = 'X';
         if (IsGagged(target)) buffer_cat(" (gagged)");
         if (IsRegistering(target)) buffer_cat(" (registered account)");
         buffer[bpos] = 0;
@@ -2545,6 +2534,8 @@ static MODCMD_FUNC(cmd_stats_alerts) {
         case REACT_SVSPART: reaction = "svspart"; break;
         case REACT_VERSION: reaction = "version"; break;
         case REACT_MARK: reaction = "mark"; break;
+        case REACT_NOTICEUSER: reaction = "noticeuser"; break;
+        case REACT_MSGUSER: reaction = "msguser"; break;
         default: reaction = "<unknown>"; break;
         }
         reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner);
@@ -2758,7 +2749,7 @@ opserv_part_channel(void *data)
 static int alert_check_user(const char *key, void *data, void *extra);
 
 static int
-opserv_new_user_check(struct userNode *user)
+opserv_new_user_check(struct userNode *user, UNUSED_ARG(void *extra))
 {
     struct opserv_hostinfo *ohi;
     struct gag_entry *gag;
@@ -2774,7 +2765,7 @@ opserv_new_user_check(struct userNode *user)
 
     /* Gag them if appropriate. */
     for (gag = gagList; gag; gag = gag->next) {
-        if (user_matches_glob(user, gag->mask, MATCH_USENICK)) {
+        if (user_matches_glob(user, gag->mask, MATCH_USENICK, 0)) {
             gag_helper_func(user, NULL);
             break;
         }
@@ -2811,9 +2802,9 @@ opserv_new_user_check(struct userNode *user)
 
         strcpy(target + 2, user->hostname);
         if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS))
-            gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, now, 1, 0);
+            gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1, 0);
         else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS))
-            shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, now, 1);
+            shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1);
           
         return 0;
     }
@@ -2837,7 +2828,7 @@ opserv_new_user_check(struct userNode *user)
         } else if (ohi->clients.used > limit) {
             char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' };
             strcpy(target + 2, addr);
-            gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, now, 1, 1);
+            gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, 1, 1);
         }
     }
 
@@ -2845,7 +2836,7 @@ opserv_new_user_check(struct userNode *user)
 }
 
 static void
-opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why))
+opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why), UNUSED_ARG(void *extra))
 {
     struct opserv_hostinfo *ohi;
     char addr[IRC_NTOP_MAX_SIZE];
@@ -2909,7 +2900,7 @@ opserv_shutdown_channel(struct chanNode *channel, const char *reason)
 }
 
 static void
-opserv_channel_check(struct chanNode *newchan)
+opserv_channel_check(struct chanNode *newchan, UNUSED_ARG(void *extra))
 {
     /*char *warning; */
 
@@ -2928,7 +2919,7 @@ opserv_channel_check(struct chanNode *newchan)
 }
 
 static void
-opserv_channel_delete(struct chanNode *chan)
+opserv_channel_delete(struct chanNode *chan, UNUSED_ARG(void *extra))
 {
     timeq_del(0, opserv_part_channel, chan, TIMEQ_IGNORE_WHEN);
 }
@@ -2959,7 +2950,7 @@ opserv_notice_handler(struct userNode *user, struct userNode *bot, const char *t
 }
 
 static int
-opserv_join_check(struct modeNode *mNode)
+opserv_join_check(struct modeNode *mNode, UNUSED_ARG(void *extra))
 {
     struct userNode *user = mNode->user;
     struct chanNode *channel = mNode->channel;
@@ -2968,7 +2959,9 @@ opserv_join_check(struct modeNode *mNode)
     if (IsService(user))
         return 0;
 
-    dict_foreach(opserv_channel_alerts, alert_check_user, user);
+    /* Check for alerts, and stop if we find one that kills them. */
+    if (dict_foreach(opserv_user_alerts, alert_check_user, user))
+        return 1;
 
     if (opserv && channel->bad_channel) {
         opserv_debug("Found $b%s$b in bad-word channel $b%s$b; removing the user.", user->nick, channel->name);
@@ -4877,6 +4870,10 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra))
         reaction = REACT_VERSION;
     else if (!irccasecmp(react, "mark"))
         reaction = REACT_MARK;
+    else if (!irccasecmp(react, "noticeuser"))
+        reaction = REACT_NOTICEUSER;
+    else if (!irccasecmp(react, "msguser"))
+        reaction = REACT_MSGUSER;
     else {
         log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key);
         return 0;
@@ -5164,6 +5161,8 @@ opserv_saxdb_write(struct saxdb_context *ctx)
             case REACT_SVSPART: reaction = "svspart"; break;
             case REACT_VERSION: reaction = "version"; break;
             case REACT_MARK: reaction = "mark"; break;
+            case REACT_NOTICEUSER: reaction = "noticeuser"; break;
+            case REACT_MSGUSER: reaction = "msguser"; break;
             default:
                 reaction = NULL;
                 log_module(OS_LOG, LOG_ERROR, "Invalid reaction type %d for alert %s (while writing database).", alert->reaction, iter_key(it));
@@ -5883,6 +5882,30 @@ trace_print_func(struct userNode *match, void *extra)
     return 0;
 }
 
+static int
+trace_privmsg_func(struct userNode *match, void *extra)
+{
+    struct discrim_and_source *das = extra;
+    char *reason;
+    if (das->discrim->reason) {
+        reason = das->discrim->reason;
+        irc_privmsg_user(opserv, match, reason);
+    }
+    return 0;
+}
+
+static int
+trace_notice_func(struct userNode *match, void *extra)
+{
+    struct discrim_and_source *das = extra;
+    char *reason;
+    if (das->discrim->reason) {
+        reason = das->discrim->reason;
+        irc_notice_user(opserv, match, reason);
+    }
+    return 0;
+}
+
 static int
 trace_count_func(UNUSED_ARG(struct userNode *match), UNUSED_ARG(void *extra))
 {
@@ -6170,6 +6193,10 @@ static MODCMD_FUNC(cmd_trace)
         action = trace_print_func;
     else if (!irccasecmp(argv[1], "count"))
         action = trace_count_func;
+    else if (!irccasecmp(argv[1], "privmsg"))
+        action = trace_privmsg_func;
+    else if (!irccasecmp(argv[1], "notice"))
+        action = trace_notice_func;
     else if (!irccasecmp(argv[1], "domains"))
         action = trace_domains_func;
     else if (!irccasecmp(argv[1], "gline"))
@@ -6504,19 +6531,14 @@ gtrace_print_func(struct gline *gline, void *extra)
 {
     struct gline_extra *xtra = extra;
     char issued[INTERVALLEN];
-    char lastmod[INTERVALLEN];
     char expires[INTERVALLEN];
 
     intervalString(issued, now - gline->issued, xtra->user->handle_info);
-    if (gline->lastmod)
-        intervalString(lastmod, now - gline->lastmod, xtra->user->handle_info);
-    else
-        strcpy(lastmod, "<unknown>");
     if (gline->expires)
         intervalString(expires, gline->expires - now, xtra->user->handle_info);
     else
         strcpy(expires, "never");
-    send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason);
+    send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, expires, gline->reason);
 }
 
 static MODCMD_FUNC(cmd_stats_glines) {
@@ -6613,19 +6635,14 @@ strace_print_func(struct shun *shun, void *extra)
 {
     struct shun_extra *xtra = extra;
     char issued[INTERVALLEN];
-    char lastmod[INTERVALLEN];
     char expires[INTERVALLEN];
 
     intervalString(issued, now - shun->issued, xtra->user->handle_info);
-    if (shun->lastmod)
-        intervalString(lastmod, now - shun->lastmod, xtra->user->handle_info);
-    else
-        strcpy(lastmod, "<unknown>");
     if (shun->expires)
         intervalString(expires, shun->expires - now, xtra->user->handle_info);
     else
         strcpy(expires, "never");
-    send_message(xtra->user, opserv, "OSMSG_STRACE_FORMAT", shun->target, issued, shun->issuer, lastmod, expires, shun->reason);
+    send_message(xtra->user, opserv, "OSMSG_STRACE_FORMAT", shun->target, issued, shun->issuer, expires, shun->reason);
 }
 
 static MODCMD_FUNC(cmd_stats_shuns) {
@@ -6779,18 +6796,24 @@ alert_check_user(const char *key, void *data, void *extra)
        add_track_user(user);
 #endif
        break;
+    case REACT_NOTICEUSER:
+        irc_notice_user(opserv, user, alert->discrim->reason);
+        break;
+    case REACT_MSGUSER:
+        irc_privmsg_user(opserv, user, alert->discrim->reason);
+        break;
     }
     return 0;
 }
 
 static void
-opserv_alert_check_account(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle))
+opserv_alert_check_account(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle), UNUSED_ARG(void *extra))
 {
     dict_foreach(opserv_account_based_alerts, alert_check_user, user);
 }
 
 static void
-opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick))
+opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick), UNUSED_ARG(void *extra))
 {
     struct gag_entry *gag;
 
@@ -6799,7 +6822,7 @@ opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick))
     /* Gag them if appropriate (and only if). */
     user->modes &= ~FLAGS_GAGGED;
     for (gag = gagList; gag; gag = gag->next) {
-        if (user_matches_glob(user, gag->mask, MATCH_USENICK)) {
+        if (user_matches_glob(user, gag->mask, MATCH_USENICK, 0)) {
             gag_helper_func(user, NULL);
             break;
         }
@@ -6807,7 +6830,7 @@ opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick))
 }
 
 static void
-opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle))
+opserv_staff_alert(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle), UNUSED_ARG(void *extra))
 {
     const char *type;
 
@@ -6964,6 +6987,10 @@ static MODCMD_FUNC(cmd_addalert)
         reaction = REACT_VERSION;
     else if(!irccasecmp(argv[2], "mark"))
         reaction = REACT_MARK;
+    else if(!irccasecmp(argv[2], "noticeuser"))
+        reaction = REACT_NOTICEUSER;
+    else if(!irccasecmp(argv[2], "msguser"))
+        reaction = REACT_MSGUSER;
     else {
         reply("OSMSG_UNKNOWN_REACTION", argv[2]);
         return 0;
@@ -7210,7 +7237,7 @@ opserv_db_init(void) {
 }
 
 static void
-opserv_db_cleanup(void)
+opserv_db_cleanup(UNUSED_ARG(void* extra))
 {
     unsigned int nn;
 
@@ -7219,7 +7246,7 @@ opserv_db_cleanup(void)
     free_string_list(opserv_bad_words);
     dict_delete(opserv_exempt_channels);
     dict_delete(opserv_trusted_hosts);
-    unreg_del_user_func(opserv_user_cleanup);
+    unreg_del_user_func(opserv_user_cleanup, NULL);
     dict_delete(opserv_hostinfo_dict);
     dict_delete(opserv_nick_based_alerts);
     dict_delete(opserv_account_based_alerts);
@@ -7248,6 +7275,8 @@ init_opserv(const char *nick)
     opserv_define_func("ACCESS", cmd_access, 0, 0, 0);
     opserv_define_func("ADDALERT", cmd_addalert, 800, 0, 4);
     opserv_define_func("ADDALERT NOTICE", NULL, 0, 0, 0);
+    opserv_define_func("ADDALERT NOTICEUSER", NULL, 0, 0, 0);
+    opserv_define_func("ADDALERT MSGUSER", NULL, 0, 0, 0);
     opserv_define_func("ADDALERT SILENT", NULL, 900, 0, 0);
     opserv_define_func("ADDALERT GLINE", NULL, 900, 0, 0);
     opserv_define_func("ADDALERT SHUN", NULL, 900, 0, 0);
@@ -7359,6 +7388,8 @@ init_opserv(const char *nick)
     opserv_define_func("TRACE", cmd_trace, 100, 0, 3);
     opserv_define_func("TRACE PRINT", NULL, 0, 0, 0);
     opserv_define_func("TRACE COUNT", NULL, 0, 0, 0);
+    opserv_define_func("TRACE PRIVMSG", NULL, 0, 0, 0);
+    opserv_define_func("TRACE NOTICE", NULL, 0, 0, 0);
     opserv_define_func("TRACE DOMAINS", NULL, 0, 0, 0);
     opserv_define_func("TRACE GLINE", NULL, 600, 0, 0);
     opserv_define_func("TRACE SHUN", NULL, 600, 0, 0);
@@ -7390,14 +7421,14 @@ init_opserv(const char *nick)
     opserv_waiting_connections = dict_new();
     dict_set_free_data(opserv_waiting_connections, opserv_free_waiting_connection);
 
-    reg_new_user_func(opserv_new_user_check);
-    reg_nick_change_func(opserv_alert_check_nick);
-    reg_del_user_func(opserv_user_cleanup);
-    reg_new_channel_func(opserv_channel_check); 
-    reg_del_channel_func(opserv_channel_delete);
-    reg_join_func(opserv_join_check);
-    reg_auth_func(opserv_staff_alert);
-    reg_auth_func(opserv_alert_check_account);
+    reg_new_user_func(opserv_new_user_check, NULL);
+    reg_nick_change_func(opserv_alert_check_nick, NULL);
+    reg_del_user_func(opserv_user_cleanup, NULL);
+    reg_new_channel_func(opserv_channel_check, NULL); 
+    reg_del_channel_func(opserv_channel_delete, NULL);
+    reg_join_func(opserv_join_check, NULL);
+    reg_auth_func(opserv_staff_alert, NULL);
+    reg_auth_func(opserv_alert_check_account, NULL);
     reg_notice_func(opserv, opserv_notice_handler);
 
     opserv_db_init();
@@ -7415,6 +7446,6 @@ init_opserv(const char *nick)
     /* start the karma timer, using the saved one if available */
     routing_karma_timer(dict_find(opserv_routing_plan_options, "KARMA_TIMER", NULL));
 
-    reg_exit_func(opserv_db_cleanup);
+    reg_exit_func(opserv_db_cleanup, NULL);
     message_register_table(msgtab);
 }