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

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 "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 michael 887 { 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 michael 887
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 adx 30 */
76     static void
77 michael 887 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 adx 30 m_accept(struct Client *client_p, struct Client *source_p,
105     int parc, char *parv[])
106     {
107 michael 887 char *mask = NULL;
108 adx 30 char *p = NULL;
109 michael 887 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 adx 30 {
117     list_accepts(source_p);
118     return;
119     }
120    
121 michael 887 for (mask = strtoken(&p, parv[1], ","); mask != NULL;
122     mask = strtoken(&p, NULL, ","))
123 adx 30 {
124 michael 887 if (*mask == '-' && *++mask != '\0')
125 adx 30 {
126 michael 887 nuh.nuhmask = mask;
127     nuh.nickptr = nick;
128     nuh.userptr = user;
129     nuh.hostptr = host;
130 adx 30
131 michael 887 nuh.nicksize = sizeof(nick);
132     nuh.usersize = sizeof(user);
133     nuh.hostsize = sizeof(host);
134 adx 30
135 michael 887 split_nuh(&nuh);
136 adx 30
137 michael 887 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 adx 30
144 michael 887 del_accept(accept_p, source_p);
145 adx 30 }
146 michael 887 else if (*mask != '\0')
147 adx 30 {
148 michael 887 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 adx 30
156 michael 887 nuh.nuhmask = mask;
157     nuh.nickptr = nick;
158     nuh.userptr = user;
159     nuh.hostptr = host;
160 adx 30
161 michael 887 nuh.nicksize = sizeof(nick);
162     nuh.usersize = sizeof(user);
163     nuh.hostsize = sizeof(host);
164 adx 30
165 michael 887 split_nuh(&nuh);
166 adx 30
167 michael 887 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 adx 30 }
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 michael 887 DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
196 adx 30 {
197 michael 887 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 adx 30
202 michael 887 if ((t - nicks) + masklen + len > IRCD_BUFSIZE)
203 adx 30 {
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 michael 887 t += ircsprintf(t, "%s!%s@%s ",
211     accept_p->nickptr,
212     accept_p->userptr, accept_p->hostptr);
213 adx 30 }
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