ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/user.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (5 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 21663 byte(s)
Log Message:
- Bump copyright years

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 9857 * Copyright (c) 1997-2021 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 michael 7304 #include "conf_gecos.h"
42 michael 1309 #include "log.h"
43 michael 3347 #include "server.h"
44 adx 30 #include "send.h"
45     #include "memory.h"
46     #include "packet.h"
47 michael 982 #include "rng_mt.h"
48 michael 3347 #include "misc.h"
49 michael 1243 #include "parse.h"
50 michael 9750 #include "monitor.h"
51 michael 6185 #include "isupport.h"
52 michael 7105 #include "tls.h"
53 michael 8729 #include "patchlevel.h"
54 adx 30
55 michael 8063 static char umode_buffer[UMODE_MAX_STR];
56 adx 30
57 michael 5392 const struct user_modes *umode_map[256];
58     const struct user_modes umode_tab[] =
59 adx 30 {
60 michael 9775 { 'B', UMODE_BOT },
61 michael 5392 { 'D', UMODE_DEAF },
62     { 'F', UMODE_FARCONNECT },
63     { 'G', UMODE_SOFTCALLERID },
64     { 'H', UMODE_HIDDEN },
65 michael 8963 { 'X', UMODE_EXPIRATION },
66 michael 5392 { 'R', UMODE_REGONLY },
67 michael 9157 { 'S', UMODE_SECURE },
68 michael 5392 { 'W', UMODE_WEBIRC },
69     { 'a', UMODE_ADMIN },
70     { 'c', UMODE_CCONN },
71     { 'd', UMODE_DEBUG },
72     { 'e', UMODE_EXTERNAL },
73 michael 9638 { 'f', UMODE_FLOOD },
74 michael 5392 { 'g', UMODE_CALLERID },
75     { 'i', UMODE_INVISIBLE },
76     { 'j', UMODE_REJ },
77     { 'k', UMODE_SKILL },
78     { 'l', UMODE_LOCOPS },
79     { 'n', UMODE_NCHANGE },
80     { 'o', UMODE_OPER },
81     { 'p', UMODE_HIDECHANS },
82     { 'q', UMODE_HIDEIDLE },
83     { 'r', UMODE_REGISTERED },
84     { 's', UMODE_SERVNOTICE },
85     { 'w', UMODE_WALLOP },
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 9250 show_lusers(struct Client *client)
112 adx 30 {
113 michael 9250 if (ConfigServerHide.hide_servers == 0 || HasUMode(client, UMODE_OPER))
114     sendto_one_numeric(client, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi),
115 michael 4209 Count.invisi, dlink_list_length(&global_server_list));
116 adx 30 else
117 michael 9250 sendto_one_numeric(client, &me, RPL_LUSERCLIENT, (dlink_list_length(&global_client_list) - Count.invisi),
118 michael 4724 Count.invisi, 1);
119 adx 30
120 michael 3375 if (Count.oper)
121 michael 9250 sendto_one_numeric(client, &me, RPL_LUSEROP, Count.oper);
122 adx 30
123 michael 3375 if (dlink_list_length(&unknown_list))
124 michael 9250 sendto_one_numeric(client, &me, RPL_LUSERUNKNOWN, dlink_list_length(&unknown_list));
125 adx 30
126 michael 8439 if (dlink_list_length(channel_get_list()))
127 michael 9250 sendto_one_numeric(client, &me, RPL_LUSERCHANNELS, dlink_list_length(channel_get_list()));
128 adx 30
129 michael 9250 if (ConfigServerHide.hide_servers == 0 || HasUMode(client, UMODE_OPER))
130 adx 30 {
131 michael 9250 sendto_one_numeric(client, &me, RPL_LUSERME, dlink_list_length(&local_client_list), dlink_list_length(&local_server_list));
132     sendto_one_numeric(client, &me, RPL_LOCALUSERS, dlink_list_length(&local_client_list), Count.max_loc);
133     sendto_one_numeric(client, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
134     sendto_one_numeric(client, &me, RPL_STATSCONN, Count.max_loc_con, Count.max_loc, Count.totalrestartcount);
135 adx 30 }
136     else
137     {
138 michael 9250 sendto_one_numeric(client, &me, RPL_LUSERME, dlink_list_length(&global_client_list), 0);
139     sendto_one_numeric(client, &me, RPL_LOCALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
140     sendto_one_numeric(client, &me, RPL_GLOBALUSERS, dlink_list_length(&global_client_list), Count.max_tot);
141 adx 30 }
142     }
143    
144 michael 3272 /* report_and_set_user_flags()
145     *
146 michael 9250 * inputs - pointer to client
147 michael 3272 * - pointer to conf for this user
148     * output - NONE
149     * side effects - Report to user any special flags
150     * they are getting, and set them.
151     */
152     static void
153 michael 9250 report_and_set_user_flags(struct Client *client, const struct MaskItem *conf)
154 michael 3272 {
155     /* If this user is being spoofed, tell them so */
156     if (IsConfDoSpoofIp(conf))
157 michael 9250 sendto_one_notice(client, &me, ":*** Spoofing your IP");
158 michael 3272
159 michael 4856 /* If this user is in the exception class, set it "E lined" */
160 michael 3272 if (IsConfExemptKline(conf))
161     {
162 michael 9250 AddFlag(client, FLAGS_EXEMPTKLINE);
163     sendto_one_notice(client, &me, ":*** You are exempt from K/D lines");
164 michael 3272 }
165    
166 michael 5985 if (IsConfExemptXline(conf))
167     {
168 michael 9250 AddFlag(client, FLAGS_EXEMPTXLINE);
169     sendto_one_notice(client, &me, ":*** You are exempt from X lines");
170 michael 5985 }
171    
172 michael 3272 if (IsConfExemptResv(conf))
173     {
174 michael 9250 AddFlag(client, FLAGS_EXEMPTRESV);
175     sendto_one_notice(client, &me, ":*** You are exempt from resvs");
176 michael 3272 }
177    
178     /* If this user is exempt from user limits set it "F lined" */
179     if (IsConfExemptLimits(conf))
180     {
181 michael 9250 AddFlag(client, FLAGS_NOLIMIT);
182     sendto_one_notice(client, &me, ":*** You are exempt from user limits");
183 michael 3272 }
184    
185     if (IsConfCanFlood(conf))
186     {
187 michael 9250 AddFlag(client, FLAGS_CANFLOOD);
188     sendto_one_notice(client, &me, ":*** You are exempt from flood protection");
189 michael 3272 }
190     }
191    
192     /* introduce_client()
193     *
194 michael 9250 * inputs - client
195 michael 3272 * output - NONE
196     * side effects - This common function introduces a client to the rest
197     * of the net, either from a local client connect or
198     * from a remote connect.
199     */
200     static void
201 michael 9250 introduce_client(struct Client *client)
202 michael 3272 {
203 michael 8059 dlink_node *node;
204 michael 8063 char buf[UMODE_MAX_STR] = "";
205 michael 3272
206 michael 9250 send_umode(client, MyConnect(client), 0, buf);
207 michael 9750 monitor_signon(client);
208 michael 3272
209 michael 8063 if (buf[0] == '\0')
210 michael 3272 {
211 michael 8063 buf[0] = '+';
212     buf[1] = '\0';
213 michael 3272 }
214    
215 michael 4815 DLINK_FOREACH(node, local_server_list.head)
216 michael 3272 {
217 michael 9264 struct Client *server = node->data;
218 michael 3272
219 michael 9264 if (server == client->from)
220 michael 3272 continue;
221    
222 michael 9854 sendto_one(server, ":%s UID %s %u %ju %s %s %s %s %s %s %s :%s",
223     client->servptr->id,
224     client->name, client->hopcount + 1,
225     client->tsinfo,
226     buf, client->username, client->host, client->realhost,
227     client->sockhost, client->id,
228     client->account,
229     client->info);
230 michael 3272
231 michael 9408 if (!EmptyString(client->tls_certfp))
232     sendto_one(server, ":%s CERTFP %s", client->id, client->tls_certfp);
233 michael 3272 }
234     }
235    
236     /* user_welcome()
237     *
238     * inputs - client pointer to client to welcome
239     * output - NONE
240     * side effects -
241     */
242     static void
243 michael 9250 user_welcome(struct Client *client)
244 michael 3272 {
245     static const char built_date[] = __DATE__ " at " __TIME__;
246    
247 michael 9250 if (HasFlag(client, FLAGS_TLS))
248 michael 3272 {
249 michael 9250 AddUMode(client, UMODE_SECURE);
250 michael 9411
251     client->tls_cipher = xstrdup(tls_get_cipher(&client->connection->fd->tls));
252 michael 9250 sendto_one_notice(client, &me, ":*** Connected securely via %s",
253 michael 9411 client->tls_cipher);
254 michael 3272 }
255    
256 michael 9250 sendto_one_numeric(client, &me, RPL_WELCOME, ConfigServerInfo.network_name,
257     client->name, client->username, client->realhost);
258     sendto_one_numeric(client, &me, RPL_YOURHOST,
259     listener_get_name(client->connection->listener), PATCHLEVEL);
260     sendto_one_numeric(client, &me, RPL_CREATED, built_date);
261     sendto_one_numeric(client, &me, RPL_MYINFO, me.name, PATCHLEVEL, umode_buffer);
262 michael 6252
263 michael 9250 isupport_show(client);
264     show_lusers(client);
265     motd_signon(client);
266 michael 3272 }
267    
268 michael 3317 /*! \brief This function is called when both NICK and USER messages
269 michael 3316 * have been accepted for the client, in whatever order. Only
270     * after this, is the UID message propagated.
271 michael 9250 * \param client Pointer to given client to introduce
272 michael 3316 */
273 adx 30 void
274 michael 9250 register_local_user(struct Client *client)
275 adx 30 {
276 michael 1632 const struct MaskItem *conf = NULL;
277 adx 30
278 michael 9250 assert(client == client->from);
279     assert(client->connection->registration == 0);
280     assert(MyConnect(client));
281     assert(IsUnknown(client));
282 adx 30
283 michael 4340 if (ConfigGeneral.ping_cookie)
284 adx 30 {
285 michael 9250 if (!HasFlag(client, FLAGS_PINGSENT) && client->connection->random_ping == 0)
286 adx 30 {
287 michael 983 do
288 michael 9250 client->connection->random_ping = genrand_int32();
289     while (client->connection->random_ping == 0);
290 michael 983
291 michael 9250 sendto_one(client, "PING :%u", client->connection->random_ping);
292     AddFlag(client, FLAGS_PINGSENT);
293 adx 30 return;
294     }
295    
296 michael 9250 if (!HasFlag(client, FLAGS_PING_COOKIE))
297 adx 30 return;
298     }
299    
300 michael 9250 if (conf_check_client(client) == false)
301 adx 30 return;
302    
303 michael 9250 conf = client->connection->confs.head->data;
304 adx 30
305 michael 9250 if (!HasFlag(client, FLAGS_GOTID))
306 adx 30 {
307 michael 9431 char username[USERLEN + 1];
308 adx 30 unsigned int i = 0;
309    
310 michael 1632 if (IsNeedIdentd(conf))
311 adx 30 {
312 michael 896 ++ServerStats.is_ref;
313 michael 9250 sendto_one_notice(client, &me, ":*** Notice -- You need to install "
314 michael 3110 "identd to use this server");
315 michael 9250 exit_client(client, "Install identd");
316 adx 30 return;
317     }
318    
319 michael 9250 strlcpy(username, client->username, sizeof(username));
320 adx 30
321 michael 1632 if (!IsNoTilde(conf))
322 michael 9250 client->username[i++] = '~';
323 adx 30
324 michael 6357 for (const char *p = username; *p && i < USERLEN; ++p)
325 michael 9250 client->username[i++] = *p;
326 adx 30
327 michael 9250 client->username[i] = '\0';
328 adx 30 }
329    
330 michael 3317 /* Password check */
331 michael 1632 if (!EmptyString(conf->passwd))
332 adx 30 {
333 michael 9250 if (match_conf_password(client->connection->password, conf) == false)
334 adx 30 {
335 michael 896 ++ServerStats.is_ref;
336 michael 3109
337 michael 9250 sendto_one_numeric(client, &me, ERR_PASSWDMISMATCH);
338     exit_client(client, "Bad Password");
339 adx 30 return;
340     }
341     }
342    
343 michael 9319 xfree(client->connection->password);
344     client->connection->password = NULL;
345 adx 30
346 michael 3317 /*
347 michael 9250 * Report if user has &^>= etc. and set flags as needed in client
348 michael 3317 */
349 michael 9250 report_and_set_user_flags(client, conf);
350 adx 30
351 michael 9250 if (IsDead(client))
352 michael 980 return;
353    
354 michael 3317 /*
355     * Limit clients -
356 adx 30 * We want to be able to have servers and F-line clients
357     * connect, so save room for "buffer" connections.
358     * Smaller servers may want to decrease this, and it should
359     * probably be just a percentage of the MAXCLIENTS...
360     * -Taner
361     */
362 michael 7969 if ((dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients + MAX_BUFFER) ||
363 michael 9250 (dlink_list_length(&local_client_list) >= GlobalSetOptions.maxclients && !HasFlag(client, FLAGS_NOLIMIT)))
364 adx 30 {
365 michael 9637 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
366 adx 30 "Too many clients, rejecting %s[%s].",
367 michael 9250 client->name, client->host);
368 michael 896 ++ServerStats.is_ref;
369 michael 9250 exit_client(client, "Sorry, server is full - try later");
370 adx 30 return;
371     }
372    
373 michael 9250 if (valid_username(client->username, true) == false)
374 adx 30 {
375 michael 9764 char buf[sizeof("Invalid username []") + sizeof(client->username)];
376 adx 30
377 michael 1618 sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
378     "Invalid username: %s (%s@%s)",
379 michael 9250 client->name, client->username, client->host);
380 michael 896 ++ServerStats.is_ref;
381 michael 9250 snprintf(buf, sizeof(buf), "Invalid username [%s]", client->username);
382     exit_client(client, buf);
383 adx 30 return;
384     }
385    
386 michael 9250 if (!HasFlag(client, FLAGS_EXEMPTXLINE))
387 michael 9106 {
388 michael 9250 const struct GecosItem *gecos = gecos_find(client->info, match);
389 michael 9106 if (gecos)
390     {
391     sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
392     "X-line Rejecting [%s] [%s], user %s [%s]",
393 michael 9250 client->info, gecos->reason,
394     client_get_name(client, HIDE_IP),
395     client->sockhost);
396 michael 9106 ++ServerStats.is_ref;
397 michael 9250 exit_client(client, "Bad user info");
398 michael 9106 return;
399     }
400     }
401 adx 30
402 michael 7570 const char *id;
403 michael 3215 while (hash_find_id((id = uid_get())))
404 michael 1115 ;
405 michael 573
406 michael 9250 strlcpy(client->id, id, sizeof(client->id));
407     hash_add_id(client);
408 adx 30
409 michael 1618 sendto_realops_flags(UMODE_CCONN, L_ALL, SEND_NOTICE,
410 michael 1137 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s>",
411 michael 9250 client->name, client->username, client->realhost,
412     client->sockhost,
413     get_client_class(&client->connection->confs),
414     client->info, client->id);
415 adx 30
416 michael 4340 if (ConfigGeneral.invisible_on_connect)
417 michael 159 {
418 michael 9250 AddUMode(client, UMODE_INVISIBLE);
419 michael 980 ++Count.invisi;
420 michael 159 }
421 adx 30
422 michael 9250 SetClient(client);
423 michael 9361
424     client->servptr = &me;
425 michael 9250 client->connection->last_privmsg = event_base->time.sec_monotonic;
426 michael 8710
427 michael 9250 dlinkAdd(client, &client->lnode, &client->servptr->serv->client_list);
428     dlinkAdd(client, &client->node, &global_client_list);
429 michael 1080
430 michael 9250 assert(dlinkFind(&unknown_list, client));
431 michael 1013
432 michael 9250 dlink_move_node(&client->connection->lclient_node,
433 michael 1126 &unknown_list, &local_client_list);
434 adx 30
435 michael 7969 if (dlink_list_length(&local_client_list) > Count.max_loc)
436     {
437     Count.max_loc = dlink_list_length(&local_client_list);
438    
439     if (!(Count.max_loc % 10))
440     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
441     "New maximum local client connections: %u",
442     Count.max_loc);
443     }
444    
445 michael 8001 if ((dlink_list_length(&local_client_list) +
446     dlink_list_length(&local_server_list)) > Count.max_loc_con)
447     Count.max_loc_con = dlink_list_length(&local_client_list) +
448     dlink_list_length(&local_server_list);
449    
450 michael 7965 if (dlink_list_length(&global_client_list) > Count.max_tot)
451     Count.max_tot = dlink_list_length(&global_client_list);
452     ++Count.totalrestartcount;
453    
454 michael 9250 user_welcome(client);
455 adx 30
456 michael 9250 introduce_client(client);
457 adx 30 }
458    
459     /* register_remote_user()
460     *
461 michael 9250 * inputs - client remote or directly connected client
462 adx 30 * - username to register as
463     * - host name to register as
464     * - server name
465     * output - NONE
466     * side effects - This function is called when a remote client
467     * is introduced by a server.
468     */
469     void
470 michael 9250 register_remote_user(struct Client *client)
471 adx 30 {
472 michael 9250 assert(client->servptr->from == client->from);
473 adx 30
474 michael 1167 /*
475     * If the nick has been introduced by a services server,
476     * make it a service as well.
477     */
478 michael 9250 if (HasFlag(client->servptr, FLAGS_SERVICE))
479     AddFlag(client, FLAGS_SERVICE);
480 michael 1167
481 michael 9250 SetClient(client);
482     dlinkAdd(client, &client->lnode, &client->servptr->serv->client_list);
483     dlinkAdd(client, &client->node, &global_client_list);
484 michael 7965
485     if (dlink_list_length(&global_client_list) > Count.max_tot)
486     Count.max_tot = dlink_list_length(&global_client_list);
487    
488 michael 9250 if (HasFlag(client->servptr, FLAGS_EOB))
489 michael 5743 sendto_realops_flags(UMODE_FARCONNECT, L_ALL, SEND_NOTICE,
490     "Client connecting at %s: %s (%s@%s) [%s] [%s] <%s>",
491 michael 9250 client->servptr->name,
492     client->name, client->username, client->realhost,
493     client->sockhost, client->info, client->id);
494 michael 1976
495 michael 9250 introduce_client(client);
496 adx 30 }
497    
498     /* valid_hostname()
499     *
500     * Inputs - pointer to hostname
501     * Output - 1 if valid, 0 if not
502     * Side effects - check hostname for validity
503     *
504     * NOTE: this doesn't allow a hostname to begin with a dot and
505     * will not allow more dots than chars.
506     */
507 michael 8658 bool
508 adx 30 valid_hostname(const char *hostname)
509     {
510     const char *p = hostname;
511    
512 michael 3235 assert(p);
513 adx 30
514 michael 2352 if (EmptyString(p) || *p == '.' || *p == ':')
515 michael 8658 return false;
516 adx 30
517 michael 1080 for (; *p; ++p)
518 adx 30 if (!IsHostChar(*p))
519 michael 8658 return false;
520 adx 30
521 michael 1795 return p - hostname <= HOSTLEN;
522 adx 30 }
523    
524     /* valid_username()
525     *
526     * Inputs - pointer to user
527     * Output - 1 if valid, 0 if not
528     * Side effects - check username for validity
529     *
530     * Absolutely always reject any '*' '!' '?' '@' in an user name
531     * reject any odd control characters names.
532     * Allow '.' in username to allow for "first.last"
533     * style of username
534     */
535 michael 8658 bool
536 michael 8660 valid_username(const char *username, bool local)
537 adx 30 {
538     const char *p = username;
539    
540 michael 3235 assert(p);
541 adx 30
542 michael 1080 if (*p == '~')
543 adx 30 ++p;
544    
545 michael 2067 /*
546     * Reject usernames that don't start with an alphanum
547 adx 30 * i.e. reject jokers who have '-@somehost' or '.@somehost'
548     * or "-hi-@somehost", "h-----@somehost" would still be accepted.
549     */
550     if (!IsAlNum(*p))
551 michael 8658 return false;
552 adx 30
553 michael 2067 if (local)
554 adx 30 {
555 michael 6756 unsigned int dots = 0;
556    
557 michael 2067 while (*++p)
558 adx 30 {
559 michael 4340 if (*p == '.' && ConfigGeneral.dots_in_ident)
560 michael 2067 {
561 michael 4340 if (++dots > ConfigGeneral.dots_in_ident)
562 michael 8658 return false;
563 michael 2067 if (!IsUserChar(*(p + 1)))
564 michael 8658 return false;
565 michael 2067 }
566     else if (!IsUserChar(*p))
567 michael 8658 return false;
568 adx 30 }
569     }
570 michael 2067 else
571     {
572     while (*++p)
573     if (!IsUserChar(*p))
574 michael 8658 return false;
575 michael 2067 }
576 adx 30
577 michael 3656 return p - username <= USERLEN;
578 adx 30 }
579    
580 michael 1165 /* clean_nick_name()
581     *
582     * input - nickname
583     * - whether it's a local nick (1) or remote (0)
584     * output - none
585     * side effects - walks through the nickname, returning 0 if erroneous
586     */
587 michael 8658 bool
588 michael 8660 valid_nickname(const char *nickname, bool local)
589 michael 1165 {
590     const char *p = nickname;
591 michael 3318
592 michael 4982 assert(p);
593 michael 1165
594 michael 3317 /*
595     * Nicks can't start with a digit or - or be 0 length.
596     */
597 michael 4709 if (EmptyString(p) || *p == '-' || (IsDigit(*p) && local))
598 michael 8658 return false;
599 michael 1165
600     for (; *p; ++p)
601     if (!IsNickChar(*p))
602 michael 8658 return false;
603 michael 1165
604 michael 1431 return p - nickname <= NICKLEN;
605 michael 1165 }
606    
607 michael 7599 /*! \brief Builds a mode change string to buffer pointed by \a buf
608 michael 9250 * \param client Pointer to client
609     * \param dispatch Whether to send a MODE message to client
610     * \param old Old user mode to compare against when building new mode buffer
611     * \param buf Pointer to buffer to build string in
612 adx 30 */
613     void
614 michael 9250 send_umode(struct Client *client, bool dispatch, unsigned int old, char *buf)
615 adx 30 {
616 michael 7599 char *m = buf;
617 adx 30 int what = 0;
618    
619 michael 56 /*
620 michael 3317 * Build a string in umode_buf to represent the change in the user's
621 michael 9250 * mode between the new (client->umodes) and 'old'.
622 adx 30 */
623 michael 5392 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
624 adx 30 {
625 michael 9250 if ((tab->flag & old) && !HasUMode(client, tab->flag))
626 adx 30 {
627     if (what == MODE_DEL)
628 michael 5392 *m++ = tab->c;
629 adx 30 else
630     {
631     what = MODE_DEL;
632     *m++ = '-';
633 michael 5392 *m++ = tab->c;
634 adx 30 }
635     }
636 michael 9250 else if (!(tab->flag & old) && HasUMode(client, tab->flag))
637 adx 30 {
638     if (what == MODE_ADD)
639 michael 5392 *m++ = tab->c;
640 adx 30 else
641     {
642     what = MODE_ADD;
643     *m++ = '+';
644 michael 5392 *m++ = tab->c;
645 adx 30 }
646     }
647     }
648    
649     *m = '\0';
650    
651 michael 8658 if (dispatch == true && *buf)
652 michael 9250 sendto_one(client, ":%s!%s@%s MODE %s :%s",
653     client->name, client->username,
654     client->host, client->name, buf);
655 adx 30 }
656    
657     /* send_umode_out()
658     *
659     * inputs -
660     * output - NONE
661     * side effects - Only send ubuf out to servers that know about this client
662     */
663     void
664 michael 9250 send_umode_out(struct Client *client, unsigned int old)
665 adx 30 {
666 michael 8063 char buf[UMODE_MAX_STR] = "";
667 adx 30
668 michael 9250 send_umode(client, MyConnect(client), old, buf);
669 adx 30
670 michael 573 if (buf[0])
671 michael 9250 sendto_server(client, 0, 0, ":%s MODE %s :%s",
672     client->id, client->id, buf);
673 adx 30 }
674    
675 michael 1819 void
676 michael 9250 user_set_hostmask(struct Client *client, const char *hostname)
677 michael 1819 {
678 michael 8059 dlink_node *node;
679 michael 2141
680 michael 9250 if (strcmp(client->host, hostname) == 0)
681 michael 2145 return;
682 michael 2141
683 michael 4340 if (ConfigGeneral.cycle_on_host_change)
684 michael 9250 sendto_common_channels_local(client, false, 0, CAP_CHGHOST, ":%s!%s@%s QUIT :Changing hostname",
685     client->name, client->username, client->host);
686 michael 2145
687 michael 9250 sendto_common_channels_local(client, true, CAP_CHGHOST, 0, ":%s!%s@%s CHGHOST %s %s",
688     client->name, client->username,
689     client->host, client->username, hostname);
690 michael 6774
691 michael 9250 strlcpy(client->host, hostname, sizeof(client->host));
692 michael 2145
693 michael 9250 if (MyConnect(client))
694 michael 2137 {
695 michael 9250 sendto_one_numeric(client, &me, RPL_VISIBLEHOST, client->host);
696     clear_ban_cache_list(&client->channel);
697 michael 2137 }
698 michael 2141
699 michael 8512 if (ConfigGeneral.cycle_on_host_change == 0)
700 michael 2283 return;
701    
702 michael 9250 DLINK_FOREACH(node, client->channel.head)
703 michael 2141 {
704 michael 6904 char modebuf[CMEMBER_STATUS_FLAGS_LEN + 1];
705     char nickbuf[CMEMBER_STATUS_FLAGS_LEN * NICKLEN + CMEMBER_STATUS_FLAGS_LEN] = "";
706 michael 2141 char *p = modebuf;
707     int len = 0;
708 michael 9081 const struct ChannelMember *member = node->data;
709 michael 2141
710 michael 9598 if (member_has_flags(member, CHFL_CHANOP) == true)
711 michael 2283 {
712 michael 2141 *p++ = 'o';
713 michael 9250 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name);
714 michael 2141 }
715    
716 michael 9598 if (member_has_flags(member, CHFL_HALFOP) == true)
717 michael 2283 {
718 michael 2141 *p++ = 'h';
719 michael 9250 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name);
720 michael 2141 }
721    
722 michael 9598 if (member_has_flags(member, CHFL_VOICE) == true)
723 michael 2283 {
724 michael 2141 *p++ = 'v';
725 michael 9250 len += snprintf(nickbuf + len, sizeof(nickbuf) - len, len ? " %s" : "%s", client->name);
726 michael 2141 }
727    
728     *p = '\0';
729    
730 michael 9250 sendto_channel_local(client, member->channel, 0, CAP_EXTENDED_JOIN, CAP_CHGHOST, ":%s!%s@%s JOIN %s %s :%s",
731     client->name, client->username,
732     client->host, member->channel->name,
733     client->account, client->info);
734     sendto_channel_local(client, member->channel, 0, 0, CAP_EXTENDED_JOIN | CAP_CHGHOST, ":%s!%s@%s JOIN :%s",
735     client->name, client->username,
736     client->host, member->channel->name);
737 michael 4792
738 michael 2141 if (nickbuf[0])
739 michael 9250 sendto_channel_local(client, member->channel, 0, 0, CAP_CHGHOST, ":%s MODE %s +%s %s",
740     client->servptr->name, member->channel->name,
741 michael 6759 modebuf, nickbuf);
742 michael 2141 }
743 michael 6777
744 michael 9250 if (client->away[0])
745     sendto_common_channels_local(client, false, CAP_AWAY_NOTIFY, CAP_CHGHOST,
746 michael 6777 ":%s!%s@%s AWAY :%s",
747 michael 9250 client->name, client->username,
748     client->host, client->away);
749 michael 1819 }

Properties

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