/* proto-common.c - common IRC protocol parsing/sending support
- * Copyright 2000-2004 srvx Development Team
+ * Copyright 2000-2006 srvx Development Team
*
* This file is part of srvx.
*
#include "ioset.h"
#include "log.h"
#include "nickserv.h"
+#include "opserv.h"
+#include "chanserv.h"
+#include "spamserv.h"
#include "timeq.h"
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
extern unsigned int nuf_size, nuf_used;
extern del_user_func_t *duf_list;
extern unsigned int duf_size, duf_used;
-extern time_t boot_time;
+extern unsigned long boot_time;
void received_ping(void);
void
socket_destroyed(struct io_fd *fd)
{
- if (fd && fd->eof)
+ if (fd && fd->state != IO_CONNECTED)
log_module(MAIN_LOG, LOG_ERROR, "Connection to server lost.");
socket_io_fd = NULL;
cManager.uplink->state = DISCONNECTED;
while (!quit_services) {
if (!replay_connected) {
/* this time fudging is to get some of the logging right */
- self->link = self->boot = now;
+ self->link_time = self->boot = now;
cManager.uplink->state = AUTHENTICATING;
irc_introduce(cManager.uplink->password);
replay_connected = 1;
socket_io_fd->readable_cb = uplink_readable;
socket_io_fd->destroy_cb = socket_destroyed;
socket_io_fd->line_reads = 1;
- socket_io_fd->wants_reads = 1;
log_module(MAIN_LOG, LOG_INFO, "Connection to server established.");
cManager.uplink = target;
target->state = AUTHENTICATING;
replay_read_line(void)
{
struct tm timestamp;
- time_t new_time;
+ unsigned long new_time;
if (replay_line[0]) return;
read_line:
timestamp.tm_year = strtoul(replay_line+16, NULL, 10) - 1900;
timestamp.tm_isdst = 0;
new_time = mktime(×tamp);
- if (new_time == -1) {
+ if (new_time == (unsigned long)-1) {
log_module(MAIN_LOG, LOG_ERROR, "Unable to parse time struct tm_sec=%d tm_min=%d tm_hour=%d tm_mday=%d tm_mon=%d tm_year=%d", timestamp.tm_sec, timestamp.tm_min, timestamp.tm_hour, timestamp.tm_mday, timestamp.tm_mon, timestamp.tm_year);
} else {
now = new_time;
replay_connected = 0;
socket_destroyed(socket_io_fd);
} else {
- ioset_close(socket_io_fd->fd, 1);
+ ioset_close(socket_io_fd, 3);
+ socket_io_fd = NULL;
}
}
return 0;
true_pass = cManager.uplink->their_password;
if (true_pass && strcmp(true_pass, argv[1])) {
- /* It might be good to mark the uplink as unavailable when
- this happens, though there should be a way of resetting
- the flag. */
- irc_squit(self, "Incorrect password received.", NULL);
- return 1;
+ /* It might be good to mark the uplink as unavailable when
+ this happens, though there should be a way of resetting
+ the flag. */
+ irc_squit(self, "Incorrect password received.", NULL);
+ return 1;
}
cManager.uplink->state = BURSTING;
static CMD_FUNC(cmd_error)
{
- if (argv[1]) log_module(MAIN_LOG, LOG_ERROR, "Error: %s", argv[1]);
+ if (argv[1]) log_module(MAIN_LOG, LOG_ERROR, "Error from ircd: %s", argv[1]);
log_module(MAIN_LOG, LOG_ERROR, "Error received from uplink, squitting.");
if (cManager.uplink->state != CONNECTED) {
- /* Error messages while connected should be fine. */
- cManager.uplink->flags |= UPLINK_UNAVAILABLE;
- log_module(MAIN_LOG, LOG_ERROR, "Disabling uplink.");
+ /* Error messages while connected should be fine. */
+ cManager.uplink->flags |= UPLINK_UNAVAILABLE;
+ log_module(MAIN_LOG, LOG_ERROR, "Disabling uplink.");
}
close_socket();
return 0;
switch (argv[1][0]) {
case 'u': {
- unsigned int uptime = now - boot_time;
+ unsigned long uptime;
+ uptime = now - boot_time;
irc_numeric(un, RPL_STATSUPTIME, ":Server Up %d days %d:%02d:%02d",
uptime/(24*60*60), (uptime/(60*60))%24, (uptime/60)%60, uptime%60);
irc_numeric(un, RPL_MAXCONNECTIONS, ":Highest connection count: %d (%d clients)",
static void
privmsg_chan_helper(struct chanNode *cn, void *data)
{
+ extern unsigned short offchannel_allowed[256];
struct privmsg_desc *pd = data;
struct modeNode *mn;
- struct chanmsg_func *cf = &chanmsg_funcs[(unsigned char)pd->text[0]];
+ struct chanmsg_func *cf;
int x;
/* Don't complain if it can't find the modeNode because the channel might
mn->idle_since = now;
/* Never send a NOTICE to a channel to one of the services */
- if (!pd->is_notice && cf->func
- && ((cn->modes & MODE_REGISTERED) || GetUserMode(cn, cf->service)))
- cf->func(pd->user, cn, pd->text+1, cf->service);
+ cf = &chanmsg_funcs[(unsigned char)pd->text[0]];
+ if (cf->func && !pd->is_notice
+ && (offchannel_allowed[(unsigned char)pd->text[0]]
+ || (GetUserMode(cn, cf->service) && !IsDeaf(cf->service))))
+ cf->func(pd->user, cn, pd->text+1, cf->service, pd->is_notice);
+ else
+ spamserv_channel_message(cn, pd->user, pd->text);
/* This catches *all* text sent to the channel that the services server sees */
for (x = 0; x < ALLCHANMSG_FUNCS_MAX; x++) {
if (!cf->func)
break; /* end of list */
else
- cf->func(pd->user, cn, pd->text, cf->service);
+ cf->func(pd->user, cn, pd->text, cf->service, pd->is_notice);
}
}
irc_numeric(pd->user, ERR_NOSUCHNICK, "%s@%s :No such nick", name, self->name);
}
+struct part_desc {
+ struct userNode *user;
+ const char *text;
+};
+
static void
part_helper(struct chanNode *cn, void *data)
{
- DelChannelUser(data, cn, false, 0);
+ struct part_desc *desc = data;
+ DelChannelUser(desc->user, cn, desc->text, false);
+ if (IsOper(desc->user))
+ operpart(cn, desc->user);
+}
+
+static CMD_FUNC(cmd_part)
+{
+ struct part_desc desc;
+
+ if (argc < 2)
+ return 0;
+ desc.user = GetUserH(origin);
+ if (!desc.user)
+ return 0;
+ desc.text = (argc > 2) ? argv[argc - 1] : NULL;
+ parse_foreach(argv[1], part_helper, NULL, NULL, NULL, &desc);
+ return 1;
}
void
reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler)
{
if (chanmsg_funcs[prefix].func)
- log_module(MAIN_LOG, LOG_WARNING, "Re-registering new chanmsg handler for character `%c'.", prefix);
+ log_module(MAIN_LOG, LOG_WARNING, "Re-registering new chanmsg handler for character `%c'.", prefix);
chanmsg_funcs[prefix].func = handler;
chanmsg_funcs[prefix].service = service;
}
reg_mode_change_func(mode_change_func_t handler)
{
if (mcf_used == mcf_size) {
- if (mcf_size) {
- mcf_size <<= 1;
- mcf_list = realloc(mcf_list, mcf_size*sizeof(mode_change_func_t));
- } else {
- mcf_size = 8;
- mcf_list = malloc(mcf_size*sizeof(mode_change_func_t));
- }
+ if (mcf_size) {
+ mcf_size <<= 1;
+ mcf_list = realloc(mcf_list, mcf_size*sizeof(mode_change_func_t));
+ } else {
+ mcf_size = 8;
+ mcf_list = malloc(mcf_size*sizeof(mode_change_func_t));
+ }
}
mcf_list[mcf_used++] = handler;
}
+static oper_func_t *of_list;
+static unsigned int of_size = 0, of_used = 0;
+
+void
+reg_oper_func(oper_func_t handler)
+{
+ if (of_used == of_size) {
+ if (of_size) {
+ of_size <<= 1;
+ of_list = realloc(of_list, of_size*sizeof(oper_func_t));
+ } else {
+ of_size = 8;
+ of_list = malloc(of_size*sizeof(oper_func_t));
+ }
+ }
+ of_list[of_used++] = handler;
+}
+
+static void
+call_oper_funcs(struct userNode *user)
+{
+ unsigned int n;
+ if (IsLocal(user))
+ return;
+ for (n=0; (n<of_used) && !user->dead; n++)
+ {
+ of_list[n](user);
+ }
+}
+
+static xquery_func_t *xqf_list;
+static unsigned int xqf_size = 0, xqf_used = 0;
+
+void
+reg_xquery_func(xquery_func_t handler)
+{
+ if (xqf_used == xqf_size) {
+ if (xqf_size) {
+ xqf_size <<= 1;
+ xqf_list = realloc(xqf_list, xqf_size*sizeof(xquery_func_t));
+ } else {
+ xqf_size = 8;
+ xqf_list = malloc(xqf_size*sizeof(xquery_func_t));
+ }
+ }
+ xqf_list[xqf_used++] = handler;
+}
+
+static void
+call_xquery_funcs(struct server *source, const char routing[], const char query[])
+{
+ unsigned int n;
+ for (n=0; n < xqf_used; n++)
+ {
+ xqf_list[n](source, routing, query);
+ }
+}
+
struct mod_chanmode *
mod_chanmode_alloc(unsigned int argc)
{
res->modes_set = orig->modes_set;
res->modes_clear = orig->modes_clear;
res->new_limit = orig->new_limit;
+ res->new_access = orig->new_access;
+ memcpy(res->new_altchan, orig->new_altchan, sizeof(res->new_altchan));
+ memcpy(res->new_noflood, orig->new_noflood, sizeof(res->new_noflood));
memcpy(res->new_key, orig->new_key, sizeof(res->new_key));
memcpy(res->new_upass, orig->new_upass, sizeof(res->new_upass));
memcpy(res->new_apass, orig->new_apass, sizeof(res->new_apass));
channel->modes = (channel->modes & ~change->modes_clear) | change->modes_set;
if (change->modes_set & MODE_LIMIT)
channel->limit = change->new_limit;
+ if (change->modes_set & MODE_ACCESS)
+ channel->access = change->new_access;
if (change->modes_set & MODE_KEY)
strcpy(channel->key, change->new_key);
+ if (change->modes_set & MODE_ALTCHAN)
+ strcpy(channel->altchan, change->new_altchan);
+ if (change->modes_set & MODE_NOFLOOD)
+ strcpy(channel->noflood, change->new_noflood);
if (change->modes_set & MODE_UPASS)
strcpy(channel->upass, change->new_upass);
if (change->modes_set & MODE_APASS)
int
mod_chanmode(struct userNode *who, struct chanNode *channel, char **modes, unsigned int argc, unsigned int flags)
{
+ struct modeNode *member;
struct mod_chanmode *change;
unsigned int ii;
+ short base_oplevel;
if (!modes || !modes[0])
return 0;
- if (!(change = mod_chanmode_parse(channel, modes, argc, flags)))
+ if (who && (member = GetUserMode(channel, who)))
+ base_oplevel = member->oplevel;
+ else
+ base_oplevel = MAXOPLEVEL;
+ if (!(change = mod_chanmode_parse(channel, who, modes, argc, flags, base_oplevel)))
return 0;
if (flags & MC_ANNOUNCE)
mod_chanmode_announce(who, channel, change);
mod_chanmode_init(&change);
change.modes_set = chan->modes;
change.new_limit = chan->limit;
+ change.new_access = chan->access;
+ safestrncpy(change.new_altchan, chan->altchan, sizeof(change.new_altchan));
+ safestrncpy(change.new_noflood, chan->noflood, sizeof(change.new_noflood));
safestrncpy(change.new_key, chan->key, sizeof(change.new_key));
safestrncpy(change.new_upass, chan->upass, sizeof(change.new_upass));
safestrncpy(change.new_apass, chan->apass, sizeof(change.new_apass));
ident = user->ident;
else if (options & GENMASK_ANY_IDENT)
ident = "*";
+ else if (IsFakeIdent(user) && IsHiddenHost(user) && !(options & GENMASK_NO_HIDING))
+ ident = user->fakeident;
else {
ident = alloca(strlen(user->ident)+2);
ident[0] = '*';
}
hostname = user->hostname;
if (IsFakeHost(user) && IsHiddenHost(user) && !(options & GENMASK_NO_HIDING)) {
- hostname = user->fakehost;
+ if(user->fakehost && user->fakehost[0] == '$') {
+ hostname = alloca(strlen(user->handle_info->handle) + strlen(user->fakehost));
+ sprintf(hostname, "%s%s", user->handle_info->handle, user->fakehost+1);
+ } else {
+ hostname = user->fakehost;
+ }
} else if (IsHiddenHost(user) && user->handle_info && hidden_host_suffix && !(options & GENMASK_NO_HIDING)) {
hostname = alloca(strlen(user->handle_info->handle) + strlen(hidden_host_suffix) + 2);
sprintf(hostname, "%s.%s", user->handle_info->handle, hidden_host_suffix);
- } else if (options & GENMASK_STRICT_HOST && options & GENMASK_BYIP) {
- hostname = (char*)irc_ntoa(&user->ip);
+ } else if (options & GENMASK_STRICT_HOST) {
+ if (options & GENMASK_BYIP)
+ hostname = (char*)irc_ntoa(&user->ip);
} else if ((options & GENMASK_BYIP) || irc_pton(&ip, NULL, hostname)) {
/* Should generate an IP-based hostmask. */
hostname = alloca(IRC_NTOP_MAX_SIZE);
sprintf(hostname, "%d.%d.*", user->ip.in6_8[12], user->ip.in6_8[13]);
} else if (irc_in_addr_is_ipv6(user->ip)) {
/* Who knows what the default mask should be? Use a /48 to start with. */
- sprintf(hostname, "%x:%x:%x:*", user->ip.in6[0], user->ip.in6[1], user->ip.in6[2]);
+ sprintf(hostname, "%x:%x:%x:*", ntohs(user->ip.in6[0]), ntohs(user->ip.in6[1]), ntohs(user->ip.in6[2]));
} else {
/* Unknown type; just copy IP directly. */
irc_ntop(hostname, IRC_NTOP_MAX_SIZE, &user->ip);
for (ii=cnt=0; hostname[ii]; ii++)
if (hostname[ii] == '.')
cnt++;
- if (cnt == 1) {
- /* only a two-level domain name; leave hostname */
+ if (cnt == 0 || cnt == 1) {
+ /* only a one- or two-level domain name; leave hostname */
} else if (cnt == 2) {
for (ii=0; user->hostname[ii] != '.'; ii++) ;
/* Add 3 to account for the *. and \0. */
}
return 1;
}
+
+unsigned int
+irc_user_modes(const struct userNode *user, char modes[], size_t length)
+{
+ unsigned int ii, jj;
+
+ for (ii = jj = 0; (jj < length) && (irc_user_mode_chars[ii] != '\0'); ++ii) {
+ if ((user->modes & (1 << ii)) && (irc_user_mode_chars[ii] != ' '))
+ modes[jj++] = irc_user_mode_chars[ii];
+ }
+
+ ii = jj;
+ while (jj < length)
+ modes[jj++] = '\0';
+
+ return ii;
+}