ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_undline.c
Revision: 7428
Committed: Mon Mar 7 17:46:09 2016 UTC (8 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 5889 byte(s)
Log Message:
- parse_aline() cleanups

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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
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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_undline.c
23 * \brief Includes required functions for processing the UNDLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "conf.h"
32 #include "conf_cluster.h"
33 #include "conf_shared.h"
34 #include "ircd.h"
35 #include "hostmask.h"
36 #include "numeric.h"
37 #include "log.h"
38 #include "misc.h"
39 #include "send.h"
40 #include "server.h"
41 #include "parse.h"
42 #include "modules.h"
43 #include "memory.h"
44
45
46 /* static int remove_tdline_match(const char *host, const char *user)
47 * Input: An ip to undline.
48 * Output: returns YES on success, NO if no tdline removed.
49 * Side effects: Any matching tdlines are removed.
50 */
51 static int
52 dline_remove(const char *host)
53 {
54 struct irc_ssaddr iphost, *piphost;
55 struct MaskItem *conf;
56 int t = 0;
57 int aftype = 0;
58
59 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
60 {
61 if (t == HM_IPV6)
62 aftype = AF_INET6;
63 else
64 aftype = AF_INET;
65
66 piphost = &iphost;
67 }
68 else
69 piphost = NULL;
70
71 if ((conf = find_conf_by_address(host, piphost, CONF_DLINE, aftype, NULL, NULL, 0)))
72 {
73 if (IsConfDatabase(conf))
74 {
75 delete_one_address_conf(host, conf);
76 return 1;
77 }
78 }
79
80 return 0;
81 }
82
83 static void
84 dline_remove_and_notify(struct Client *source_p, const char *host)
85 {
86 if (dline_remove(host))
87 {
88 if (IsClient(source_p))
89 sendto_one_notice(source_p, &me, ":D-Line for [%s] is removed", host);
90
91 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
92 "%s has removed the D-Line for: [%s]",
93 get_oper_name(source_p), host);
94 ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
95 get_oper_name(source_p), host);
96 }
97 else if (IsClient(source_p))
98 sendto_one_notice(source_p, &me, ":No D-Line for [%s] found", host);
99 }
100
101 /*! \brief UNDLINE command handler
102 *
103 * \param source_p Pointer to allocated Client struct from which the message
104 * originally comes from. This can be a local or remote client.
105 * \param parc Integer holding the number of supplied arguments.
106 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
107 * pointers.
108 * \note Valid arguments for this command are:
109 * - parv[0] = command
110 * - parv[1] = IP address
111 * - parv[2] = "ON"
112 * - parv[3] = target server
113 */
114 static int
115 mo_undline(struct Client *source_p, int parc, char *parv[])
116 {
117 char *addr = NULL;
118 char *target_server = NULL;
119
120 if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
121 {
122 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "undline");
123 return 0;
124 }
125
126 if (parc < 2 || EmptyString(parv[1]))
127 {
128 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNDLINE");
129 return 0;
130 }
131
132 if (!parse_aline("UNDLINE", source_p, parc, parv, &addr,
133 NULL, NULL, &target_server, NULL))
134 return 0;
135
136 if (target_server)
137 {
138 sendto_match_servs(source_p, target_server, CAPAB_UNDLN,
139 "UNDLINE %s %s", target_server, addr);
140
141 /* Allow ON to apply local undline as well if it matches */
142 if (match(target_server, me.name))
143 return 0;
144 }
145 else
146 cluster_distribute(source_p, "UNDLINE", CAPAB_UNDLN, CLUSTER_UNDLINE, "%s", addr);
147
148 dline_remove_and_notify(source_p, addr);
149 return 0;
150 }
151
152 /*! \brief UNDLINE command handler
153 *
154 * \param source_p Pointer to allocated Client struct from which the message
155 * originally comes from. This can be a local or remote client.
156 * \param parc Integer holding the number of supplied arguments.
157 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
158 * pointers.
159 * \note Valid arguments for this command are:
160 * - parv[0] = command
161 * - parv[1] = target server mask
162 * - parv[2] = IP address
163 */
164 static int
165 ms_undline(struct Client *source_p, int parc, char *parv[])
166 {
167 const char *addr = parv[2];
168
169 if (parc != 3 || EmptyString(parv[2]))
170 return 0;
171
172 sendto_match_servs(source_p, parv[1], CAPAB_UNDLN, "UNDLINE %s %s",
173 parv[1], parv[2]);
174
175 if (match(parv[1], me.name))
176 return 0;
177
178 if (HasFlag(source_p, FLAGS_SERVICE) ||
179 shared_find(SHARED_UNDLINE, source_p->servptr->name,
180 source_p->username, source_p->host))
181 dline_remove_and_notify(source_p, addr);
182
183 return 0;
184 }
185
186 static struct Message undline_msgtab =
187 {
188 .cmd = "UNDLINE",
189 .args_min = 2,
190 .args_max = MAXPARA,
191 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
192 .handlers[CLIENT_HANDLER] = m_not_oper,
193 .handlers[SERVER_HANDLER] = ms_undline,
194 .handlers[ENCAP_HANDLER] = m_ignore,
195 .handlers[OPER_HANDLER] = mo_undline
196 };
197
198 static void
199 module_init(void)
200 {
201 mod_add_cmd(&undline_msgtab);
202 add_capability("UNDLN", CAPAB_UNDLN);
203 }
204
205 static void
206 module_exit(void)
207 {
208 mod_del_cmd(&undline_msgtab);
209 delete_capability("UNDLN");
210 }
211
212 struct module module_entry =
213 {
214 .version = "$Revision$",
215 .modinit = module_init,
216 .modexit = module_exit,
217 };

Properties

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