2 * Copyright (C) 2006 Michael Tharp <gxti@partiallystapled.com>
3 * Copyright (C) 2006 charybdis development team
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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.
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.
47 #include "sprintf_irc.h"
52 #include "irc_string.h"
55 static int me_svslogin(struct Client
*, struct Client
*, int, const char **);
56 static int ms_signon(struct Client
*, struct Client
*, int, const char **);
58 static void send_signon(struct Client
*, struct Client
*, const char *, const char *, const char *, unsigned int, const char *);
60 struct Message svslogin_msgtab
= {
61 "SVSLOGIN", 0, 0, 0, MFLG_SLOW
,
62 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_svslogin
, 6}, mg_ignore
}
64 struct Message signon_msgtab
= {
65 "SIGNON", 0, 0, 0, MFLG_SLOW
,
66 {mg_ignore
, mg_ignore
, {ms_signon
, 6}, mg_ignore
, mg_ignore
, mg_ignore
}
69 mapi_clist_av1 signon_clist
[] = {
70 &svslogin_msgtab
, &signon_msgtab
, NULL
73 DECLARE_MODULE_AV1(signon
, NULL
, NULL
, signon_clist
, NULL
, NULL
, "$Revision: 108 $");
80 clean_nick(const char *nick
)
87 /* This is used to check logins, which are often
88 * numeric. Don't check for leading digits, if
89 * services wants to set someone's nick to something
90 * starting with a number, let it try.
97 if(!IsNickChar(*nick
))
109 clean_username(const char *username
)
113 for (; *username
; username
++)
117 if(!IsUserChar(*username
))
128 clean_host(const char *host
)
132 for (; *host
; host
++)
136 if(!IsHostChar(*host
))
147 me_svslogin(struct Client
*client_p
, struct Client
*source_p
,
148 int parc
, const char *parv
[])
150 struct Client
*target_p
, *exist_p
;
151 char nick
[NICKLEN
+1], login
[NICKLEN
+1];
152 char user
[USERLEN
+1], host
[HOSTLEN
+1];
155 if(!(source_p
->flags
& FLAGS_SERVICE
))
158 if((target_p
= find_client(parv
[1])) == NULL
)
161 if(!MyClient(target_p
) && !IsUnknown(target_p
))
164 if(clean_nick(parv
[2]))
166 strlcpy(nick
, parv
[2], NICKLEN
+ 1);
169 else if(*target_p
->name
)
170 strlcpy(nick
, target_p
->name
, NICKLEN
+ 1);
174 if(clean_username(parv
[3]))
176 strlcpy(user
, parv
[3], USERLEN
+ 1);
180 strlcpy(user
, target_p
->username
, USERLEN
+ 1);
182 if(clean_host(parv
[4]))
184 strlcpy(host
, parv
[4], HOSTLEN
+ 1);
188 strlcpy(host
, target_p
->host
, HOSTLEN
+ 1);
193 strlcpy(login
, target_p
->user
->suser
, NICKLEN
+ 1);
197 else if(!strcmp(parv
[5], "0"))
200 strlcpy(login
, parv
[5], NICKLEN
+ 1);
202 /* Login (mostly) follows nick rules. */
203 if(*login
&& !clean_nick(login
))
206 if((exist_p
= find_person(nick
)) && target_p
!= exist_p
)
210 if(MyClient(exist_p
))
211 sendto_one(exist_p
, ":%s KILL %s :(Nickname regained by services)",
212 me
.name
, exist_p
->name
);
214 exist_p
->flags
|= FLAGS_KILLED
;
215 kill_client_serv_butone(NULL
, exist_p
, "%s (Nickname regained by services)",
218 snprintf(buf
, sizeof(buf
), "Killed (%s (Nickname regained by services))",
220 exit_client(NULL
, exist_p
, &me
, buf
);
221 }else if((exist_p
= find_client(nick
)) && IsUnknown(exist_p
) && exist_p
!= target_p
) {
222 exit_client(NULL
, exist_p
, &me
, "Overridden");
227 /* Strip leading digits, unless it's purely numeric. */
228 const char *p
= login
;
234 sendto_one(target_p
, form_str(RPL_LOGGEDIN
), me
.name
, EmptyString(target_p
->name
) ? "*" : target_p
->name
,
235 nick
, user
, host
, p
, p
);
238 sendto_one(target_p
, form_str(RPL_LOGGEDOUT
), me
.name
, EmptyString(target_p
->name
) ? "*" : target_p
->name
,
241 if(IsUnknown(target_p
))
243 struct User
*user_p
= make_user(target_p
);
245 if(valid
& NICK_VALID
)
246 strcpy(target_p
->preClient
->spoofnick
, nick
);
248 if(valid
& USER_VALID
)
249 strcpy(target_p
->preClient
->spoofuser
, user
);
251 if(valid
& HOST_VALID
)
252 strcpy(target_p
->preClient
->spoofhost
, host
);
254 strlcpy(user_p
->suser
, login
, NICKLEN
+ 1);
258 send_signon(NULL
, target_p
, nick
, user
, host
, CurrentTime
, login
);
259 comm_note(target_p
->localClient
->fd
, "Nick: %s", target_p
->name
);
266 ms_signon(struct Client
*client_p
, struct Client
*source_p
,
267 int parc
, const char *parv
[])
269 struct Client
*target_p
;
271 char login
[NICKLEN
+1];
273 if(!clean_nick(parv
[1]))
275 ServerStats
->is_kill
++;
276 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
277 "Bad Nick from SIGNON: %s From: %s(via %s)",
278 parv
[1], source_p
->servptr
->name
, client_p
->name
);
279 /* if source_p has an id, kill_client_serv_butone() will
280 * send a kill to client_p, otherwise do it here */
281 if (!has_id(source_p
))
282 sendto_one(client_p
, ":%s KILL %s :%s (Bad nickname from SIGNON)",
283 get_id(&me
, client_p
), parv
[1], me
.name
);
284 kill_client_serv_butone(client_p
, source_p
, "%s (Bad nickname from SIGNON)",
286 source_p
->flags
|= FLAGS_KILLED
;
287 exit_client(NULL
, source_p
, &me
, "Bad nickname from SIGNON");
291 if(!clean_username(parv
[2]) || !clean_host(parv
[3]))
293 ServerStats
->is_kill
++;
294 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
295 "Bad user@host from SIGNON: %s@%s From: %s(via %s)",
296 parv
[2], parv
[3], source_p
->servptr
->name
, client_p
->name
);
297 /* if source_p has an id, kill_client_serv_butone() will
298 * send a kill to client_p, otherwise do it here */
299 if (!has_id(source_p
))
300 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host from SIGNON)",
301 get_id(&me
, client_p
), parv
[1], me
.name
);
302 kill_client_serv_butone(client_p
, source_p
, "%s (Bad user@host from SIGNON)",
304 source_p
->flags
|= FLAGS_KILLED
;
305 exit_client(NULL
, source_p
, &me
, "Bad user@host from SIGNON");
309 newts
= atol(parv
[4]);
311 if(!strcmp(parv
[5], "0"))
313 else if(*parv
[5] != '*')
315 if (clean_nick(parv
[5]))
316 strlcpy(login
, parv
[5], NICKLEN
+ 1);
321 target_p
= find_named_client(parv
[1]);
322 if(target_p
!= NULL
&& target_p
!= source_p
)
324 /* In case of collision, follow NICK rules. */
325 /* XXX this is duplicated code and does not do SAVE */
326 if(IsUnknown(target_p
))
327 exit_client(NULL
, target_p
, &me
, "Overridden");
330 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
332 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
333 "Nick change collision from SIGNON from %s to %s(%s <- %s)(both killed)",
334 source_p
->name
, target_p
->name
, target_p
->from
->name
,
337 ServerStats
->is_kill
++;
338 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
339 form_str(ERR_NICKCOLLISION
), target_p
->name
);
341 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
343 ServerStats
->is_kill
++;
345 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
347 target_p
->flags
|= FLAGS_KILLED
;
348 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
349 source_p
->flags
|= FLAGS_KILLED
;
350 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
355 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
356 !irccmp(target_p
->host
, source_p
->host
);
358 if((sameuser
&& newts
< target_p
->tsinfo
) ||
359 (!sameuser
&& newts
> target_p
->tsinfo
))
362 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
363 "Nick change collision from SIGNON from %s to %s(%s <- %s)(older killed)",
364 source_p
->name
, target_p
->name
,
365 target_p
->from
->name
, client_p
->name
);
367 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
368 "Nick change collision from SIGNON from %s to %s(%s <- %s)(newer killed)",
369 source_p
->name
, target_p
->name
,
370 target_p
->from
->name
, client_p
->name
);
372 ServerStats
->is_kill
++;
374 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
375 form_str(ERR_NICKCOLLISION
), target_p
->name
);
377 /* kill the client issuing the nickchange */
378 kill_client_serv_butone(client_p
, source_p
,
379 "%s (Nick change collision)", me
.name
);
381 source_p
->flags
|= FLAGS_KILLED
;
384 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
386 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
392 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
393 "Nick collision from SIGNON on %s(%s <- %s)(older killed)",
394 target_p
->name
, target_p
->from
->name
,
397 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
398 "Nick collision from SIGNON on %s(%s <- %s)(newer killed)",
399 target_p
->name
, target_p
->from
->name
,
402 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
403 form_str(ERR_NICKCOLLISION
), target_p
->name
);
405 /* kill the client who existed before hand */
406 kill_client_serv_butone(client_p
, target_p
,
407 "%s (Nick collision)", me
.name
);
409 ServerStats
->is_kill
++;
411 target_p
->flags
|= FLAGS_KILLED
;
412 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
419 send_signon(client_p
, source_p
, parv
[1], parv
[2], parv
[3], newts
, login
);
424 send_signon(struct Client
*client_p
, struct Client
*target_p
,
425 const char *nick
, const char *user
, const char *host
,
426 unsigned int newts
, const char *login
)
428 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s SIGNON %s %s %s %ld %s",
429 use_id(target_p
), nick
, user
, host
,
430 (long) target_p
->tsinfo
, *login
? login
: "0");
431 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s SIGNON %s %s %s %ld %s",
432 target_p
->name
, nick
, user
, host
,
433 (long) target_p
->tsinfo
, *login
? login
: "0");
435 strcpy(target_p
->user
->suser
, login
);
437 change_nick_user_host(target_p
, nick
, user
, host
, newts
, "Signing %s (%s)", *login
? "in" : "out", nick
);