ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_accept.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (4 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5976 byte(s)
Log Message:
- Bump copyright years

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 9857 * Copyright (c) 2000-2021 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * 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 "client.h"
29     #include "irc_string.h"
30     #include "ircd.h"
31     #include "list.h"
32     #include "numeric.h"
33 michael 1309 #include "conf.h"
34 adx 30 #include "send.h"
35     #include "parse.h"
36     #include "modules.h"
37 michael 1666 #include "memory.h"
38 adx 30
39    
40 michael 1007 /*! \brief Creates and sends a list of nick!user\@host masks a Client
41     * has on its acceptlist.
42 michael 887 *
43 michael 1007 * \param source_p The actual Client the list will be sent to.
44 adx 30 */
45     static void
46 michael 1007 list_accepts(struct Client *source_p)
47     {
48 michael 9344 char buf[IRCD_BUFSIZE];
49     char *bufptr = buf;
50 michael 7687 dlink_node *node;
51 michael 1007
52 michael 4955 /* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */
53 michael 4014 /* 1 23456 78 9 10 */
54 michael 9348 size_t len = strlen(me.name) + strlen(source_p->name) + 10;
55 michael 1007
56 michael 4815 DLINK_FOREACH(node, source_p->connection->acceptlist.head)
57 michael 1007 {
58 michael 4975 const struct split_nuh_item *accept_p = node->data;
59     size_t masklen = strlen(accept_p->nickptr) +
60     strlen(accept_p->userptr) +
61     strlen(accept_p->hostptr) + 3; /* +3 for ! + @ + space */
62 michael 1007
63 michael 9344 if ((bufptr - buf) + masklen + len > sizeof(buf))
64 michael 1007 {
65 michael 9344 *(bufptr - 1) = '\0';
66     sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, buf);
67     bufptr = buf;
68 michael 1007 }
69    
70 michael 9348 bufptr += snprintf(bufptr, sizeof(buf) - (bufptr - buf), "%s!%s@%s ",
71 michael 9346 accept_p->nickptr,
72     accept_p->userptr,
73     accept_p->hostptr);
74 michael 1007 }
75    
76 michael 9344 if (bufptr != buf)
77 michael 1007 {
78 michael 9344 *(bufptr - 1) = '\0';
79     sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, buf);
80 michael 1007 }
81    
82 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
83 michael 1007 }
84    
85     /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
86     * mask to a Client's acceptlist.
87     *
88     * \param nuh A split_nuh_item already prepared with required masks.
89     * \param source_p The actual Client the new accept is added to.
90     */
91     static void
92 michael 887 add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
93     {
94 michael 8431 struct split_nuh_item *accept_p = xcalloc(sizeof(*accept_p));
95 michael 887
96 michael 4975 accept_p->nickptr = xstrdup(nuh->nickptr);
97     accept_p->userptr = xstrdup(nuh->userptr);
98     accept_p->hostptr = xstrdup(nuh->hostptr);
99 michael 887
100 michael 4975 dlinkAdd(accept_p, &accept_p->node, &source_p->connection->acceptlist);
101 michael 887
102     list_accepts(source_p);
103     }
104    
105     /*! \brief ACCEPT command handler
106     *
107     * \param source_p Pointer to allocated Client struct from which the message
108     * originally comes from. This can be a local or remote client.
109     * \param parc Integer holding the number of supplied arguments.
110     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
111     * pointers.
112     * \note Valid arguments for this command are:
113 michael 3096 * - parv[0] = command
114 michael 3300 * - parv[1] = comma-separated list of masks to be accepted or removed
115 michael 887 */
116 michael 9077 static void
117 michael 3156 m_accept(struct Client *source_p, int parc, char *parv[])
118 adx 30 {
119 michael 6466 struct split_nuh_item nuh;
120     struct split_nuh_item *accept_p = NULL;
121 michael 9834 char nick[NICKLEN + 1];
122     char user[USERLEN + 1];
123     char host[HOSTLEN + 1];
124 michael 6466 char *p = NULL;
125     char *mask = collapse(parv[1]);
126 michael 887
127 michael 8603 if (EmptyString(mask) || strcmp(mask, "*") == 0)
128 adx 30 {
129     list_accepts(source_p);
130 michael 9077 return;
131 adx 30 }
132    
133 michael 6546 for (mask = strtok_r(mask, ",", &p); mask;
134     mask = strtok_r(NULL, ",", &p))
135 adx 30 {
136 michael 3605 if (*mask == '-' && *++mask)
137 adx 30 {
138 michael 887 nuh.nuhmask = mask;
139     nuh.nickptr = nick;
140     nuh.userptr = user;
141     nuh.hostptr = host;
142 adx 30
143 michael 887 nuh.nicksize = sizeof(nick);
144     nuh.usersize = sizeof(user);
145     nuh.hostsize = sizeof(host);
146 adx 30
147 michael 887 split_nuh(&nuh);
148 adx 30
149 michael 4975 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
150 michael 887 {
151 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
152 michael 887 continue;
153     }
154 adx 30
155 michael 4975 del_accept(accept_p, source_p);
156 adx 30 }
157 michael 3605 else if (*mask)
158 adx 30 {
159 michael 8431 if (dlink_list_length(&source_p->connection->acceptlist) >= ConfigGeneral.max_accept)
160 michael 887 {
161 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
162 michael 9077 return;
163 michael 887 }
164 adx 30
165 michael 887 nuh.nuhmask = mask;
166     nuh.nickptr = nick;
167     nuh.userptr = user;
168     nuh.hostptr = host;
169 adx 30
170 michael 887 nuh.nicksize = sizeof(nick);
171     nuh.usersize = sizeof(user);
172     nuh.hostsize = sizeof(host);
173 adx 30
174 michael 887 split_nuh(&nuh);
175 adx 30
176 michael 4975 if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
177 michael 887 {
178 michael 3109 sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
179 michael 887 continue;
180     }
181    
182     add_accept(&nuh, source_p);
183 adx 30 }
184     }
185     }
186 michael 1230
187 michael 2820 static struct Message accept_msgtab =
188     {
189 michael 5881 .cmd = "ACCEPT",
190 michael 9374 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
191     .handlers[CLIENT_HANDLER] = { .handler = m_accept },
192     .handlers[SERVER_HANDLER] = { .handler = m_ignore },
193     .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
194     .handlers[OPER_HANDLER] = { .handler = m_accept }
195 michael 1230 };
196    
197     static void
198     module_init(void)
199     {
200     mod_add_cmd(&accept_msgtab);
201     }
202    
203     static void
204     module_exit(void)
205     {
206     mod_del_cmd(&accept_msgtab);
207     }
208    
209 michael 2820 struct module module_entry =
210     {
211 michael 1230 .version = "$Revision$",
212     .modinit = module_init,
213     .modexit = module_exit,
214     };

Properties

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