ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_user.c
Revision: 1113
Committed: Sat Dec 18 22:44:10 2010 UTC (14 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/src/s_user.c
File size: 39826 byte(s)
Log Message:
- move Client.client_host and Client.client_server to LocalUser struct

File Contents

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

Properties

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