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