ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_accept.c
Revision: 235
Committed: Sat Nov 5 11:31:51 2005 UTC (20 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 6346 byte(s)
Log Message:
- Fixed and cleaned up new acceptcode, e.g fix memory leaks,
  don't allow wildcards in a mask when removing accepts, don't
  allow redundant masks etc.

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "hash.h" /* for find_client() */
29     #include "ircd.h"
30     #include "numeric.h"
31     #include "s_conf.h"
32     #include "s_serv.h"
33     #include "send.h"
34     #include "msg.h"
35     #include "parse.h"
36     #include "s_user.h"
37     #include "modules.h"
38    
39     static void m_accept(struct Client *, struct Client *, int, char *[]);
40 db 232 static void build_nuh_list(struct Client *, char *, char *, char *);
41 michael 235 static void add_accept(const char *, const char *, const char *, struct Client *);
42     static int del_accept(const char *, const char *, const char *, struct Client *);
43 adx 30 static void list_accepts(struct Client *);
44    
45     struct Message accept_msgtab = {
46 michael 235 "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
47     { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
48 adx 30 };
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 knight 31 const char *_version = "$Revision$";
64 adx 30 #endif
65    
66     /*
67     * m_accept - ACCEPT command handler
68     * parv[0] = sender prefix
69     * parv[1] = servername
70     */
71     static void
72     m_accept(struct Client *client_p, struct Client *source_p,
73     int parc, char *parv[])
74     {
75 michael 235 struct Accept *accept = NULL;
76 db 232 char *mask, *nick, *user, *host;
77 adx 30 char *p = NULL;
78     char addbuf[IRCD_BUFSIZE] = { '\0' };
79     char delbuf[IRCD_BUFSIZE] = { '\0' };
80 michael 235 int accept_num = 0;
81 adx 30
82 db 232 if (parc < 2)
83 adx 30 {
84     list_accepts(source_p);
85     return;
86     }
87    
88 db 232 build_nuh_list(source_p, addbuf, delbuf, parv[1]);
89 adx 30
90     /* parse the delete list */
91 db 232 for (mask = strtoken(&p, delbuf, ","); mask != NULL;
92 michael 235 mask = strtoken(&p, NULL, ","))
93 adx 30 {
94 db 232 /* user isn't on clients accept list */
95     split_nuh(mask, &nick, &user, &host);
96 michael 235
97     if ((accept = find_accept(nick, user, host, source_p, 0)) == NULL)
98 adx 30 {
99     sendto_one(source_p, form_str(ERR_ACCEPTNOT),
100 db 232 me.name, source_p->name, nick, user, host);
101 michael 235 MyFree(nick);
102     MyFree(user);
103     MyFree(host);
104 adx 30 continue;
105     }
106    
107 michael 235 del_accept(accept, source_p);
108    
109     MyFree(nick);
110     MyFree(user);
111     MyFree(host);
112 adx 30 }
113    
114     /* get the number of accepts they have */
115 db 232 accept_num = dlink_list_length(&source_p->localClient->acceptlist);
116 adx 30
117     /* parse the add list */
118 db 232 for (mask = strtoken(&p, addbuf, ","); mask;
119 michael 235 mask = strtoken(&p, NULL, ","), ++accept_num)
120 adx 30 {
121 db 232 /* user is already on clients accept list */
122     split_nuh(mask, &nick, &user, &host);
123 adx 30
124 michael 235 if ((accept = find_accept(nick, user, host, source_p, 0)) != NULL)
125 adx 30 {
126     sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
127 db 232 me.name, source_p->name, nick, user, host);
128 michael 235 MyFree(nick);
129     MyFree(user);
130     MyFree(host);
131 adx 30 continue;
132     }
133    
134     if (accept_num >= ConfigFileEntry.max_accept)
135     {
136     sendto_one(source_p, form_str(ERR_ACCEPTFULL),
137     me.name, source_p->name);
138 michael 235 MyFree(nick);
139     MyFree(user);
140     MyFree(host);
141 adx 30 return;
142     }
143 db 232
144     add_accept(nick, user, host, source_p);
145 michael 235 MyFree(nick);
146     MyFree(user);
147     MyFree(host);
148 adx 30 }
149     }
150    
151 db 232 /* build_nuh_list()
152 adx 30 *
153     * input - pointer to client
154     * - pointer to addbuffer
155     * - pointer to remove buffer
156     * - pointer to list of nicks
157 db 232 * - pointer to list of nicks!user@host
158 adx 30 * output -
159 db 232 * side effects - addbuf/delbuf are modified to give valid masks
160 adx 30 */
161     static void
162 db 232 build_nuh_list(struct Client *source_p, char *addbuf,
163 michael 235 char *delbuf, char *mask)
164 adx 30 {
165 db 232 char *mask = NULL;
166 adx 30 char *p = NULL;
167 michael 235 char *buf_p = NULL;
168 adx 30
169 db 232 *addbuf = *delbuf = '\0';
170    
171     /* build list of nuh to add into addbuf, nuh to remove in delbuf */
172 michael 235 for (mask = strtoken(&p, mask, ","); mask;
173 db 232 mask = strtoken(&p, NULL, ","))
174 adx 30 {
175 db 232 if (*mask == '-')
176 michael 235 buf_p = delbuf, ++name;
177     else
178     buf_p = addbuf;
179 db 232
180 michael 235 if (*buf_p)
181     strlcat(buf_p, ",", IRCD_BUFSIZE);
182     strlcat(buf_p, mask, IRCD_BUFSIZE);
183 adx 30 }
184     }
185    
186     /* add_accept()
187     *
188 db 232 * input - nick
189     * - username
190     * - host
191     * - pointer to client to add to acceptlist
192 adx 30 * output - none
193     * side effects - target is added to clients list
194     */
195     static void
196 michael 235 add_accept(const char *nick, const char *user,
197     const char *host, struct Client *source_p)
198 adx 30 {
199 michael 235 struct Accept *accept = MyMalloc(sizeof(*accept));
200    
201     DupString(accept->nick, nick);
202     DupString(accept->user, user);
203 db 232 DupString(accept->host, host);
204 michael 235
205 db 232 dlinkAdd(accept, &accept->node, &source_p->localClient->acceptlist);
206    
207 adx 30 list_accepts(source_p);
208     }
209    
210     /* list_accepts()
211     *
212     * input - pointer to client
213     * output - none
214     * side effects - print accept list to client
215     */
216     static void
217     list_accepts(struct Client *source_p)
218     {
219 db 232 struct Accept *accept;
220 adx 30 int len = 0;
221 db 232 char nuh_list[IRCD_BUFSIZE] = { '\0' };
222     char *t = nuh_list;
223 adx 30 const dlink_node *ptr = NULL;
224    
225     len = strlen(me.name) + strlen(source_p->name) + 12;
226    
227 db 232 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
228 adx 30 {
229 db 232 accept = ptr->data;
230 adx 30
231 db 232 if ((t - nuh_list) + strlen(source_p->name) + len > IRCD_BUFSIZE)
232 adx 30 {
233     *(t - 1) = '\0';
234     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
235 db 232 me.name, source_p->name, nuh_list);
236     t = nuh_list;
237 adx 30 }
238    
239 db 232 t += ircsprintf(t, "%s!%s@%s ",
240 michael 235 accept->nick, accept->user, accept->host);
241 adx 30 }
242    
243 db 232 if (nuh_list[0] != '\0')
244 adx 30 {
245     *(t - 1) = '\0';
246     sendto_one(source_p, form_str(RPL_ACCEPTLIST),
247 db 232 me.name, source_p->name, nuh_list);
248 adx 30 }
249    
250     sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
251     me.name, source_p->name);
252     }

Properties

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