| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 2000-2015 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file m_accept.c |
| 23 |
* \brief Includes required functions for processing the ACCEPT command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "client.h" |
| 29 |
#include "irc_string.h" |
| 30 |
#include "ircd.h" |
| 31 |
#include "list.h" |
| 32 |
#include "numeric.h" |
| 33 |
#include "conf.h" |
| 34 |
#include "send.h" |
| 35 |
#include "parse.h" |
| 36 |
#include "modules.h" |
| 37 |
#include "memory.h" |
| 38 |
|
| 39 |
|
| 40 |
/*! \brief Creates and sends a list of nick!user\@host masks a Client |
| 41 |
* has on its acceptlist. |
| 42 |
* |
| 43 |
* \param source_p The actual Client the list will be sent to. |
| 44 |
*/ |
| 45 |
static void |
| 46 |
list_accepts(struct Client *source_p) |
| 47 |
{ |
| 48 |
int len = 0; |
| 49 |
char nicks[IRCD_BUFSIZE] = ""; |
| 50 |
char *t = nicks; |
| 51 |
const dlink_node *node = NULL; |
| 52 |
|
| 53 |
/* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */ |
| 54 |
/* 1 23456 78 9 10 */ |
| 55 |
len = strlen(me.name) + strlen(source_p->name) + 10; |
| 56 |
|
| 57 |
DLINK_FOREACH(node, source_p->connection->acceptlist.head) |
| 58 |
{ |
| 59 |
const struct split_nuh_item *accept_p = node->data; |
| 60 |
size_t masklen = strlen(accept_p->nickptr) + |
| 61 |
strlen(accept_p->userptr) + |
| 62 |
strlen(accept_p->hostptr) + 3; /* +3 for ! + @ + space */ |
| 63 |
|
| 64 |
if ((t - nicks) + masklen + len > IRCD_BUFSIZE) |
| 65 |
{ |
| 66 |
*(t - 1) = '\0'; |
| 67 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
| 68 |
t = nicks; |
| 69 |
} |
| 70 |
|
| 71 |
t += sprintf(t, "%s!%s@%s ", |
| 72 |
accept_p->nickptr, |
| 73 |
accept_p->userptr, accept_p->hostptr); |
| 74 |
} |
| 75 |
|
| 76 |
if (nicks[0]) |
| 77 |
{ |
| 78 |
*(t - 1) = '\0'; |
| 79 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
| 80 |
} |
| 81 |
|
| 82 |
sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT); |
| 83 |
} |
| 84 |
|
| 85 |
/*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host |
| 86 |
* mask to a Client's acceptlist. |
| 87 |
* |
| 88 |
* \param nuh A split_nuh_item already prepared with required masks. |
| 89 |
* \param source_p The actual Client the new accept is added to. |
| 90 |
*/ |
| 91 |
static void |
| 92 |
add_accept(const struct split_nuh_item *nuh, struct Client *source_p) |
| 93 |
{ |
| 94 |
struct split_nuh_item *const accept_p = MyCalloc(sizeof(*accept_p)); |
| 95 |
|
| 96 |
accept_p->nickptr = xstrdup(nuh->nickptr); |
| 97 |
accept_p->userptr = xstrdup(nuh->userptr); |
| 98 |
accept_p->hostptr = xstrdup(nuh->hostptr); |
| 99 |
|
| 100 |
dlinkAdd(accept_p, &accept_p->node, &source_p->connection->acceptlist); |
| 101 |
|
| 102 |
list_accepts(source_p); |
| 103 |
} |
| 104 |
|
| 105 |
/*! \brief ACCEPT command handler |
| 106 |
* |
| 107 |
* \param source_p Pointer to allocated Client struct from which the message |
| 108 |
* originally comes from. This can be a local or remote client. |
| 109 |
* \param parc Integer holding the number of supplied arguments. |
| 110 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 111 |
* pointers. |
| 112 |
* \note Valid arguments for this command are: |
| 113 |
* - parv[0] = command |
| 114 |
* - parv[1] = comma-separated list of masks to be accepted or removed |
| 115 |
*/ |
| 116 |
static int |
| 117 |
m_accept(struct Client *source_p, int parc, char *parv[]) |
| 118 |
{ |
| 119 |
struct split_nuh_item nuh; |
| 120 |
struct split_nuh_item *accept_p = NULL; |
| 121 |
char nick[NICKLEN + 1] = ""; |
| 122 |
char user[USERLEN + 1] = ""; |
| 123 |
char host[HOSTLEN + 1] = ""; |
| 124 |
char *p = NULL; |
| 125 |
char *mask = collapse(parv[1]); |
| 126 |
|
| 127 |
if (EmptyString(mask) || !strcmp(mask, "*")) |
| 128 |
{ |
| 129 |
list_accepts(source_p); |
| 130 |
return 0; |
| 131 |
} |
| 132 |
|
| 133 |
for (mask = strtok_r(mask, ",", &p); mask; |
| 134 |
mask = strtok_r(NULL, ",", &p)) |
| 135 |
{ |
| 136 |
if (*mask == '-' && *++mask) |
| 137 |
{ |
| 138 |
nuh.nuhmask = mask; |
| 139 |
nuh.nickptr = nick; |
| 140 |
nuh.userptr = user; |
| 141 |
nuh.hostptr = host; |
| 142 |
|
| 143 |
nuh.nicksize = sizeof(nick); |
| 144 |
nuh.usersize = sizeof(user); |
| 145 |
nuh.hostsize = sizeof(host); |
| 146 |
|
| 147 |
split_nuh(&nuh); |
| 148 |
|
| 149 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL) |
| 150 |
{ |
| 151 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host); |
| 152 |
continue; |
| 153 |
} |
| 154 |
|
| 155 |
del_accept(accept_p, source_p); |
| 156 |
} |
| 157 |
else if (*mask) |
| 158 |
{ |
| 159 |
if (dlink_list_length(&source_p->connection->acceptlist) >= |
| 160 |
ConfigGeneral.max_accept) |
| 161 |
{ |
| 162 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL); |
| 163 |
return 0; |
| 164 |
} |
| 165 |
|
| 166 |
nuh.nuhmask = mask; |
| 167 |
nuh.nickptr = nick; |
| 168 |
nuh.userptr = user; |
| 169 |
nuh.hostptr = host; |
| 170 |
|
| 171 |
nuh.nicksize = sizeof(nick); |
| 172 |
nuh.usersize = sizeof(user); |
| 173 |
nuh.hostsize = sizeof(host); |
| 174 |
|
| 175 |
split_nuh(&nuh); |
| 176 |
|
| 177 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp))) |
| 178 |
{ |
| 179 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host); |
| 180 |
continue; |
| 181 |
} |
| 182 |
|
| 183 |
add_accept(&nuh, source_p); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
return 0; |
| 188 |
} |
| 189 |
|
| 190 |
static struct Message accept_msgtab = |
| 191 |
{ |
| 192 |
.cmd = "ACCEPT", |
| 193 |
.args_max = MAXPARA, |
| 194 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
| 195 |
.handlers[CLIENT_HANDLER] = m_accept, |
| 196 |
.handlers[SERVER_HANDLER] = m_ignore, |
| 197 |
.handlers[ENCAP_HANDLER] = m_ignore, |
| 198 |
.handlers[OPER_HANDLER] = m_accept |
| 199 |
}; |
| 200 |
|
| 201 |
static void |
| 202 |
module_init(void) |
| 203 |
{ |
| 204 |
mod_add_cmd(&accept_msgtab); |
| 205 |
} |
| 206 |
|
| 207 |
static void |
| 208 |
module_exit(void) |
| 209 |
{ |
| 210 |
mod_del_cmd(&accept_msgtab); |
| 211 |
} |
| 212 |
|
| 213 |
struct module module_entry = |
| 214 |
{ |
| 215 |
.version = "$Revision$", |
| 216 |
.modinit = module_init, |
| 217 |
.modexit = module_exit, |
| 218 |
}; |