0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

Remove ^M.

This commit is contained in:
Jilles Tjoelker 2008-04-02 20:50:20 +02:00
parent 34ce42c1a1
commit 1087485cf2
5 changed files with 448 additions and 448 deletions

View file

@ -1,37 +1,37 @@
/*
* ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
* cache.c - code for caching files
*
* Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
* Copyright (C) 2003-2005 ircd-ratbox development team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1.Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2.Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3.The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $
*/
/*
* ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
* cache.c - code for caching files
*
* Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk>
* Copyright (C) 2003-2005 ircd-ratbox development team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1.Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2.Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3.The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: cache.c 25119 2008-03-13 16:57:05Z androsyn $
*/
#include "stdinc.h"
#include "ircd_defs.h"
#include "common.h"
@ -41,145 +41,145 @@
#include "cache.h"
#include "sprintf_irc.h"
#include "irc_dictionary.h"
#include "numeric.h"
struct cachefile *user_motd = NULL;
struct cachefile *oper_motd = NULL;
struct cacheline *emptyline = NULL;
rb_dlink_list links_cache_list;
char user_motd_changed[MAX_DATE_STRING];
#include "numeric.h"
struct cachefile *user_motd = NULL;
struct cachefile *oper_motd = NULL;
struct cacheline *emptyline = NULL;
rb_dlink_list links_cache_list;
char user_motd_changed[MAX_DATE_STRING];
struct Dictionary *help_dict_oper = NULL;
struct Dictionary *help_dict_user = NULL;
/* init_cache()
*
* inputs -
* outputs -
* side effects - inits the file/line cache blockheaps, loads motds
*/
void
init_cache(void)
{
/* allocate the emptyline */
emptyline = rb_malloc(sizeof(struct cacheline));
emptyline->data[0] = ' ';
emptyline->data[1] = '\0';
user_motd_changed[0] = '\0';
user_motd = cache_file(MPATH, "ircd.motd", 0);
oper_motd = cache_file(OPATH, "opers.motd", 0);
memset(&links_cache_list, 0, sizeof(links_cache_list));
struct Dictionary *help_dict_user = NULL;
/* init_cache()
*
* inputs -
* outputs -
* side effects - inits the file/line cache blockheaps, loads motds
*/
void
init_cache(void)
{
/* allocate the emptyline */
emptyline = rb_malloc(sizeof(struct cacheline));
emptyline->data[0] = ' ';
emptyline->data[1] = '\0';
user_motd_changed[0] = '\0';
user_motd = cache_file(MPATH, "ircd.motd", 0);
oper_motd = cache_file(OPATH, "opers.motd", 0);
memset(&links_cache_list, 0, sizeof(links_cache_list));
help_dict_oper = irc_dictionary_create(strcasecmp);
help_dict_user = irc_dictionary_create(strcasecmp);
}
/* cache_file()
*
* inputs - file to cache, files "shortname", flags to set
* outputs - pointer to file cached, else NULL
* side effects -
*/
struct cachefile *
cache_file(const char *filename, const char *shortname, int flags)
{
FILE *in;
struct cachefile *cacheptr;
struct cacheline *lineptr;
char line[BUFSIZE];
char *p;
if((in = fopen(filename, "r")) == NULL)
return NULL;
cacheptr = rb_malloc(sizeof(struct cachefile));
rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
cacheptr->flags = flags;
/* cache the file... */
while(fgets(line, sizeof(line), in) != NULL)
{
if((p = strpbrk(line, "\r\n")) != NULL)
*p = '\0';
if(!EmptyString(line))
{
lineptr = rb_malloc(sizeof(struct cacheline));
rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));
rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
}
else
rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);
}
fclose(in);
return cacheptr;
}
void
cache_links(void *unused)
{
struct Client *target_p;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
char *links_line;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)
{
rb_free(ptr->data);
rb_free_rb_dlink_node(ptr);
}
links_cache_list.head = links_cache_list.tail = NULL;
links_cache_list.length = 0;
RB_DLINK_FOREACH(ptr, global_serv_list.head)
{
target_p = ptr->data;
/* skip ourselves (done in /links) and hidden servers */
if(IsMe(target_p) ||
(IsHidden(target_p) && !ConfigServerHide.disable_hidden))
continue;
/* if the below is ever modified, change LINKSLINELEN */
links_line = rb_malloc(LINKSLINELEN);
rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",
target_p->name, me.name,
target_p->info[0] ? target_p->info :
"(Unknown Location)");
rb_dlinkAddTailAlloc(links_line, &links_cache_list);
}
}
/* free_cachefile()
*
* inputs - cachefile to free
* outputs -
* side effects - cachefile and its data is free'd
*/
void
free_cachefile(struct cachefile *cacheptr)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
if(cacheptr == NULL)
return;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
{
if(ptr->data != emptyline)
rb_free(ptr->data);
}
rb_free(cacheptr);
}
help_dict_user = irc_dictionary_create(strcasecmp);
}
/* cache_file()
*
* inputs - file to cache, files "shortname", flags to set
* outputs - pointer to file cached, else NULL
* side effects -
*/
struct cachefile *
cache_file(const char *filename, const char *shortname, int flags)
{
FILE *in;
struct cachefile *cacheptr;
struct cacheline *lineptr;
char line[BUFSIZE];
char *p;
if((in = fopen(filename, "r")) == NULL)
return NULL;
cacheptr = rb_malloc(sizeof(struct cachefile));
rb_strlcpy(cacheptr->name, shortname, sizeof(cacheptr->name));
cacheptr->flags = flags;
/* cache the file... */
while(fgets(line, sizeof(line), in) != NULL)
{
if((p = strpbrk(line, "\r\n")) != NULL)
*p = '\0';
if(!EmptyString(line))
{
lineptr = rb_malloc(sizeof(struct cacheline));
rb_strlcpy(lineptr->data, line, sizeof(lineptr->data));
rb_dlinkAddTail(lineptr, &lineptr->linenode, &cacheptr->contents);
}
else
rb_dlinkAddTailAlloc(emptyline, &cacheptr->contents);
}
fclose(in);
return cacheptr;
}
void
cache_links(void *unused)
{
struct Client *target_p;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
char *links_line;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, links_cache_list.head)
{
rb_free(ptr->data);
rb_free_rb_dlink_node(ptr);
}
links_cache_list.head = links_cache_list.tail = NULL;
links_cache_list.length = 0;
RB_DLINK_FOREACH(ptr, global_serv_list.head)
{
target_p = ptr->data;
/* skip ourselves (done in /links) and hidden servers */
if(IsMe(target_p) ||
(IsHidden(target_p) && !ConfigServerHide.disable_hidden))
continue;
/* if the below is ever modified, change LINKSLINELEN */
links_line = rb_malloc(LINKSLINELEN);
rb_snprintf(links_line, LINKSLINELEN, "%s %s :1 %s",
target_p->name, me.name,
target_p->info[0] ? target_p->info :
"(Unknown Location)");
rb_dlinkAddTailAlloc(links_line, &links_cache_list);
}
}
/* free_cachefile()
*
* inputs - cachefile to free
* outputs -
* side effects - cachefile and its data is free'd
*/
void
free_cachefile(struct cachefile *cacheptr)
{
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
if(cacheptr == NULL)
return;
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cacheptr->contents.head)
{
if(ptr->data != emptyline)
rb_free(ptr->data);
}
rb_free(cacheptr);
}
/* load_help()
*
* inputs -
@ -234,57 +234,57 @@ load_help(void)
}
closedir(helpfile_dir);
}
/* send_user_motd()
*
* inputs - client to send motd to
* outputs - client is sent motd if exists, else ERR_NOMOTD
* side effects -
*/
void
send_user_motd(struct Client *source_p)
{
struct cacheline *lineptr;
rb_dlink_node *ptr;
const char *myname = get_id(&me, source_p);
const char *nick = get_id(source_p, source_p);
if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0)
{
sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);
return;
}
sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);
RB_DLINK_FOREACH(ptr, user_motd->contents.head)
{
lineptr = ptr->data;
sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);
}
sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick);
}
void
cache_user_motd(void)
{
struct stat sb;
struct tm *local_tm;
if(stat(MPATH, &sb) == 0)
{
local_tm = localtime(&sb.st_mtime);
if(local_tm != NULL)
{
rb_snprintf(user_motd_changed, sizeof(user_motd_changed),
"%d/%d/%d %d:%d",
local_tm->tm_mday, local_tm->tm_mon + 1,
1900 + local_tm->tm_year, local_tm->tm_hour,
local_tm->tm_min);
}
}
free_cachefile(user_motd);
user_motd = cache_file(MPATH, "ircd.motd", 0);
}
}
/* send_user_motd()
*
* inputs - client to send motd to
* outputs - client is sent motd if exists, else ERR_NOMOTD
* side effects -
*/
void
send_user_motd(struct Client *source_p)
{
struct cacheline *lineptr;
rb_dlink_node *ptr;
const char *myname = get_id(&me, source_p);
const char *nick = get_id(source_p, source_p);
if(user_motd == NULL || rb_dlink_list_length(&user_motd->contents) == 0)
{
sendto_one(source_p, form_str(ERR_NOMOTD), myname, nick);
return;
}
sendto_one(source_p, form_str(RPL_MOTDSTART), myname, nick, me.name);
RB_DLINK_FOREACH(ptr, user_motd->contents.head)
{
lineptr = ptr->data;
sendto_one(source_p, form_str(RPL_MOTD), myname, nick, lineptr->data);
}
sendto_one(source_p, form_str(RPL_ENDOFMOTD), myname, nick);
}
void
cache_user_motd(void)
{
struct stat sb;
struct tm *local_tm;
if(stat(MPATH, &sb) == 0)
{
local_tm = localtime(&sb.st_mtime);
if(local_tm != NULL)
{
rb_snprintf(user_motd_changed, sizeof(user_motd_changed),
"%d/%d/%d %d:%d",
local_tm->tm_mday, local_tm->tm_mon + 1,
1900 + local_tm->tm_year, local_tm->tm_hour,
local_tm->tm_min);
}
}
free_cachefile(user_motd);
user_motd = cache_file(MPATH, "ircd.motd", 0);
}

View file

@ -44,31 +44,31 @@
rb_dlink_list class_list;
struct Class *default_class;
struct Class *
make_class(void)
{
struct Class *tmp;
tmp = rb_malloc(sizeof(struct Class));
ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY;
PingFreq(tmp) = DEFAULT_PINGFREQUENCY;
MaxUsers(tmp) = 1;
MaxSendq(tmp) = DEFAULT_SENDQ;
tmp->ip_limits = rb_new_patricia(PATRICIA_BITS);
return tmp;
}
void
free_class(struct Class *tmp)
{
if(tmp->ip_limits)
rb_destroy_patricia(tmp->ip_limits, NULL);
rb_free(tmp->class_name);
rb_free(tmp);
struct Class *
make_class(void)
{
struct Class *tmp;
tmp = rb_malloc(sizeof(struct Class));
ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY;
PingFreq(tmp) = DEFAULT_PINGFREQUENCY;
MaxUsers(tmp) = 1;
MaxSendq(tmp) = DEFAULT_SENDQ;
tmp->ip_limits = rb_new_patricia(PATRICIA_BITS);
return tmp;
}
void
free_class(struct Class *tmp)
{
if(tmp->ip_limits)
rb_destroy_patricia(tmp->ip_limits, NULL);
rb_free(tmp->class_name);
rb_free(tmp);
}
/*

View file

@ -118,7 +118,7 @@ init_client(void)
* start off the check ping event .. -- adrian
* Every 30 seconds is plenty -- db
*/
client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap");
client_heap = rb_bh_create(sizeof(struct Client), CLIENT_HEAP_SIZE, "client_heap");
lclient_heap = rb_bh_create(sizeof(struct LocalUser), LCLIENT_HEAP_SIZE, "lclient_heap");
pclient_heap = rb_bh_create(sizeof(struct PreClient), PCLIENT_HEAP_SIZE, "pclient_heap");
away_heap = rb_bh_create(AWAYLEN, AWAY_HEAP_SIZE, "away_heap");
@ -1711,8 +1711,8 @@ exit_client(struct Client *client_p, /* The local client originating the
void
count_local_client_memory(size_t * count, size_t * local_client_memory_used)
{
size_t lusage;
rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);
size_t lusage;
rb_bh_usage(lclient_heap, count, NULL, &lusage, NULL);
*local_client_memory_used = lusage + (*count * (sizeof(void *) + sizeof(struct Client)));
}
@ -1722,10 +1722,10 @@ count_local_client_memory(size_t * count, size_t * local_client_memory_used)
void
count_remote_client_memory(size_t * count, size_t * remote_client_memory_used)
{
size_t lcount, rcount;
rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);
rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);
*count = rcount - lcount;
size_t lcount, rcount;
rb_bh_usage(lclient_heap, &lcount, NULL, NULL, NULL);
rb_bh_usage(client_heap, &rcount, NULL, NULL, NULL);
*count = rcount - lcount;
*remote_client_memory_used = *count * (sizeof(void *) + sizeof(struct Client));
}

View file

@ -52,7 +52,7 @@ static const struct in6_addr in6addr_any =
#endif
static listener_t *ListenerPollList = NULL;
static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data);
static listener_t *
@ -195,60 +195,60 @@ inetport(listener_t *listener)
}
}
if(F == NULL)
{
report_error("opening listener socket %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
return 0;
}
else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/
{
report_error("no more connections left for listener %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
if(F == NULL)
{
report_error("opening listener socket %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
return 0;
}
else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/
{
report_error("no more connections left for listener %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
}
/*
* XXX - we don't want to do all this crap for a listener
* set_sock_opts(listener);
*/
if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))
{
report_error("setting SO_REUSEADDR for listener %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
/*
* XXX - we don't want to do all this crap for a listener
* set_sock_opts(listener);
*/
if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt)))
{
report_error("setting SO_REUSEADDR for listener %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
}
/*
* Bind a port to listen for new connections if port is non-null,
* else assume it is already open and try get something from it.
*/
if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))
{
report_error("binding listener socket %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
/*
* Bind a port to listen for new connections if port is non-null,
* else assume it is already open and try get something from it.
*/
if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr)))
{
report_error("binding listener socket %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
}
if((ret = rb_listen(F, RATBOX_SOMAXCONN)))
{
report_error("listen failed for %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
if((ret = rb_listen(F, RATBOX_SOMAXCONN)))
{
report_error("listen failed for %s:%s",
get_listener_name(listener),
get_listener_name(listener), errno);
rb_close(F);
return 0;
}
listener->F = F;
listener->F = F;
rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener);
return 1;
}
@ -273,9 +273,9 @@ find_listener(struct rb_sockaddr_storage *addr)
if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr &&
in4->sin_port == lin4->sin_port )
{
if(listener->F == NULL)
last_closed = listener;
else
if(listener->F == NULL)
last_closed = listener;
else
return(listener);
}
break;
@ -288,9 +288,9 @@ find_listener(struct rb_sockaddr_storage *addr)
if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) &&
in6->sin6_port == lin6->sin6_port)
{
if(listener->F == NULL)
last_closed = listener;
else
if(listener->F == NULL)
last_closed = listener;
else
return(listener);
}
break;
@ -374,7 +374,7 @@ add_listener(int port, const char *vhost_ip, int family)
}
if((listener = find_listener(&vaddr)))
{
if(listener->F != NULL)
if(listener->F != NULL)
return;
}
else
@ -401,10 +401,10 @@ close_listener(listener_t *listener)
s_assert(listener != NULL);
if(listener == NULL)
return;
if(listener->F != NULL)
{
rb_close(listener->F);
listener->F = NULL;
if(listener->F != NULL)
{
rb_close(listener->F);
listener->F = NULL;
}
listener->active = 0;
@ -441,7 +441,7 @@ close_listeners()
* The client is sent to the auth module for verification, and not put in
* any client list yet.
*/
static void
static void
add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int exempt)
{
struct Client *new_client;
@ -481,79 +481,79 @@ add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, int
start_auth(new_client);
}
static int
accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{
struct Listener *listener = (struct Listener *)data;
char buf[BUFSIZE];
struct ConfItem *aconf;
static time_t last_oper_notice = 0;
if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */
{
++ServerStats->is_ref;
/*
* slow down the whining to opers bit
*/
if((last_oper_notice + 20) <= rb_current_time())
{
sendto_realops_flags(SNO_GENERAL, L_ALL,
"All connections in use. (%s)",
get_listener_name(listener));
last_oper_notice = rb_current_time();
}
rb_write(F, "ERROR :All connections in use\r\n", 32);
rb_close(F);
/* Re-register a new IO request for the next accept .. */
return 0;
}
aconf = find_dline(addr, AF_INET);
if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))
return 1;
/* Do an initial check we aren't connecting too fast or with too many
* from this IP... */
if(aconf != NULL)
{
ServerStats->is_ref++;
if(ConfigFileEntry.dline_with_reason)
{
if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))
{
buf[sizeof(buf) - 3] = '\r';
buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0';
}
}
else
strcpy(buf, "ERROR :You have been D-lined.\r\n");
rb_write(F, buf, strlen(buf));
rb_close(F);
return 0;
}
return 1;
}
static void
accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{
struct Listener *listener = data;
struct rb_sockaddr_storage lip;
unsigned int locallen = sizeof(struct rb_sockaddr_storage);
ServerStats->is_ac++;
if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)
{
/* this shouldn't fail so... */
/* XXX add logging of this */
rb_close(F);
}
add_connection(listener, F, addr, 1);
static int
accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{
struct Listener *listener = (struct Listener *)data;
char buf[BUFSIZE];
struct ConfItem *aconf;
static time_t last_oper_notice = 0;
if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */
{
++ServerStats->is_ref;
/*
* slow down the whining to opers bit
*/
if((last_oper_notice + 20) <= rb_current_time())
{
sendto_realops_flags(SNO_GENERAL, L_ALL,
"All connections in use. (%s)",
get_listener_name(listener));
last_oper_notice = rb_current_time();
}
rb_write(F, "ERROR :All connections in use\r\n", 32);
rb_close(F);
/* Re-register a new IO request for the next accept .. */
return 0;
}
aconf = find_dline(addr, AF_INET);
if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE))
return 1;
/* Do an initial check we aren't connecting too fast or with too many
* from this IP... */
if(aconf != NULL)
{
ServerStats->is_ref++;
if(ConfigFileEntry.dline_with_reason)
{
if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1))
{
buf[sizeof(buf) - 3] = '\r';
buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0';
}
}
else
strcpy(buf, "ERROR :You have been D-lined.\r\n");
rb_write(F, buf, strlen(buf));
rb_close(F);
return 0;
}
return 1;
}
static void
accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data)
{
struct Listener *listener = data;
struct rb_sockaddr_storage lip;
unsigned int locallen = sizeof(struct rb_sockaddr_storage);
ServerStats->is_ac++;
if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0)
{
/* this shouldn't fail so... */
/* XXX add logging of this */
rb_close(F);
}
add_connection(listener, F, addr, 1);
}

View file

@ -165,63 +165,63 @@ flood_endgrace(struct Client *client_p)
client_p->localClient->sent_parsed = 0;
}
/*
* flood_recalc
*
* recalculate the number of allowed flood lines. this should be called
* once a second on any given client. We then attempt to flush some data.
*/
void
flood_recalc(void *unused)
{
rb_dlink_node *ptr, *next;
struct Client *client_p;
RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
{
client_p = ptr->data;
if(unlikely(IsMe(client_p)))
continue;
if(unlikely(client_p->localClient == NULL))
continue;
if(IsFloodDone(client_p))
client_p->localClient->sent_parsed -= 2;
else
client_p->localClient->sent_parsed = 0;
if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0;
parse_client_queued(client_p);
if(unlikely(IsAnyDead(client_p)))
continue;
}
RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
{
client_p = ptr->data;
if(client_p->localClient == NULL)
continue;
client_p->localClient->sent_parsed--;
if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0;
parse_client_queued(client_p);
}
/*
* flood_recalc
*
* recalculate the number of allowed flood lines. this should be called
* once a second on any given client. We then attempt to flush some data.
*/
void
flood_recalc(void *unused)
{
rb_dlink_node *ptr, *next;
struct Client *client_p;
RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
{
client_p = ptr->data;
if(unlikely(IsMe(client_p)))
continue;
if(unlikely(client_p->localClient == NULL))
continue;
if(IsFloodDone(client_p))
client_p->localClient->sent_parsed -= 2;
else
client_p->localClient->sent_parsed = 0;
if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0;
parse_client_queued(client_p);
if(unlikely(IsAnyDead(client_p)))
continue;
}
RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
{
client_p = ptr->data;
if(client_p->localClient == NULL)
continue;
client_p->localClient->sent_parsed--;
if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0;
parse_client_queued(client_p);
}
}
/*