ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
Revision: 7105
Committed: Sat Jan 23 20:11:27 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 23405 byte(s)
Log Message:
- Incorporate gnutls support by Adam & Attila

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 7006 * Copyright (c) 1997-2016 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 5563 /*! \file user.c
23 michael 2916 * \brief User related functions.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 michael 3347 #include "user.h"
30 adx 30 #include "channel.h"
31     #include "channel_mode.h"
32     #include "client.h"
33     #include "hash.h"
34 michael 6161 #include "id.h"
35 adx 30 #include "irc_string.h"
36     #include "ircd.h"
37     #include "listener.h"
38     #include "motd.h"
39     #include "numeric.h"
40 michael 1309 #include "conf.h"
41     #include "log.h"
42 michael 3347 #include "server.h"
43 adx 30 #include "send.h"
44     #include "memory.h"
45     #include "packet.h"
46 michael 982 #include "rng_mt.h"
47 adx 30 #include "userhost.h"
48 michael 3347 #include "misc.h"
49 michael 1243 #include "parse.h"
50 michael 876 #include "watch.h"
51 michael 6185 #include "isupport.h"
52 michael 7105 #include "tls.h"
53 adx 30
54     static char umode_buffer[IRCD_BUFSIZE];
55    
56 michael 5392 const struct user_modes *umode_map[256];
57     const struct user_modes umode_tab[] =
58 adx 30 {
59 michael 5392 { 'D', UMODE_DEAF },
60     { 'F', UMODE_FARCONNECT },
61     { 'G', UMODE_SOFTCALLERID },
62     { 'H', UMODE_HIDDEN },
63     { 'R', UMODE_REGONLY },
64     { 'S', UMODE_SSL },
65     { 'W', UMODE_WEBIRC },
66     { 'a', UMODE_ADMIN },
67     { 'b', UMODE_BOTS },
68     { 'c', UMODE_CCONN },
69     { 'd', UMODE_DEBUG },
70     { 'e', UMODE_EXTERNAL },
71     { 'f', UMODE_FULL },
72     { 'g', UMODE_CALLERID },
73     { 'i', UMODE_INVISIBLE },
74     { 'j', UMODE_REJ },
75     { 'k', UMODE_SKILL },
76     { 'l', UMODE_LOCOPS },
77     { 'n', UMODE_NCHANGE },
78     { 'o', UMODE_OPER },
79     { 'p', UMODE_HIDECHANS },
80     { 'q', UMODE_HIDEIDLE },
81     { 'r', UMODE_REGISTERED },
82     { 's', UMODE_SERVNOTICE },
83     { 'u', UMODE_UNAUTH },
84     { 'w', UMODE_WALLOP },
85     { 'x', UMODE_HIDDENHOST },
86     { 'y', UMODE_SPY },
87     { '\0', 0 }
88 adx 30 };
89    
90     void
91 michael 6189 user_modes_init(void)
92 adx 30 {
93     char *umode_buffer_ptr = umode_buffer;
94    
95 michael 5392 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
96     {
97     umode_map[tab->c] = tab;
98     *umode_buffer_ptr++ = tab->c;
99     }
100 adx 30
101     *umode_buffer_ptr = '\0';
102     }
103    
104     /* show_lusers()
105     *
106     * inputs - pointer to client
107     * output - NONE
108     * side effects - display to client user counts etc.
109     */
110     void
111 michael 2345 show_lusers(struct Client *source_p)
112 adx 30 {
113 michael 1219 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
114 michael 4724 sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total - Count.invisi),
115 michael 4209 Count.invisi, dlink_list_length(&global_server_list));
116 adx 30 else
117 michael 4724 sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total - Count.invisi),
118     Count.invisi, 1);
119 adx 30
120 michael 3375 if (Count.oper)
121 michael 3109 sendto_one_numeric(source_p, &me, RPL_LUSEROP, Count.oper);
122 adx 30
123 michael 3375 if (dlink_list_length(&unknown_list))
124 michael 3109 sendto_one_numeric(source_p, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
125 adx 30
126 michael 3944 if (dlink_list_length(&channel_list))
127     sendto_one_numeric(source_p, &me, RPL_LUSERCHANNELS, dlink_list_length(&channel_list));
128 adx 30
129 michael 1219 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
130 adx 30 {
131 michael 3109 sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.local, Count.myserver);
132     sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.local, Count.max_loc);
133 adx 30 }
134     else
135     {
136 michael 3109 sendto_one_numeric(source_p, &me, RPL_LUSERME, Count.total, 0);
137     sendto_one_numeric(source_p, &me, RPL_LOCALUSERS, Count.total, Count.max_tot);
138 adx 30 }
139    
140 michael 3109 sendto_one_numeric(source_p, &me, RPL_GLOBALUSERS, Count.total, Count.max_tot);
141 adx 30
142 michael 1219 if (!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER))
143 michael 3109 sendto_one_numeric(source_p, &me, RPL_STATSCONN, Count.max_loc_con,
144     Count.max_loc_cli, Count.totalrestartcount);
145 adx 30
146 michael 1143 if (Count.local > Count.max_loc_cli)
147     Count.max_loc_cli = Count.local;
148 adx 30
149 michael 1143 if ((Count.local + Count.myserver) > Count.max_loc_con)
150 michael 2345 Count.max_loc_con = Count.local + Count.myserver;
151 adx 30 }
152    
153 michael 3272 /* report_and_set_user_flags()
154     *
155     * inputs - pointer to source_p
156     * - pointer to conf for this user
157     * output - NONE
158     * side effects - Report to user any special flags
159     * they are getting, and set them.
160     */
161     static void
162     report_and_set_user_flags(struct Client *source_p, const struct MaskItem *conf)
163     {
164     /* If this user is being spoofed, tell them so */
165     if (IsConfDoSpoofIp(conf))
166 michael 6811 sendto_one_notice(source_p, &me, ":*** Spoofing your IP");
167 michael 3272
168 michael 4856 /* If this user is in the exception class, set it "E lined" */
169 michael 3272 if (IsConfExemptKline(conf))
170     {
171 michael 6313 AddFlag(source_p, FLAGS_EXEMPTKLINE);
172 michael 6811 sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines");
173 michael 3272 }
174    
175 michael 5985 if (IsConfExemptXline(conf))
176     {
177 michael 6313 AddFlag(source_p, FLAGS_EXEMPTXLINE);
178 michael 6811 sendto_one_notice(source_p, &me, ":*** You are exempt from X lines");
179 michael 5985 }
180    
181 michael 3272 if (IsConfExemptResv(conf))
182     {
183 michael 6313 AddFlag(source_p, FLAGS_EXEMPTRESV);
184 michael 6811 sendto_one_notice(source_p, &me, ":*** You are exempt from resvs");
185 michael 3272 }
186    
187     /* If this user is exempt from user limits set it "F lined" */
188     if (IsConfExemptLimits(conf))
189     {
190 michael 6313 AddFlag(source_p, FLAGS_NOLIMIT);
191 michael 6811 sendto_one_notice(source_p, &me, ":*** You are exempt from user limits");
192 michael 3272 }
193    
194     if (IsConfCanFlood(conf))
195     {
196 michael 6313 AddFlag(source_p, FLAGS_CANFLOOD);
197 michael 6811 sendto_one_notice(source_p, &me, ":*** You are exempt from flood protection");
198 michael 3272 }
199     }
200    
201     /* introduce_client()
202     *
203     * inputs - source_p
204     * output - NONE
205     * side effects - This common function introduces a client to the rest
206     * of the net, either from a local client connect or
207     * from a remote connect.
208     */
209     static void
210     introduce_client(struct Client *source_p)
211     {
212 michael 4815 dlink_node *node = NULL;
213 michael 3272 char ubuf[IRCD_BUFSIZE] = "";
214    
215 michael 7049 if (MyConnect(source_p))
216 michael 4020 send_umode(source_p, source_p, 0, ubuf);
217 michael 3272 else
218 michael 4020 send_umode(NULL, source_p, 0, ubuf);
219 michael 3272
220     watch_check_hash(source_p, RPL_LOGON);
221    
222     if (ubuf[0] == '\0')
223     {
224     ubuf[0] = '+';
225     ubuf[1] = '\0';
226     }
227    
228 michael 4815 DLINK_FOREACH(node, local_server_list.head)
229 michael 3272 {
230 michael 4815 struct Client *server = node->data;
231 michael 3272
232     if (server == source_p->from)
233     continue;
234    
235 michael 6832 sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s :%s",
236     source_p->servptr->id,
237     source_p->name, source_p->hopcount+1,
238     source_p->tsinfo,
239     ubuf, source_p->username, source_p->host,
240     source_p->sockhost, source_p->id,
241     source_p->account,
242     source_p->info);
243 michael 3272
244     if (!EmptyString(source_p->certfp))
245     sendto_one(server, ":%s CERTFP %s", source_p->id, source_p->certfp);
246     }
247     }
248    
249     /* user_welcome()
250     *
251     * inputs - client pointer to client to welcome
252     * output - NONE
253     * side effects -
254     */
255     static void
256     user_welcome(struct Client *source_p)
257     {
258     static const char built_date[] = __DATE__ " at " __TIME__;
259    
260 michael 7105 #ifdef HAVE_TLS
261 michael 3272 if (HasFlag(source_p, FLAGS_SSL))
262     {
263     AddUMode(source_p, UMODE_SSL);
264     sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
265 michael 7105 tls_get_cipher(&source_p->connection->fd.ssl));
266 michael 3272 }
267     #endif
268    
269 michael 4340 sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
270 michael 3272 source_p->name);
271     sendto_one_numeric(source_p, &me, RPL_YOURHOST,
272 michael 6367 listener_get_name(source_p->connection->listener), ircd_version);
273 michael 3272 sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
274     sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
275 michael 6252
276 michael 6185 isupport_show(source_p);
277 michael 3272 show_lusers(source_p);
278     motd_signon(source_p);
279     }
280    
281     /* check_xline()
282     *
283     * inputs - pointer to client to test
284     * outupt - 1 if exiting 0 if ok
285     * side effects -
286     */
287     static int
288     check_xline(struct Client *source_p)
289     {
290     struct MaskItem *conf = NULL;
291    
292 michael 6313 if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
293 michael 5985 return 0;
294    
295 michael 3272 if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
296     {
297     ++conf->count;
298     sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
299     "X-line Rejecting [%s] [%s], user %s [%s]",
300 michael 4938 source_p->info, conf->reason,
301 michael 3272 get_client_name(source_p, HIDE_IP),
302     source_p->sockhost);
303    
304     ++ServerStats.is_ref;
305     exit_client(source_p, "Bad user info");
306     return 1;
307     }
308    
309     return 0;
310     }
311    
312 michael 3317 /*! \brief This function is called when both NICK and USER messages
313 michael 3316 * have been accepted for the client, in whatever order. Only
314     * after this, is the UID message propagated.
315 michael 3317 * \param source_p Pointer to given client to introduce
316 michael 3316 */
317 adx 30 void
318 michael 1080 register_local_user(struct Client *source_p)
319 adx 30 {
320 michael 1115 const char *id = NULL;
321 michael 1632 const struct MaskItem *conf = NULL;
322 adx 30
323 michael 1080 assert(source_p == source_p->from);
324 adx 30 assert(MyConnect(source_p));
325 michael 5590 assert(IsUnknown(source_p));
326 michael 4588 assert(!source_p->connection->registration);
327 adx 30
328 michael 4340 if (ConfigGeneral.ping_cookie)
329 adx 30 {
330 michael 6313 if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
331 adx 30 {
332 michael 983 do
333 michael 4588 source_p->connection->random_ping = genrand_int32();
334     while (!source_p->connection->random_ping);
335 michael 983
336 michael 4724 sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
337 michael 6313 AddFlag(source_p, FLAGS_PINGSENT);
338 adx 30 return;
339     }
340    
341 michael 6313 if (!HasFlag(source_p, FLAGS_PING_COOKIE))
342 adx 30 return;
343     }
344    
345 michael 4588 source_p->connection->last_privmsg = CurrentTime;
346 adx 30 /* Straight up the maximum rate of flooding... */
347 michael 4588 source_p->connection->allow_read = MAX_FLOOD_BURST;
348 adx 30
349 michael 1644 if (!check_client(source_p))
350 adx 30 return;
351    
352 michael 2314 if (!valid_hostname(source_p->host))
353 adx 30 {
354 michael 3110 sendto_one_notice(source_p, &me, ":*** Notice -- You have an illegal "
355     "character in your hostname");
356 michael 4724 strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
357 adx 30 }
358    
359 michael 4588 conf = source_p->connection->confs.head->data;
360 adx 30
361 michael 6313 if (!HasFlag(source_p, FLAGS_GOTID))
362 adx 30 {
363 michael 3215 char username[USERLEN + 1] = "";
364 adx 30 unsigned int i = 0;
365    
366 michael 1632 if (IsNeedIdentd(conf))
367 adx 30 {
368 michael 896 ++ServerStats.is_ref;
369 michael 3110 sendto_one_notice(source_p, &me, ":*** Notice -- You need to install "
370     "identd to use this server");
371 michael 3171 exit_client(source_p, "Install identd");
372 adx 30 return;
373     }
374    
375 michael 1080 strlcpy(username, source_p->username, sizeof(username));
376 adx 30
377 michael 1632 if (!IsNoTilde(conf))
378 adx 30 source_p->username[i++] = '~';
379    
380 michael 6357 for (const char *p = username; *p && i < USERLEN; ++p)
381 michael 4108 source_p->username[i++] = *p;
382 adx 30
383     source_p->username[i] = '\0';
384     }
385    
386 michael 3317 /* Password check */
387 michael 1632 if (!EmptyString(conf->passwd))
388 adx 30 {
389 michael 4588 if (!match_conf_password(source_p->connection->password, conf))
390 adx 30 {
391 michael 896 ++ServerStats.is_ref;
392 michael 3109
393     sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
394 michael 3171 exit_client(source_p, "Bad Password");
395 adx 30 return;
396     }
397     }
398    
399 michael 3317 /*
400 michael 4588 * Don't free source_p->connection->password here - it can be required
401 michael 4724 * by masked /stats I if there are auth {} blocks with need_password = no;
402 adx 30 * --adx
403     */
404    
405 michael 3317 /*
406     * Report if user has &^>= etc. and set flags as needed in source_p
407     */
408 michael 1632 report_and_set_user_flags(source_p, conf);
409 adx 30
410 michael 1080 if (IsDead(source_p))
411 michael 980 return;
412    
413 michael 3317 /*
414     * Limit clients -
415 adx 30 * We want to be able to have servers and F-line clients
416     * connect, so save room for "buffer" connections.
417     * Smaller servers may want to decrease this, and it should
418     * probably be just a percentage of the MAXCLIENTS...
419     * -Taner
420     */
421 michael 5489 if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
422 michael 6313 (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
423 adx 30 {
424 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
425 adx 30 "Too many clients, rejecting %s[%s].",
426 michael 1080 source_p->name, source_p->host);
427 michael 896 ++ServerStats.is_ref;
428 michael 3171 exit_client(source_p, "Sorry, server is full - try later");
429 adx 30 return;
430     }
431    
432 michael 2314 if (!valid_username(source_p->username, 1))
433 adx 30 {
434 michael 3375 char buf[IRCD_BUFSIZE] = "";
435 adx 30
436 michael 1618 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
437     "Invalid username: %s (%s@%s)",
438 michael 1080 source_p->name, source_p->username, source_p->host);
439 michael 896 ++ServerStats.is_ref;
440 michael 3375 snprintf(buf, sizeof(buf), "Invalid username [%s]", source_p->username);
441     exit_client(source_p, buf);
442 adx 30 return;
443     }
444    
445 michael 592 if (check_xline(source_p))
446 adx 30 return;
447    
448 michael 3215 while (hash_find_id((id = uid_get())))
449 michael 1115 ;
450 michael 573
451 michael 1115 strlcpy(source_p->id, id, sizeof(source_p->id));
452     hash_add_id(source_p);
453 adx 30
454 michael 1618 sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
455 michael 1137 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
456 michael 1080 source_p->name, source_p->username, source_p->host,
457 michael 4967 source_p->sockhost,
458 michael 4588 get_client_class(&source_p->connection->confs),
459 michael 1137 source_p->info, source_p->id);
460 adx 30
461 michael 4340 if (ConfigGeneral.invisible_on_connect)
462 michael 159 {
463 michael 1219 AddUMode(source_p, UMODE_INVISIBLE);
464 michael 980 ++Count.invisi;
465 michael 159 }
466 adx 30
467 michael 2314 if (++Count.local > Count.max_loc)
468 adx 30 {
469     Count.max_loc = Count.local;
470    
471     if (!(Count.max_loc % 10))
472 michael 6318 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
473 michael 4586 "New maximum local client connections: %u",
474 adx 30 Count.max_loc);
475     }
476    
477     if (++Count.total > Count.max_tot)
478     Count.max_tot = Count.total;
479 michael 948 ++Count.totalrestartcount;
480 adx 30
481 michael 1080 assert(source_p->servptr == &me);
482     SetClient(source_p);
483     dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
484 michael 4189 dlinkAdd(source_p, &source_p->node, &global_client_list);
485 michael 1080
486 michael 1125 assert(dlinkFind(&unknown_list, source_p));
487 michael 1013
488 michael 4588 dlink_move_node(&source_p->connection->lclient_node,
489 michael 1126 &unknown_list, &local_client_list);
490 adx 30
491     user_welcome(source_p);
492 michael 6441 userhost_add(source_p->username, source_p->host, 0);
493 michael 6313 AddFlag(source_p, FLAGS_USERHOST);
494 adx 30
495 michael 1080 introduce_client(source_p);
496 adx 30 }
497    
498     /* register_remote_user()
499     *
500 michael 1080 * inputs - source_p remote or directly connected client
501 adx 30 * - username to register as
502     * - host name to register as
503     * - server name
504     * output - NONE
505     * side effects - This function is called when a remote client
506     * is introduced by a server.
507     */
508     void
509 michael 4088 register_remote_user(struct Client *source_p)
510 adx 30 {
511 michael 4223 const struct Client *target_p = NULL;
512 adx 30
513     if ((target_p = source_p->servptr) && target_p->from != source_p->from)
514     {
515 michael 1618 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
516 adx 30 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
517 michael 1080 source_p->from->name, source_p->name, source_p->username,
518 adx 30 source_p->host, source_p->servptr->name,
519     target_p->name, target_p->from->name);
520 michael 3176 sendto_one(source_p->from,
521 michael 4972 ":%s KILL %s :%s (UID from wrong direction (%s != %s))",
522 michael 3186 me.id, source_p->id, me.name, source_p->servptr->name,
523 michael 3176 target_p->from->name);
524    
525 michael 1219 AddFlag(source_p, FLAGS_KILLED);
526 michael 4972 exit_client(source_p, "UID server wrong direction");
527 adx 30 return;
528     }
529    
530 michael 1167 /*
531     * If the nick has been introduced by a services server,
532     * make it a service as well.
533     */
534 michael 1219 if (HasFlag(source_p->servptr, FLAGS_SERVICE))
535     AddFlag(source_p, FLAGS_SERVICE);
536 michael 1167
537 michael 510 if (++Count.total > Count.max_tot)
538     Count.max_tot = Count.total;
539    
540 adx 30 SetClient(source_p);
541 michael 889 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
542 michael 4189 dlinkAdd(source_p, &source_p->node, &global_client_list);
543 michael 6441 userhost_add(source_p->username, source_p->host, 1);
544 michael 6313 AddFlag(source_p, FLAGS_USERHOST);
545 adx 30
546 michael 1976 if (HasFlag(source_p->servptr, FLAGS_EOB))
547 michael 5743 sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
548     "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
549     source_p->servptr->name,
550     source_p->name, source_p->username, source_p->host,
551     source_p->sockhost, source_p->info, source_p->id);
552 michael 1976
553 michael 1080 introduce_client(source_p);
554 adx 30 }
555    
556     /* valid_hostname()
557     *
558     * Inputs - pointer to hostname
559     * Output - 1 if valid, 0 if not
560     * Side effects - check hostname for validity
561     *
562     * NOTE: this doesn't allow a hostname to begin with a dot and
563     * will not allow more dots than chars.
564     */
565     int
566     valid_hostname(const char *hostname)
567     {
568     const char *p = hostname;
569    
570 michael 3235 assert(p);
571 adx 30
572 michael 2352 if (EmptyString(p) || *p == '.' || *p == ':')
573 michael 56 return 0;
574 adx 30
575 michael 1080 for (; *p; ++p)
576 adx 30 if (!IsHostChar(*p))
577 michael 56 return 0;
578 adx 30
579 michael 1795 return p - hostname <= HOSTLEN;
580 adx 30 }
581    
582     /* valid_username()
583     *
584     * Inputs - pointer to user
585     * Output - 1 if valid, 0 if not
586     * Side effects - check username for validity
587     *
588     * Absolutely always reject any '*' '!' '?' '@' in an user name
589     * reject any odd control characters names.
590     * Allow '.' in username to allow for "first.last"
591     * style of username
592     */
593     int
594 michael 2069 valid_username(const char *username, const int local)
595 adx 30 {
596     const char *p = username;
597    
598 michael 3235 assert(p);
599 adx 30
600 michael 1080 if (*p == '~')
601 adx 30 ++p;
602    
603 michael 2067 /*
604     * Reject usernames that don't start with an alphanum
605 adx 30 * i.e. reject jokers who have '-@somehost' or '.@somehost'
606     * or "-hi-@somehost", "h-----@somehost" would still be accepted.
607     */
608     if (!IsAlNum(*p))
609 michael 56 return 0;
610 adx 30
611 michael 2067 if (local)
612 adx 30 {
613 michael 6756 unsigned int dots = 0;
614    
615 michael 2067 while (*++p)
616 adx 30 {
617 michael 4340 if (*p == '.' && ConfigGeneral.dots_in_ident)
618 michael 2067 {
619 michael 4340 if (++dots > ConfigGeneral.dots_in_ident)
620 michael 2067 return 0;
621     if (!IsUserChar(*(p + 1)))
622     return 0;
623     }
624     else if (!IsUserChar(*p))
625 michael 56 return 0;
626 adx 30 }
627     }
628 michael 2067 else
629     {
630     while (*++p)
631     if (!IsUserChar(*p))
632     return 0;
633     }
634 adx 30
635 michael 3656 return p - username <= USERLEN;
636 adx 30 }
637    
638 michael 1165 /* clean_nick_name()
639     *
640     * input - nickname
641     * - whether it's a local nick (1) or remote (0)
642     * output - none
643     * side effects - walks through the nickname, returning 0 if erroneous
644     */
645     int
646     valid_nickname(const char *nickname, const int local)
647     {
648     const char *p = nickname;
649 michael 3318
650 michael 4982 assert(p);
651 michael 1165
652 michael 3317 /*
653     * Nicks can't start with a digit or - or be 0 length.
654     */
655 michael 4709 if (EmptyString(p) || *p == '-' || (IsDigit(*p) && local))
656 michael 1165 return 0;
657    
658     for (; *p; ++p)
659     if (!IsNickChar(*p))
660     return 0;
661    
662 michael 1431 return p - nickname <= NICKLEN;
663 michael 1165 }
664    
665 adx 30 /* send_umode()
666     * send the MODE string for user (user) to connection client_p
667     * -avalon
668 db 849 *
669     * inputs - client_p
670     * - source_p
671     * - int old
672     * - suplied umode_buf
673     * output - NONE
674 adx 30 */
675     void
676     send_umode(struct Client *client_p, struct Client *source_p,
677 michael 4020 unsigned int old, char *umode_buf)
678 adx 30 {
679 michael 1013 char *m = umode_buf;
680 adx 30 int what = 0;
681    
682 michael 56 /*
683 michael 3317 * Build a string in umode_buf to represent the change in the user's
684 adx 30 * mode between the new (source_p->umodes) and 'old'.
685     */
686 michael 5392 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
687 adx 30 {
688 michael 5392 if ((tab->flag & old) && !HasUMode(source_p, tab->flag))
689 adx 30 {
690     if (what == MODE_DEL)
691 michael 5392 *m++ = tab->c;
692 adx 30 else
693     {
694     what = MODE_DEL;
695     *m++ = '-';
696 michael 5392 *m++ = tab->c;
697 adx 30 }
698     }
699 michael 5392 else if (!(tab->flag & old) && HasUMode(source_p, tab->flag))
700 adx 30 {
701     if (what == MODE_ADD)
702 michael 5392 *m++ = tab->c;
703 adx 30 else
704     {
705     what = MODE_ADD;
706     *m++ = '+';
707 michael 5392 *m++ = tab->c;
708 adx 30 }
709     }
710     }
711    
712     *m = '\0';
713    
714     if (*umode_buf && client_p)
715 michael 528 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
716 michael 4704 client_p->name, client_p->username,
717     client_p->host, client_p->name, umode_buf);
718 adx 30 }
719    
720     /* send_umode_out()
721     *
722     * inputs -
723     * output - NONE
724     * side effects - Only send ubuf out to servers that know about this client
725     */
726     void
727 michael 4707 send_umode_out(struct Client *source_p, unsigned int old)
728 adx 30 {
729 michael 3215 char buf[IRCD_BUFSIZE] = "";
730 adx 30
731 michael 4707 send_umode(MyClient(source_p) ? source_p : NULL, source_p, old, buf);
732 adx 30
733 michael 573 if (buf[0])
734 michael 4962 sendto_server(source_p, 0, 0, ":%s MODE %s :%s",
735 michael 3186 source_p->id, source_p->id, buf);
736 adx 30 }
737    
738 michael 1819 void
739 michael 2137 user_set_hostmask(struct Client *target_p, const char *hostname, const int what)
740 michael 1819 {
741 michael 4815 dlink_node *node = NULL;
742 michael 2141
743 michael 2145 if (!strcmp(target_p->host, hostname))
744     return;
745 michael 2141
746 michael 2137 switch (what)
747     {
748     case MODE_ADD:
749     AddUMode(target_p, UMODE_HIDDENHOST);
750     break;
751     case MODE_DEL:
752     DelUMode(target_p, UMODE_HIDDENHOST);
753     break;
754 michael 2145 default: return;
755 michael 2137 }
756    
757 michael 4340 if (ConfigGeneral.cycle_on_host_change)
758 michael 6774 sendto_common_channels_local(target_p, 0, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname",
759 michael 2289 target_p->name, target_p->username, target_p->host);
760 michael 2145
761 michael 6774 sendto_common_channels_local(target_p, 0, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s",
762     target_p->name, target_p->username,
763     target_p->host, target_p->username, hostname);
764    
765 michael 6313 if (HasFlag(target_p, FLAGS_USERHOST))
766 michael 6441 userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
767 michael 2145
768     strlcpy(target_p->host, hostname, sizeof(target_p->host));
769    
770 michael 6441 userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
771 michael 6313 AddFlag(target_p, FLAGS_USERHOST);
772 michael 2145
773 michael 6732 if (MyConnect(target_p))
774 michael 2137 {
775 michael 4557 sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host);
776 michael 1819 clear_ban_cache_client(target_p);
777 michael 2137 }
778 michael 2141
779 michael 4340 if (!ConfigGeneral.cycle_on_host_change)
780 michael 2283 return;
781    
782 michael 4815 DLINK_FOREACH(node, target_p->channel.head)
783 michael 2141 {
784 michael 6904 char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1];
785     char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = "";
786 michael 2141 char *p = modebuf;
787     int len = 0;
788 michael 4815 const struct Membership *member = node->data;
789 michael 2141
790 michael 4815 if (has_member_flags(member, CHFL_CHANOP))
791 michael 2283 {
792 michael 2141 *p++ = 'o';
793     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
794     }
795    
796 michael 4815 if (has_member_flags(member, CHFL_HALFOP))
797 michael 2283 {
798 michael 2141 *p++ = 'h';
799     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
800     }
801    
802 michael 4815 if (has_member_flags(member, CHFL_VOICE))
803 michael 2283 {
804 michael 2141 *p++ = 'v';
805     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
806     }
807    
808     *p = '\0';
809    
810 michael 6774 sendto_channel_local(target_p, member->chptr, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s",
811 michael 6759 target_p->name, target_p->username,
812     target_p->host, member->chptr->name,
813 michael 6827 target_p->account, target_p->info);
814 michael 6774 sendto_channel_local(target_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s",
815 michael 6759 target_p->name, target_p->username,
816     target_p->host, member->chptr->name);
817 michael 4792
818 michael 2141 if (nickbuf[0])
819 michael 6774 sendto_channel_local(target_p, member->chptr, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s",
820 michael 6759 target_p->servptr->name, member->chptr->name,
821     modebuf, nickbuf);
822 michael 2141 }
823 michael 6777
824     if (target_p->away[0])
825     sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY, CAP_CHGHOST,
826     ":%s!%s@%s AWAY :%s",
827     target_p->name, target_p->username,
828     target_p->host, target_p->away);
829 michael 1819 }

Properties

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