ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 3317
Committed: Tue Apr 15 14:25:19 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/s_user.c
File size: 33814 byte(s)
Log Message:
- s_user.c: update/cleanup documentation

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file s_user.c
23 * \brief User related functions.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "s_user.h"
30 #include "s_misc.h"
31 #include "channel.h"
32 #include "channel_mode.h"
33 #include "client.h"
34 #include "hash.h"
35 #include "irc_string.h"
36 #include "ircd.h"
37 #include "listener.h"
38 #include "motd.h"
39 #include "numeric.h"
40 #include "conf.h"
41 #include "log.h"
42 #include "s_serv.h"
43 #include "send.h"
44 #include "supported.h"
45 #include "memory.h"
46 #include "packet.h"
47 #include "rng_mt.h"
48 #include "userhost.h"
49 #include "s_misc.h"
50 #include "parse.h"
51 #include "watch.h"
52
53 static char umode_buffer[IRCD_BUFSIZE];
54 static const char *uid_get(void);
55
56 /* Used for building up the isupport string,
57 * used with init_isupport, add_isupport, delete_isupport
58 */
59 struct Isupport
60 {
61 dlink_node node;
62 char *name;
63 char *options;
64 int number;
65 };
66
67 static dlink_list support_list;
68 static dlink_list support_list_lines;
69
70 /* memory is cheap. map 0-255 to equivalent mode */
71 const unsigned int user_modes[256] =
72 {
73 /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */
74 /* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */
75 /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2F */
76 /* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3F */
77 0, /* @ */
78 0, /* A */
79 0, /* B */
80 0, /* C */
81 UMODE_DEAF, /* D */
82 0, /* E */
83 UMODE_FARCONNECT, /* F */
84 UMODE_SOFTCALLERID, /* G */
85 UMODE_HIDDEN, /* H */
86 0, /* I */
87 0, /* J */
88 0, /* K */
89 0, /* L */
90 0, /* M */
91 0, /* N */
92 0, /* O */
93 0, /* P */
94 0, /* Q */
95 UMODE_REGONLY, /* R */
96 UMODE_SSL, /* S */
97 0, /* T */
98 0, /* U */
99 0, /* V */
100 UMODE_WEBIRC, /* W */
101 0, /* X */
102 0, /* Y */
103 0, /* Z 0x5A */
104 0, 0, 0, 0, 0, /* 0x5F */
105 0, /* 0x60 */
106 UMODE_ADMIN, /* a */
107 UMODE_BOTS, /* b */
108 UMODE_CCONN, /* c */
109 UMODE_DEBUG, /* d */
110 UMODE_EXTERNAL, /* e */
111 UMODE_FULL, /* f */
112 UMODE_CALLERID, /* g */
113 0, /* h */
114 UMODE_INVISIBLE, /* i */
115 UMODE_REJ, /* j */
116 UMODE_SKILL, /* k */
117 UMODE_LOCOPS, /* l */
118 0, /* m */
119 UMODE_NCHANGE, /* n */
120 UMODE_OPER, /* o */
121 0, /* p */
122 0, /* q */
123 UMODE_REGISTERED, /* r */
124 UMODE_SERVNOTICE, /* s */
125 0, /* t */
126 UMODE_UNAUTH, /* u */
127 0, /* v */
128 UMODE_WALLOP, /* w */
129 UMODE_HIDDENHOST, /* x */
130 UMODE_SPY, /* y */
131 UMODE_OPERWALL, /* z 0x7A */
132 0,0,0,0,0, /* 0x7B - 0x7F */
133
134 /* 0x80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8F */
135 /* 0x90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9F */
136 /* 0xA0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xAF */
137 /* 0xB0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xBF */
138 /* 0xC0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xCF */
139 /* 0xD0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xDF */
140 /* 0xE0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xEF */
141 /* 0xF0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xFF */
142 };
143
144 void
145 assemble_umode_buffer(void)
146 {
147 unsigned int idx = 0;
148 char *umode_buffer_ptr = umode_buffer;
149
150 for (; idx < (sizeof(user_modes) / sizeof(user_modes[0])); ++idx)
151 if (user_modes[idx])
152 *umode_buffer_ptr++ = idx;
153
154 *umode_buffer_ptr = '\0';
155 }
156
157 /* show_lusers()
158 *
159 * inputs - pointer to client
160 * output - NONE
161 * side effects - display to client user counts etc.
162 */
163 void
164 show_lusers(struct Client *source_p)
165 {
166 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
167 sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total-Count.invisi),
168 Count.invisi, dlink_list_length(&global_serv_list));
169 else
170 sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT,
171 (Count.total-Count.invisi), Count.invisi, 1);
172
173 if (Count.oper > 0)
174 sendto_one_numeric(source_p, &me, RPL_LUSEROP, Count.oper);
175
176 if (dlink_list_length(&unknown_list) > 0)
177 sendto_one_numeric(source_p, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
178
179 if (dlink_list_length(&global_channel_list) > 0)
180 sendto_one_numeric(source_p, &me, RPL_LUSERCHANNELS, dlink_list_length(&global_channel_list));
181
182 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
183 {
184 sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.local, Count.myserver);
185 sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.local, Count.max_loc);
186 }
187 else
188 {
189 sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.total, 0);
190 sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.total, Count.max_tot);
191 }
192
193 sendto_one_numeric(source_p, &me, RPL_GLOBALUSERS, Count.total, Count.max_tot);
194
195 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
196 sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
197 Count.max_loc_cli, Count.totalrestartcount);
198
199 if (Count.local > Count.max_loc_cli)
200 Count.max_loc_cli = Count.local;
201
202 if ((Count.local + Count.myserver) > Count.max_loc_con)
203 Count.max_loc_con = Count.local + Count.myserver;
204 }
205
206 /* show_isupport()
207 *
208 * inputs - pointer to client
209 * output - NONE
210 * side effects - display to client what we support (for them)
211 */
212 void
213 show_isupport(struct Client *source_p)
214 {
215 const dlink_node *ptr = NULL;
216
217 DLINK_FOREACH(ptr, support_list_lines.head)
218 sendto_one_numeric(source_p, &me, RPL_ISUPPORT, ptr->data);
219 }
220
221
222 /* report_and_set_user_flags()
223 *
224 * inputs - pointer to source_p
225 * - pointer to conf for this user
226 * output - NONE
227 * side effects - Report to user any special flags
228 * they are getting, and set them.
229 */
230 static void
231 report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
232 {
233 /* If this user is being spoofed, tell them so */
234 if (IsConfDoSpoofIp(conf))
235 sendto_one_notice(source_p, &me, ":*** Spoofing your IP. Congrats.");
236
237 /* If this user is in the exception class, Set it "E lined" */
238 if (IsConfExemptKline(conf))
239 {
240 SetExemptKline(source_p);
241 sendto_one_notice(source_p, &me, ":*** You are exempt from K/D/G lines. Congrats.");
242 }
243
244 /*
245 * The else here is to make sure that G line exempt users
246 * do not get noticed twice.
247 */
248 else if (IsConfExemptGline(conf))
249 {
250 SetExemptGline(source_p);
251 sendto_one_notice(source_p, &me, ":*** You are exempt from G lines. Congrats.");
252 }
253
254 if (IsConfExemptResv(conf))
255 {
256 SetExemptResv(source_p);
257 sendto_one_notice(source_p, &me, ":*** You are exempt from resvs. Congrats.");
258 }
259
260 /* If this user is exempt from user limits set it "F lined" */
261 if (IsConfExemptLimits(conf))
262 {
263 SetExemptLimits(source_p);
264 sendto_one_notice(source_p, &me, ":*** You are exempt from user limits. Congrats.");
265 }
266
267 if (IsConfCanFlood(conf))
268 {
269 SetCanFlood(source_p);
270 sendto_one_notice(source_p, &me, ":*** You are exempt from flood "
271 "protection, aren't you fearsome.");
272 }
273 }
274
275 /* introduce_client()
276 *
277 * inputs - source_p
278 * output - NONE
279 * side effects - This common function introduces a client to the rest
280 * of the net, either from a local client connect or
281 * from a remote connect.
282 */
283 static void
284 introduce_client(struct Client *source_p)
285 {
286 dlink_node *ptr = NULL;
287 char ubuf[IRCD_BUFSIZE] = "";
288
289 if (MyClient(source_p))
290 send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
291 else
292 send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
293
294 watch_check_hash(source_p, RPL_LOGON);
295
296 if (ubuf[0] == '\0')
297 {
298 ubuf[0] = '+';
299 ubuf[1] = '\0';
300 }
301
302 DLINK_FOREACH(ptr, serv_list.head)
303 {
304 struct Client *server = ptr->data;
305
306 if (server == source_p->from)
307 continue;
308
309 if (IsCapable(server, CAP_SVS))
310 sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
311 source_p->servptr->id,
312 source_p->name, source_p->hopcount+1,
313 (unsigned long)source_p->tsinfo,
314 ubuf, source_p->username, source_p->host,
315 (MyClient(source_p) && IsIPSpoof(source_p)) ?
316 "0" : source_p->sockhost, source_p->id,
317 source_p->svid,
318 source_p->info);
319 else
320 sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
321 source_p->servptr->id,
322 source_p->name, source_p->hopcount+1,
323 (unsigned long)source_p->tsinfo,
324 ubuf, source_p->username, source_p->host,
325 (MyClient(source_p) && IsIPSpoof(source_p)) ?
326 "0" : source_p->sockhost, source_p->id, source_p->info);
327
328 if (!EmptyString(source_p->certfp))
329 sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
330 }
331 }
332
333 /* user_welcome()
334 *
335 * inputs - client pointer to client to welcome
336 * output - NONE
337 * side effects -
338 */
339 static void
340 user_welcome(struct Client *source_p)
341 {
342 #if defined(__TIME__) && defined(__DATE__)
343 static const char built_date[] = __DATE__ " at " __TIME__;
344 #else
345 static const char built_date[] = "unknown";
346 #endif
347
348 #ifdef HAVE_LIBCRYPTO
349 if (HasFlag(source_p, FLAGS_SSL))
350 {
351 AddUMode(source_p, UMODE_SSL);
352 sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
353 ssl_get_cipher(source_p->localClient->fd.ssl));
354 }
355 #endif
356
357 sendto_one_numeric(source_p, &me, RPL_WELCOME, ServerInfo.network_name,
358 source_p->name);
359 sendto_one_numeric(source_p, &me, RPL_YOURHOST,
360 get_listener_name(source_p->localClient->listener), ircd_version);
361 sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
362 sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
363 show_isupport(source_p);
364
365 if (source_p->id[0])
366 sendto_one_numeric(source_p, &me, RPL_YOURID, source_p->id);
367
368 show_lusers(source_p);
369 motd_signon(source_p);
370 }
371
372 /* check_xline()
373 *
374 * inputs - pointer to client to test
375 * outupt - 1 if exiting 0 if ok
376 * side effects -
377 */
378 static int
379 check_xline(struct Client *source_p)
380 {
381 struct MaskItem *conf = NULL;
382 const char *reason = NULL;
383
384 if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
385 {
386 ++conf->count;
387
388 if (conf->reason)
389 reason = conf->reason;
390 else
391 reason = CONF_NOREASON;
392
393 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
394 "X-line Rejecting [%s] [%s], user %s [%s]",
395 source_p->info, reason,
396 get_client_name(source_p, HIDE_IP),
397 source_p->sockhost);
398
399 ++ServerStats.is_ref;
400 exit_client(source_p, "Bad user info");
401 return 1;
402 }
403
404 return 0;
405 }
406
407 /*! \brief This function is called when both NICK and USER messages
408 * have been accepted for the client, in whatever order. Only
409 * after this, is the UID message propagated.
410 * \param source_p Pointer to given client to introduce
411 */
412 void
413 register_local_user(struct Client *source_p)
414 {
415 const char *id = NULL;
416 const struct MaskItem *conf = NULL;
417
418 assert(source_p == source_p->from);
419 assert(MyConnect(source_p));
420 assert(!source_p->localClient->registration);
421
422 ClearCap(source_p, CAP_TS6);
423
424 if (ConfigFileEntry.ping_cookie)
425 {
426 if (!IsPingSent(source_p) && !source_p->localClient->random_ping)
427 {
428 do
429 source_p->localClient->random_ping = genrand_int32();
430 while (!source_p->localClient->random_ping);
431
432 sendto_one(source_p, "PING :%u",
433 source_p->localClient->random_ping);
434 SetPingSent(source_p);
435 return;
436 }
437
438 if (!HasPingCookie(source_p))
439 return;
440 }
441
442 source_p->localClient->last_privmsg = CurrentTime;
443 /* Straight up the maximum rate of flooding... */
444 source_p->localClient->allow_read = MAX_FLOOD_BURST;
445
446 if (!check_client(source_p))
447 return;
448
449 if (!valid_hostname(source_p->host))
450 {
451 sendto_one_notice(source_p, &me, ":*** Notice -- You have an illegal "
452 "character in your hostname");
453 strlcpy(source_p->host, source_p->sockhost,
454 sizeof(source_p->host));
455 }
456
457 conf = source_p->localClient->confs.head->data;
458
459 if (!IsGotId(source_p))
460 {
461 char username[USERLEN + 1] = "";
462 const char *p = username;
463 unsigned int i = 0;
464
465 if (IsNeedIdentd(conf))
466 {
467 ++ServerStats.is_ref;
468 sendto_one_notice(source_p, &me, ":*** Notice -- You need to install "
469 "identd to use this server");
470 exit_client(source_p, "Install identd");
471 return;
472 }
473
474 strlcpy(username, source_p->username, sizeof(username));
475
476 if (!IsNoTilde(conf))
477 source_p->username[i++] = '~';
478
479 for (; *p && i < USERLEN; ++p)
480 if (*p != '[')
481 source_p->username[i++] = *p;
482
483 source_p->username[i] = '\0';
484 }
485
486 /* Password check */
487 if (!EmptyString(conf->passwd))
488 {
489 const char *pass = source_p->localClient->passwd;
490
491 if (!match_conf_password(pass, conf))
492 {
493 ++ServerStats.is_ref;
494
495 sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
496 exit_client(source_p, "Bad Password");
497 return;
498 }
499 }
500
501 /*
502 * Don't free source_p->localClient->passwd here - it can be required
503 * by masked /stats I if there are auth{} blocks with need_password = no;
504 * --adx
505 */
506
507 /*
508 * Report if user has &^>= etc. and set flags as needed in source_p
509 */
510 report_and_set_user_flags(source_p, conf);
511
512 if (IsDead(source_p))
513 return;
514
515 /*
516 * Limit clients -
517 * We want to be able to have servers and F-line clients
518 * connect, so save room for "buffer" connections.
519 * Smaller servers may want to decrease this, and it should
520 * probably be just a percentage of the MAXCLIENTS...
521 * -Taner
522 */
523 if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
524 (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
525 {
526 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
527 "Too many clients, rejecting %s[%s].",
528 source_p->name, source_p->host);
529 ++ServerStats.is_ref;
530 exit_client(source_p, "Sorry, server is full - try later");
531 return;
532 }
533
534 if (!valid_username(source_p->username, 1))
535 {
536 char tmpstr2[IRCD_BUFSIZE] = "";
537
538 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
539 "Invalid username: %s (%s@%s)",
540 source_p->name, source_p->username, source_p->host);
541 ++ServerStats.is_ref;
542 snprintf(tmpstr2, sizeof(tmpstr2), "Invalid username [%s]",
543 source_p->username);
544 exit_client(source_p, tmpstr2);
545 return;
546 }
547
548 if (check_xline(source_p))
549 return;
550
551 while (hash_find_id((id = uid_get())))
552 ;
553
554 strlcpy(source_p->id, id, sizeof(source_p->id));
555 hash_add_id(source_p);
556
557 sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
558 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
559 source_p->name, source_p->username, source_p->host,
560 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
561 "255.255.255.255" : source_p->sockhost,
562 get_client_class(&source_p->localClient->confs),
563 source_p->info, source_p->id);
564
565 if (ConfigFileEntry.invisible_on_connect)
566 {
567 AddUMode(source_p, UMODE_INVISIBLE);
568 ++Count.invisi;
569 }
570
571 if (++Count.local > Count.max_loc)
572 {
573 Count.max_loc = Count.local;
574
575 if (!(Count.max_loc % 10))
576 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
577 "New Max Local Clients: %d",
578 Count.max_loc);
579 }
580
581 if (++Count.total > Count.max_tot)
582 Count.max_tot = Count.total;
583 ++Count.totalrestartcount;
584
585 assert(source_p->servptr == &me);
586 SetClient(source_p);
587 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
588
589 source_p->localClient->allow_read = MAX_FLOOD_BURST;
590
591 assert(dlinkFind(&unknown_list, source_p));
592
593 dlink_move_node(&source_p->localClient->lclient_node,
594 &unknown_list, &local_client_list);
595
596 user_welcome(source_p);
597 add_user_host(source_p->username, source_p->host, 0);
598 SetUserHost(source_p);
599
600 introduce_client(source_p);
601 }
602
603 /* register_remote_user()
604 *
605 * inputs - source_p remote or directly connected client
606 * - username to register as
607 * - host name to register as
608 * - server name
609 * output - NONE
610 * side effects - This function is called when a remote client
611 * is introduced by a server.
612 */
613 void
614 register_remote_user(struct Client *source_p, const char *username,
615 const char *host, const char *server)
616 {
617 struct Client *target_p = NULL;
618
619 assert(source_p->username != username);
620
621 strlcpy(source_p->host, host, sizeof(source_p->host));
622 strlcpy(source_p->username, username, sizeof(source_p->username));
623
624 /*
625 * Coming from another server, take the servers word for it
626 */
627 source_p->servptr = hash_find_server(server);
628
629 /*
630 * Super GhostDetect:
631 * If we can't find the server the user is supposed to be on,
632 * then simply blow the user away. -Taner
633 */
634 if (source_p->servptr == NULL)
635 {
636 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
637 "No server %s for user %s[%s@%s] from %s",
638 server, source_p->name, source_p->username,
639 source_p->host, source_p->from->name);
640 sendto_one(source_p->from,
641 ":%s KILL %s :%s (Ghosted, server %s doesn't exist)",
642 me.id, source_p->id, me.name, server);
643
644 AddFlag(source_p, FLAGS_KILLED);
645 exit_client(source_p, "Ghosted Client");
646 return;
647 }
648
649 if ((target_p = source_p->servptr) && target_p->from != source_p->from)
650 {
651 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
652 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
653 source_p->from->name, source_p->name, source_p->username,
654 source_p->host, source_p->servptr->name,
655 target_p->name, target_p->from->name);
656 sendto_one(source_p->from,
657 ":%s KILL %s :%s (NICK from wrong direction (%s != %s))",
658 me.id, source_p->id, me.name, source_p->servptr->name,
659 target_p->from->name);
660
661 AddFlag(source_p, FLAGS_KILLED);
662 exit_client(source_p, "USER server wrong direction");
663 return;
664 }
665
666 /*
667 * If the nick has been introduced by a services server,
668 * make it a service as well.
669 */
670 if (HasFlag(source_p->servptr, FLAGS_SERVICE))
671 AddFlag(source_p, FLAGS_SERVICE);
672
673 if (++Count.total > Count.max_tot)
674 Count.max_tot = Count.total;
675
676 SetClient(source_p);
677 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
678 add_user_host(source_p->username, source_p->host, 1);
679 SetUserHost(source_p);
680
681 if (HasFlag(source_p->servptr, FLAGS_EOB))
682 sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
683 "Client connecting at %s: %s (%s@%s) [%s] <%s>",
684 source_p->servptr->name,
685 source_p->name, source_p->username, source_p->host,
686 source_p->info, source_p->id);
687
688 introduce_client(source_p);
689 }
690
691 /* valid_hostname()
692 *
693 * Inputs - pointer to hostname
694 * Output - 1 if valid, 0 if not
695 * Side effects - check hostname for validity
696 *
697 * NOTE: this doesn't allow a hostname to begin with a dot and
698 * will not allow more dots than chars.
699 */
700 int
701 valid_hostname(const char *hostname)
702 {
703 const char *p = hostname;
704
705 assert(p);
706
707 if (EmptyString(p) || *p == '.' || *p == ':')
708 return 0;
709
710 for (; *p; ++p)
711 if (!IsHostChar(*p))
712 return 0;
713
714 return p - hostname <= HOSTLEN;
715 }
716
717 /* valid_username()
718 *
719 * Inputs - pointer to user
720 * Output - 1 if valid, 0 if not
721 * Side effects - check username for validity
722 *
723 * Absolutely always reject any '*' '!' '?' '@' in an user name
724 * reject any odd control characters names.
725 * Allow '.' in username to allow for "first.last"
726 * style of username
727 */
728 int
729 valid_username(const char *username, const int local)
730 {
731 int dots = 0;
732 const char *p = username;
733
734 assert(p);
735
736 if (*p == '~')
737 ++p;
738
739 /*
740 * Reject usernames that don't start with an alphanum
741 * i.e. reject jokers who have '-@somehost' or '.@somehost'
742 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
743 */
744 if (!IsAlNum(*p))
745 return 0;
746
747 if (local)
748 {
749 while (*++p)
750 {
751 if ((*p == '.') && ConfigFileEntry.dots_in_ident)
752 {
753 if (++dots > ConfigFileEntry.dots_in_ident)
754 return 0;
755 if (!IsUserChar(*(p + 1)))
756 return 0;
757 }
758 else if (!IsUserChar(*p))
759 return 0;
760 }
761 }
762 else
763 {
764 while (*++p)
765 if (!IsUserChar(*p))
766 return 0;
767 }
768
769 return p - username <= USERLEN;;
770 }
771
772 /* clean_nick_name()
773 *
774 * input - nickname
775 * - whether it's a local nick (1) or remote (0)
776 * output - none
777 * side effects - walks through the nickname, returning 0 if erroneous
778 */
779 int
780 valid_nickname(const char *nickname, const int local)
781 {
782 const char *p = nickname;
783 assert(nickname && *nickname);
784
785 assert(p);
786
787 /*
788 * Nicks can't start with a digit or - or be 0 length.
789 */
790 if (*p == '-' || (IsDigit(*p) && local) || *p == '\0')
791 return 0;
792
793 for (; *p; ++p)
794 if (!IsNickChar(*p))
795 return 0;
796
797 return p - nickname <= NICKLEN;
798 }
799
800 /* send_umode()
801 * send the MODE string for user (user) to connection client_p
802 * -avalon
803 *
804 * inputs - client_p
805 * - source_p
806 * - int old
807 * - sendmask mask of modes to send
808 * - suplied umode_buf
809 * output - NONE
810 */
811 void
812 send_umode(struct Client *client_p, struct Client *source_p,
813 unsigned int old, unsigned int sendmask, char *umode_buf)
814 {
815 char *m = umode_buf;
816 int what = 0;
817 unsigned int i;
818 unsigned int flag;
819
820 /*
821 * Build a string in umode_buf to represent the change in the user's
822 * mode between the new (source_p->umodes) and 'old'.
823 */
824 for (i = 0; i < 128; ++i)
825 {
826 flag = user_modes[i];
827 if (!flag)
828 continue;
829
830 if (MyClient(source_p) && !(flag & sendmask))
831 continue;
832
833 if ((flag & old) && !HasUMode(source_p, flag))
834 {
835 if (what == MODE_DEL)
836 *m++ = (char)i;
837 else
838 {
839 what = MODE_DEL;
840 *m++ = '-';
841 *m++ = (char)i;
842 }
843 }
844 else if (!(flag & old) && HasUMode(source_p, flag))
845 {
846 if (what == MODE_ADD)
847 *m++ = (char)i;
848 else
849 {
850 what = MODE_ADD;
851 *m++ = '+';
852 *m++ = (char)i;
853 }
854 }
855 }
856
857 *m = '\0';
858
859 if (*umode_buf && client_p)
860 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
861 source_p->name, source_p->username,
862 source_p->host, source_p->name, umode_buf);
863 }
864
865 /* send_umode_out()
866 *
867 * inputs -
868 * output - NONE
869 * side effects - Only send ubuf out to servers that know about this client
870 */
871 void
872 send_umode_out(struct Client *client_p, struct Client *source_p,
873 unsigned int old)
874 {
875 char buf[IRCD_BUFSIZE] = "";
876
877 send_umode(NULL, source_p, old, SEND_UMODES, buf);
878
879 if (buf[0])
880 sendto_server(source_p, NOCAPS, NOCAPS, ":%s MODE %s :%s",
881 source_p->id, source_p->id, buf);
882
883 if (client_p && MyClient(client_p))
884 send_umode(client_p, source_p, old, 0xffffffff, buf);
885 }
886
887 void
888 user_set_hostmask(struct Client *target_p, const char *hostname, const int what)
889 {
890 dlink_node *ptr = NULL;
891
892 if (!strcmp(target_p->host, hostname))
893 return;
894
895 switch (what)
896 {
897 case MODE_ADD:
898 AddUMode(target_p, UMODE_HIDDENHOST);
899 AddFlag(target_p, FLAGS_IP_SPOOFING);
900 break;
901 case MODE_DEL:
902 DelUMode(target_p, UMODE_HIDDENHOST);
903
904 if (!HasFlag(target_p, FLAGS_AUTH_SPOOF))
905 DelFlag(target_p, FLAGS_IP_SPOOFING);
906 break;
907 default: return;
908 }
909
910 if (ConfigFileEntry.cycle_on_host_change)
911 sendto_common_channels_local(target_p, 0, 0, ":%s!%s@%s QUIT :Changing hostname",
912 target_p->name, target_p->username, target_p->host);
913
914 if (IsUserHostIp(target_p))
915 delete_user_host(target_p->username, target_p->host, !MyConnect(target_p));
916
917 strlcpy(target_p->host, hostname, sizeof(target_p->host));
918
919 add_user_host(target_p->username, target_p->host, !MyConnect(target_p));
920 SetUserHost(target_p);
921
922 if (MyClient(target_p))
923 {
924 sendto_one_numeric(target_p, &me, RPL_NEWHOSTIS, target_p->host);
925 clear_ban_cache_client(target_p);
926 }
927
928 if (!ConfigFileEntry.cycle_on_host_change)
929 return;
930
931 DLINK_FOREACH(ptr, target_p->channel.head)
932 {
933 char modebuf[4], nickbuf[NICKLEN * 3 + 3] = "";
934 char *p = modebuf;
935 int len = 0;
936 const struct Membership *ms = ptr->data;
937
938 if (has_member_flags(ms, CHFL_CHANOP))
939 {
940 *p++ = 'o';
941 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
942 }
943
944 if (has_member_flags(ms, CHFL_HALFOP))
945 {
946 *p++ = 'h';
947 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
948 }
949
950 if (has_member_flags(ms, CHFL_VOICE))
951 {
952 *p++ = 'v';
953 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
954 }
955
956 *p = '\0';
957
958 sendto_channel_local_butone(target_p, 0, 0, ms->chptr, ":%s!%s@%s JOIN :%s",
959 target_p->name, target_p->username, target_p->host,
960 ms->chptr->chname);
961 if (nickbuf[0])
962 sendto_channel_local_butone(target_p, 0, 0, ms->chptr, ":%s MODE %s +%s %s",
963 target_p->servptr->name, ms->chptr->chname,
964 modebuf, nickbuf);
965
966 }
967
968 if (target_p->away[0])
969 sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY,
970 ":%s!%s@%s AWAY :%s",
971 target_p->name, target_p->username,
972 target_p->host, target_p->away);
973 }
974
975 /*! \brief Blindly opers up given source_p, using conf info.
976 * All checks on passwords have already been done.
977 * \param source_p Pointer to given client to oper
978 */
979 void
980 oper_up(struct Client *source_p)
981 {
982 const unsigned int old = source_p->umodes;
983 const struct MaskItem *conf = source_p->localClient->confs.head->data;
984
985 assert(source_p->localClient->confs.head);
986
987 ++Count.oper;
988 SetOper(source_p);
989
990 if (conf->modes)
991 AddUMode(source_p, conf->modes);
992 else if (ConfigFileEntry.oper_umodes)
993 AddUMode(source_p, ConfigFileEntry.oper_umodes);
994
995 if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
996 ++Count.invisi;
997 if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
998 --Count.invisi;
999
1000 assert(dlinkFind(&oper_list, source_p) == NULL);
1001 dlinkAdd(source_p, make_dlink_node(), &oper_list);
1002
1003 AddOFlag(source_p, conf->port);
1004
1005 if (HasOFlag(source_p, OPER_FLAG_ADMIN))
1006 AddUMode(source_p, UMODE_ADMIN);
1007
1008 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "%s is now an operator",
1009 get_oper_name(source_p));
1010 send_umode_out(source_p, source_p, old);
1011 sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
1012 }
1013
1014 static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */
1015
1016 int
1017 valid_sid(const char *sid)
1018 {
1019 if (strlen(sid) == IRC_MAXSID)
1020 if (IsDigit(*sid))
1021 if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1022 return 1;
1023
1024 return 0;
1025 }
1026
1027 /*
1028 * init_uid()
1029 *
1030 * inputs - NONE
1031 * output - NONE
1032 * side effects - new_uid is filled in with server id portion (sid)
1033 * (first 3 bytes) or defaulted to 'A'.
1034 * Rest is filled in with 'A'
1035 */
1036 void
1037 init_uid(void)
1038 {
1039 memset(new_uid, 0, sizeof(new_uid));
1040
1041 if (!EmptyString(ServerInfo.sid))
1042 strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1043
1044 for (unsigned int i = 0; i < IRC_MAXSID; ++i)
1045 if (new_uid[i] == '\0')
1046 new_uid[i] = 'A';
1047
1048 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1049 memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1050 }
1051
1052 /*
1053 * add_one_to_uid
1054 *
1055 * inputs - index number into new_uid
1056 * output - NONE
1057 * side effects - new_uid is incremented by one
1058 * note this is a recursive function
1059 */
1060 static void
1061 add_one_to_uid(int i)
1062 {
1063 if (i != IRC_MAXSID) /* Not reached server SID portion yet? */
1064 {
1065 if (new_uid[i] == 'Z')
1066 new_uid[i] = '0';
1067 else if (new_uid[i] == '9')
1068 {
1069 new_uid[i] = 'A';
1070 add_one_to_uid(i-1);
1071 }
1072 else
1073 ++new_uid[i];
1074 }
1075 else
1076 {
1077 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1078 if (new_uid[i] == 'Z')
1079 memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1080 else
1081 ++new_uid[i];
1082 }
1083 }
1084
1085 /*
1086 * uid_get
1087 *
1088 * inputs - struct Client *
1089 * output - new UID is returned to caller
1090 * side effects - new_uid is incremented by one.
1091 */
1092 static const char *
1093 uid_get(void)
1094 {
1095 add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */
1096 return new_uid;
1097 }
1098
1099 /*
1100 * init_isupport()
1101 *
1102 * input - NONE
1103 * output - NONE
1104 * side effects - Must be called before isupport is enabled
1105 */
1106 void
1107 init_isupport(void)
1108 {
1109 add_isupport("CALLERID", NULL, -1);
1110 add_isupport("CASEMAPPING", CASEMAP, -1);
1111 add_isupport("DEAF", "D", -1);
1112 add_isupport("KICKLEN", NULL, KICKLEN);
1113 add_isupport("MODES", NULL, MAXMODEPARAMS);
1114 #ifdef HALFOPS
1115 add_isupport("PREFIX", "(ohv)@%+", -1);
1116 add_isupport("STATUSMSG", "@%+", -1);
1117 #else
1118 add_isupport("PREFIX", "(ov)@+", -1);
1119 add_isupport("STATUSMSG", "@+", -1);
1120 #endif
1121 add_isupport("EXCEPTS", "e", -1);
1122 add_isupport("INVEX", "I", -1);
1123 }
1124
1125 /*
1126 * add_isupport()
1127 *
1128 * input - name of supported function
1129 * - options if any
1130 * - number if any
1131 * output - NONE
1132 * side effects - Each supported item must call this when activated
1133 */
1134 void
1135 add_isupport(const char *name, const char *options, int n)
1136 {
1137 dlink_node *ptr;
1138 struct Isupport *support;
1139
1140 DLINK_FOREACH(ptr, support_list.head)
1141 {
1142 support = ptr->data;
1143 if (irccmp(support->name, name) == 0)
1144 {
1145 MyFree(support->name);
1146 MyFree(support->options);
1147 break;
1148 }
1149 }
1150
1151 if (ptr == NULL)
1152 {
1153 support = MyMalloc(sizeof(*support));
1154 dlinkAddTail(support, &support->node, &support_list);
1155 }
1156
1157 support->name = xstrdup(name);
1158 if (options != NULL)
1159 support->options = xstrdup(options);
1160 support->number = n;
1161
1162 rebuild_isupport_message_line();
1163 }
1164
1165 /*
1166 * delete_isupport()
1167 *
1168 * input - name of supported function
1169 * output - NONE
1170 * side effects - Each supported item must call this when deactivated
1171 */
1172 void
1173 delete_isupport(const char *name)
1174 {
1175 dlink_node *ptr;
1176 struct Isupport *support;
1177
1178 DLINK_FOREACH(ptr, support_list.head)
1179 {
1180 support = ptr->data;
1181 if (irccmp(support->name, name) == 0)
1182 {
1183 dlinkDelete(ptr, &support_list);
1184 MyFree(support->name);
1185 MyFree(support->options);
1186 MyFree(support);
1187 break;
1188 }
1189 }
1190
1191 rebuild_isupport_message_line();
1192 }
1193
1194 /*
1195 * rebuild_isupport_message_line
1196 *
1197 * input - NONE
1198 * output - NONE
1199 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1200 */
1201 void
1202 rebuild_isupport_message_line(void)
1203 {
1204 char isupportbuffer[IRCD_BUFSIZE];
1205 char *p = isupportbuffer;
1206 dlink_node *ptr = NULL, *ptr_next = NULL;
1207 int n = 0;
1208 int tokens = 0;
1209 size_t len = 0;
1210 size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
1211
1212 DLINK_FOREACH_SAFE(ptr, ptr_next, support_list_lines.head)
1213 {
1214 dlinkDelete(ptr, &support_list_lines);
1215 MyFree(ptr->data);
1216 free_dlink_node(ptr);
1217 }
1218
1219 DLINK_FOREACH(ptr, support_list.head)
1220 {
1221 struct Isupport *support = ptr->data;
1222
1223 p += (n = sprintf(p, "%s", support->name));
1224 len += n;
1225
1226 if (support->options != NULL)
1227 {
1228 p += (n = sprintf(p, "=%s", support->options));
1229 len += n;
1230 }
1231
1232 if (support->number > 0)
1233 {
1234 p += (n = sprintf(p, "=%d", support->number));
1235 len += n;
1236 }
1237
1238 *p++ = ' ';
1239 len++;
1240 *p = '\0';
1241
1242 if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1243 { /* arbritrary for now */
1244 if (*--p == ' ')
1245 *p = '\0';
1246
1247 dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1248 p = isupportbuffer;
1249 len = 0;
1250 n = tokens = 0;
1251 }
1252 }
1253
1254 if (len != 0)
1255 {
1256 if (*--p == ' ')
1257 *p = '\0';
1258 dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &support_list_lines);
1259 }
1260 }

Properties

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