ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/user.c
Revision: 9102
Committed: Wed Jan 1 09:58:57 2020 UTC (6 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 22885 byte(s)
Log Message:
- Bump copyright years everywhere

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

Properties

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