ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_accept.c
Revision: 887
Committed: Thu Nov 1 11:54:48 2007 UTC (16 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 6154 byte(s)
Log Message:
- Backported new ACCEPT code which adds support for n!u@h masks

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_accept.c: Allows a user to talk to a +g user.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "handlers.h"
27 #include "client.h"
28 #include "irc_string.h"
29 #include "sprintf_irc.h"
30 #include "hash.h" /* for find_client() */
31 #include "ircd.h"
32 #include "list.h"
33 #include "numeric.h"
34 #include "s_conf.h"
35 #include "s_serv.h"
36 #include "send.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "s_user.h"
40 #include "modules.h"
41
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
43 static void list_accepts(struct Client *);
44
45 struct Message accept_msgtab = {
46 "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
47 { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
48 };
49
50 #ifndef STATIC_MODULES
51 void
52 _modinit(void)
53 {
54 mod_add_cmd(&accept_msgtab);
55 }
56
57 void
58 _moddeinit(void)
59 {
60 mod_del_cmd(&accept_msgtab);
61 }
62
63 const char *_version = "$Revision$";
64 #endif
65
66
67 /* add_accept()
68 *
69 * input - pointer to preallocated nick
70 * - pointer to preallocated username
71 * - pointer to preallocated host
72 * - pointer to client to add to acceptlist
73 * output - none
74 * side effects - target is added to clients list
75 */
76 static void
77 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
78 {
79 struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
80
81 DupString(accept_p->nickptr, nuh->nickptr);
82 DupString(accept_p->userptr, nuh->userptr);
83 DupString(accept_p->hostptr, nuh->hostptr);
84
85 dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
86
87 list_accepts(source_p);
88 }
89
90 /*! \brief ACCEPT command handler
91 *
92 * \param client_p Pointer to allocated Client struct with physical connection
93 * to this server, i.e. with an open socket connected.
94 * \param source_p Pointer to allocated Client struct from which the message
95 * originally comes from. This can be a local or remote client.
96 * \param parc Integer holding the number of supplied arguments.
97 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
98 * pointers.
99 * \note Valid arguments for this command are:
100 * - parv[0] = sender prefix
101 * - parv[1] = list of masks to be accepted or removed (optional)
102 */
103 static void
104 m_accept(struct Client *client_p, struct Client *source_p,
105 int parc, char *parv[])
106 {
107 char *mask = NULL;
108 char *p = NULL;
109 char nick[NICKLEN + 1];
110 char user[USERLEN + 1];
111 char host[HOSTLEN + 1];
112 struct split_nuh_item nuh;
113 struct split_nuh_item *accept_p = NULL;
114
115 if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
116 {
117 list_accepts(source_p);
118 return;
119 }
120
121 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
122 mask = strtoken(&p, NULL, ","))
123 {
124 if (*mask == '-' && *++mask != '\0')
125 {
126 nuh.nuhmask = mask;
127 nuh.nickptr = nick;
128 nuh.userptr = user;
129 nuh.hostptr = host;
130
131 nuh.nicksize = sizeof(nick);
132 nuh.usersize = sizeof(user);
133 nuh.hostsize = sizeof(host);
134
135 split_nuh(&nuh);
136
137 if ((accept_p = find_accept(nick, user, host, source_p, 0)) == NULL)
138 {
139 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
140 me.name, source_p->name, nick, user, host);
141 continue;
142 }
143
144 del_accept(accept_p, source_p);
145 }
146 else if (*mask != '\0')
147 {
148 if (dlink_list_length(&source_p->localClient->acceptlist) >=
149 ConfigFileEntry.max_accept)
150 {
151 sendto_one(source_p, form_str(ERR_ACCEPTFULL),
152 me.name, source_p->name);
153 return;
154 }
155
156 nuh.nuhmask = mask;
157 nuh.nickptr = nick;
158 nuh.userptr = user;
159 nuh.hostptr = host;
160
161 nuh.nicksize = sizeof(nick);
162 nuh.usersize = sizeof(user);
163 nuh.hostsize = sizeof(host);
164
165 split_nuh(&nuh);
166
167 if ((accept_p = find_accept(nick, user, host, source_p, 0)) != NULL)
168 {
169 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
170 me.name, source_p->name, nick, user, host);
171 continue;
172 }
173
174 add_accept(&nuh, source_p);
175 }
176 }
177 }
178
179 /* list_accepts()
180 *
181 * input - pointer to client
182 * output - none
183 * side effects - print accept list to client
184 */
185 static void
186 list_accepts(struct Client *source_p)
187 {
188 int len = 0;
189 char nicks[IRCD_BUFSIZE] = { '\0' };
190 char *t = nicks;
191 const dlink_node *ptr = NULL;
192
193 len = strlen(me.name) + strlen(source_p->name) + 12;
194
195 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
196 {
197 const struct split_nuh_item *accept_p = ptr->data;
198 size_t masklen = strlen(accept_p->nickptr) +
199 strlen(accept_p->userptr) +
200 strlen(accept_p->hostptr) + 2 /* !@ */ ;
201
202 if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
203 {
204 *(t - 1) = '\0';
205 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
206 me.name, source_p->name, nicks);
207 t = nicks;
208 }
209
210 t += ircsprintf(t, "%s!%s@%s ",
211 accept_p->nickptr,
212 accept_p->userptr, accept_p->hostptr);
213 }
214
215 if (nicks[0] != '\0')
216 {
217 *(t - 1) = '\0';
218 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
219 me.name, source_p->name, nicks);
220 }
221
222 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
223 me.name, source_p->name);
224 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision