*
* $Id$
*/
+#include "config.h"
+
#include "s_user.h"
#include "IPcheck.h"
#include "channel.h"
#include "class.h"
#include "client.h"
-#include "gline.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_chattr.h"
#include "ircd_features.h"
#include "ircd_log.h"
+#include "ircd_policy.h"
#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "match.h"
#include "s_misc.h"
#include "s_serv.h" /* max_client_count */
#include "send.h"
-#include "sprintf_irc.h"
#include "struct.h"
#include "support.h"
#include "supported.h"
*bytes_out = userCount * sizeof(struct User);
}
-/*
- * user_set_away - set user away state
- * returns 1 if client is away or changed away message, 0 if
- * client is removing away status.
- * NOTE: this function may modify user and message, so they
- * must be mutable.
- */
-int user_set_away(struct User* user, char* message)
-{
- char* away;
- assert(0 != user);
-
- away = user->away;
-
- if (EmptyString(message)) {
- /*
- * Marking as not away
- */
- if (away) {
- MyFree(away);
- user->away = 0;
- }
- }
- else {
- /*
- * Marking as away
- */
- unsigned int len = strlen(message);
-
- if (len > TOPICLEN) {
- message[TOPICLEN] = '\0';
- len = TOPICLEN;
- }
- if (away)
- away = (char*) MyRealloc(away, len + 1);
- else
- away = (char*) MyMalloc(len + 1);
- assert(0 != away);
-
- user->away = away;
- strcpy(away, message);
- }
- return (user->away != 0);
-}
/*
* next_client
if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
return (HUNTED_ISME);
+ if (MustBeOper && !IsPrivileged(from))
+ {
+ send_reply(from, ERR_NOPRIVILEGES);
+ return HUNTED_NOSUCH;
+ }
+
/* Make sure it's a server */
if (MyUser(from)) {
/* Make sure it's a server */
return (HUNTED_PASS);
}
+int hunt_server_prio_cmd(struct Client *from, const char *cmd, const char *tok,
+ struct Client *one, int MustBeOper,
+ const char *pattern, int server, int parc,
+ char *parv[])
+{
+ struct Client *acptr;
+ char *to;
+
+ /* Assume it's me, if no server or an unregistered client */
+ if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
+ return (HUNTED_ISME);
+
+ /* Make sure it's a server */
+ if (MyUser(from)) {
+ /* Make sure it's a server */
+ if (!strchr(to, '*')) {
+ if (0 == (acptr = FindClient(to)))
+ return HUNTED_NOSUCH;
+
+ if (cli_user(acptr))
+ acptr = cli_user(acptr)->server;
+ } else if (!(acptr = find_match_server(to))) {
+ send_reply(from, ERR_NOSUCHSERVER, to);
+ return (HUNTED_NOSUCH);
+ }
+ } else if (!(acptr = FindNServer(to)))
+ return (HUNTED_NOSUCH); /* Server broke off in the meantime */
+
+ if (IsMe(acptr))
+ return (HUNTED_ISME);
+
+ if (MustBeOper && !IsPrivileged(from)) {
+ send_reply(from, ERR_NOPRIVILEGES);
+ return HUNTED_NOSUCH;
+ }
+
+ assert(!IsServer(from));
+
+ parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
+
+ sendcmdto_prio_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3],
+ parv[4], parv[5], parv[6], parv[7], parv[8]);
+
+ return (HUNTED_PASS);
+}
+
/*
* 'do_nick_name' ensures that the given parameter (nick) is really a proper
* string for a nickname (note, the 'nick' may be modified in the process...)
* nick from local user or kill him/her...
*/
int register_user(struct Client *cptr, struct Client *sptr,
- const char *nick, char *username, struct Gline *agline)
+ const char *nick, char *username)
{
struct ConfItem* aconf;
char* parv[3];
short digitgroups = 0;
struct User* user = cli_user(sptr);
char ip_base64[8];
- char featurebuf[512];
user->last = CurrentTime;
parv[0] = cli_name(sptr);
{
last_too_many1 = CurrentTime;
sendto_opmask_butone(0, SNO_TOOMANY, "Too many connections in "
- "class for %s.",
- get_client_name(sptr, HIDE_IP));
+ "class %i for %s.", get_client_class(sptr),
+ get_client_name(sptr, SHOW_IP));
}
++ServerStats->is_ref;
IPcheck_connect_fail(cli_ip(sptr));
last_too_many2 = CurrentTime;
sendto_opmask_butone(0, SNO_TOOMANY, "Too many connections from "
"same IP for %s.",
- get_client_name(sptr, HIDE_IP));
+ get_client_name(sptr, SHOW_IP));
}
++ServerStats->is_ref;
return exit_client(cptr, sptr, &me,
return exit_client(cptr, sptr, &me, "Unknown error -- Try again");
}
ircd_strncpy(user->host, cli_sockhost(sptr), HOSTLEN);
+ ircd_strncpy(user->realhost, cli_sockhost(sptr), HOSTLEN);
aconf = cli_confs(sptr)->value.aconf;
clean_user_id(user->username,
}
SetUser(sptr);
- /* a gline wasn't passed in, so find a matching global one that isn't
- * a Uworld-set one, and propagate it if there is such an animal.
- */
- if (!agline &&
- (agline = gline_lookup(sptr, GLINE_GLOBAL | GLINE_LASTMOD)) &&
- !IsBurstOrBurstAck(cptr))
- gline_resend(cptr, agline);
-
if (IsInvisible(sptr))
++UserStats.inv_clients;
if (IsOper(sptr))
send_reply(sptr, RPL_YOURHOST, cli_name(&me), version);
send_reply(sptr, RPL_CREATED, creation);
send_reply(sptr, RPL_MYINFO, cli_name(&me), version);
- sprintf_irc(featurebuf,FEATURES,FEATURESVALUES);
- send_reply(sptr, RPL_ISUPPORT, featurebuf);
+ send_supported(sptr);
m_lusers(sptr, sptr, 1, parv);
update_load();
motd_signon(sptr);
- nextping = CurrentTime;
+/* nextping = CurrentTime; */
if (cli_snomask(sptr) & SNO_NOISY)
set_snomask(sptr, cli_snomask(sptr) & SNO_NOISY, SNO_ADD);
IPcheck_connect_succeeded(sptr);
}
}
tmpstr = umode_str(sptr);
- if (agline)
- sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
- "%s %d %Tu %s %s %s%s%s%%%Tu:%s@%s %s %s%s :%s",
- nick, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
- user->username, user->host,
- *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
- GlineLastMod(agline), GlineUser(agline),
- GlineHost(agline),
- inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
- NumNick(sptr), cli_info(sptr));
- else
- sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
- "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
- nick, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
- user->username, user->host,
- *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
- inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
- NumNick(sptr), cli_info(sptr));
+ sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
+ "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
+ nick, cli_hopcount(sptr) + 1, cli_lastnick(sptr),
+ user->username, user->realhost,
+ *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
+ inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
+ NumNick(sptr), cli_info(sptr));
/* Send umode to client */
if (MyUser(sptr))
{ FLAGS_SERVNOTICE, 's' },
{ FLAGS_DEAF, 'd' },
{ FLAGS_CHSERV, 'k' },
- { FLAGS_DEBUG, 'g' }
+ { FLAGS_DEBUG, 'g' },
+ { FLAGS_ACCOUNT, 'r' },
+ { FLAGS_HIDDENHOST, 'x' }
};
#define USERMODELIST_SIZE sizeof(userModeList) / sizeof(struct UserMode)
{
if (IsServer(sptr)) {
int i;
+ const char* account = 0;
const char* p;
- char *t;
- struct Gline *agline = 0;
/*
* A server introducing a new client, change source
for (i = 0; i < USERMODELIST_SIZE; ++i) {
if (userModeList[i].c == *p) {
cli_flags(new_client) |= userModeList[i].flag;
+ if (userModeList[i].flag & FLAGS_ACCOUNT)
+ account = parv[7];
break;
}
}
cli_serv(sptr)->ghost = 0; /* :server NICK means end of net.burst */
ircd_strncpy(cli_username(new_client), parv[4], USERLEN);
ircd_strncpy(cli_user(new_client)->host, parv[5], HOSTLEN);
+ ircd_strncpy(cli_user(new_client)->realhost, parv[5], HOSTLEN);
ircd_strncpy(cli_info(new_client), parv[parc - 1], REALLEN);
+ if (account)
+ ircd_strncpy(cli_user(new_client)->account, account, ACCOUNTLEN);
+ if (HasHiddenHost(new_client))
+ ircd_snprintf(0, cli_user(new_client)->host, HOSTLEN, "%s.%s",
+ account, feature_str(FEAT_HIDDEN_HOST));
- /* Deal with GLINE parameters... */
- if (*parv[parc - 4] == '%' && (t = strchr(parv[parc - 4] + 1, ':'))) {
- time_t lastmod;
-
- *(t++) = '\0';
- lastmod = atoi(parv[parc - 4] + 1);
-
- if (lastmod &&
- (agline = gline_find(t, GLINE_EXACT | GLINE_GLOBAL | GLINE_LASTMOD))
- && GlineLastMod(agline) > lastmod && !IsBurstOrBurstAck(cptr))
- gline_resend(cptr, agline);
- }
- return register_user(cptr, new_client, cli_name(new_client), parv[4], agline);
+ return register_user(cptr, new_client, cli_name(new_client), parv[4]);
}
else if ((cli_name(sptr))[0]) {
/*
* on that channel. Propagate notice to other servers.
*/
if (IsUser(sptr)) {
- sendcmdto_common_channels(sptr, CMD_NICK, ":%s", nick);
+ sendcmdto_common_channels_butone(sptr, CMD_NICK, NULL, ":%s", nick);
add_history(sptr, 1);
sendcmdto_serv_butone(sptr, CMD_NICK, cptr, "%s %Tu", nick,
cli_lastnick(sptr));
* for it - must test this and exit m_nick too !
*/
cli_lastnick(sptr) = TStime(); /* Always local client */
- if (register_user(cptr, sptr, nick, cli_user(sptr)->username, 0) == CPTR_KILLED)
+ if (register_user(cptr, sptr, nick, cli_user(sptr)->username) == CPTR_KILLED)
return CPTR_KILLED;
}
}
msgq_clean(mb);
}
+/*
+ * hide_hostmask()
+ *
+ * If, after setting the flags, the user has both HiddenHost and Account
+ * set, its hostmask is changed.
+ */
+#define FLAGS_HOST_HIDDEN (FLAGS_ACCOUNT|FLAGS_HIDDENHOST)
+int hide_hostmask(struct Client *cptr, unsigned int flags)
+{
+ struct Membership *chan;
+ int newflags;
+
+ if (MyConnect(cptr) && !feature_bool(FEAT_HOST_HIDING))
+ flags &= ~FLAGS_HIDDENHOST;
+
+ newflags = cli_flags(cptr) | flags;
+ if ((newflags & FLAGS_HOST_HIDDEN) != FLAGS_HOST_HIDDEN) {
+ /* The user doesn't have both flags, don't change the hostmask */
+ cli_flags(cptr) |= flags;
+ return 0;
+ }
+
+ sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered");
+ ircd_snprintf(0, cli_user(cptr)->host, HOSTLEN, "%s.%s",
+ cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
+ cli_flags(cptr) |= flags;
+
+ /*
+ * Go through all channels the client was on, rejoin him
+ * and set the modes, if any
+ */
+ for (chan = cli_user(cptr)->channel; chan; chan = chan->next_channel) {
+ sendcmdto_channel_butserv_butone(cptr, CMD_JOIN, chan->channel, cptr,
+ "%H", chan->channel);
+ if (IsChanOp(chan) && HasVoice(chan)) {
+ sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr,
+ "%H +ov %C %C", chan->channel, cptr, cptr);
+ } else if (IsChanOp(chan) || HasVoice(chan)) {
+ sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr,
+ "%H +%c %C", chan->channel, IsChanOp(chan) ? 'o' : 'v', cptr);
+ }
+ }
+ return 0;
+}
+
/*
* set_user_mode() added 15/10/91 By Darren Reed.
int snomask_given = 0;
char buf[BUFSIZE];
int prop = 0;
+ int do_host_hiding = 0;
what = MODE_ADD;
if (IsServer(sptr) || sptr != acptr)
{
if (IsServer(cptr))
- sendcmdto_flag_butone(&me, CMD_WALLOPS, 0, FLAGS_WALLOP,
- ":MODE for User %s from %s!%s", parv[1],
+ sendwallto_group_butone(&me, WALL_WALLOPS, 0,
+ "MODE for User %s from %s!%s", parv[1],
cli_name(cptr), cli_name(sptr));
else
send_reply(sptr, ERR_USERSDONTMATCH);
m = buf;
*m++ = '+';
for (i = 0; i < USERMODELIST_SIZE; ++i) {
- if ( (userModeList[i].flag & cli_flags(sptr)))
+ if ((userModeList[i].flag & cli_flags(sptr)) &&
+ !(userModeList[i].flag & FLAGS_ACCOUNT))
*m++ = userModeList[i].c;
}
*m = '\0';
tmpmask = (what == MODE_ADD) ?
(IsAnOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT) : 0;
if (tmpmask)
- cli_flags(sptr) |= FLAGS_SERVNOTICE;
+ SetServNotice(sptr);
else
- cli_flags(sptr) &= ~FLAGS_SERVNOTICE;
+ ClearServNotice(sptr);
break;
case 'w':
if (what == MODE_ADD)
else
ClearDebug(sptr);
break;
+ case 'x':
+ if (what == MODE_ADD)
+ do_host_hiding = 1;
+ break;
default:
break;
}
if (feature_bool(FEAT_WALLOPS_OPER_ONLY) && !IsAnOper(sptr) &&
!(setflags & FLAGS_WALLOP))
ClearWallops(sptr);
+#ifdef SERVNOTICE_OPER_ONLY
+ if (MyConnect(sptr) && !IsAnOper(sptr) && !(setflags & FLAGS_SERVNOTICE)) {
+ ClearServNotice(sptr);
+ set_snomask(sptr, 0, SNO_SET);
+ }
+#endif
+#ifdef DEBUG_OPER_ONLY
+ if (!IsAnOper(sptr) && !(setflags & FLAGS_DEBUG))
+ ClearDebug(sptr);
+#endif
}
if (MyConnect(sptr)) {
if ((setflags & (FLAGS_OPER | FLAGS_LOCOP)) && !IsAnOper(sptr))
det_confs_butmask(sptr, CONF_CLIENT & ~CONF_OPS);
- if (tmpmask != cli_snomask(sptr))
- set_snomask(sptr, tmpmask, SNO_SET);
- if (cli_snomask(sptr) && snomask_given)
- send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
+ if (SendServNotice(sptr)) {
+ if (tmpmask != cli_snomask(sptr))
+ set_snomask(sptr, tmpmask, SNO_SET);
+ if (cli_snomask(sptr) && snomask_given)
+ send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
+ } else
+ set_snomask(sptr, 0, SNO_SET);
}
/*
* Compare new flags with old flags and send string which
--UserStats.inv_clients;
if (!(setflags & FLAGS_INVISIBLE) && IsInvisible(sptr))
++UserStats.inv_clients;
+ if (!(setflags & FLAGS_HIDDENHOST) && do_host_hiding)
+ hide_hostmask(sptr, FLAGS_HIDDENHOST);
send_umode_out(cptr, sptr, setflags, prop);
return 0;
if ( (c_flags & userModeList[i].flag))
*m++ = userModeList[i].c;
}
+
+ if (IsAccount(cptr)) {
+ char* t = cli_user(cptr)->account;
+
+ *m++ = ' ';
+ while ((*m++ = *t++))
+ ; /* Empty loop */
+ }
+
*m = '\0';
return umodeBuf; /* Note: static buffer, gets
struct User *user;
static char sender[HOSTLEN + NICKLEN + USERLEN + 5];
static char senderip[16 + NICKLEN + USERLEN + 5];
+ static char senderh[HOSTLEN + ACCOUNTLEN + USERLEN + 6];
if (!cli_user(acptr) || !(lp = cli_user(acptr)->silence) || !(user = cli_user(sptr)))
return 0;
- sprintf_irc(sender, "%s!%s@%s", cli_name(sptr), user->username, user->host);
- sprintf_irc(senderip, "%s!%s@%s", cli_name(sptr), user->username,
- ircd_ntoa((const char*) &(cli_ip(sptr))));
+ ircd_snprintf(0, sender, sizeof(sender), "%s!%s@%s", cli_name(sptr),
+ user->username, user->host);
+ ircd_snprintf(0, senderip, sizeof(senderip), "%s!%s@%s", cli_name(sptr),
+ user->username, ircd_ntoa((const char*) &(cli_ip(sptr))));
+ if (HasHiddenHost(sptr))
+ ircd_snprintf(0, senderh, sizeof(senderh), "%s!%s@%s", cli_name(sptr),
+ user->username, user->realhost);
for (; lp; lp = lp->next)
{
- if ((!(lp->flags & CHFL_SILENCE_IPMASK) && !match(lp->value.cp, sender)) ||
+ if ((!(lp->flags & CHFL_SILENCE_IPMASK) && (!match(lp->value.cp, sender) ||
+ (HasHiddenHost(sptr) && !match(lp->value.cp, senderh)))) ||
((lp->flags & CHFL_SILENCE_IPMASK) && !match(lp->value.cp, senderip)))
{
if (!MyConnect(sptr))
return 0;
}
+int
+send_supported(struct Client *cptr)
+{
+ char featurebuf[512];
+
+ ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES1, FEATURESVALUES1);
+ send_reply(cptr, RPL_ISUPPORT, featurebuf);
+ ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES2, FEATURESVALUES2);
+ send_reply(cptr, RPL_ISUPPORT, featurebuf);
+
+ return 0; /* convenience return, if it's ever needed */
+}