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/modules/m_accept.c (file contents), Revision 33 by knight, Sun Oct 2 20:50:00 2005 UTC vs.
ircd-hybrid/branches/8.2.x/modules/m_accept.c (file contents), Revision 9345 by michael, Sat Apr 25 16:42:46 2020 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_accept.c: Allows a user to talk to a +g user.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
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 16 | 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 < *  $Id$
20 > */
21 >
22 > /*! \file m_accept.c
23 > * \brief Includes required functions for processing the ACCEPT command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
26 #include "handlers.h"
28   #include "client.h"
29   #include "irc_string.h"
29 #include "sprintf_irc.h"
30 #include "hash.h"       /* for find_client() */
30   #include "ircd.h"
31   #include "list.h"
32   #include "numeric.h"
33 < #include "s_conf.h"
35 < #include "s_serv.h"
33 > #include "conf.h"
34   #include "send.h"
37 #include "msg.h"
35   #include "parse.h"
39 #include "s_user.h"
36   #include "modules.h"
37 + #include "memory.h"
38  
42 static void m_accept(struct Client *, struct Client *, int, char *[]);
43 static void build_nicklist(struct Client *, char *, char *, char *);
44 static void add_accept(struct Client *, struct Client *);
45 static void list_accepts(struct Client *);
46
47 struct Message accept_msgtab = {
48  "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
49  {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
50 };
51
52 #ifndef STATIC_MODULES
53 void
54 _modinit(void)
55 {
56  mod_add_cmd(&accept_msgtab);
57 }
58
59 void
60 _moddeinit(void)
61 {
62  mod_del_cmd(&accept_msgtab);
63 }
64
65 const char *_version = "$Revision$";
66 #endif
39  
40 < /*
41 < * m_accept - ACCEPT command handler
42 < *      parv[0] = sender prefix
43 < *      parv[1] = servername
40 > /*! \brief Creates and sends a list of nick!user\@host masks a Client
41 > *         has on its acceptlist.
42 > *
43 > * \param source_p The actual Client the list will be sent to.
44   */
45   static void
46 < m_accept(struct Client *client_p, struct Client *source_p,
75 <         int parc, char *parv[])
46 > list_accepts(struct Client *source_p)
47   {
48 <  char *nick;
49 <  char *p = NULL;
50 <  char addbuf[IRCD_BUFSIZE] = { '\0' };
80 <  char delbuf[IRCD_BUFSIZE] = { '\0' };
81 <  struct Client *target_p = NULL;
82 <  int accept_num;
83 <  
84 <  if ((parc < 2) || (*parv[1] == '*'))
85 <  {
86 <    list_accepts(source_p);
87 <    return;
88 <  }
48 >  char buf[IRCD_BUFSIZE];
49 >  char *bufptr = buf;
50 >  dlink_node *node;
51  
52 <  build_nicklist(source_p, addbuf, delbuf, parv[1]);
52 >  /* :me.name 281 source_p->name :n1!u1@h1 n2!u2@h2 ...\r\n */
53 >  /* 1       23456              78                     9 10 */
54 >  int len = strlen(me.name) + strlen(source_p->name) + 10;
55  
56 <  /* parse the delete list */
93 <  for (nick = strtoken(&p, delbuf, ","); nick != NULL;
94 <       nick = strtoken(&p, NULL, ","))
56 >  DLINK_FOREACH(node, source_p->connection->acceptlist.head)
57    {
58 <    /* shouldnt happen, but lets be paranoid */
59 <    if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
60 <    {
61 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
100 <                 me.name, source_p->name, nick);
101 <      continue;
102 <    }
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) + 3;  /* +3 for ! + @ + space */
62  
63 <    /* user isnt on clients accept list */
105 <    if (!accept_message(target_p, source_p))
63 >    if ((bufptr - buf) + masklen + len > sizeof(buf))
64      {
65 <      sendto_one(source_p, form_str(ERR_ACCEPTNOT),
66 <                 me.name, source_p->name, target_p->name);
67 <      continue;
65 >      *(bufptr - 1) = '\0';
66 >      sendto_one_numeric(source_p, &me, RPL_ACCEPTLIST, buf);
67 >      bufptr = buf;
68      }
69  
70 <    del_from_accept(target_p, source_p);
70 >    bufptr += snprintf(bufptr, sizeof(buf) - (buf - bufptr), "%s!%s@%s ",
71 >                       accept_p->nickptr,
72 >                       accept_p->userptr,
73 >                       accept_p->hostptr);
74    }
75  
76 <  /* get the number of accepts they have */
116 <  accept_num = dlink_list_length(&source_p->allow_list);
117 <
118 <  /* parse the add list */
119 <  for (nick = strtoken(&p, addbuf, ","); nick;
120 <       nick = strtoken(&p, NULL, ","), accept_num++)
76 >  if (bufptr != buf)
77    {
78 <    /* shouldnt happen, but lets be paranoid */
79 <    if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
124 <    {
125 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
126 <                 me.name, source_p->name, nick);
127 <      continue;
128 <    }
129 <
130 <    /* user is already on clients accept list */
131 <    if (accept_message(target_p, source_p))
132 <    {
133 <      sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
134 <                 me.name, source_p->name, target_p->name);
135 <      continue;
136 <    }
137 <
138 <    if (accept_num >= ConfigFileEntry.max_accept)
139 <    {
140 <      sendto_one(source_p, form_str(ERR_ACCEPTFULL),
141 <                 me.name, source_p->name);
142 <      return;
143 <    }
144 <      
145 <    /* why is this here? */
146 <    /* del_from accept(target_p, source_p); */
147 <    add_accept(source_p, target_p);
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);
83   }
84  
85 < /* build_nicklist()
85 > /*! \brief Allocates and adds a split_nuh_item holding a nick!user\@host
86 > *         mask to a Client's acceptlist.
87   *
88 < * input        - pointer to client
89 < *              - pointer to addbuffer
155 < *              - pointer to remove buffer
156 < *              - pointer to list of nicks
157 < * output       -
158 < * side effects - addbuf/delbuf are modified to give valid nicks
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 < build_nicklist(struct Client *source_p, char *addbuf,
162 <               char *delbuf, char *nicks)
92 > add_accept(const struct split_nuh_item *nuh, struct Client *source_p)
93   {
94 <  char *name = NULL;
165 <  char *p = NULL;
166 <  char *buf_p = NULL;
167 <  struct Client *target_p = NULL;
94 >  struct split_nuh_item *accept_p = xcalloc(sizeof(*accept_p));
95  
96 <  /* build list of clients to add into addbuf, clients to remove in delbuf */
97 <  for (name = strtoken(&p, nicks, ","); name;
98 <       name = strtoken(&p, NULL, ","))
172 <  {
173 <    if (*name == '-')
174 <      buf_p = delbuf, ++name;
175 <    else
176 <      buf_p = addbuf;
96 >  accept_p->nickptr = xstrdup(nuh->nickptr);
97 >  accept_p->userptr = xstrdup(nuh->userptr);
98 >  accept_p->hostptr = xstrdup(nuh->hostptr);
99  
100 <    if (((target_p = find_client(name)) == NULL) || !IsClient(target_p))
179 <    {
180 <      sendto_one(source_p, form_str(ERR_NOSUCHNICK),
181 <                 me.name, source_p->name, name);
182 <      continue;
183 <    }
100 >  dlinkAdd(accept_p, &accept_p->node, &source_p->connection->acceptlist);
101  
185    if (*buf_p)
186      strlcat(buf_p, ",", IRCD_BUFSIZE);
187    strlcat(buf_p, name, IRCD_BUFSIZE);
188  }
189 }
190
191 /* add_accept()
192 *
193 * input        - pointer to clients accept list to add to
194 *              - pointer to client to add
195 * output       - none
196 * side effects - target is added to clients list
197 */
198 static void
199 add_accept(struct Client *source_p, struct Client *target_p)
200 {
201  dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list);
202  dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list);
102    list_accepts(source_p);
103   }
104  
105 < /* list_accepts()
105 > /*! \brief ACCEPT command handler
106   *
107 < * input        - pointer to client
108 < * output       - none
109 < * side effects - print accept list to client
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 > *      - parv[0] = command
114 > *      - parv[1] = comma-separated list of masks to be accepted or removed
115   */
116   static void
117 < list_accepts(struct Client *source_p)
117 > m_accept(struct Client *source_p, int parc, char *parv[])
118   {
119 <  int len = 0;
120 <  char nicks[IRCD_BUFSIZE] = { '\0' };
121 <  char *t = nicks;
122 <  const dlink_node *ptr = NULL;
123 <
124 <  len = strlen(me.name) + strlen(source_p->name) + 12;
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 >  char *p = NULL;
125 >  char *mask = collapse(parv[1]);
126  
127 <  DLINK_FOREACH(ptr, source_p->allow_list.head)
127 >  if (EmptyString(mask) || strcmp(mask, "*") == 0)
128    {
129 <    const struct Client *target_p = ptr->data;
129 >    list_accepts(source_p);
130 >    return;
131 >  }
132  
133 <    if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE)
133 >  for (mask = strtok_r(mask, ",", &p); mask;
134 >       mask = strtok_r(NULL, ",", &p))
135 >  {
136 >    if (*mask == '-' && *++mask)
137      {
138 <      *(t - 1) = '\0';
139 <      sendto_one(source_p, form_str(RPL_ACCEPTLIST),
140 <                 me.name, source_p->name, nicks);
141 <      t = nicks;
138 >      nuh.nuhmask  = mask;
139 >      nuh.nickptr  = nick;
140 >      nuh.userptr  = user;
141 >      nuh.hostptr  = host;
142 >
143 >      nuh.nicksize = sizeof(nick);
144 >      nuh.usersize = sizeof(user);
145 >      nuh.hostsize = sizeof(host);
146 >
147 >      split_nuh(&nuh);
148 >
149 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)) == NULL)
150 >      {
151 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTNOT, nick, user, host);
152 >        continue;
153 >      }
154 >
155 >      del_accept(accept_p, source_p);
156      }
157 +    else if (*mask)
158 +    {
159 +      if (dlink_list_length(&source_p->connection->acceptlist) >= ConfigGeneral.max_accept)
160 +      {
161 +        sendto_one_numeric(source_p, &me, ERR_ACCEPTFULL);
162 +        return;
163 +      }
164  
165 <    t += ircsprintf(t, "%s ", target_p->name);
166 <  }
165 >      nuh.nuhmask  = mask;
166 >      nuh.nickptr  = nick;
167 >      nuh.userptr  = user;
168 >      nuh.hostptr  = host;
169  
170 <  if (nicks[0] != '\0')
171 <  {
172 <    *(t - 1) = '\0';
173 <    sendto_one(source_p, form_str(RPL_ACCEPTLIST),
174 <               me.name, source_p->name, nicks);
170 >      nuh.nicksize = sizeof(nick);
171 >      nuh.usersize = sizeof(user);
172 >      nuh.hostsize = sizeof(host);
173 >
174 >      split_nuh(&nuh);
175 >
176 >      if ((accept_p = find_accept(nick, user, host, source_p, irccmp)))
177 >      {
178 >        sendto_one_numeric(source_p, &me, ERR_ACCEPTEXIST, nick, user, host);
179 >        continue;
180 >      }
181 >
182 >      add_accept(&nuh, source_p);
183 >    }
184    }
185 + }
186  
187 <  sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
188 <             me.name, source_p->name);
187 > static struct Message accept_msgtab =
188 > {
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
199 > module_init(void)
200 > {
201 >  mod_add_cmd(&accept_msgtab);
202   }
203 +
204 + static void
205 + module_exit(void)
206 + {
207 +  mod_del_cmd(&accept_msgtab);
208 + }
209 +
210 + struct module module_entry =
211 + {
212 +  .version = "$Revision$",
213 +  .modinit = module_init,
214 +  .modexit = module_exit,
215 + };

Diff Legend

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