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 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* 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 "s_serv.h" |
35 |
|
|
#include "send.h" |
36 |
|
|
#include "parse.h" |
37 |
|
|
#include "modules.h" |
38 |
michael |
1666 |
#include "memory.h" |
39 |
adx |
30 |
|
40 |
|
|
|
41 |
michael |
1007 |
/*! \brief Creates and sends a list of nick!user\@host masks a Client |
42 |
|
|
* has on its acceptlist. |
43 |
michael |
887 |
* |
44 |
michael |
1007 |
* \param source_p The actual Client the list will be sent to. |
45 |
adx |
30 |
*/ |
46 |
|
|
static void |
47 |
michael |
1007 |
list_accepts(struct Client *source_p) |
48 |
|
|
{ |
49 |
|
|
int len = 0; |
50 |
|
|
char nicks[IRCD_BUFSIZE] = { '\0' }; |
51 |
|
|
char *t = nicks; |
52 |
|
|
const dlink_node *ptr = NULL; |
53 |
|
|
|
54 |
|
|
len = strlen(me.name) + strlen(source_p->name) + 12; |
55 |
|
|
|
56 |
|
|
DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head) |
57 |
|
|
{ |
58 |
|
|
const struct split_nuh_item *accept_p = ptr->data; |
59 |
|
|
size_t masklen = strlen(accept_p->nickptr) + |
60 |
|
|
strlen(accept_p->userptr) + |
61 |
|
|
strlen(accept_p->hostptr) + 2 /* !@ */ ; |
62 |
|
|
|
63 |
|
|
if ((t - nicks) + masklen + len > IRCD_BUFSIZE) |
64 |
|
|
{ |
65 |
|
|
*(t - 1) = '\0'; |
66 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
67 |
michael |
1007 |
t = nicks; |
68 |
|
|
} |
69 |
|
|
|
70 |
michael |
1793 |
t += sprintf(t, "%s!%s@%s ", |
71 |
|
|
accept_p->nickptr, |
72 |
|
|
accept_p->userptr, accept_p->hostptr); |
73 |
michael |
1007 |
} |
74 |
|
|
|
75 |
|
|
if (nicks[0] != '\0') |
76 |
|
|
{ |
77 |
|
|
*(t - 1) = '\0'; |
78 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks); |
79 |
michael |
1007 |
} |
80 |
|
|
|
81 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT); |
82 |
michael |
1007 |
} |
83 |
|
|
|
84 |
|
|
/*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host |
85 |
|
|
* mask to a Client's acceptlist. |
86 |
|
|
* |
87 |
|
|
* \param nuh A split_nuh_item already prepared with required masks. |
88 |
|
|
* \param source_p The actual Client the new accept is added to. |
89 |
|
|
*/ |
90 |
|
|
static void |
91 |
michael |
887 |
add_accept(const struct split_nuh_item *nuh, struct Client *source_p) |
92 |
|
|
{ |
93 |
|
|
struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p)); |
94 |
|
|
|
95 |
michael |
1646 |
accept_p->nickptr = xstrdup(nuh->nickptr); |
96 |
|
|
accept_p->userptr = xstrdup(nuh->userptr); |
97 |
|
|
accept_p->hostptr = xstrdup(nuh->hostptr); |
98 |
michael |
887 |
|
99 |
|
|
dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist); |
100 |
|
|
|
101 |
|
|
list_accepts(source_p); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
/*! \brief ACCEPT command handler |
105 |
|
|
* |
106 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
107 |
|
|
* originally comes from. This can be a local or remote client. |
108 |
|
|
* \param parc Integer holding the number of supplied arguments. |
109 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
110 |
|
|
* pointers. |
111 |
|
|
* \note Valid arguments for this command are: |
112 |
michael |
3096 |
* - parv[0] = command |
113 |
michael |
887 |
* - parv[1] = list of masks to be accepted or removed (optional) |
114 |
|
|
*/ |
115 |
michael |
2820 |
static int |
116 |
michael |
3156 |
m_accept(struct Client *source_p, int parc, char *parv[]) |
117 |
adx |
30 |
{ |
118 |
michael |
887 |
char *mask = NULL; |
119 |
adx |
30 |
char *p = NULL; |
120 |
michael |
887 |
char nick[NICKLEN + 1]; |
121 |
|
|
char user[USERLEN + 1]; |
122 |
|
|
char host[HOSTLEN + 1]; |
123 |
|
|
struct split_nuh_item nuh; |
124 |
|
|
struct split_nuh_item *accept_p = NULL; |
125 |
|
|
|
126 |
|
|
if (EmptyString(parv[1]) || !irccmp(parv[1], "*")) |
127 |
adx |
30 |
{ |
128 |
|
|
list_accepts(source_p); |
129 |
michael |
2820 |
return 0; |
130 |
adx |
30 |
} |
131 |
|
|
|
132 |
michael |
887 |
for (mask = strtoken(&p, parv[1], ","); mask != NULL; |
133 |
|
|
mask = strtoken(&p, NULL, ",")) |
134 |
adx |
30 |
{ |
135 |
michael |
887 |
if (*mask == '-' && *++mask != '\0') |
136 |
adx |
30 |
{ |
137 |
michael |
887 |
nuh.nuhmask = mask; |
138 |
|
|
nuh.nickptr = nick; |
139 |
|
|
nuh.userptr = user; |
140 |
|
|
nuh.hostptr = host; |
141 |
adx |
30 |
|
142 |
michael |
887 |
nuh.nicksize = sizeof(nick); |
143 |
|
|
nuh.usersize = sizeof(user); |
144 |
|
|
nuh.hostsize = sizeof(host); |
145 |
adx |
30 |
|
146 |
michael |
887 |
split_nuh(&nuh); |
147 |
adx |
30 |
|
148 |
michael |
2363 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL) |
149 |
michael |
887 |
{ |
150 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host); |
151 |
michael |
887 |
continue; |
152 |
|
|
} |
153 |
adx |
30 |
|
154 |
michael |
887 |
del_accept(accept_p, source_p); |
155 |
adx |
30 |
} |
156 |
michael |
887 |
else if (*mask != '\0') |
157 |
adx |
30 |
{ |
158 |
michael |
887 |
if (dlink_list_length(&source_p->localClient->acceptlist) >= |
159 |
|
|
ConfigFileEntry.max_accept) |
160 |
|
|
{ |
161 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL); |
162 |
michael |
2820 |
return 0; |
163 |
michael |
887 |
} |
164 |
adx |
30 |
|
165 |
michael |
887 |
nuh.nuhmask = mask; |
166 |
|
|
nuh.nickptr = nick; |
167 |
|
|
nuh.userptr = user; |
168 |
|
|
nuh.hostptr = host; |
169 |
adx |
30 |
|
170 |
michael |
887 |
nuh.nicksize = sizeof(nick); |
171 |
|
|
nuh.usersize = sizeof(user); |
172 |
|
|
nuh.hostsize = sizeof(host); |
173 |
adx |
30 |
|
174 |
michael |
887 |
split_nuh(&nuh); |
175 |
adx |
30 |
|
176 |
michael |
2363 |
if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) != NULL) |
177 |
michael |
887 |
{ |
178 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host); |
179 |
michael |
887 |
continue; |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
add_accept(&nuh, source_p); |
183 |
adx |
30 |
} |
184 |
|
|
} |
185 |
michael |
2820 |
|
186 |
|
|
return 0; |
187 |
adx |
30 |
} |
188 |
michael |
1230 |
|
189 |
michael |
2820 |
static struct Message accept_msgtab = |
190 |
|
|
{ |
191 |
michael |
1230 |
"ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
192 |
|
|
{ m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore } |
193 |
|
|
}; |
194 |
|
|
|
195 |
|
|
static void |
196 |
|
|
module_init(void) |
197 |
|
|
{ |
198 |
|
|
mod_add_cmd(&accept_msgtab); |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
static void |
202 |
|
|
module_exit(void) |
203 |
|
|
{ |
204 |
|
|
mod_del_cmd(&accept_msgtab); |
205 |
|
|
} |
206 |
|
|
|
207 |
michael |
2820 |
struct module module_entry = |
208 |
|
|
{ |
209 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
210 |
|
|
.name = NULL, |
211 |
|
|
.version = "$Revision$", |
212 |
|
|
.handle = NULL, |
213 |
|
|
.modinit = module_init, |
214 |
|
|
.modexit = module_exit, |
215 |
|
|
.flags = 0 |
216 |
|
|
}; |