ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/s_user.c
Revision: 1158
Committed: Wed Aug 10 19:46:00 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 39605 byte(s)
Log Message:
- UMODE_REJ goes to usermode 'j'
- add UMODE_REGISTERED ('r') (registered nickname)

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 1143
58 adx 30 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 michael 1080 static void introduce_client(struct Client *);
67     static const char *uid_get(void);
68 adx 30
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 db 849 UMODE_CCONN_FULL, /* C */
95 adx 30 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 michael 1158 UMODE_REJ, /* j */
130 adx 30 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 michael 1158 UMODE_REGISTERED, /* r */
138 adx 30 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 michael 1013 for (; idx < (sizeof(user_modes) / sizeof(user_modes[0])); ++idx)
165 adx 30 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 michael 56 (Count.total-Count.invisi), Count.invisi, 1);
200 adx 30
201     if (Count.oper > 0)
202     sendto_one(source_p, form_str(RPL_LUSEROP),
203 michael 56 from, to, Count.oper);
204 adx 30
205     if (dlink_list_length(&unknown_list) > 0)
206     sendto_one(source_p, form_str(RPL_LUSERUNKNOWN),
207 michael 56 from, to, dlink_list_length(&unknown_list));
208 adx 30
209     if (dlink_list_length(&global_channel_list) > 0)
210     sendto_one(source_p, form_str(RPL_LUSERCHANNELS),
211 michael 56 from, to, dlink_list_length(&global_channel_list));
212 adx 30
213     if (!ConfigServerHide.hide_servers || IsOper(source_p))
214     {
215     sendto_one(source_p, form_str(RPL_LUSERME),
216 michael 56 from, to, Count.local, Count.myserver);
217 adx 30 sendto_one(source_p, form_str(RPL_LOCALUSERS),
218 michael 56 from, to, Count.local, Count.max_loc,
219     Count.local, Count.max_loc);
220 adx 30 }
221     else
222     {
223     sendto_one(source_p, form_str(RPL_LUSERME),
224 michael 56 from, to, Count.total, 0);
225 adx 30 sendto_one(source_p, form_str(RPL_LOCALUSERS),
226 michael 56 from, to, Count.total, Count.max_tot,
227 adx 30 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 michael 1143 Count.max_loc_con, Count.max_loc_cli, Count.totalrestartcount);
237 adx 30
238 michael 1143 if (Count.local > Count.max_loc_cli)
239     Count.max_loc_cli = Count.local;
240 adx 30
241 michael 1143 if ((Count.local + Count.myserver) > Count.max_loc_con)
242     Count.max_loc_con = Count.local + Count.myserver;
243 adx 30 }
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 michael 1080 register_local_user(struct Client *source_p)
282 adx 30 {
283 michael 1115 const char *id = NULL;
284 adx 30 const struct AccessItem *aconf = NULL;
285 michael 56 dlink_node *ptr = NULL;
286 adx 30
287     assert(source_p != NULL);
288 michael 1080 assert(source_p == source_p->from);
289 adx 30 assert(MyConnect(source_p));
290 michael 503 assert(!source_p->localClient->registration);
291 adx 30
292 michael 1080 ClearCap(source_p, CAP_TS6);
293 michael 589
294 adx 30 if (ConfigFileEntry.ping_cookie)
295     {
296 michael 1080 if (!IsPingSent(source_p) && source_p->localClient->random_ping == 0)
297 adx 30 {
298 michael 983 do
299     source_p->localClient->random_ping = genrand_int32();
300     while (!source_p->localClient->random_ping);
301    
302 michael 982 sendto_one(source_p, "PING :%u",
303 adx 30 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 michael 1080 if (!execute_callback(client_check_cb, source_p, source_p->username))
317 adx 30 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 michael 1080 char username[USERLEN + 1];
333     const char *p = username;
334 adx 30 unsigned int i = 0;
335    
336     if (IsNeedIdentd(aconf))
337     {
338 michael 896 ++ServerStats.is_ref;
339 adx 30 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 michael 1080 strlcpy(username, source_p->username, sizeof(username));
346 adx 30
347     if (!IsNoTilde(aconf))
348     source_p->username[i++] = '~';
349    
350 michael 1080 for (; *p && i < USERLEN; ++p)
351 adx 30 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 michael 896 ++ServerStats.is_ref;
365 adx 30 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 michael 1080 if (IsDead(source_p))
381 michael 980 return;
382    
383 adx 30 /* 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 michael 1080 source_p->name, source_p->host);
397 michael 896 ++ServerStats.is_ref;
398 adx 30 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 michael 1080 source_p->name, source_p->username, source_p->host);
409 michael 896 ++ServerStats.is_ref;
410 michael 1124 snprintf(tmpstr2, sizeof(tmpstr2), "Invalid username [%s]",
411     source_p->username);
412 adx 30 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 1115 while (hash_find_id((id = uid_get())) != NULL)
420     ;
421 michael 573
422 michael 1115 strlcpy(source_p->id, id, sizeof(source_p->id));
423     hash_add_id(source_p);
424 adx 30
425     sendto_realops_flags(UMODE_CCONN, L_ALL,
426 michael 1137 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
427 michael 1080 source_p->name, source_p->username, source_p->host,
428 adx 30 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
429 michael 891 "255.255.255.255" : source_p->sockhost,
430     get_client_class(source_p),
431 michael 1137 source_p->info, source_p->id);
432 adx 30
433 db 849 sendto_realops_flags(UMODE_CCONN_FULL, L_ALL,
434     "CLICONN %s %s %s %s %s %s %s 0 %s",
435 michael 1080 source_p->name, source_p->username, source_p->host,
436 db 849 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
437 michael 891 "255.255.255.255" : source_p->sockhost,
438 db 849 get_client_class(source_p),
439     ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
440 michael 1113 "<hidden>" : source_p->localClient->client_host,
441 db 849 ConfigFileEntry.hide_spoof_ips && IsIPSpoof(source_p) ?
442 michael 1113 "<hidden>" : source_p->localClient->client_server,
443 db 849 source_p->info);
444    
445    
446 adx 30 if (ConfigFileEntry.invisible_on_connect)
447 michael 159 {
448 adx 30 source_p->umodes |= UMODE_INVISIBLE;
449 michael 980 ++Count.invisi;
450 michael 159 }
451 adx 30
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 michael 948 ++Count.totalrestartcount;
465 adx 30
466 michael 1080 assert(source_p->servptr == &me);
467     SetClient(source_p);
468     dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
469    
470 adx 30 source_p->localClient->allow_read = MAX_FLOOD_BURST;
471    
472 michael 1125 assert(dlinkFind(&unknown_list, source_p));
473 michael 1013
474 michael 1126 dlink_move_node(&source_p->localClient->lclient_node,
475     &unknown_list, &local_client_list);
476 adx 30
477     user_welcome(source_p);
478     add_user_host(source_p->username, source_p->host, 0);
479     SetUserHost(source_p);
480    
481 michael 1080 introduce_client(source_p);
482 adx 30 }
483    
484     /* register_remote_user()
485     *
486 michael 1080 * inputs - source_p remote or directly connected client
487 adx 30 * - 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 michael 1080 register_remote_user(struct Client *source_p,
497 michael 56 const char *username, const char *host, const char *server,
498     const char *realname)
499 adx 30 {
500 michael 56 struct Client *target_p = NULL;
501 adx 30
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 michael 1080 kill_client(source_p->from, source_p, "%s (Server doesn't exist)", me.name);
524 adx 30
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 michael 1080 source_p->from->name, source_p->name, source_p->username,
535 adx 30 source_p->host, source_p->servptr->name,
536     target_p->name, target_p->from->name);
537 michael 1080 kill_client(source_p->from, source_p,
538 adx 30 "%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 michael 510 /* Increment our total user count here */
546     if (++Count.total > Count.max_tot)
547     Count.max_tot = Count.total;
548    
549 adx 30 SetClient(source_p);
550 michael 889 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
551 adx 30 add_user_host(source_p->username, source_p->host, 1);
552     SetUserHost(source_p);
553    
554 michael 1080 introduce_client(source_p);
555 adx 30 }
556    
557     /* introduce_client()
558     *
559 michael 1080 * inputs - source_p
560 adx 30 * 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 michael 1080 introduce_client(struct Client *source_p)
567 adx 30 {
568 michael 56 dlink_node *server_node = NULL;
569 adx 30 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 michael 876 watch_check_hash(source_p, RPL_LOGON);
577    
578 adx 30 if (*ubuf == '\0')
579     {
580     ubuf[0] = '+';
581     ubuf[1] = '\0';
582     }
583    
584 michael 885 DLINK_FOREACH(server_node, serv_list.head)
585     {
586     struct Client *server = server_node->data;
587 adx 30
588 michael 1080 if (server == source_p->from)
589 michael 885 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 adx 30 source_p->servptr->id,
594     source_p->name, source_p->hopcount+1,
595 adx 386 (unsigned long)source_p->tsinfo,
596 adx 30 ubuf, source_p->username, source_p->host,
597 adx 386 (MyClient(source_p) && IsIPSpoof(source_p)) ?
598     "0" : source_p->sockhost, source_p->id, source_p->info);
599 adx 30 else
600 michael 885 sendto_one(server, "NICK %s %d %lu %s %s %s %s :%s",
601 adx 30 source_p->name, source_p->hopcount+1,
602 adx 386 (unsigned long)source_p->tsinfo,
603 adx 30 ubuf, source_p->username, source_p->host,
604 adx 386 source_p->servptr->name, source_p->info);
605 adx 30 }
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 michael 1080 if (*p == '.' || *p == ':')
625 michael 56 return 0;
626 adx 30
627 michael 1080 for (; *p; ++p)
628 adx 30 if (!IsHostChar(*p))
629 michael 56 return 0;
630 adx 30
631 michael 56 return 1;
632 adx 30 }
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 michael 1080 if (*p == '~')
654 adx 30 ++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 michael 56 return 0;
662 adx 30
663     while (*++p)
664     {
665     if ((*p == '.') && ConfigFileEntry.dots_in_ident)
666     {
667 michael 1080 if (++dots > ConfigFileEntry.dots_in_ident)
668 michael 56 return 0;
669 michael 1080 if (!IsUserChar(*(p + 1)))
670 michael 56 return 0;
671 adx 30 }
672     else if (!IsUserChar(*p))
673 michael 56 return 0;
674 adx 30 }
675    
676 michael 56 return 1;
677 adx 30 }
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 michael 627 struct Client *client_p;
760 adx 30 struct Client *source_p;
761     int what;
762     unsigned int flag;
763    
764 michael 627 client_p = va_arg(args, struct Client *);
765 adx 30 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 michael 56
793     assert(!(parc < 2));
794    
795 adx 30 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 michael 1115 if (source_p != target_p)
811 adx 30 {
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 michael 1116 source_p->umodes &= ~ConfigFileEntry.oper_only_umodes;
877 adx 30
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 michael 1158 case 'r':
889 adx 30 case ' ' :
890     case '\n':
891     case '\r':
892     case '\t':
893     break;
894    
895     default:
896     if ((flag = user_modes[(unsigned char)*m]))
897     {
898     if (MyConnect(source_p) && !IsOper(source_p) &&
899     (ConfigFileEntry.oper_only_umodes & flag))
900     {
901     badflag = 1;
902     }
903     else
904 michael 56 execute_callback(umode_cb, client_p, source_p, what, flag);
905 adx 30 }
906     else
907     {
908     if (MyConnect(source_p))
909     badflag = 1;
910     }
911    
912     break;
913     }
914     }
915     }
916    
917     if (badflag)
918     sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG),
919     me.name, source_p->name);
920    
921 michael 1158 if (HasUMode(source_p, UMODE_NCHANGE) && !IsOperN(source_p))
922 adx 30 {
923     sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
924     me.name, source_p->name);
925 michael 1158 DelUMode(source_p, UMODE_NCHANGE); /* only tcm's really need this */
926 adx 30 }
927    
928     if (MyConnect(source_p) && (source_p->umodes & UMODE_ADMIN) &&
929     !IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
930     {
931     sendto_one(source_p, ":%s NOTICE %s :*** You have no admin flag;",
932     me.name, source_p->name);
933     source_p->umodes &= ~UMODE_ADMIN;
934     }
935    
936     if (!(setflags & UMODE_INVISIBLE) && IsInvisible(source_p))
937     ++Count.invisi;
938     if ((setflags & UMODE_INVISIBLE) && !IsInvisible(source_p))
939     --Count.invisi;
940    
941 michael 56 /*
942     * compare new flags with old flags and send string which
943 adx 30 * will cause servers to update correctly.
944     */
945     send_umode_out(client_p, source_p, setflags);
946     }
947    
948     /* send_umode()
949     * send the MODE string for user (user) to connection client_p
950     * -avalon
951 db 849 *
952     * inputs - client_p
953     * - source_p
954     * - int old
955     * - sendmask mask of modes to send
956     * - suplied umode_buf
957     * output - NONE
958 adx 30 */
959     void
960     send_umode(struct Client *client_p, struct Client *source_p,
961     unsigned int old, unsigned int sendmask, char *umode_buf)
962     {
963 michael 1013 char *m = umode_buf;
964 adx 30 int what = 0;
965     unsigned int i;
966     unsigned int flag;
967    
968 michael 56 /*
969     * build a string in umode_buf to represent the change in the user's
970 adx 30 * mode between the new (source_p->umodes) and 'old'.
971     */
972     for (i = 0; i < 128; i++)
973     {
974     flag = user_modes[i];
975     if (!flag)
976     continue;
977    
978     if (MyClient(source_p) && !(flag & sendmask))
979     continue;
980    
981     if ((flag & old) && !(source_p->umodes & flag))
982     {
983     if (what == MODE_DEL)
984     *m++ = (char)i;
985     else
986     {
987     what = MODE_DEL;
988     *m++ = '-';
989     *m++ = (char)i;
990     }
991     }
992     else if (!(flag & old) && (source_p->umodes & flag))
993     {
994     if (what == MODE_ADD)
995     *m++ = (char)i;
996     else
997     {
998     what = MODE_ADD;
999     *m++ = '+';
1000     *m++ = (char)i;
1001     }
1002     }
1003     }
1004    
1005     *m = '\0';
1006    
1007     if (*umode_buf && client_p)
1008 michael 528 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
1009     source_p->name, source_p->username,
1010     source_p->host, source_p->name, umode_buf);
1011 adx 30 }
1012    
1013     /* send_umode_out()
1014     *
1015     * inputs -
1016     * output - NONE
1017     * side effects - Only send ubuf out to servers that know about this client
1018     */
1019     void
1020     send_umode_out(struct Client *client_p, struct Client *source_p,
1021     unsigned int old)
1022     {
1023 michael 573 char buf[IRCD_BUFSIZE] = { '\0' };
1024 adx 30 dlink_node *ptr = NULL;
1025    
1026     send_umode(NULL, source_p, old, IsOperHiddenAdmin(source_p) ?
1027     SEND_UMODES & ~UMODE_ADMIN : SEND_UMODES, buf);
1028    
1029 michael 573 if (buf[0])
1030 adx 30 {
1031     DLINK_FOREACH(ptr, serv_list.head)
1032     {
1033     struct Client *target_p = ptr->data;
1034    
1035     if ((target_p != client_p) && (target_p != source_p))
1036 michael 885 sendto_one(target_p, ":%s MODE %s :%s",
1037     ID_or_name(source_p, target_p),
1038     ID_or_name(source_p, target_p), buf);
1039 adx 30 }
1040     }
1041    
1042     if (client_p && MyClient(client_p))
1043     send_umode(client_p, source_p, old, 0xffffffff, buf);
1044     }
1045    
1046     /* user_welcome()
1047     *
1048     * inputs - client pointer to client to welcome
1049     * output - NONE
1050     * side effects -
1051     */
1052     static void
1053     user_welcome(struct Client *source_p)
1054     {
1055     #if defined(__TIME__) && defined(__DATE__)
1056     static const char built_date[] = __DATE__ " at " __TIME__;
1057     #else
1058     static const char built_date[] = "unknown";
1059     #endif
1060    
1061     #ifdef HAVE_LIBCRYPTO
1062     if (source_p->localClient->fd.ssl != NULL)
1063     sendto_one(source_p, ":%s NOTICE %s :*** Connected securely via %s",
1064     me.name, source_p->name,
1065     ssl_get_cipher(source_p->localClient->fd.ssl));
1066     #endif
1067    
1068     sendto_one(source_p, form_str(RPL_WELCOME), me.name, source_p->name,
1069     ServerInfo.network_name, source_p->name);
1070     sendto_one(source_p, form_str(RPL_YOURHOST), me.name, source_p->name,
1071 michael 56 get_listener_name(source_p->localClient->listener), ircd_version);
1072 adx 30 sendto_one(source_p, form_str(RPL_CREATED),
1073 michael 56 me.name, source_p->name, built_date);
1074 adx 30 sendto_one(source_p, form_str(RPL_MYINFO),
1075     me.name, source_p->name, me.name, ircd_version, umode_buffer);
1076     show_isupport(source_p);
1077    
1078     if (source_p->id[0] != '\0')
1079     sendto_one(source_p, form_str(RPL_YOURID), me.name,
1080     source_p->name, source_p->id);
1081    
1082     show_lusers(source_p);
1083    
1084     if (ConfigFileEntry.short_motd)
1085     {
1086 michael 1115 sendto_one(source_p, ":%s NOTICE %s :*** Notice -- motd was last changed at %s",
1087     me.name, source_p->name, ConfigFileEntry.motd.lastChangedDate);
1088 adx 30 sendto_one(source_p,
1089 michael 1115 ":%s NOTICE %s :*** Notice -- Please read the motd if you haven't "
1090     "read it", me.name, source_p->name);
1091 adx 30 sendto_one(source_p, form_str(RPL_MOTDSTART),
1092     me.name, source_p->name, me.name);
1093     sendto_one(source_p, form_str(RPL_MOTD),
1094     me.name, source_p->name,
1095     "*** This is the short motd ***");
1096     sendto_one(source_p, form_str(RPL_ENDOFMOTD),
1097     me.name, source_p->name);
1098     }
1099     else
1100     send_message_file(source_p, &ConfigFileEntry.motd);
1101     }
1102    
1103     /* check_xline()
1104     *
1105     * inputs - pointer to client to test
1106     * outupt - 1 if exiting 0 if ok
1107     * side effects -
1108     */
1109     static int
1110     check_xline(struct Client *source_p)
1111     {
1112 michael 592 struct ConfItem *conf = NULL;
1113     const char *reason = NULL;
1114 adx 30
1115 michael 592 if ((conf = find_matching_name_conf(XLINE_TYPE, source_p->info, NULL, NULL, 0)) ||
1116     (conf = find_matching_name_conf(RXLINE_TYPE, source_p->info, NULL, NULL, 0)))
1117 adx 30 {
1118 michael 592 struct MatchItem *reg = map_to_conf(conf);
1119 adx 30
1120 michael 592 ++reg->count;
1121    
1122     if (reg->reason != NULL)
1123     reason = reg->reason;
1124 adx 30 else
1125     reason = "No Reason";
1126    
1127     sendto_realops_flags(UMODE_REJ, L_ALL,
1128 michael 56 "X-line Rejecting [%s] [%s], user %s [%s]",
1129     source_p->info, reason,
1130     get_client_name(source_p, HIDE_IP),
1131     source_p->sockhost);
1132 adx 30
1133 michael 896 ++ServerStats.is_ref;
1134 michael 56 if (REJECT_HOLD_TIME > 0)
1135 adx 30 {
1136     sendto_one(source_p, ":%s NOTICE %s :Bad user info",
1137 michael 56 me.name, source_p->name);
1138 adx 30 source_p->localClient->reject_delay = CurrentTime + REJECT_HOLD_TIME;
1139     SetCaptured(source_p);
1140     }
1141     else
1142     exit_client(source_p, &me, "Bad user info");
1143     return 1;
1144     }
1145    
1146     return 0;
1147     }
1148    
1149     /* oper_up()
1150     *
1151     * inputs - pointer to given client to oper
1152     * output - NONE
1153     * side effects - Blindly opers up given source_p, using aconf info
1154     * all checks on passwords have already been done.
1155     * This could also be used by rsa oper routines.
1156     */
1157     void
1158     oper_up(struct Client *source_p)
1159     {
1160     unsigned int old = source_p->umodes;
1161     const char *operprivs = "";
1162 michael 56 const struct AccessItem *oconf = NULL;
1163 adx 30
1164 michael 56 assert(source_p->localClient->confs.head);
1165     oconf = map_to_conf((source_p->localClient->confs.head)->data);
1166    
1167     ++Count.oper;
1168 adx 30 SetOper(source_p);
1169    
1170 michael 56 if (oconf->modes)
1171     source_p->umodes |= oconf->modes;
1172     else if (ConfigFileEntry.oper_umodes)
1173 adx 30 source_p->umodes |= ConfigFileEntry.oper_umodes;
1174     else
1175     source_p->umodes |= (UMODE_SERVNOTICE|UMODE_OPERWALL|
1176 michael 56 UMODE_WALLOP|UMODE_LOCOPS);
1177 adx 30
1178 michael 882 if (!(old & UMODE_INVISIBLE) && IsInvisible(source_p))
1179     ++Count.invisi;
1180     if ((old & UMODE_INVISIBLE) && !IsInvisible(source_p))
1181     --Count.invisi;
1182    
1183 adx 30 assert(dlinkFind(&oper_list, source_p) == NULL);
1184     dlinkAdd(source_p, make_dlink_node(), &oper_list);
1185    
1186     operprivs = oper_privs_as_string(oconf->port);
1187    
1188     SetOFlag(source_p, oconf->port);
1189    
1190     if (IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p))
1191 michael 1158 AddUMode(source_p, UMODE_ADMIN);
1192 adx 30 if (!IsOperN(source_p))
1193 michael 1158 DelUMode(source_p, UMODE_NCHANGE);
1194 adx 30
1195     sendto_realops_flags(UMODE_ALL, L_ALL, "%s (%s@%s) is now an operator",
1196     source_p->name, source_p->username, source_p->host);
1197     send_umode_out(source_p, source_p, old);
1198     sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
1199     sendto_one(source_p, ":%s NOTICE %s :*** Oper privs are %s",
1200     me.name, source_p->name, operprivs);
1201     send_message_file(source_p, &ConfigFileEntry.opermotd);
1202     }
1203    
1204 michael 573 static char new_uid[TOTALSIDUID + 1]; /* allow for \0 */
1205 adx 30
1206 michael 573 int
1207     valid_sid(const char *sid)
1208     {
1209     if (strlen(sid) == IRC_MAXSID)
1210     if (IsDigit(*sid))
1211 michael 582 if (IsAlNum(*(sid + 1)) && IsAlNum(*(sid + 2)))
1212 michael 573 return 1;
1213    
1214     return 0;
1215     }
1216    
1217 adx 30 /*
1218     * init_uid()
1219     *
1220     * inputs - NONE
1221     * output - NONE
1222     * side effects - new_uid is filled in with server id portion (sid)
1223     * (first 3 bytes) or defaulted to 'A'.
1224     * Rest is filled in with 'A'
1225     */
1226     void
1227     init_uid(void)
1228     {
1229     int i;
1230    
1231     memset(new_uid, 0, sizeof(new_uid));
1232    
1233 michael 1115 if (!EmptyString(ServerInfo.sid))
1234 michael 573 strlcpy(new_uid, ServerInfo.sid, sizeof(new_uid));
1235    
1236 michael 1115 for (i = 0; i < IRC_MAXSID; ++i)
1237 adx 30 if (new_uid[i] == '\0')
1238     new_uid[i] = 'A';
1239    
1240 michael 573 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1241 adx 30 /* Yes nenolod, I have known it was off by one ever since I wrote it
1242     * But *JUST* for you, though, it really doesn't look as *pretty*
1243     * -Dianora
1244     */
1245 michael 573 memcpy(new_uid + IRC_MAXSID, "AAAAA@", IRC_MAXUID);
1246 adx 30
1247     entering_umode_cb = register_callback("entering_umode", NULL);
1248     umode_cb = register_callback("changing_umode", change_simple_umode);
1249     }
1250    
1251     /*
1252     * add_one_to_uid
1253     *
1254     * inputs - index number into new_uid
1255     * output - NONE
1256     * side effects - new_uid is incremented by one
1257     * note this is a recursive function
1258     */
1259     static void
1260     add_one_to_uid(int i)
1261     {
1262 michael 56 if (i != IRC_MAXSID) /* Not reached server SID portion yet? */
1263 adx 30 {
1264     if (new_uid[i] == 'Z')
1265     new_uid[i] = '0';
1266     else if (new_uid[i] == '9')
1267     {
1268     new_uid[i] = 'A';
1269     add_one_to_uid(i-1);
1270     }
1271 michael 573 else
1272     ++new_uid[i];
1273 adx 30 }
1274     else
1275     {
1276 michael 573 /* NOTE: if IRC_MAXUID != 6, this will have to be rewritten */
1277 adx 30 if (new_uid[i] == 'Z')
1278 michael 573 memcpy(new_uid + IRC_MAXSID, "AAAAAA", IRC_MAXUID);
1279 adx 30 else
1280 michael 573 ++new_uid[i];
1281 adx 30 }
1282     }
1283    
1284     /*
1285 michael 573 * uid_get
1286     *
1287     * inputs - struct Client *
1288     * output - new UID is returned to caller
1289     * side effects - new_uid is incremented by one.
1290     */
1291 michael 1080 static const char *
1292     uid_get(void)
1293 michael 573 {
1294     add_one_to_uid(TOTALSIDUID - 1); /* index from 0 */
1295     return new_uid;
1296     }
1297    
1298     /*
1299 adx 30 * init_isupport()
1300     *
1301     * input - NONE
1302     * output - NONE
1303     * side effects - Must be called before isupport is enabled
1304     */
1305     void
1306     init_isupport(void)
1307     {
1308     isupportFile = init_MessageLine();
1309    
1310     add_isupport("CALLERID", NULL, -1);
1311     add_isupport("CASEMAPPING", CASEMAP, -1);
1312 adx 716 add_isupport("DEAF", "D", -1);
1313 adx 30 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 michael 56 *p = '\0';
1442 adx 30
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