/** Set a channel topic or report an error. * @param[in] sptr Original topic setter. * @param[in] cptr Neighbor that sent the topic message. * @param[in] chptr Channel to set topic on. * @param[in] topic New topic. * @param[in] ts Timestamp that topic was set (0 for current time). */ static void do_settopic(struct Client *sptr, struct Client *cptr, struct Channel *chptr, char *topic, time_t ts) { struct Client *from; int newtopic; if (feature_bool(FEAT_HIS_BANWHO) && IsServer(sptr)) from = &his; else from = sptr; /* Note if this is just a refresh of an old topic, and don't * send it to all the clients to save bandwidth. We still send * it to other servers as they may have split and lost the topic. */ newtopic=ircd_strncmp(chptr->topic,topic,TOPICLEN)!=0; /* setting a topic */ ircd_strncpy(chptr->topic, topic, TOPICLEN); ircd_strncpy(chptr->topic_nick, cli_name(from), NICKLEN); chptr->topic_time = ts ? ts : TStime(); /* Fixed in 2.10.11: Don't propagate local topics */ if (!IsLocalChannel(chptr->chname)) sendcmdto_serv(sptr, CMD_TOPIC, cptr, "%H %Tu %Tu :%s", chptr, chptr->creationtime, chptr->topic_time, chptr->topic); if (newtopic) sendcmdto_channel(from, CMD_TOPIC, chptr, NULL, SKIP_SERVERS, "%H :%s", chptr, chptr->topic); /* if this is the same topic as before we send it to the person that * set it (so they knew it went through ok), but don't bother sending * it to everyone else on the channel to save bandwidth */ else if (MyUser(sptr)) sendcmdto_one(sptr, CMD_TOPIC, sptr, "%H :%s", chptr, chptr->topic); }
void server_relay_private_message(struct Client* sptr, const char* name, const char* text) { struct Client* acptr; assert(0 != sptr); assert(0 != name); assert(0 != text); /* * nickname addressed? */ if (0 == (acptr = findNUser(name)) || !IsUser(acptr)) { send_reply(sptr, SND_EXPLICIT | ERR_NOSUCHNICK, "* :Target left %s. " "Failed to deliver: [%.20s]", feature_str(FEAT_NETWORK), text); return; } if (!IsChannelService(sptr) && is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } if (IsOnlyreg(acptr) && !IsRegnick(sptr)) { send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); return; } if (MyUser(acptr)) add_target(acptr, sptr); sendcmdto_one(sptr, CMD_PRIVATE, acptr, "%C :%s", acptr, text); }
void server_relay_private_notice(struct Client* sptr, const char* name, const char* text) { struct Client* acptr; assert(0 != sptr); assert(0 != name); assert(0 != text); /* * nickname addressed? */ if (0 == (acptr = findNUser(name)) || !IsUser(acptr)) return; if (!IsChannelService(sptr) && is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } if (IsOnlyreg(acptr) && !IsRegnick(sptr)) { send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); return; } if (MyUser(acptr)) add_target(acptr, sptr); sendcmdto_one(sptr, CMD_NOTICE, acptr, "%C :%s", acptr, text); }
/* * mo_asll - oper message handler */ int mo_asll(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { char *mask; struct Client *acptr; int hits; int i; if (parc < 2) return need_more_params(sptr, "ASLL"); if (parc == 2 && MyUser(sptr)) parv[parc++] = cli_name(&me); if (hunt_server_prio_cmd(sptr, CMD_ASLL, cptr, 1, "%s %C", 2, parc, parv) != HUNTED_ISME) return 0; mask = parv[1]; for (i = hits = 0; i <= HighestFd; i++) { acptr = LocalClientArray[i]; if (!acptr || !IsServer(acptr) || !MyConnect(acptr) || match(mask, cli_name(acptr))) continue; send_asll_reply(&me, sptr, cli_name(acptr), cli_serv(acptr)->asll_rtt, cli_serv(acptr)->asll_to, cli_serv(acptr)->asll_from); hits++; } sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :AsLL for %s: %d local servers matched", sptr, mask, hits); return 0; }
void relay_private_notice(struct Client* sptr, const char* name, const char* text) { struct Client* acptr; assert(0 != sptr); assert(0 != name); assert(0 != text); if (0 == (acptr = FindUser(name))) return; if (IsOnlyreg(acptr) && !IsRegnick(sptr)) { send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); return; } if (!IsChannelService(acptr)) { if (check_target_limit(sptr, acptr, cli_name(acptr), 0)) { return; } if (is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } } /* * deliver the message */ if (MyUser(acptr)) add_target(acptr, sptr); sendcmdto_one(sptr, CMD_NOTICE, acptr, "%C :%s", acptr, text); }
/** Send a (prefixed) command to all users on this channel, except for * \a one and those matching \a skip. * @warning \a pattern must not contain %v. * @param[in] from Client originating the command. * @param[in] cmd Long name of command. * @param[in] tok Short name of command. * @param[in] to Destination channel. * @param[in] one Client direction to skip (or NULL). * @param[in] skip Bitmask of SKIP_NONOPS, SKIP_NONVOICES, SKIP_DEAF, SKIP_BURST, SKIP_SERVERS. * @param[in] pattern Format string for command arguments. */ void sendcmdto_channel(struct Client *from, const char *cmd, const char *tok, struct Channel *to, struct Client *one, unsigned int skip, const char *pattern, ...) { struct Membership *member; struct VarData vd; struct MsgBuf *user_mb; struct MsgBuf *serv_mb; vd.vd_format = pattern; /* Build buffer to send to users */ va_start(vd.vd_args, pattern); user_mb = msgq_make(0, skip & (SKIP_NONOPS | SKIP_NONVOICES) ? "%:#C %s @%v" : "%:#C %s %v", from, cmd, &vd); va_end(vd.vd_args); /* Build buffer to send to servers */ if ((skip & SKIP_SERVERS) || IsLocalChannel(to->chname)) serv_mb = NULL; else { va_start(vd.vd_args, pattern); serv_mb = msgq_make(&me, skip & SKIP_NONOPS ? "%C %s @%v" : "%C %s %v", from, tok, &vd); va_end(vd.vd_args); } /* send buffer along! */ bump_sentalong(one); for (member = to->members; member; member = member->next_member) { /* skip duplicates, zombies, and flagged users... */ if (cli_sentalong(member->user) == sentalong_marker || IsZombie(member) || (skip & SKIP_DEAF && IsDeaf(member->user)) || #if defined(DDB) || defined(SERVICES) (skip & SKIP_NONOPS && !IsChanOwner(member) && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOwner(member) && !IsChanOp(member) && !HasVoice(member)) || #else (skip & SKIP_NONOPS && !IsChanOp(member)) || (skip & SKIP_NONVOICES && !IsChanOp(member) && !HasVoice(member)) || #endif (skip & SKIP_COLOUR && !IsStripColour(member->user)) || (skip & SKIP_NOCOLOUR && IsStripColour(member->user)) || (skip & SKIP_BURST && IsBurstOrBurstAck(cli_from(member->user))) || !(serv_mb || MyUser(member->user)) || cli_fd(cli_from(member->user)) < 0) continue; cli_sentalong(member->user) = sentalong_marker; /* pick right buffer to send */ send_buffer(member->user, MyConnect(member->user) ? user_mb : serv_mb, 0); } msgq_clean(user_mb); if (serv_mb) msgq_clean(serv_mb); }
static void stats_help(struct Client* to, struct StatDesc* sd, int stat, char* param) { struct StatDesc *asd; if (MyUser(to)) /* only if it's my user */ for (asd = statsinfo; asd->sd_c; asd++) if (asd->sd_c != sd->sd_c) /* don't send the help for us */ sendcmdto_one(&me, CMD_NOTICE, to, "%C :%c - %s", to, asd->sd_c, asd->sd_desc); }
/** Handle a STATS message from some connection. * * \a parv has the following elements: * \li \a parv[1] is the statistics selector * \li \a parv[2] (optional) is server to query * \li \a parv[3] (optional) is a mask to filter the results * * If \a parv[1] is "l" (or "links"), \a parv[3] is a mask of servers. * If \a parv[1] is "p" (or "P" or "ports"), \a parv[3] is a mask of * ports. If \a parv[1] is "k" (or "K" or "klines" or "i" or "I" or * "access"), \a parv[3] is a hostname with optional username@ prefix * (for opers, hostmasks are allowed). * * See @ref m_functions for discussion of the arguments. * @param[in] cptr Client that sent us the message. * @param[in] sptr Original source of message. * @param[in] parc Number of arguments. * @param[in] parv Argument vector. */ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { const struct StatDesc *sd; char *param; /* If we didn't find a descriptor, send them help */ if ((parc < 2) || !(sd = stats_find(parv[1]))) parv[1] = "*", sd = stats_find("*"); assert(sd != 0); /* Check whether the client can issue this command. If source is * not privileged (server or an operator), then the STAT_FLAG_OPERONLY * flag must not be set, and if the STAT_FLAG_OPERFEAT flag is set, * then the feature given by sd->sd_control must be off. * * This checks cptr rather than sptr so that a local oper may send * /stats queries to other servers. */ if (!IsPrivileged(cptr) && ((sd->sd_flags & STAT_FLAG_OPERONLY) || ((sd->sd_flags & STAT_FLAG_OPERFEAT) && feature_bool(sd->sd_control)))) return send_reply(sptr, ERR_NOPRIVILEGES); /* Check for extra parameter */ if ((sd->sd_flags & STAT_FLAG_VARPARAM) && parc > 3 && !EmptyString(parv[3])) param = parv[3]; else param = NULL; /* Ok, track down who's supposed to get this... */ if (hunt_server_cmd(sptr, CMD_STATS, cptr, feature_int(FEAT_HIS_REMOTE), param ? "%s %C :%s" : "%s :%C", 2, parc, parv) != HUNTED_ISME) return 0; /* Someone else--cool :) */ /* Check if they are a local user */ if ((sd->sd_flags & STAT_FLAG_LOCONLY) && !MyUser(sptr)) return send_reply(sptr, ERR_NOPRIVILEGES); assert(sd->sd_func != 0); /* Ok, dispatch the stats function */ (*sd->sd_func)(sptr, sd, param); /* Done sending them the stats */ return send_reply(sptr, RPL_ENDOFSTATS, parv[1]); }
void relay_directed_notice(struct Client* sptr, char* name, char* server, const char* text) { struct Client* acptr; char* host; assert(0 != sptr); assert(0 != name); assert(0 != text); assert(0 != server); if (0 == (acptr = FindServer(server + 1))) return; /* * NICK[%host]@server addressed? See if <server> is me first */ if (!IsMe(acptr)) { sendcmdto_one(sptr, CMD_NOTICE, acptr, "%s :%s", name, text); return; } /* * Look for an user whose NICK is equal to <name> and then * check if it's hostname matches <host> and if it's a local * user. */ *server = '\0'; if ((host = strchr(name, '%'))) *host++ = '\0'; if (!(acptr = FindUser(name)) || !MyUser(acptr) || (!EmptyString(host) && 0 != match(host, cli_user(acptr)->realhost))) return; *server = '@'; if (host) *--host = '%'; if (!IsChannelService(sptr) && is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } if (IsOnlyreg(acptr) && !IsRegnick(sptr)) send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); else sendcmdto_one(sptr, CMD_NOTICE, acptr, "%s :%s", name, text); }
/** Attempt to apply a SILENCE update to a user. * * Silences are propagated lazily between servers to save on bandwidth * and remote memory. Any removal and any silence exception must be * propagated until a server has not seen the mask being removed or * has no positive silences for the user. * * @param[in] sptr Client to update. * @param[in] mask Single silence mask to apply, optionally preceded by '+' or '-' and maybe '~'. * @return The new ban entry on success, NULL on failure. */ static struct Ban * apply_silence(struct Client *sptr, char *mask) { struct Ban *sile; int flags; int res; char orig_mask[NICKLEN+USERLEN+HOSTLEN+3]; assert(mask && mask[0]); /* Check for add or remove. */ if (mask[0] == '-') { flags = BAN_DEL; mask++; } else if (mask[0] == '+') { flags = BAN_ADD; mask++; } else flags = BAN_ADD; /* Check for being an exception. */ if (mask[0] == '~') { flags |= BAN_EXCEPTION; mask++; } /* Make the silence and set additional flags. */ ircd_strncpy(orig_mask, mask, sizeof(orig_mask) - 1); sile = make_ban(pretty_mask(mask)); sile->flags |= flags; /* If they're a local user trying to ban too broad a mask, forbid it. */ if (MyUser(sptr) && (sile->flags & BAN_IPMASK) && sile->addrbits > 0 && sile->addrbits < (irc_in_addr_is_ipv4(&sile->address) ? 112 : 32)) { send_reply(sptr, ERR_MASKTOOWIDE, orig_mask); free_ban(sile); return NULL; } /* Apply it to the silence list. */ res = apply_ban(&cli_user(sptr)->silence, sile, 1); return res ? NULL : sile; }
int main() { std::cout << "Main thread start..." << std::endl; InterfaceQ IQ = InterfaceQ(); IQ.setRunning(true); IQ.run(); MyUser myUser = MyUser(&IQ); std::string str = "hello"; myUser.sendMsg(str); std::string str2 = "world"; myUser.sendMsg(str2); std::string str3 = "c++"; myUser.sendMsg(str3); sleep(3); }
/** Handle a remote user's attempt to set a channel topic. * \a parv has the following elements: * \li \a parv[1] is the channel name * \li \a parv[2] is the channel creation timestamp (optional) * \li \a parv[2] is the topic's timestamp (optional) * \li \a parv[\a parc - 1] is the topic * * See @ref m_functions for discussion of the arguments. * @param[in] cptr Client that sent us the message. * @param[in] sptr Original source of message. * @param[in] parc Number of arguments. * @param[in] parv Argument vector. */ int ms_topic(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Channel *chptr; char *topic = 0, *name, *p = 0; time_t ts = 0; if (parc < 3) return need_more_params(sptr, "TOPIC"); topic = parv[parc - 1]; for (; (name = ircd_strtok(&p, parv[1], ",")); parv[1] = 0) { chptr = 0; /* Does the channel exist */ if (!IsChannelName(name) || !(chptr = FindChannel(name))) { send_reply(sptr,ERR_NOSUCHCHANNEL,name); continue; } /* Ignore requests for topics from remote servers */ if (IsLocalChannel(name) && !MyUser(sptr)) { protocol_violation(sptr,"Topic request"); continue; } /* If existing channel is older or has newer topic, ignore */ if (parc > 3 && (ts = atoi(parv[2])) && chptr->creationtime < ts) continue; ts = 0; /* Default to the current time if no topic_time is passed. */ if (parc > 4 && (ts = atoi(parv[3])) && chptr->topic_time > ts) continue; do_settopic(sptr,cptr,chptr,topic, ts); } return 0; }
/* * ms_asll - server message handler */ int ms_asll(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { char *mask; struct Client *acptr; int hits; int i; if (parc < 2) return need_more_params(sptr, "ASLL"); if (parc > 5) { if (!(acptr = findNUser(parv[1]))) return 0; if (MyUser(acptr)) send_asll_reply(sptr, acptr, parv[2], atoi(parv[3]), atoi(parv[4]), atoi(parv[5])); else sendcmdto_prio_one(sptr, CMD_ASLL, acptr, "%C %s %s %s %s", acptr, parv[2], parv[3], parv[4], parv[5]); return 0; } if (hunt_server_prio_cmd(sptr, CMD_ASLL, cptr, 1, "%s %C", 2, parc, parv) != HUNTED_ISME) return 0; mask = parv[1]; for (i = hits = 0; i <= HighestFd; i++) { acptr = LocalClientArray[i]; if (!acptr || !IsServer(acptr) || !MyConnect(acptr) || match(mask, cli_name(acptr))) continue; sendcmdto_prio_one(&me, CMD_ASLL, sptr, "%C %s %i %i %i", sptr, cli_name(acptr), cli_serv(acptr)->asll_rtt, cli_serv(acptr)->asll_to, cli_serv(acptr)->asll_from); hits++; } sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :AsLL for %s: %d local servers matched", sptr, mask, hits); return 0; }
/** Find the first matching MOTD block for a user. * If the user is remote, always use remote MOTD. * Otherwise, if there is a hostmask- or class-based MOTD that matches * the user, use it. * Otherwise, use the local MOTD. * @param[in] cptr Client to find MOTD for. * @return Pointer to first matching MOTD for the client. */ static struct Motd * motd_lookup(struct Client *cptr) { struct Motd *ptr; char *c_class = NULL; assert(0 != cptr); if (!MyUser(cptr)) /* not my user, always return remote motd */ return MotdList.remote; c_class = get_client_class(cptr); assert(c_class != NULL); /* check the motd blocks first */ for (ptr = MotdList.other; ptr; ptr = ptr->next) { if (ptr->type == MOTD_CLASS && !match(ptr->hostmask, c_class)) return ptr; else if (ptr->type == MOTD_HOSTMASK && !match(ptr->hostmask, cli_sockhost(cptr))) return ptr; else if (ptr->type == MOTD_IPMASK && ipmask_check(&cli_ip(cptr), &ptr->address, ptr->addrbits)) return ptr; else if (ptr->type == MOTD_COUNTRY && !match(ptr->hostmask, cli_countrycode(cptr))) return ptr; else if (ptr->type == MOTD_CONTINENT && !match(ptr->hostmask, cli_continentcode(cptr))) return ptr; } return MotdList.local; /* Ok, return the default motd */ }
int ms_challenge(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { #ifdef USE_SSL struct ConfItem *aconf; RSA *rsa_public_key; BIO *file = NULL; char *challenge = NULL; char *name; char *tmpname; char chan[CHANNELLEN-1]; char* join[2]; int nl; struct Client *acptr = NULL; char *privbuf; if (!IsServer(cptr)) return 0; /* if theyre an oper, reprint oper motd and ignore */ if (IsOper(sptr)) { send_reply(sptr, RPL_YOUREOPER); if (feature_bool(FEAT_OPERMOTD)) m_opermotd(sptr, sptr, 1, parv); } if (parc < 3) { return send_reply(sptr, ERR_NOOPERHOST); } if (!(acptr = FindNServer(parv[1]))) { return send_reply(sptr, ERR_NOOPERHOST); } else if (!IsMe(acptr)) { sendcmdto_one(sptr, CMD_CHALLENGE, acptr, "%C %s %s", acptr, parv[2], parv[3]); return 0; } if (*parv[2] == '+') { /* Ignore it if we aren't expecting this... -A1kmm */ if (cli_user(sptr)->response == NULL) return 0; if (ircd_strcmp(cli_user(sptr)->response, ++parv[2])) { send_reply(sptr, ERR_PASSWDMISMATCH); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (Password Incorrect)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); tmpname = strdup(cli_user(sptr)->auth_oper); failed_challenge_notice(sptr, tmpname, "challenge failed"); return 0; } name = strdup(cli_user(sptr)->auth_oper); aconf = find_conf_exact(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, MyUser(sptr) ? cli_sockhost(sptr) : cli_user(sptr)->realhost, CONF_OPS); if (!aconf) aconf = find_conf_exact(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, ircd_ntoa((const char*) &(cli_ip(sptr))), CONF_OPS); if (!aconf) aconf = find_conf_cidr(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, cli_ip(sptr), CONF_OPS); if (!aconf) { send_reply(sptr, ERR_NOOPERHOST); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (No O:line)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); return 0; } if (CONF_LOCOP == aconf->status) { ClearOper(sptr); SetLocOp(sptr); } else { /* This must be called before client_set_privs() */ SetRemoteOper(sptr); if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_WHOIS)) { OSetWhois(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_IDLE)) { OSetIdle(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_XTRAOP)) { OSetXtraop(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_HIDECHANS)) { OSetHideChans(sptr); } /* prevent someone from being both oper and local oper */ ClearLocOp(sptr); if (!feature_bool(FEAT_OPERFLAGS) || !(aconf->port & OFLAG_ADMIN)) { /* Global Oper */ ClearAdmin(sptr); OSetGlobal(sptr); SetOper(sptr); } else { /* Admin */ OSetGlobal(sptr); OSetAdmin(sptr); SetOper(sptr); SetAdmin(sptr); } /* Tell client_set_privs to send privileges to the user */ client_set_privs(sptr, aconf); ClearOper(sptr); ClearAdmin(sptr); ClearRemoteOper(sptr); privbuf = client_print_privs(sptr); sendcmdto_one(&me, CMD_PRIVS, sptr, "%C %s", sptr, privbuf); } sendcmdto_one(&me, CMD_MODE, sptr, "%s %s", cli_name(sptr), (OIsAdmin(sptr)) ? "+aoiwsg" : "+oiwsg"); send_reply(sptr, RPL_YOUREOPER); if (OIsAdmin(sptr)) { sendto_allops(&me, SNO_OLDSNO, "%s (%s@%s) is now an IRC Administrator", parv[0], cli_user(sptr)->username, cli_sockhost(sptr)); /* Autojoin admins to admin channel and oper channel (if enabled) */ if (feature_bool(FEAT_AUTOJOIN_ADMIN)) { if (feature_bool(FEAT_AUTOJOIN_ADMIN_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_ADMIN_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_ADMIN_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } if (feature_bool(FEAT_AUTOJOIN_OPER) && OIsGlobal(sptr)) { if (feature_bool(FEAT_AUTOJOIN_OPER_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_OPER_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_OPER_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } } else { sendto_allops(&me, SNO_OLDSNO, "%s (%s@%s) is now an IRC Operator (%c)", parv[0], cli_user(sptr)->username, cli_sockhost(sptr), OIsGlobal(sptr) ? 'O' : 'o'); if (feature_bool(FEAT_AUTOJOIN_OPER) && OIsGlobal(sptr)) { if (feature_bool(FEAT_AUTOJOIN_OPER_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_OPER_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_OPER_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } } if (feature_bool(FEAT_OPERMOTD)) m_opermotd(sptr, sptr, 1, parv); log_write(LS_OPER, L_INFO, 0, "OPER (%s) by (%#C)", name, sptr); ircd_snprintf(0, cli_user(sptr)->response, BUFSIZE+1, "%s", ""); return 0; } ircd_snprintf(0, cli_user(sptr)->response, BUFSIZE+1, "%s", ""); ircd_snprintf(0, cli_user(sptr)->auth_oper, NICKLEN+1, "%s", ""); aconf = find_conf_exact(parv[2], cli_user(sptr)->realusername, cli_user(sptr)->realhost, CONF_OPS); if (!aconf) aconf = find_conf_exact(parv[2], cli_user(sptr)->realusername, ircd_ntoa((const char*) &(cli_ip(sptr))), CONF_OPS); if (!aconf) aconf = find_conf_cidr(parv[2], cli_user(sptr)->realusername, cli_ip(sptr), CONF_OPS); if (aconf == NULL) { send_reply(sptr, ERR_NOOPERHOST); failed_challenge_notice(sptr, parv[2], "No o:line"); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (No O:line)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); return 0; } if (!(aconf->port & OFLAG_REMOTE)) { send_reply(sptr, ERR_NOOPERHOST); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (Remote Oper)", parv[0], cli_user(sptr)->realusername, cli_user(sptr)->realhost); return 0; } if (!(aconf->port & OFLAG_RSA)) { send_reply(sptr, RPL_NO_CHALL); return 0; } if (!verify_sslclifp(sptr, aconf)) { sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (SSL Fingerprint Missmatch)", parv[0], cli_user(sptr)->realusername, cli_user(sptr)->realhost); send_reply(sptr, ERR_SSLCLIFP); return 0; } if ((file = BIO_new_file(aconf->passwd, "r")) == NULL) { send_reply(sptr, RPL_NO_KEY); return 0; } rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); if (rsa_public_key == NULL) return send_reply(sptr, RPL_INVALID_KEY); if (!generate_challenge(&challenge, rsa_public_key, sptr)) { Debug((DEBUG_DEBUG, "generating challenge sum (%s)", challenge)); send_reply(sptr, RPL_RSACHALLENGE, challenge); ircd_snprintf(0, cli_user(sptr)->auth_oper, NICKLEN + 1, "%s", aconf->name); } nl = BIO_set_close(file, BIO_CLOSE); BIO_free(file); return 1; #else return 1; #endif }
/* * ms_kick - server message handler * * parv[0] = sender prefix * parv[1] = channel * parv[2] = client to kick * parv[parc-1] = kick comment */ int ms_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct Client *who; struct Channel *chptr; struct Membership *member = 0, *sptr_link = 0; char *name, *comment; ClrFlag(sptr, FLAG_TS8); if (parc < 3 || *parv[1] == '\0') return need_more_params(sptr, "KICK"); name = parv[1]; comment = parv[parc - 1]; /* figure out who gets kicked from what */ if (IsLocalChannel(name) || !(chptr = get_channel(sptr, name, CGT_NO_CREATE)) || !(who = findNUser(parv[2]))) return 0; /* We go ahead and pass on the KICK for users not on the channel */ member = find_member_link(chptr, who); if (member && IsZombie(member)) { /* We might get a KICK from a zombie's own server because the user * net-rode during a burst (which always generates a KICK) *and* * was kicked via another server. In that case, we must remove * the user from the channel. */ if (sptr == cli_user(who)->server) { remove_user_from_channel(who, chptr); } /* Otherwise, we treat zombies like they are not channel members. */ member = 0; } /* Send HACK notice, but not for servers in BURST */ /* 2002-10-17: Don't send HACK if the users local server is kicking them */ if (IsServer(sptr) && !IsBurstOrBurstAck(sptr) && sptr!=cli_user(who)->server) sendto_opmask_butone(0, SNO_HACK4, "HACK: %C KICK %H %C %s", sptr, chptr, who, comment); /* Unless someone accepted it downstream (or the user isn't on the channel * here), if kicker is not on channel, or if kicker is not a channel * operator, bounce the kick */ if (!IsServer(sptr) && member && cli_from(who) != cptr && (!(sptr_link = find_member_link(chptr, sptr)) || !IsChanOp(sptr_link))) { sendto_opmask_butone(0, SNO_HACK2, "HACK: %C KICK %H %C %s", sptr, chptr, who, comment); sendcmdto_one(who, CMD_JOIN, cptr, "%H", chptr); /* Reop/revoice member */ if (IsChanOp(member) || HasVoice(member)) { struct ModeBuf mbuf; modebuf_init(&mbuf, sptr, cptr, chptr, (MODEBUF_DEST_SERVER | /* Send mode to a server */ MODEBUF_DEST_DEOP | /* Deop the source */ MODEBUF_DEST_BOUNCE)); /* And bounce the MODE */ if (IsChanOp(member)) modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, who, OpLevel(member)); if (HasVoice(member)) modebuf_mode_client(&mbuf, MODE_DEL | MODE_VOICE, who, MAXOPLEVEL + 1); modebuf_flush(&mbuf); } } else { /* Propagate kick... */ sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who, comment); if (member) { /* and tell the channel about it */ if (IsDelayedJoin(member)) { if (MyUser(who)) sendcmdto_one(IsServer(sptr) ? &his : sptr, CMD_KICK, who, "%H %C :%s", chptr, who, comment); } else { sendcmdto_channel_butserv_butone(IsServer(sptr) ? &his : sptr, CMD_KICK, chptr, NULL, 0, "%H %C :%s", chptr, who, comment); } make_zombie(member, who, cptr, sptr, chptr); } } return 0; }
/* * m_kick - generic message handler * * parv[0] = sender prefix * parv[1] = channel * parv[2] = client to kick * parv[parc-1] = kick comment */ int m_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct Client *who; struct Channel *chptr; struct Membership *member = 0; struct Membership* member2; char *name, *comment; ClrFlag(sptr, FLAG_TS8); if (parc < 3 || *parv[1] == '\0') return need_more_params(sptr, "KICK"); name = parv[1]; /* simple checks */ if (!(chptr = get_channel(sptr, name, CGT_NO_CREATE))) return send_reply(sptr, ERR_NOSUCHCHANNEL, name); if (!(member2 = find_member_link(chptr, sptr)) || IsZombie(member2) || !IsChanOp(member2)) return send_reply(sptr, ERR_CHANOPRIVSNEEDED, name); if (!(who = find_chasing(sptr, parv[2], 0))) return 0; /* find_chasing sends the reply for us */ /* Don't allow the channel service to be kicked */ if (IsChannelService(who)) return send_reply(sptr, ERR_ISCHANSERVICE, cli_name(who), chptr->chname); /* Prevent kicking opers from local channels -DM- */ if (IsLocalChannel(chptr->chname) && HasPriv(who, PRIV_DEOP_LCHAN)) return send_reply(sptr, ERR_ISOPERLCHAN, cli_name(who), chptr->chname); /* check if kicked user is actually on the channel */ if (!(member = find_member_link(chptr, who)) || IsZombie(member)) return send_reply(sptr, ERR_USERNOTINCHANNEL, cli_name(who), chptr->chname); /* Don't allow to kick member with a higher op-level, * or members with the same op-level unless both are MAXOPLEVEL. */ if (OpLevel(member) < OpLevel(member2) || (OpLevel(member) == OpLevel(member2) && OpLevel(member) < MAXOPLEVEL)) return send_reply(sptr, ERR_NOTLOWEROPLEVEL, cli_name(who), chptr->chname, OpLevel(member2), OpLevel(member), "kick", OpLevel(member) == OpLevel(member2) ? "the same" : "a higher"); /* We rely on ircd_snprintf to truncate the comment */ comment = EmptyString(parv[parc - 1]) ? parv[0] : parv[parc - 1]; if (!IsLocalChannel(name)) sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who, comment); if (IsDelayedJoin(member)) { /* If it's a delayed join, only send the KICK to the person doing * the kicking and the victim */ if (MyUser(who)) sendcmdto_one(sptr, CMD_KICK, who, "%H %C :%s", chptr, who, comment); sendcmdto_one(who, CMD_JOIN, sptr, "%H", chptr); sendcmdto_one(sptr, CMD_KICK, sptr, "%H %C :%s", chptr, who, comment); CheckDelayedJoins(chptr); } else sendcmdto_channel_butserv_butone(sptr, CMD_KICK, chptr, NULL, 0, "%H %C :%s", chptr, who, comment); make_zombie(member, who, cptr, sptr, chptr); return 0; }
/* * ms_burst - server message handler * * -- by Run [email protected] december 1995 till march 1997 * * parv[0] = sender prefix * parv[1] = channel name * parv[2] = channel timestamp * The meaning of the following parv[]'s depend on their first character: * If parv[n] starts with a '+': * Net burst, additive modes * parv[n] = <mode> * parv[n+1] = <param> (optional) * parv[n+2] = <param> (optional) * If parv[n] starts with a '%', then n will be parc-1: * parv[n] = %<ban> <ban> <ban> ... * If parv[n] starts with another character: * parv[n] = <nick>[:<mode>],<nick>[:<mode>],... * where <mode> is the channel mode (ov) of nick and all following nicks. * * Example: * "S BURST #channel 87654321 +ntkl key 123 AAA,AAB:o,BAA,BAB:ov :%ban1 ban2" * * Anti net.ride code. * * When the channel already exist, and its TS is larger then * the TS in the BURST message, then we cancel all existing modes. * If its is smaller then the received BURST message is ignored. * If it's equal, then the received modes are just added. */ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct ModeBuf modebuf, *mbuf = 0; struct Channel *chptr; time_t timestamp; struct Membership *member, *nmember; struct SLink *lp, **lp_p; unsigned int parse_flags = (MODE_PARSE_FORCE | MODE_PARSE_BURST); int param, nickpos = 0, banpos = 0; char modestr[BUFSIZE], nickstr[BUFSIZE], banstr[BUFSIZE]; if (parc < 3) return protocol_violation(sptr,"Too few parameters for BURST"); if (!IsBurst(sptr)) /* don't allow BURST outside of burst */ return exit_client_msg(cptr, cptr, &me, "HACK: BURST message outside " "net.burst from %s", cli_name(sptr)); if (!(chptr = get_channel(sptr, parv[1], CGT_CREATE))) return 0; /* can't create the channel? */ timestamp = atoi(parv[2]); if (!chptr->creationtime || chptr->creationtime > timestamp) { /* * Kick local members if channel is +i or +k and our TS was larger * than the burst TS (anti net.ride). The modes hack is here because * we have to do this before mode_parse, as chptr may go away. */ for (param = 3; param < parc; param++) { if (parv[param][0] != '+') continue; if (strchr(parv[param], 'i') || strchr(parv[param], 'k')) { /* Clear any outstanding rogue invites */ mode_invite_clear(chptr); for (member = chptr->members; member; member = nmember) { nmember=member->next_member; if (!MyUser(member->user) || IsZombie(member)) continue; sendcmdto_serv_butone(&me, CMD_KICK, NULL, "%H %C :Net Rider", chptr, member->user); sendcmdto_channel_butserv_butone(&me, CMD_KICK, chptr, NULL, "%H %C :Net Rider", chptr, member->user); make_zombie(member, member->user, &me, &me, chptr); } } break; } /* If the channel had only locals, it went away by now. */ if (!(chptr = get_channel(sptr, parv[1], CGT_CREATE))) return 0; /* can't create the channel? */ } /* turn off burst joined flag */ for (member = chptr->members; member; member = member->next_member) member->status &= ~CHFL_BURST_JOINED; if (!chptr->creationtime) /* mark channel as created during BURST */ chptr->mode.mode |= MODE_BURSTADDED; /* new channel or an older one */ if (!chptr->creationtime || chptr->creationtime > timestamp) { chptr->creationtime = timestamp; modebuf_init(mbuf = &modebuf, &me, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_NOKEY); modebuf_mode(mbuf, MODE_DEL | chptr->mode.mode); /* wipeout modes */ chptr->mode.mode &= ~(MODE_ADD | MODE_DEL | MODE_PRIVATE | MODE_SECRET | MODE_MODERATED | MODE_TOPICLIMIT | MODE_INVITEONLY | MODE_NOPRIVMSGS); parse_flags |= (MODE_PARSE_SET | MODE_PARSE_WIPEOUT); /* wipeout keys */ /* mark bans for wipeout */ for (lp = chptr->banlist; lp; lp = lp->next) lp->flags |= CHFL_BURST_BAN_WIPEOUT; /* clear topic set by netrider (if set) */ if (*chptr->topic) { *chptr->topic = '\0'; *chptr->topic_nick = '\0'; chptr->topic_time = 0; sendcmdto_channel_butserv_butone(&me, CMD_TOPIC, chptr, NULL, "%H :%s", chptr, chptr->topic); } } else if (chptr->creationtime == timestamp) { modebuf_init(mbuf = &modebuf, &me, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_NOKEY); parse_flags |= MODE_PARSE_SET; /* set new modes */ } param = 3; /* parse parameters */ while (param < parc) { switch (*parv[param]) { case '+': /* parameter introduces a mode string */ param += mode_parse(mbuf, cptr, sptr, chptr, parc - param, parv + param, parse_flags); break; case '%': /* parameter contains bans */ if (parse_flags & MODE_PARSE_SET) { char *banlist = parv[param] + 1, *p = 0, *ban, *ptr; struct SLink *newban; for (ban = ircd_strtok(&p, banlist, " "); ban; ban = ircd_strtok(&p, 0, " ")) { ban = collapse(pretty_mask(ban)); /* * Yeah, we should probably do this elsewhere, and make it better * and more general; this will hold until we get there, though. * I dislike the current add_banid API... -Kev * * I wish there were a better algo. for this than the n^2 one * shown below *sigh* */ for (lp = chptr->banlist; lp; lp = lp->next) { if (!ircd_strcmp(lp->value.ban.banstr, ban)) { ban = 0; /* don't add ban */ lp->flags &= ~CHFL_BURST_BAN_WIPEOUT; /* not wiping out */ break; /* new ban already existed; don't even repropagate */ } else if (!(lp->flags & CHFL_BURST_BAN_WIPEOUT) && !mmatch(lp->value.ban.banstr, ban)) { ban = 0; /* don't add ban unless wiping out bans */ break; /* new ban is encompassed by an existing one; drop */ } else if (!mmatch(ban, lp->value.ban.banstr)) lp->flags |= CHFL_BAN_OVERLAPPED; /* remove overlapping ban */ if (!lp->next) break; } if (ban) { /* add the new ban to the end of the list */ /* Build ban buffer */ if (!banpos) { banstr[banpos++] = ' '; banstr[banpos++] = ':'; banstr[banpos++] = '%'; } else banstr[banpos++] = ' '; for (ptr = ban; *ptr; ptr++) /* add ban to buffer */ banstr[banpos++] = *ptr; newban = make_link(); /* create new ban */ DupString(newban->value.ban.banstr, ban); DupString(newban->value.ban.who, cli_name(feature_bool(FEAT_HIS_BANWHO) ? &me : sptr)); newban->value.ban.when = TStime(); newban->flags = CHFL_BAN | CHFL_BURST_BAN; /* set flags */ if ((ptr = strrchr(ban, '@')) && check_if_ipmask(ptr + 1)) newban->flags |= CHFL_BAN_IPMASK; newban->next = 0; if (lp) lp->next = newban; /* link it in */ else chptr->banlist = newban; } } } param++; /* look at next param */ break; default: /* parameter contains clients */ { struct Client *acptr; char *nicklist = parv[param], *p = 0, *nick, *ptr; int default_mode = CHFL_DEOPPED | CHFL_BURST_JOINED; int last_mode = CHFL_DEOPPED | CHFL_BURST_JOINED; for (nick = ircd_strtok(&p, nicklist, ","); nick; nick = ircd_strtok(&p, 0, ",")) { if ((ptr = strchr(nick, ':'))) { /* new flags; deal */ *ptr++ = '\0'; if (parse_flags & MODE_PARSE_SET) { for (default_mode = CHFL_DEOPPED | CHFL_BURST_JOINED; *ptr; ptr++) { if (*ptr == 'o') /* has oper status */ default_mode = (default_mode & ~CHFL_DEOPPED) | CHFL_CHANOP; else if (*ptr == 'v') /* has voice status */ default_mode |= CHFL_VOICE; else /* I don't recognize that flag */ break; /* so stop processing */ } } } if (!(acptr = findNUser(nick)) || cli_from(acptr) != cptr) continue; /* ignore this client */ /* Build nick buffer */ nickstr[nickpos] = nickpos ? ',' : ' '; /* first char */ nickpos++; for (ptr = nick; *ptr; ptr++) /* store nick */ nickstr[nickpos++] = *ptr; if (default_mode != last_mode) { /* if mode changed... */ last_mode = default_mode; nickstr[nickpos++] = ':'; /* add a specifier */ if (default_mode & CHFL_CHANOP) nickstr[nickpos++] = 'o'; if (default_mode & CHFL_VOICE) nickstr[nickpos++] = 'v'; } add_user_to_channel(chptr, acptr, default_mode); sendcmdto_channel_butserv_butone(acptr, CMD_JOIN, chptr, NULL, "%H", chptr); } } param++; break; } /* switch (*parv[param]) { */ } /* while (param < parc) { */ nickstr[nickpos] = '\0'; banstr[banpos] = '\0'; if (parse_flags & MODE_PARSE_SET) { modebuf_extract(mbuf, modestr + 1); /* for sending BURST onward */ modestr[0] = modestr[1] ? ' ' : '\0'; } else modestr[0] = '\0'; sendcmdto_serv_butone(sptr, CMD_BURST, cptr, "%H %Tu%s%s%s", chptr, chptr->creationtime, modestr, nickstr, banstr); if (parse_flags & MODE_PARSE_WIPEOUT || banpos) mode_ban_invalidate(chptr); if (parse_flags & MODE_PARSE_SET) { /* any modes changed? */ /* first deal with channel members */ for (member = chptr->members; member; member = member->next_member) { if (member->status & CHFL_BURST_JOINED) { /* joined during burst */ if (member->status & CHFL_CHANOP) modebuf_mode_client(mbuf, MODE_ADD | CHFL_CHANOP, member->user); if (member->status & CHFL_VOICE) modebuf_mode_client(mbuf, MODE_ADD | CHFL_VOICE, member->user); } else if (parse_flags & MODE_PARSE_WIPEOUT) { /* wipeout old ops */ if (member->status & CHFL_CHANOP) modebuf_mode_client(mbuf, MODE_DEL | CHFL_CHANOP, member->user); if (member->status & CHFL_VOICE) modebuf_mode_client(mbuf, MODE_DEL | CHFL_VOICE, member->user); member->status = ((member->status & ~(CHFL_CHANOP | CHFL_VOICE)) | CHFL_DEOPPED); } } /* Now deal with channel bans */ lp_p = &chptr->banlist; while (*lp_p) { lp = *lp_p; /* remove ban from channel */ if (lp->flags & (CHFL_BAN_OVERLAPPED | CHFL_BURST_BAN_WIPEOUT)) { modebuf_mode_string(mbuf, MODE_DEL | MODE_BAN, lp->value.ban.banstr, 1); /* let it free banstr */ *lp_p = lp->next; /* clip out of list */ MyFree(lp->value.ban.who); /* free who */ free_link(lp); /* free ban */ continue; } else if (lp->flags & CHFL_BURST_BAN) /* add ban to channel */ modebuf_mode_string(mbuf, MODE_ADD | MODE_BAN, lp->value.ban.banstr, 0); /* don't free banstr */ lp->flags &= (CHFL_BAN | CHFL_BAN_IPMASK); /* reset the flag */ lp_p = &(*lp_p)->next; } } return mbuf ? modebuf_flush(mbuf) : 0; }
/* * mo_settime - oper message handler * * parv[0] = sender prefix * parv[1] = new time * parv[2] = servername (Only used when sptr is an Oper). */ int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { time_t t; long dt; static char tbuf[11]; /* Must be a global oper */ if (!IsOper(sptr)) return send_reply(sptr, ERR_NOPRIVILEGES); if (parc < 2) /* verify argument count */ return need_more_params(sptr, "SETTIME"); if (parc == 2 && MyUser(sptr)) /* default to me */ parv[parc++] = cli_name(&me); t = atoi(parv[1]); /* convert the time */ /* If we're reliable_clock or if the oper specified a 0 time, use current */ if (!t || feature_bool(FEAT_RELIABLE_CLOCK)) { t = TStime(); ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime()); parv[1] = tbuf; } dt = TStime() - t; /* calculate the delta */ if (t < OLDEST_TS || dt < -9000000) /* verify value */ { sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :SETTIME: Bad value", sptr); return 0; } /* OK, send the message off to its destination */ if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) != HUNTED_ISME) return 0; if (feature_bool(FEAT_RELIABLE_CLOCK)) /* don't apply settime--reliable */ { if ((dt > 600) || (dt < -600)) sendcmdto_serv_butone(&me, CMD_DESYNCH, 0, ":Bad SETTIME from %s: %Tu " "(delta %ld)", cli_name(sptr), t, dt); if (IsUser(sptr)) /* Let user know we're ignoring him */ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds " "%s: RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards"); } else /* tell opers about time change */ { sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld " "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards"); TSoffset -= dt; /* apply time change */ if (IsUser(sptr)) /* let user know what we did */ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s", sptr, (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards"); } return 0; }
void relay_channel_message(struct Client* sptr, const char* name, const char* text) { struct Channel* chptr; struct Membership *member; assert(0 != sptr); assert(0 != name); assert(0 != text); if (0 == (chptr = FindChannel(name))) { send_reply(sptr, ERR_NOSUCHCHANNEL, name); return; } /* * This first: Almost never a server/service */ if (!client_can_send_to_channel(sptr, chptr) && !(cli_flags(sptr) & FLAGS_CHSERV)) { send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname); return; } /* Los ctcps empiezan con el ASCII numero 1 */ if ((strlen(text) > 1) && (chptr->rhmode.mode & RHMODE_NOCTCP) && (text[0] == 1) && (strncasecmp(text+1, ACTION_STR, ACTION_STR_LEN))) { member = find_member_link(chptr, sptr); if (!member || (!es_representante(sptr) && !IsPreoper(sptr) && !IsVoicedOrOpped(member))) { send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname); return; } } if ((chptr->mode.mode & MODE_NOPRIVMSGS) && check_target_limit(sptr, chptr, chptr->chname, 0)) return; /* Parseo de los colores en el texto a un canal si tiene +c */ if (MyUser(sptr) && !es_representante(sptr)) { int flags = 0; char *texto_procesado; if (chptr->rhmode.mode & (RHMODE_NOCOLOR | RHMODE_BADWORDS)) member = find_member_link(chptr, sptr); if (chptr->rhmode.mode & RHMODE_NOCOLOR) { if (member && !IsVoicedOrOpped(member)) { int len = strlen(text); correct_colors((char *)text); if (len != strlen(text)) { send_reply(sptr, ERR_NOCOLORSCHAN, chptr->chname); } } } if (chptr->rhmode.mode & RHMODE_BADWORDS) { if (member) { if (!(member->status & (CHFL_CHANOP | CHFL_OWNER | CHFL_HALFOP))) flags = (BADWORDS_CHANNEL | BADWORDS_CHANPRIO); } else flags = (BADWORDS_CHANNEL | BADWORDS_CHANPRIO); } else flags = (BADWORDS_CHANPRIO); if ((texto_procesado = process_badwords(text, flags)) != NULL) { sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr), SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, texto_procesado); return; } } sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr), SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text); }
static void vsendto_prefix_one(struct Client *to, struct Client *from, char *pattern, va_list vlorig) { va_list vl; va_copy(vl,vlorig); if (to && from && MyUser(to) && IsUser(from)) { static char sender[HOSTLEN + NICKLEN + USERLEN + 5]; char *par; int flag = 0; Reg3 anUser *user = from->cli_user; par = va_arg(vl, char *); strcpy(sender, from->name); #if defined(ESNET_NEG) if (user && !(to->cli_connect->negociacion & USER_TOK)) #else if (user) #endif { if (user->username) { strcat(sender, "!"); strcat(sender, user->username); } if (user->host && !MyConnect(from)) { strcat(sender, "@"); #if defined(BDD_VIP) strcat(sender, get_visiblehost(from, NULL)); #else strcat(sender, user->host); #endif flag = 1; } } /* * Flag is used instead of strchr(sender, '@') for speed and * also since username/nick may have had a '@' in them. -avalon */ #if defined(ESNET_NEG) if (!flag && MyConnect(from) && user->host && !(to->cli_connect->negociacion & USER_TOK)) #else if (!flag && MyConnect(from) && user->host) #endif { strcat(sender, "@"); #if defined(BDD_VIP) strcat(sender, get_visiblehost(from, NULL)); #else if (IsUnixSocket(from)) strcat(sender, user->host); else strcat(sender, from->sockhost); #endif } *sendbuf = ':'; strcpy(&sendbuf[1], sender); /* Assuming 'pattern' always starts with ":%s ..." */ vsprintf_irc(sendbuf + strlen(sendbuf), &pattern[3], vl); } else
void checkClient(struct Client *sptr, struct Client *acptr) { struct Channel *chptr; struct Membership *lp; char outbuf[BUFSIZE]; char *privs; time_t nowr; /* Header */ send_reply(sptr, RPL_DATASTR, " "); send_reply(sptr, RPL_CHKHEAD, "user", acptr->cli_name); send_reply(sptr, RPL_DATASTR, " "); ircd_snprintf(0, outbuf, sizeof(outbuf), " Nick:: %s (%s%s)", acptr->cli_name, NumNick(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); if (MyUser(acptr)) { ircd_snprintf(0, outbuf, sizeof(outbuf), " Signed on:: %s", myctime(acptr->cli_firsttime)); send_reply(sptr, RPL_DATASTR, outbuf); } ircd_snprintf(0, outbuf, sizeof(outbuf), " Timestamp:: %s (%d)", myctime(acptr->cli_lastnick), acptr->cli_lastnick); send_reply(sptr, RPL_DATASTR, outbuf); ircd_snprintf(0, outbuf, sizeof(outbuf), " User/Hostmask:: %s@%s (%s)", acptr->cli_user->username, acptr->cli_user->host, ircd_ntoa((const char*) &(cli_ip(acptr)))); send_reply(sptr, RPL_DATASTR, outbuf); if (((feature_int(FEAT_HOST_HIDING_STYLE) == 1) ? HasHiddenHost(acptr) : IsHiddenHost(acptr)) || IsSetHost(acptr)) { ircd_snprintf(0, outbuf, sizeof(outbuf), " Real User/Host:: %s@%s", acptr->cli_user->realusername, acptr->cli_user->realhost); send_reply(sptr, RPL_DATASTR, outbuf); } ircd_snprintf(0, outbuf, sizeof(outbuf), " Real Name:: %s%c", cli_info(acptr), COLOR_OFF); send_reply(sptr, RPL_DATASTR, outbuf); if (IsService(cli_user(acptr)->server)) { if (acptr) send_reply(sptr, RPL_DATASTR, " Status:: Network Service"); else if (IsAdmin(acptr)) send_reply(sptr, RPL_DATASTR, " Status:: IRC Administrator (service)"); else if (IsAnOper(acptr)) send_reply(sptr, RPL_DATASTR, " Status:: IRC Operator (service)"); else send_reply(sptr, RPL_DATASTR, " Status:: Client (service)"); } else if (IsAdmin(acptr)) { send_reply(sptr, RPL_DATASTR, " Status:: IRC Administrator"); } else if (IsAnOper(acptr)) { send_reply(sptr, RPL_DATASTR, " Status:: IRC Operator"); } else { send_reply(sptr, RPL_DATASTR, " Status:: Client"); } if (MyUser(acptr)) { ircd_snprintf(0, outbuf, sizeof(outbuf), " Class:: %s", get_client_class(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); } privs = client_print_privs(acptr); if (strlen(privs) > 1) client_check_privs(acptr, sptr); ircd_snprintf(0, outbuf, sizeof(outbuf), " Connected to:: %s", cli_name(acptr->cli_user->server)); send_reply(sptr, RPL_DATASTR, outbuf); if (cli_version(acptr)) { if (strlen(cli_version(acptr)) > 0) { ircd_snprintf(0, outbuf, sizeof(outbuf), " CTCP Version:: %s", cli_version(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); } } if (cli_user(acptr) && !EmptyString(cli_user(acptr)->swhois)) { ircd_snprintf(0, outbuf, sizeof(outbuf), " SWHOIS:: %s", cli_user(acptr)->swhois); send_reply(sptr, RPL_DATASTR, outbuf); } if (cli_webirc(acptr)) { if (strlen(cli_webirc(acptr)) > 0) { ircd_snprintf(0, outbuf, sizeof(outbuf), " WebIRC:: %s", cli_webirc(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); } } if (cli_sslclifp(acptr) && (strlen(cli_sslclifp(acptr)) > 0)) { ircd_snprintf(0, outbuf, sizeof(outbuf), "SSL Fingerprint:: %s", cli_sslclifp(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); } if (MyUser(acptr)) get_eflags(sptr, acptr); /* +s (SERV_NOTICE) is not relayed to us from remote servers, * so we cannot tell if a remote client has that mode set. * And hacking it onto the end of the output of umode_str is EVIL BAD AND WRONG * (and breaks if the user is +r) so we won't do that either. */ if (strlen(umode_str(acptr)) < 1) strcpy(outbuf, " Umode(s):: <none>"); else ircd_snprintf(0, outbuf, sizeof(outbuf), " Umode(s):: +%s", umode_str(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); if (acptr->cli_user->joined == 0) send_reply(sptr, RPL_DATASTR, " Channel(s):: <none>"); else if (acptr->cli_user->joined > 50) { /* NB. As a sanity check, we DO NOT show the individual channels the * client is on if it is on > 50 channels. This is to prevent the ircd * barfing ala Uworld when someone does /quote check Q :).. (I shouldn't imagine * an Oper would want to see every single channel 'x' client is on anyway if * they are on *that* many). */ ircd_snprintf(0, outbuf, sizeof(outbuf), " Channel(s):: - (total: %u)", acptr->cli_user->joined); send_reply(sptr, RPL_DATASTR, outbuf); } else { char chntext[BUFSIZE]; int len = strlen(" Channel(s):: "); int mlen = strlen(me.cli_name) + len + strlen(sptr->cli_name); *chntext = '\0'; strcpy(chntext, " Channel(s):: "); for (lp = acptr->cli_user->channel; lp; lp = lp->next_channel) { chptr = lp->channel; if (len + strlen(chptr->chname) + mlen > BUFSIZE - 5) { send_reply(sptr, RPL_DATASTR, chntext); *chntext = '\0'; strcpy(chntext, " Channel(s):: "); len = strlen(chntext); } if (IsDeaf(acptr)) *(chntext + len++) = '-'; if (is_chan_op(acptr, chptr)) *(chntext + len++) = '@'; if (is_half_op(acptr, chptr)) *(chntext + len++) = '%'; if (IsOper(sptr) && !ShowChannel(sptr,chptr)) *(chntext + len++) = '*'; if (IsZombie(lp)) *(chntext + len++) = '!'; if (len) *(chntext + len) = '\0'; strcpy(chntext + len, chptr->chname); len += strlen(chptr->chname); strcat(chntext + len, " "); len++; } if (chntext[0] != '\0') send_reply(sptr, RPL_DATASTR, chntext); } /* If client processing command ISN'T target (or a registered * Network Service), show idle time since the last time we * parsed something. */ if (MyUser(acptr) && !(IsService(acptr) == -1) && !(strCasediff(acptr->cli_name, sptr->cli_name) == 0)) { nowr = CurrentTime - acptr->cli_user->last; ircd_snprintf(0, outbuf, sizeof(outbuf), " Idle for:: %d days, %02ld:%02ld:%02ld", nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60); send_reply(sptr, RPL_DATASTR, outbuf); } /* Away message (if applicable) */ if (acptr->cli_user->away) { ircd_snprintf(0, outbuf, sizeof(outbuf), " Away message:: %s", acptr->cli_user->away); send_reply(sptr, RPL_DATASTR, outbuf); } /* If local user.. */ if (MyUser(acptr)) { send_reply(sptr, RPL_DATASTR, " "); ircd_snprintf(0, outbuf, sizeof(outbuf), " Ports:: %d -> %d (client -> server)", cli_port(acptr), cli_listener(acptr)->port); send_reply(sptr, RPL_DATASTR, outbuf); if (feature_bool(FEAT_CHECK_EXTENDED)) { /* Note: sendq = receiveq for a client (it makes sense really) */ ircd_snprintf(0, outbuf, sizeof(outbuf), " Data sent:: %u.%0.3u Kb (%u protocol messages)", cli_receiveK(acptr), cli_receiveB(acptr), cli_receiveM(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); ircd_snprintf(0, outbuf, sizeof(outbuf), " Data received:: %u.%0.3u Kb (%u protocol messages)", cli_sendK(acptr), cli_sendB(acptr), cli_sendM(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); ircd_snprintf(0, outbuf, sizeof(outbuf), " receiveQ size:: %d bytes (max. %d bytes)", DBufLength(&(cli_recvQ(acptr))), feature_int(FEAT_CLIENT_FLOOD)); send_reply(sptr, RPL_DATASTR, outbuf); ircd_snprintf(0, outbuf, sizeof(outbuf), " sendQ size:: %d bytes (max. %d bytes)", DBufLength(&(cli_sendQ(acptr))), get_sendq(acptr)); send_reply(sptr, RPL_DATASTR, outbuf); } } /* Send 'END OF CHECK' message */ send_reply(sptr, RPL_ENDOFCHECK, " "); }
static void do_trace(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { int i; struct Client *acptr; struct Client *acptr2; const struct ConnectionClass* cl; char* tname; int doall; int *link_s; int *link_u; int cnt = 0; int wilds; int dow; if (parc < 2 || BadPtr(parv[1])) { /* just "TRACE" without parameters. Must be from local client */ parc = 1; acptr = &me; tname = cli_name(&me); i = HUNTED_ISME; } else if (parc < 3 || BadPtr(parv[2])) { /* No target specified. Make one before propagating. */ parc = 2; tname = parv[1]; if ((acptr = find_match_server(parv[1])) || ((acptr = FindClient(parv[1])) && !MyUser(acptr))) { if (IsUser(acptr)) parv[2] = cli_name(cli_user(acptr)->server); else parv[2] = cli_name(acptr); parc = 3; parv[3] = 0; if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr), "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH) return; } else i = HUNTED_ISME; } else { /* Got "TRACE <tname> :<target>" */ parc = 3; if (MyUser(sptr) || Protocol(cptr) < 10) acptr = find_match_server(parv[2]); else acptr = FindNServer(parv[2]); if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH) return; tname = parv[1]; } if (i == HUNTED_PASS) { if (!acptr) acptr = next_client(GlobalClientList, tname); else acptr = cli_from(acptr); send_reply(sptr, RPL_TRACELINK, version, debugmode, tname, acptr ? cli_name(cli_from(acptr)) : "<No_match>"); return; } doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1; wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?'); dow = wilds || doall; /* Don't give (long) remote listings to lusers */ if (dow && !MyConnect(sptr) && !IsAnOper(sptr)) { send_reply(sptr, RPL_TRACEEND); return; } link_s = MyCalloc(2 * maxconnections, sizeof(link_s[0])); link_u = link_s + maxconnections; if (doall) { for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) { if (IsUser(acptr)) link_u[cli_fd(cli_from(acptr))]++; else if (IsServer(acptr)) link_s[cli_fd(cli_from(acptr))]++; } } /* report all direct connections */ for (i = 0; i <= HighestFd; i++) { const char *conClass; if (!(acptr = LocalClientArray[i])) /* Local Connection? */ continue; if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) && !IsAnOper(acptr) && (acptr != sptr)) continue; if (!doall && wilds && match(tname, cli_name(acptr))) continue; if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr))) continue; conClass = get_client_class(acptr); switch (cli_status(acptr)) { case STAT_CONNECTING: send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr)); cnt++; break; case STAT_HANDSHAKE: send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr)); cnt++; break; case STAT_ME: break; case STAT_UNKNOWN: case STAT_UNKNOWN_USER: send_reply(sptr, RPL_TRACEUNKNOWN, conClass, get_client_name(acptr, HIDE_IP)); cnt++; break; case STAT_UNKNOWN_SERVER: send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server"); cnt++; break; case STAT_USER: /* Only opers see users if there is a wildcard but anyone can see all the opers. */ if ((IsAnOper(sptr) && (MyUser(sptr) || !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) { if (IsAnOper(acptr)) send_reply(sptr, RPL_TRACEOPERATOR, conClass, get_client_name(acptr, SHOW_IP), CurrentTime - cli_lasttime(acptr)); else send_reply(sptr, RPL_TRACEUSER, conClass, get_client_name(acptr, SHOW_IP), CurrentTime - cli_lasttime(acptr)); cnt++; } break; /* * Connection is a server * * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age> * * class Class the server is in * nS Number of servers reached via this link * nC Number of clients reached via this link * name Name of the server linked * ConnBy Who established this link * last Seconds since we got something from this link * age Seconds this link has been alive * * Additional comments etc...... -Cym-<*****@*****.**> */ case STAT_SERVER: if (cli_serv(acptr)->user) { if (!cli_serv(acptr)->by[0] || !(acptr2 = findNUser(cli_serv(acptr)->by)) || (cli_user(acptr2) != cli_serv(acptr)->user)) acptr2 = NULL; send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i], link_u[i], cli_name(acptr), acptr2 ? cli_name(acptr2) : "*", cli_serv(acptr)->user->username, cli_serv(acptr)->user->host, CurrentTime - cli_lasttime(acptr), CurrentTime - cli_serv(acptr)->timestamp); } else send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i], link_u[i], cli_name(acptr), (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*", cli_name(&me), CurrentTime - cli_lasttime(acptr), CurrentTime - cli_serv(acptr)->timestamp); cnt++; break; default: /* We actually shouldn't come here, -msa */ send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP)); cnt++; break; } } /* * Add these lines to summarize the above which can get rather long * and messy when done remotely - Avalon */ if (IsAnOper(sptr) && doall) { for (cl = get_class_list(); cl; cl = cl->next) { if (Links(cl) > 1) send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl) - 1); } } send_reply(sptr, RPL_TRACEEND); MyFree(link_s); }
/* Rewritten by Run - 24 sept 94 */ static void exit_one_client(struct Client* bcptr, const char* comment) { struct SLink *lp; struct Ban *bp; if (cli_serv(bcptr) && cli_serv(bcptr)->client_list) /* Was SetServerYXX called ? */ ClearServerYXX(bcptr); /* Removes server from server_list[] */ if (IsUser(bcptr)) { /* * clear out uping requests */ if (IsUPing(bcptr)) uping_cancel(bcptr, 0); /* * Stop a running /LIST clean */ if (MyUser(bcptr) && cli_listing(bcptr)) { MyFree(cli_listing(bcptr)); cli_listing(bcptr) = NULL; } /* * If a person is on a channel, send a QUIT notice * to every client (person) on the same channel (so * that the client can show the "**signoff" message). * (Note: The notice is to the local clients *only*) */ sendcmdto_common_channels_butone(bcptr, CMD_QUIT, NULL, ":%s", comment); remove_user_from_all_channels(bcptr); /* Clean up invitefield */ while ((lp = cli_user(bcptr)->invited)) del_invite(bcptr, lp->value.chptr); /* Clean up silencefield */ while ((bp = cli_user(bcptr)->silence)) { cli_user(bcptr)->silence = bp->next; free_ban(bp); } /* Clean up snotice lists */ if (MyUser(bcptr)) set_snomask(bcptr, ~0, SNO_DEL); if (IsInvisible(bcptr)) { assert(UserStats.inv_clients > 0); --UserStats.inv_clients; } if (IsOper(bcptr)) { assert(UserStats.opers > 0); --UserStats.opers; } if (MyConnect(bcptr)) Count_clientdisconnects(bcptr, UserStats); else Count_remoteclientquits(UserStats, bcptr); } else if (IsServer(bcptr)) { /* Remove downlink list node of uplink */ remove_dlink(&(cli_serv(cli_serv(bcptr)->up))->down, cli_serv(bcptr)->updown); cli_serv(bcptr)->updown = 0; if (MyConnect(bcptr)) Count_serverdisconnects(UserStats); else Count_remoteserverquits(UserStats); } else if (IsMe(bcptr)) { sendto_opmask_butone(0, SNO_OLDSNO, "ERROR: tried to exit me! : %s", comment); return; /* ...must *never* exit self! */ } else if (IsUnknown(bcptr) || IsConnecting(bcptr) || IsHandshake(bcptr)) Count_unknowndisconnects(UserStats); /* * Update IPregistry */ if (IsIPChecked(bcptr)) IPcheck_disconnect(bcptr); /* * Remove from serv->client_list * NOTE: user is *always* NULL if this is a server */ if (cli_user(bcptr)) { assert(!IsServer(bcptr)); /* bcptr->user->server->serv->client_list[IndexYXX(bcptr)] = NULL; */ RemoveYXXClient(cli_user(bcptr)->server, cli_yxx(bcptr)); } /* Remove bcptr from the client list */ #ifdef DEBUGMODE if (hRemClient(bcptr) != 0) Debug((DEBUG_ERROR, "%p !in tab %s[%s] %p %p %p %d %d %p", bcptr, cli_name(bcptr), cli_from(bcptr) ? cli_sockhost(cli_from(bcptr)) : "??host", cli_from(bcptr), cli_next(bcptr), cli_prev(bcptr), cli_fd(bcptr), cli_status(bcptr), cli_user(bcptr))); #else hRemClient(bcptr); #endif remove_client_from_list(bcptr); }
/** Apply and send silence updates for a user. * @param[in] sptr Client whose silence list has been updated. * @param[in] silences Comma-separated list of silence updates. * @param[in] dest Direction to send updates in (NULL for broadcast). */ static void forward_silences(struct Client *sptr, char *silences, struct Client *dest) { struct Ban *accepted[MAXPARA], *sile, **plast; char *cp, *p, buf[BUFSIZE]; size_t ac_count, buf_used, slen, ii; /* Split the list of silences and try to apply each one in turn. */ for (cp = ircd_strtok(&p, silences, ","), ac_count = 0; cp && (ac_count < MAXPARA); cp = ircd_strtok(&p, 0, ",")) { if ((sile = apply_silence(sptr, cp))) accepted[ac_count++] = sile; } if (MyUser(sptr)) { size_t siles, maxsiles, totlength, maxlength, jj; /* Check that silence count and total length are permitted. */ maxsiles = feature_int(FEAT_MAXSILES); maxlength = maxsiles * feature_int(FEAT_AVBANLEN); siles = totlength = 0; /* Count number of current silences and their total length. */ plast = &cli_user(sptr)->silence; for (sile = cli_user(sptr)->silence; sile; sile = sile->next) { if (sile->flags & (BAN_OVERLAPPED | BAN_ADD | BAN_DEL)) continue; siles++; totlength += strlen(sile->banstr); plast = &sile->next; } for (ii = jj = 0; ii < ac_count; ++ii) { sile = accepted[ii]; /* If the update is being added, and we would exceed the maximum * count or length, drop the update. */ if (!(sile->flags & (BAN_OVERLAPPED | BAN_DEL))) { slen = strlen(sile->banstr); if ((siles >= maxsiles) || (totlength + slen >= maxlength)) { *plast = NULL; if (MyUser(sptr)) send_reply(sptr, ERR_SILELISTFULL, accepted[ii]->banstr); free_ban(accepted[ii]); continue; } /* Update counts. */ siles++; totlength += slen; plast = &sile->next; } /* Store the update. */ accepted[jj++] = sile; } /* Write back the number of accepted updates. */ ac_count = jj; /* Send the silence update list, including overlapped silences (to * make it easier on clients). */ buf_used = 0; for (sile = cli_user(sptr)->silence; sile; sile = sile->next) { char ch; if (sile->flags & (BAN_OVERLAPPED | BAN_DEL)) ch = '-'; else if (sile->flags & BAN_ADD) ch = '+'; else continue; slen = strlen(sile->banstr); if (buf_used + slen + 4 > 400) { buf[buf_used] = '\0'; sendcmdto_one(sptr, CMD_SILENCE, sptr, "%s", buf); buf_used = 0; } if (buf_used) buf[buf_used++] = ','; buf[buf_used++] = ch; if (sile->flags & BAN_EXCEPTION) buf[buf_used++] = '~'; memcpy(buf + buf_used, sile->banstr, slen); buf_used += slen; } if (buf_used > 0) { buf[buf_used] = '\0'; sendcmdto_one(sptr, CMD_SILENCE, sptr, "%s", buf); buf_used = 0; } } /* Forward any silence removals or exceptions updates to other * servers if the user has positive silences. */ if (!dest || !MyUser(dest)) { for (ii = buf_used = 0; ii < ac_count; ++ii) { char ch; sile = accepted[ii]; if (sile->flags & BAN_OVERLAPPED) continue; else if (sile->flags & BAN_DEL) ch = '-'; else if (sile->flags & BAN_ADD) { if (!(sile->flags & BAN_EXCEPTION)) continue; ch = '+'; } else continue; slen = strlen(sile->banstr); if (buf_used + slen + 4 > 400) { buf[buf_used] = '\0'; if (dest) sendcmdto_one(sptr, CMD_SILENCE, dest, "%C %s", dest, buf); else sendcmdto_serv_butone(sptr, CMD_SILENCE, sptr, "* %s", buf); buf_used = 0; } if (buf_used) buf[buf_used++] = ','; buf[buf_used++] = ch; if (sile->flags & BAN_EXCEPTION) buf[buf_used++] = '~'; memcpy(buf + buf_used, sile->banstr, slen); buf_used += slen; } if (buf_used > 0) { buf[buf_used] = '\0'; if (dest) sendcmdto_one(sptr, CMD_SILENCE, dest, "%C %s", dest, buf); else sendcmdto_serv_butone(sptr, CMD_SILENCE, sptr, "* %s", buf); buf_used = 0; } } /* Remove overlapped and deleted silences from the user's silence * list. Clear BAN_ADD since we're walking the list anyway. */ for (plast = &cli_user(sptr)->silence; (sile = *plast) != NULL; ) { if (sile->flags & (BAN_OVERLAPPED | BAN_DEL)) { *plast = sile->next; free_ban(sile); } else { sile->flags &= ~BAN_ADD; *plast = sile; plast = &sile->next; } } /* Free any silence-deleting updates. */ for (ii = 0; ii < ac_count; ++ii) { if ((accepted[ii]->flags & (BAN_ADD | BAN_DEL)) == BAN_DEL) { free_ban(accepted[ii]); } } }
void relay_private_message(struct Client *cptr, struct Client* sptr, const char* name, const char* text) { struct Client* acptr; static char *pmsg = NULL; static int last_length = 0; int len; assert(0 != sptr); assert(0 != name); assert(0 != text); if (0 == (acptr = FindUser(name))) { send_reply(sptr, ERR_NOSUCHNICK, name); return; } if (IsOnlyreg(acptr) && !IsRegnick(sptr)) { send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); return; } if (!IsChannelService(acptr)) { if (check_target_limit(sptr, acptr, cli_name(acptr), 0)) { return; } if (is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } } if (MyUser(cptr) && !es_representante(cptr)) { if ((len = strlen(text)+1) > last_length) { if (pmsg) free(pmsg); pmsg = (char *)MyMalloc(sizeof(char)*len); last_length = len; } strcpy(pmsg, text); correct_colors(pmsg); if (process_badwords(pmsg, BADWORDS_QUERY) != NULL) return; } /* * send away message if user away */ if (cli_user(acptr) && cli_user(acptr)->away) send_reply(sptr, RPL_AWAY, cli_name(acptr), cli_user(acptr)->away); /* * deliver the message */ if (MyUser(acptr)) add_target(acptr, sptr); sendcmdto_one(sptr, CMD_PRIVATE, acptr, "%C :%s", acptr, text); }
int m_challenge(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { #ifdef USE_SSL struct ConfItem *aconf; RSA *rsa_public_key; BIO *file = NULL; char *challenge = NULL; char *name; char *tmpname; char chan[CHANNELLEN-1]; char* join[2]; int nl; struct Flags old_mode = cli_flags(sptr); if (!MyUser(sptr)) return 0; if (parc < 2) return need_more_params(sptr, "CHALLENGE"); if (parc > 2) { /* This is a remote OPER Request */ struct Client *srv; if (!string_has_wildcards(parv[1])) srv = FindServer(parv[1]); else srv = find_match_server(parv[1]); if (!feature_bool(FEAT_REMOTE_OPER)) return send_reply(sptr, ERR_NOOPERHOST); if (!srv) return send_reply(sptr, ERR_NOOPERHOST); if (IsMe(srv)) { parv[1] = parv[2]; } else { sendcmdto_one(sptr, CMD_CHALLENGE, srv, "%C %s", srv, parv[2]); return 0; } } /* if theyre an oper, reprint oper motd and ignore */ if (IsOper(sptr)) { send_reply(sptr, RPL_YOUREOPER); if (feature_bool(FEAT_OPERMOTD)) m_opermotd(sptr, sptr, 1, parv); } if (*parv[1] == '+') { /* Ignore it if we aren't expecting this... -A1kmm */ if (cli_user(sptr)->response == NULL) return 0; if (ircd_strcmp(cli_user(sptr)->response, ++parv[1])) { send_reply(sptr, ERR_PASSWDMISMATCH); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (Password Incorrect)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); tmpname = strdup(cli_user(sptr)->auth_oper); failed_challenge_notice(sptr, tmpname, "challenge failed"); return 0; } name = strdup(cli_user(sptr)->auth_oper); aconf = find_conf_exact(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, MyUser(sptr) ? cli_sockhost(sptr) : cli_user(sptr)->realhost, CONF_OPS); if (!aconf) aconf = find_conf_exact(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, ircd_ntoa((const char*) &(cli_ip(sptr))), CONF_OPS); if (!aconf) aconf = find_conf_cidr(cli_user(sptr)->auth_oper, cli_user(sptr)->realusername, cli_ip(sptr), CONF_OPS); if (!aconf) { send_reply(sptr, ERR_NOOPERHOST); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (No O:line)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); return 0; } if (CONF_LOCOP == aconf->status) { ClearOper(sptr); SetLocOp(sptr); } else { /* * prevent someone from being both oper and local oper */ ClearLocOp(sptr); if (!feature_bool(FEAT_OPERFLAGS) || !(aconf->port & OFLAG_ADMIN)) { /* Global Oper */ SetOper(sptr); ClearAdmin(sptr); } else { /* Admin */ SetOper(sptr); OSetGlobal(sptr); SetAdmin(sptr); } ++UserStats.opers; } cli_handler(cptr) = OPER_HANDLER; if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_WHOIS)) { OSetWhois(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_IDLE)) { OSetIdle(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_XTRAOP)) { OSetXtraop(sptr); } if (!feature_bool(FEAT_OPERFLAGS) || (aconf->port & OFLAG_HIDECHANS)) { OSetHideChans(sptr); } SetFlag(sptr, FLAG_WALLOP); SetFlag(sptr, FLAG_SERVNOTICE); SetFlag(sptr, FLAG_DEBUG); if (!IsAdmin(sptr)) cli_oflags(sptr) = aconf->port; set_snomask(sptr, SNO_OPERDEFAULT, SNO_ADD); client_set_privs(sptr, aconf); cli_max_sendq(sptr) = 0; /* Get the sendq from the oper's class */ send_umode_out(cptr, sptr, &old_mode, HasPriv(sptr, PRIV_PROPAGATE)); send_reply(sptr, RPL_YOUREOPER); if (IsAdmin(sptr)) { sendto_allops(&me, SNO_OLDSNO, "%s (%s@%s) is now an IRC Administrator", parv[0], cli_user(sptr)->username, cli_sockhost(sptr)); /* Autojoin admins to admin channel and oper channel (if enabled) */ if (feature_bool(FEAT_AUTOJOIN_ADMIN)) { if (feature_bool(FEAT_AUTOJOIN_ADMIN_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_ADMIN_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_ADMIN_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } if (feature_bool(FEAT_AUTOJOIN_OPER) && IsOper(sptr)) { if (feature_bool(FEAT_AUTOJOIN_OPER_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_OPER_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_OPER_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } } else { sendto_allops(&me, SNO_OLDSNO, "%s (%s@%s) is now an IRC Operator (%c)", parv[0], cli_user(sptr)->username, cli_sockhost(sptr), IsOper(sptr) ? 'O' : 'o'); if (feature_bool(FEAT_AUTOJOIN_OPER) && IsOper(sptr)) { if (feature_bool(FEAT_AUTOJOIN_OPER_NOTICE)) sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, feature_str(FEAT_AUTOJOIN_OPER_NOTICE_VALUE)); ircd_strncpy(chan, feature_str(FEAT_AUTOJOIN_OPER_CHANNEL), CHANNELLEN-1); join[0] = cli_name(sptr); join[1] = chan; m_join(sptr, sptr, 2, join); } } if (feature_bool(FEAT_OPERMOTD)) m_opermotd(sptr, sptr, 1, parv); log_write(LS_OPER, L_INFO, 0, "OPER (%s) by (%#C)", name, sptr); ircd_snprintf(0, cli_user(sptr)->response, BUFSIZE+1, "%s", ""); return 0; } ircd_snprintf(0, cli_user(sptr)->response, BUFSIZE+1, "%s", ""); ircd_snprintf(0, cli_user(sptr)->auth_oper, NICKLEN+1, "%s", ""); aconf = find_conf_exact(parv[1], cli_user(sptr)->realusername, cli_user(sptr)->realhost, CONF_OPS); if (!aconf) aconf = find_conf_exact(parv[1], cli_user(sptr)->realusername, ircd_ntoa((const char*) &(cli_ip(sptr))), CONF_OPS); if (!aconf) aconf = find_conf_cidr(parv[1], cli_user(sptr)->realusername, cli_ip(sptr), CONF_OPS); if (aconf == NULL) { send_reply(sptr, ERR_NOOPERHOST); failed_challenge_notice(sptr, parv[1], "No o:line"); sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (No O:line)", parv[0], cli_user(sptr)->realusername, cli_sockhost(sptr)); return 0; } if (!(aconf->port & OFLAG_RSA)) { send_reply(sptr, RPL_NO_CHALL); return 0; } if (!verify_sslclifp(sptr, aconf)) { sendto_allops(&me, SNO_OLDREALOP, "Failed OPER attempt by %s (%s@%s) (SSL Fingerprint Missmatch)", parv[0], cli_user(sptr)->realusername, cli_user(sptr)->realhost); send_reply(sptr, ERR_SSLCLIFP); return 0; } if ((file = BIO_new_file(aconf->passwd, "r")) == NULL) { send_reply(sptr, RPL_NO_KEY); return 0; } rsa_public_key = (RSA *)PEM_read_bio_RSA_PUBKEY(file, NULL, 0, NULL); if (rsa_public_key == NULL) return send_reply(sptr, RPL_INVALID_KEY); if (!generate_challenge(&challenge, rsa_public_key, sptr)) { Debug((DEBUG_DEBUG, "generating challenge sum (%s)", challenge)); send_reply(sptr, RPL_RSACHALLENGE, challenge); ircd_snprintf(0, cli_user(sptr)->auth_oper, NICKLEN + 1, "%s", aconf->name); } nl = BIO_set_close(file, BIO_CLOSE); BIO_free(file); return 1; #else return 1; #endif }
/** Create a new Z-line and add it to global lists. * \a ipmask must be an IP mask to create an IP-based ban. * * @param[in] cptr Client that sent us the Z-line. * @param[in] sptr Client that originated the Z-line. * @param[in] ipmask Text mask for the Z-line. * @param[in] reason Reason for Z-line. * @param[in] expire Expiration time of Z-line. * @param[in] lastmod Last modification time of Z-line. * @param[in] lifetime Lifetime of Z-line. * @param[in] flags Bitwise combination of ZLINE_* flags. * @return Zero or CPTR_KILLED, depending on whether \a sptr is suicidal. */ int zline_add(struct Client *cptr, struct Client *sptr, char *ipmask, char *reason, time_t expire, time_t lastmod, time_t lifetime, unsigned int flags) { struct Zline *azline; char imask[HOSTLEN + 2]; char *mask; int tmp; assert(0 != ipmask); assert(0 != reason); assert(((flags & (ZLINE_GLOBAL | ZLINE_LOCAL)) == ZLINE_GLOBAL) || ((flags & (ZLINE_GLOBAL | ZLINE_LOCAL)) == ZLINE_LOCAL)); Debug((DEBUG_DEBUG, "zline_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu " "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), ipmask, reason, expire, lastmod, lifetime, flags)); mask = ipmask; if (sizeof(imask) < ircd_snprintf(0, imask, sizeof(imask), "%s", mask)) return send_reply(sptr, ERR_LONGMASK); else if (MyUser(sptr) || (IsUser(sptr) && flags & ZLINE_LOCAL)) { switch (zline_checkmask(mask)) { case CHECK_OVERRIDABLE: /* oper overrided restriction */ if (flags & ZLINE_OPERFORCE) break; /*FALLTHROUGH*/ case CHECK_REJECTED: return send_reply(sptr, ERR_MASKTOOWIDE, imask); break; } if ((tmp = count_users(imask, flags)) >= feature_int(FEAT_ZLINEMAXUSERCOUNT) && !(flags & ZLINE_OPERFORCE)) return send_reply(sptr, ERR_TOOMANYUSERS, tmp); } if (!check_if_ipmask(ipmask)) return send_reply(sptr, ERR_INVALIDMASK); /* * You cannot set a negative (or zero) expire time, nor can you set an * expiration time for greater than ZLINE_MAX_EXPIRE. */ if (!(flags & ZLINE_FORCE) && (expire <= TStime() || expire > TStime() + ZLINE_MAX_EXPIRE)) { if (!IsServer(sptr) && MyConnect(sptr)) send_reply(sptr, ERR_BADEXPIRE, expire); return 0; } else if (expire <= TStime()) { /* This expired Z-line was forced to be added, so mark it inactive. */ flags &= ~ZLINE_ACTIVE; } if (!lifetime) /* no lifetime set, use expiration time */ lifetime = expire; /* lifetime is already an absolute timestamp */ /* Inform ops... */ sendto_opmask_butone(0, ircd_strncmp(reason, "AUTO", 4) ? SNO_GLINE : SNO_AUTO, "%s adding %s%s ZLINE for %s, expiring at " "%Tu: %s", (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? cli_name(sptr) : cli_name((cli_user(sptr))->server), (flags & ZLINE_ACTIVE) ? "" : "deactivated ", (flags & ZLINE_LOCAL) ? "local" : "global", mask, expire, reason); /* and log it */ log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE, "%#C adding %s ZLINE for %s, expiring at %Tu: %s", sptr, flags & ZLINE_LOCAL ? "local" : "global", mask, expire, reason); /* make the zline */ azline = make_zline(mask, reason, expire, lastmod, lifetime, flags); /* since we've disabled overlapped Z-line checking, azline should * never be NULL... */ assert(azline); zline_propagate(cptr, sptr, azline); return do_zline(cptr, sptr, azline); /* knock off users if necessary */ }
/* * ms_burst - server message handler * * -- by Run [email protected] december 1995 till march 1997 * * parv[0] = sender prefix * parv[1] = channel name * parv[2] = channel timestamp * The meaning of the following parv[]'s depend on their first character: * If parv[n] starts with a '+': * Net burst, additive modes * parv[n] = <mode> * parv[n+1] = <param> (optional) * parv[n+2] = <param> (optional) * If parv[n] starts with a '%', then n will be parc-1: * parv[n] = %<ban> <ban> <ban> ... * If parv[n] starts with another character: * parv[n] = <nick>[:<mode>],<nick>[:<mode>],... * where <mode> defines the mode and op-level * for nick and all following nicks until the * next <mode> field. * Digits in the <mode> field have of two meanings: * 1) if it is the first field in this BURST message * that contains digits, and/or when a 'v' is * present in the <mode>: * The absolute value of the op-level. * 2) if there are only digits in this field and * it is not the first field with digits: * An op-level increment relative to the previous * op-level. * First all modeless nicks must be emmitted, * then all combinations of modes without ops * (currently that is only 'v') followed by the same * series but then with ops (currently 'o','ov'). * * Example: * "A8 B #test 87654321 +ntkAl key secret 123 A8AAG,A8AAC:v,A8AAA:0,A8AAF:2,A8AAD,A8AAB:v1,A8AAE:1 :%ban1 ban2" * * <mode> list example: * * "xxx,sss:v,ttt,aaa:123,bbb,ccc:2,ddd,kkk:v2,lll:2,mmm" * * means * * xxx // first modeless nicks * sss +v // then opless nicks * ttt +v // no ":<mode>": everything stays the same * aaa -123 // first field with digit: absolute value * bbb -123 * ccc -125 // only digits, not first field: increment * ddd -125 * kkk -2 +v // field with a 'v': absolute value * lll -4 +v // only digits: increment * mmm -4 +v * * Anti net.ride code. * * When the channel already exist, and its TS is larger than * the TS in the BURST message, then we cancel all existing modes. * If its is smaller then the received BURST message is ignored. * If it's equal, then the received modes are just added. * * BURST is also accepted outside a netburst now because it * is sent upstream as reaction to a DESTRUCT message. For * these BURST messages it is possible that the listed channel * members are already joined. */ int ms_burst(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) { struct ModeBuf modebuf, *mbuf = 0; struct Channel *chptr; time_t timestamp; struct Membership *member, *nmember; struct Ban *lp, **lp_p; unsigned int parse_flags = (MODE_PARSE_FORCE | MODE_PARSE_BURST); int param, nickpos = 0, banpos = 0; char modestr[BUFSIZE], nickstr[BUFSIZE], banstr[BUFSIZE]; if (parc < 3) return protocol_violation(sptr,"Too few parameters for BURST"); if (!(chptr = get_channel(sptr, parv[1], CGT_CREATE))) return 0; /* can't create the channel? */ timestamp = atoi(parv[2]); if (chptr->creationtime) /* 0 for new (empty) channels, i.e. when this server just restarted. */ { if (parc == 3) /* Zannel BURST? */ { /* An empty channel without +A set, will cause a BURST message with exactly 3 parameters (because all modes have been reset). If the timestamp on such channels is only a few seconds older from our own, then we ignore this burst: we do not deop our own side. Likewise, we expect the other (empty) side to copy our timestamp from our own BURST message, even though it is slightly larger. The reason for this is to allow people to join an empty non-A channel (a zannel) during a net.split, and not be deopped when the net reconnects (with another zannel). When someone joins a split zannel, their side increments the TS by one. If they cycle a few times then we still don't have a reason to deop them. Theoretically I see no reason not to accept ANY timestamp, but to be sure, we only accept timestamps that are just a few seconds off (one second for each time they cycled the channel). */ /* Don't even deop users who cycled four times during the net.break. */ if (timestamp < chptr->creationtime && chptr->creationtime <= timestamp + 4 && chptr->users != 0) /* Only do this when WE have users, so that if we do this the BURST that we sent has parc > 3 and the other side will use the test below: */ timestamp = chptr->creationtime; /* Do not deop our side. */ } else if (chptr->creationtime < timestamp && timestamp <= chptr->creationtime + 4 && chptr->users == 0) { /* If one side of the net.junction does the above timestamp = chptr->creationtime, then the other side must do this: */ chptr->creationtime = timestamp; /* Use the same TS on both sides. */ } /* In more complex cases, we might still end up with a creationtime desync of a few seconds, but that should be synced automatically rather quickly (every JOIN caries a timestamp and will sync it; modes by users do not carry timestamps and are accepted regardless). Only when nobody joins the channel on the side with the oldest timestamp before a new net.break occurs precisely inbetween the desync, an unexpected bounce might happen on reconnect. */ } if (!chptr->creationtime || chptr->creationtime > timestamp) { /* * Kick local members if channel is +i or +k and our TS was larger * than the burst TS (anti net.ride). The modes hack is here because * we have to do this before mode_parse, as chptr may go away. */ for (param = 3; param < parc; param++) { int check_modes; if (parv[param][0] != '+') continue; check_modes = netride_modes(parc - param, parv + param, chptr->mode.key); if (check_modes < 0) { if (chptr->users == 0) sub1_from_channel(chptr); return protocol_violation(sptr, "Invalid mode string in BURST"); } else if (check_modes) { /* Clear any outstanding rogue invites */ mode_invite_clear(chptr); for (member = chptr->members; member; member = nmember) { nmember = member->next_member; if (!MyUser(member->user) || IsZombie(member)) continue; /* Kick as netrider if key mismatch *or* remote channel is * +i (unless user is an oper) *or* remote channel is +r * (unless user has an account). */ if (!(check_modes & MODE_KEY) && (!(check_modes & MODE_INVITEONLY) || IsAnOper(member->user)) && (!(check_modes & MODE_REGONLY) || IsAccount(member->user))) continue; sendcmdto_serv_butone(&me, CMD_KICK, NULL, "%H %C :Net Rider", chptr, member->user); sendcmdto_channel_butserv_butone(&his, CMD_KICK, chptr, NULL, 0, "%H %C :Net Rider", chptr, member->user); make_zombie(member, member->user, &me, &me, chptr); } } break; } /* If the channel had only locals, it went away by now. */ if (!(chptr = get_channel(sptr, parv[1], CGT_CREATE))) return 0; /* can't create the channel? */ } /* turn off burst joined flag */ for (member = chptr->members; member; member = member->next_member) member->status &= ~(CHFL_BURST_JOINED|CHFL_BURST_ALREADY_OPPED|CHFL_BURST_ALREADY_VOICED); if (!chptr->creationtime) /* mark channel as created during BURST */ chptr->mode.mode |= MODE_BURSTADDED; /* new channel or an older one */ if (!chptr->creationtime || chptr->creationtime > timestamp) { chptr->creationtime = timestamp; modebuf_init(mbuf = &modebuf, &me, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_NOKEY); modebuf_mode(mbuf, MODE_DEL | chptr->mode.mode); /* wipeout modes */ chptr->mode.mode &= MODE_BURSTADDED | MODE_WASDELJOINS; /* wipe out modes not represented in chptr->mode.mode */ if (chptr->mode.limit) { modebuf_mode_uint(mbuf, MODE_DEL | MODE_LIMIT, chptr->mode.limit); chptr->mode.limit = 0; } if (chptr->mode.key[0]) { modebuf_mode_string(mbuf, MODE_DEL | MODE_KEY, chptr->mode.key, 0); chptr->mode.key[0] = '\0'; } if (chptr->mode.upass[0]) { modebuf_mode_string(mbuf, MODE_DEL | MODE_UPASS, chptr->mode.upass, 0); chptr->mode.upass[0] = '\0'; } if (chptr->mode.apass[0]) { modebuf_mode_string(mbuf, MODE_DEL | MODE_APASS, chptr->mode.apass, 0); chptr->mode.apass[0] = '\0'; } parse_flags |= (MODE_PARSE_SET | MODE_PARSE_WIPEOUT); /* wipeout keys */ /* mark bans for wipeout */ for (lp = chptr->banlist; lp; lp = lp->next) lp->flags |= BAN_BURST_WIPEOUT; /* clear topic set by netrider (if set) */ if (*chptr->topic) { *chptr->topic = '\0'; *chptr->topic_nick = '\0'; chptr->topic_time = 0; sendcmdto_channel_butserv_butone(&his, CMD_TOPIC, chptr, NULL, 0, "%H :%s", chptr, chptr->topic); } } else if (chptr->creationtime == timestamp) { modebuf_init(mbuf = &modebuf, &me, cptr, chptr, MODEBUF_DEST_CHANNEL | MODEBUF_DEST_NOKEY); parse_flags |= MODE_PARSE_SET; /* set new modes */ } param = 3; /* parse parameters */ while (param < parc) { switch (*parv[param]) { case '+': /* parameter introduces a mode string */ param += mode_parse(mbuf, cptr, sptr, chptr, parc - param, parv + param, parse_flags, NULL); break; case '%': /* parameter contains bans */ if (parse_flags & MODE_PARSE_SET) { char *banlist = parv[param] + 1, *p = 0, *ban, *ptr; struct Ban *newban; for (ban = ircd_strtok(&p, banlist, " "); ban; ban = ircd_strtok(&p, 0, " ")) { ban = collapse(pretty_mask(ban)); /* * Yeah, we should probably do this elsewhere, and make it better * and more general; this will hold until we get there, though. * I dislike the current add_banid API... -Kev * * I wish there were a better algo. for this than the n^2 one * shown below *sigh* */ for (lp = chptr->banlist; lp; lp = lp->next) { if (!ircd_strcmp(lp->banstr, ban)) { ban = 0; /* don't add ban */ lp->flags &= ~BAN_BURST_WIPEOUT; /* not wiping out */ break; /* new ban already existed; don't even repropagate */ } else if (!(lp->flags & BAN_BURST_WIPEOUT) && !mmatch(lp->banstr, ban)) { ban = 0; /* don't add ban unless wiping out bans */ break; /* new ban is encompassed by an existing one; drop */ } else if (!mmatch(ban, lp->banstr)) lp->flags |= BAN_OVERLAPPED; /* remove overlapping ban */ if (!lp->next) break; } if (ban) { /* add the new ban to the end of the list */ /* Build ban buffer */ if (!banpos) { banstr[banpos++] = ' '; banstr[banpos++] = ':'; banstr[banpos++] = '%'; } else banstr[banpos++] = ' '; for (ptr = ban; *ptr; ptr++) /* add ban to buffer */ banstr[banpos++] = *ptr; newban = make_ban(ban); /* create new ban */ strcpy(newban->who, "*"); newban->when = TStime(); newban->flags |= BAN_BURSTED; newban->next = 0; if (lp) lp->next = newban; /* link it in */ else chptr->banlist = newban; } } } param++; /* look at next param */ break; default: /* parameter contains clients */ { struct Client *acptr; char *nicklist = parv[param], *p = 0, *nick, *ptr; int current_mode, last_mode, base_mode; int oplevel = -1; /* Mark first field with digits: means the same as 'o' (but with level). */ int last_oplevel = 0; struct Membership* member; base_mode = CHFL_DEOPPED | CHFL_BURST_JOINED; if (chptr->mode.mode & MODE_DELJOINS) base_mode |= CHFL_DELAYED; current_mode = last_mode = base_mode; for (nick = ircd_strtok(&p, nicklist, ","); nick; nick = ircd_strtok(&p, 0, ",")) { if ((ptr = strchr(nick, ':'))) { /* new flags; deal */ *ptr++ = '\0'; if (parse_flags & MODE_PARSE_SET) { int current_mode_needs_reset; for (current_mode_needs_reset = 1; *ptr; ptr++) { if (*ptr == 'o') { /* has oper status */ /* * An 'o' is pre-oplevel protocol, so this is only for * backwards compatibility. Give them an op-level of * MAXOPLEVEL so everyone can deop them. */ oplevel = MAXOPLEVEL; if (current_mode_needs_reset) { current_mode = base_mode; current_mode_needs_reset = 0; } current_mode = (current_mode & ~(CHFL_DEOPPED | CHFL_DELAYED)) | CHFL_CHANOP; /* * Older servers may send XXYYY:ov, in which case we * do not want to use the code for 'v' below. */ if (ptr[1] == 'v') { current_mode |= CHFL_VOICE; ptr++; } } else if (*ptr == 'v') { /* has voice status */ if (current_mode_needs_reset) { current_mode = base_mode; current_mode_needs_reset = 0; } current_mode = (current_mode & ~CHFL_DELAYED) | CHFL_VOICE; oplevel = -1; /* subsequent digits are an absolute op-level value. */ } else if (IsDigit(*ptr)) { int level_increment = 0; if (oplevel == -1) { /* op-level is absolute value? */ if (current_mode_needs_reset) { current_mode = base_mode; current_mode_needs_reset = 0; } oplevel = 0; } current_mode = (current_mode & ~(CHFL_DEOPPED | CHFL_DELAYED)) | CHFL_CHANOP; do { level_increment = 10 * level_increment + *ptr++ - '0'; } while (IsDigit(*ptr)); oplevel += level_increment; } else /* I don't recognize that flag */ break; /* so stop processing */ } } } if (!(acptr = findNUser(nick)) || cli_from(acptr) != cptr) continue; /* ignore this client */ /* Build nick buffer */ nickstr[nickpos] = nickpos ? ',' : ' '; /* first char */ nickpos++; for (ptr = nick; *ptr; ptr++) /* store nick */ nickstr[nickpos++] = *ptr; if (current_mode != last_mode) { /* if mode changed... */ last_mode = current_mode; last_oplevel = oplevel; nickstr[nickpos++] = ':'; /* add a specifier */ if (current_mode & CHFL_VOICE) nickstr[nickpos++] = 'v'; if (current_mode & CHFL_CHANOP) { if (chptr->mode.apass[0]) nickpos += ircd_snprintf(0, nickstr + nickpos, sizeof(nickstr) - nickpos, "%u", oplevel); else nickstr[nickpos++] = 'o'; } } else if (current_mode & CHFL_CHANOP && oplevel != last_oplevel) { /* if just op level changed... */ nickstr[nickpos++] = ':'; /* add a specifier */ nickpos += ircd_snprintf(0, nickstr + nickpos, sizeof(nickstr) - nickpos, "%u", oplevel - last_oplevel); last_oplevel = oplevel; } if (!(member = find_member_link(chptr, acptr))) { add_user_to_channel(chptr, acptr, current_mode, oplevel); if (!(current_mode & CHFL_DELAYED)) sendcmdto_channel_butserv_butone(acptr, CMD_JOIN, chptr, NULL, 0, "%H", chptr); } else { /* The member was already joined (either by CREATE or JOIN). Remember the current mode. */ if (member->status & CHFL_CHANOP) member->status |= CHFL_BURST_ALREADY_OPPED; if (member->status & CHFL_VOICE) member->status |= CHFL_BURST_ALREADY_VOICED; /* Synchronize with the burst. */ member->status |= CHFL_BURST_JOINED | (current_mode & (CHFL_CHANOP|CHFL_VOICE)); SetOpLevel(member, oplevel); } } } param++; break; } /* switch (*parv[param]) */ } /* while (param < parc) */ nickstr[nickpos] = '\0'; banstr[banpos] = '\0'; if (parse_flags & MODE_PARSE_SET) { modebuf_extract(mbuf, modestr + 1); /* for sending BURST onward */ modestr[0] = modestr[1] ? ' ' : '\0'; } else modestr[0] = '\0'; sendcmdto_serv_butone(sptr, CMD_BURST, cptr, "%H %Tu%s%s%s", chptr, chptr->creationtime, modestr, nickstr, banstr); if (parse_flags & MODE_PARSE_WIPEOUT || banpos) mode_ban_invalidate(chptr); if (parse_flags & MODE_PARSE_SET) { /* any modes changed? */ /* first deal with channel members */ for (member = chptr->members; member; member = member->next_member) { if (member->status & CHFL_BURST_JOINED) { /* joined during burst */ if ((member->status & CHFL_CHANOP) && !(member->status & CHFL_BURST_ALREADY_OPPED)) modebuf_mode_client(mbuf, MODE_ADD | CHFL_CHANOP, member->user, OpLevel(member)); if ((member->status & CHFL_VOICE) && !(member->status & CHFL_BURST_ALREADY_VOICED)) modebuf_mode_client(mbuf, MODE_ADD | CHFL_VOICE, member->user, OpLevel(member)); } else if (parse_flags & MODE_PARSE_WIPEOUT) { /* wipeout old ops */ if (member->status & CHFL_CHANOP) modebuf_mode_client(mbuf, MODE_DEL | CHFL_CHANOP, member->user, OpLevel(member)); if (member->status & CHFL_VOICE) modebuf_mode_client(mbuf, MODE_DEL | CHFL_VOICE, member->user, OpLevel(member)); member->status = (member->status & ~(CHFL_CHANNEL_MANAGER | CHFL_CHANOP | CHFL_VOICE)) | CHFL_DEOPPED; } } /* Now deal with channel bans */ lp_p = &chptr->banlist; while (*lp_p) { lp = *lp_p; /* remove ban from channel */ if (lp->flags & (BAN_OVERLAPPED | BAN_BURST_WIPEOUT)) { char *bandup; DupString(bandup, lp->banstr); modebuf_mode_string(mbuf, MODE_DEL | MODE_BAN, bandup, 1); *lp_p = lp->next; /* clip out of list */ free_ban(lp); continue; } else if (lp->flags & BAN_BURSTED) /* add ban to channel */ modebuf_mode_string(mbuf, MODE_ADD | MODE_BAN, lp->banstr, 0); /* don't free banstr */ lp->flags &= BAN_IPMASK; /* reset the flag */ lp_p = &(*lp_p)->next; } } return mbuf ? modebuf_flush(mbuf) : 0; }
void relay_directed_message(struct Client* sptr, char* name, char* server, const char* text) { struct Client* acptr; char* host; assert(0 != sptr); assert(0 != name); assert(0 != text); assert(0 != server); if (0 == (acptr = FindServer(server + 1))) { send_reply(sptr, ERR_NOSUCHNICK, name); return; } /* * NICK[%host]@server addressed? See if <server> is me first */ if (!IsMe(acptr)) { sendcmdto_one(sptr, CMD_PRIVATE, acptr, "%s :%s", name, text); return; } /* * Look for an user whose NICK is equal to <name> and then * check if it's hostname matches <host> and if it's a local * user. */ *server = '\0'; if ((host = strchr(name, '%'))) *host++ = '\0'; /* As reported by Vampire-, it's possible to brute force finding users * by sending a message to each server and see which one succeeded. * This means we have to remove error reporting. Sigh. Better than * removing the ability to send directed messages to client servers * Thanks for the suggestion Vampire=. -- Isomer 2001-08-28 * Argh, /ping nick@server, disallow messages to non +k clients :/ I hate * this. -- Isomer 2001-09-16 */ if (!(acptr = FindUser(name)) || !MyUser(acptr) || (!EmptyString(host) && 0 != match(host, cli_user(acptr)->realhost)) || !IsChannelService(acptr)) { #if 0 send_reply(sptr, ERR_NOSUCHNICK, name); #endif return; } *server = '@'; if (host) *--host = '%'; if (!IsChannelService(sptr) && is_silenced(sptr, acptr)) { send_reply(sptr, ERR_SILENCED, cli_name(acptr)); return; } if (IsOnlyreg(acptr) && !IsRegnick(sptr)) send_reply(sptr, RPL_MSGONLYREG, cli_name(acptr)); else sendcmdto_one(sptr, CMD_PRIVATE, acptr, "%s :%s", name, text); }