ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 9249
Committed: Sat Feb 1 13:35:32 2020 UTC (6 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 22214 byte(s)
Log Message:
- Rename most occurrences of 'client_p' to 'client' 

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

Properties

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