client_p->localClient->ip.ss_family, NULL);
if (aconf == NULL || !(aconf->status & CONF_CLIENT))
return 0;
- if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->name, "webirc."))
+ if (!IsConfDoSpoofIp(aconf) || irccmp(aconf->info.name, "webirc."))
{
/* XXX */
sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block");
--- /dev/null
+#ifndef INCLUDED_operhash_h
+#define INCLUDED_operhash_h
+
+struct operhash_entry
+{
+ char *name;
+ int refcount;
+};
+
+void init_operhash(void);
+const char *operhash_add(const char *name);
+const char *operhash_find(const char *name);
+void operhash_delete(const char *name);
+
+#endif
unsigned int status; /* If CONF_ILLEGAL, delete when no clients */
unsigned int flags;
int clients; /* Number of *LOCAL* clients using this */
- char *name; /* IRC name, nick, server name, or original u@h */
+ union
+ {
+ char *name; /* IRC name, nick, server name, or original u@h */
+ const char *oper;
+ } info;
char *host; /* host part of user@host */
char *passwd; /* doubles as kline reason *ugh* */
char *spasswd; /* Password to send. */
/* Macros for struct ConfItem */
+#define IsConfBan(x) ((x)->status & (CONF_KILL|CONF_XLINE|CONF_DLINE|\
+ CONF_RESV_CHANNEL|CONF_RESV_NICK))
+
#define IsNoTilde(x) ((x)->flags & CONF_FLAGS_NO_TILDE)
#define IsNeedIdentd(x) ((x)->flags & CONF_FLAGS_NEED_IDENTD)
#define IsConfExemptKline(x) ((x)->flags & CONF_FLAGS_EXEMPTKLINE)
#include "parse.h"
#include "modules.h"
#include "bandbi.h"
+#include "operhash.h"
static int mo_dline(struct Client *, struct Client *, int, const char **);
static int me_dline(struct Client *, struct Client *, int, const char **);
aconf->created = rb_current_time();
aconf->host = rb_strdup(dlhost);
aconf->passwd = rb_strdup(reason);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
/* Look for an oper reason */
if((oper_reason = strchr(reason, '|')) != NULL)
#include "modules.h"
#include "reject.h"
#include "bandbi.h"
+#include "operhash.h"
static int mo_kline(struct Client *, struct Client *, int, const char **);
static int ms_kline(struct Client *, struct Client *, int, const char **);
aconf->user = rb_strdup(user);
aconf->port = 0;
aconf->passwd = rb_strdup(reason);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
/* Look for an oper reason */
if((oper_reason = strchr(reason, '|')) != NULL)
aconf->user = rb_strdup(user);
aconf->host = rb_strdup(host);
aconf->passwd = rb_strdup(reason);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
/* Look for an oper reason */
if((oper_reason = strchr(reason, '|')) != NULL)
#include "hash.h"
#include "logger.h"
#include "bandbi.h"
+#include "operhash.h"
static int mo_resv(struct Client *, struct Client *, int, const char **);
static int ms_resv(struct Client *, struct Client *, int, const char **);
aconf->created = rb_current_time();
aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
add_to_resv_hash(aconf->host, aconf);
resv_chan_forcepart(aconf->host, aconf->passwd, temp_time);
aconf->created = rb_current_time();
aconf->host = rb_strdup(name);
aconf->passwd = rb_strdup(reason);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
rb_dlinkAddAlloc(aconf, &resv_conf_list);
if(temp_time > 0)
if(aconf && aconf->status & CONF_CLIENT)
{
sendto_one_numeric(source_p, RPL_STATSILINE, form_str(RPL_STATSILINE),
- aconf->name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd,
+ aconf->info.name, EmptyString(aconf->spasswd) ? "<NULL>" : aconf->spasswd,
show_iline_prefix(source_p, aconf, aconf->user),
aconf->host, aconf->port, aconf->className);
return 0;
#include "s_newconf.h"
#include "reject.h"
#include "bandbi.h"
+#include "operhash.h"
static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
aconf->passwd = rb_strdup(reason);
collapse(aconf->host);
+ aconf->info.oper = operhash_add(get_oper_name(source_p));
+
if(temp_time > 0)
{
aconf->hold = rb_current_time() + temp_time;
monitor.c \
newconf.c \
numeric.c \
+ operhash.c \
packet.c \
parse.c \
privilege.c \
#include "send.h"
#include "ircd.h"
#include "msg.h" /* XXX: MAXPARA */
+#include "operhash.h"
static char bandb_add_letter[LAST_BANDB_TYPE] = {
'K', 'D', 'X', 'R'
aconf->user = rb_strdup(parv[para++]);
aconf->host = rb_strdup(parv[para++]);
- /* We do not have the 'oper' field yet. */
- para++;
+ aconf->info.oper = operhash_add(parv[para++]);
switch (parv[0][0])
{
/* if theres a spoof, check it against klines.. */
if(IsConfDoSpoofIp(iconf))
{
- char *p = strchr(iconf->name, '@');
+ char *p = strchr(iconf->info.name, '@');
/* note, we dont need to pass sockhost here, as its
* guaranteed to not match by whats above.. --anfl
if(p)
{
*p = '\0';
- kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->name, NULL);
+ kconf = find_conf_by_address(p+1, NULL, NULL, ip, CONF_KILL, aftype, iconf->info.name, NULL);
*p = '@';
}
else
- kconf = find_conf_by_address(iconf->name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL);
+ kconf = find_conf_by_address(iconf->info.name, NULL, NULL, ip, CONF_KILL, aftype, vuser, NULL);
if(kconf)
return kconf;
rb_dlink_node *ptr;
rb_dlink_node *next_ptr;
- if(EmptyString(yy_aconf->name))
- yy_aconf->name = rb_strdup("NOMATCH");
+ if(EmptyString(yy_aconf->info.name))
+ yy_aconf->info.name = rb_strdup("NOMATCH");
/* didnt even get one ->host? */
if(EmptyString(yy_aconf->host))
yy_tmp->spasswd = rb_strdup(yy_aconf->spasswd);
/* this will always exist.. */
- yy_tmp->name = rb_strdup(yy_aconf->name);
+ yy_tmp->info.name = rb_strdup(yy_aconf->info.name);
if(yy_aconf->className)
yy_tmp->className = rb_strdup(yy_aconf->className);
return;
}
- rb_free(yy_aconf->name);
- yy_aconf->name = rb_strdup(data);
+ rb_free(yy_aconf->info.name);
+ yy_aconf->info.name = rb_strdup(data);
yy_aconf->flags |= CONF_FLAGS_SPOOF_IP;
}
conf_set_auth_redir_serv(void *data)
{
yy_aconf->flags |= CONF_FLAGS_REDIR;
- rb_free(yy_aconf->name);
- yy_aconf->name = rb_strdup(data);
+ rb_free(yy_aconf->info.name);
+ yy_aconf->info.name = rb_strdup(data);
}
static void
--- /dev/null
+/* ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
+ * operhash.c - Hashes nick!user@host{oper}
+ *
+ * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk>
+ * Copyright (C) 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: operhash.c 26094 2008-09-19 15:33:46Z androsyn $
+ */
+#include <ratbox_lib.h>
+#include "stdinc.h"
+#include "match.h"
+#include "hash.h"
+#include "operhash.h"
+
+#define OPERHASH_MAX_BITS 7
+#define OPERHASH_MAX (1<<OPERHASH_MAX_BITS)
+
+#define hash_opername(x) fnv_hash_upper((const unsigned char *)(x), OPERHASH_MAX_BITS)
+
+static rb_dlink_list operhash_table[OPERHASH_MAX];
+
+const char *
+operhash_add(const char *name)
+{
+ struct operhash_entry *ohash;
+ unsigned int hashv;
+ rb_dlink_node *ptr;
+
+ if(EmptyString(name))
+ return NULL;
+
+ hashv = hash_opername(name);
+
+ RB_DLINK_FOREACH(ptr, operhash_table[hashv].head)
+ {
+ ohash = ptr->data;
+
+ if(!irccmp(ohash->name, name))
+ {
+ ohash->refcount++;
+ return ohash->name;
+ }
+ }
+
+ ohash = rb_malloc(sizeof(struct operhash_entry));
+ ohash->refcount = 1;
+ ohash->name = rb_strdup(name);
+
+ rb_dlinkAddAlloc(ohash, &operhash_table[hashv]);
+
+ return ohash->name;
+}
+
+const char *
+operhash_find(const char *name)
+{
+ struct operhash_entry *ohash;
+ unsigned int hashv;
+ rb_dlink_node *ptr;
+
+ if(EmptyString(name))
+ return NULL;
+
+ hashv = hash_opername(name);
+
+ RB_DLINK_FOREACH(ptr, operhash_table[hashv].head)
+ {
+ ohash = ptr->data;
+
+ if(!irccmp(ohash->name, name))
+ return ohash->name;
+ }
+
+ return NULL;
+}
+
+void
+operhash_delete(const char *name)
+{
+ struct operhash_entry *ohash;
+ unsigned int hashv;
+ rb_dlink_node *ptr;
+
+ if(EmptyString(name))
+ return;
+
+ hashv = hash_opername(name);
+
+ RB_DLINK_FOREACH(ptr, operhash_table[hashv].head)
+ {
+ ohash = ptr->data;
+
+ if(irccmp(ohash->name, name))
+ continue;
+
+ ohash->refcount--;
+
+ if(ohash->refcount == 0)
+ {
+ rb_free(ohash->name);
+ rb_free(ohash);
+ rb_dlinkDestroy(ptr, &operhash_table[hashv]);
+ return;
+ }
+ }
+}
#include "privilege.h"
#include "sslproc.h"
#include "bandbi.h"
+#include "operhash.h"
struct config_server_hide ConfigServerHide;
rb_free(aconf->passwd);
rb_free(aconf->spasswd);
- rb_free(aconf->name);
rb_free(aconf->className);
rb_free(aconf->user);
rb_free(aconf->host);
+ if(IsConfBan(aconf))
+ operhash_delete(aconf->info.oper);
+ else
+ rb_free(aconf->info.name);
+
rb_bh_free(confitem_heap, aconf);
}
if(aconf->flags & CONF_FLAGS_REDIR)
{
sendto_one_numeric(client_p, RPL_REDIR, form_str(RPL_REDIR),
- aconf->name ? aconf->name : "", aconf->port);
+ aconf->info.name ? aconf->info.name : "", aconf->port);
return (NOT_AUTHORISED);
}
sendto_realops_snomask(SNO_GENERAL, L_ALL,
"%s spoofing: %s as %s",
client_p->name,
- show_ip(NULL, client_p) ? client_p->host : aconf->name,
- aconf->name);
+ show_ip(NULL, client_p) ? client_p->host : aconf->info.name,
+ aconf->info.name);
}
/* user@host spoof */
- if((p = strchr(aconf->name, '@')) != NULL)
+ if((p = strchr(aconf->info.name, '@')) != NULL)
{
char *host = p+1;
*p = '\0';
- rb_strlcpy(client_p->username, aconf->name,
+ rb_strlcpy(client_p->username, aconf->info.name,
sizeof(client_p->username));
rb_strlcpy(client_p->host, host,
sizeof(client_p->host));
*p = '@';
}
else
- rb_strlcpy(client_p->host, aconf->name, sizeof(client_p->host));
+ rb_strlcpy(client_p->host, aconf->info.name, sizeof(client_p->host));
}
return (attach_iline(client_p, aconf));
}
static char null[] = "<NULL>";
static char zero[] = "default";
- *name = EmptyString(aconf->name) ? null : aconf->name;
+ *name = EmptyString(aconf->info.name) ? null : aconf->info.name;
*host = EmptyString(aconf->host) ? null : aconf->host;
*pass = EmptyString(aconf->passwd) ? null : aconf->passwd;
*user = EmptyString(aconf->user) ? null : aconf->user;
}
/* dont replace username if its supposed to be spoofed --fl */
- if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->name, '@'))
+ if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@'))
{
p = username;