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.
52 static int me_svslogin(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
53 static int ms_signon(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
55 static void send_signon(struct Client
*, struct Client
*, const char *, const char *, const char *, unsigned int, const char *);
57 struct Message svslogin_msgtab
= {
58 "SVSLOGIN", 0, 0, 0, 0,
59 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_svslogin
, 6}, mg_ignore
}
61 struct Message signon_msgtab
= {
63 {mg_ignore
, mg_ignore
, {ms_signon
, 6}, mg_ignore
, mg_ignore
, mg_ignore
}
66 mapi_clist_av1 signon_clist
[] = {
67 &svslogin_msgtab
, &signon_msgtab
, NULL
70 DECLARE_MODULE_AV2(signon
, NULL
, NULL
, signon_clist
, NULL
, NULL
, NULL
, NULL
, NULL
);
77 clean_username(const char *username
)
81 for (; *username
; username
++)
85 if(!IsUserChar(*username
))
96 clean_host(const char *host
)
100 for (; *host
; host
++)
104 if(!IsHostChar(*host
))
115 me_svslogin(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
116 int parc
, const char *parv
[])
118 struct Client
*target_p
, *exist_p
;
119 char nick
[NICKLEN
+1], login
[NICKLEN
+1];
120 char user
[USERLEN
+1], host
[HOSTLEN
+1];
123 if(!(source_p
->flags
& FLAGS_SERVICE
))
125 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
126 "Non-service server %s attempting to execute services-only command SVSLOGIN", source_p
->name
);
130 if((target_p
= find_client(parv
[1])) == NULL
)
133 if(!MyClient(target_p
) && !IsUnknown(target_p
))
136 if(clean_nick(parv
[2], 0))
138 rb_strlcpy(nick
, parv
[2], NICKLEN
+ 1);
141 else if(*target_p
->name
)
142 rb_strlcpy(nick
, target_p
->name
, NICKLEN
+ 1);
146 if(clean_username(parv
[3]))
148 rb_strlcpy(user
, parv
[3], USERLEN
+ 1);
152 rb_strlcpy(user
, target_p
->username
, USERLEN
+ 1);
154 if(clean_host(parv
[4]))
156 rb_strlcpy(host
, parv
[4], HOSTLEN
+ 1);
160 rb_strlcpy(host
, target_p
->host
, HOSTLEN
+ 1);
165 rb_strlcpy(login
, target_p
->user
->suser
, NICKLEN
+ 1);
169 else if(!strcmp(parv
[5], "0"))
172 rb_strlcpy(login
, parv
[5], NICKLEN
+ 1);
174 /* Login (mostly) follows nick rules. */
175 if(*login
&& !clean_nick(login
, 0))
178 if((exist_p
= find_person(nick
)) && target_p
!= exist_p
)
182 if(MyClient(exist_p
))
183 sendto_one(exist_p
, ":%s KILL %s :(Nickname regained by services)",
184 me
.name
, exist_p
->name
);
186 exist_p
->flags
|= FLAGS_KILLED
;
187 kill_client_serv_butone(NULL
, exist_p
, "%s (Nickname regained by services)",
189 sendto_realops_snomask(SNO_SKILL
, L_ALL
,
190 "Nick collision due to SVSLOGIN on %s",
193 snprintf(buf
, sizeof(buf
), "Killed (%s (Nickname regained by services))",
195 exit_client(NULL
, exist_p
, &me
, buf
);
196 }else if((exist_p
= find_client(nick
)) && IsUnknown(exist_p
) && exist_p
!= target_p
) {
197 exit_client(NULL
, exist_p
, &me
, "Overridden");
202 /* Strip leading digits, unless it's purely numeric. */
203 const char *p
= login
;
209 sendto_one(target_p
, form_str(RPL_LOGGEDIN
), me
.name
, EmptyString(target_p
->name
) ? "*" : target_p
->name
,
210 nick
, user
, host
, p
, p
);
213 sendto_one(target_p
, form_str(RPL_LOGGEDOUT
), me
.name
, EmptyString(target_p
->name
) ? "*" : target_p
->name
,
216 if(IsUnknown(target_p
))
218 struct User
*user_p
= make_user(target_p
);
220 if(valid
& NICK_VALID
)
221 strcpy(target_p
->preClient
->spoofnick
, nick
);
223 if(valid
& USER_VALID
)
224 strcpy(target_p
->preClient
->spoofuser
, user
);
226 if(valid
& HOST_VALID
)
227 strcpy(target_p
->preClient
->spoofhost
, host
);
229 rb_strlcpy(user_p
->suser
, login
, NICKLEN
+ 1);
233 char note
[NICKLEN
+ 10];
235 send_signon(NULL
, target_p
, nick
, user
, host
, rb_current_time(), login
);
237 snprintf(note
, NICKLEN
+ 10, "Nick: %s", target_p
->name
);
238 rb_note(target_p
->localClient
->F
, note
);
245 ms_signon(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
,
246 int parc
, const char *parv
[])
248 struct Client
*target_p
;
250 char login
[NICKLEN
+1];
252 if(!clean_nick(parv
[1], 0))
254 ServerStats
.is_kill
++;
255 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
256 "Bad Nick from SIGNON: %s From: %s(via %s)",
257 parv
[1], source_p
->servptr
->name
, client_p
->name
);
258 /* if source_p has an id, kill_client_serv_butone() will
259 * send a kill to client_p, otherwise do it here */
260 if (!has_id(source_p
))
261 sendto_one(client_p
, ":%s KILL %s :%s (Bad nickname from SIGNON)",
262 get_id(&me
, client_p
), parv
[1], me
.name
);
263 kill_client_serv_butone(client_p
, source_p
, "%s (Bad nickname from SIGNON)",
265 source_p
->flags
|= FLAGS_KILLED
;
266 exit_client(NULL
, source_p
, &me
, "Bad nickname from SIGNON");
270 if(!clean_username(parv
[2]) || !clean_host(parv
[3]))
272 ServerStats
.is_kill
++;
273 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
274 "Bad user@host from SIGNON: %s@%s From: %s(via %s)",
275 parv
[2], parv
[3], source_p
->servptr
->name
, client_p
->name
);
276 /* if source_p has an id, kill_client_serv_butone() will
277 * send a kill to client_p, otherwise do it here */
278 if (!has_id(source_p
))
279 sendto_one(client_p
, ":%s KILL %s :%s (Bad user@host from SIGNON)",
280 get_id(&me
, client_p
), parv
[1], me
.name
);
281 kill_client_serv_butone(client_p
, source_p
, "%s (Bad user@host from SIGNON)",
283 source_p
->flags
|= FLAGS_KILLED
;
284 exit_client(NULL
, source_p
, &me
, "Bad user@host from SIGNON");
288 newts
= atol(parv
[4]);
290 if(!strcmp(parv
[5], "0"))
292 else if(*parv
[5] != '*')
294 if (clean_nick(parv
[5], 0))
295 rb_strlcpy(login
, parv
[5], NICKLEN
+ 1);
302 target_p
= find_named_client(parv
[1]);
303 if(target_p
!= NULL
&& target_p
!= source_p
)
305 /* In case of collision, follow NICK rules. */
306 /* XXX this is duplicated code and does not do SAVE */
307 if(IsUnknown(target_p
))
308 exit_client(NULL
, target_p
, &me
, "Overridden");
311 if(!newts
|| !target_p
->tsinfo
|| (newts
== target_p
->tsinfo
) || !source_p
->user
)
313 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
314 "Nick change collision from SIGNON from %s to %s(%s <- %s)(both killed)",
315 source_p
->name
, target_p
->name
, target_p
->from
->name
,
318 ServerStats
.is_kill
++;
319 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
320 form_str(ERR_NICKCOLLISION
), target_p
->name
);
322 kill_client_serv_butone(NULL
, source_p
, "%s (Nick change collision)", me
.name
);
324 ServerStats
.is_kill
++;
326 kill_client_serv_butone(NULL
, target_p
, "%s (Nick change collision)", me
.name
);
328 target_p
->flags
|= FLAGS_KILLED
;
329 exit_client(NULL
, target_p
, &me
, "Nick collision(new)");
330 source_p
->flags
|= FLAGS_KILLED
;
331 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
336 sameuser
= !irccmp(target_p
->username
, source_p
->username
) &&
337 !irccmp(target_p
->host
, source_p
->host
);
339 if((sameuser
&& newts
< target_p
->tsinfo
) ||
340 (!sameuser
&& newts
> target_p
->tsinfo
))
343 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
344 "Nick change collision from SIGNON from %s to %s(%s <- %s)(older killed)",
345 source_p
->name
, target_p
->name
,
346 target_p
->from
->name
, client_p
->name
);
348 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
349 "Nick change collision from SIGNON from %s to %s(%s <- %s)(newer killed)",
350 source_p
->name
, target_p
->name
,
351 target_p
->from
->name
, client_p
->name
);
353 ServerStats
.is_kill
++;
355 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
356 form_str(ERR_NICKCOLLISION
), target_p
->name
);
358 /* kill the client issuing the nickchange */
359 kill_client_serv_butone(client_p
, source_p
,
360 "%s (Nick change collision)", me
.name
);
362 source_p
->flags
|= FLAGS_KILLED
;
365 exit_client(client_p
, source_p
, &me
, "Nick collision(old)");
367 exit_client(client_p
, source_p
, &me
, "Nick collision(new)");
373 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
374 "Nick collision from SIGNON on %s(%s <- %s)(older killed)",
375 target_p
->name
, target_p
->from
->name
,
378 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
379 "Nick collision from SIGNON on %s(%s <- %s)(newer killed)",
380 target_p
->name
, target_p
->from
->name
,
383 sendto_one_numeric(target_p
, ERR_NICKCOLLISION
,
384 form_str(ERR_NICKCOLLISION
), target_p
->name
);
386 /* kill the client who existed before hand */
387 kill_client_serv_butone(client_p
, target_p
,
388 "%s (Nick collision)", me
.name
);
390 ServerStats
.is_kill
++;
392 target_p
->flags
|= FLAGS_KILLED
;
393 (void) exit_client(client_p
, target_p
, &me
, "Nick collision");
400 send_signon(client_p
, source_p
, parv
[1], parv
[2], parv
[3], newts
, login
);
405 send_signon(struct Client
*client_p
, struct Client
*target_p
,
406 const char *nick
, const char *user
, const char *host
,
407 unsigned int newts
, const char *login
)
409 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
, ":%s SIGNON %s %s %s %ld %s",
410 use_id(target_p
), nick
, user
, host
,
411 (long) target_p
->tsinfo
, *login
? login
: "0");
413 strcpy(target_p
->user
->suser
, login
);
415 change_nick_user_host(target_p
, nick
, user
, host
, newts
, "Signing %s (%s)", *login
? "in" : "out", nick
);