2 * ircd-ratbox: A slightly useful ircd.
3 * s_user.c: User related functions.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
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 2 of the License, or
12 * (at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: s_user.c 3161 2007-01-25 07:23:01Z nenolod $
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
43 #include "s_newconf.h"
49 #include "supported.h"
58 #include "blacklist.h"
59 #include "substitution.h"
61 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
62 void user_welcome(struct Client
*source_p
);
68 int user_modes
[256] = {
69 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
70 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
71 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
72 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
90 UMODE_NOFORWARD
, /* Q */
91 UMODE_REGONLYMSG
, /* R */
92 UMODE_SERVICE
, /* S */
100 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
107 UMODE_CALLERID
, /* g */
109 UMODE_INVISIBLE
, /* i */
112 UMODE_LOCOPS
, /* l */
119 UMODE_SERVNOTICE
, /* s */
123 UMODE_WALLOP
, /* w */
126 UMODE_OPERWALL
, /* z */
127 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
128 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
129 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
130 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
131 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
132 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
133 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
134 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
135 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
142 * inputs - pointer to client
144 * side effects - display to client user counts etc.
147 show_lusers(struct Client
*source_p
)
149 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
150 (Count
.total
- Count
.invisi
),
151 Count
.invisi
, dlink_list_length(&global_serv_list
));
153 if(dlink_list_length(&oper_list
) > 0)
154 sendto_one_numeric(source_p
, RPL_LUSEROP
,
155 form_str(RPL_LUSEROP
), dlink_list_length(&oper_list
));
157 if(dlink_list_length(&unknown_list
) > 0)
158 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
159 form_str(RPL_LUSERUNKNOWN
),
160 dlink_list_length(&unknown_list
));
162 if(dlink_list_length(&global_channel_list
) > 0)
163 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
164 form_str(RPL_LUSERCHANNELS
),
165 dlink_list_length(&global_channel_list
));
167 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
168 dlink_list_length(&lclient_list
),
169 dlink_list_length(&serv_list
));
171 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
172 form_str(RPL_LOCALUSERS
),
173 dlink_list_length(&lclient_list
),
175 dlink_list_length(&lclient_list
),
178 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
179 Count
.total
, Count
.max_tot
,
180 Count
.total
, Count
.max_tot
);
182 sendto_one_numeric(source_p
, RPL_STATSCONN
,
183 form_str(RPL_STATSCONN
),
184 MaxConnectionCount
, MaxClientCount
,
185 Count
.totalrestartcount
);
187 if(dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
188 MaxClientCount
= dlink_list_length(&lclient_list
);
190 if((dlink_list_length(&lclient_list
) + dlink_list_length(&serv_list
)) >
191 (unsigned long)MaxConnectionCount
)
192 MaxConnectionCount
= dlink_list_length(&lclient_list
) +
193 dlink_list_length(&serv_list
);
199 ** register_local_user
200 ** This function is called when both NICK and USER messages
201 ** have been accepted for the client, in whatever order. Only
202 ** after this, is the USER message propagated.
204 ** NICK's must be propagated at once when received, although
205 ** it would be better to delay them too until full info is
206 ** available. Doing it is not so simple though, would have
207 ** to implement the following:
209 ** (actually it has been implemented already for a while) -orabidoo
211 ** 1) user telnets in and gives only "NICK foobar" and waits
212 ** 2) another user far away logs in normally with the nick
213 ** "foobar" (quite legal, as this server didn't propagate
215 ** 3) now this server gets nick "foobar" from outside, but
216 ** has alread the same defined locally. Current server
217 ** would just issue "KILL foobar" to clean out dups. But,
218 ** this is not fair. It should actually request another
219 ** nick from local user or kill him/her...
223 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
225 struct ConfItem
*aconf
;
226 struct User
*user
= source_p
->user
;
227 char tmpstr2
[IRCD_BUFSIZE
];
228 char ipaddr
[HOSTIPLEN
];
229 char myusername
[USERLEN
+1];
232 s_assert(NULL
!= source_p
);
233 s_assert(MyConnect(source_p
));
234 s_assert(source_p
->username
!= username
);
239 if(IsAnyDead(source_p
))
242 if(ConfigFileEntry
.ping_cookie
)
244 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
246 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
247 sendto_one(source_p
, "PING :%08lX",
248 (unsigned long) source_p
->localClient
->random_ping
);
249 source_p
->flags
|= FLAGS_PINGSENT
;
252 if(!(source_p
->flags2
& FLAGS2_PING_COOKIE
))
258 /* hasnt finished client cap negotiation */
259 if(source_p
->flags2
& FLAGS2_CLICAP
)
262 /* still has DNSbls to validate against */
263 if(dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
266 client_p
->localClient
->last
= CurrentTime
;
267 /* Straight up the maximum rate of flooding... */
268 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
270 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
271 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
278 while(*p
&& i
< USERLEN
)
281 myusername
[i
++] = *p
;
285 myusername
[i
] = '\0';
286 username
= myusername
;
289 if((status
= check_client(client_p
, source_p
, username
)) < 0)
290 return (CLIENT_EXITED
);
292 /* Apply nick override */
293 if(*source_p
->preClient
->spoofnick
)
295 del_from_client_hash(source_p
->name
, source_p
);
296 strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
297 add_to_client_hash(source_p
->name
, source_p
);
298 comm_note(source_p
->localClient
->fd
, "Nick: %s", source_p
->name
);
301 if(!valid_hostname(source_p
->host
))
303 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
305 strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
308 if(ConfigFileEntry
.dot_in_ip6_addr
== 1)
309 strlcat(source_p
->host
, ".", sizeof(source_p
->host
));
314 aconf
= source_p
->localClient
->att_conf
;
318 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
319 return (CLIENT_EXITED
);
322 if(!IsGotId(source_p
))
327 if(IsNeedIdentd(aconf
))
329 ServerStats
->is_ref
++;
330 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
331 exit_client(client_p
, source_p
, &me
, "Install identd");
332 return (CLIENT_EXITED
);
335 /* dont replace username if its supposed to be spoofed --fl */
336 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
340 if(!IsNoTilde(aconf
))
341 source_p
->username
[i
++] = '~';
343 while (*p
&& i
< USERLEN
)
346 source_p
->username
[i
++] = *p
;
350 source_p
->username
[i
] = '\0';
354 if(IsNeedSasl(aconf
) && !*user
->suser
)
356 ServerStats
->is_ref
++;
357 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
358 exit_client(client_p
, source_p
, &me
, "SASL access only");
359 return (CLIENT_EXITED
);
363 if(!EmptyString(aconf
->passwd
))
367 if(EmptyString(source_p
->localClient
->passwd
))
369 else if(IsConfEncrypted(aconf
))
370 encr
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
372 encr
= source_p
->localClient
->passwd
;
374 if(strcmp(encr
, aconf
->passwd
))
376 ServerStats
->is_ref
++;
377 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
378 exit_client(client_p
, source_p
, &me
, "Bad Password");
379 return (CLIENT_EXITED
);
382 /* clear password only if used now, otherwise send it
383 * to services -- jilles */
384 if(source_p
->localClient
->passwd
)
386 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
387 MyFree(source_p
->localClient
->passwd
);
388 source_p
->localClient
->passwd
= NULL
;
392 /* report if user has &^>= etc. and set flags as needed in source_p */
393 report_and_set_user_flags(source_p
, aconf
);
397 * We want to be able to have servers and F-line clients
398 * connect, so save room for "buffer" connections.
399 * Smaller servers may want to decrease this, and it should
400 * probably be just a percentage of the MAXCLIENTS...
403 /* Except "F:" clients */
404 if(((dlink_list_length(&lclient_list
) + 1) >=
405 ((unsigned long)GlobalSetOptions
.maxclients
+ MAX_BUFFER
) ||
406 (dlink_list_length(&lclient_list
) + 1) >=
407 ((unsigned long)GlobalSetOptions
.maxclients
- 5)) && !(IsExemptLimits(source_p
)))
409 sendto_realops_snomask(SNO_FULL
, L_ALL
,
410 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
412 ServerStats
->is_ref
++;
413 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
414 return (CLIENT_EXITED
);
417 /* valid user name check */
419 if(!valid_username(source_p
->username
))
421 sendto_realops_snomask(SNO_REJ
, L_ALL
,
422 "Invalid username: %s (%s@%s)",
423 source_p
->name
, source_p
->username
, source_p
->host
);
424 ServerStats
->is_ref
++;
425 ircsprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
426 exit_client(client_p
, source_p
, &me
, tmpstr2
);
427 return (CLIENT_EXITED
);
430 /* end of valid user name check */
432 /* kline exemption extends to xline too */
433 if(!IsExemptKline(source_p
) &&
434 find_xline(source_p
->info
, 1) != NULL
)
436 ServerStats
->is_ref
++;
437 add_reject(source_p
);
438 exit_client(client_p
, source_p
, &me
, "Bad user info");
439 return CLIENT_EXITED
;
443 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
445 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
446 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
447 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
452 substitution_append_var(&varlist
, "nick", source_p
->name
);
453 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
454 substitution_append_var(&varlist
, "host", source_p
->host
);
455 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
456 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
458 ServerStats
->is_ref
++;
460 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
461 me
.name
, source_p
->name
,
462 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
464 substitution_free(&varlist
);
466 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
467 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
468 source_p
->preClient
->dnsbl_listed
->hits
++;
469 add_reject(source_p
);
470 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
471 return CLIENT_EXITED
;
475 /* Store original hostname -- jilles */
476 strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
478 /* Spoof user@host */
479 if(*source_p
->preClient
->spoofuser
)
480 strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
481 if(*source_p
->preClient
->spoofhost
)
483 strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
484 if (irccmp(source_p
->host
, source_p
->orighost
))
485 SetDynSpoof(source_p
);
488 if(IsAnyDead(client_p
))
489 return CLIENT_EXITED
;
491 inetntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
493 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
494 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
495 source_p
->name
, source_p
->username
, source_p
->orighost
,
496 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
497 get_client_class(source_p
), source_p
->info
);
499 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
500 "CLICONN %s %s %s %s %s %s 0 %s",
501 source_p
->name
, source_p
->username
, source_p
->orighost
,
502 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
503 get_client_class(source_p
),
504 /* mirc can sometimes send ips here */
505 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
508 /* If they have died in send_* don't do anything. */
509 if(IsAnyDead(source_p
))
510 return CLIENT_EXITED
;
512 add_to_hostname_hash(source_p
->orighost
, source_p
);
514 /* Allocate a UID if it was not previously allocated.
515 * If this already occured, it was probably during SASL auth...
519 strcpy(source_p
->id
, generate_uid());
520 add_to_id_hash(source_p
->id
, source_p
);
523 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
;
525 if (source_p
->umodes
& UMODE_INVISIBLE
)
528 s_assert(!IsClient(source_p
));
529 dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
532 /* XXX source_p->servptr is &me, since local client */
533 source_p
->servptr
= find_server(NULL
, user
->server
);
534 dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
535 /* Increment our total user count here */
536 if(++Count
.total
> Count
.max_tot
)
537 Count
.max_tot
= Count
.total
;
538 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
540 Count
.totalrestartcount
++;
542 s_assert(source_p
->localClient
!= NULL
);
544 if(dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
546 Count
.max_loc
= dlink_list_length(&lclient_list
);
547 if(!(Count
.max_loc
% 10))
548 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
549 "New Max Local Clients: %d", Count
.max_loc
);
552 /* they get a reduced limit */
553 if(find_tgchange(source_p
->sockhost
))
554 USED_TARGETS(source_p
) = 6;
556 call_hook(h_new_local_user
, source_p
);
558 monitor_signon(source_p
);
559 user_welcome(source_p
);
561 free_pre_client(source_p
);
563 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
571 * side effects - This common function introduces a client to the rest
572 * of the net, either from a local client connect or
573 * from a remote connect.
576 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
578 static char ubuf
[12];
579 struct Client
*identifyservice_p
;
581 hook_data_umode_changed hdata
;
582 hook_data_client hdata2
;
584 if(MyClient(source_p
))
585 send_umode(source_p
, source_p
, 0, 0, ubuf
);
587 send_umode(NULL
, source_p
, 0, 0, ubuf
);
595 /* if it has an ID, introduce it with its id to TS6 servers,
596 * otherwise introduce it normally to all.
600 char sockhost
[HOSTLEN
];
601 if(source_p
->sockhost
[0] == ':')
605 strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
607 strcpy(sockhost
, source_p
->sockhost
);
610 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
611 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
612 source_p
->servptr
->id
, nick
,
613 source_p
->hopcount
+ 1,
614 (long) source_p
->tsinfo
, ubuf
,
615 source_p
->username
, source_p
->host
,
616 IsIPSpoof(source_p
) ? "0" : sockhost
,
618 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
619 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
622 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
623 ":%s UID %s %d %ld %s %s %s %s %s :%s",
624 source_p
->servptr
->id
, nick
,
625 source_p
->hopcount
+ 1,
626 (long) source_p
->tsinfo
, ubuf
,
627 source_p
->username
, source_p
->host
,
628 IsIPSpoof(source_p
) ? "0" : sockhost
,
629 source_p
->id
, source_p
->info
);
631 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
,
632 "NICK %s %d %ld %s %s %s %s :%s",
633 nick
, source_p
->hopcount
+ 1,
634 (long) source_p
->tsinfo
,
635 ubuf
, source_p
->username
, source_p
->host
,
636 user
->server
, source_p
->info
);
639 sendto_server(client_p
, NULL
, NOCAPS
, NOCAPS
,
640 "NICK %s %d %ld %s %s %s %s :%s",
641 nick
, source_p
->hopcount
+ 1,
642 (long) source_p
->tsinfo
,
643 ubuf
, source_p
->username
, source_p
->host
,
644 user
->server
, source_p
->info
);
646 if (IsDynSpoof(source_p
))
648 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
649 use_id(source_p
), source_p
->orighost
);
650 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * REALHOST %s",
651 source_p
->name
, source_p
->orighost
);
653 if (!EmptyString(source_p
->user
->suser
))
655 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
656 use_id(source_p
), source_p
->user
->suser
);
657 sendto_server(client_p
, NULL
, NOCAPS
, CAP_TS6
, ":%s ENCAP * LOGIN %s",
658 source_p
->name
, source_p
->user
->suser
);
661 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
663 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
664 ConfigFileEntry
.identifycommand
[0] != '\0')
666 /* use user@server */
667 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
669 identifyservice_p
= find_named_client(p
+ 1);
671 identifyservice_p
= NULL
;
672 if (identifyservice_p
!= NULL
)
673 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
674 get_id(source_p
, identifyservice_p
),
675 ConfigFileEntry
.identifyservice
,
676 ConfigFileEntry
.identifycommand
,
677 source_p
->localClient
->passwd
);
679 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
680 MyFree(source_p
->localClient
->passwd
);
681 source_p
->localClient
->passwd
= NULL
;
684 /* let modules providing usermodes know that we've got a new user,
685 * why is this here? -- well, some modules need to be able to send out new
686 * information about a client, so this was the best place to do it
689 hdata
.client
= source_p
;
691 hdata
.oldsnomask
= 0;
692 call_hook(h_umode_changed
, &hdata
);
694 /* On the other hand, some modules need to know when a client is
695 * being introduced, period.
698 hdata2
.client
= client_p
;
699 hdata2
.target
= source_p
;
700 call_hook(h_introduce_client
, &hdata2
);
706 * valid_hostname - check hostname for validity
708 * Inputs - pointer to user
709 * Output - YES if valid, NO if not
710 * Side effects - NONE
712 * NOTE: this doesn't allow a hostname to begin with a dot and
713 * will not allow more dots than chars.
716 valid_hostname(const char *hostname
)
718 const char *p
= hostname
;
726 if('.' == *p
|| ':' == *p
)
733 if(*p
== '.' || *p
== ':')
745 * valid_username - check username for validity
747 * Inputs - pointer to user
748 * Output - YES if valid, NO if not
749 * Side effects - NONE
751 * Absolutely always reject any '*' '!' '?' '@' in an user name
752 * reject any odd control characters names.
753 * Allow '.' in username to allow for "first.last"
757 valid_username(const char *username
)
760 const char *p
= username
;
770 /* reject usernames that don't start with an alphanum
771 * i.e. reject jokers who have '-@somehost' or '.@somehost'
772 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
779 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
782 if(dots
> ConfigFileEntry
.dots_in_ident
)
784 if(!IsUserChar(p
[1]))
787 else if(!IsUserChar(*p
))
793 /* report_and_set_user_flags
795 * Inputs - pointer to source_p
796 * - pointer to aconf for this user
799 * Report to user any special flags they are getting, and set them.
803 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
805 /* If this user is being spoofed, tell them so */
806 if(IsConfDoSpoofIp(aconf
))
808 sendto_one_notice(source_p
, ":*** Spoofing your IP. congrats.");
811 /* If this user is in the exception class, Set it "E lined" */
812 if(IsConfExemptKline(aconf
))
814 SetExemptKline(source_p
);
815 sendto_one_notice(source_p
, ":*** You are exempt from K/D/G/X lines. congrats.");
818 if(IsConfExemptGline(aconf
))
820 SetExemptGline(source_p
);
822 /* dont send both a kline and gline exempt notice */
823 if(!IsConfExemptKline(aconf
))
824 sendto_one_notice(source_p
, ":*** You are exempt from G lines.");
827 if(IsConfExemptDNSBL(aconf
))
828 /* kline exempt implies this, don't send both */
829 if(!IsConfExemptKline(aconf
))
830 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists.");
832 /* If this user is exempt from user limits set it F lined" */
833 if(IsConfExemptLimits(aconf
))
835 SetExemptLimits(source_p
);
836 sendto_one_notice(source_p
, "*** You are exempt from user limits. congrats.");
839 /* If this user is exempt from idle time outs */
840 if(IsConfIdlelined(aconf
))
842 SetIdlelined(source_p
);
843 sendto_one_notice(source_p
, ":*** You are exempt from idle limits. congrats.");
846 if(IsConfExemptFlood(aconf
))
848 SetExemptFlood(source_p
);
849 sendto_one_notice(source_p
, ":*** You are exempt from flood limits.");
852 if(IsConfExemptSpambot(aconf
))
854 SetExemptSpambot(source_p
);
855 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks.");
858 if(IsConfExemptJupe(aconf
))
860 SetExemptJupe(source_p
);
861 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings.");
864 if(IsConfExemptResv(aconf
))
866 SetExemptResv(source_p
);
867 sendto_one_notice(source_p
, ":*** You are exempt from resvs.");
870 if(IsConfExemptShide(aconf
))
872 SetExemptShide(source_p
);
873 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding.");
878 * user_mode - set get current users mode
880 * m_umode() added 15/10/91 By Darren Reed.
882 * parv[1] - username to change mode for
883 * parv[2] - modes to change
886 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
892 struct Client
*target_p
;
894 int badflag
= NO
; /* Only send one bad flag notice */
895 int showsnomask
= NO
;
896 unsigned int setsnomask
;
898 hook_data_umode_changed hdata
;
904 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
908 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
910 if(MyConnect(source_p
))
911 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
912 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
916 /* Dont know why these were commented out..
917 * put them back using new sendto() funcs
920 if(IsServer(source_p
))
922 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
923 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
927 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
929 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
938 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
939 if (source_p
->umodes
& user_modes
[i
])
943 sendto_one(source_p
, form_str(RPL_UMODEIS
), me
.name
, source_p
->name
, buf
);
944 if (source_p
->snomask
!= 0)
945 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
946 construct_snobuf(source_p
->snomask
));
950 /* find flags already set for user */
951 setflags
= source_p
->umodes
;
952 setsnomask
= source_p
->snomask
;
955 * parse mode change string(s)
957 for (pm
= parv
[2]; *pm
; pm
++)
970 if(IsServer(client_p
) && !IsOper(source_p
))
974 dlinkAddAlloc(source_p
, &oper_list
);
979 /* Only decrement the oper counts if an oper to begin with
980 * found by Pat Szuta, Perly , perly@xnet.com
983 if(!IsOper(source_p
))
990 if(MyConnect(source_p
))
992 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
993 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
995 source_p
->snomask
= 0;
998 source_p
->flags2
&= ~OPER_FLAGS
;
1000 MyFree(source_p
->localClient
->opername
);
1001 source_p
->localClient
->opername
= NULL
;
1003 dlinkFindDestroy(source_p
, &local_oper_list
);
1006 dlinkFindDestroy(source_p
, &oper_list
);
1010 /* we may not get these,
1011 * but they shouldnt be in default
1014 /* can only be set on burst */
1023 if (MyConnect(source_p
))
1025 if(!IsOper(source_p
)
1026 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1028 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1033 if(what
== MODE_ADD
)
1036 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1038 source_p
->snomask
|= SNO_GENERAL
;
1041 source_p
->snomask
= 0;
1042 if (source_p
->snomask
!= 0)
1043 source_p
->umodes
|= UMODE_SERVNOTICE
;
1045 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1050 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1055 if((flag
= user_modes
[(unsigned char) *pm
]))
1057 if(MyConnect(source_p
)
1058 && !IsOper(source_p
)
1059 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1061 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1066 if(what
== MODE_ADD
)
1067 source_p
->umodes
|= flag
;
1069 source_p
->umodes
&= ~flag
;
1074 if(MyConnect(source_p
))
1081 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1083 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1085 sendto_one_notice(source_p
, ":*** You need oper and N flag for +s +n");
1086 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1089 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1091 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1092 source_p
->umodes
&= ~UMODE_OPERWALL
;
1095 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1096 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1098 sendto_one_notice(source_p
, ":*** You need oper and A flag for +a");
1099 source_p
->umodes
&= ~UMODE_ADMIN
;
1102 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1103 hdata
.client
= source_p
;
1104 hdata
.oldumodes
= setflags
;
1105 hdata
.oldsnomask
= setsnomask
;
1106 call_hook(h_umode_changed
, &hdata
);
1108 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1110 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1113 * compare new flags with old flags and send string which
1114 * will cause servers to update correctly.
1116 send_umode_out(client_p
, source_p
, setflags
);
1117 if (showsnomask
&& MyConnect(source_p
))
1118 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
1119 construct_snobuf(source_p
->snomask
));
1125 * send the MODE string for user (user) to connection client_p
1129 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1137 * build a string in umode_buf to represent the change in the user's
1138 * mode between the new (source_p->flag) and 'old'.
1143 for (i
= 0; i
< 128; i
++)
1145 flag
= user_modes
[i
];
1147 if((flag
& old
) && !(source_p
->umodes
& flag
))
1149 if(what
== MODE_DEL
)
1158 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1160 if(what
== MODE_ADD
)
1172 if(*umode_buf
&& client_p
)
1173 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1184 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1186 struct Client
*target_p
;
1190 send_umode(NULL
, source_p
, old
, 0, buf
);
1192 DLINK_FOREACH(ptr
, serv_list
.head
)
1194 target_p
= ptr
->data
;
1196 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1198 sendto_one(target_p
, ":%s MODE %s :%s",
1199 get_id(source_p
, target_p
),
1200 get_id(source_p
, target_p
), buf
);
1204 if(client_p
&& MyClient(client_p
))
1205 send_umode(client_p
, source_p
, old
, 0, buf
);
1211 * inputs - client pointer to client to welcome
1216 user_welcome(struct Client
*source_p
)
1218 sendto_one(source_p
, form_str(RPL_WELCOME
), me
.name
, source_p
->name
,
1219 ServerInfo
.network_name
, source_p
->name
);
1220 sendto_one(source_p
, form_str(RPL_YOURHOST
), me
.name
,
1222 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1224 sendto_one(source_p
, form_str(RPL_CREATED
), me
.name
, source_p
->name
, creation
);
1225 sendto_one(source_p
, form_str(RPL_MYINFO
), me
.name
, source_p
->name
, me
.name
, ircd_version
, umodebuf
);
1227 show_isupport(source_p
);
1229 show_lusers(source_p
);
1231 if(ConfigFileEntry
.short_motd
)
1233 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1234 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1236 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1237 me
.name
, source_p
->name
, me
.name
);
1239 sendto_one(source_p
, form_str(RPL_MOTD
),
1240 me
.name
, source_p
->name
, "*** This is the short motd ***");
1242 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1245 send_user_motd(source_p
);
1250 * inputs - pointer to given client to oper
1251 * - pointer to ConfItem to use
1253 * side effects - opers up source_p using aconf for reference
1256 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1258 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1259 hook_data_umode_changed hdata
;
1264 source_p
->umodes
|= oper_p
->umodes
;
1265 else if(ConfigFileEntry
.oper_umodes
)
1266 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1268 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1270 if (oper_p
->snomask
)
1272 source_p
->snomask
|= oper_p
->snomask
;
1273 source_p
->umodes
|= UMODE_SERVNOTICE
;
1275 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1277 /* Only apply these if +s is already set -- jilles */
1278 if (ConfigFileEntry
.oper_snomask
)
1279 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1281 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1286 SetExemptKline(source_p
);
1288 source_p
->flags2
|= oper_p
->flags
;
1289 DupString(source_p
->localClient
->opername
, oper_p
->name
);
1291 dlinkAddAlloc(source_p
, &local_oper_list
);
1292 dlinkAddAlloc(source_p
, &oper_list
);
1294 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1295 source_p
->umodes
|= UMODE_ADMIN
;
1296 if(!IsOperN(source_p
))
1297 source_p
->snomask
&= ~SNO_NCHANGE
;
1298 if(!IsOperOperwall(source_p
))
1299 source_p
->umodes
&= ~UMODE_OPERWALL
;
1300 hdata
.client
= source_p
;
1301 hdata
.oldumodes
= old
;
1302 hdata
.oldsnomask
= oldsnomask
;
1303 call_hook(h_umode_changed
, &hdata
);
1305 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1306 "%s (%s@%s) is now an operator", source_p
->name
,
1307 source_p
->username
, source_p
->host
);
1308 send_umode_out(source_p
, source_p
, old
);
1309 sendto_one(source_p
, form_str(RPL_SNOMASK
), me
.name
, source_p
->name
,
1310 construct_snobuf(source_p
->snomask
));
1311 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1312 sendto_one_notice(source_p
, ":*** Oper privs are %s", get_oper_privs(oper_p
->flags
));
1313 send_oper_motd(source_p
);
1319 construct_umodebuf(void)
1322 char *ptr
= umodebuf
;
1326 for (i
= 0; i
< 128; i
++)
1334 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1335 const char *host
, int newts
, char *format
, ...)
1338 struct Channel
*chptr
;
1339 struct membership
*mscptr
;
1340 int changed
= irccmp(target_p
->name
, nick
);
1341 int changed_case
= strcmp(target_p
->name
, nick
);
1342 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1343 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1350 target_p
->tsinfo
= newts
;
1351 monitor_signoff(target_p
);
1353 invalidate_bancache_user(target_p
);
1357 va_start(ap
, format
);
1358 vsnprintf(reason
, 255, format
, ap
);
1361 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1362 target_p
->name
, target_p
->username
, target_p
->host
,
1365 DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1368 chptr
= mscptr
->chptr
;
1371 if(is_chanop(mscptr
))
1374 strcat(modeval
, nick
);
1375 strcat(modeval
, " ");
1378 if(is_voiced(mscptr
))
1381 strcat(modeval
, nick
);
1386 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1387 nick
, user
, host
, chptr
->chname
);
1389 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1390 ":%s MODE %s +%s %s",
1391 target_p
->servptr
->name
,
1392 chptr
->chname
, mode
, modeval
);
1397 if(MyClient(target_p
) && changed_case
)
1398 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1399 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1401 else if(changed_case
)
1403 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1404 target_p
->name
, target_p
->username
,
1405 target_p
->host
, nick
);
1408 strlcpy(target_p
->username
, user
, USERLEN
);
1409 strlcpy(target_p
->host
, host
, HOSTLEN
);
1412 add_history(target_p
, 1);
1414 del_from_client_hash(target_p
->name
, target_p
);
1415 strlcpy(target_p
->name
, nick
, NICKLEN
);
1416 add_to_client_hash(target_p
->name
, target_p
);
1420 monitor_signon(target_p
);
1421 del_all_accepts(target_p
);