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