]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_services.c
Remove obsolete comment.
[irc/rqf/shadowircd.git] / modules / m_services.c
CommitLineData
212380e3 1/* modules/m_services.c
2 * Copyright (C) 2005 Lee Hardy <lee -at- leeh.co.uk>
3 * Copyright (C) 2005 ircd-ratbox development team
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * 1.Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * 2.Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3.The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id: m_services.c 1907 2006-08-29 19:18:15Z jilles $
30 */
31
32#include "stdinc.h"
33
212380e3 34#include "send.h"
35#include "channel.h"
36#include "client.h"
37#include "common.h"
38#include "config.h"
39#include "ircd.h"
40#include "numeric.h"
212380e3 41#include "s_conf.h"
42#include "s_newconf.h"
43#include "s_serv.h"
44#include "hash.h"
45#include "msg.h"
46#include "parse.h"
47#include "modules.h"
212380e3 48#include "whowas.h"
49#include "monitor.h"
50
51static int me_su(struct Client *, struct Client *, int, const char **);
52static int me_login(struct Client *, struct Client *, int, const char **);
53static int me_rsfnc(struct Client *, struct Client *, int, const char **);
54static int me_nickdelay(struct Client *, struct Client *, int, const char **);
55
56static void h_svc_server_introduced(hook_data_client *);
57static void h_svc_whois(hook_data_client *);
58static void h_svc_stats(hook_data_int *);
59
60struct Message su_msgtab = {
61 "SU", 0, 0, 0, MFLG_SLOW,
62 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_su, 2}, mg_ignore}
63};
64struct Message login_msgtab = {
65 "LOGIN", 0, 0, 0, MFLG_SLOW,
66 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_login, 2}, mg_ignore}
67};
68struct Message rsfnc_msgtab = {
69 "RSFNC", 0, 0, 0, MFLG_SLOW,
70 {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_rsfnc, 4}, mg_ignore}
71};
72struct Message nickdelay_msgtab = {
73 "NICKDELAY", 0, 0, 0, MFLG_SLOW,
74 {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_nickdelay, 3}, mg_ignore}
75};
76
77mapi_clist_av1 services_clist[] = {
78 &su_msgtab, &login_msgtab, &rsfnc_msgtab, &nickdelay_msgtab, NULL
79};
80mapi_hfn_list_av1 services_hfnlist[] = {
81 { "doing_stats", (hookfn) h_svc_stats },
82 { "doing_whois", (hookfn) h_svc_whois },
83 { "doing_whois_global", (hookfn) h_svc_whois },
84 { "server_introduced", (hookfn) h_svc_server_introduced },
85 { NULL, NULL }
86};
87
88DECLARE_MODULE_AV1(services, NULL, NULL, services_clist, NULL, services_hfnlist, "$Revision: 1907 $");
89
90static int
91me_su(struct Client *client_p, struct Client *source_p,
92 int parc, const char *parv[])
93{
94 struct Client *target_p;
95
96 if(!(source_p->flags & FLAGS_SERVICE))
97 return 0;
98
99 if((target_p = find_client(parv[1])) == NULL)
100 return 0;
101
102 if(!target_p->user)
103 return 0;
104
105 if(EmptyString(parv[2]))
106 target_p->user->suser[0] = '\0';
107 else
907468c4 108 rb_strlcpy(target_p->user->suser, parv[2], sizeof(target_p->user->suser));
212380e3 109
110 invalidate_bancache_user(target_p);
111
112 return 0;
113}
114
115static int
116me_login(struct Client *client_p, struct Client *source_p,
117 int parc, const char *parv[])
118{
119 if(!IsPerson(source_p))
120 return 0;
121
907468c4 122 rb_strlcpy(source_p->user->suser, parv[1], sizeof(source_p->user->suser));
212380e3 123 return 0;
124}
125
126static int
127clean_nick(const char *nick)
128{
129 int len = 0;
130
131 if(EmptyString(nick) || *nick == '-' || IsDigit(*nick))
132 return 0;
133
134 for(; *nick; nick++)
135 {
136 len++;
137 if(!IsNickChar(*nick))
138 return 0;
139 }
140
141 if(len >= NICKLEN)
142 return 0;
143
144 return 1;
145}
146
147static int
148me_rsfnc(struct Client *client_p, struct Client *source_p,
149 int parc, const char *parv[])
150{
151 struct Client *target_p;
152 struct Client *exist_p;
153 time_t newts, curts;
03e24016 154 char note[NICKLEN + 10];
212380e3 155
156 if(!(source_p->flags & FLAGS_SERVICE))
157 return 0;
158
159 if((target_p = find_person(parv[1])) == NULL)
160 return 0;
161
162 if(!MyClient(target_p))
163 return 0;
164
165 if(!clean_nick(parv[2]))
166 return 0;
167
168 curts = atol(parv[4]);
169
170 /* if tsinfo is different from what it was when services issued the
171 * RSFNC, then we ignore it. This can happen when a client changes
172 * nicknames before the RSFNC arrives.. --anfl
173 */
174 if(target_p->tsinfo != curts)
175 return 0;
176
177 if((exist_p = find_named_client(parv[2])))
178 {
179 char buf[BUFSIZE];
180
181 /* this would be one hell of a race condition to trigger
182 * this one given the tsinfo check above, but its here for
183 * safety --anfl
184 */
185 if(target_p == exist_p)
186 return 0;
187
188 if(MyClient(exist_p))
189 sendto_one(exist_p, ":%s KILL %s :(Nickname regained by services)",
190 me.name, exist_p->name);
191
192 exist_p->flags |= FLAGS_KILLED;
193 /* Do not send kills to servers for unknowns -- jilles */
194 if(IsClient(exist_p))
195 kill_client_serv_butone(NULL, exist_p, "%s (Nickname regained by services)",
196 me.name);
197
5b0a5279 198 rb_snprintf(buf, sizeof(buf), "Killed (%s (Nickname regained by services))",
212380e3 199 me.name);
200 exit_client(NULL, exist_p, &me, buf);
201 }
202
203 newts = atol(parv[3]);
204
205 /* timestamp is older than 15mins, ignore it */
9f6bbe3c
VY
206 if(newts < (rb_current_time() - 900))
207 newts = rb_current_time() - 900;
212380e3 208
209 target_p->tsinfo = newts;
210
211 monitor_signoff(target_p);
212
213 invalidate_bancache_user(target_p);
214
215 sendto_realops_snomask(SNO_NCHANGE, L_ALL,
216 "Nick change: From %s to %s [%s@%s]",
217 target_p->name, parv[2], target_p->username,
218 target_p->host);
219
220 sendto_common_channels_local(target_p, ":%s!%s@%s NICK :%s",
221 target_p->name, target_p->username,
222 target_p->host, parv[2]);
223
224 add_history(target_p, 1);
225 sendto_server(NULL, NULL, CAP_TS6, NOCAPS, ":%s NICK %s :%ld",
226 use_id(target_p), parv[2], (long) target_p->tsinfo);
212380e3 227
228 del_from_client_hash(target_p->name, target_p);
229 strcpy(target_p->name, parv[2]);
230 add_to_client_hash(target_p->name, target_p);
231
232 monitor_signon(target_p);
233
234 del_all_accepts(target_p);
235
03e24016
WP
236 rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name);
237 rb_note(target_p->localClient->F, note);
212380e3 238 return 0;
239}
240
241/*
242** me_nickdelay
212380e3 243** parv[1] = duration in seconds (0 to remove)
244** parv[2] = nick
245*/
246static int
247me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
248{
249 int duration;
250 struct nd_entry *nd;
251
252 if(!(source_p->flags & FLAGS_SERVICE))
253 return 0;
254
255 duration = atoi(parv[1]);
256 if (duration <= 0)
257 {
b37021a4 258 nd = irc_dictionary_retrieve(nd_dict, parv[2]);
212380e3 259 if (nd != NULL)
260 free_nd_entry(nd);
261 }
262 else
263 {
264 if (duration > 86400)
265 duration = 86400;
266 add_nd_entry(parv[2]);
b37021a4 267 nd = irc_dictionary_retrieve(nd_dict, parv[2]);
212380e3 268 if (nd != NULL)
9f6bbe3c 269 nd->expire = rb_current_time() + duration;
212380e3 270 }
271
272 return 0;
273}
274
275static void
276h_svc_server_introduced(hook_data_client *hdata)
277{
08d11e34 278 rb_dlink_node *ptr;
212380e3 279
08d11e34 280 RB_DLINK_FOREACH(ptr, service_list.head)
212380e3 281 {
282 if(!irccmp((const char *) ptr->data, hdata->target->name))
283 {
284 hdata->target->flags |= FLAGS_SERVICE;
285 return;
286 }
287 }
288}
289
290static void
291h_svc_whois(hook_data_client *data)
292{
293 char *p = data->target->user->suser;
294 if(!EmptyString(p))
295 {
296 /* Try to strip off any leading digits as this may be used to
297 * store both an ID number and an account name in one field.
298 * If only digits are present, leave as is.
299 */
300 while(IsDigit(*p))
301 p++;
302 if(*p == '\0')
303 p = data->target->user->suser;
304
305 sendto_one(data->client, form_str(RPL_WHOISLOGGEDIN),
306 get_id(&me, data->client),
307 get_id(data->client, data->client),
308 data->target->name, p);
309 }
310}
311
312static void
313h_svc_stats(hook_data_int *data)
314{
315 char statchar = (char) data->arg2;
08d11e34 316 rb_dlink_node *ptr;
212380e3 317
318 if (statchar == 'U' && IsOper(data->client))
319 {
08d11e34 320 RB_DLINK_FOREACH(ptr, service_list.head)
212380e3 321 {
322 sendto_one_numeric(data->client, RPL_STATSULINE,
323 form_str(RPL_STATSULINE),
324 ptr->data, "*", "*", "s");
325 }
326 }
327}