ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 7114
Committed: Sat Jan 23 20:31:37 2016 UTC (10 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 23382 byte(s)
Log Message:
- Remove some HAVE_TLS

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 7007 * 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 4564 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 5564 /*! \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 6160 #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 6186 #include "isupport.h"
52 michael 7106 #include "tls.h"
53 adx 30
54     static char umode_buffer[IRCD_BUFSIZE];
55    
56 michael 5393 const struct user_modes *umode_map[256];
57     const struct user_modes umode_tab[] =
58 adx 30 {
59 michael 5393 { '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 6190 user_modes_init(void)
92 adx 30 {
93     char *umode_buffer_ptr = umode_buffer;
94    
95 michael 5393 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 4723 sendto_one_numeric(source_p, &me, RPL_LUSERCLIENT, (Count.total - Count.invisi),
115 michael 4208 Count.invisi, dlink_list_length(&global_server_list));
116 adx 30 else
117 michael 4723 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 3945 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 6812 sendto_one_notice(source_p, &me, ":*** Spoofing your IP");
167 michael 3272
168 michael 4855 /* If this user is in the exception class, set it "E lined" */
169 michael 3272 if (IsConfExemptKline(conf))
170     {
171 michael 6314 AddFlag(source_p, FLAGS_EXEMPTKLINE);
172 michael 6812 sendto_one_notice(source_p, &me, ":*** You are exempt from K/D lines");
173 michael 3272 }
174    
175 michael 5986 if (IsConfExemptXline(conf))
176     {
177 michael 6314 AddFlag(source_p, FLAGS_EXEMPTXLINE);
178 michael 6812 sendto_one_notice(source_p, &me, ":*** You are exempt from X lines");
179 michael 5986 }
180    
181 michael 3272 if (IsConfExemptResv(conf))
182     {
183 michael 6314 AddFlag(source_p, FLAGS_EXEMPTRESV);
184 michael 6812 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 6314 AddFlag(source_p, FLAGS_NOLIMIT);
191 michael 6812 sendto_one_notice(source_p, &me, ":*** You are exempt from user limits");
192 michael 3272 }
193    
194     if (IsConfCanFlood(conf))
195     {
196 michael 6314 AddFlag(source_p, FLAGS_CANFLOOD);
197 michael 6812 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 4816 dlink_node *node = NULL;
213 michael 3272 char ubuf[IRCD_BUFSIZE] = "";
214    
215 michael 7050 if (MyConnect(source_p))
216 michael 4021 send_umode(source_p, source_p, 0, ubuf);
217 michael 3272 else
218 michael 4021 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 4816 DLINK_FOREACH(node, local_server_list.head)
229 michael 3272 {
230 michael 4816 struct Client *server = node->data;
231 michael 3272
232     if (server == source_p->from)
233     continue;
234    
235 michael 6921 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     if (HasFlag(source_p, FLAGS_SSL))
261     {
262     AddUMode(source_p, UMODE_SSL);
263     sendto_one_notice(source_p, &me, ":*** Connected securely via %s",
264 michael 7106 tls_get_cipher(&source_p->connection->fd.ssl));
265 michael 3272 }
266    
267 michael 4341 sendto_one_numeric(source_p, &me, RPL_WELCOME, ConfigServerInfo.network_name,
268 michael 3272 source_p->name);
269     sendto_one_numeric(source_p, &me, RPL_YOURHOST,
270 michael 6368 listener_get_name(source_p->connection->listener), ircd_version);
271 michael 3272 sendto_one_numeric(source_p, &me, RPL_CREATED, built_date);
272     sendto_one_numeric(source_p, &me, RPL_MYINFO, me.name, ircd_version, umode_buffer);
273 michael 6253
274 michael 6186 isupport_show(source_p);
275 michael 3272 show_lusers(source_p);
276     motd_signon(source_p);
277     }
278    
279     /* check_xline()
280     *
281     * inputs - pointer to client to test
282     * outupt - 1 if exiting 0 if ok
283     * side effects -
284     */
285     static int
286     check_xline(struct Client *source_p)
287     {
288     struct MaskItem *conf = NULL;
289    
290 michael 6314 if (HasFlag(source_p, FLAGS_EXEMPTXLINE))
291 michael 5986 return 0;
292    
293 michael 3272 if ((conf = find_matching_name_conf(CONF_XLINE, source_p->info, NULL, NULL, 0)))
294     {
295     ++conf->count;
296     sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
297     "X-line Rejecting [%s] [%s], user %s [%s]",
298 michael 4939 source_p->info, conf->reason,
299 michael 3272 get_client_name(source_p, HIDE_IP),
300     source_p->sockhost);
301    
302     ++ServerStats.is_ref;
303     exit_client(source_p, "Bad user info");
304     return 1;
305     }
306    
307     return 0;
308     }
309    
310 michael 3317 /*! \brief This function is called when both NICK and USER messages
311 michael 3316 * have been accepted for the client, in whatever order. Only
312     * after this, is the UID message propagated.
313 michael 3317 * \param source_p Pointer to given client to introduce
314 michael 3316 */
315 adx 30 void
316 michael 1080 register_local_user(struct Client *source_p)
317 adx 30 {
318 michael 1115 const char *id = NULL;
319 michael 1632 const struct MaskItem *conf = NULL;
320 adx 30
321 michael 1080 assert(source_p == source_p->from);
322 adx 30 assert(MyConnect(source_p));
323 michael 5591 assert(IsUnknown(source_p));
324 michael 4589 assert(!source_p->connection->registration);
325 adx 30
326 michael 4341 if (ConfigGeneral.ping_cookie)
327 adx 30 {
328 michael 6314 if (!HasFlag(source_p, FLAGS_PINGSENT) && !source_p->connection->random_ping)
329 adx 30 {
330 michael 983 do
331 michael 4589 source_p->connection->random_ping = genrand_int32();
332     while (!source_p->connection->random_ping);
333 michael 983
334 michael 4723 sendto_one(source_p, "PING :%u", source_p->connection->random_ping);
335 michael 6314 AddFlag(source_p, FLAGS_PINGSENT);
336 adx 30 return;
337     }
338    
339 michael 6314 if (!HasFlag(source_p, FLAGS_PING_COOKIE))
340 adx 30 return;
341     }
342    
343 michael 4589 source_p->connection->last_privmsg = CurrentTime;
344 adx 30 /* Straight up the maximum rate of flooding... */
345 michael 4589 source_p->connection->allow_read = MAX_FLOOD_BURST;
346 adx 30
347 michael 1644 if (!check_client(source_p))
348 adx 30 return;
349    
350 michael 2314 if (!valid_hostname(source_p->host))
351 adx 30 {
352 michael 3110 sendto_one_notice(source_p, &me, ":*** Notice -- You have an illegal "
353     "character in your hostname");
354 michael 4723 strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
355 adx 30 }
356    
357 michael 4589 conf = source_p->connection->confs.head->data;
358 adx 30
359 michael 6314 if (!HasFlag(source_p, FLAGS_GOTID))
360 adx 30 {
361 michael 3215 char username[USERLEN + 1] = "";
362 adx 30 unsigned int i = 0;
363    
364 michael 1632 if (IsNeedIdentd(conf))
365 adx 30 {
366 michael 896 ++ServerStats.is_ref;
367 michael 3110 sendto_one_notice(source_p, &me, ":*** Notice -- You need to install "
368     "identd to use this server");
369 michael 3171 exit_client(source_p, "Install identd");
370 adx 30 return;
371     }
372    
373 michael 1080 strlcpy(username, source_p->username, sizeof(username));
374 adx 30
375 michael 1632 if (!IsNoTilde(conf))
376 adx 30 source_p->username[i++] = '~';
377    
378 michael 6358 for (const char *p = username; *p && i < USERLEN; ++p)
379 michael 4109 source_p->username[i++] = *p;
380 adx 30
381     source_p->username[i] = '\0';
382     }
383    
384 michael 3317 /* Password check */
385 michael 1632 if (!EmptyString(conf->passwd))
386 adx 30 {
387 michael 4589 if (!match_conf_password(source_p->connection->password, conf))
388 adx 30 {
389 michael 896 ++ServerStats.is_ref;
390 michael 3109
391     sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
392 michael 3171 exit_client(source_p, "Bad Password");
393 adx 30 return;
394     }
395     }
396    
397 michael 3317 /*
398 michael 4589 * Don't free source_p->connection->password here - it can be required
399 michael 4723 * by masked /stats I if there are auth {} blocks with need_password = no;
400 adx 30 * --adx
401     */
402    
403 michael 3317 /*
404     * Report if user has &^>= etc. and set flags as needed in source_p
405     */
406 michael 1632 report_and_set_user_flags(source_p, conf);
407 adx 30
408 michael 1080 if (IsDead(source_p))
409 michael 980 return;
410    
411 michael 3317 /*
412     * Limit clients -
413 adx 30 * We want to be able to have servers and F-line clients
414     * connect, so save room for "buffer" connections.
415     * Smaller servers may want to decrease this, and it should
416     * probably be just a percentage of the MAXCLIENTS...
417     * -Taner
418     */
419 michael 5488 if ((Count.local >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
420 michael 6314 (Count.local >= GlobalSetOptions.maxclients && !HasFlag(source_p, FLAGS_NOLIMIT)))
421 adx 30 {
422 michael 1618 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
423 adx 30 "Too many clients, rejecting %s[%s].",
424 michael 1080 source_p->name, source_p->host);
425 michael 896 ++ServerStats.is_ref;
426 michael 3171 exit_client(source_p, "Sorry, server is full - try later");
427 adx 30 return;
428     }
429    
430 michael 2314 if (!valid_username(source_p->username, 1))
431 adx 30 {
432 michael 3375 char buf[IRCD_BUFSIZE] = "";
433 adx 30
434 michael 1618 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
435     "Invalid username: %s (%s@%s)",
436 michael 1080 source_p->name, source_p->username, source_p->host);
437 michael 896 ++ServerStats.is_ref;
438 michael 3375 snprintf(buf, sizeof(buf), "Invalid username [%s]", source_p->username);
439     exit_client(source_p, buf);
440 adx 30 return;
441     }
442    
443 michael 592 if (check_xline(source_p))
444 adx 30 return;
445    
446 michael 3215 while (hash_find_id((id = uid_get())))
447 michael 1115 ;
448 michael 573
449 michael 1115 strlcpy(source_p->id, id, sizeof(source_p->id));
450     hash_add_id(source_p);
451 adx 30
452 michael 1618 sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
453 michael 1137 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
454 michael 1080 source_p->name, source_p->username, source_p->host,
455 michael 4968 source_p->sockhost,
456 michael 4589 get_client_class(&source_p->connection->confs),
457 michael 1137 source_p->info, source_p->id);
458 adx 30
459 michael 4341 if (ConfigGeneral.invisible_on_connect)
460 michael 159 {
461 michael 1219 AddUMode(source_p, UMODE_INVISIBLE);
462 michael 980 ++Count.invisi;
463 michael 159 }
464 adx 30
465 michael 2314 if (++Count.local > Count.max_loc)
466 adx 30 {
467     Count.max_loc = Count.local;
468    
469     if (!(Count.max_loc % 10))
470 michael 6317 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
471 michael 4587 "New maximum local client connections: %u",
472 adx 30 Count.max_loc);
473     }
474    
475     if (++Count.total > Count.max_tot)
476     Count.max_tot = Count.total;
477 michael 948 ++Count.totalrestartcount;
478 adx 30
479 michael 1080 assert(source_p->servptr == &me);
480     SetClient(source_p);
481     dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
482 michael 4188 dlinkAdd(source_p, &source_p->node, &global_client_list);
483 michael 1080
484 michael 1125 assert(dlinkFind(&unknown_list, source_p));
485 michael 1013
486 michael 4589 dlink_move_node(&source_p->connection->lclient_node,
487 michael 1126 &unknown_list, &local_client_list);
488 adx 30
489     user_welcome(source_p);
490 michael 6442 userhost_add(source_p->username, source_p->host, 0);
491 michael 6314 AddFlag(source_p, FLAGS_USERHOST);
492 adx 30
493 michael 1080 introduce_client(source_p);
494 adx 30 }
495    
496     /* register_remote_user()
497     *
498 michael 1080 * inputs - source_p remote or directly connected client
499 adx 30 * - username to register as
500     * - host name to register as
501     * - server name
502     * output - NONE
503     * side effects - This function is called when a remote client
504     * is introduced by a server.
505     */
506     void
507 michael 4091 register_remote_user(struct Client *source_p)
508 adx 30 {
509 michael 4224 const struct Client *target_p = NULL;
510 adx 30
511     if ((target_p = source_p->servptr) && target_p->from != source_p->from)
512     {
513 michael 1618 sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
514 adx 30 "Bad User [%s] :%s USER %s@%s %s, != %s[%s]",
515 michael 1080 source_p->from->name, source_p->name, source_p->username,
516 adx 30 source_p->host, source_p->servptr->name,
517     target_p->name, target_p->from->name);
518 michael 3176 sendto_one(source_p->from,
519 michael 4973 ":%s KILL %s :%s (UID from wrong direction (%s != %s))",
520 michael 3186 me.id, source_p->id, me.name, source_p->servptr->name,
521 michael 3176 target_p->from->name);
522    
523 michael 1219 AddFlag(source_p, FLAGS_KILLED);
524 michael 4973 exit_client(source_p, "UID server wrong direction");
525 adx 30 return;
526     }
527    
528 michael 1167 /*
529     * If the nick has been introduced by a services server,
530     * make it a service as well.
531     */
532 michael 1219 if (HasFlag(source_p->servptr, FLAGS_SERVICE))
533     AddFlag(source_p, FLAGS_SERVICE);
534 michael 1167
535 michael 510 if (++Count.total > Count.max_tot)
536     Count.max_tot = Count.total;
537    
538 adx 30 SetClient(source_p);
539 michael 889 dlinkAdd(source_p, &source_p->lnode, &source_p->servptr->serv->client_list);
540 michael 4188 dlinkAdd(source_p, &source_p->node, &global_client_list);
541 michael 6442 userhost_add(source_p->username, source_p->host, 1);
542 michael 6314 AddFlag(source_p, FLAGS_USERHOST);
543 adx 30
544 michael 1976 if (HasFlag(source_p->servptr, FLAGS_EOB))
545 michael 5744 sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
546     "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
547     source_p->servptr->name,
548     source_p->name, source_p->username, source_p->host,
549     source_p->sockhost, source_p->info, source_p->id);
550 michael 1976
551 michael 1080 introduce_client(source_p);
552 adx 30 }
553    
554     /* valid_hostname()
555     *
556     * Inputs - pointer to hostname
557     * Output - 1 if valid, 0 if not
558     * Side effects - check hostname for validity
559     *
560     * NOTE: this doesn't allow a hostname to begin with a dot and
561     * will not allow more dots than chars.
562     */
563     int
564     valid_hostname(const char *hostname)
565     {
566     const char *p = hostname;
567    
568 michael 3235 assert(p);
569 adx 30
570 michael 2352 if (EmptyString(p) || *p == '.' || *p == ':')
571 michael 56 return 0;
572 adx 30
573 michael 1080 for (; *p; ++p)
574 adx 30 if (!IsHostChar(*p))
575 michael 56 return 0;
576 adx 30
577 michael 1795 return p - hostname <= HOSTLEN;
578 adx 30 }
579    
580     /* valid_username()
581     *
582     * Inputs - pointer to user
583     * Output - 1 if valid, 0 if not
584     * Side effects - check username for validity
585     *
586     * Absolutely always reject any '*' '!' '?' '@' in an user name
587     * reject any odd control characters names.
588     * Allow '.' in username to allow for "first.last"
589     * style of username
590     */
591     int
592 michael 2069 valid_username(const char *username, const int local)
593 adx 30 {
594     const char *p = username;
595    
596 michael 3235 assert(p);
597 adx 30
598 michael 1080 if (*p == '~')
599 adx 30 ++p;
600    
601 michael 2067 /*
602     * Reject usernames that don't start with an alphanum
603 adx 30 * i.e. reject jokers who have '-@somehost' or '.@somehost'
604     * or "-hi-@somehost", "h-----@somehost" would still be accepted.
605     */
606     if (!IsAlNum(*p))
607 michael 56 return 0;
608 adx 30
609 michael 2067 if (local)
610 adx 30 {
611 michael 6757 unsigned int dots = 0;
612    
613 michael 2067 while (*++p)
614 adx 30 {
615 michael 4341 if (*p == '.' && ConfigGeneral.dots_in_ident)
616 michael 2067 {
617 michael 4341 if (++dots > ConfigGeneral.dots_in_ident)
618 michael 2067 return 0;
619     if (!IsUserChar(*(p + 1)))
620     return 0;
621     }
622     else if (!IsUserChar(*p))
623 michael 56 return 0;
624 adx 30 }
625     }
626 michael 2067 else
627     {
628     while (*++p)
629     if (!IsUserChar(*p))
630     return 0;
631     }
632 adx 30
633 michael 3657 return p - username <= USERLEN;
634 adx 30 }
635    
636 michael 1165 /* clean_nick_name()
637     *
638     * input - nickname
639     * - whether it's a local nick (1) or remote (0)
640     * output - none
641     * side effects - walks through the nickname, returning 0 if erroneous
642     */
643     int
644     valid_nickname(const char *nickname, const int local)
645     {
646     const char *p = nickname;
647 michael 3318
648 michael 4983 assert(p);
649 michael 1165
650 michael 3317 /*
651     * Nicks can't start with a digit or - or be 0 length.
652     */
653 michael 4708 if (EmptyString(p) || *p == '-' || (IsDigit(*p) && local))
654 michael 1165 return 0;
655    
656     for (; *p; ++p)
657     if (!IsNickChar(*p))
658     return 0;
659    
660 michael 1431 return p - nickname <= NICKLEN;
661 michael 1165 }
662    
663 adx 30 /* send_umode()
664     * send the MODE string for user (user) to connection client_p
665     * -avalon
666 db 849 *
667     * inputs - client_p
668     * - source_p
669     * - int old
670     * - suplied umode_buf
671     * output - NONE
672 adx 30 */
673     void
674     send_umode(struct Client *client_p, struct Client *source_p,
675 michael 4021 unsigned int old, char *umode_buf)
676 adx 30 {
677 michael 1013 char *m = umode_buf;
678 adx 30 int what = 0;
679    
680 michael 56 /*
681 michael 3317 * Build a string in umode_buf to represent the change in the user's
682 adx 30 * mode between the new (source_p->umodes) and 'old'.
683     */
684 michael 5393 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
685 adx 30 {
686 michael 5393 if ((tab->flag & old) && !HasUMode(source_p, tab->flag))
687 adx 30 {
688     if (what == MODE_DEL)
689 michael 5393 *m++ = tab->c;
690 adx 30 else
691     {
692     what = MODE_DEL;
693     *m++ = '-';
694 michael 5393 *m++ = tab->c;
695 adx 30 }
696     }
697 michael 5393 else if (!(tab->flag & old) && HasUMode(source_p, tab->flag))
698 adx 30 {
699     if (what == MODE_ADD)
700 michael 5393 *m++ = tab->c;
701 adx 30 else
702     {
703     what = MODE_ADD;
704     *m++ = '+';
705 michael 5393 *m++ = tab->c;
706 adx 30 }
707     }
708     }
709    
710     *m = '\0';
711    
712     if (*umode_buf && client_p)
713 michael 528 sendto_one(client_p, ":%s!%s@%s MODE %s :%s",
714 michael 4705 client_p->name, client_p->username,
715     client_p->host, client_p->name, umode_buf);
716 adx 30 }
717    
718     /* send_umode_out()
719     *
720     * inputs -
721     * output - NONE
722     * side effects - Only send ubuf out to servers that know about this client
723     */
724     void
725 michael 4706 send_umode_out(struct Client *source_p, unsigned int old)
726 adx 30 {
727 michael 3215 char buf[IRCD_BUFSIZE] = "";
728 adx 30
729 michael 4706 send_umode(MyClient(source_p) ? source_p : NULL, source_p, old, buf);
730 adx 30
731 michael 573 if (buf[0])
732 michael 4963 sendto_server(source_p, 0, 0, ":%s MODE %s :%s",
733 michael 3186 source_p->id, source_p->id, buf);
734 adx 30 }
735    
736 michael 1819 void
737 michael 2137 user_set_hostmask(struct Client *target_p, const char *hostname, const int what)
738 michael 1819 {
739 michael 4816 dlink_node *node = NULL;
740 michael 2141
741 michael 2145 if (!strcmp(target_p->host, hostname))
742     return;
743 michael 2141
744 michael 2137 switch (what)
745     {
746     case MODE_ADD:
747     AddUMode(target_p, UMODE_HIDDENHOST);
748     break;
749     case MODE_DEL:
750     DelUMode(target_p, UMODE_HIDDENHOST);
751     break;
752 michael 2145 default: return;
753 michael 2137 }
754    
755 michael 4341 if (ConfigGeneral.cycle_on_host_change)
756 michael 6775 sendto_common_channels_local(target_p, 0, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname",
757 michael 2289 target_p->name, target_p->username, target_p->host);
758 michael 2145
759 michael 6775 sendto_common_channels_local(target_p, 0, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s",
760     target_p->name, target_p->username,
761     target_p->host, target_p->username, hostname);
762    
763 michael 6314 if (HasFlag(target_p, FLAGS_USERHOST))
764 michael 6442 userhost_del(target_p->username, target_p->host, !MyConnect(target_p));
765 michael 2145
766     strlcpy(target_p->host, hostname, sizeof(target_p->host));
767    
768 michael 6442 userhost_add(target_p->username, target_p->host, !MyConnect(target_p));
769 michael 6314 AddFlag(target_p, FLAGS_USERHOST);
770 michael 2145
771 michael 6731 if (MyConnect(target_p))
772 michael 2137 {
773 michael 4558 sendto_one_numeric(target_p, &me, RPL_VISIBLEHOST, target_p->host);
774 michael 1819 clear_ban_cache_client(target_p);
775 michael 2137 }
776 michael 2141
777 michael 4341 if (!ConfigGeneral.cycle_on_host_change)
778 michael 2283 return;
779    
780 michael 4816 DLINK_FOREACH(node, target_p->channel.head)
781 michael 2141 {
782 michael 6902 char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1];
783     char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = "";
784 michael 2141 char *p = modebuf;
785     int len = 0;
786 michael 4816 const struct Membership *member = node->data;
787 michael 2141
788 michael 4816 if (has_member_flags(member, CHFL_CHANOP))
789 michael 2283 {
790 michael 2141 *p++ = 'o';
791     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
792     }
793    
794 michael 4816 if (has_member_flags(member, CHFL_HALFOP))
795 michael 2283 {
796 michael 2141 *p++ = 'h';
797     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
798     }
799    
800 michael 4816 if (has_member_flags(member, CHFL_VOICE))
801 michael 2283 {
802 michael 2141 *p++ = 'v';
803     len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", target_p->name);
804     }
805    
806     *p = '\0';
807    
808 michael 6775 sendto_channel_local(target_p, member->chptr, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s",
809 michael 6760 target_p->name, target_p->username,
810     target_p->host, member->chptr->name,
811 michael 6920 target_p->account, target_p->info);
812 michael 6775 sendto_channel_local(target_p, member->chptr, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s",
813 michael 6760 target_p->name, target_p->username,
814     target_p->host, member->chptr->name);
815 michael 4793
816 michael 2141 if (nickbuf[0])
817 michael 6775 sendto_channel_local(target_p, member->chptr, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s",
818 michael 6760 target_p->servptr->name, member->chptr->name,
819     modebuf, nickbuf);
820 michael 2141 }
821 michael 6778
822     if (target_p->away[0])
823     sendto_common_channels_local(target_p, 0, CAP_AWAY_NOTIFY, CAP_CHGHOST,
824     ":%s!%s@%s AWAY :%s",
825     target_p->name, target_p->username,
826     target_p->host, target_p->away);
827 michael 1819 }

Properties

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