]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/s_user.c
merge 07 in
[irc/quakenet/snircd.git] / ircd / s_user.c
1 /*
2 * IRC - Internet Relay Chat, ircd/s_user.c (formerly ircd/s_msg.c)
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
6 * See file AUTHORS in IRC package for additional names of
7 * the programmers.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23 /** @file
24 * @brief Miscellaneous user-related helper functions.
25 * @version $Id: s_user.c,v 1.99.2.2 2006/02/16 03:49:54 entrope Exp $
26 */
27 #include "config.h"
28
29 #include "s_user.h"
30 #include "IPcheck.h"
31 #include "channel.h"
32 #include "class.h"
33 #include "client.h"
34 #include "hash.h"
35 #include "ircd.h"
36 #include "ircd_alloc.h"
37 #include "ircd_chattr.h"
38 #include "ircd_features.h"
39 #include "ircd_log.h"
40 #include "ircd_reply.h"
41 #include "ircd_snprintf.h"
42 #include "ircd_string.h"
43 #include "list.h"
44 #include "match.h"
45 #include "motd.h"
46 #include "msg.h"
47 #include "msgq.h"
48 #include "numeric.h"
49 #include "numnicks.h"
50 #include "parse.h"
51 #include "querycmds.h"
52 #include "random.h"
53 #include "s_auth.h"
54 #include "s_bsd.h"
55 #include "s_conf.h"
56 #include "s_debug.h"
57 #include "s_misc.h"
58 #include "s_serv.h" /* max_client_count */
59 #include "send.h"
60 #include "struct.h"
61 #include "supported.h"
62 #include "sys.h"
63 #include "userload.h"
64 #include "version.h"
65 #include "whowas.h"
66
67 #include "handlers.h" /* m_motd and m_lusers */
68
69 /* #include <assert.h> -- Now using assert in ircd_log.h */
70 #include <fcntl.h>
71 #include <stdio.h>
72 #include <stdlib.h>
73 #include <string.h>
74 #include <sys/stat.h>
75
76 static char *IsVhost(char *hostmask, int oper);
77 static char *IsVhostPass(char *hostmask);
78
79 /** Count of allocated User structures. */
80 static int userCount = 0;
81
82 /** Makes sure that \a cptr has a User information block.
83 * If cli_user(cptr) != NULL, does nothing.
84 * @param[in] cptr Client to attach User struct to.
85 * @return User struct associated with \a cptr.
86 */
87 struct User *make_user(struct Client *cptr)
88 {
89 assert(0 != cptr);
90
91 if (!cli_user(cptr)) {
92 cli_user(cptr) = (struct User*) MyMalloc(sizeof(struct User));
93 assert(0 != cli_user(cptr));
94
95 /* All variables are 0 by default */
96 memset(cli_user(cptr), 0, sizeof(struct User));
97 ++userCount;
98 cli_user(cptr)->refcnt = 1;
99 }
100 return cli_user(cptr);
101 }
102
103 /** Dereference \a user.
104 * User structures are reference-counted; if the refcount of \a user
105 * becomes zero, free it.
106 * @param[in] user User to dereference.
107 */
108 void free_user(struct User* user)
109 {
110 assert(0 != user);
111 assert(0 < user->refcnt);
112
113 if (--user->refcnt == 0) {
114 if (user->away)
115 MyFree(user->away);
116 /*
117 * sanity check
118 */
119 assert(0 == user->joined);
120 assert(0 == user->invited);
121 assert(0 == user->channel);
122
123 MyFree(user);
124 --userCount;
125 }
126 }
127
128 /** Find number of User structs allocated and memory used by them.
129 * @param[out] count_out Receives number of User structs allocated.
130 * @param[out] bytes_out Receives number of bytes used by User structs.
131 */
132 void user_count_memory(size_t* count_out, size_t* bytes_out)
133 {
134 assert(0 != count_out);
135 assert(0 != bytes_out);
136 *count_out = userCount;
137 *bytes_out = userCount * sizeof(struct User);
138 }
139
140
141 /** Find the next client (starting at \a next) with a name that matches \a ch.
142 * Normal usage loop is:
143 * for (x = client; x = next_client(x,mask); x = x->next)
144 * HandleMatchingClient;
145 *
146 * @param[in] next First client to check.
147 * @param[in] ch Name mask to check against.
148 * @return Next matching client found, or NULL if none.
149 */
150 struct Client *next_client(struct Client *next, const char* ch)
151 {
152 struct Client *tmp = next;
153
154 if (!tmp)
155 return NULL;
156
157 next = FindClient(ch);
158 next = next ? next : tmp;
159 if (cli_prev(tmp) == next)
160 return NULL;
161 if (next != tmp)
162 return next;
163 for (; next; next = cli_next(next))
164 if (!match(ch, cli_name(next)))
165 break;
166 return next;
167 }
168
169 /** Find the destination server for a command, and forward it if that is not us.
170 *
171 * \a server may be a nickname, server name, server mask (if \a from
172 * is a local user) or server numnick (if \a is a server or remote
173 * user).
174 *
175 * @param[in] from Client that sent the command to us.
176 * @param[in] cmd Long-form command text.
177 * @param[in] tok Token-form command text.
178 * @param[in] one Client that originated the command (ignored).
179 * @param[in] MustBeOper If non-zero and \a from is not an operator, return HUNTED_NOSUCH.
180 * @param[in] pattern Format string of arguments to command.
181 * @param[in] server Index of target name or mask in \a parv.
182 * @param[in] parc Number of valid elements in \a parv (must be less than 9).
183 * @param[in] parv Array of arguments to command.
184 * @return One of HUNTED_ISME, HUNTED_NOSUCH or HUNTED_PASS.
185 */
186 int hunt_server_cmd(struct Client *from, const char *cmd, const char *tok,
187 struct Client *one, int MustBeOper, const char *pattern,
188 int server, int parc, char *parv[])
189 {
190 struct Client *acptr;
191 char *to;
192
193 /* Assume it's me, if no server or an unregistered client */
194 if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
195 return (HUNTED_ISME);
196
197 if (MustBeOper && !IsPrivileged(from))
198 {
199 send_reply(from, ERR_NOPRIVILEGES);
200 return HUNTED_NOSUCH;
201 }
202
203 /* Make sure it's a server */
204 if (MyUser(from)) {
205 /* Make sure it's a server */
206 if (!strchr(to, '*')) {
207 if (0 == (acptr = FindClient(to))) {
208 send_reply(from, ERR_NOSUCHSERVER, to);
209 return HUNTED_NOSUCH;
210 }
211
212 if (cli_user(acptr))
213 acptr = cli_user(acptr)->server;
214 } else if (!(acptr = find_match_server(to))) {
215 send_reply(from, ERR_NOSUCHSERVER, to);
216 return (HUNTED_NOSUCH);
217 }
218 } else if (!(acptr = FindNServer(to))) {
219 send_reply(from, SND_EXPLICIT | ERR_NOSUCHSERVER, "* :Server has disconnected");
220 return (HUNTED_NOSUCH); /* Server broke off in the meantime */
221 }
222
223 if (IsMe(acptr))
224 return (HUNTED_ISME);
225
226 if (MustBeOper && !IsPrivileged(from)) {
227 send_reply(from, ERR_NOPRIVILEGES);
228 return HUNTED_NOSUCH;
229 }
230
231 /* assert(!IsServer(from)); */
232
233 parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
234
235 sendcmdto_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3],
236 parv[4], parv[5], parv[6], parv[7], parv[8]);
237
238 return (HUNTED_PASS);
239 }
240
241 /** Find the destination server for a command, and forward it (as a
242 * high-priority command) if that is not us.
243 *
244 * \a server may be a nickname, server name, server mask (if \a from
245 * is a local user) or server numnick (if \a is a server or remote
246 * user).
247 * Unlike hunt_server_cmd(), this appends the message to the
248 * high-priority message queue for the destination server.
249 *
250 * @param[in] from Client that sent the command to us.
251 * @param[in] cmd Long-form command text.
252 * @param[in] tok Token-form command text.
253 * @param[in] one Client that originated the command (ignored).
254 * @param[in] MustBeOper If non-zero and \a from is not an operator, return HUNTED_NOSUCH.
255 * @param[in] pattern Format string of arguments to command.
256 * @param[in] server Index of target name or mask in \a parv.
257 * @param[in] parc Number of valid elements in \a parv (must be less than 9).
258 * @param[in] parv Array of arguments to command.
259 * @return One of HUNTED_ISME, HUNTED_NOSUCH or HUNTED_PASS.
260 */
261 int hunt_server_prio_cmd(struct Client *from, const char *cmd, const char *tok,
262 struct Client *one, int MustBeOper,
263 const char *pattern, int server, int parc,
264 char *parv[])
265 {
266 struct Client *acptr;
267 char *to;
268
269 /* Assume it's me, if no server or an unregistered client */
270 if (parc <= server || EmptyString((to = parv[server])) || IsUnknown(from))
271 return (HUNTED_ISME);
272
273 /* Make sure it's a server */
274 if (MyUser(from)) {
275 /* Make sure it's a server */
276 if (!strchr(to, '*')) {
277 if (0 == (acptr = FindClient(to))) {
278 send_reply(from, ERR_NOSUCHSERVER, to);
279 return HUNTED_NOSUCH;
280 }
281
282 if (cli_user(acptr))
283 acptr = cli_user(acptr)->server;
284 } else if (!(acptr = find_match_server(to))) {
285 send_reply(from, ERR_NOSUCHSERVER, to);
286 return (HUNTED_NOSUCH);
287 }
288 } else if (!(acptr = FindNServer(to)))
289 return (HUNTED_NOSUCH); /* Server broke off in the meantime */
290
291 if (IsMe(acptr))
292 return (HUNTED_ISME);
293
294 if (MustBeOper && !IsPrivileged(from)) {
295 send_reply(from, ERR_NOPRIVILEGES);
296 return HUNTED_NOSUCH;
297 }
298
299 /* assert(!IsServer(from)); SETTIME to particular destinations permitted */
300
301 parv[server] = (char *) acptr; /* HACK! HACK! HACK! ARGH! */
302
303 sendcmdto_prio_one(from, cmd, tok, acptr, pattern, parv[1], parv[2], parv[3],
304 parv[4], parv[5], parv[6], parv[7], parv[8]);
305
306 return (HUNTED_PASS);
307 }
308
309
310 /*
311 * register_user
312 *
313 * This function is called when both NICK and USER messages
314 * have been accepted for the client, in whatever order. Only
315 * after this the USER message is propagated.
316 *
317 * NICK's must be propagated at once when received, although
318 * it would be better to delay them too until full info is
319 * available. Doing it is not so simple though, would have
320 * to implement the following:
321 *
322 * 1) user telnets in and gives only "NICK foobar" and waits
323 * 2) another user far away logs in normally with the nick
324 * "foobar" (quite legal, as this server didn't propagate it).
325 * 3) now this server gets nick "foobar" from outside, but
326 * has already the same defined locally. Current server
327 * would just issue "KILL foobar" to clean out dups. But,
328 * this is not fair. It should actually request another
329 * nick from local user or kill him/her...
330 */
331 /** Finish registering a user who has sent both NICK and USER.
332 * For local connections, possibly check IAuth; make sure there is a
333 * matching Client config block; clean the username field; check
334 * K/k-lines; check for "hacked" looking usernames; assign a numnick;
335 * and send greeting (WELCOME, ISUPPORT, MOTD, etc).
336 * For all connections, update the invisible user and operator counts;
337 * run IPcheck against their address; and forward the NICK.
338 *
339 * @param[in] cptr Client who introduced the user.
340 * @param[in,out] sptr Client who has been fully introduced.
341 * @return Zero or CPTR_KILLED.
342 */
343 int register_user(struct Client *cptr, struct Client *sptr)
344 {
345 char* parv[4];
346 char* tmpstr;
347 struct User* user = cli_user(sptr);
348 char ip_base64[25];
349
350 user->last = CurrentTime;
351 parv[0] = cli_name(sptr);
352 parv[1] = parv[2] = NULL;
353
354 if (MyConnect(sptr))
355 {
356 assert(cptr == sptr);
357
358 Count_unknownbecomesclient(sptr, UserStats);
359
360 if (MyConnect(sptr) && feature_bool(FEAT_AUTOINVISIBLE))
361 SetInvisible(sptr);
362
363 if(MyConnect(sptr) && feature_bool(FEAT_SETHOST_AUTO)) {
364 if (conf_check_slines(sptr)) {
365 send_reply(sptr, RPL_USINGSLINE);
366 SetSetHost(sptr);
367 }
368 }
369
370 SetUser(sptr);
371 cli_handler(sptr) = CLIENT_HANDLER;
372 SetLocalNumNick(sptr);
373 send_reply(sptr,
374 RPL_WELCOME,
375 feature_str(FEAT_NETWORK),
376 feature_str(FEAT_PROVIDER) ? " via " : "",
377 feature_str(FEAT_PROVIDER) ? feature_str(FEAT_PROVIDER) : "",
378 cli_name(sptr));
379 /*
380 * This is a duplicate of the NOTICE but see below...
381 */
382 send_reply(sptr, RPL_YOURHOST, cli_name(&me), version);
383 send_reply(sptr, RPL_CREATED, creation);
384 send_reply(sptr, RPL_MYINFO, cli_name(&me), version, infousermodes,
385 infochanmodes, infochanmodeswithparams);
386 send_supported(sptr);
387 m_lusers(sptr, sptr, 1, parv);
388 update_load();
389 motd_signon(sptr);
390 if (cli_snomask(sptr) & SNO_NOISY)
391 set_snomask(sptr, cli_snomask(sptr) & SNO_NOISY, SNO_ADD);
392 if (feature_bool(FEAT_CONNEXIT_NOTICES))
393 sendto_opmask_butone(0, SNO_CONNEXIT,
394 "Client connecting: %s (%s@%s) [%s] {%s} [%s] <%s%s>",
395 cli_name(sptr), user->username, user->host,
396 cli_sock_ip(sptr), get_client_class(sptr),
397 cli_info(sptr), NumNick(cptr) /* two %s's */);
398
399 IPcheck_connect_succeeded(sptr);
400 /*
401 * Set user's initial modes
402 */
403 tmpstr = (char*)client_get_default_umode(sptr);
404 if (tmpstr) for (; *tmpstr; ++tmpstr) {
405 switch (*tmpstr) {
406 case 's':
407 if (!feature_bool(FEAT_HIS_SNOTICES_OPER_ONLY)) {
408 SetServNotice(sptr);
409 set_snomask(sptr, SNO_DEFAULT, SNO_SET);
410 }
411 break;
412 case 'w':
413 if (!feature_bool(FEAT_WALLOPS_OPER_ONLY))
414 SetWallops(sptr);
415 break;
416 case 'i':
417 SetInvisible(sptr);
418 break;
419 case 'd':
420 SetDeaf(sptr);
421 break;
422 case 'g':
423 if (!feature_bool(FEAT_HIS_DEBUG_OPER_ONLY))
424 SetDebug(sptr);
425 break;
426 }
427 }
428 }
429 else {
430 struct Client *acptr = user->server;
431
432 Count_newremoteclient(UserStats, acptr);
433
434 if (cli_from(acptr) != cli_from(sptr))
435 {
436 sendcmdto_one(&me, CMD_KILL, cptr, "%C :%s (%s != %s[%s])",
437 sptr, cli_name(&me), cli_name(user->server), cli_name(cli_from(acptr)),
438 cli_sockhost(cli_from(acptr)));
439 SetFlag(sptr, FLAG_KILLED);
440 return exit_client(cptr, sptr, &me, "NICK server wrong direction");
441 }
442 else if (HasFlag(acptr, FLAG_TS8))
443 SetFlag(sptr, FLAG_TS8);
444
445 /*
446 * Check to see if this user is being propagated
447 * as part of a net.burst, or is using protocol 9.
448 * FIXME: This can be sped up - its stupid to check it for
449 * every NICK message in a burst again --Run.
450 */
451 for (; acptr != &me; acptr = cli_serv(acptr)->up)
452 {
453 if (IsBurst(acptr) || Protocol(acptr) < 10)
454 break;
455 }
456 if (!IPcheck_remote_connect(sptr, (acptr != &me)))
457 {
458 /*
459 * We ran out of bits to count this
460 */
461 sendcmdto_one(&me, CMD_KILL, sptr, "%C :%s (Too many connections from your host -- Ghost)",
462 sptr, cli_name(&me));
463 return exit_client(cptr, sptr, &me,"Too many connections from your host -- throttled");
464 }
465
466 if(MyConnect(sptr) && feature_bool(FEAT_SETHOST_AUTO)) {
467 if (conf_check_slines(sptr)) {
468 send_reply(sptr, RPL_USINGSLINE);
469 SetSetHost(sptr);
470 }
471 }
472
473 SetUser(sptr);
474 }
475
476 if (IsInvisible(sptr))
477 ++UserStats.inv_clients;
478 if (IsOper(sptr))
479 ++UserStats.opers;
480
481 tmpstr = umode_str(sptr);
482 /* Send full IP address to IPv6-grokking servers. */
483 sendcmdto_flag_serv_butone(user->server, CMD_NICK, cptr,
484 FLAG_IPV6, FLAG_LAST_FLAG,
485 "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
486 cli_name(sptr), cli_hopcount(sptr) + 1,
487 cli_lastnick(sptr),
488 user->realusername, user->realhost,
489 *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
490 iptobase64(ip_base64, &cli_ip(sptr), sizeof(ip_base64), 1),
491 NumNick(sptr), cli_info(sptr));
492 /* Send fake IPv6 addresses to pre-IPv6 servers. */
493 sendcmdto_flag_serv_butone(user->server, CMD_NICK, cptr,
494 FLAG_LAST_FLAG, FLAG_IPV6,
495 "%s %d %Tu %s %s %s%s%s%s %s%s :%s",
496 cli_name(sptr), cli_hopcount(sptr) + 1,
497 cli_lastnick(sptr),
498 user->realusername, user->realhost,
499 *tmpstr ? "+" : "", tmpstr, *tmpstr ? " " : "",
500 iptobase64(ip_base64, &cli_ip(sptr), sizeof(ip_base64), 0),
501 NumNick(sptr), cli_info(sptr));
502
503 /* Send user mode to client */
504 if (MyUser(sptr))
505 {
506 static struct Flags flags; /* automatically initialized to zeros */
507 /* To avoid sending +r to the client due to auth-on-connect, set
508 * the "old" FLAG_ACCOUNT bit to match the client's value.
509 */
510 if (IsAccount(cptr))
511 FlagSet(&flags, FLAG_ACCOUNT);
512 else
513 FlagClr(&flags, FLAG_ACCOUNT);
514 send_umode(cptr, sptr, &flags, ALL_UMODES);
515 if ((cli_snomask(sptr) != SNO_DEFAULT) && HasFlag(sptr, FLAG_SERVNOTICE))
516 send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
517 }
518 return 0;
519 }
520
521 /** List of user mode characters. */
522 static const struct UserMode {
523 unsigned int flag; /**< User mode constant. */
524 char c; /**< Character corresponding to the mode. */
525 } userModeList[] = {
526 { FLAG_OPER, 'o' },
527 { FLAG_LOCOP, 'O' },
528 { FLAG_INVISIBLE, 'i' },
529 { FLAG_WALLOP, 'w' },
530 { FLAG_SERVNOTICE, 's' },
531 { FLAG_DEAF, 'd' },
532 { FLAG_CHSERV, 'k' },
533 { FLAG_DEBUG, 'g' },
534 { FLAG_ACCOUNT, 'r' },
535 { FLAG_HIDDENHOST, 'x' },
536 { FLAG_ACCOUNTONLY, 'R' },
537 { FLAG_XTRAOP, 'X' },
538 { FLAG_NOCHAN, 'n' },
539 { FLAG_NOIDLE, 'I' },
540 { FLAG_SETHOST, 'h' },
541 { FLAG_PARANOID, 'P' }
542 };
543
544 /** Length of #userModeList. */
545 #define USERMODELIST_SIZE sizeof(userModeList) / sizeof(struct UserMode)
546
547 /*
548 * XXX - find a way to get rid of this
549 */
550 /** Nasty global buffer used for communications with umode_str() and others. */
551 static char umodeBuf[BUFSIZE];
552
553 /** Try to set a user's nickname.
554 * If \a sptr is a server, the client is being introduced for the first time.
555 * @param[in] cptr Client to set nickname.
556 * @param[in] sptr Client sending the NICK.
557 * @param[in] nick New nickname.
558 * @param[in] parc Number of arguments to NICK.
559 * @param[in] parv Argument list to NICK.
560 * @return CPTR_KILLED if \a cptr was killed, else 0.
561 */
562 int set_nick_name(struct Client* cptr, struct Client* sptr,
563 const char* nick, int parc, char* parv[])
564 {
565 if (IsServer(sptr)) {
566 int i;
567 const char* account = 0;
568 char* hostmask = 0;
569 char* host = 0;
570 const char* p;
571
572 /*
573 * A server introducing a new client, change source
574 */
575 struct Client* new_client = make_client(cptr, STAT_UNKNOWN);
576 assert(0 != new_client);
577
578 cli_hopcount(new_client) = atoi(parv[2]);
579 cli_lastnick(new_client) = atoi(parv[3]);
580 if (Protocol(cptr) > 9 && parc > 7 && *parv[6] == '+')
581 {
582 for (p = parv[6] + 1; *p; p++)
583 {
584 for (i = 0; i < USERMODELIST_SIZE; ++i)
585 {
586 if (userModeList[i].c == *p)
587 {
588 SetFlag(new_client, userModeList[i].flag);
589 if (userModeList[i].flag == FLAG_ACCOUNT)
590 account = parv[7];
591 if (userModeList[i].flag == FLAG_SETHOST)
592 hostmask = parv[parc - 4];
593 break;
594 }
595 }
596 }
597 }
598 client_set_privs(new_client, NULL); /* set privs on user */
599 /*
600 * Set new nick name.
601 */
602 strcpy(cli_name(new_client), nick);
603 cli_user(new_client) = make_user(new_client);
604 cli_user(new_client)->server = sptr;
605 SetRemoteNumNick(new_client, parv[parc - 2]);
606 /*
607 * IP# of remote client
608 */
609 base64toip(parv[parc - 3], &cli_ip(new_client));
610
611 add_client_to_list(new_client);
612 hAddClient(new_client);
613
614 cli_serv(sptr)->ghost = 0; /* :server NICK means end of net.burst */
615 ircd_strncpy(cli_username(new_client), parv[4], USERLEN);
616 ircd_strncpy(cli_user(new_client)->realusername, parv[4], USERLEN);
617 ircd_strncpy(cli_user(new_client)->host, parv[5], HOSTLEN);
618 ircd_strncpy(cli_user(new_client)->realhost, parv[5], HOSTLEN);
619 ircd_strncpy(cli_info(new_client), parv[parc - 1], REALLEN);
620 if (account) {
621 int len = ACCOUNTLEN;
622 if ((p = strchr(account, ':'))) {
623 len = (p++) - account;
624 cli_user(new_client)->acc_create = atoi(p);
625 Debug((DEBUG_DEBUG, "Received timestamped account in user mode; "
626 "account \"%s\", timestamp %Tu", account,
627 cli_user(new_client)->acc_create));
628 }
629 ircd_strncpy(cli_user(new_client)->account, account, len);
630 }
631 if (HasHiddenHost(new_client))
632 ircd_snprintf(0, cli_user(new_client)->host, HOSTLEN, "%s.%s",
633 account, feature_str(FEAT_HIDDEN_HOST));
634 if (HasSetHost(new_client)) {
635 if ((host = strrchr(hostmask, '@')) != NULL) {
636 *host++ = '\0';
637 ircd_strncpy(cli_username(new_client), hostmask, USERLEN);
638 ircd_strncpy(cli_user(new_client)->host, host, HOSTLEN);
639 }
640 }
641
642 return register_user(cptr, new_client);
643 }
644 else if ((cli_name(sptr))[0]) {
645 /*
646 * Client changing its nick
647 *
648 * If the client belongs to me, then check to see
649 * if client is on any channels where it is currently
650 * banned. If so, do not allow the nick change to occur.
651 */
652 if (MyUser(sptr)) {
653 const char* channel_name;
654 struct Membership *member;
655 if ((channel_name = find_no_nickchange_channel(sptr)) && !IsXtraOp(sptr)) {
656 return send_reply(cptr, ERR_BANNICKCHANGE, channel_name);
657 }
658 /*
659 * Refuse nick change if the last nick change was less
660 * then 30 seconds ago. This is intended to get rid of
661 * clone bots doing NICK FLOOD. -SeKs
662 * If someone didn't change their nick for more then 60 seconds
663 * however, allow to do two nick changes immediately after another
664 * before limiting the nick flood. -Run
665 */
666 if (CurrentTime < cli_nextnick(cptr))
667 {
668 cli_nextnick(cptr) += 2;
669 send_reply(cptr, ERR_NICKTOOFAST, parv[1],
670 cli_nextnick(cptr) - CurrentTime);
671 /* Send error message */
672 sendcmdto_one(cptr, CMD_NICK, cptr, "%s", cli_name(cptr));
673 /* bounce NICK to user */
674 return 0; /* ignore nick change! */
675 }
676 else {
677 /* Limit total to 1 change per NICK_DELAY seconds: */
678 cli_nextnick(cptr) += NICK_DELAY;
679 /* However allow _maximal_ 1 extra consecutive nick change: */
680 if (cli_nextnick(cptr) < CurrentTime)
681 cli_nextnick(cptr) = CurrentTime;
682 }
683 /* Invalidate all bans against the user so we check them again */
684 for (member = (cli_user(cptr))->channel; member;
685 member = member->next_channel)
686 ClearBanValid(member);
687 }
688 /*
689 * Also set 'lastnick' to current time, if changed.
690 */
691 if (0 != ircd_strcmp(parv[0], nick))
692 cli_lastnick(sptr) = (sptr == cptr) ? TStime() : atoi(parv[2]);
693
694 /*
695 * Client just changing his/her nick. If he/she is
696 * on a channel, send note of change to all clients
697 * on that channel. Propagate notice to other servers.
698 */
699 if (IsUser(sptr)) {
700 sendcmdto_common_channels_butone(sptr, CMD_NICK, NULL, ":%s", nick);
701 add_history(sptr, 1);
702 sendcmdto_serv_butone(sptr, CMD_NICK, cptr, "%s %Tu", nick,
703 cli_lastnick(sptr));
704 }
705 else
706 sendcmdto_one(sptr, CMD_NICK, sptr, ":%s", nick);
707
708 if ((cli_name(sptr))[0])
709 hRemClient(sptr);
710 strcpy(cli_name(sptr), nick);
711 hAddClient(sptr);
712 }
713 else {
714 /* Local client setting NICK the first time */
715 strcpy(cli_name(sptr), nick);
716 hAddClient(sptr);
717 return auth_set_nick(cli_auth(sptr), nick);
718 }
719 return 0;
720 }
721
722 /** Calculate the hash value for a target.
723 * @param[in] target Pointer to target, cast to unsigned int.
724 * @return Hash value constructed from the pointer.
725 */
726 static unsigned char hash_target(unsigned int target)
727 {
728 return (unsigned char) (target >> 16) ^ (target >> 8);
729 }
730
731 /** Records \a target as a recent target for \a sptr.
732 * @param[in] sptr User who has sent to a new target.
733 * @param[in] target Target to add.
734 */
735 void
736 add_target(struct Client *sptr, void *target)
737 {
738 /* Ok, this shouldn't work esp on alpha
739 */
740 unsigned char hash = hash_target((unsigned long) target);
741 unsigned char* targets;
742 int i;
743 assert(0 != sptr);
744 assert(cli_local(sptr));
745
746 targets = cli_targets(sptr);
747
748 /*
749 * Already in table?
750 */
751 for (i = 0; i < MAXTARGETS; ++i) {
752 if (targets[i] == hash)
753 return;
754 }
755 /*
756 * New target
757 */
758 memmove(&targets[RESERVEDTARGETS + 1],
759 &targets[RESERVEDTARGETS], MAXTARGETS - RESERVEDTARGETS - 1);
760 targets[RESERVEDTARGETS] = hash;
761 }
762
763 /** Check whether \a sptr can send to or join \a target yet.
764 * @param[in] sptr User trying to join a channel or send a message.
765 * @param[in] target Target of the join or message.
766 * @param[in] name Name of the target.
767 * @param[in] created If non-zero, trying to join a new channel.
768 * @return Non-zero if too many target changes; zero if okay to send.
769 */
770 int check_target_limit(struct Client *sptr, void *target, const char *name,
771 int created)
772 {
773 unsigned char hash = hash_target((unsigned long) target);
774 int i;
775 unsigned char* targets;
776
777 assert(0 != sptr);
778 assert(cli_local(sptr));
779 targets = cli_targets(sptr);
780
781 /* If user is invited to channel, give him/her a free target */
782 if (IsChannelName(name) && IsInvited(sptr, target))
783 return 0;
784
785 /* opers always have a free target */
786 if (IsAnOper(sptr))
787 return 0;
788
789 /*
790 * Same target as last time?
791 */
792 if (targets[0] == hash)
793 return 0;
794 for (i = 1; i < MAXTARGETS; ++i) {
795 if (targets[i] == hash) {
796 memmove(&targets[1], &targets[0], i);
797 targets[0] = hash;
798 return 0;
799 }
800 }
801 /*
802 * New target
803 */
804 if (!created) {
805 if (CurrentTime < cli_nexttarget(sptr)) {
806 if (cli_nexttarget(sptr) - CurrentTime < TARGET_DELAY + 8) {
807 /*
808 * No server flooding
809 */
810 cli_nexttarget(sptr) += 2;
811 send_reply(sptr, ERR_TARGETTOOFAST, name,
812 cli_nexttarget(sptr) - CurrentTime);
813 }
814 return 1;
815 }
816 else {
817 cli_nexttarget(sptr) += TARGET_DELAY;
818 if (cli_nexttarget(sptr) < CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1)))
819 cli_nexttarget(sptr) = CurrentTime - (TARGET_DELAY * (MAXTARGETS - 1));
820 }
821 }
822 memmove(&targets[1], &targets[0], MAXTARGETS - 1);
823 targets[0] = hash;
824 return 0;
825 }
826
827 /** Allows a channel operator to avoid target change checks when
828 * sending messages to users on their channel.
829 * @param[in] source User sending the message.
830 * @param[in] nick Destination of the message.
831 * @param[in] channel Name of channel being sent to.
832 * @param[in] text Message to send.
833 * @param[in] is_notice If non-zero, use CNOTICE instead of CPRIVMSG.
834 */
835 /* Added 971023 by Run. */
836 int whisper(struct Client* source, const char* nick, const char* channel,
837 const char* text, int is_notice)
838 {
839 struct Client* dest;
840 struct Channel* chptr;
841 struct Membership* membership;
842
843 assert(0 != source);
844 assert(0 != nick);
845 assert(0 != channel);
846 assert(MyUser(source));
847
848 if (!(dest = FindUser(nick))) {
849 return send_reply(source, ERR_NOSUCHNICK, nick);
850 }
851 if (!(chptr = FindChannel(channel))) {
852 return send_reply(source, ERR_NOSUCHCHANNEL, channel);
853 }
854 /*
855 * compare both users channel lists, instead of the channels user list
856 * since the link is the same, this should be a little faster for channels
857 * with a lot of users
858 */
859 for (membership = cli_user(source)->channel; membership; membership = membership->next_channel) {
860 if (chptr == membership->channel)
861 break;
862 }
863 if (0 == membership) {
864 return send_reply(source, ERR_NOTONCHANNEL, chptr->chname);
865 }
866 if (!IsVoicedOrOpped(membership)) {
867 return send_reply(source, ERR_VOICENEEDED, chptr->chname);
868 }
869 /*
870 * lookup channel in destination
871 */
872 assert(0 != cli_user(dest));
873 for (membership = cli_user(dest)->channel; membership; membership = membership->next_channel) {
874 if (chptr == membership->channel)
875 break;
876 }
877 if (0 == membership || IsZombie(membership)) {
878 return send_reply(source, ERR_USERNOTINCHANNEL, cli_name(dest), chptr->chname);
879 }
880 if (is_silenced(source, dest))
881 return 0;
882
883 if (cli_user(dest)->away)
884 send_reply(source, RPL_AWAY, cli_name(dest), cli_user(dest)->away);
885 if (is_notice)
886 sendcmdto_one(source, CMD_NOTICE, dest, "%C :%s", dest, text);
887 else
888 sendcmdto_one(source, CMD_PRIVATE, dest, "%C :%s", dest, text);
889 return 0;
890 }
891
892
893 /** Send a user mode change for \a cptr to neighboring servers.
894 * @param[in] cptr User whose mode is changing.
895 * @param[in] sptr Client who sent us the mode change message.
896 * @param[in] old Prior set of user flags.
897 * @param[in] prop If non-zero, also include FLAG_OPER.
898 */
899 void send_umode_out(struct Client *cptr, struct Client *sptr,
900 struct Flags *old, int prop)
901 {
902 int i;
903 struct Client *acptr;
904
905 send_umode(NULL, sptr, old, prop ? SEND_UMODES : SEND_UMODES_BUT_OPER);
906
907 for (i = HighestFd; i >= 0; i--)
908 {
909 if ((acptr = LocalClientArray[i]) && IsServer(acptr) &&
910 (acptr != cptr) && (acptr != sptr) && *umodeBuf)
911 sendcmdto_one(sptr, CMD_MODE, acptr, "%s %s", cli_name(sptr), umodeBuf);
912 }
913 if (cptr && MyUser(cptr))
914 send_umode(cptr, sptr, old, ALL_UMODES);
915 }
916
917
918 /** Call \a fmt for each Client named in \a names.
919 * @param[in] sptr Client requesting information.
920 * @param[in] names Space-delimited list of nicknames.
921 * @param[in] rpl Base reply string for messages.
922 * @param[in] fmt Formatting callback function.
923 */
924 void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt)
925 {
926 char* name;
927 char* p = 0;
928 int arg_count = 0;
929 int users_found = 0;
930 struct Client* acptr;
931 struct MsgBuf* mb;
932
933 assert(0 != sptr);
934 assert(0 != names);
935 assert(0 != fmt);
936
937 mb = msgq_make(sptr, rpl_str(rpl), cli_name(&me), cli_name(sptr));
938
939 for (name = ircd_strtok(&p, names, " "); name; name = ircd_strtok(&p, 0, " ")) {
940 if ((acptr = FindUser(name))) {
941 if (users_found++)
942 msgq_append(0, mb, " ");
943 (*fmt)(acptr, sptr, mb);
944 }
945 if (5 == ++arg_count)
946 break;
947 }
948 send_buffer(sptr, mb, 0);
949 msgq_clean(mb);
950 }
951
952 /** Set \a flag on \a cptr and possibly hide the client's hostmask.
953 * @param[in,out] cptr User who is getting a new flag.
954 * @param[in] flag Some flag that affects host-hiding (FLAG_HIDDENHOST, FLAG_ACCOUNT).
955 * @return Zero.
956 */
957 int
958 hide_hostmask(struct Client *cptr, unsigned int flag)
959 {
960 struct Membership *chan;
961
962 switch (flag) {
963 case FLAG_HIDDENHOST:
964 /* Local users cannot set +x unless FEAT_HOST_HIDING is true. */
965 if (MyConnect(cptr) && !feature_bool(FEAT_HOST_HIDING))
966 return 0;
967 /* If the user is +h, we don't hide the hostmask. Set the flag to keep sync though */
968 if (HasSetHost(cptr)) {
969 SetFlag(cptr, flag);
970 return 0;
971 }
972 break;
973 case FLAG_ACCOUNT:
974 /* Invalidate all bans against the user so we check them again */
975 for (chan = (cli_user(cptr))->channel; chan;
976 chan = chan->next_channel)
977 ClearBanValid(chan);
978 break;
979 default:
980 return 0;
981 }
982
983 SetFlag(cptr, flag);
984 if (!HasFlag(cptr, FLAG_HIDDENHOST) || !HasFlag(cptr, FLAG_ACCOUNT))
985 return 0;
986
987 sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered");
988 ircd_snprintf(0, cli_user(cptr)->host, HOSTLEN, "%s.%s",
989 cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
990
991 /* ok, the client is now fully hidden, so let them know -- hikari */
992 if (MyConnect(cptr))
993 send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host);
994
995 /*
996 * Go through all channels the client was on, rejoin him
997 * and set the modes, if any
998 */
999 for (chan = cli_user(cptr)->channel; chan; chan = chan->next_channel)
1000 {
1001 if (IsZombie(chan))
1002 continue;
1003 /* Send a JOIN unless the user's join has been delayed. */
1004 if (!IsDelayedJoin(chan))
1005 sendcmdto_channel_butserv_butone(cptr, CMD_JOIN, chan->channel, cptr, 0,
1006 "%H", chan->channel);
1007 if (IsChanOp(chan) && HasVoice(chan))
1008 sendcmdto_channel_butserv_butone(&his, CMD_MODE, chan->channel, cptr, 0,
1009 "%H +ov %C %C", chan->channel, cptr,
1010 cptr);
1011 else if (IsChanOp(chan) || HasVoice(chan))
1012 sendcmdto_channel_butserv_butone(&his, CMD_MODE, chan->channel, cptr, 0,
1013 "%H +%c %C", chan->channel, IsChanOp(chan) ? 'o' : 'v', cptr);
1014 }
1015 return 0;
1016 }
1017
1018 /*
1019 * set_hostmask() - derived from hide_hostmask()
1020 *
1021 */
1022 int set_hostmask(struct Client *cptr, char *hostmask, char *password)
1023 {
1024 int restore = 0;
1025 int freeform = 0;
1026 char *host, *new_vhost, *vhost_pass;
1027 char hiddenhost[USERLEN + HOSTLEN + 2];
1028 struct Membership *chan;
1029
1030 Debug((DEBUG_INFO, "set_hostmask() %C, %s, %s", cptr, hostmask, password));
1031
1032 /* sethost enabled? */
1033 if (MyConnect(cptr) && !feature_bool(FEAT_SETHOST)) {
1034 send_reply(cptr, ERR_DISABLED, "SETHOST");
1035 return 0;
1036 }
1037
1038 /* sethost enabled for users? */
1039 if (MyConnect(cptr) && !IsAnOper(cptr) && !feature_bool(FEAT_SETHOST_USER)) {
1040 send_reply(cptr, ERR_NOPRIVILEGES);
1041 return 0;
1042 }
1043
1044 /* MODE_DEL: restore original hostmask */
1045 if (EmptyString(hostmask)) {
1046 /* is already sethost'ed? */
1047 if (IsSetHost(cptr)) {
1048 restore = 1;
1049 sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Host change");
1050 /* If they are +rx, we need to return to their +x host, not their "real" host */
1051 if (HasHiddenHost(cptr))
1052 ircd_snprintf(0, cli_user(cptr)->host, HOSTLEN, "%s.%s",
1053 cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
1054 else
1055 strncpy(cli_user(cptr)->host, cli_user(cptr)->realhost, HOSTLEN);
1056 strncpy(cli_user(cptr)->username, cli_user(cptr)->realusername, USERLEN);
1057 /* log it */
1058 if (MyConnect(cptr))
1059 log_write(LS_SETHOST, L_INFO, LOG_NOSNOTICE,
1060 "SETHOST (%s@%s) by (%#R): restoring real hostmask",
1061 cli_user(cptr)->username, cli_user(cptr)->host, cptr);
1062 } else
1063 return 0;
1064 /* MODE_ADD: set a new hostmask */
1065 } else {
1066 /* chop up ident and host.cc */
1067 if ((host = strrchr(hostmask, '@'))) /* oper can specifiy ident@host.cc */
1068 *host++ = '\0';
1069 else /* user can only specifiy host.cc [password] */
1070 host = hostmask;
1071 /*
1072 * Oper sethost
1073 */
1074 if (MyConnect(cptr)) {
1075 if (IsAnOper(cptr)) {
1076 if ((new_vhost = IsVhost(host, 1)) == NULL) {
1077 if (!feature_bool(FEAT_SETHOST_FREEFORM)) {
1078 send_reply(cptr, ERR_HOSTUNAVAIL, hostmask);
1079 log_write(LS_SETHOST, L_INFO, LOG_NOSNOTICE,
1080 "SETHOST (%s@%s) by (%#R): no such s-line",
1081 (host != hostmask) ? hostmask : cli_user(cptr)->username, host, cptr);
1082 return 0;
1083 } else /* freeform active, log and go */
1084 freeform = 1;
1085 }
1086 sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Host change");
1087 /* set the new ident and host */
1088 if (host != hostmask) /* oper only specified host.cc */
1089 strncpy(cli_user(cptr)->username, hostmask, USERLEN);
1090 strncpy(cli_user(cptr)->host, host, HOSTLEN);
1091 /* log it */
1092 log_write(LS_SETHOST, (freeform) ? L_NOTICE : L_INFO,
1093 (freeform) ? 0 : LOG_NOSNOTICE, "SETHOST (%s@%s) by (%#R)%s",
1094 cli_user(cptr)->username, cli_user(cptr)->host, cptr,
1095 (freeform) ? ": using freeform" : "");
1096 /*
1097 * plain user sethost, handled here
1098 */
1099 } else {
1100 /* empty password? */
1101 if (EmptyString(password)) {
1102 send_reply(cptr, ERR_NEEDMOREPARAMS, "MODE");
1103 return 0;
1104 }
1105 /* no such s-line */
1106 if ((new_vhost = IsVhost(host, 0)) == NULL) {
1107 send_reply(cptr, ERR_HOSTUNAVAIL, hostmask);
1108 log_write(LS_SETHOST, L_INFO, LOG_NOSNOTICE, "SETHOST (%s@%s %s) by (%#R): no such s-line",
1109 cli_user(cptr)->username, host, password, cptr);
1110 return 0;
1111 }
1112 /* no password */
1113 if ((vhost_pass = IsVhostPass(new_vhost)) == NULL) {
1114 send_reply(cptr, ERR_PASSWDMISMATCH);
1115 log_write(LS_SETHOST, L_INFO, 0, "SETHOST (%s@%s %s) by (%#R): trying to use an oper s-line",
1116 cli_user(cptr)->username, host, password, cptr);
1117 return 0;
1118 }
1119 /* incorrect password */
1120 if (strCasediff(vhost_pass, password)) {
1121 send_reply(cptr, ERR_PASSWDMISMATCH);
1122 log_write(LS_SETHOST, L_NOTICE, 0, "SETHOST (%s@%s %s) by (%#R): incorrect password",
1123 cli_user(cptr)->username, host, password, cptr);
1124 return 0;
1125 }
1126 sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Host change");
1127 /* set the new host */
1128 strncpy(cli_user(cptr)->host, new_vhost, HOSTLEN);
1129 /* log it */
1130 log_write(LS_SETHOST, L_INFO, LOG_NOSNOTICE, "SETHOST (%s@%s) by (%#R)",
1131 cli_user(cptr)->username, cli_user(cptr)->host, cptr);
1132 }
1133 } else { /* remote user */
1134 sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Host change");
1135 if (host != hostmask) /* oper only specified host.cc */
1136 strncpy(cli_user(cptr)->username, hostmask, USERLEN);
1137 strncpy(cli_user(cptr)->host, host, HOSTLEN);
1138 }
1139 }
1140
1141 if (restore)
1142 ClearSetHost(cptr);
1143 else
1144 SetSetHost(cptr);
1145
1146 if (MyConnect(cptr)) {
1147 ircd_snprintf(0, hiddenhost, HOSTLEN + USERLEN + 2, "%s@%s",
1148 cli_user(cptr)->username, cli_user(cptr)->host);
1149 send_reply(cptr, RPL_HOSTHIDDEN, hiddenhost);
1150 }
1151
1152 #if 0
1153 /* Code copied from hide_hostmask(). This is the old (pre-delayedjoin)
1154 * version. Switch this in if you're not using the delayed join patch. */
1155 /*
1156 * Go through all channels the client was on, rejoin him
1157 * and set the modes, if any
1158 */
1159 for (chan = cli_user(cptr)->channel; chan; chan = chan->next_channel) {
1160 if (IsZombie(chan))
1161 continue;
1162 sendcmdto_channel_butserv_butone(cptr, CMD_JOIN, chan->channel, cptr,
1163 "%H", chan->channel);
1164 if (IsChanOp(chan) && HasVoice(chan)) {
1165 sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr,
1166 "%H +ov %C %C", chan->channel, cptr, cptr);
1167 } else if (IsChanOp(chan) || HasVoice(chan)) {
1168 sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr,
1169 "%H +%c %C", chan->channel, IsChanOp(chan) ? 'o' : 'v', cptr);
1170 }
1171 }
1172 #endif
1173
1174 /*
1175 * Go through all channels the client was on, rejoin him
1176 * and set the modes, if any
1177 */
1178 for (chan = cli_user(cptr)->channel; chan; chan = chan->next_channel) {
1179 if (IsZombie(chan))
1180 continue;
1181 /* If this channel has delayed joins and the user has no modes, just set
1182 * the delayed join flag rather than showing the join, even if the user
1183 * was visible before */
1184 if (!IsChanOp(chan) && !HasVoice(chan)
1185 && (chan->channel->mode.mode & MODE_DELJOINS)) {
1186 SetDelayedJoin(chan);
1187 } else {
1188 sendcmdto_channel_butserv_butone(cptr, CMD_JOIN, chan->channel, cptr, 0,
1189 "%H", chan->channel);
1190 }
1191 if (IsChanOp(chan) && HasVoice(chan)) {
1192 sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr, 0,
1193 "%H +ov %C %C", chan->channel, cptr, cptr);
1194 } else if (IsChanOp(chan) || HasVoice(chan)) {
1195 sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan->channel, cptr, 0,
1196 "%H +%c %C", chan->channel, IsChanOp(chan) ? 'o' : 'v', cptr);
1197 }
1198 }
1199 return 1;
1200 }
1201
1202 /** Set a user's mode. This function checks that \a cptr is trying to
1203 * set his own mode, prevents local users from setting inappropriate
1204 * modes through this function, and applies any other side effects of
1205 * a successful mode change.
1206 *
1207 * @param[in,out] cptr User setting someone's mode.
1208 * @param[in] sptr Client who sent the mode change message.
1209 * @param[in] parc Number of parameters in \a parv.
1210 * @param[in] parv Parameters to MODE.
1211 * @return Zero.
1212 */
1213 int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
1214 {
1215 char** p;
1216 char* m;
1217 struct Client *acptr;
1218 int what;
1219 int i;
1220 struct Flags setflags;
1221 unsigned int tmpmask = 0;
1222 int snomask_given = 0;
1223 char buf[BUFSIZE];
1224 char *hostmask, *password;
1225 int prop = 0;
1226 int do_host_hiding = 0;
1227 int do_set_host = 0;
1228
1229 hostmask = password = NULL;
1230 what = MODE_ADD;
1231
1232 if (parc < 2)
1233 return need_more_params(sptr, "MODE");
1234
1235 if (!(acptr = FindUser(parv[1])))
1236 {
1237 if (MyConnect(sptr))
1238 send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
1239 return 0;
1240 }
1241
1242 if (IsServer(sptr) || sptr != acptr)
1243 {
1244 if (IsServer(cptr))
1245 sendwallto_group_butone(&me, WALL_WALLOPS, 0,
1246 "MODE for User %s from %s!%s", parv[1],
1247 cli_name(cptr), cli_name(sptr));
1248 else
1249 send_reply(sptr, ERR_USERSDONTMATCH);
1250 return 0;
1251 }
1252
1253 if (parc < 3)
1254 {
1255 m = buf;
1256 *m++ = '+';
1257 for (i = 0; i < USERMODELIST_SIZE; i++)
1258 {
1259 if (HasFlag(sptr, userModeList[i].flag) &&
1260 ((userModeList[i].flag != FLAG_ACCOUNT) &&
1261 (userModeList[i].flag != FLAG_SETHOST)))
1262 *m++ = userModeList[i].c;
1263 }
1264 *m = '\0';
1265 send_reply(sptr, RPL_UMODEIS, buf);
1266 if (HasFlag(sptr, FLAG_SERVNOTICE) && MyConnect(sptr)
1267 && cli_snomask(sptr) !=
1268 (unsigned int)(IsOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT))
1269 send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
1270 return 0;
1271 }
1272
1273 /*
1274 * find flags already set for user
1275 * why not just copy them?
1276 */
1277 setflags = cli_flags(sptr);
1278
1279 if (MyConnect(sptr))
1280 tmpmask = cli_snomask(sptr);
1281
1282 /*
1283 * parse mode change string(s)
1284 */
1285 for (p = &parv[2]; *p; p++) { /* p is changed in loop too */
1286 for (m = *p; *m; m++) {
1287 switch (*m) {
1288 case '+':
1289 what = MODE_ADD;
1290 break;
1291 case '-':
1292 what = MODE_DEL;
1293 break;
1294 case 's':
1295 if (*(p + 1) && is_snomask(*(p + 1))) {
1296 snomask_given = 1;
1297 tmpmask = umode_make_snomask(tmpmask, *++p, what);
1298 tmpmask &= (IsAnOper(sptr) ? SNO_ALL : SNO_USER);
1299 }
1300 else
1301 tmpmask = (what == MODE_ADD) ?
1302 (IsAnOper(sptr) ? SNO_OPERDEFAULT : SNO_DEFAULT) : 0;
1303 if (tmpmask)
1304 SetServNotice(sptr);
1305 else
1306 ClearServNotice(sptr);
1307 break;
1308 case 'w':
1309 if (what == MODE_ADD)
1310 SetWallops(sptr);
1311 else
1312 ClearWallops(sptr);
1313 break;
1314 case 'o':
1315 if (what == MODE_ADD)
1316 SetOper(sptr);
1317 else {
1318 ClrFlag(sptr, FLAG_OPER);
1319 ClrFlag(sptr, FLAG_LOCOP);
1320 if (MyConnect(sptr))
1321 {
1322 tmpmask = cli_snomask(sptr) & ~SNO_OPER;
1323 cli_handler(sptr) = CLIENT_HANDLER;
1324 }
1325 }
1326 break;
1327 case 'O':
1328 if (what == MODE_ADD)
1329 SetLocOp(sptr);
1330 else
1331 {
1332 ClrFlag(sptr, FLAG_OPER);
1333 ClrFlag(sptr, FLAG_LOCOP);
1334 if (MyConnect(sptr))
1335 {
1336 tmpmask = cli_snomask(sptr) & ~SNO_OPER;
1337 cli_handler(sptr) = CLIENT_HANDLER;
1338 }
1339 }
1340 break;
1341 case 'i':
1342 if (what == MODE_ADD)
1343 SetInvisible(sptr);
1344 else
1345 if (!feature_bool(FEAT_AUTOINVISIBLE) || IsOper(sptr)) /* Don't allow non-opers to -i if FEAT_AUTOINVISIBLE is set */
1346 ClearInvisible(sptr);
1347 break;
1348 case 'd':
1349 if (what == MODE_ADD)
1350 SetDeaf(sptr);
1351 else
1352 ClearDeaf(sptr);
1353 break;
1354 case 'k':
1355 if (what == MODE_ADD)
1356 SetChannelService(sptr);
1357 else
1358 ClearChannelService(sptr);
1359 break;
1360 case 'X':
1361 if (what == MODE_ADD)
1362 SetXtraOp(sptr);
1363 else
1364 ClearXtraOp(sptr);
1365 break;
1366 case 'n':
1367 if (what == MODE_ADD)
1368 SetNoChan(sptr);
1369 else
1370 ClearNoChan(sptr);
1371 break;
1372 case 'I':
1373 if (what == MODE_ADD)
1374 SetNoIdle(sptr);
1375 else
1376 ClearNoIdle(sptr);
1377 break;
1378 case 'g':
1379 if (what == MODE_ADD)
1380 SetDebug(sptr);
1381 else
1382 ClearDebug(sptr);
1383 break;
1384 case 'x':
1385 if (what == MODE_ADD)
1386 do_host_hiding = 1;
1387 break;
1388 case 'h':
1389 if (what == MODE_ADD) {
1390 if (*(p + 1) && is_hostmask(*(p + 1))) {
1391 do_set_host = 1;
1392 hostmask = *++p;
1393 /* DON'T step p onto the trailing NULL in the parameter array! - splidge */
1394 if (*(p+1))
1395 password = *++p;
1396 else
1397 password = NULL;
1398 } else {
1399 if (!*(p+1))
1400 send_reply(sptr, ERR_NEEDMOREPARAMS, "SETHOST");
1401 else {
1402 send_reply(sptr, ERR_BADHOSTMASK, *(p+1));
1403 p++; /* Swallow the arg anyway */
1404 }
1405 }
1406 } else { /* MODE_DEL */
1407 do_set_host = 1;
1408 hostmask = NULL;
1409 password = NULL;
1410 }
1411 break;
1412 case 'R':
1413 if (what == MODE_ADD)
1414 SetAccountOnly(sptr);
1415 else
1416 ClearAccountOnly(sptr);
1417 break;
1418 case 'P':
1419 if (what == MODE_ADD)
1420 SetParanoid(sptr);
1421 else
1422 ClearParanoid(sptr);
1423 break;
1424 default:
1425 send_reply(sptr, ERR_UMODEUNKNOWNFLAG, *m);
1426 break;
1427 }
1428 }
1429 }
1430 /*
1431 * Evaluate rules for new user mode
1432 * Stop users making themselves operators too easily:
1433 */
1434 if (!IsServer(cptr))
1435 {
1436 if (!FlagHas(&setflags, FLAG_OPER) && IsOper(sptr))
1437 ClearOper(sptr);
1438 if (!FlagHas(&setflags, FLAG_LOCOP) && IsLocOp(sptr))
1439 ClearLocOp(sptr);
1440 /*
1441 * new umode; servers can set it, local users cannot;
1442 * prevents users from /kick'ing or /mode -o'ing
1443 */
1444 if (!FlagHas(&setflags, FLAG_CHSERV) && !IsOper(sptr))
1445 ClearChannelService(sptr);
1446 if (!FlagHas(&setflags, FLAG_XTRAOP) && !IsOper(sptr))
1447 ClearXtraOp(sptr);
1448 if (!FlagHas(&setflags, FLAG_NOCHAN) && !(IsOper(sptr) || feature_bool(FEAT_USER_HIDECHANS)))
1449 ClearNoChan(sptr);
1450 if (!FlagHas(&setflags, FLAG_NOIDLE) && !IsOper(sptr))
1451 ClearNoIdle(sptr);
1452 if (!FlagHas(&setflags, FLAG_PARANOID) && !IsOper(sptr))
1453 ClearParanoid(sptr);
1454
1455 /*
1456 * only send wallops to opers
1457 */
1458 if (feature_bool(FEAT_WALLOPS_OPER_ONLY) && !IsAnOper(sptr) &&
1459 !FlagHas(&setflags, FLAG_WALLOP))
1460 ClearWallops(sptr);
1461 if (feature_bool(FEAT_HIS_SNOTICES_OPER_ONLY) && MyConnect(sptr) &&
1462 !IsAnOper(sptr) && !FlagHas(&setflags, FLAG_SERVNOTICE))
1463 {
1464 ClearServNotice(sptr);
1465 set_snomask(sptr, 0, SNO_SET);
1466 }
1467 if (feature_bool(FEAT_HIS_DEBUG_OPER_ONLY) &&
1468 !IsAnOper(sptr) && !FlagHas(&setflags, FLAG_DEBUG))
1469 ClearDebug(sptr);
1470 }
1471 if (MyConnect(sptr))
1472 {
1473 if ((FlagHas(&setflags, FLAG_OPER) || FlagHas(&setflags, FLAG_LOCOP)) &&
1474 !IsAnOper(sptr))
1475 det_confs_butmask(sptr, CONF_CLIENT & ~CONF_OPERATOR);
1476
1477 if (SendServNotice(sptr))
1478 {
1479 if (tmpmask != cli_snomask(sptr))
1480 set_snomask(sptr, tmpmask, SNO_SET);
1481 if (cli_snomask(sptr) && snomask_given)
1482 send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
1483 }
1484 else
1485 set_snomask(sptr, 0, SNO_SET);
1486 }
1487 /*
1488 * Compare new flags with old flags and send string which
1489 * will cause servers to update correctly.
1490 */
1491 if (!FlagHas(&setflags, FLAG_OPER) && IsOper(sptr))
1492 {
1493 /* user now oper */
1494 ++UserStats.opers;
1495 client_set_privs(sptr, NULL); /* may set propagate privilege */
1496 }
1497 /* remember propagate privilege setting */
1498 if (HasPriv(sptr, PRIV_PROPAGATE))
1499 prop = 1;
1500 if (FlagHas(&setflags, FLAG_OPER) && !IsOper(sptr))
1501 {
1502 /* user no longer oper */
1503 --UserStats.opers;
1504 client_set_privs(sptr, NULL); /* will clear propagate privilege */
1505 }
1506 if (FlagHas(&setflags, FLAG_INVISIBLE) && !IsInvisible(sptr))
1507 --UserStats.inv_clients;
1508 if (!FlagHas(&setflags, FLAG_INVISIBLE) && IsInvisible(sptr))
1509 ++UserStats.inv_clients;
1510 if (!FlagHas(&setflags, FLAG_HIDDENHOST) && do_host_hiding)
1511 hide_hostmask(sptr, FLAG_HIDDENHOST);
1512 if (do_set_host) {
1513 /* We clear the flag in the old mask, so that the +h will be sent */
1514 /* Only do this if we're SETTING +h and it succeeded */
1515 if (set_hostmask(sptr, hostmask, password) && hostmask)
1516 FlagClr(&setflags, FLAG_SETHOST);
1517 }
1518 send_umode_out(cptr, sptr, &setflags, prop);
1519
1520 return 0;
1521 }
1522
1523 /** Build a mode string to describe modes for \a cptr.
1524 * @param[in] cptr Some user.
1525 * @return Pointer to a static buffer.
1526 */
1527 char *umode_str(struct Client *cptr)
1528 {
1529 /* Maximum string size: "owidgrx\0" */
1530 char *m = umodeBuf;
1531 int i;
1532 struct Flags c_flags = cli_flags(cptr);
1533
1534 if (!HasPriv(cptr, PRIV_PROPAGATE))
1535 FlagClr(&c_flags, FLAG_OPER);
1536
1537 for (i = 0; i < USERMODELIST_SIZE; ++i)
1538 {
1539 if (FlagHas(&c_flags, userModeList[i].flag) &&
1540 userModeList[i].flag >= FLAG_GLOBAL_UMODES)
1541 *m++ = userModeList[i].c;
1542 }
1543
1544 if (IsAccount(cptr))
1545 {
1546 char* t = cli_user(cptr)->account;
1547
1548 *m++ = ' ';
1549 while ((*m++ = *t++))
1550 ; /* Empty loop */
1551
1552 if (cli_user(cptr)->acc_create) {
1553 char nbuf[20];
1554 Debug((DEBUG_DEBUG, "Sending timestamped account in user mode for "
1555 "account \"%s\"; timestamp %Tu", cli_user(cptr)->account,
1556 cli_user(cptr)->acc_create));
1557 ircd_snprintf(0, t = nbuf, sizeof(nbuf), ":%Tu",
1558 cli_user(cptr)->acc_create);
1559 m--; /* back up over previous nul-termination */
1560 while ((*m++ = *t++))
1561 ; /* Empty loop */
1562 }
1563 m--; /* Step back over the '\0' */
1564 }
1565
1566 if (IsSetHost(cptr)) {
1567 *m++ = ' ';
1568 ircd_snprintf(0, m, USERLEN + HOSTLEN + 2, "%s@%s", cli_user(cptr)->username,
1569 cli_user(cptr)->host);
1570 } else
1571 *m = '\0';
1572 return umodeBuf; /* Note: static buffer, gets
1573 overwritten by send_umode() */
1574 }
1575
1576 /** Send a mode change string for \a sptr to \a cptr.
1577 * @param[in] cptr Destination of mode change message.
1578 * @param[in] sptr User whose mode has changed.
1579 * @param[in] old Pre-change set of modes for \a sptr.
1580 * @param[in] sendset One of ALL_UMODES, SEND_UMODES_BUT_OPER,
1581 * SEND_UMODES, to select which changed user modes to send.
1582 */
1583 void send_umode(struct Client *cptr, struct Client *sptr, struct Flags *old,
1584 int sendset)
1585 {
1586 int i;
1587 int flag;
1588 int needhost = 0;
1589 char *m;
1590 int what = MODE_NULL;
1591
1592 /*
1593 * Build a string in umodeBuf to represent the change in the user's
1594 * mode between the new (cli_flags(sptr)) and 'old', but skipping
1595 * the modes indicated by sendset.
1596 */
1597 m = umodeBuf;
1598 *m = '\0';
1599 for (i = 0; i < USERMODELIST_SIZE; ++i)
1600 {
1601 flag = userModeList[i].flag;
1602 if (FlagHas(old, flag)
1603 == HasFlag(sptr, flag))
1604 continue;
1605 switch (sendset)
1606 {
1607 case ALL_UMODES:
1608 break;
1609 case SEND_UMODES_BUT_OPER:
1610 if (flag == FLAG_OPER)
1611 continue;
1612 /* and fall through */
1613 case SEND_UMODES:
1614 if (flag < FLAG_GLOBAL_UMODES)
1615 continue;
1616 break;
1617 }
1618 /* Special case for SETHOST.. */
1619 if (flag == FLAG_SETHOST) {
1620 /* Don't send to users */
1621 if (cptr && MyUser(cptr))
1622 continue;
1623
1624 /* If we're setting +h, add the parameter later */
1625 if (!FlagHas(old, flag))
1626 needhost++;
1627 }
1628 if (FlagHas(old, flag))
1629 {
1630 if (what == MODE_DEL)
1631 *m++ = userModeList[i].c;
1632 else
1633 {
1634 what = MODE_DEL;
1635 *m++ = '-';
1636 *m++ = userModeList[i].c;
1637 }
1638 }
1639 else /* !FlagHas(old, flag) */
1640 {
1641 if (what == MODE_ADD)
1642 *m++ = userModeList[i].c;
1643 else
1644 {
1645 what = MODE_ADD;
1646 *m++ = '+';
1647 *m++ = userModeList[i].c;
1648 }
1649 }
1650 }
1651 if (needhost) {
1652 *m++ = ' ';
1653 ircd_snprintf(0, m, USERLEN + HOSTLEN + 1, "%s@%s", cli_user(sptr)->username,
1654 cli_user(sptr)->host);
1655 } else
1656 *m = '\0';
1657 if (*umodeBuf && cptr)
1658 sendcmdto_one(sptr, CMD_MODE, cptr, "%s %s", cli_name(sptr), umodeBuf);
1659 }
1660
1661 /**
1662 * Check to see if this resembles a sno_mask. It is if 1) there is
1663 * at least one digit and 2) The first digit occurs before the first
1664 * alphabetic character.
1665 * @param[in] word Word to check for sno_mask-ness.
1666 * @return Non-zero if \a word looks like a server notice mask; zero if not.
1667 */
1668 int is_snomask(char *word)
1669 {
1670 if (word)
1671 {
1672 for (; *word; word++)
1673 if (IsDigit(*word))
1674 return 1;
1675 else if (IsAlpha(*word))
1676 return 0;
1677 }
1678 return 0;
1679 }
1680
1681 /*
1682 * Check to see if it resembles a valid hostmask.
1683 */
1684 int is_hostmask(char *word)
1685 {
1686 int i = 0;
1687 char *host;
1688
1689 Debug((DEBUG_INFO, "is_hostmask() %s", word));
1690
1691 if (strlen(word) > (HOSTLEN + USERLEN + 1) || strlen(word) <= 0)
1692 return 0;
1693
1694 /* if a host is specified, make sure it's valid */
1695 host = strrchr(word, '@');
1696 if (host) {
1697 if (strlen(++host) < 1)
1698 return 0;
1699 if (strlen(host) > HOSTLEN)
1700 return 0;
1701 }
1702
1703 if (word) {
1704 if ('@' == *word) /* no leading @'s */
1705 return 0;
1706
1707 if ('#' == *word) { /* numeric index given? */
1708 for (word++; *word; word++) {
1709 if (!IsDigit(*word))
1710 return 0;
1711 }
1712 return 1;
1713 }
1714
1715 /* normal hostmask, account for at most one '@' */
1716 for (; *word; word++) {
1717 if ('@' == *word) {
1718 i++;
1719 continue;
1720 }
1721 if (!IsHostChar(*word))
1722 return 0;
1723 }
1724 return (1 < i) ? 0 : 1; /* no more than on '@' */
1725 }
1726 return 0;
1727 }
1728
1729 /*
1730 * IsVhost() - Check if given host is a valid spoofhost
1731 * (ie: configured thru a S:line)
1732 */
1733 static char *IsVhost(char *hostmask, int oper)
1734 {
1735 unsigned int i = 0, y = 0;
1736 struct sline *sconf;
1737
1738 Debug((DEBUG_INFO, "IsVhost() %s", hostmask));
1739
1740 if (EmptyString(hostmask))
1741 return NULL;
1742
1743 /* spoofhost specified as index, ie: #27 */
1744 if ('#' == hostmask[0]) {
1745 y = atoi(hostmask + 1);
1746 for (i = 0, sconf = GlobalSList; sconf; sconf = sconf->next) {
1747 if (!oper && EmptyString(sconf->passwd))
1748 continue;
1749 if (y == ++i)
1750 return sconf->spoofhost;
1751 }
1752 return NULL;
1753 }
1754
1755 /* spoofhost specified as host, ie: host.cc */
1756 for (sconf = GlobalSList; sconf; sconf = sconf->next)
1757 if (strCasediff(hostmask, sconf->spoofhost) == 0)
1758 return sconf->spoofhost;
1759
1760 return NULL;
1761 }
1762
1763 /*
1764 * IsVhostPass() - Check if given spoofhost has a password
1765 * associated with it, and if, return the password (cleartext)
1766 */
1767 static char *IsVhostPass(char *hostmask)
1768 {
1769 struct sline *sconf;
1770
1771 Debug((DEBUG_INFO, "IsVhostPass() %s", hostmask));
1772
1773 if (EmptyString(hostmask))
1774 return NULL;
1775
1776 for (sconf = GlobalSList; sconf; sconf = sconf->next)
1777 if (strCasediff(hostmask, sconf->spoofhost) == 0) {
1778 Debug((DEBUG_INFO, "sconf->passwd %s", sconf->passwd));
1779 return EmptyString(sconf->passwd) ? NULL : sconf->passwd;
1780 }
1781
1782 return NULL;
1783 }
1784
1785 /** Update snomask \a oldmask according to \a arg and \a what.
1786 * @param[in] oldmask Original user mask.
1787 * @param[in] arg Update string (either a number or '+'/'-' followed by a number).
1788 * @param[in] what MODE_ADD if adding the mask.
1789 * @return New value of service notice mask.
1790 */
1791 unsigned int umode_make_snomask(unsigned int oldmask, char *arg, int what)
1792 {
1793 unsigned int sno_what;
1794 unsigned int newmask;
1795 if (*arg == '+')
1796 {
1797 arg++;
1798 if (what == MODE_ADD)
1799 sno_what = SNO_ADD;
1800 else
1801 sno_what = SNO_DEL;
1802 }
1803 else if (*arg == '-')
1804 {
1805 arg++;
1806 if (what == MODE_ADD)
1807 sno_what = SNO_DEL;
1808 else
1809 sno_what = SNO_ADD;
1810 }
1811 else
1812 sno_what = (what == MODE_ADD) ? SNO_SET : SNO_DEL;
1813 /* pity we don't have strtoul everywhere */
1814 newmask = (unsigned int)atoi(arg);
1815 if (sno_what == SNO_DEL)
1816 newmask = oldmask & ~newmask;
1817 else if (sno_what == SNO_ADD)
1818 newmask |= oldmask;
1819 return newmask;
1820 }
1821
1822 /** Remove \a cptr from the singly linked list \a list.
1823 * @param[in] cptr Client to remove from list.
1824 * @param[in,out] list Pointer to head of list containing \a cptr.
1825 */
1826 static void delfrom_list(struct Client *cptr, struct SLink **list)
1827 {
1828 struct SLink* tmp;
1829 struct SLink* prv = NULL;
1830
1831 for (tmp = *list; tmp; tmp = tmp->next) {
1832 if (tmp->value.cptr == cptr) {
1833 if (prv)
1834 prv->next = tmp->next;
1835 else
1836 *list = tmp->next;
1837 free_link(tmp);
1838 break;
1839 }
1840 prv = tmp;
1841 }
1842 }
1843
1844 /** Set \a cptr's server notice mask, according to \a what.
1845 * @param[in,out] cptr Client whose snomask is updating.
1846 * @param[in] newmask Base value for new snomask.
1847 * @param[in] what One of SNO_ADD, SNO_DEL, SNO_SET, to choose operation.
1848 */
1849 void set_snomask(struct Client *cptr, unsigned int newmask, int what)
1850 {
1851 unsigned int oldmask, diffmask; /* unsigned please */
1852 int i;
1853 struct SLink *tmp;
1854
1855 oldmask = cli_snomask(cptr);
1856
1857 if (what == SNO_ADD)
1858 newmask |= oldmask;
1859 else if (what == SNO_DEL)
1860 newmask = oldmask & ~newmask;
1861 else if (what != SNO_SET) /* absolute set, no math needed */
1862 sendto_opmask_butone(0, SNO_OLDSNO, "setsnomask called with %d ?!", what);
1863
1864 newmask &= (IsAnOper(cptr) ? SNO_ALL : SNO_USER);
1865
1866 diffmask = oldmask ^ newmask;
1867
1868 for (i = 0; diffmask >> i; i++) {
1869 if (((diffmask >> i) & 1))
1870 {
1871 if (((newmask >> i) & 1))
1872 {
1873 tmp = make_link();
1874 tmp->next = opsarray[i];
1875 tmp->value.cptr = cptr;
1876 opsarray[i] = tmp;
1877 }
1878 else
1879 /* not real portable :( */
1880 delfrom_list(cptr, &opsarray[i]);
1881 }
1882 }
1883 cli_snomask(cptr) = newmask;
1884 }
1885
1886 /** Check whether \a sptr is allowed to send a message to \a acptr.
1887 * If \a sptr is a remote user, it means some server has an outdated
1888 * SILENCE list for \a acptr, so send the missing SILENCE mask(s) back
1889 * in the direction of \a sptr. Skip the check if \a sptr is a server.
1890 * @param[in] sptr Client trying to send a message.
1891 * @param[in] acptr Destination of message.
1892 * @return Non-zero if \a sptr is SILENCEd by \a acptr, zero if not.
1893 */
1894 int is_silenced(struct Client *sptr, struct Client *acptr)
1895 {
1896 struct Ban *found;
1897 struct User *user;
1898 size_t buf_used, slen;
1899 char buf[BUFSIZE];
1900
1901 if (IsServer(sptr) || !(user = cli_user(acptr))
1902 || !(found = find_ban(sptr, user->silence)))
1903 return 0;
1904 assert(!(found->flags & BAN_EXCEPTION));
1905 if (!MyConnect(sptr)) {
1906 /* Buffer positive silence to send back. */
1907 buf_used = strlen(found->banstr);
1908 memcpy(buf, found->banstr, buf_used);
1909 /* Add exceptions to buffer. */
1910 for (found = user->silence; found; found = found->next) {
1911 if (!(found->flags & BAN_EXCEPTION))
1912 continue;
1913 slen = strlen(found->banstr);
1914 if (buf_used + slen + 4 > 400) {
1915 buf[buf_used] = '\0';
1916 sendcmdto_one(acptr, CMD_SILENCE, cli_from(sptr), "%C %s", sptr, buf);
1917 buf_used = 0;
1918 }
1919 if (buf_used)
1920 buf[buf_used++] = ',';
1921 buf[buf_used++] = '+';
1922 buf[buf_used++] = '~';
1923 memcpy(buf + buf_used, found->banstr, slen);
1924 buf_used += slen;
1925 }
1926 /* Flush silence buffer. */
1927 if (buf_used) {
1928 buf[buf_used] = '\0';
1929 sendcmdto_one(acptr, CMD_SILENCE, cli_from(sptr), "%C %s", sptr, buf);
1930 buf_used = 0;
1931 }
1932 }
1933 return 1;
1934 }
1935
1936 /** Send RPL_ISUPPORT lines to \a cptr.
1937 * @param[in] cptr Client to send ISUPPORT to.
1938 * @return Zero.
1939 */
1940 int
1941 send_supported(struct Client *cptr)
1942 {
1943 char featurebuf[512];
1944
1945 ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES1, FEATURESVALUES1);
1946 send_reply(cptr, RPL_ISUPPORT, featurebuf);
1947 ircd_snprintf(0, featurebuf, sizeof(featurebuf), FEATURES2, FEATURESVALUES2);
1948 send_reply(cptr, RPL_ISUPPORT, featurebuf);
1949
1950 return 0; /* convenience return, if it's ever needed */
1951 }