| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 2000-2014 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 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 |
michael |
4564 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
1007 |
/*! \file m_accept.c |
| 23 |
|
|
* \brief Includes required functions for processing the ACCEPT command. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#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 |
michael |
1309 |
#include "conf.h" |
| 34 |
adx |
30 |
#include "send.h" |
| 35 |
|
|
#include "parse.h" |
| 36 |
|
|
#include "modules.h" |
| 37 |
michael |
1666 |
#include "memory.h" |
| 38 |
adx |
30 |
|
| 39 |
|
|
|
| 40 |
michael |
1007 |
/*! \brief Creates and sends a list of nick!user\@host masks a Client |
| 41 |
|
|
* has on its acceptlist. |
| 42 |
michael |
887 |
* |
| 43 |
michael |
1007 |
* \param source_p The actual Client the list will be sent to. |
| 44 |
adx |
30 |
*/ |
| 45 |
|
|
static void |
| 46 |
michael |
1007 |
list_accepts(struct Client *source_p) |
| 47 |
|
|
{ |
| 48 |
|
|
int len = 0; |
| 49 |
michael |
3246 |
char nicks[IRCD_BUFSIZE] = ""; |
| 50 |
michael |
1007 |
char *t = nicks; |
| 51 |
|
|
const dlink_node *ptr = NULL; |
| 52 |
|
|
|
| 53 |
michael |
4015 |
/* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */ |
| 54 |
|
|
/* 1 23456 78 9 10 */ |
| 55 |
michael |
4012 |
len = strlen(me.name) + strlen(source_p->name) + 10; |
| 56 |
michael |
1007 |
|
| 57 |
michael |
4589 |
DLINK_FOREACH(ptr, source_p->connection->acceptlist.head) |
| 58 |
michael |
1007 |
{ |
| 59 |
|
|
const struct split_nuh_item *accept_p = ptr->data; |
| 60 |
|
|
size_t masklen = strlen(accept_p->nickptr) + |
| 61 |
|
|
strlen(accept_p->userptr) + |
| 62 |
michael |
4042 |
strlen(accept_p->hostptr) + 3; /* +3 for ! + @ + space */ |
| 63 |
michael |
1007 |
|
| 64 |
michael |
4015 |
if ((t - nicks) + masklen + len > IRCD_BUFSIZE) |
| 65 |
michael |
1007 |
{ |
| 66 |
|
|
*(t - 1) = '\0'; |
| 67 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
| 68 |
michael |
1007 |
t = nicks; |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
michael |
1793 |
t += sprintf(t, "%s!%s@%s ", |
| 72 |
|
|
accept_p->nickptr, |
| 73 |
|
|
accept_p->userptr, accept_p->hostptr); |
| 74 |
michael |
1007 |
} |
| 75 |
|
|
|
| 76 |
michael |
3246 |
if (nicks[0]) |
| 77 |
michael |
1007 |
{ |
| 78 |
|
|
*(t - 1) = '\0'; |
| 79 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
| 80 |
michael |
1007 |
} |
| 81 |
|
|
|
| 82 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT); |
| 83 |
michael |
1007 |
} |
| 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 |
michael |
887 |
add_accept(const struct split_nuh_item *nuh, struct Client *source_p) |
| 93 |
|
|
{ |
| 94 |
michael |
3505 |
struct split_nuh_item *accept_p = MyCalloc(sizeof(*accept_p)); |
| 95 |
michael |
887 |
|
| 96 |
michael |
1646 |
accept_p->nickptr = xstrdup(nuh->nickptr); |
| 97 |
|
|
accept_p->userptr = xstrdup(nuh->userptr); |
| 98 |
|
|
accept_p->hostptr = xstrdup(nuh->hostptr); |
| 99 |
michael |
887 |
|
| 100 |
michael |
4589 |
dlinkAdd(accept_p, &accept_p->node, &source_p->connection->acceptlist); |
| 101 |
michael |
887 |
|
| 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 |
michael |
3096 |
* - parv[0] = command |
| 114 |
michael |
3300 |
* - parv[1] = comma-separated list of masks to be accepted or removed |
| 115 |
michael |
887 |
*/ |
| 116 |
michael |
2820 |
static int |
| 117 |
michael |
3156 |
m_accept(struct Client *source_p, int parc, char *parv[]) |
| 118 |
adx |
30 |
{ |
| 119 |
michael |
887 |
char *mask = NULL; |
| 120 |
adx |
30 |
char *p = NULL; |
| 121 |
michael |
3246 |
char nick[NICKLEN + 1] = ""; |
| 122 |
|
|
char user[USERLEN + 1] = ""; |
| 123 |
|
|
char host[HOSTLEN + 1] = ""; |
| 124 |
michael |
887 |
struct split_nuh_item nuh; |
| 125 |
|
|
struct split_nuh_item *accept_p = NULL; |
| 126 |
|
|
|
| 127 |
michael |
3370 |
if (EmptyString(parv[1]) || !strcmp(parv[1], "*")) |
| 128 |
adx |
30 |
{ |
| 129 |
|
|
list_accepts(source_p); |
| 130 |
michael |
2820 |
return 0; |
| 131 |
adx |
30 |
} |
| 132 |
|
|
|
| 133 |
michael |
3246 |
for (mask = strtoken(&p, parv[1], ","); mask; |
| 134 |
michael |
887 |
mask = strtoken(&p, NULL, ",")) |
| 135 |
adx |
30 |
{ |
| 136 |
michael |
3604 |
if (*mask == '-' && *++mask) |
| 137 |
adx |
30 |
{ |
| 138 |
michael |
887 |
nuh.nuhmask = mask; |
| 139 |
|
|
nuh.nickptr = nick; |
| 140 |
|
|
nuh.userptr = user; |
| 141 |
|
|
nuh.hostptr = host; |
| 142 |
adx |
30 |
|
| 143 |
michael |
887 |
nuh.nicksize = sizeof(nick); |
| 144 |
|
|
nuh.usersize = sizeof(user); |
| 145 |
|
|
nuh.hostsize = sizeof(host); |
| 146 |
adx |
30 |
|
| 147 |
michael |
887 |
split_nuh(&nuh); |
| 148 |
adx |
30 |
|
| 149 |
michael |
2363 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL) |
| 150 |
michael |
887 |
{ |
| 151 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host); |
| 152 |
michael |
887 |
continue; |
| 153 |
|
|
} |
| 154 |
adx |
30 |
|
| 155 |
michael |
887 |
del_accept(accept_p, source_p); |
| 156 |
adx |
30 |
} |
| 157 |
michael |
3604 |
else if (*mask) |
| 158 |
adx |
30 |
{ |
| 159 |
michael |
4589 |
if (dlink_list_length(&source_p->connection->acceptlist) >= |
| 160 |
michael |
4341 |
ConfigGeneral.max_accept) |
| 161 |
michael |
887 |
{ |
| 162 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL); |
| 163 |
michael |
2820 |
return 0; |
| 164 |
michael |
887 |
} |
| 165 |
adx |
30 |
|
| 166 |
michael |
887 |
nuh.nuhmask = mask; |
| 167 |
|
|
nuh.nickptr = nick; |
| 168 |
|
|
nuh.userptr = user; |
| 169 |
|
|
nuh.hostptr = host; |
| 170 |
adx |
30 |
|
| 171 |
michael |
887 |
nuh.nicksize = sizeof(nick); |
| 172 |
|
|
nuh.usersize = sizeof(user); |
| 173 |
|
|
nuh.hostsize = sizeof(host); |
| 174 |
adx |
30 |
|
| 175 |
michael |
887 |
split_nuh(&nuh); |
| 176 |
adx |
30 |
|
| 177 |
michael |
3246 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp))) |
| 178 |
michael |
887 |
{ |
| 179 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host); |
| 180 |
michael |
887 |
continue; |
| 181 |
|
|
} |
| 182 |
|
|
|
| 183 |
|
|
add_accept(&nuh, source_p); |
| 184 |
adx |
30 |
} |
| 185 |
|
|
} |
| 186 |
michael |
2820 |
|
| 187 |
|
|
return 0; |
| 188 |
adx |
30 |
} |
| 189 |
michael |
1230 |
|
| 190 |
michael |
2820 |
static struct Message accept_msgtab = |
| 191 |
|
|
{ |
| 192 |
michael |
4546 |
"ACCEPT", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 193 |
michael |
1230 |
{ m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore } |
| 194 |
|
|
}; |
| 195 |
|
|
|
| 196 |
|
|
static void |
| 197 |
|
|
module_init(void) |
| 198 |
|
|
{ |
| 199 |
|
|
mod_add_cmd(&accept_msgtab); |
| 200 |
|
|
} |
| 201 |
|
|
|
| 202 |
|
|
static void |
| 203 |
|
|
module_exit(void) |
| 204 |
|
|
{ |
| 205 |
|
|
mod_del_cmd(&accept_msgtab); |
| 206 |
|
|
} |
| 207 |
|
|
|
| 208 |
michael |
2820 |
struct module module_entry = |
| 209 |
|
|
{ |
| 210 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 211 |
|
|
.name = NULL, |
| 212 |
|
|
.version = "$Revision$", |
| 213 |
|
|
.handle = NULL, |
| 214 |
|
|
.modinit = module_init, |
| 215 |
|
|
.modexit = module_exit, |
| 216 |
|
|
.flags = 0 |
| 217 |
|
|
}; |