ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/s_user.c
File size: 41224 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

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

Properties

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