Пример #1
0
int denora_event_push(char *source, int ac, char **av)
{
/* Thanks to w00t from the inspircd team for helping me to write this function
 * debug: Received: :rock.musichat.net PUSH TestBOT ::rock.musichat.net 242 TestBOT :Server up 1 days, 07:47:54
 */
    Server *s;
    char *num;
    char buf[NET_BUFSIZE];

    if (denora->protocoldebug) {
        protocol_debug(source, ac, av);
    }

    num = myStrGetToken(av[1], ' ', 1);
    av[1] = myStrGetTokenRemainder(av[1], ' ', 3);

    if (!num || !av[1]) {
        alog(LOG_ERROR,
             "ERROR: Something wicked while handling the PUSH message (truncated message)");
        return MOD_CONT;
    }

    if (!strcmp(num, "375")) {
        rdb_query(QUERY_LOW, "UPDATE %s SET motd=\'\' WHERE server=\'%s\'",
                  ServerTable, source);
    } else if (!strcmp(num, "372")) {
        s = server_find(source);
        if (!s) {
            return MOD_CONT;
        }
        av[1]++;
        if (ac >= 2) {
            if (s->motd) {
                ircsnprintf(buf, NET_BUFSIZE - 1, "%s\n\r%s", s->motd,
                            av[1]);
                free(s->motd);
                s->motd = sstrdup(buf);
            } else {
                s->motd = sstrdup(av[1]);
            }
        }
    } else if (!strcmp(num, "376")) {
        s = server_find(source);
        if (!s) {
            return MOD_CONT;
        }
        sql_motd_store(s);
    } else if (!strcmp(num, "242")) {
        av[1]++;
        sql_do_uptime(source, av[1]);
    } else if (!strcmp(num, "248")) {
        av[2] = myStrGetTokenRemainder(av[1], ' ', 1);
        av[1] = myStrGetToken(av[1], ' ', 1);   /* possible memleak at this location */
        sql_uline(av[2]);
    }
    return MOD_CONT;
}
Пример #2
0
void ConnectServ(User * u, char *buf)
{
    char *cmd, *buf2;
    char *str;

    buf2 = sstrdup(buf);
    cmd = myStrGetToken(buf, ' ', 0);
    str = myStrGetTokenRemainder(buf, ' ', 1);

    SET_SEGV_LOCATION();

    if (!cmd) {
        free(buf2);
        return;
    } else if (stricmp(cmd, "\1PING") == 0) {
        denora_cmd_ctcp(s_StatServ, u->nick, "PING %s", str);
    } else {
        SET_SEGV_LOCATION();
        mod_run_cmd(s_StatServ, u, STATSERV, cmd, str);
    }
    free(cmd);
    if (str) {
        free(str);
    }
    free(buf2);
}
Пример #3
0
/**
 * Handle NOTICE commands
 *
 * @param source is the nick of the person whom sent the notice
 * @param receiver is the nick whom it was sent to
 * @param msg is the message that was sent
 *
 * @return always returns MOD_CONT
 */
int m_notice(char *source, char *receiver, char *msg)
{
    char *temp = NULL;
    char *version;
    char *clean;

    if (BadPtr(source) || BadPtr(receiver) || BadPtr(msg)) {
        return MOD_CONT;
    }

    if (!stricmp(receiver, s_StatServ)
        || (s_StatServ_alias && !stricmp(receiver, s_StatServ_alias))) {
        clean = normalizeBuffer(msg);
        doCleanBuffer((char *) clean);
        temp = myStrGetToken(clean, ' ', 0);
        if (!temp) {
            free(clean);
            return MOD_CONT;
        }
        if (!stricmp(temp, "VERSION")) {
            version = myStrGetTokenRemainder(clean, ' ', 1);
            handle_ctcp_version(source, version);
            free(version);
        }
        free(clean);
        free(temp);
    }

    return MOD_CONT;
}
Пример #4
0
/*
  :%s NEWMASK %s
	parv[0] = sender
	parv[1] = new mask (if no '@', hostname is assumed)
*/
int denora_event_newmask(char *source, int ac, char **av)
{
    char *newhost;
    char *newuser;

    if (denora->protocoldebug) {
        protocol_debug(source, ac, av);
    }
    if (ac != 1) {
        return MOD_CONT;
    }
    newuser = myStrGetOnlyToken(av[0], '@', 0);
    if (newuser) {
        newhost = myStrGetTokenRemainder(av[0], '@', 1);
        change_user_username(source, newuser);
        free(newuser);
    } else {
        newhost = av[0];
    }

    if (*newhost == '@')
        newhost++;

    if (newhost) {
        change_user_host(source, newhost);
    }

    return MOD_CONT;
}
Пример #5
0
static int hs_do_reject(User * u)
{
    char *cur_buffer;
    char *nick;
    char *reason;
    HostCore *tmp, *hc;
    boolean found = false;

    cur_buffer = moduleGetLastBuffer();
    nick = myStrGetToken(cur_buffer, ' ', 0);
    reason = myStrGetTokenRemainder(cur_buffer, ' ', 1);

    if (!nick) {
        moduleNoticeLang(s_HostServ, u, LNG_REJECT_SYNTAX);
        if (reason)
            free(reason);
        return MOD_CONT;
    }

    tmp = findHostCore(hs_request_head, nick, &found);
    if (found) {
        if (!tmp)
            hc = hs_request_head;
        else
            hc = tmp->next;

        if (HSRequestMemoUser) {
            if (reason)
                my_memo_lang(u, hc->nick, 2, NULL, LNG_REJECT_MEMO_REASON,
                             reason);
            else
                my_memo_lang(u, hc->nick, 2, NULL, LNG_REJECT_MEMO);
        }

        hs_request_head = deleteHostCore(hs_request_head, tmp);
        moduleNoticeLang(s_HostServ, u, LNG_REJECTED, nick);
        alog("Host Request for %s rejected by %s (%s)", nick, u->nick,
             reason ? reason : "");
    } else {
        moduleNoticeLang(s_HostServ, u, LNG_NO_REQUEST, nick);
    }

    free(nick);
    if (reason)
        free(reason);

    return MOD_CONT;
}
Пример #6
0
/**
 * Handle kickban/kb fantasy commands.
 * @param argc Argument count
 * @param argv Argument list
 * @return MOD_CONT or MOD_STOP
 **/
int do_fantasy(int argc, char **argv)
{
    User *u, *u2;
    ChannelInfo *ci;
    char *target = NULL;
    char *reason = NULL;

    if (argc < 3)
        return MOD_CONT;

    if ((stricmp(argv[0], "kickban") == 0)
        || (stricmp(argv[0], "kb") == 0)) {
        u = finduser(argv[1]);
        ci = cs_findchan(argv[2]);
        if (!u || !ci)
            return MOD_CONT;

        if (argc >= 4) {
            target = myStrGetToken(argv[3], ' ', 0);
            reason = myStrGetTokenRemainder(argv[3], ' ', 1);
        }
        if (!target && check_access(u, ci, CA_BANME)) {
            bot_raw_ban(u, ci, u->nick, "Requested");
        } else if (target && check_access(u, ci, CA_BAN)) {
            if (stricmp(target, ci->bi->nick) == 0) {
                bot_raw_ban(u, ci, u->nick, "Oops!");
            } else {
                u2 = finduser(target);
                if (u2 && ci->c && is_on_chan(ci->c, u2)) {
                    if (!reason && !is_protected(u2))
                        bot_raw_ban(u, ci, target, "Requested");
                    else if (!is_protected(u2))
                        bot_raw_ban(u, ci, target, reason);
                }
            }
        }
    }

    if (target)
       free(target);
    if (reason)
       free(reason);

    return MOD_CONT;
}
Пример #7
0
/**
 * The /hs set command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int myDoSet(User * u)
{
    char *nick = strtok(NULL, " ");
    char *rawhostmask = strtok(NULL, " ");
    char *hostmask = smalloc(HOSTMAX);

    NickAlias *na;
    int32 tmp_time;
    char *s;

    char *vIdent = NULL;

    if (!nick || !rawhostmask) {
        syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
        free(hostmask);
        return MOD_CONT;
    }

    vIdent = myStrGetOnlyToken(rawhostmask, '@', 0);    /* Get the first substring, @ as delimiter */
    if (vIdent) {
        rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1);      /* get the remaining string */
        if (!rawhostmask) {
            syntax_error(s_HostServ, u, "SET", HOST_SET_SYNTAX);
            free(vIdent);
            free(hostmask);
            return MOD_CONT;
        }
        if (strlen(vIdent) > USERMAX - 1) {
            notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
            free(vIdent);
            free(rawhostmask);
            free(hostmask);
            return MOD_CONT;
        } else {
            for (s = vIdent; *s; s++) {
                if (!isvalidchar(*s)) {
                    notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
                    free(vIdent);
                    free(rawhostmask);
                    free(hostmask);
                    return MOD_CONT;
                }
            }
        }
        if (!ircd->vident) {
            notice_lang(s_HostServ, u, HOST_NO_VIDENT);
            free(vIdent);
            free(rawhostmask);
            free(hostmask);
            return MOD_CONT;
        }
    }
    if (strlen(rawhostmask) < HOSTMAX)
        snprintf(hostmask, HOSTMAX, "%s", rawhostmask);
    else {
        notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
        if (vIdent) {
            free(vIdent);
            free(rawhostmask);
        }
        free(hostmask);
        return MOD_CONT;
    }

    if (!isValidHost(hostmask, 3)) {
        notice_lang(s_HostServ, u, HOST_SET_ERROR);
        if (vIdent) {
            free(vIdent);
            free(rawhostmask);
        }
        free(hostmask);
        return MOD_CONT;
    }


    tmp_time = time(NULL);

    if ((na = findnick(nick))) {
        if (na->status & NS_VERBOTEN) {
            notice_lang(s_HostServ, u, NICK_X_FORBIDDEN, nick);
            if (vIdent) {
                free(vIdent);
                free(rawhostmask);
            }
            free(hostmask);
            return MOD_CONT;
        }
        if (vIdent && ircd->vident) {
            alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick);
        } else {
            alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick);
        }
        addHostCore(nick, vIdent, hostmask, u->nick, tmp_time);
        if (vIdent) {
            notice_lang(s_HostServ, u, HOST_IDENT_SET, nick, vIdent,
                        hostmask);
        } else {
            notice_lang(s_HostServ, u, HOST_SET, nick, hostmask);
        }
    } else {
        notice_lang(s_HostServ, u, HOST_NOREG, nick);
    }
    free(hostmask);
    if (vIdent) {
        free(vIdent);
        free(rawhostmask);
    }
    return MOD_CONT;
}
Пример #8
0
int do_avoice(User *u)
{
	char *buf = moduleGetLastBuffer();
    char *chan = myStrGetToken(buf, ' ', 0);
    char *option = myStrGetTokenRemainder(buf, ' ', 1);
	char *data;
    ChannelInfo *ci;
    if (!chan) {
		moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_SYNTAX);
		return MOD_CONT;
    }
    if ((ci = cs_findchan(chan))) {
        if (!check_access(u, ci, CA_PROTECT)) {
            notice_lang(s_ChanServ, u, PERMISSION_DENIED);
			if (chan) free(chan);
			if (option) free(option);
            return MOD_CONT;
        }
		if (!option) {
			if ((data = moduleGetData(&ci->moduleData, "avoice"))) {
				if (stricmp(data, "REG") == 0) {
					moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_REG, chan);
				} else if (stricmp(data, "ALL") == 0) {
					moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_ALL, chan);
				}
				free(data);
			} else {
				moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_OFF, chan);
			}
		} else {
			if (stricmp(option, "REG") == 0) {
				moduleAddData(&ci->moduleData, "avoice", "REG");
				moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_SET_REG, chan);
			} else if (stricmp(option, "ALL") == 0) {
				moduleAddData(&ci->moduleData, "avoice", "ALL");
				moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_SET_ALL, chan);
			} else if (stricmp(option, "OFF") == 0) {
				moduleDelData(&ci->moduleData, "avoice");
				moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_SET_OFF, chan);
			} else if (stricmp(option, "STATUS") == 0) {
				if ((data = moduleGetData(&ci->moduleData, "avoice"))) {
					if (stricmp(data, "REG") == 0) {
						moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_REG, chan);
					} else if (stricmp(data, "ALL") == 0) {
						moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_ALL, chan);
					}
					free(data);
				} else {
					moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_STATUS_OFF, chan);
				}
			} else {
				moduleNoticeLang(s_ChanServ, u, CS_AUTOVOICE_SYNTAX);
			}
		}
	} else {
        notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
    }
	if (chan)
		free(chan);
	if (option)
		free(option);
    return MOD_CONT;
}
Пример #9
0
int fantasy_defkick(int argc, char **argv)
{
    User *u, *u2;
    ChannelInfo *ci;
    char *target = NULL;
    char *reason = NULL;

    if (argc < 3)
        return MOD_CONT;
    if (!stricmp(argv[0], "help")) 
    {
            u = finduser(argv[1]);
       		if (argc >= 4) 
            {
			   int ret = MOD_CONT;
			   char *cmd, *param;
			   cmd = myStrGetToken(argv[3],' ',0);
			   param = myStrGetToken(argv[3],' ',1);
			   if (!stricmp(cmd, "kickr")) 
               {
                  notice(s_BotServ, u->nick, "\037Syntax\037: \002!kickr [NICK] [TRIGGER]\002   or");
                  notice(s_BotServ, u->nick, "\037Syntax\037: \002!kr [NICK] [TRIGGER]\002");
                  notice(s_BotServ, u->nick, "(For example: !kr VisioN idling  or !kickr VisioN idling)");
                  notice(s_BotServ, u->nick, "\n");
                  notice(s_BotServ, u->nick, "----------------------------------------------------------------------------------------------------------");
                  notice(s_BotServ, u->nick, "\n");
                  notice(s_BotServ, u->nick, "\037Description\037: This command allows you to kick a user from a channel, using the bot's default kick reasons.");
                  notice(s_BotServ, u->nick, "The bot supports multipule kick reasons for each of the basic abuses for channels, a list of which");
                  notice(s_BotServ, u->nick, "you can find below.");
                  notice(s_BotServ, u->nick, "\n");
                  notice(s_BotServ, u->nick, "List of triggers:");
                  notice(s_BotServ, u->nick, "\037\002Name\002\037           \037\002Description\002\037");
                  notice(s_BotServ, u->nick, "badlang        Kicks for bad language (insults etc)");
                  notice(s_BotServ, u->nick, "caps             Kicks for capital letters ");
                  notice(s_BotServ, u->nick, "flood            Kicks for channel flooding ");
                  notice(s_BotServ, u->nick, "bold             Kicks for bold letters ");
                  notice(s_BotServ, u->nick, "advertise      Kicks for Spam/Advertising ");
                  notice(s_BotServ, u->nick, "repeat          Kicks for repetition ");
                  notice(s_BotServ, u->nick, "idle               Kicks for idling (mostly for help chans) ");
                  notice(s_BotServ, u->nick, "badnick        Kicks for bad nicknames ");
                  ret = MOD_CONT;
               }
			free(cmd);
			if (param) free(param);
			return ret;
            }
   }
   else if ((stricmp(argv[0], "kickr") == 0) || (stricmp(argv[0], "kr") == 0)) 
   {
        u = finduser(argv[1]);
        ci = cs_findchan(argv[2]);
        if (!u || !ci)
            return MOD_CONT;
        if (argc >= 4) 
        {
            target = myStrGetToken(argv[3], ' ', 0);
            reason = myStrGetTokenRemainder(argv[3], ' ', 1);
        }
        if (!check_access(u, ci, CA_KICK)) 
        {
            notice(s_BotServ, u->nick, "You are not authorised to kick the selected user.");
        }
        else if (!target && check_access(u, ci, CA_KICKME)) 
        {
            notice(s_BotServ, u->nick, "\037Syntax\037: \002!kickr [NICK] [TRIGGER]\002   or");
            notice(s_BotServ, u->nick, "\037Syntax\037: \002!kr [NICK] [TRIGGER]\002");
            notice(s_BotServ, u->nick, "For detailed information about this command and");
            notice(s_BotServ, u->nick, "for a list of triggers, type \002!help kickr\002");
        } 
        else if (target && check_access(u, ci, CA_KICK)) 
        {
            if (!stricmp(target, ci->bi->nick))
                bot_raw_kick(u, ci, u->nick, "Wrong Move!");
            else 
            {
                u2 = finduser(target);
                if (u2 && ci->c && is_on_chan(ci->c, u2)) 
                {   
                    if (!reason && !is_protected(u2))
                        bot_raw_kick(u, ci, target, "Requested");
                    else if (!is_protected(u2)) 
                    {
                         if ((stricmp(reason , "badlang") == 0))  
                            bot_raw_kick(u, ci, target, BADLANG);
			             else if ((stricmp(reason , "caps") == 0)) 
                              bot_raw_kick(u, ci, target, CAPS);
			             else if ((stricmp(reason , "flood") == 0)) 
				              bot_raw_kick(u, ci, target, FLOOD);
			             else if ((stricmp(reason , "bold") == 0))
				              bot_raw_kick(u, ci, target, BOLD);
                         else if ((stricmp(reason , "advertise") == 0)) 
				              bot_raw_kick(u, ci, target, ADVERTISE);
	                     else if ((stricmp(reason , "repeat") == 0)) 
				              bot_raw_kick(u, ci, target, REPEAT);
	                     else if ((stricmp(reason , "idle") == 0)) 
				              bot_raw_kick(u, ci, target, IDLE);
	                     else if ((stricmp(reason , "badnick") == 0)) 
				              bot_raw_kick(u, ci, target, BADNICK);

                     else     
                     {
                           notice(s_BotServ, u->nick, "The number you chose does not correspond to a kick reason.");
                           notice(s_BotServ, u->nick, "If you want to kick with your own custom reason , use !kick trigger");
                     }
                 }      
                    
              }
            }
        }
    }
    if (target) free(target);
    if (reason) free(reason);
    return MOD_CONT;
}
Пример #10
0
static int hs_do_request(User * u)
{
    char *cur_buffer;
    char *nick;
    char *rawhostmask;
    char hostmask[HOSTMAX];
    NickAlias *na;
    int32 tmp_time;
    char *s;
    char *vIdent = NULL;
    time_t now = time(NULL);

    cur_buffer = moduleGetLastBuffer();
    nick = u->nick;
    rawhostmask = myStrGetToken(cur_buffer, ' ', 0);

    if (!nick || !rawhostmask) {
        if (rawhostmask)
            free(rawhostmask);
        moduleNoticeLang(s_HostServ, u, LNG_REQUEST_SYNTAX);
        return MOD_CONT;
    }

    vIdent = myStrGetOnlyToken(rawhostmask, '@', 0);    /* Get the first substring, @ as delimiter */
    if (vIdent) {
        rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1);      /* get the remaining string */
        if (!rawhostmask) {
            moduleNoticeLang(s_HostServ, u, LNG_REQUEST_SYNTAX);
            free(vIdent);
            return MOD_CONT;
        }
        if (strlen(vIdent) > USERMAX - 1) {
            notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX);
            free(vIdent);
            free(rawhostmask);
            return MOD_CONT;
        } else {
            for (s = vIdent; *s; s++) {
                if (!my_isvalidchar(*s)) {
                    notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR);
                    free(vIdent);
                    free(rawhostmask);
                    return MOD_CONT;
                }
            }
        }
        if (!ircd->vident) {
            notice_lang(s_HostServ, u, HOST_NO_VIDENT);
            free(vIdent);
            free(rawhostmask);
            return MOD_CONT;
        }
    }
    if (strlen(rawhostmask) < HOSTMAX) {
        snprintf(hostmask, HOSTMAX, "%s", rawhostmask);
    } else {
        notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX);
        if (vIdent)
            free(vIdent);
        free(rawhostmask);
        return MOD_CONT;
    }

    if (!isValidHost(hostmask, 3)) {
        notice_lang(s_HostServ, u, HOST_SET_ERROR);
        if (vIdent)
            free(vIdent);
        free(rawhostmask);
        return MOD_CONT;
    }

    tmp_time = time(NULL);
    if ((na = findnick(nick))) {
        if (HSRequestMemoOper || HSRequestMemoSetters) {
            if (MSSendDelay > 0 && u
                && u->lastmemosend + MSSendDelay > now) {
                moduleNoticeLang(s_HostServ, u, LNG_REQUEST_WAIT,
                                 MSSendDelay);
                u->lastmemosend = now;
                if (vIdent)
                    free(vIdent);
                free(rawhostmask);
                return MOD_CONT;
            }
        }
        my_add_host_request(nick, vIdent, hostmask, u->nick, tmp_time);

        moduleNoticeLang(s_HostServ, u, LNG_REQUESTED);
        req_send_memos(u, hostmask);
        alog("New vHost Requested by %s", nick);
    } else {
        notice_lang(s_HostServ, u, HOST_NOREG, nick);
    }

    if (vIdent)
        free(vIdent);
    free(rawhostmask);

    return MOD_CONT;
}
Пример #11
0
/**
 * The /ns list command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
static int do_list(User * u)
{

/* SADMINS can search for nicks based on their NS_VERBOTEN and NS_NO_EXPIRE
 * status. The keywords FORBIDDEN and NOEXPIRE represent these two states
 * respectively. These keywords should be included after the search pattern.
 * Multiple keywords are accepted and should be separated by spaces. Only one
 * of the keywords needs to match a nick's state for the nick to be displayed.
 * Forbidden nicks can be identified by "[Forbidden]" appearing in the last
 * seen address field. Nicks with NOEXPIRE set are preceeded by a "!". Only
 * SADMINS will be shown forbidden nicks and the "!" indicator.
 * Syntax for sadmins: LIST pattern [FORBIDDEN] [NOEXPIRE]
 * -TheShadow
 *
 * UPDATE: SUSPENDED keyword is now accepted as well.
 */


    char *pattern = strtok(NULL, " ");
    char *keyword;
    NickAlias *na;
    NickCore *mync;
    int nnicks, i;
    char buf[BUFSIZE];
    int is_servadmin = is_services_admin(u);
    int16 matchflags = 0;
    NickRequest *nr = NULL;
    int nronly = 0;
    int susp_keyword = 0;
    char noexpire_char = ' ';
    int count = 0, from = 0, to = 0, tofree = 0;
    char *tmp = NULL;
    char *s = NULL;

    if (!(!NSListOpersOnly || (is_oper(u)))) {  /* reverse the help logic */
        notice_lang(s_NickServ, u, ACCESS_DENIED);
        return MOD_STOP;
    }

    if (!pattern) {
        syntax_error(s_NickServ, u, "LIST",
                     is_servadmin ? NICK_LIST_SERVADMIN_SYNTAX :
                     NICK_LIST_SYNTAX);
    } else {

        if (pattern) {
            if (pattern[0] == '#') {
                tmp = myStrGetOnlyToken((pattern + 1), '-', 0); /* Read FROM out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                from = atoi(tmp);
                free(tmp);
                tmp = myStrGetTokenRemainder(pattern, '-', 1);  /* Read TO out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                to = atoi(tmp);
                free(tmp);
                pattern = sstrdup("*");
                tofree = 1;
            }
        }

        nnicks = 0;

        while (is_servadmin && (keyword = strtok(NULL, " "))) {
            if (stricmp(keyword, "FORBIDDEN") == 0)
                matchflags |= NS_VERBOTEN;
            if (stricmp(keyword, "NOEXPIRE") == 0)
                matchflags |= NS_NO_EXPIRE;
            if (stricmp(keyword, "SUSPENDED") == 0)
                susp_keyword = 1;
            if (stricmp(keyword, "UNCONFIRMED") == 0)
                nronly = 1;
        }

        mync = (nick_identified(u) ? u->na->nc : NULL);

        notice_lang(s_NickServ, u, NICK_LIST_HEADER, pattern);
        if (nronly != 1) {
            for (i = 0; i < 1024; i++) {
                for (na = nalists[i]; na; na = na->next) {
                    /* Don't show private and forbidden nicks to non-services admins. */
                    if ((na->status & NS_VERBOTEN) && !is_servadmin)
                        continue;
                    if ((na->nc->flags & NI_PRIVATE) && !is_servadmin
                        && na->nc != mync)
                        continue;
                    if ((matchflags != 0) && !(na->status & matchflags) && (susp_keyword == 0))
                        continue;
		    else if ((susp_keyword == 1) && !(na->nc->flags & NI_SUSPENDED))
                        continue;

                    /* We no longer compare the pattern against the output buffer.
                     * Instead we build a nice nick!user@host buffer to compare.
                     * The output is then generated separately. -TheShadow */
                    snprintf(buf, sizeof(buf), "%s!%s", na->nick,
                             (na->last_usermask
                              && !(na->status & NS_VERBOTEN)) ? na->
                             last_usermask : "*@*");
                    if (stricmp(pattern, na->nick) == 0
                        || match_wild_nocase(pattern, buf)) {

                        if ((((count + 1 >= from) && (count + 1 <= to))
                             || ((from == 0) && (to == 0)))
                            && (++nnicks <= NSListMax)) {
                            if (is_servadmin
                                && (na->status & NS_NO_EXPIRE))
                                noexpire_char = '!';
                            else {
                                noexpire_char = ' ';
                            }
                            if ((na->nc->flags & NI_HIDE_MASK)
                                && !is_servadmin && na->nc != mync) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Hostname Hidden]",
                                         na->nick);
                            } else if (na->status & NS_VERBOTEN) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Forbidden]", na->nick);
                            } else if (na->nc->flags & NI_SUSPENDED) {
                                snprintf(buf, sizeof(buf),
                                         "%-20s  [Suspended]", na->nick);
                            } else {
                                snprintf(buf, sizeof(buf), "%-20s  %s",
                                         na->nick, na->last_usermask);
                            }
                            notice_user(s_NickServ, u, "   %c%s",
                                        noexpire_char, buf);
                        }
                        count++;
                    }
                }
            }
        }

        if (nronly == 1 || (is_servadmin && matchflags == 0 && susp_keyword == 0)) {
            noexpire_char = ' ';
            for (i = 0; i < 1024; i++) {
                for (nr = nrlists[i]; nr; nr = nr->next) {
                    snprintf(buf, sizeof(buf), "%s!*@*", nr->nick);
                    if (stricmp(pattern, nr->nick) == 0
                        || match_wild_nocase(pattern, buf)) {
                        if (++nnicks <= NSListMax) {
                            snprintf(buf, sizeof(buf),
                                     "%-20s  [UNCONFIRMED]", nr->nick);
                            notice_user(s_NickServ, u, "   %c%s",
                                        noexpire_char, buf);
                        }
                    }
                }
            }
        }
        notice_lang(s_NickServ, u, NICK_LIST_RESULTS,
                    nnicks > NSListMax ? NSListMax : nnicks, nnicks);
    }
    if (tofree)
        free(pattern);
    return MOD_CONT;
}
Пример #12
0
/**
 * The /hs list command.
 * @param u The user who issued the command
 * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing.
 **/
int listOut(User * u)
{
    char *key = strtok(NULL, "");
    struct tm *tm;
    char buf[BUFSIZE];
    int counter = 1;
    int from = 0, to = 0;
    char *tmp = NULL;
    char *s = NULL;
    int display_counter = 0;
    HostCore *head = NULL;
    HostCore *current;

    head = hostCoreListHead();

    current = head;
    if (current == NULL)
        notice_lang(s_HostServ, u, HOST_EMPTY);
    else {
                /**
		 * Do a check for a range here, then in the next loop
		 * we'll only display what has been requested..
		 **/
        if (key) {
            if (key[0] == '#') {
                tmp = myStrGetOnlyToken((key + 1), '-', 0);     /* Read FROM out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                from = atoi(tmp);
                free(tmp);
                tmp = myStrGetTokenRemainder(key, '-', 1);      /* Read TO out */
                if (!tmp) {
                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
	                	notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
                        return MOD_CONT;
                    }
                }
                to = atoi(tmp);
                free(tmp);
                key = NULL;
            }
        }

        while (current != NULL) {
            if (key) {
                if (((match_wild_nocase(key, current->nick))
                     || (match_wild_nocase(key, current->vHost)))
                    && (display_counter < NSListMax)) {
                    display_counter++;
                    tm = localtime(&current->time);
                    strftime_lang(buf, sizeof(buf), u,
                                  STRFTIME_DATE_TIME_FORMAT, tm);
                    if (current->vIdent) {
                        notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
                                    counter, current->nick,
                                    current->vIdent, current->vHost,
                                    current->creator, buf);
                    } else {
                        notice_lang(s_HostServ, u, HOST_ENTRY, counter,
                                    current->nick, current->vHost,
                                    current->creator, buf);
                    }
                }
            } else {
                        /**
			 * List the host if its in the display range, and not more
			 * than NSListMax records have been displayed...
			 **/
                if ((((counter >= from) && (counter <= to))
                     || ((from == 0) && (to == 0)))
                    && (display_counter < NSListMax)) {
                    display_counter++;
                    tm = localtime(&current->time);
                    strftime_lang(buf, sizeof(buf), u,
                                  STRFTIME_DATE_TIME_FORMAT, tm);
                    if (current->vIdent) {
                        notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
                                    counter, current->nick,
                                    current->vIdent, current->vHost,
                                    current->creator, buf);
                    } else {
                        notice_lang(s_HostServ, u, HOST_ENTRY, counter,
                                    current->nick, current->vHost,
                                    current->creator, buf);
                    }
                }
            }
            counter++;
            current = current->next;
        }
        if (key) {
            notice_lang(s_HostServ, u, HOST_LIST_KEY_FOOTER, key,
                        display_counter);
        } else {
            if (from != 0) {
                notice_lang(s_HostServ, u, HOST_LIST_RANGE_FOOTER, from,
                            to);
            } else {
                notice_lang(s_HostServ, u, HOST_LIST_FOOTER,
                            display_counter);
            }
        }
    }
    return MOD_CONT;
}
Пример #13
0
static int do_exclude(User * u, int ac, char **av)
{
    Exclude *e;
    char *tmp = NULL;
    char *s = NULL;
    int count = 0, from = 0, to = 0;
    int nnicks = 0, i;
    int disp = 1;
    char *name;
    char *ch = NULL;
    User *u2;

    if (ac < 1) {
        notice_lang(s_StatServ, u, STAT_EXCLUDE_SYNTAX);
        return MOD_CONT;
    }

    if (!stricmp(av[0], "ADD")) {
        if (ac < 2) {
            notice_lang(s_StatServ, u, STAT_EXCLUDE_SYNTAX);
            return MOD_CONT;
        }
        if (strlen(av[1]) > NICKMAX) {
            notice(s_StatServ, u->nick, "Invalid nick length");
            return MOD_CONT;
        }
        if (isdigit(av[1][0]) || av[1][0] == '-') {
            notice(s_StatServ, u->nick, "Invalid nick");
            return MOD_CONT;
        }
        for (ch = av[1]; *ch && (ch - av[1]) < NICKMAX; ch++) {
            if (!isvalidnick(*ch)) {
                notice(s_StatServ, u->nick, "Invalid nick");
                return MOD_CONT;
            }
        }
        e = find_exclude(av[1], NULL);
        if (!e) {
            make_exclude(av[1]);
            notice_lang(s_StatServ, u, STAT_EXCLUDE_ADDED, av[1]);
            name = rdb_escape(av[1]);
            u2 = user_find(av[1]);
            rdb_query(QUERY_LOW, "DELETE FROM %s WHERE uname=\'%s\'",
                      UStatsTable, u2 ? u2->sgroup : name);
            rdb_query(QUERY_LOW,
                      "UPDATE `%s` SET `ignore`=\'Y\' WHERE `uname`=\'%s\'",
                      AliasesTable, u2 ? u2->sgroup : name);
            free(name);
        } else {
            notice_lang(s_StatServ, u, STAT_EXCLUDE_ALREADY, av[1]);
        }
    } else if (!stricmp(av[0], "DEL")) {
        if (ac < 2) {
            notice_lang(s_StatServ, u, STAT_EXCLUDE_SYNTAX);
            return MOD_CONT;
        }
        e = find_exclude(av[1], NULL);
        if (e) {
            del_exclude(e);
            u->cstats = 0;
            notice_lang(s_StatServ, u, STAT_EXCLUDE_DELETED, av[1]);
            name = rdb_escape(av[1]);
            u2 = user_find(av[1]);
            rdb_query(QUERY_LOW,
                      "UPDATE `%s` SET `ignore`=\'N\' WHERE `uname`=\'%s\'",
                      AliasesTable, u2 ? u2->sgroup : name);
            for (i = 0; i < 4; i++) {
                rdb_query
                    (QUERY_LOW,
                     "INSERT IGNORE INTO %s SET uname=\'%s\', chan=\'global\', type=%i;",
                     UStatsTable, u2 ? u2->sgroup : name, i);
            }
            free(name);
        } else {
            notice_lang(s_StatServ, u, STAT_EXCLUDE_NOT_FOUND, av[1]);
        }
    } else if (!stricmp(av[0], "LIST")) {
        if (ac >= 2) {
            if (*av[1] == '#') {
                tmp = myStrGetOnlyToken((av[1] + 1), '-', 0);   /* Read FROM out */
                if (!tmp) {
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
                        return MOD_CONT;
                    }
                }
                from = atoi(tmp);
                free(tmp);
                tmp = myStrGetTokenRemainder(av[1], '-', 1);    /* Read TO out */
                if (!tmp) {
                    return MOD_CONT;
                }
                for (s = tmp; *s; s++) {
                    if (!isdigit(*s)) {
                        free(tmp);
                        return MOD_CONT;
                    }
                }
                to = atoi(tmp);
                free(tmp);
            }
        }

        notice_lang(s_StatServ, u, STAT_EXCLUDE_LIST_HEADER);

        for (i = 0; i < 1024; i++) {
            for (e = exlists[i]; e; e = e->next) {
                if ((count + 1 >= from) && (count + 1 <= to)) {
                    notice(s_StatServ, u->nick, "%d %s", disp++, e->name);
                } else if (((from == 0) && (to == 0)) && (++nnicks <= 50)) {
                    notice(s_StatServ, u->nick, "%d %s", disp++, e->name);
                }
                count++;
            }
        }
    } else {
        notice_lang(s_StatServ, u, STAT_EXCLUDE_SYNTAX);
        return MOD_CONT;
    }

    return MOD_CONT;
}
Пример #14
0
static int my_cs_appendtopic(User * u)
{
    char *cur_buffer;
    char *chan;
    char *newtopic;
    char topic[1024];
    Channel *c;
    ChannelInfo *ci;

    cur_buffer = moduleGetLastBuffer();
    chan = myStrGetToken(cur_buffer, ' ', 0);
    newtopic = myStrGetTokenRemainder(cur_buffer, ' ', 1);

    if (!chan || !newtopic) {
        moduleNoticeLang(s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX);
    } else if (!(c = findchan(chan))) {
        notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
    } else if (!(ci = c->ci)) {
        notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
    } else if (ci->flags & CI_VERBOTEN) {
        notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
    } else if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) {
        notice_lang(s_ChanServ, u, PERMISSION_DENIED);
    } else {
        if (ci->last_topic) {
            snprintf(topic, sizeof(topic), "%s %s", ci->last_topic,
                     newtopic);
            free(ci->last_topic);
        } else {
            strscpy(topic, newtopic, sizeof(topic));
        }

        ci->last_topic = *topic ? sstrdup(topic) : NULL;
        strscpy(ci->last_topic_setter, u->nick, NICKMAX);
        ci->last_topic_time = time(NULL);

        if (c->topic)
            free(c->topic);
        c->topic = *topic ? sstrdup(topic) : NULL;
        strscpy(c->topic_setter, u->nick, NICKMAX);
        if (ircd->topictsbackward)
            c->topic_time = c->topic_time - 1;
        else
            c->topic_time = ci->last_topic_time;

        if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC))
            alog("%s: %s!%s@%s changed topic of %s as services admin.",
                 s_ChanServ, u->nick, u->username, u->host, c->name);
        if (ircd->join2set) {
            if (whosends(ci) == s_ChanServ) {
                anope_cmd_join(s_ChanServ, c->name, c->creation_time);
                anope_cmd_mode(NULL, c->name, "+o %s", GET_BOT(s_ChanServ));
            }
        }
        anope_cmd_topic(whosends(ci), c->name, u->nick, topic, c->topic_time);
        if (ircd->join2set) {
            if (whosends(ci) == s_ChanServ) {
                anope_cmd_part(s_ChanServ, c->name, NULL);
            }
        }
    }
    Anope_Free(chan);
    Anope_Free(newtopic);
    return MOD_CONT;
}