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 3586 2007-11-20 11:16:43Z nenolod $
40 #include "s_newconf.h"
46 #include "supported.h"
54 #include "blacklist.h"
55 #include "substitution.h"
57 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
58 void user_welcome(struct Client
*source_p
);
64 static int orphaned_umodes
= 0;
65 int user_modes
[256] = {
66 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
67 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
68 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
69 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
87 UMODE_NOFORWARD
, /* Q */
88 UMODE_REGONLYMSG
, /* R */
89 UMODE_SERVICE
, /* S */
96 UMODE_SSLCLIENT
, /* Z */
97 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
104 UMODE_CALLERID
, /* g */
106 UMODE_INVISIBLE
, /* i */
109 UMODE_LOCOPS
, /* l */
116 UMODE_SERVNOTICE
, /* s */
120 UMODE_WALLOP
, /* w */
123 UMODE_OPERWALL
, /* z */
124 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
125 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
126 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
127 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
128 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
129 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
130 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
131 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
132 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
139 * inputs - pointer to client
141 * side effects - display to client user counts etc.
144 show_lusers(struct Client
*source_p
)
146 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
147 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
149 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
150 (unsigned long)MaxConnectionCount
)
151 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
152 rb_dlink_list_length(&serv_list
);
154 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
155 (Count
.total
- Count
.invisi
),
156 Count
.invisi
, rb_dlink_list_length(&global_serv_list
));
158 if(rb_dlink_list_length(&oper_list
) > 0)
159 sendto_one_numeric(source_p
, RPL_LUSEROP
,
160 form_str(RPL_LUSEROP
), rb_dlink_list_length(&oper_list
));
162 if(rb_dlink_list_length(&unknown_list
) > 0)
163 sendto_one_numeric(source_p
, RPL_LUSERUNKNOWN
,
164 form_str(RPL_LUSERUNKNOWN
),
165 rb_dlink_list_length(&unknown_list
));
167 if(rb_dlink_list_length(&global_channel_list
) > 0)
168 sendto_one_numeric(source_p
, RPL_LUSERCHANNELS
,
169 form_str(RPL_LUSERCHANNELS
),
170 rb_dlink_list_length(&global_channel_list
));
172 sendto_one_numeric(source_p
, RPL_LUSERME
, form_str(RPL_LUSERME
),
173 rb_dlink_list_length(&lclient_list
),
174 rb_dlink_list_length(&serv_list
));
176 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
177 form_str(RPL_LOCALUSERS
),
178 rb_dlink_list_length(&lclient_list
),
180 rb_dlink_list_length(&lclient_list
),
183 sendto_one_numeric(source_p
, RPL_GLOBALUSERS
, form_str(RPL_GLOBALUSERS
),
184 Count
.total
, Count
.max_tot
,
185 Count
.total
, Count
.max_tot
);
187 sendto_one_numeric(source_p
, RPL_STATSCONN
,
188 form_str(RPL_STATSCONN
),
189 MaxConnectionCount
, MaxClientCount
,
190 Count
.totalrestartcount
);
196 ** register_local_user
197 ** This function is called when both NICK and USER messages
198 ** have been accepted for the client, in whatever order. Only
199 ** after this, is the USER message propagated.
201 ** NICK's must be propagated at once when received, although
202 ** it would be better to delay them too until full info is
203 ** available. Doing it is not so simple though, would have
204 ** to implement the following:
206 ** (actually it has been implemented already for a while) -orabidoo
208 ** 1) user telnets in and gives only "NICK foobar" and waits
209 ** 2) another user far away logs in normally with the nick
210 ** "foobar" (quite legal, as this server didn't propagate
212 ** 3) now this server gets nick "foobar" from outside, but
213 ** has alread the same defined locally. Current server
214 ** would just issue "KILL foobar" to clean out dups. But,
215 ** this is not fair. It should actually request another
216 ** nick from local user or kill him/her...
220 register_local_user(struct Client
*client_p
, struct Client
*source_p
, const char *username
)
222 struct ConfItem
*aconf
, *xconf
;
223 struct User
*user
= source_p
->user
;
224 char tmpstr2
[IRCD_BUFSIZE
];
225 char ipaddr
[HOSTIPLEN
];
226 char myusername
[USERLEN
+1];
229 s_assert(NULL
!= source_p
);
230 s_assert(MyConnect(source_p
));
231 s_assert(source_p
->username
!= username
);
236 if(IsAnyDead(source_p
))
239 if(ConfigFileEntry
.ping_cookie
)
241 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
243 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
244 sendto_one(source_p
, "PING :%08lX",
245 (unsigned long) source_p
->localClient
->random_ping
);
246 source_p
->flags
|= FLAGS_PINGSENT
;
249 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
255 /* hasnt finished client cap negotiation */
256 if(source_p
->flags
& FLAGS_CLICAP
)
259 /* still has DNSbls to validate against */
260 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
263 client_p
->localClient
->last
= rb_current_time();
264 /* Straight up the maximum rate of flooding... */
265 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
267 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
268 if(!IsGotId(source_p
) && (strchr(username
, '[') != NULL
))
275 while(*p
&& i
< USERLEN
)
278 myusername
[i
++] = *p
;
282 myusername
[i
] = '\0';
283 username
= myusername
;
286 if((status
= check_client(client_p
, source_p
, username
)) < 0)
287 return (CLIENT_EXITED
);
289 /* Apply nick override */
290 if(*source_p
->preClient
->spoofnick
)
292 char note
[NICKLEN
+ 10];
294 del_from_client_hash(source_p
->name
, source_p
);
295 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
296 add_to_client_hash(source_p
->name
, source_p
);
298 rb_snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
299 rb_note(source_p
->localClient
->F
, note
);
302 if(!valid_hostname(source_p
->host
))
304 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
306 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
310 aconf
= source_p
->localClient
->att_conf
;
314 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
315 return (CLIENT_EXITED
);
318 if(!IsGotId(source_p
))
323 if(IsNeedIdentd(aconf
))
325 ServerStats
.is_ref
++;
326 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
327 exit_client(client_p
, source_p
, &me
, "Install identd");
328 return (CLIENT_EXITED
);
331 /* dont replace username if its supposed to be spoofed --fl */
332 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->name
, '@'))
336 if(!IsNoTilde(aconf
))
337 source_p
->username
[i
++] = '~';
339 while (*p
&& i
< USERLEN
)
342 source_p
->username
[i
++] = *p
;
346 source_p
->username
[i
] = '\0';
350 if(IsNeedSasl(aconf
) && !*user
->suser
)
352 ServerStats
.is_ref
++;
353 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
354 exit_client(client_p
, source_p
, &me
, "SASL access only");
355 return (CLIENT_EXITED
);
359 if(!EmptyString(aconf
->passwd
))
363 if(EmptyString(source_p
->localClient
->passwd
))
365 else if(IsConfEncrypted(aconf
))
366 encr
= crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
368 encr
= source_p
->localClient
->passwd
;
370 if(strcmp(encr
, aconf
->passwd
))
372 ServerStats
.is_ref
++;
373 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
374 exit_client(client_p
, source_p
, &me
, "Bad Password");
375 return (CLIENT_EXITED
);
378 /* clear password only if used now, otherwise send it
379 * to services -- jilles */
380 if(source_p
->localClient
->passwd
)
382 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
383 rb_free(source_p
->localClient
->passwd
);
384 source_p
->localClient
->passwd
= NULL
;
388 /* report if user has &^>= etc. and set flags as needed in source_p */
389 report_and_set_user_flags(source_p
, aconf
);
393 * We want to be able to have servers and F-line clients
394 * connect, so save room for "buffer" connections.
395 * Smaller servers may want to decrease this, and it should
396 * probably be just a percentage of the MAXCLIENTS...
399 /* Except "F:" clients */
400 if(rb_dlink_list_length(&lclient_list
) >=
401 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
403 sendto_realops_snomask(SNO_FULL
, L_ALL
,
404 "Too many clients, rejecting %s[%s].", source_p
->name
, source_p
->host
);
406 ServerStats
.is_ref
++;
407 exit_client(client_p
, source_p
, &me
, "Sorry, server is full - try later");
408 return (CLIENT_EXITED
);
411 /* kline exemption extends to xline too */
412 if(!IsExemptKline(source_p
) &&
413 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
415 ServerStats
.is_ref
++;
416 add_reject(source_p
, xconf
->name
, NULL
);
417 exit_client(client_p
, source_p
, &me
, "Bad user info");
418 return CLIENT_EXITED
;
422 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
424 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
425 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
426 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
429 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
431 substitution_append_var(&varlist
, "nick", source_p
->name
);
432 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
433 substitution_append_var(&varlist
, "host", source_p
->host
);
434 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
435 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
437 ServerStats
.is_ref
++;
439 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
440 me
.name
, source_p
->name
,
441 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
443 substitution_free(&varlist
);
445 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
446 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
447 source_p
->preClient
->dnsbl_listed
->hits
++;
448 add_reject(source_p
, NULL
, NULL
);
449 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
450 return CLIENT_EXITED
;
454 /* valid user name check */
456 if(!valid_username(source_p
->username
))
458 sendto_realops_snomask(SNO_REJ
, L_ALL
,
459 "Invalid username: %s (%s@%s)",
460 source_p
->name
, source_p
->username
, source_p
->host
);
461 ServerStats
.is_ref
++;
462 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
463 "only alphanumeric characters.");
464 rb_sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
465 exit_client(client_p
, source_p
, &me
, tmpstr2
);
466 return (CLIENT_EXITED
);
469 /* end of valid user name check */
471 /* Store original hostname -- jilles */
472 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
474 /* Spoof user@host */
475 if(*source_p
->preClient
->spoofuser
)
476 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
477 if(*source_p
->preClient
->spoofhost
)
479 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
480 if (irccmp(source_p
->host
, source_p
->orighost
))
481 SetDynSpoof(source_p
);
484 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
486 call_hook(h_new_local_user
, source_p
);
488 /* If they have died in send_* or were thrown out by the
489 * new_local_user hook don't do anything. */
490 if(IsAnyDead(source_p
))
491 return CLIENT_EXITED
;
493 /* To avoid inconsistencies, do not abort the registration
494 * starting from this point -- jilles
496 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
498 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
499 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
500 source_p
->name
, source_p
->username
, source_p
->orighost
,
501 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
502 get_client_class(source_p
), source_p
->info
);
504 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
505 "CLICONN %s %s %s %s %s %s 0 %s",
506 source_p
->name
, source_p
->username
, source_p
->orighost
,
507 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
508 get_client_class(source_p
),
509 /* mirc can sometimes send ips here */
510 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
513 add_to_hostname_hash(source_p
->orighost
, source_p
);
515 /* Allocate a UID if it was not previously allocated.
516 * If this already occured, it was probably during SASL auth...
520 strcpy(source_p
->id
, generate_uid());
521 add_to_id_hash(source_p
->id
, source_p
);
525 source_p
->umodes
|= UMODE_SSLCLIENT
;
527 if (source_p
->umodes
& UMODE_INVISIBLE
)
530 s_assert(!IsClient(source_p
));
531 del_unknown_ip(source_p
);
532 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
535 source_p
->servptr
= &me
;
536 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
538 /* Increment our total user count here */
539 if(++Count
.total
> Count
.max_tot
)
540 Count
.max_tot
= Count
.total
;
542 source_p
->localClient
->allow_read
= MAX_FLOOD_BURST
;
544 Count
.totalrestartcount
++;
546 s_assert(source_p
->localClient
!= NULL
);
548 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
550 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
551 if(!(Count
.max_loc
% 10))
552 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
553 "New Max Local Clients: %d", Count
.max_loc
);
556 /* they get a reduced limit */
557 if(find_tgchange(source_p
->sockhost
))
558 USED_TARGETS(source_p
) = 6;
560 monitor_signon(source_p
);
561 user_welcome(source_p
);
563 free_pre_client(source_p
);
565 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
573 * side effects - This common function introduces a client to the rest
574 * of the net, either from a local client connect or
575 * from a remote connect.
578 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
580 static char ubuf
[12];
581 struct Client
*identifyservice_p
;
583 hook_data_umode_changed hdata
;
584 hook_data_client hdata2
;
585 char sockhost
[HOSTLEN
];
587 if(MyClient(source_p
))
588 send_umode(source_p
, source_p
, 0, 0, ubuf
);
590 send_umode(NULL
, source_p
, 0, 0, ubuf
);
598 s_assert(has_id(source_p
));
600 if(source_p
->sockhost
[0] == ':')
604 rb_strlcat(sockhost
, source_p
->sockhost
, sizeof(sockhost
));
606 strcpy(sockhost
, source_p
->sockhost
);
609 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
610 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
611 source_p
->servptr
->id
, nick
,
612 source_p
->hopcount
+ 1,
613 (long) source_p
->tsinfo
, ubuf
,
614 source_p
->username
, source_p
->host
,
615 IsIPSpoof(source_p
) ? "0" : sockhost
,
617 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
618 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
621 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
622 ":%s UID %s %d %ld %s %s %s %s %s :%s",
623 source_p
->servptr
->id
, nick
,
624 source_p
->hopcount
+ 1,
625 (long) source_p
->tsinfo
, ubuf
,
626 source_p
->username
, source_p
->host
,
627 IsIPSpoof(source_p
) ? "0" : sockhost
,
628 source_p
->id
, source_p
->info
);
630 if (IsDynSpoof(source_p
))
632 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
633 use_id(source_p
), source_p
->orighost
);
636 if (!EmptyString(source_p
->user
->suser
))
638 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
639 use_id(source_p
), source_p
->user
->suser
);
642 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
644 if (ConfigFileEntry
.identifyservice
[0] != '\0' &&
645 ConfigFileEntry
.identifycommand
[0] != '\0')
647 /* use user@server */
648 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
650 identifyservice_p
= find_named_client(p
+ 1);
652 identifyservice_p
= NULL
;
653 if (identifyservice_p
!= NULL
)
654 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
655 get_id(source_p
, identifyservice_p
),
656 ConfigFileEntry
.identifyservice
,
657 ConfigFileEntry
.identifycommand
,
658 source_p
->localClient
->passwd
);
660 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
661 rb_free(source_p
->localClient
->passwd
);
662 source_p
->localClient
->passwd
= NULL
;
665 /* let modules providing usermodes know that we've got a new user,
666 * why is this here? -- well, some modules need to be able to send out new
667 * information about a client, so this was the best place to do it
670 hdata
.client
= source_p
;
672 hdata
.oldsnomask
= 0;
673 call_hook(h_umode_changed
, &hdata
);
675 /* On the other hand, some modules need to know when a client is
676 * being introduced, period.
679 hdata2
.client
= client_p
;
680 hdata2
.target
= source_p
;
681 call_hook(h_introduce_client
, &hdata2
);
687 * valid_hostname - check hostname for validity
689 * Inputs - pointer to user
690 * Output - YES if valid, NO if not
691 * Side effects - NONE
693 * NOTE: this doesn't allow a hostname to begin with a dot and
694 * will not allow more dots than chars.
697 valid_hostname(const char *hostname
)
699 const char *p
= hostname
;
707 if('.' == *p
|| ':' == *p
)
714 if(*p
== '.' || *p
== ':')
726 * valid_username - check username for validity
728 * Inputs - pointer to user
729 * Output - YES if valid, NO if not
730 * Side effects - NONE
732 * Absolutely always reject any '*' '!' '?' '@' in an user name
733 * reject any odd control characters names.
734 * Allow '.' in username to allow for "first.last"
738 valid_username(const char *username
)
741 const char *p
= username
;
751 /* reject usernames that don't start with an alphanum
752 * i.e. reject jokers who have '-@somehost' or '.@somehost'
753 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
760 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
763 if(dots
> ConfigFileEntry
.dots_in_ident
)
765 if(!IsUserChar(p
[1]))
768 else if(!IsUserChar(*p
))
774 /* report_and_set_user_flags
776 * Inputs - pointer to source_p
777 * - pointer to aconf for this user
780 * Report to user any special flags they are getting, and set them.
784 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
786 /* If this user is being spoofed, tell them so */
787 if(IsConfDoSpoofIp(aconf
))
789 sendto_one_notice(source_p
, ":*** Spoofing your IP. congrats.");
792 /* If this user is in the exception class, Set it "E lined" */
793 if(IsConfExemptKline(aconf
))
795 SetExemptKline(source_p
);
796 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines. congrats.");
799 if(IsConfExemptDNSBL(aconf
))
800 /* kline exempt implies this, don't send both */
801 if(!IsConfExemptKline(aconf
))
802 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists.");
804 /* If this user is exempt from user limits set it F lined" */
805 if(IsConfExemptLimits(aconf
))
807 sendto_one_notice(source_p
, ":*** You are exempt from user limits. congrats.");
810 if(IsConfExemptFlood(aconf
))
812 SetExemptFlood(source_p
);
813 sendto_one_notice(source_p
, ":*** You are exempt from flood limits.");
816 if(IsConfExemptSpambot(aconf
))
818 SetExemptSpambot(source_p
);
819 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks.");
822 if(IsConfExemptJupe(aconf
))
824 SetExemptJupe(source_p
);
825 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings.");
828 if(IsConfExemptResv(aconf
))
830 SetExemptResv(source_p
);
831 sendto_one_notice(source_p
, ":*** You are exempt from resvs.");
834 if(IsConfExemptShide(aconf
))
836 SetExemptShide(source_p
);
837 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding.");
842 * user_mode - set get current users mode
844 * m_umode() added 15/10/91 By Darren Reed.
846 * parv[1] - username to change mode for
847 * parv[2] - modes to change
850 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
856 struct Client
*target_p
;
858 int badflag
= NO
; /* Only send one bad flag notice */
859 int showsnomask
= NO
;
860 unsigned int setsnomask
;
862 hook_data_umode_changed hdata
;
868 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
872 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
874 if(MyConnect(source_p
))
875 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
876 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
880 /* Dont know why these were commented out..
881 * put them back using new sendto() funcs
884 if(IsServer(source_p
))
886 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
887 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
891 if(source_p
!= target_p
|| target_p
->from
!= source_p
->from
)
893 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
902 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
903 if (source_p
->umodes
& user_modes
[i
])
907 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
909 if (source_p
->snomask
!= 0)
910 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
911 construct_snobuf(source_p
->snomask
));
916 /* find flags already set for user */
917 setflags
= source_p
->umodes
;
918 setsnomask
= source_p
->snomask
;
921 * parse mode change string(s)
923 for (pm
= parv
[2]; *pm
; pm
++)
936 if(IsServer(client_p
) && !IsOper(source_p
))
940 rb_dlinkAddAlloc(source_p
, &oper_list
);
945 /* Only decrement the oper counts if an oper to begin with
946 * found by Pat Szuta, Perly , perly@xnet.com
949 if(!IsOper(source_p
))
956 if(MyConnect(source_p
))
958 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
959 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
961 source_p
->snomask
= 0;
964 source_p
->flags2
&= ~OPER_FLAGS
;
966 rb_free(source_p
->localClient
->opername
);
967 source_p
->localClient
->opername
= NULL
;
969 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
972 rb_dlinkFindDestroy(source_p
, &oper_list
);
976 /* we may not get these,
977 * but they shouldnt be in default
980 /* can only be set on burst */
990 if (MyConnect(source_p
))
993 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
995 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1000 if(what
== MODE_ADD
)
1003 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1005 source_p
->snomask
|= SNO_GENERAL
;
1008 source_p
->snomask
= 0;
1009 if (source_p
->snomask
!= 0)
1010 source_p
->umodes
|= UMODE_SERVNOTICE
;
1012 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1017 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
) {
1022 if((flag
= user_modes
[(unsigned char) *pm
]))
1024 if(MyConnect(source_p
)
1025 && ((!IsOper(source_p
)
1026 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1027 || (orphaned_umodes
& flag
)))
1029 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1034 if(what
== MODE_ADD
)
1035 source_p
->umodes
|= flag
;
1037 source_p
->umodes
&= ~flag
;
1042 if(MyConnect(source_p
))
1049 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1051 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1053 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1054 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1057 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1059 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1060 source_p
->umodes
&= ~UMODE_OPERWALL
;
1063 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1064 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1066 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1067 source_p
->umodes
&= ~UMODE_ADMIN
;
1070 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1071 hdata
.client
= source_p
;
1072 hdata
.oldumodes
= setflags
;
1073 hdata
.oldsnomask
= setsnomask
;
1074 call_hook(h_umode_changed
, &hdata
);
1076 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1078 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1081 * compare new flags with old flags and send string which
1082 * will cause servers to update correctly.
1084 send_umode_out(client_p
, source_p
, setflags
);
1085 if (showsnomask
&& MyConnect(source_p
))
1086 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1087 construct_snobuf(source_p
->snomask
));
1093 * send the MODE string for user (user) to connection client_p
1097 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, int sendmask
, char *umode_buf
)
1105 * build a string in umode_buf to represent the change in the user's
1106 * mode between the new (source_p->flag) and 'old'.
1111 for (i
= 0; i
< 128; i
++)
1113 flag
= user_modes
[i
];
1115 if((flag
& old
) && !(source_p
->umodes
& flag
))
1117 if(what
== MODE_DEL
)
1126 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1128 if(what
== MODE_ADD
)
1140 if(*umode_buf
&& client_p
)
1141 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1152 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1154 struct Client
*target_p
;
1158 send_umode(NULL
, source_p
, old
, 0, buf
);
1160 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1162 target_p
= ptr
->data
;
1164 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1166 sendto_one(target_p
, ":%s MODE %s :%s",
1167 get_id(source_p
, target_p
),
1168 get_id(source_p
, target_p
), buf
);
1172 if(client_p
&& MyClient(client_p
))
1173 send_umode(client_p
, source_p
, old
, 0, buf
);
1179 * inputs - client pointer to client to welcome
1184 user_welcome(struct Client
*source_p
)
1186 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1187 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1188 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1189 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1190 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
);
1192 show_isupport(source_p
);
1194 show_lusers(source_p
);
1196 if(ConfigFileEntry
.short_motd
)
1198 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1199 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1201 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1202 me
.name
, source_p
->name
, me
.name
);
1204 sendto_one(source_p
, form_str(RPL_MOTD
),
1205 me
.name
, source_p
->name
, "*** This is the short motd ***");
1207 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1210 send_user_motd(source_p
);
1215 * inputs - pointer to given client to oper
1216 * - pointer to ConfItem to use
1218 * side effects - opers up source_p using aconf for reference
1221 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1223 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1224 hook_data_umode_changed hdata
;
1229 source_p
->umodes
|= oper_p
->umodes
;
1230 else if(ConfigFileEntry
.oper_umodes
)
1231 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1233 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1235 if (oper_p
->snomask
)
1237 source_p
->snomask
|= oper_p
->snomask
;
1238 source_p
->umodes
|= UMODE_SERVNOTICE
;
1240 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1242 /* Only apply these if +s is already set -- jilles */
1243 if (ConfigFileEntry
.oper_snomask
)
1244 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1246 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1251 SetExemptKline(source_p
);
1253 source_p
->flags2
|= oper_p
->flags
;
1254 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1256 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1257 rb_dlinkAddAlloc(source_p
, &oper_list
);
1259 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1260 source_p
->umodes
|= UMODE_ADMIN
;
1261 if(!IsOperN(source_p
))
1262 source_p
->snomask
&= ~SNO_NCHANGE
;
1263 if(!IsOperOperwall(source_p
))
1264 source_p
->umodes
&= ~UMODE_OPERWALL
;
1265 hdata
.client
= source_p
;
1266 hdata
.oldumodes
= old
;
1267 hdata
.oldsnomask
= oldsnomask
;
1268 call_hook(h_umode_changed
, &hdata
);
1270 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1271 "%s (%s@%s) is now an operator", source_p
->name
,
1272 source_p
->username
, source_p
->host
);
1273 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1275 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1277 send_umode_out(source_p
, source_p
, old
);
1278 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1279 construct_snobuf(source_p
->snomask
));
1280 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1281 sendto_one_notice(source_p
, ":*** Oper privs are %s", get_oper_privs(oper_p
->flags
));
1282 send_oper_motd(source_p
);
1291 * outputs - an available umode bitmask or
1292 * 0 if no umodes are available
1293 * side effects - NONE
1296 find_umode_slot(void)
1298 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1300 for (i
= 0; i
< 128; i
++)
1301 all_umodes
|= user_modes
[i
];
1303 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1310 construct_umodebuf(void)
1313 char *ptr
= umodebuf
;
1314 static int prev_user_modes
[128];
1318 for (i
= 0; i
< 128; i
++)
1320 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1322 if (user_modes
[i
] == 0)
1324 orphaned_umodes
|= prev_user_modes
[i
];
1325 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1329 orphaned_umodes
&= ~prev_user_modes
[i
];
1330 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1332 user_modes
[i
] = prev_user_modes
[i
];
1335 prev_user_modes
[i
] = user_modes
[i
];
1344 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1345 const char *host
, int newts
, const char *format
, ...)
1348 struct Channel
*chptr
;
1349 struct membership
*mscptr
;
1350 int changed
= irccmp(target_p
->name
, nick
);
1351 int changed_case
= strcmp(target_p
->name
, nick
);
1352 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1353 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1360 target_p
->tsinfo
= newts
;
1361 monitor_signoff(target_p
);
1363 invalidate_bancache_user(target_p
);
1367 va_start(ap
, format
);
1368 vsnprintf(reason
, 255, format
, ap
);
1371 sendto_common_channels_local_butone(target_p
, ":%s!%s@%s QUIT :%s",
1372 target_p
->name
, target_p
->username
, target_p
->host
,
1375 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1378 chptr
= mscptr
->chptr
;
1381 if(is_chanop(mscptr
))
1384 strcat(modeval
, nick
);
1385 strcat(modeval
, " ");
1388 if(is_voiced(mscptr
))
1391 strcat(modeval
, nick
);
1396 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
1397 nick
, user
, host
, chptr
->chname
);
1399 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1400 ":%s MODE %s +%s %s",
1401 target_p
->servptr
->name
,
1402 chptr
->chname
, mode
, modeval
);
1407 if(MyClient(target_p
) && changed_case
)
1408 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1409 target_p
->name
, target_p
->username
, target_p
->host
, nick
);
1411 else if(changed_case
)
1413 sendto_common_channels_local(target_p
, ":%s!%s@%s NICK :%s",
1414 target_p
->name
, target_p
->username
,
1415 target_p
->host
, nick
);
1418 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1419 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1422 add_history(target_p
, 1);
1424 del_from_client_hash(target_p
->name
, target_p
);
1425 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1426 add_to_client_hash(target_p
->name
, target_p
);
1430 monitor_signon(target_p
);
1431 del_all_accepts(target_p
);