ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/s_user.c
Revision: 471
Committed: Fri Feb 17 10:01:53 2006 UTC (18 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 39341 byte(s)
Log Message:
- Don't allocate new dlink_node pointer on each client creation,
  rather reuse localClient->lclient_node for linking it into
  unknown_list and move it into local_client_list after client
  registration.

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

Properties

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