*
* $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 "motd.h"
#include "msg.h"
+#include "msgq.h"
#include "numeric.h"
#include "numnicks.h"
#include "parse.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"
{
assert(0 != cptr);
- if (!cptr->user) {
- cptr->user = (struct User*) MyMalloc(sizeof(struct User));
- assert(0 != cptr->user);
+ if (!cli_user(cptr)) {
+ cli_user(cptr) = (struct User*) MyMalloc(sizeof(struct User));
+ assert(0 != cli_user(cptr));
/* All variables are 0 by default */
- memset(cptr->user, 0, sizeof(struct User));
+ memset(cli_user(cptr), 0, sizeof(struct User));
#ifdef DEBUGMODE
++userCount;
#endif
- cptr->user->refcnt = 1;
+ cli_user(cptr)->refcnt = 1;
}
- return cptr->user;
+ return cli_user(cptr);
}
/*
*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
next = FindClient(ch);
next = next ? next : tmp;
- if (tmp->prev == next)
+ if (cli_prev(tmp) == next)
return NULL;
if (next != tmp)
return next;
- for (; next; next = next->next)
- if (!match(ch, next->name))
+ for (; next; next = cli_next(next))
+ if (!match(ch, cli_name(next)))
break;
return next;
}
*
* returns: (see #defines)
*/
-int hunt_server(int MustBeOper, struct Client *cptr, struct Client *sptr, char *command,
- int server, int parc, char *parv[])
+int hunt_server_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 y[8];
+ char *to;
/* Assume it's me, if no server or an unregistered client */
- if (parc <= server || EmptyString(parv[server]) || IsUnknown(sptr))
+ if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
return (HUNTED_ISME);
/* Make sure it's a server */
- if (MyUser(sptr) || Protocol(cptr) < 10)
- {
+ if (MyUser(from)) {
/* Make sure it's a server */
- if (!strchr(parv[server], '*')) {
- if (0 == (acptr = FindClient(parv[server])))
+ if (!strchr(to, '*')) {
+ if (0 == (acptr = FindClient(to)))
return HUNTED_NOSUCH;
- if (acptr->user)
- acptr = acptr->user->server;
- }
- else if (!(acptr = find_match_server(parv[server])))
- {
- send_reply(sptr, ERR_NOSUCHSERVER, parv[server]);
+
+ 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(parv[server])))
+ } else if (!(acptr = FindNServer(to)))
return (HUNTED_NOSUCH); /* Server broke off in the meantime */
if (IsMe(acptr))
return (HUNTED_ISME);
- if (MustBeOper && !IsPrivileged(sptr))
- {
- send_reply(sptr, ERR_NOPRIVILEGES);
+ if (MustBeOper && !IsPrivileged(from)) {
+ send_reply(from, ERR_NOPRIVILEGES);
return HUNTED_NOSUCH;
}
- strcpy(y, acptr->yxx);
- parv[server] = y;
+ assert(!IsServer(from));
- assert(!IsServer(sptr));
- /* XXX sendto_one used with explicit command; must be very careful */
- sendto_one(acptr, command, NumNick(sptr), parv[1], parv[2], parv[3], parv[4], /* XXX hunt_server */
- parv[5], parv[6], parv[7], parv[8]);
+ parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
+
+ sendcmdto_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);
}
-int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok,
- struct Client *one, int MustBeOper, const char *pattern,
- int server, int parc, char *parv[])
+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;
if (0 == (acptr = FindClient(to)))
return HUNTED_NOSUCH;
- if (acptr->user)
- acptr = acptr->user->server;
+ 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);
parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
- sendcmdto_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3],
- parv[4], parv[5], parv[6], parv[7], parv[8]);
+ 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);
}
* 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 digits = 0;
short badid = 0;
short digitgroups = 0;
- struct User* user = sptr->user;
+ struct User* user = cli_user(sptr);
char ip_base64[8];
- char featurebuf[512];
user->last = CurrentTime;
- parv[0] = sptr->name;
+ parv[0] = cli_name(sptr);
parv[1] = parv[2] = NULL;
if (MyConnect(sptr))
break;
case ACR_NO_AUTHORIZATION:
sendto_opmask_butone(0, SNO_UNAUTH, "Unauthorized connection from %s.",
- get_client_name(sptr, HIDE_IP));
+ get_client_name(sptr, HIDE_IP));
++ServerStats->is_ref;
return exit_client(cptr, sptr, &me,
- "No Authorization - use another server");
+ "No Authorization - use another server");
case ACR_TOO_MANY_IN_CLASS:
if (CurrentTime - last_too_many1 >= (time_t) 60)
{
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));
return exit_client(cptr, sptr, &me,
- "Sorry, your connection class is full - try "
- "again later or try another server");
+ "Sorry, your connection class is full - try "
+ "again later or try another server");
case ACR_TOO_MANY_FROM_IP:
if (CurrentTime - last_too_many2 >= (time_t) 60)
{
last_too_many2 = CurrentTime;
sendto_opmask_butone(0, SNO_TOOMANY, "Too many connections from "
- "same IP for %s.",
- get_client_name(sptr, HIDE_IP));
+ "same IP for %s.",
+ get_client_name(sptr, SHOW_IP));
}
++ServerStats->is_ref;
return exit_client(cptr, sptr, &me,
- "Too many connections from your host");
+ "Too many connections from your host");
case ACR_ALREADY_AUTHORIZED:
/* Can this ever happen? */
case ACR_BAD_SOCKET:
++ServerStats->is_ref;
+ IPcheck_connect_fail(cli_ip(sptr));
return exit_client(cptr, sptr, &me, "Unknown error -- Try again");
}
- ircd_strncpy(user->host, sptr->sockhost, HOSTLEN);
- aconf = sptr->confs->value.aconf;
+ ircd_strncpy(user->host, cli_sockhost(sptr), HOSTLEN);
+ aconf = cli_confs(sptr)->value.aconf;
clean_user_id(user->username,
- (sptr->flags & FLAGS_GOTID) ? sptr->username : username,
- (sptr->flags & FLAGS_DOID) && !(sptr->flags & FLAGS_GOTID));
+ (cli_flags(sptr) & FLAGS_GOTID) ? cli_username(sptr) : username,
+ (cli_flags(sptr) & FLAGS_DOID) && !(cli_flags(sptr) & FLAGS_GOTID));
if ((user->username[0] == '\0')
|| ((user->username[0] == '~') && (user->username[1] == '\000')))
if (!EmptyString(aconf->passwd)
&& !(IsDigit(*aconf->passwd) && !aconf->passwd[1])
- && strcmp(sptr->passwd, aconf->passwd))
+ && strcmp(cli_passwd(sptr), aconf->passwd))
{
ServerStats->is_ref++;
+ IPcheck_connect_fail(cli_ip(sptr));
send_reply(sptr, ERR_PASSWDMISMATCH);
return exit_client(cptr, sptr, &me, "Bad Password");
}
- memset(sptr->passwd, 0, sizeof(sptr->passwd));
+ memset(cli_passwd(sptr), 0, sizeof(cli_passwd(sptr)));
/*
* following block for the benefit of time-dependent K:-lines
*/
if (find_kill(sptr)) {
ServerStats->is_ref++;
+ IPcheck_connect_fail(cli_ip(sptr));
return exit_client(cptr, sptr, &me, "K-lined");
}
/*
else if ((!lower && !upper) || !IsAlnum(c))
badid = 1;
}
- if (badid && (!(sptr->flags & FLAGS_GOTID) ||
- strcmp(sptr->username, username) != 0))
+ if (badid && (!(cli_flags(sptr) & FLAGS_GOTID) ||
+ strcmp(cli_username(sptr), username) != 0))
{
ServerStats->is_ref++;
send_reply(cptr, SND_EXPLICIT | ERR_INVALIDUSERNAME,
- ":Your username is invalid.");
+ ":Your username is invalid.");
send_reply(cptr, SND_EXPLICIT | ERR_INVALIDUSERNAME,
- ":Connect with your real username, in lowercase.");
+ ":Connect with your real username, in lowercase.");
send_reply(cptr, SND_EXPLICIT | ERR_INVALIDUSERNAME,
- ":If your mail address were foo@bar.com, your username "
- "would be foo.");
+ ":If your mail address were foo@bar.com, your username "
+ "would be foo.");
return exit_client(cptr, sptr, &me, "USER: Bad username");
}
Count_unknownbecomesclient(sptr, UserStats);
}
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))
++UserStats.opers;
if (MyConnect(sptr)) {
- sptr->handler = CLIENT_HANDLER;
+ cli_handler(sptr) = CLIENT_HANDLER;
release_dns_reply(sptr);
send_reply(sptr, RPL_WELCOME, nick);
/*
* This is a duplicate of the NOTICE but see below...
*/
- send_reply(sptr, RPL_YOURHOST, me.name, version);
+ send_reply(sptr, RPL_YOURHOST, cli_name(&me), version);
send_reply(sptr, RPL_CREATED, creation);
- send_reply(sptr, RPL_MYINFO, me.name, version);
- sprintf_irc(featurebuf,FEATURES,FEATURESVALUES);
- send_reply(sptr, RPL_ISUPPORT, featurebuf);
+ send_reply(sptr, RPL_MYINFO, cli_name(&me), version);
+ send_supported(sptr);
m_lusers(sptr, sptr, 1, parv);
update_load();
-#ifdef NODEFAULTMOTD
- m_motd(sptr, NULL, 1, parv);
-#else
- m_motd(sptr, sptr, 1, parv);
-#endif
- nextping = CurrentTime;
- if (sptr->snomask & SNO_NOISY)
- set_snomask(sptr, sptr->snomask & SNO_NOISY, SNO_ADD);
+ motd_signon(sptr);
+/* nextping = CurrentTime; */
+ if (cli_snomask(sptr) & SNO_NOISY)
+ set_snomask(sptr, cli_snomask(sptr) & SNO_NOISY, SNO_ADD);
+ IPcheck_connect_succeeded(sptr);
}
else
/* if (IsServer(cptr)) */
struct Client *acptr;
acptr = user->server;
- if (acptr->from != sptr->from)
+ if (cli_from(acptr) != cli_from(sptr))
{
sendcmdto_one(&me, CMD_KILL, cptr, "%C :%s (%s != %s[%s])",
- sptr, me.name, user->server->name, acptr->from->name,
- acptr->from->sockhost);
- sptr->flags |= FLAGS_KILLED;
+ sptr, cli_name(&me), cli_name(user->server), cli_name(cli_from(acptr)),
+ cli_sockhost(cli_from(acptr)));
+ cli_flags(sptr) |= FLAGS_KILLED;
return exit_client(cptr, sptr, &me, "NICK server wrong direction");
}
else
- sptr->flags |= (acptr->flags & FLAGS_TS8);
+ cli_flags(sptr) |= (cli_flags(acptr) & FLAGS_TS8);
/*
* Check to see if this user is being propogated
* FIXME: This can be speeded up - its stupid to check it for
* every NICK message in a burst again --Run.
*/
- for (acptr = user->server; acptr != &me; acptr = acptr->serv->up) {
+ for (acptr = user->server; acptr != &me; acptr = cli_serv(acptr)->up) {
if (IsBurst(acptr) || Protocol(acptr) < 10)
break;
}
+ if (!IPcheck_remote_connect(sptr, (acptr != &me))) {
+ /*
+ * We ran out of bits to count this
+ */
+ sendcmdto_one(&me, CMD_KILL, sptr, "%C :%s (Too many connections from your host -- Ghost)",
+ sptr, cli_name(&me));
+ return exit_client(cptr, sptr, &me,"Too many connections from your host -- throttled");
+ }
}
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, sptr->hopcount + 1, sptr->lastnick,
- user->username, user->host,
- *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
- GlineLastMod(agline), GlineUser(agline),
- GlineHost(agline),
- inttobase64(ip_base64, ntohl(sptr->ip.s_addr), 6),
- NumNick(sptr), sptr->info);
- else
- sendcmdto_serv_butone(user->server, CMD_NICK, cptr,
- "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
- nick, sptr->hopcount + 1, sptr->lastnick,
- user->username, user->host,
- *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
- inttobase64(ip_base64, ntohl(sptr->ip.s_addr), 6),
- NumNick(sptr), sptr->info);
+ 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));
/* Send umode to client */
if (MyUser(sptr))
{
send_umode(cptr, sptr, 0, ALL_UMODES);
- if (sptr->snomask != SNO_DEFAULT && (sptr->flags & FLAGS_SERVNOTICE))
- send_reply(sptr, RPL_SNOMASK, sptr->snomask, sptr->snomask);
+ if (cli_snomask(sptr) != SNO_DEFAULT && (cli_flags(sptr) & FLAGS_SERVNOTICE))
+ send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
}
return 0;
#define USERMODELIST_SIZE sizeof(userModeList) / sizeof(struct UserMode)
-#if 0
-static int user_modes[] = {
- FLAGS_OPER, 'o',
- FLAGS_LOCOP, 'O',
- FLAGS_INVISIBLE, 'i',
- FLAGS_WALLOP, 'w',
- FLAGS_SERVNOTICE, 's',
- FLAGS_DEAF, 'd',
- FLAGS_CHSERV, 'k',
- FLAGS_DEBUG, 'g',
- 0, 0
-};
-#endif
-
/*
* XXX - find a way to get rid of this
*/
if (IsServer(sptr)) {
int i;
const char* p;
- char *t;
- struct Gline *agline = 0;
/*
* A server introducing a new client, change source
struct Client* new_client = make_client(cptr, STAT_UNKNOWN);
assert(0 != new_client);
- new_client->hopcount = atoi(parv[2]);
- new_client->lastnick = atoi(parv[3]);
+ cli_hopcount(new_client) = atoi(parv[2]);
+ cli_lastnick(new_client) = atoi(parv[3]);
if (Protocol(cptr) > 9 && parc > 7 && *parv[6] == '+') {
for (p = parv[6] + 1; *p; p++) {
for (i = 0; i < USERMODELIST_SIZE; ++i) {
if (userModeList[i].c == *p) {
- new_client->flags |= userModeList[i].flag;
+ cli_flags(new_client) |= userModeList[i].flag;
break;
}
}
}
}
+ client_set_privs(new_client); /* set privs on user */
/*
* Set new nick name.
*/
- strcpy(new_client->name, nick);
- new_client->user = make_user(new_client);
- new_client->user->server = sptr;
+ strcpy(cli_name(new_client), nick);
+ cli_user(new_client) = make_user(new_client);
+ cli_user(new_client)->server = sptr;
SetRemoteNumNick(new_client, parv[parc - 2]);
/*
* IP# of remote client
*/
- new_client->ip.s_addr = htonl(base64toint(parv[parc - 3]));
+ cli_ip(new_client).s_addr = htonl(base64toint(parv[parc - 3]));
add_client_to_list(new_client);
hAddClient(new_client);
- sptr->serv->ghost = 0; /* :server NICK means end of net.burst */
- ircd_strncpy(new_client->username, parv[4], USERLEN);
- ircd_strncpy(new_client->user->host, parv[5], HOSTLEN);
- ircd_strncpy(new_client->info, parv[parc - 1], REALLEN);
-
- /* 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);
+ 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_info(new_client), parv[parc - 1], REALLEN);
- if (lastmod &&
- (agline = gline_find(t, GLINE_EXACT | GLINE_GLOBAL | GLINE_LASTMOD))
- && GlineLastMod(agline) > lastmod && !IsBurstOrBurstAck(cptr))
- gline_resend(cptr, agline);
- }
- if (!ip_registry_remote_connect(new_client)) {
- sendcmdto_one(&me, CMD_KILL, new_client, "%C :%s (Too many connections from your host -- Ghost)",
- new_client,me.name);
- return exit_client(cptr,new_client,&me,"Too many connections from your host -- throttled");
- }
- sendto_ops("Registering new remote client");
- return register_user(cptr, new_client, new_client->name, parv[4], agline);
+ return register_user(cptr, new_client, cli_name(new_client), parv[4]);
}
- else if (sptr->name[0]) {
+ else if ((cli_name(sptr))[0]) {
/*
* Client changing its nick
*
if (MyUser(sptr)) {
const char* channel_name;
if ((channel_name = find_no_nickchange_channel(sptr))) {
- return send_reply(cptr, ERR_BANNICKCHANGE, channel_name);
+ return send_reply(cptr, ERR_BANNICKCHANGE, channel_name);
}
/*
* Refuse nick change if the last nick change was less
* however, allow to do two nick changes immedately after another
* before limiting the nick flood. -Run
*/
- if (CurrentTime < cptr->nextnick) {
- cptr->nextnick += 2;
- send_reply(cptr, ERR_NICKTOOFAST, parv[1],
- cptr->nextnick - CurrentTime);
+ if (CurrentTime < cli_nextnick(cptr)) {
+ cli_nextnick(cptr) += 2;
+ send_reply(cptr, ERR_NICKTOOFAST, parv[1],
+ cli_nextnick(cptr) - CurrentTime);
/* Send error message */
- sendcmdto_one(cptr, CMD_NICK, cptr, "%s", cptr->name);
+ sendcmdto_one(cptr, CMD_NICK, cptr, "%s", cli_name(cptr));
/* bounce NICK to user */
return 0; /* ignore nick change! */
}
else {
/* Limit total to 1 change per NICK_DELAY seconds: */
- cptr->nextnick += NICK_DELAY;
+ cli_nextnick(cptr) += NICK_DELAY;
/* However allow _maximal_ 1 extra consecutive nick change: */
- if (cptr->nextnick < CurrentTime)
- cptr->nextnick = CurrentTime;
+ if (cli_nextnick(cptr) < CurrentTime)
+ cli_nextnick(cptr) = CurrentTime;
}
}
/*
* Also set 'lastnick' to current time, if changed.
*/
if (0 != ircd_strcmp(parv[0], nick))
- sptr->lastnick = (sptr == cptr) ? TStime() : atoi(parv[2]);
+ cli_lastnick(sptr) = (sptr == cptr) ? TStime() : atoi(parv[2]);
/*
* Client just changing his/her nick. If he/she is
sendcmdto_common_channels(sptr, CMD_NICK, ":%s", nick);
add_history(sptr, 1);
sendcmdto_serv_butone(sptr, CMD_NICK, cptr, "%s %Tu", nick,
- sptr->lastnick);
+ cli_lastnick(sptr));
}
else
sendcmdto_one(sptr, CMD_NICK, sptr, ":%s", nick);
- if (sptr->name[0])
+ if ((cli_name(sptr))[0])
hRemClient(sptr);
- strcpy(sptr->name, nick);
+ strcpy(cli_name(sptr), nick);
hAddClient(sptr);
}
else {
/* Local client setting NICK the first time */
- strcpy(sptr->name, nick);
- if (!sptr->user) {
- sptr->user = make_user(sptr);
- sptr->user->server = &me;
+ strcpy(cli_name(sptr), nick);
+ if (!cli_user(sptr)) {
+ cli_user(sptr) = make_user(sptr);
+ cli_user(sptr)->server = &me;
}
SetLocalNumNick(sptr);
hAddClient(sptr);
* If the client hasn't gotten a cookie-ping yet,
* choose a cookie and send it. -record!jegelhof@cloud9.net
*/
- if (!sptr->cookie) {
+ if (!cli_cookie(sptr)) {
do {
- sptr->cookie = (ircrandom() & 0x7fffffff);
- } while (!sptr->cookie);
- sendrawto_one(cptr, MSG_PING " :%u", sptr->cookie);
+ cli_cookie(sptr) = (ircrandom() & 0x7fffffff);
+ } while (!cli_cookie(sptr));
+ sendrawto_one(cptr, MSG_PING " :%u", cli_cookie(sptr));
}
- else if (*sptr->user->host && sptr->cookie == COOKIE_VERIFIED) {
+ else if (*(cli_user(sptr))->host && cli_cookie(sptr) == COOKIE_VERIFIED) {
/*
* USER and PONG already received, now we have NICK.
* register_user may reject the client and call exit_client
* for it - must test this and exit m_nick too !
*/
- sptr->lastnick = TStime(); /* Always local client */
- if (register_user(cptr, sptr, nick, sptr->user->username, 0) == CPTR_KILLED)
+ cli_lastnick(sptr) = TStime(); /* Always local client */
+ if (register_user(cptr, sptr, nick, cli_user(sptr)->username) == CPTR_KILLED)
return CPTR_KILLED;
}
}
*/
void add_target(struct Client *sptr, void *target)
{
- unsigned char hash = hash_target((unsigned int) target);
+ /* Ok, this shouldn't work esp on alpha
+ */
+ unsigned char hash = hash_target((unsigned long) target);
unsigned char* targets;
int i;
assert(0 != sptr);
- assert(sptr->local);
+ assert(cli_local(sptr));
- targets = sptr->targets;
+ targets = cli_targets(sptr);
/*
* Already in table?
*/
int check_target_limit(struct Client *sptr, void *target, const char *name,
int created)
{
- unsigned char hash = hash_target((unsigned int) target);
+ unsigned char hash = hash_target((unsigned long) target);
int i;
unsigned char* targets;
assert(0 != sptr);
- assert(sptr->local);
- targets = sptr->targets;
+ assert(cli_local(sptr));
+ targets = cli_targets(sptr);
/*
* Same target as last time?
* New target
*/
if (!created) {
- if (CurrentTime < sptr->nexttarget) {
- if (sptr->nexttarget - CurrentTime < TARGET_DELAY + 8) {
+ if (CurrentTime < cli_nexttarget(sptr)) {
+ if (cli_nexttarget(sptr) - CurrentTime < TARGET_DELAY + 8) {
/*
* No server flooding
*/
- sptr->nexttarget += 2;
- send_reply(sptr, ERR_TARGETTOOFAST, name,
- sptr->nexttarget - CurrentTime);
+ cli_nexttarget(sptr) += 2;
+ send_reply(sptr, ERR_TARGETTOOFAST, name,
+ cli_nexttarget(sptr) - CurrentTime);
}
return 1;
}
else {
-#ifdef GODMODE
- /* XXX Let's get rid of GODMODE */
- sendto_one(sptr, ":%s NOTICE %s :New target: %s; ft " TIME_T_FMT, /* XXX Possibly DEAD */
- me.name, sptr->name, name, (CurrentTime - sptr->nexttarget) / TARGET_DELAY);
-#endif
- sptr->nexttarget += TARGET_DELAY;
- if (sptr->nexttarget < CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1)))
- sptr->nexttarget = CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1));
+ cli_nexttarget(sptr) += TARGET_DELAY;
+ if (cli_nexttarget(sptr) < CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1)))
+ cli_nexttarget(sptr) = CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1));
}
}
memmove(&targets[1], &targets[0], MAXTARGETS - 1);
* since the link is the same, this should be a little faster for channels
* with a lot of users
*/
- for (membership = source->user->channel; membership; membership = membership->next_channel) {
+ for (membership = cli_user(source)->channel; membership; membership = membership->next_channel) {
if (chptr == membership->channel)
break;
}
/*
* lookup channel in destination
*/
- assert(0 != dest->user);
- for (membership = dest->user->channel; membership; membership = membership->next_channel) {
+ assert(0 != cli_user(dest));
+ for (membership = cli_user(dest)->channel; membership; membership = membership->next_channel) {
if (chptr == membership->channel)
break;
}
if (0 == membership || IsZombie(membership)) {
- return send_reply(source, ERR_USERNOTINCHANNEL, dest->name, chptr->chname);
+ return send_reply(source, ERR_USERNOTINCHANNEL, cli_name(dest), chptr->chname);
}
if (is_silenced(source, dest))
return 0;
- if (dest->user->away)
- send_reply(source, RPL_AWAY, dest->name, dest->user->away);
+ if (cli_user(dest)->away)
+ send_reply(source, RPL_AWAY, cli_name(dest), cli_user(dest)->away);
if (is_notice)
sendcmdto_one(source, CMD_NOTICE, dest, "%C :%s", dest, text);
else
/*
* added Sat Jul 25 07:30:42 EST 1992
*/
-void send_umode_out(struct Client *cptr, struct Client *sptr, int old)
+void send_umode_out(struct Client *cptr, struct Client *sptr, int old,
+ int prop)
{
int i;
struct Client *acptr;
- send_umode(NULL, sptr, old, SEND_UMODES);
+ send_umode(NULL, sptr, old, SEND_UMODES & ~(prop ? 0 : FLAGS_OPER));
for (i = HighestFd; i >= 0; i--) {
if ((acptr = LocalClientArray[i]) && IsServer(acptr) &&
(acptr != cptr) && (acptr != sptr) && *umodeBuf)
- sendcmdto_one(sptr, CMD_MODE, acptr, "%s :%s", sptr->name, umodeBuf);
+ sendcmdto_one(sptr, CMD_MODE, acptr, "%s :%s", cli_name(sptr), umodeBuf);
}
if (cptr && MyUser(cptr))
send_umode(cptr, sptr, old, ALL_UMODES);
*/
void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt)
{
- char* sbuf;
char* name;
char* p = 0;
int arg_count = 0;
int users_found = 0;
struct Client* acptr;
- char buf[BUFSIZE * 2];
+ struct MsgBuf* mb;
assert(0 != sptr);
assert(0 != names);
assert(0 != fmt);
- sbuf = sprintf_irc(buf, rpl_str(rpl), me.name, sptr->name);
+ mb = msgq_make(sptr, rpl_str(rpl), cli_name(&me), cli_name(sptr));
for (name = ircd_strtok(&p, names, " "); name; name = ircd_strtok(&p, 0, " ")) {
if ((acptr = FindUser(name))) {
if (users_found++)
- *sbuf++ = ' ';
- sbuf = (*fmt)(acptr, sbuf);
+ msgq_append(0, mb, " ");
+ (*fmt)(acptr, mb);
}
if (5 == ++arg_count)
break;
}
- if (users_found)
- send_buffer(sptr, buf);
+ send_buffer(sptr, mb, 0);
+ msgq_clean(mb);
}
unsigned int tmpmask = 0;
int snomask_given = 0;
char buf[BUFSIZE];
+ int prop = 0;
what = MODE_ADD;
{
if (IsServer(cptr))
sendcmdto_flag_butone(&me, CMD_WALLOPS, 0, FLAGS_WALLOP,
- ":MODE for User %s from %s!%s", parv[1],
- cptr->name, sptr->name);
+ ":MODE for User %s from %s!%s", parv[1],
+ cli_name(cptr), cli_name(sptr));
else
send_reply(sptr, ERR_USERSDONTMATCH);
return 0;
m = buf;
*m++ = '+';
for (i = 0; i < USERMODELIST_SIZE; ++i) {
- if ( (userModeList[i].flag & sptr->flags))
+ if ( (userModeList[i].flag & cli_flags(sptr)))
*m++ = userModeList[i].c;
}
*m = '\0';
send_reply(sptr, RPL_UMODEIS, buf);
- if ((sptr->flags & FLAGS_SERVNOTICE) && MyConnect(sptr)
- && sptr->snomask !=
+ if ((cli_flags(sptr) & FLAGS_SERVNOTICE) && MyConnect(sptr)
+ && cli_snomask(sptr) !=
(unsigned int)(IsOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT))
- send_reply(sptr, RPL_SNOMASK, sptr->snomask, sptr->snomask);
+ send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
return 0;
}
* find flags already set for user
* why not just copy them?
*/
- setflags = sptr->flags;
-#if 0
- setflags = 0;
- for (i = 0; i < USERMODELIST_SIZE; ++i) {
- if (sptr->flags & userModeList[i].flag)
- setflags |= userModeList[i].flag;
- }
-#endif
+ setflags = cli_flags(sptr);
+
if (MyConnect(sptr))
- tmpmask = sptr->snomask;
+ tmpmask = cli_snomask(sptr);
/*
* parse mode change string(s)
tmpmask = (what == MODE_ADD) ?
(IsAnOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT) : 0;
if (tmpmask)
- sptr->flags |= FLAGS_SERVNOTICE;
+ SetServNotice(sptr);
else
- sptr->flags &= ~FLAGS_SERVNOTICE;
+ ClearServNotice(sptr);
break;
case 'w':
if (what == MODE_ADD)
if (what == MODE_ADD)
SetOper(sptr);
else {
- sptr->flags &= ~(FLAGS_OPER | FLAGS_LOCOP);
+ cli_flags(sptr) &= ~(FLAGS_OPER | FLAGS_LOCOP);
if (MyConnect(sptr)) {
- tmpmask = sptr->snomask & ~SNO_OPER;
- sptr->handler = CLIENT_HANDLER;
+ tmpmask = cli_snomask(sptr) & ~SNO_OPER;
+ cli_handler(sptr) = CLIENT_HANDLER;
}
}
break;
if (what == MODE_ADD)
SetLocOp(sptr);
else {
- sptr->flags &= ~(FLAGS_OPER | FLAGS_LOCOP);
+ cli_flags(sptr) &= ~(FLAGS_OPER | FLAGS_LOCOP);
if (MyConnect(sptr)) {
- tmpmask = sptr->snomask & ~SNO_OPER;
- sptr->handler = CLIENT_HANDLER;
+ tmpmask = cli_snomask(sptr) & ~SNO_OPER;
+ cli_handler(sptr) = CLIENT_HANDLER;
}
}
break;
* Evaluate rules for new user mode
* Stop users making themselves operators too easily:
*/
- if (!(setflags & FLAGS_OPER) && IsOper(sptr) && !IsServer(cptr))
- ClearOper(sptr);
- if (!(setflags & FLAGS_LOCOP) && IsLocOp(sptr) && !IsServer(cptr))
- ClearLocOp(sptr);
-#ifdef WALLOPS_OPER_ONLY
- /*
- * only send wallops to opers
- */
- if (!IsAnOper(sptr) && !(setflags & FLAGS_WALLOP) && !IsServer(cptr))
- ClearWallops(sptr);
+ if (!IsServer(cptr)) {
+ if (!(setflags & FLAGS_OPER) && IsOper(sptr))
+ ClearOper(sptr);
+ if (!(setflags & FLAGS_LOCOP) && IsLocOp(sptr))
+ ClearLocOp(sptr);
+ /*
+ * new umode; servers can set it, local users cannot;
+ * prevents users from /kick'ing or /mode -o'ing
+ */
+ if (!(setflags & FLAGS_CHSERV))
+ ClearChannelService(sptr);
+ /*
+ * only send wallops to opers
+ */
+ 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
- if ((setflags & (FLAGS_OPER | FLAGS_LOCOP)) && !IsAnOper(sptr) &&
- MyConnect(sptr))
- det_confs_butmask(sptr, CONF_CLIENT & ~CONF_OPS);
- /*
- * new umode; servers can set it, local users cannot;
- * prevents users from /kick'ing or /mode -o'ing
- */
- if (!(setflags & FLAGS_CHSERV) && !IsServer(cptr))
- ClearChannelService(sptr);
+#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 (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
* will cause servers to update correctly.
*/
- if ((setflags & FLAGS_OPER) && !IsOper(sptr))
- --UserStats.opers;
- if (!(setflags & FLAGS_OPER) && IsOper(sptr))
+ if (!(setflags & FLAGS_OPER) && IsOper(sptr)) { /* user now oper */
++UserStats.opers;
+ client_set_privs(sptr); /* may set propagate privilege */
+ }
+ if (HasPriv(sptr, PRIV_PROPAGATE)) /* remember propagate privilege setting */
+ prop = 1;
+ if ((setflags & FLAGS_OPER) && !IsOper(sptr)) { /* user no longer oper */
+ --UserStats.opers;
+ client_set_privs(sptr); /* will clear propagate privilege */
+ }
if ((setflags & FLAGS_INVISIBLE) && !IsInvisible(sptr))
--UserStats.inv_clients;
if (!(setflags & FLAGS_INVISIBLE) && IsInvisible(sptr))
++UserStats.inv_clients;
- send_umode_out(cptr, sptr, setflags);
-
- if (MyConnect(sptr)) {
- if (tmpmask != sptr->snomask)
- set_snomask(sptr, tmpmask, SNO_SET);
- if (sptr->snomask && snomask_given)
- send_reply(sptr, RPL_SNOMASK, sptr->snomask, sptr->snomask);
- }
+ send_umode_out(cptr, sptr, setflags, prop);
return 0;
}
int i;
int c_flags;
- c_flags = cptr->flags & SEND_UMODES; /* cleaning up the original code */
+ c_flags = cli_flags(cptr) & SEND_UMODES; /* cleaning up the original code */
+ if (HasPriv(cptr, PRIV_PROPAGATE))
+ c_flags |= FLAGS_OPER;
+ else
+ c_flags &= ~FLAGS_OPER;
for (i = 0; i < USERMODELIST_SIZE; ++i) {
if ( (c_flags & userModeList[i].flag))
flag = userModeList[i].flag;
if (MyUser(sptr) && !(flag & sendmask))
continue;
- if ( (flag & old) && !(sptr->flags & flag))
+ if ( (flag & old) && !(cli_flags(sptr) & flag))
{
if (what == MODE_DEL)
*m++ = userModeList[i].c;
*m++ = userModeList[i].c;
}
}
- else if (!(flag & old) && (sptr->flags & flag))
+ else if (!(flag & old) && (cli_flags(sptr) & flag))
{
if (what == MODE_ADD)
*m++ = userModeList[i].c;
}
*m = '\0';
if (*umodeBuf && cptr)
- sendcmdto_one(sptr, CMD_MODE, cptr, "%s :%s", sptr->name, umodeBuf);
+ sendcmdto_one(sptr, CMD_MODE, cptr, "%s :%s", cli_name(sptr), umodeBuf);
}
/*
int i;
struct SLink *tmp;
- oldmask = cptr->snomask;
+ oldmask = cli_snomask(cptr);
if (what == SNO_ADD)
newmask |= oldmask;
delfrom_list(cptr, &opsarray[i]);
}
}
- cptr->snomask = newmask;
+ cli_snomask(cptr) = newmask;
}
/*
static char sender[HOSTLEN + NICKLEN + USERLEN + 5];
static char senderip[16 + NICKLEN + USERLEN + 5];
- if (!(acptr->user) || !(lp = acptr->user->silence) || !(user = sptr->user))
+ if (!cli_user(acptr) || !(lp = cli_user(acptr)->silence) || !(user = cli_user(sptr)))
return 0;
- sprintf_irc(sender, "%s!%s@%s", sptr->name, user->username, user->host);
- sprintf_irc(senderip, "%s!%s@%s", sptr->name, user->username,
- ircd_ntoa((const char*) &sptr->ip));
+ 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))));
for (; lp; lp = lp->next)
{
if ((!(lp->flags & CHFL_SILENCE_IPMASK) && !match(lp->value.cp, sender)) ||
{
if (!MyConnect(sptr))
{
- sendcmdto_one(acptr, CMD_SILENCE, sptr->from, "%C %s", sptr,
- lp->value.cp);
+ sendcmdto_one(acptr, CMD_SILENCE, cli_from(sptr), "%C %s", sptr,
+ lp->value.cp);
}
return 1;
}
struct SLink *tmp;
int ret = -1;
- for (lp = &sptr->user->silence; *lp;) {
+ for (lp = &(cli_user(sptr))->silence; *lp;) {
if (!mmatch(mask, (*lp)->value.cp))
{
tmp = *lp;
int cnt = 0, len = strlen(mask);
char *ip_start;
- for (lpp = &sptr->user->silence, lp = *lpp; lp;)
+ for (lpp = &(cli_user(sptr))->silence, lp = *lpp; lp;)
{
if (0 == ircd_strcmp(mask, lp->value.cp))
return -1;
if (MyUser(sptr))
{
len += strlen(lp->value.cp);
- if ((len > MAXSILELENGTH) || (++cnt >= MAXSILES))
+ if ((len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXSILES))) ||
+ (++cnt >= feature_int(FEAT_MAXSILES)))
{
- send_reply(sptr, ERR_SILELISTFULL, mask);
+ send_reply(sptr, ERR_SILELISTFULL, mask);
return -1;
}
else if (!mmatch(lp->value.cp, mask))
}
lp = make_link();
memset(lp, 0, sizeof(struct SLink));
- lp->next = sptr->user->silence;
+ lp->next = cli_user(sptr)->silence;
lp->value.cp = (char*) MyMalloc(strlen(mask) + 1);
assert(0 != lp->value.cp);
strcpy(lp->value.cp, mask);
if ((ip_start = strrchr(mask, '@')) && check_if_ipmask(ip_start + 1))
lp->flags = CHFL_SILENCE_IPMASK;
- sptr->user->silence = lp;
+ cli_user(sptr)->silence = lp;
return 0;
}
+int
+send_supported(struct Client *cptr)
+{
+ char featurebuf[512];
+
+ ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES1, FEATURESVALUES1);
+ send_reply(sptr, RPL_ISUPPORT, featurebuf);
+ ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES2, FEATURESVALUES2);
+ send_reply(sptr, RPL_ISUPPORT, featurebuf);
+
+ return 0; /* convenience return, if it's ever needed */
+}