ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_user.c
Revision: 1143
Committed: Mon Jul 25 18:58:51 2011 UTC (14 years, 1 month ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/src/s_user.c
File size: 39590 byte(s)
Log Message:
- Update NEWS file
- Minor optimization to update_client_exit_stats close_connection
- Move MaxConnectionCount/MaxClientCount to Counter struct

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * s_user.c: User related functions.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "s_user.h"
28 #include "s_misc.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "common.h"
33 #include "fdlist.h"
34 #include "hash.h"
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "s_bsd.h"
38 #include "ircd.h"
39 #include "listener.h"
40 #include "motd.h"
41 #include "numeric.h"
42 #include "s_conf.h"
43 #include "s_log.h"
44 #include "s_serv.h"
45 #include "send.h"
46 #include "supported.h"
47 #include "whowas.h"
48 #include "memory.h"
49 #include "packet.h"
50 #include "rng_mt.h"
51 #include "userhost.h"
52 #include "hook.h"
53 #include "s_misc.h"
54 #include "msg.h"
55 #include "watch.h"
56
57
58 struct Callback *entering_umode_cb = NULL;
59 struct Callback *umode_cb = NULL;
60
61 static char umode_buffer[IRCD_BUFSIZE];
62
63 static void user_welcome(struct Client *);
64 static void report_and_set_user_flags(struct Client *, const struct AccessItem *);
65 static int check_xline(struct Client *);
66 static void introduce_client(struct Client *);
67 static const char *uid_get(void);
68
69 /* Used for building up the isupport string,
70 * used with init_isupport, add_isupport, delete_isupport
71 */
72
73 struct Isupport
74 {
75 dlink_node node;
76 char *name;
77 char *options;
78 int number;
79 };
80
81 static dlink_list support_list = { NULL, NULL, 0 };
82 MessageFile *isupportFile;
83
84 /* memory is cheap. map 0-255 to equivalent mode */
85 unsigned int user_modes[256] =
86 {
87 /* 0x00 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x0F */
88 /* 0x10 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x1F */
89 /* 0x20 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x2F */
90 /* 0x30 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x3F */
91 0, /* @ */
92 0, /* A */
93 0, /* B */
94 UMODE_CCONN_FULL, /* C */
95 UMODE_DEAF, /* D */
96 0, /* E */
97 0, /* F */
98 UMODE_SOFTCALLERID, /* G */
99 0, /* H */
100 0, /* I */
101 0, /* J */
102 0, /* K */
103 0, /* L */
104 0, /* M */
105 0, /* N */
106 0, /* O */
107 0, /* P */
108 0, /* Q */
109 0, /* R */
110 0, /* S */
111 0, /* T */
112 0, /* U */
113 0, /* V */
114 0, /* W */
115 0, /* X */
116 0, /* Y */
117 0, /* Z 0x5A */
118 0, 0, 0, 0, 0, /* 0x5F */
119 0, /* 0x60 */
120 UMODE_ADMIN, /* a */
121 UMODE_BOTS, /* b */
122 UMODE_CCONN, /* c */
123 UMODE_DEBUG, /* d */
124 0, /* e */
125 UMODE_FULL, /* f */
126 UMODE_CALLERID, /* g */
127 0, /* h */
128 UMODE_INVISIBLE, /* i */
129 0, /* j */
130 UMODE_SKILL, /* k */
131 UMODE_LOCOPS, /* l */
132 0, /* m */
133 UMODE_NCHANGE, /* n */
134 UMODE_OPER, /* o */
135 0, /* p */
136 0, /* q */
137 UMODE_REJ, /* r */
138 UMODE_SERVNOTICE, /* s */
139 0, /* t */
140 UMODE_UNAUTH, /* u */
141 0, /* v */
142 UMODE_WALLOP, /* w */
143 UMODE_EXTERNAL, /* x */
144 UMODE_SPY, /* y */
145 UMODE_OPERWALL, /* z 0x7A */
146 0,0,0,0,0, /* 0x7B - 0x7F */
147
148 /* 0x80 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x8F */
149 /* 0x90 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x9F */
150 /* 0xA0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xAF */
151 /* 0xB0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xBF */
152 /* 0xC0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xCF */
153 /* 0xD0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xDF */
154 /* 0xE0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xEF */
155 /* 0xF0 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* 0xFF */
156 };
157
158 void
159 assemble_umode_buffer(void)
160 {
161 unsigned int idx = 0;
162 char *umode_buffer_ptr = umode_buffer;
163
164 for (; idx < (sizeof(user_modes) / sizeof(user_modes[0])); ++idx)
165 if (user_modes[idx])
166 *umode_buffer_ptr++ = idx;
167
168 *umode_buffer_ptr = '\0';
169 }
170
171 /* show_lusers()
172 *
173 * inputs - pointer to client
174 * output - NONE
175 * side effects - display to client user counts etc.
176 */
177 void
178 show_lusers(struct Client *source_p)
179 {
180 const char *from, *to;
181
182 if (!MyConnect(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
183 {
184 from = me.id;
185 to = source_p->id;
186 }
187 else
188 {
189 from = me.name;
190 to = source_p->name;
191 }
192
193 if (!ConfigServerHide.hide_servers || IsOper(source_p))
194 sendto_one(source_p, form_str(RPL_LUSERCLIENT),
195 from, to, (Count.total-Count.invisi),
196 Count.invisi, dlink_list_length(&global_serv_list));
197 else
198 sendto_one(source_p, form_str(RPL_LUSERCLIENT), from, to,
199 (Count.total-Count.invisi), Count.invisi, 1);
200
201 if (Count.oper > 0)
202 sendto_one(source_p, form_str(RPL_LUSEROP),
203 from, to, Count.oper);
204
205 if (dlink_list_length(&unknown_list) > 0)
206 sendto_one(source_p, form_str(RPL_LUSERUNKNOWN),
207 from, to, dlink_list_length(&unknown_list));
208
209 if (dlink_list_length(&global_channel_list) > 0)
210 sendto_one(source_p, form_str(RPL_LUSERCHANNELS),
211 from, to, dlink_list_length(&global_channel_list));
212
213 if (!ConfigServerHide.hide_servers || IsOper(source_p))
214 {
215 sendto_one(source_p, form_str(RPL_LUSERME),
216 from, to, Count.local, Count.myserver);
217 sendto_one(source_p, form_str(RPL_LOCALUSERS),
218 from, to, Count.local, Count.max_loc,
219 Count.local, Count.max_loc);
220 }
221 else
222 {
223 sendto_one(source_p, form_str(RPL_LUSERME),
224 from, to, Count.total, 0);
225 sendto_one(source_p, form_str(RPL_LOCALUSERS),
226 from, to, Count.total, Count.max_tot,
227 Count.total, Count.max_tot);
228 }
229
230 sendto_one(source_p, form_str(RPL_GLOBALUSERS),
231 from, to, Count.total, Count.max_tot,
232 Count.total, Count.max_tot);
233
234 if (!ConfigServerHide.hide_servers || IsOper(source_p))
235 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
236 Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
237
238 if (Count.local > Count.max_loc_cli)
239 Count.max_loc_cli = Count.local;
240
241 if ((Count.local + Count.myserver) > Count.max_loc_con)
242 Count.max_loc_con = Count.local + Count.myserver;
243 }
244
245 /* show_isupport()
246 *
247 * inputs - pointer to client
248 * output - NONE
249 * side effects - display to client what we support (for them)
250 */
251 void
252 show_isupport(struct Client *source_p)
253 {
254 send_message_file(source_p, isupportFile);
255 }
256
257 /*
258 ** register_local_user
259 ** This function is called when both NICK and USER messages
260 ** have been accepted for the client, in whatever order. Only
261 ** after this, is the USER message propagated.
262 **
263 ** NICK's must be propagated at once when received, although
264 ** it would be better to delay them too until full info is
265 ** available. Doing it is not so simple though, would have
266 ** to implement the following:
267 **
268 ** (actually it has been implemented already for a while) -orabidoo
269 **
270 ** 1) user telnets in and gives only "NICK foobar" and waits
271 ** 2) another user far away logs in normally with the nick
272 ** "foobar" (quite legal, as this server didn't propagate
273 ** it).
274 ** 3) now this server gets nick "foobar" from outside, but
275 ** has alread the same defined locally. Current server
276 ** would just issue "KILL foobar" to clean out dups. But,
277 ** this is not fair. It should actually request another
278 ** nick from local user or kill him/her...
279 */
280 void
281 register_local_user(struct Client *source_p)
282 {
283 const char *id = NULL;
284 const struct AccessItem *aconf = NULL;
285 dlink_node *ptr = NULL;
286
287 assert(source_p != NULL);
288 assert(source_p == source_p->from);
289 assert(MyConnect(source_p));
290 assert(!source_p->localClient->registration);
291
292 ClearCap(source_p, CAP_TS6);
293
294 if (ConfigFileEntry.ping_cookie)
295 {
296 if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0)
297 {
298 do
299 source_p->localClient->random_ping = genrand_int32();
300 while (!source_p->localClient->random_ping);
301
302 sendto_one(source_p, "PING :%u",
303 source_p->localClient->random_ping);
304 SetPingSent(source_p);
305 return;
306 }
307
308 if (!HasPingCookie(source_p))
309 return;
310 }
311
312 source_p->localClient->last = CurrentTime;
313 /* Straight up the maximum rate of flooding... */
314 source_p->localClient->allow_read = MAX_FLOOD_BURST;
315
316 if (!execute_callback(client_check_cb, source_p, source_p->username))
317 return;
318
319 if (valid_hostname(source_p->host) == 0)
320 {
321 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You have an illegal "
322 "character in your hostname", me.name, source_p->name);
323 strlcpy(source_p->host, source_p->sockhost,
324 sizeof(source_p->host));
325 }
326
327 ptr = source_p->localClient->confs.head;
328 aconf = map_to_conf(ptr->data);
329
330 if (!IsGotId(source_p))
331 {
332 char username[USERLEN + 1];
333 const char *p = username;
334 unsigned int i = 0;
335
336 if (IsNeedIdentd(aconf))
337 {
338 ++ServerStats.is_ref;
339 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- You need to install "
340 "identd to use this server", me.name, source_p->name);
341 exit_client(source_p, &me, "Install identd");
342 return;
343 }
344
345 strlcpy(username, source_p->username, sizeof(username));
346
347 if (!IsNoTilde(aconf))
348 source_p->username[i++] = '~';
349
350 for (; *p && i < USERLEN; ++p)
351 if (*p != '[')
352 source_p->username[i++] = *p;
353
354 source_p->username[i] = '\0';
355 }
356
357 /* password check */
358 if (!EmptyString(aconf->passwd))
359 {
360 const char *pass = source_p->localClient->passwd;
361
362 if (!match_conf_password(pass, aconf))
363 {
364 ++ServerStats.is_ref;
365 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH),
366 me.name, source_p->name);
367 exit_client(source_p, &me, "Bad Password");
368 return;
369 }
370 }
371
372 /* don't free source_p->localClient->passwd here - it can be required
373 * by masked /stats I if there are auth{} blocks with need_password = no;
374 * --adx
375 */
376
377 /* report if user has &^>= etc. and set flags as needed in source_p */
378 report_and_set_user_flags(source_p, aconf);
379
380 if (IsDead(source_p))
381 return;
382
383 /* Limit clients -
384 * We want to be able to have servers and F-line clients
385 * connect, so save room for "buffer" connections.
386 * Smaller servers may want to decrease this, and it should
387 * probably be just a percentage of the MAXCLIENTS...
388 * -Taner
389 */
390 /* Except "F:" clients */
391 if ((Count.local >= ServerInfo.max_clients + MAX_BUFFER) ||
392 (Count.local >= ServerInfo.max_clients && !IsExemptLimits(source_p)))
393 {
394 sendto_realops_flags(UMODE_FULL, L_ALL,
395 "Too many clients, rejecting %s[%s].",
396 source_p->name, source_p->host);
397 ++ServerStats.is_ref;
398 exit_client(source_p, &me, "Sorry, server is full - try later");
399 return;
400 }
401
402 /* valid user name check */
403 if (valid_username(source_p->username) == 0)
404 {
405 char tmpstr2[IRCD_BUFSIZE];
406
407 sendto_realops_flags(UMODE_REJ, L_ALL, "Invalid username: %s (%s@%s)",
408 source_p->name, source_p->username, source_p->host);
409 ++ServerStats.is_ref;
410 snprintf(tmpstr2, sizeof(tmpstr2), "Invalid username [%s]",
411 source_p->username);
412 exit_client(source_p, &me, tmpstr2);
413 return;
414 }
415
416 if (check_xline(source_p))
417 return;
418
419 while (hash_find_id((id = uid_get())) != NULL)
420 ;
421
422 strlcpy(source_p->id, id, sizeof(source_p->id));
423 hash_add_id(source_p);
424
425 sendto_realops_flags(UMODE_CCONN, L_ALL,
426 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
427 source_p->name, source_p->username, source_p->host,
428 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
429 "255.255.255.255" : source_p->sockhost,
430 get_client_class(source_p),
431 source_p->info, source_p->id);
432
433 sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
434 "CLICONN %s %s %s %s %s %s %s 0 %s",
435 source_p->name, source_p->username, source_p->host,
436 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
437 "255.255.255.255" : source_p->sockhost,
438 get_client_class(source_p),
439 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
440 "<hidden>" : source_p->localClient->client_host,
441 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
442 "<hidden>" : source_p->localClient->client_server,
443 source_p->info);
444
445
446 if (ConfigFileEntry.invisible_on_connect)
447 {
448 source_p->umodes |= UMODE_INVISIBLE;
449 ++Count.invisi;
450 }
451
452 if ((++Count.local) > Count.max_loc)
453 {
454 Count.max_loc = Count.local;
455
456 if (!(Count.max_loc % 10))
457 sendto_realops_flags(UMODE_ALL, L_ALL, "New Max Local Clients: %d",
458 Count.max_loc);
459 }
460
461 /* Increment our total user count here */
462 if (++Count.total > Count.max_tot)
463 Count.max_tot = Count.total;
464 ++Count.totalrestartcount;
465
466 assert(source_p->servptr == &me);
467 SetClient(source_p);
468 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
469
470 source_p->localClient->allow_read = MAX_FLOOD_BURST;
471
472 assert(dlinkFind(&unknown_list, source_p));
473
474 dlink_move_node(&source_p->localClient->lclient_node,
475 &unknown_list, &local_client_list);
476
477 user_welcome(source_p);
478 add_user_host(source_p->username, source_p->host, 0);
479 SetUserHost(source_p);
480
481 introduce_client(source_p);
482 }
483
484 /* register_remote_user()
485 *
486 * inputs - source_p remote or directly connected client
487 * - username to register as
488 * - host name to register as
489 * - server name
490 * - realname (gecos)
491 * output - NONE
492 * side effects - This function is called when a remote client
493 * is introduced by a server.
494 */
495 void
496 register_remote_user(struct Client *source_p,
497 const char *username, const char *host, const char *server,
498 const char *realname)
499 {
500 struct Client *target_p = NULL;
501
502 assert(source_p != NULL);
503 assert(source_p->username != username);
504
505 strlcpy(source_p->host, host, sizeof(source_p->host));
506 strlcpy(source_p->username, username, sizeof(source_p->username));
507
508 /*
509 * coming from another server, take the servers word for it
510 */
511 source_p->servptr = find_server(server);
512
513 /* Super GhostDetect:
514 * If we can't find the server the user is supposed to be on,
515 * then simply blow the user away. -Taner
516 */
517 if (source_p->servptr == NULL)
518 {
519 sendto_realops_flags(UMODE_ALL, L_ALL,
520 "No server %s for user %s[%s@%s] from %s",
521 server, source_p->name, source_p->username,
522 source_p->host, source_p->from->name);
523 kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name);
524
525 SetKilled(source_p);
526 exit_client(source_p, &me, "Ghosted Client");
527 return;
528 }
529
530 if ((target_p = source_p->servptr) && target_p->from != source_p->from)
531 {
532 sendto_realops_flags(UMODE_DEBUG, L_ALL,
533 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
534 source_p->from->name, source_p->name, source_p->username,
535 source_p->host, source_p->servptr->name,
536 target_p->name, target_p->from->name);
537 kill_client(source_p->from, source_p,
538 "%s (NICK from wrong direction (%s != %s))",
539 me.name, source_p->servptr->name, target_p->from->name);
540 SetKilled(source_p);
541 exit_client(source_p, &me, "USER server wrong direction");
542 return;
543 }
544
545 /* Increment our total user count here */
546 if (++Count.total > Count.max_tot)
547 Count.max_tot = Count.total;
548
549 SetClient(source_p);
550 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
551 add_user_host(source_p->username, source_p->host, 1);
552 SetUserHost(source_p);
553
554 introduce_client(source_p);
555 }
556
557 /* introduce_client()
558 *
559 * inputs - source_p
560 * output - NONE
561 * side effects - This common function introduces a client to the rest
562 * of the net, either from a local client connect or
563 * from a remote connect.
564 */
565 static void
566 introduce_client(struct Client *source_p)
567 {
568 dlink_node *server_node = NULL;
569 static char ubuf[12];
570
571 if (MyClient(source_p))
572 send_umode(source_p, source_p, 0, SEND_UMODES, ubuf);
573 else
574 send_umode(NULL, source_p, 0, SEND_UMODES, ubuf);
575
576 watch_check_hash(source_p, RPL_LOGON);
577
578 if (*ubuf == '\0')
579 {
580 ubuf[0] = '+';
581 ubuf[1] = '\0';
582 }
583
584 DLINK_FOREACH(server_node, serv_list.head)
585 {
586 struct Client *server = server_node->data;
587
588 if (server == source_p->from)
589 continue;
590
591 if (IsCapable(server, CAP_TS6) && HasID(source_p))
592 sendto_one(server, ":%s UID %s %d %lu %s %s %s %s %s :%s",
593 source_p->servptr->id,
594 source_p->name, source_p->hopcount+1,
595 (unsigned long)source_p->tsinfo,
596 ubuf, source_p->username, source_p->host,
597 (MyClient(source_p) && IsIPSpoof(source_p)) ?
598 "0" : source_p->sockhost, source_p->id, source_p->info);
599 else
600 sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
601 source_p->name, source_p->hopcount+1,
602 (unsigned long)source_p->tsinfo,
603 ubuf, source_p->username, source_p->host,
604 source_p->servptr->name, source_p->info);
605 }
606 }
607
608 /* valid_hostname()
609 *
610 * Inputs - pointer to hostname
611 * Output - 1 if valid, 0 if not
612 * Side effects - check hostname for validity
613 *
614 * NOTE: this doesn't allow a hostname to begin with a dot and
615 * will not allow more dots than chars.
616 */
617 int
618 valid_hostname(const char *hostname)
619 {
620 const char *p = hostname;
621
622 assert(p != NULL);
623
624 if (*p == '.' || *p == ':')
625 return 0;
626
627 for (; *p; ++p)
628 if (!IsHostChar(*p))
629 return 0;
630
631 return 1;
632 }
633
634 /* valid_username()
635 *
636 * Inputs - pointer to user
637 * Output - 1 if valid, 0 if not
638 * Side effects - check username for validity
639 *
640 * Absolutely always reject any '*' '!' '?' '@' in an user name
641 * reject any odd control characters names.
642 * Allow '.' in username to allow for "first.last"
643 * style of username
644 */
645 int
646 valid_username(const char *username)
647 {
648 int dots = 0;
649 const char *p = username;
650
651 assert(p != NULL);
652
653 if (*p == '~')
654 ++p;
655
656 /* reject usernames that don't start with an alphanum
657 * i.e. reject jokers who have '-@somehost' or '.@somehost'
658 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
659 */
660 if (!IsAlNum(*p))
661 return 0;
662
663 while (*++p)
664 {
665 if ((*p == '.') && ConfigFileEntry.dots_in_ident)
666 {
667 if (++dots > ConfigFileEntry.dots_in_ident)
668 return 0;
669 if (!IsUserChar(*(p + 1)))
670 return 0;
671 }
672 else if (!IsUserChar(*p))
673 return 0;
674 }
675
676 return 1;
677 }
678
679 /* report_and_set_user_flags()
680 *
681 * inputs - pointer to source_p
682 * - pointer to aconf for this user
683 * output - NONE
684 * side effects - Report to user any special flags
685 * they are getting, and set them.
686 */
687 static void
688 report_and_set_user_flags(struct Client *source_p, const struct AccessItem *aconf)
689 {
690 /* If this user is being spoofed, tell them so */
691 if (IsConfDoSpoofIp(aconf))
692 {
693 sendto_one(source_p,
694 ":%s NOTICE %s :*** Spoofing your IP. congrats.",
695 me.name, source_p->name);
696 }
697
698 /* If this user is in the exception class, Set it "E lined" */
699 if (IsConfExemptKline(aconf))
700 {
701 SetExemptKline(source_p);
702 sendto_one(source_p,
703 ":%s NOTICE %s :*** You are exempt from K/D/G lines. congrats.",
704 me.name, source_p->name);
705 }
706
707 /* The else here is to make sure that G line exempt users
708 * do not get noticed twice.
709 */
710 else if (IsConfExemptGline(aconf))
711 {
712 SetExemptGline(source_p);
713 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from G lines.",
714 me.name, source_p->name);
715 }
716
717 if (IsConfExemptResv(aconf))
718 {
719 SetExemptResv(source_p);
720 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from resvs.",
721 me.name, source_p->name);
722 }
723
724 /* If this user is exempt from user limits set it "F lined" */
725 if (IsConfExemptLimits(aconf))
726 {
727 SetExemptLimits(source_p);
728 sendto_one(source_p,
729 ":%s NOTICE %s :*** You are exempt from user limits. congrats.",
730 me.name,source_p->name);
731 }
732
733 /* If this user is exempt from idle time outs */
734 if (IsConfIdlelined(aconf))
735 {
736 SetIdlelined(source_p);
737 sendto_one(source_p,
738 ":%s NOTICE %s :*** You are exempt from idle limits. congrats.",
739 me.name, source_p->name);
740 }
741
742 if (IsConfCanFlood(aconf))
743 {
744 SetCanFlood(source_p);
745 sendto_one(source_p, ":%s NOTICE %s :*** You are exempt from flood "
746 "protection, aren't you fearsome.",
747 me.name, source_p->name);
748 }
749 }
750
751 /* change_simple_umode()
752 *
753 * this callback can be hooked to allow special handling of
754 * certain usermodes
755 */
756 static void *
757 change_simple_umode(va_list args)
758 {
759 struct Client *client_p;
760 struct Client *source_p;
761 int what;
762 unsigned int flag;
763
764 client_p = va_arg(args, struct Client *);
765 source_p = va_arg(args, struct Client *);
766 what = va_arg(args, int);
767 flag = va_arg(args, unsigned int);
768
769 if (what == MODE_ADD)
770 source_p->umodes |= flag;
771 else
772 source_p->umodes &= ~flag;
773
774 return NULL;
775 }
776
777 /* set_user_mode()
778 *
779 * added 15/10/91 By Darren Reed.
780 * parv[0] - sender
781 * parv[1] - username to change mode for
782 * parv[2] - modes to change
783 */
784 void
785 set_user_mode(struct Client *client_p, struct Client *source_p,
786 int parc, char *parv[])
787 {
788 unsigned int flag, setflags;
789 char **p, *m, buf[IRCD_BUFSIZE];
790 struct Client *target_p;
791 int what = MODE_ADD, badflag = 0, i;
792
793 assert(!(parc < 2));
794
795 if ((target_p = find_person(client_p, parv[1])) == NULL)
796 {
797 if (MyConnect(source_p))
798 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
799 me.name, source_p->name, parv[1]);
800 return;
801 }
802
803 if (IsServer(source_p))
804 {
805 sendto_realops_flags(UMODE_ALL, L_ADMIN, "*** Mode for User %s from %s",
806 parv[1], source_p->name);
807 return;
808 }
809
810 if (source_p != target_p)
811 {
812 sendto_one(source_p, form_str(ERR_USERSDONTMATCH),
813 me.name, source_p->name);
814 return;
815 }
816
817 if (parc < 3)
818 {
819 m = buf;
820 *m++ = '+';
821
822 for (i = 0; i < 128; i++)
823 if (source_p->umodes & user_modes[i])
824 *m++ = (char)i;
825 *m = '\0';
826
827 sendto_one(source_p, form_str(RPL_UMODEIS),
828 me.name, source_p->name, buf);
829 return;
830 }
831
832 execute_callback(entering_umode_cb, client_p, source_p);
833
834 /* find flags already set for user */
835 setflags = source_p->umodes;
836
837 /* parse mode change string(s) */
838 for (p = &parv[2]; p && *p; p++)
839 {
840 for (m = *p; *m; m++)
841 {
842 switch (*m)
843 {
844 case '+':
845 what = MODE_ADD;
846 break;
847 case '-':
848 what = MODE_DEL;
849 break;
850 case 'o':
851 if (what == MODE_ADD)
852 {
853 if (IsServer(client_p) && !IsOper(source_p))
854 {
855 ++Count.oper;
856 SetOper(source_p);
857 }
858 }
859 else
860 {
861 /* Only decrement the oper counts if an oper to begin with
862 * found by Pat Szuta, Perly , perly@xnet.com
863 */
864 if (!IsOper(source_p))
865 break;
866
867 ClearOper(source_p);
868 Count.oper--;
869
870 if (MyConnect(source_p))
871 {
872 dlink_node *dm;
873
874 detach_conf(source_p, OPER_TYPE);
875 ClearOperFlags(source_p);
876 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
877
878 if ((dm = dlinkFindDelete(&oper_list, source_p)) != NULL)
879 free_dlink_node(dm);
880 }
881 }
882
883 break;
884
885 /* we may not get these,
886 * but they shouldnt be in default
887 */
888 case ' ' :
889 case '\n':
890 case '\r':
891 case '\t':
892 break;
893
894 default:
895 if ((flag = user_modes[(unsigned char)*m]))
896 {
897 if (MyConnect(source_p) && !IsOper(source_p) &&
898 (ConfigFileEntry.oper_only_umodes & flag))
899 {
900 badflag = 1;
901 }
902 else
903 execute_callback(umode_cb, client_p, source_p, what, flag);
904 }
905 else
906 {
907 if (MyConnect(source_p))
908 badflag = 1;
909 }
910
911 break;
912 }
913 }
914 }
915
916 if (badflag)
917 sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
918 me.name, source_p->name);
919
920 if ((source_p->umodes & UMODE_NCHANGE) && !IsOperN(source_p))
921 {
922 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
923 me.name, source_p->name);
924 source_p->umodes &= ~UMODE_NCHANGE; /* only tcm's really need this */
925 }
926
927 if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
928 !IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
929 {
930 sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
931 me.name, source_p->name);
932 source_p->umodes &= ~UMODE_ADMIN;
933 }
934
935 if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
936 ++Count.invisi;
937 if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
938 --Count.invisi;
939
940 /*
941 * compare new flags with old flags and send string which
942 * will cause servers to update correctly.
943 */
944 send_umode_out(client_p, source_p, setflags);
945 }
946
947 /* send_umode()
948 * send the MODE string for user (user) to connection client_p
949 * -avalon
950 *
951 * inputs - client_p
952 * - source_p
953 * - int old
954 * - sendmask mask of modes to send
955 * - suplied umode_buf
956 * output - NONE
957 */
958 void
959 send_umode(struct Client *client_p, struct Client *source_p,
960 unsigned int old, unsigned int sendmask, char *umode_buf)
961 {
962 char *m = umode_buf;
963 int what = 0;
964 unsigned int i;
965 unsigned int flag;
966
967 /*
968 * build a string in umode_buf to represent the change in the user's
969 * mode between the new (source_p->umodes) and 'old'.
970 */
971 for (i = 0; i < 128; i++)
972 {
973 flag = user_modes[i];
974 if (!flag)
975 continue;
976
977 if (MyClient(source_p) && !(flag & sendmask))
978 continue;
979
980 if ((flag & old) && !(source_p->umodes & flag))
981 {
982 if (what == MODE_DEL)
983 *m++ = (char)i;
984 else
985 {
986 what = MODE_DEL;
987 *m++ = '-';
988 *m++ = (char)i;
989 }
990 }
991 else if (!(flag & old) && (source_p->umodes & flag))
992 {
993 if (what == MODE_ADD)
994 *m++ = (char)i;
995 else
996 {
997 what = MODE_ADD;
998 *m++ = '+';
999 *m++ = (char)i;
1000 }
1001 }
1002 }
1003
1004 *m = '\0';
1005
1006 if (*umode_buf && client_p)
1007 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1008 source_p->name, source_p->username,
1009 source_p->host, source_p->name, umode_buf);
1010 }
1011
1012 /* send_umode_out()
1013 *
1014 * inputs -
1015 * output - NONE
1016 * side effects - Only send ubuf out to servers that know about this client
1017 */
1018 void
1019 send_umode_out(struct Client *client_p, struct Client *source_p,
1020 unsigned int old)
1021 {
1022 char buf[IRCD_BUFSIZE] = { '\0' };
1023 dlink_node *ptr = NULL;
1024
1025 send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1026 SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1027
1028 if (buf[0])
1029 {
1030 DLINK_FOREACH(ptr, serv_list.head)
1031 {
1032 struct Client *target_p = ptr->data;
1033
1034 if ((target_p != client_p) && (target_p != source_p))
1035 sendto_one(target_p, ":%s MODE %s :%s",
1036 ID_or_name(source_p, target_p),
1037 ID_or_name(source_p, target_p), buf);
1038 }
1039 }
1040
1041 if (client_p && MyClient(client_p))
1042 send_umode(client_p, source_p, old, 0xffffffff, buf);
1043 }
1044
1045 /* user_welcome()
1046 *
1047 * inputs - client pointer to client to welcome
1048 * output - NONE
1049 * side effects -
1050 */
1051 static void
1052 user_welcome(struct Client *source_p)
1053 {
1054 #if defined(__TIME__) && defined(__DATE__)
1055 static const char built_date[] = __DATE__ " at " __TIME__;
1056 #else
1057 static const char built_date[] = "unknown";
1058 #endif
1059
1060 #ifdef HAVE_LIBCRYPTO
1061 if (source_p->localClient->fd.ssl != NULL)
1062 sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1063 me.name, source_p->name,
1064 ssl_get_cipher(source_p->localClient->fd.ssl));
1065 #endif
1066
1067 sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
1068 ServerInfo.network_name, source_p->name);
1069 sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
1070 get_listener_name(source_p->localClient->listener), ircd_version);
1071 sendto_one(source_p, form_str(RPL_CREATED),
1072 me.name, source_p->name, built_date);
1073 sendto_one(source_p, form_str(RPL_MYINFO),
1074 me.name, source_p->name, me.name, ircd_version, umode_buffer);
1075 show_isupport(source_p);
1076
1077 if (source_p->id[0] != '\0')
1078 sendto_one(source_p, form_str(RPL_YOURID), me.name,
1079 source_p->name, source_p->id);
1080
1081 show_lusers(source_p);
1082
1083 if (ConfigFileEntry.short_motd)
1084 {
1085 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- motd was last changed at %s",
1086 me.name, source_p->name, ConfigFileEntry.motd.lastChangedDate);
1087 sendto_one(source_p,
1088 ":%s NOTICE %s :*** Notice -- Please read the motd if you haven't "
1089 "read it", me.name, source_p->name);
1090 sendto_one(source_p, form_str(RPL_MOTDSTART),
1091 me.name, source_p->name, me.name);
1092 sendto_one(source_p, form_str(RPL_MOTD),
1093 me.name, source_p->name,
1094 "*** This is the short motd ***");
1095 sendto_one(source_p, form_str(RPL_ENDOFMOTD),
1096 me.name, source_p->name);
1097 }
1098 else
1099 send_message_file(source_p, &ConfigFileEntry.motd);
1100 }
1101
1102 /* check_xline()
1103 *
1104 * inputs - pointer to client to test
1105 * outupt - 1 if exiting 0 if ok
1106 * side effects -
1107 */
1108 static int
1109 check_xline(struct Client *source_p)
1110 {
1111 struct ConfItem *conf = NULL;
1112 const char *reason = NULL;
1113
1114 if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1115 (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1116 {
1117 struct MatchItem *reg = map_to_conf(conf);
1118
1119 ++reg->count;
1120
1121 if (reg->reason != NULL)
1122 reason = reg->reason;
1123 else
1124 reason = "No Reason";
1125
1126 sendto_realops_flags(UMODE_REJ, L_ALL,
1127 "X-line Rejecting [%s] [%s], user %s [%s]",
1128 source_p->info, reason,
1129 get_client_name(source_p, HIDE_IP),
1130 source_p->sockhost);
1131
1132 ++ServerStats.is_ref;
1133 if (REJECT_HOLD_TIME > 0)
1134 {
1135 sendto_one(source_p, ":%s NOTICE %s :Bad user info",
1136 me.name, source_p->name);
1137 source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
1138 SetCaptured(source_p);
1139 }
1140 else
1141 exit_client(source_p, &me, "Bad user info");
1142 return 1;
1143 }
1144
1145 return 0;
1146 }
1147
1148 /* oper_up()
1149 *
1150 * inputs - pointer to given client to oper
1151 * output - NONE
1152 * side effects - Blindly opers up given source_p, using aconf info
1153 * all checks on passwords have already been done.
1154 * This could also be used by rsa oper routines.
1155 */
1156 void
1157 oper_up(struct Client *source_p)
1158 {
1159 unsigned int old = source_p->umodes;
1160 const char *operprivs = "";
1161 const struct AccessItem *oconf = NULL;
1162
1163 assert(source_p->localClient->confs.head);
1164 oconf = map_to_conf((source_p->localClient->confs.head)->data);
1165
1166 ++Count.oper;
1167 SetOper(source_p);
1168
1169 if (oconf->modes)
1170 source_p->umodes |= oconf->modes;
1171 else if (ConfigFileEntry.oper_umodes)
1172 source_p->umodes |= ConfigFileEntry.oper_umodes;
1173 else
1174 source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1175 UMODE_WALLOP|UMODE_LOCOPS);
1176
1177 if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1178 ++Count.invisi;
1179 if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1180 --Count.invisi;
1181
1182 assert(dlinkFind(&oper_list, source_p) == NULL);
1183 dlinkAdd(source_p, make_dlink_node(), &oper_list);
1184
1185 operprivs = oper_privs_as_string(oconf->port);
1186
1187 SetOFlag(source_p, oconf->port);
1188
1189 if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))
1190 source_p->umodes |= UMODE_ADMIN;
1191 if (!IsOperN(source_p))
1192 source_p->umodes &= ~UMODE_NCHANGE;
1193
1194 sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator",
1195 source_p->name, source_p->username, source_p->host);
1196 send_umode_out(source_p, source_p, old);
1197 sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1198 sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s",
1199 me.name, source_p->name, operprivs);
1200 send_message_file(source_p, &ConfigFileEntry.opermotd);
1201 }
1202
1203 static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */
1204
1205 int
1206 valid_sid(const char *sid)
1207 {
1208 if (strlen(sid) == IRC_MAXSID)
1209 if (IsDigit(*sid))
1210 if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1211 return 1;
1212
1213 return 0;
1214 }
1215
1216 /*
1217 * init_uid()
1218 *
1219 * inputs - NONE
1220 * output - NONE
1221 * side effects - new_uid is filled in with server id portion (sid)
1222 * (first 3 bytes) or defaulted to 'A'.
1223 * Rest is filled in with 'A'
1224 */
1225 void
1226 init_uid(void)
1227 {
1228 int i;
1229
1230 memset(new_uid, 0, sizeof(new_uid));
1231
1232 if (!EmptyString(ServerInfo.sid))
1233 strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1234
1235 for (i = 0; i < IRC_MAXSID; ++i)
1236 if (new_uid[i] == '\0')
1237 new_uid[i] = 'A';
1238
1239 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1240 /* Yes nenolod, I have known it was off by one ever since I wrote it
1241 * But *JUST* for you, though, it really doesn't look as *pretty*
1242 * -Dianora
1243 */
1244 memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1245
1246 entering_umode_cb = register_callback("entering_umode", NULL);
1247 umode_cb = register_callback("changing_umode", change_simple_umode);
1248 }
1249
1250 /*
1251 * add_one_to_uid
1252 *
1253 * inputs - index number into new_uid
1254 * output - NONE
1255 * side effects - new_uid is incremented by one
1256 * note this is a recursive function
1257 */
1258 static void
1259 add_one_to_uid(int i)
1260 {
1261 if (i != IRC_MAXSID) /* Not reached server SID portion yet? */
1262 {
1263 if (new_uid[i] == 'Z')
1264 new_uid[i] = '0';
1265 else if (new_uid[i] == '9')
1266 {
1267 new_uid[i] = 'A';
1268 add_one_to_uid(i-1);
1269 }
1270 else
1271 ++new_uid[i];
1272 }
1273 else
1274 {
1275 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1276 if (new_uid[i] == 'Z')
1277 memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1278 else
1279 ++new_uid[i];
1280 }
1281 }
1282
1283 /*
1284 * uid_get
1285 *
1286 * inputs - struct Client *
1287 * output - new UID is returned to caller
1288 * side effects - new_uid is incremented by one.
1289 */
1290 static const char *
1291 uid_get(void)
1292 {
1293 add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */
1294 return new_uid;
1295 }
1296
1297 /*
1298 * init_isupport()
1299 *
1300 * input - NONE
1301 * output - NONE
1302 * side effects - Must be called before isupport is enabled
1303 */
1304 void
1305 init_isupport(void)
1306 {
1307 isupportFile = init_MessageLine();
1308
1309 add_isupport("CALLERID", NULL, -1);
1310 add_isupport("CASEMAPPING", CASEMAP, -1);
1311 add_isupport("DEAF", "D", -1);
1312 add_isupport("KICKLEN", NULL, KICKLEN);
1313 add_isupport("MODES", NULL, MAXMODEPARAMS);
1314 add_isupport("NICKLEN", NULL, NICKLEN-1);
1315 #ifdef HALFOPS
1316 add_isupport("PREFIX", "(ohv)@%+", -1);
1317 add_isupport("STATUSMSG", "@%+", -1);
1318 #else
1319 add_isupport("PREFIX", "(ov)@+", -1);
1320 add_isupport("STATUSMSG", "@+", -1);
1321 #endif
1322 add_isupport("TOPICLEN", NULL, TOPICLEN);
1323 }
1324
1325 /*
1326 * add_isupport()
1327 *
1328 * input - name of supported function
1329 * - options if any
1330 * - number if any
1331 * output - NONE
1332 * side effects - Each supported item must call this when activated
1333 */
1334 void
1335 add_isupport(const char *name, const char *options, int n)
1336 {
1337 dlink_node *ptr;
1338 struct Isupport *support;
1339
1340 DLINK_FOREACH(ptr, support_list.head)
1341 {
1342 support = ptr->data;
1343 if (irccmp(support->name, name) == 0)
1344 {
1345 MyFree(support->name);
1346 MyFree(support->options);
1347 break;
1348 }
1349 }
1350
1351 if (ptr == NULL)
1352 {
1353 support = MyMalloc(sizeof(*support));
1354 dlinkAddTail(support, &support->node, &support_list);
1355 }
1356
1357 DupString(support->name, name);
1358 if (options != NULL)
1359 DupString(support->options, options);
1360 support->number = n;
1361
1362 rebuild_isupport_message_line();
1363 }
1364
1365 /*
1366 * delete_isupport()
1367 *
1368 * input - name of supported function
1369 * output - NONE
1370 * side effects - Each supported item must call this when deactivated
1371 */
1372 void
1373 delete_isupport(const char *name)
1374 {
1375 dlink_node *ptr;
1376 struct Isupport *support;
1377
1378 DLINK_FOREACH(ptr, support_list.head)
1379 {
1380 support = ptr->data;
1381 if (irccmp(support->name, name) == 0)
1382 {
1383 dlinkDelete(ptr, &support_list);
1384 MyFree(support->name);
1385 MyFree(support->options);
1386 MyFree(support);
1387 break;
1388 }
1389 }
1390
1391 rebuild_isupport_message_line();
1392 }
1393
1394 /*
1395 * rebuild_isupport_message_line
1396 *
1397 * input - NONE
1398 * output - NONE
1399 * side effects - Destroy the isupport MessageFile lines, and rebuild.
1400 */
1401 void
1402 rebuild_isupport_message_line(void)
1403 {
1404 char isupportbuffer[IRCD_BUFSIZE];
1405 char *p = isupportbuffer;
1406 dlink_node *ptr = NULL;
1407 int n = 0;
1408 int tokens = 0;
1409 size_t len = 0;
1410 size_t reserve = strlen(me.name) + HOSTLEN + strlen(form_str(RPL_ISUPPORT));
1411
1412 destroy_MessageLine(isupportFile);
1413
1414 DLINK_FOREACH(ptr, support_list.head)
1415 {
1416 struct Isupport *support = ptr->data;
1417
1418 p += (n = ircsprintf(p, "%s", support->name));
1419 len += n;
1420
1421 if (support->options != NULL)
1422 {
1423 p += (n = ircsprintf(p, "=%s", support->options));
1424 len += n;
1425 }
1426
1427 if (support->number > 0)
1428 {
1429 p += (n = ircsprintf(p, "=%d", support->number));
1430 len += n;
1431 }
1432
1433 *p++ = ' ';
1434 len++;
1435 *p = '\0';
1436
1437 if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
1438 { /* arbritrary for now */
1439 if (*--p == ' ')
1440 *p = '\0';
1441
1442 addto_MessageLine(isupportFile, isupportbuffer);
1443 p = isupportbuffer;
1444 len = 0;
1445 n = tokens = 0;
1446 }
1447 }
1448
1449 if (len != 0)
1450 {
1451 if (*--p == ' ')
1452 *p = '\0';
1453 addto_MessageLine(isupportFile, isupportbuffer);
1454 }
1455 }

Properties

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