ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_accept.c
(Generate patch)

Comparing:
ircd-hybrid/trunk/modules/m_accept.c (file contents), Revision 3246 by michael, Sun Mar 30 17:37:13 2014 UTC vs.
ircd-hybrid/branches/8.2.x/modules/m_accept.c (file contents), Revision 9347 by michael, Sat Apr 25 17:00:41 2020 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 2000-2014 ircd-hybrid development team
4 > *  Copyright (c) 2000-2020 ircd-hybrid development team
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
# Line 15 | Line 15
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
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 31 | Line 31
31   #include "list.h"
32   #include "numeric.h"
33   #include "conf.h"
34 #include "s_serv.h"
34   #include "send.h"
35   #include "parse.h"
36   #include "modules.h"
# Line 46 | Line 45
45   static void
46   list_accepts(struct Client *source_p)
47   {
48 <  int len = 0;
49 <  char nicks[IRCD_BUFSIZE] = "";
50 <  char *t = nicks;
51 <  const dlink_node *ptr = NULL;
48 >  char buf[IRCD_BUFSIZE];
49 >  char *bufptr = buf;
50 >  dlink_node *node;
51 >
52 >  /* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */
53 >  /* 1       23456              78                     9 10 */
54 >  size_t len = strlen(me.name) + strlen(source_p->name) + 10;
55  
56 <  len = strlen(me.name) + strlen(source_p->name) + 12;
55 <
56 <  DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head)
56 >  DLINK_FOREACH(node, source_p->connection->acceptlist.head)
57    {
58 <    const struct split_nuh_item *accept_p = ptr->data;
58 >    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) + 2 /* !@ */ ;
61 >                     strlen(accept_p->hostptr) + 3;  /* +3 for ! + @ + space */
62  
63 <    if ((t - nicks) + masklen + len  > IRCD_BUFSIZE)
63 >    if ((bufptr - buf) + masklen + len > sizeof(buf))
64      {
65 <      *(t - 1) = '\0';
66 <      sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
67 <      t = nicks;
65 >      *(bufptr - 1) = '\0';
66 >      sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, buf);
67 >      bufptr = buf;
68      }
69  
70 <    t += sprintf(t, "%s!%s@%s ",
71 <                 accept_p->nickptr,
72 <                 accept_p->userptr, accept_p->hostptr);
70 >    bufptr += snprintf(bufptr, sizeof(buf) - (bufptr - buf), "%s!%s@%s ",
71 >                       accept_p->nickptr,
72 >                       accept_p->userptr,
73 >                       accept_p->hostptr);
74    }
75  
76 <  if (nicks[0])
76 >  if (bufptr != buf)
77    {
78 <    *(t - 1) = '\0';
79 <    sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, nicks);
78 >    *(bufptr - 1) = '\0';
79 >    sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, buf);
80    }
81  
82    sendto_one_numeric(source_p, &me, RPL_ENDOFACCEPT);
# Line 90 | Line 91 | list_accepts(struct Client *source_p)
91   static void
92   add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
93   {
94 <  struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p));
94 >  struct split_nuh_item *accept_p = xcalloc(sizeof(*accept_p));
95  
96    accept_p->nickptr = xstrdup(nuh->nickptr);
97    accept_p->userptr = xstrdup(nuh->userptr);
98    accept_p->hostptr = xstrdup(nuh->hostptr);
99  
100 <  dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist);
100 >  dlinkAdd(accept_p, &accept_p->node, &source_p->connection->acceptlist);
101  
102    list_accepts(source_p);
103   }
# Line 110 | Line 111 | add_accept(const struct split_nuh_item *
111   *                 pointers.
112   * \note Valid arguments for this command are:
113   *      - parv[0] = command
114 < *      - parv[1] = list of masks to be accepted or removed (optional)
114 > *      - parv[1] = comma-separated list of masks to be accepted or removed
115   */
116 < static int
116 > static void
117   m_accept(struct Client *source_p, int parc, char *parv[])
118   {
119 <  char *mask = NULL;
120 <  char *p = NULL;
119 >  struct split_nuh_item nuh;
120 >  struct split_nuh_item *accept_p = NULL;
121    char nick[NICKLEN + 1] = "";
122    char user[USERLEN + 1] = "";
123    char host[HOSTLEN + 1] = "";
124 <  struct split_nuh_item nuh;
125 <  struct split_nuh_item *accept_p = NULL;
124 >  char *p = NULL;
125 >  char *mask = collapse(parv[1]);
126  
127 <  if (EmptyString(parv[1]) || !irccmp(parv[1], "*"))
127 >  if (EmptyString(mask) || strcmp(mask, "*") == 0)
128    {
129      list_accepts(source_p);
130 <    return 0;
130 >    return;
131    }
132  
133 <  for (mask = strtoken(&p, parv[1], ","); mask;
134 <       mask = strtoken(&p,    NULL, ","))
133 >  for (mask = strtok_r(mask, ",", &p); mask;
134 >       mask = strtok_r(NULL, ",", &p))
135    {
136 <    if (*mask == '-' && *++mask != '\0')
136 >    if (*mask == '-' && *++mask)
137      {
138        nuh.nuhmask  = mask;
139        nuh.nickptr  = nick;
# Line 153 | Line 154 | m_accept(struct Client *source_p, int pa
154  
155        del_accept(accept_p, source_p);
156      }
157 <    else if (*mask != '\0')
157 >    else if (*mask)
158      {
159 <      if (dlink_list_length(&source_p->localClient->acceptlist) >=
159 <          ConfigFileEntry.max_accept)
159 >      if (dlink_list_length(&source_p->connection->acceptlist) >= ConfigGeneral.max_accept)
160        {
161          sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
162 <        return 0;
162 >        return;
163        }
164  
165        nuh.nuhmask  = mask;
# Line 182 | Line 182 | m_accept(struct Client *source_p, int pa
182        add_accept(&nuh, source_p);
183      }
184    }
185
186  return 0;
185   }
186  
187   static struct Message accept_msgtab =
188   {
189 <  "ACCEPT", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
190 <  { m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore }
189 >  .cmd = "ACCEPT",
190 >  .args_max = MAXPARA,
191 >  .handlers[UNREGISTERED_HANDLER] = m_unregistered,
192 >  .handlers[CLIENT_HANDLER] = m_accept,
193 >  .handlers[SERVER_HANDLER] = m_ignore,
194 >  .handlers[ENCAP_HANDLER] = m_ignore,
195 >  .handlers[OPER_HANDLER] = m_accept
196   };
197  
198   static void
# Line 206 | Line 209 | module_exit(void)
209  
210   struct module module_entry =
211   {
209  .node    = { NULL, NULL, NULL },
210  .name    = NULL,
212    .version = "$Revision$",
212  .handle  = NULL,
213    .modinit = module_init,
214    .modexit = module_exit,
215  .flags   = 0
215   };

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)