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
38 #include "s_newconf.h"
44 #include "supported.h"
52 #include "blacklist.h"
53 #include "substitution.h"
57 static void report_and_set_user_flags(struct Client
*, struct ConfItem
*);
58 void user_welcome(struct Client
*source_p
);
62 static int orphaned_umodes
= 0;
63 int user_modes
[256] = {
64 /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0F */
65 /* 0x10 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x1F */
66 /* 0x20 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x2F */
67 /* 0x30 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x3F */
85 UMODE_NOFORWARD
, /* Q */
86 UMODE_REGONLYMSG
, /* R */
87 UMODE_SERVICE
, /* S */
94 UMODE_SSLCLIENT
, /* Z */
95 /* 0x5B */ 0, 0, 0, 0, 0, 0, /* 0x60 */
102 UMODE_CALLERID
, /* g */
104 UMODE_INVISIBLE
, /* i */
107 UMODE_LOCOPS
, /* l */
114 UMODE_SERVNOTICE
, /* s */
118 UMODE_WALLOP
, /* w */
121 UMODE_OPERWALL
, /* z */
122 /* 0x7B */ 0, 0, 0, 0, 0, /* 0x7F */
123 /* 0x80 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
124 /* 0x90 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x9F */
125 /* 0xA0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xAF */
126 /* 0xB0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xBF */
127 /* 0xC0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xCF */
128 /* 0xD0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xDF */
129 /* 0xE0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xEF */
130 /* 0xF0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xFF */
137 * inputs - pointer to client
139 * side effects - display to client user counts etc.
142 show_lusers(struct Client
*source_p
)
144 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)MaxClientCount
)
145 MaxClientCount
= rb_dlink_list_length(&lclient_list
);
147 if((rb_dlink_list_length(&lclient_list
) + rb_dlink_list_length(&serv_list
)) >
148 (unsigned long)MaxConnectionCount
)
149 MaxConnectionCount
= rb_dlink_list_length(&lclient_list
) +
150 rb_dlink_list_length(&serv_list
);
152 sendto_one_numeric(source_p
, RPL_LUSERCLIENT
, form_str(RPL_LUSERCLIENT
),
153 (Count
.total
- Count
.invisi
),
155 (int)rb_dlink_list_length(&global_serv_list
));
157 if(rb_dlink_list_length(&oper_list
) > 0)
158 sendto_one_numeric(source_p
, RPL_LUSEROP
,
159 form_str(RPL_LUSEROP
),
160 (int)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 (int)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 (int)rb_dlink_list_length(&lclient_list
),
174 (int)rb_dlink_list_length(&serv_list
));
176 sendto_one_numeric(source_p
, RPL_LOCALUSERS
,
177 form_str(RPL_LOCALUSERS
),
178 (int)rb_dlink_list_length(&lclient_list
),
180 (int)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
)
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
));
235 if(IsAnyDead(source_p
))
238 if(ConfigFileEntry
.ping_cookie
)
240 if(!(source_p
->flags
& FLAGS_PINGSENT
) && source_p
->localClient
->random_ping
== 0)
242 source_p
->localClient
->random_ping
= (unsigned long) (rand() * rand()) << 1;
243 sendto_one(source_p
, "PING :%08lX",
244 (unsigned long) source_p
->localClient
->random_ping
);
245 source_p
->flags
|= FLAGS_PINGSENT
;
248 if(!(source_p
->flags
& FLAGS_PING_COOKIE
))
254 /* hasnt finished client cap negotiation */
255 if(source_p
->flags
& FLAGS_CLICAP
)
258 /* still has DNSbls to validate against */
259 if(rb_dlink_list_length(&source_p
->preClient
->dnsbl_queries
) > 0)
262 client_p
->localClient
->last
= rb_current_time();
264 /* XXX - fixme. we shouldnt have to build a users buffer twice.. */
265 if(!IsGotId(source_p
) && (strchr(source_p
->username
, '[') != NULL
))
270 p
= source_p
->username
;
272 while(*p
&& i
< USERLEN
)
275 myusername
[i
++] = *p
;
279 myusername
[i
] = '\0';
282 rb_strlcpy(myusername
, source_p
->username
, sizeof myusername
);
284 if((status
= check_client(client_p
, source_p
, myusername
)) < 0)
285 return (CLIENT_EXITED
);
287 /* Apply nick override */
288 if(*source_p
->preClient
->spoofnick
)
290 char note
[NICKLEN
+ 10];
292 del_from_client_hash(source_p
->name
, source_p
);
293 rb_strlcpy(source_p
->name
, source_p
->preClient
->spoofnick
, NICKLEN
+ 1);
294 add_to_client_hash(source_p
->name
, source_p
);
296 snprintf(note
, NICKLEN
+ 10, "Nick: %s", source_p
->name
);
297 rb_note(source_p
->localClient
->F
, note
);
300 if(!valid_hostname(source_p
->host
))
302 sendto_one_notice(source_p
, ":*** Notice -- You have an illegal character in your hostname");
304 rb_strlcpy(source_p
->host
, source_p
->sockhost
, sizeof(source_p
->host
));
308 aconf
= source_p
->localClient
->att_conf
;
312 exit_client(client_p
, source_p
, &me
, "*** Not Authorised");
313 return (CLIENT_EXITED
);
316 if(IsConfSSLNeeded(aconf
) && !IsSSL(source_p
))
318 ServerStats
.is_ref
++;
319 sendto_one_notice(source_p
, ":*** Notice -- You need to use SSL/TLS to use this server");
320 exit_client(client_p
, source_p
, &me
, "Use SSL/TLS");
321 return (CLIENT_EXITED
);
324 if(!IsGotId(source_p
))
329 if(IsNeedIdentd(aconf
))
331 ServerStats
.is_ref
++;
332 sendto_one_notice(source_p
, ":*** Notice -- You need to install identd to use this server");
333 exit_client(client_p
, source_p
, &me
, "Install identd");
334 return (CLIENT_EXITED
);
337 /* dont replace username if its supposed to be spoofed --fl */
338 if(!IsConfDoSpoofIp(aconf
) || !strchr(aconf
->info
.name
, '@'))
342 if(!IsNoTilde(aconf
))
343 source_p
->username
[i
++] = '~';
345 while (*p
&& i
< USERLEN
)
348 source_p
->username
[i
++] = *p
;
352 source_p
->username
[i
] = '\0';
356 if(IsNeedSasl(aconf
) && !*user
->suser
)
358 ServerStats
.is_ref
++;
359 sendto_one_notice(source_p
, ":*** Notice -- You need to identify via SASL to use this server");
360 exit_client(client_p
, source_p
, &me
, "SASL access only");
361 return (CLIENT_EXITED
);
365 if(!EmptyString(aconf
->passwd
))
369 if(EmptyString(source_p
->localClient
->passwd
))
371 else if(IsConfEncrypted(aconf
))
372 encr
= rb_crypt(source_p
->localClient
->passwd
, aconf
->passwd
);
374 encr
= source_p
->localClient
->passwd
;
376 if(encr
== NULL
|| strcmp(encr
, aconf
->passwd
))
378 ServerStats
.is_ref
++;
379 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
), me
.name
, source_p
->name
);
380 exit_client(client_p
, source_p
, &me
, "Bad Password");
381 return (CLIENT_EXITED
);
384 /* clear password only if used now, otherwise send it
385 * to services -- jilles */
386 if(source_p
->localClient
->passwd
)
388 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
389 rb_free(source_p
->localClient
->passwd
);
390 source_p
->localClient
->passwd
= NULL
;
394 /* report if user has &^>= etc. and set flags as needed in source_p */
395 report_and_set_user_flags(source_p
, aconf
);
399 * We want to be able to have servers and F-line clients
400 * connect, so save room for "buffer" connections.
401 * Smaller servers may want to decrease this, and it should
402 * probably be just a percentage of the MAXCLIENTS...
405 /* Except "F:" clients */
406 if(rb_dlink_list_length(&lclient_list
) >=
407 (unsigned long)GlobalSetOptions
.maxclients
&& !IsConfExemptLimits(aconf
))
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 /* kline exemption extends to xline too */
418 if(!IsExemptKline(source_p
) &&
419 (xconf
= find_xline(source_p
->info
, 1)) != NULL
)
421 ServerStats
.is_ref
++;
422 add_reject(source_p
, xconf
->host
, NULL
);
423 exit_client(client_p
, source_p
, &me
, "Bad user info");
424 return CLIENT_EXITED
;
428 if (source_p
->preClient
->dnsbl_listed
!= NULL
)
430 if (IsExemptKline(source_p
) || IsConfExemptDNSBL(aconf
))
431 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s, but you are exempt",
432 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
435 sendto_realops_snomask(SNO_REJ
, L_NETWIDE
,
436 "Listed on DNSBL %s: %s (%s@%s) [%s] [%s]",
437 source_p
->preClient
->dnsbl_listed
->host
,
439 source_p
->username
, source_p
->host
,
440 IsIPSpoof(source_p
) ? "255.255.255.255" : source_p
->sockhost
,
443 rb_dlink_list varlist
= { NULL
, NULL
, 0 };
445 substitution_append_var(&varlist
, "nick", source_p
->name
);
446 substitution_append_var(&varlist
, "ip", source_p
->sockhost
);
447 substitution_append_var(&varlist
, "host", source_p
->host
);
448 substitution_append_var(&varlist
, "dnsbl-host", source_p
->preClient
->dnsbl_listed
->host
);
449 substitution_append_var(&varlist
, "network-name", ServerInfo
.network_name
);
451 ServerStats
.is_ref
++;
453 sendto_one(source_p
, form_str(ERR_YOUREBANNEDCREEP
),
454 me
.name
, source_p
->name
,
455 substitution_parse(source_p
->preClient
->dnsbl_listed
->reject_reason
, &varlist
));
457 substitution_free(&varlist
);
459 sendto_one_notice(source_p
, ":*** Your IP address %s is listed in %s",
460 source_p
->sockhost
, source_p
->preClient
->dnsbl_listed
->host
);
461 source_p
->preClient
->dnsbl_listed
->hits
++;
462 add_reject(source_p
, NULL
, NULL
);
463 exit_client(client_p
, source_p
, &me
, "*** Banned (DNS blacklist)");
464 return CLIENT_EXITED
;
468 /* valid user name check */
470 if(!valid_username(source_p
->username
))
472 sendto_realops_snomask(SNO_REJ
, L_ALL
,
473 "Invalid username: %s (%s@%s)",
474 source_p
->name
, source_p
->username
, source_p
->host
);
475 ServerStats
.is_ref
++;
476 sendto_one_notice(source_p
, ":*** Your username is invalid. Please make sure that your username contains "
477 "only alphanumeric characters.");
478 sprintf(tmpstr2
, "Invalid username [%s]", source_p
->username
);
479 exit_client(client_p
, source_p
, &me
, tmpstr2
);
480 return (CLIENT_EXITED
);
483 /* end of valid user name check */
485 /* Store original hostname -- jilles */
486 rb_strlcpy(source_p
->orighost
, source_p
->host
, HOSTLEN
+ 1);
488 /* Spoof user@host */
489 if(*source_p
->preClient
->spoofuser
)
490 rb_strlcpy(source_p
->username
, source_p
->preClient
->spoofuser
, USERLEN
+ 1);
491 if(*source_p
->preClient
->spoofhost
)
493 rb_strlcpy(source_p
->host
, source_p
->preClient
->spoofhost
, HOSTLEN
+ 1);
494 if (irccmp(source_p
->host
, source_p
->orighost
))
495 SetDynSpoof(source_p
);
498 source_p
->umodes
|= ConfigFileEntry
.default_umodes
& ~ConfigFileEntry
.oper_only_umodes
& ~orphaned_umodes
;
500 call_hook(h_new_local_user
, source_p
);
502 /* If they have died in send_* or were thrown out by the
503 * new_local_user hook don't do anything. */
504 if(IsAnyDead(source_p
))
505 return CLIENT_EXITED
;
507 /* To avoid inconsistencies, do not abort the registration
508 * starting from this point -- jilles
510 rb_inet_ntop_sock((struct sockaddr
*)&source_p
->localClient
->ip
, ipaddr
, sizeof(ipaddr
));
512 sendto_realops_snomask(SNO_CCONN
, L_ALL
,
513 "Client connecting: %s (%s@%s) [%s] {%s} [%s]",
514 source_p
->name
, source_p
->username
, source_p
->orighost
,
515 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
516 get_client_class(source_p
), source_p
->info
);
518 sendto_realops_snomask(SNO_CCONNEXT
, L_ALL
,
519 "CLICONN %s %s %s %s %s %s 0 %s",
520 source_p
->name
, source_p
->username
, source_p
->orighost
,
521 show_ip(NULL
, source_p
) ? ipaddr
: "255.255.255.255",
522 get_client_class(source_p
),
523 /* mirc can sometimes send ips here */
524 show_ip(NULL
, source_p
) ? source_p
->localClient
->fullcaps
: "<hidden> <hidden>",
527 add_to_hostname_hash(source_p
->orighost
, source_p
);
529 /* Allocate a UID if it was not previously allocated.
530 * If this already occured, it was probably during SASL auth...
534 strcpy(source_p
->id
, generate_uid());
535 add_to_id_hash(source_p
->id
, source_p
);
539 source_p
->umodes
|= UMODE_SSLCLIENT
;
541 if (source_p
->umodes
& UMODE_INVISIBLE
)
544 s_assert(!IsClient(source_p
));
545 rb_dlinkMoveNode(&source_p
->localClient
->tnode
, &unknown_list
, &lclient_list
);
548 source_p
->servptr
= &me
;
549 rb_dlinkAdd(source_p
, &source_p
->lnode
, &source_p
->servptr
->serv
->users
);
551 /* Increment our total user count here */
552 if(++Count
.total
> Count
.max_tot
)
553 Count
.max_tot
= Count
.total
;
555 Count
.totalrestartcount
++;
557 s_assert(source_p
->localClient
!= NULL
);
559 if(rb_dlink_list_length(&lclient_list
) > (unsigned long)Count
.max_loc
)
561 Count
.max_loc
= rb_dlink_list_length(&lclient_list
);
562 if(!(Count
.max_loc
% 10))
563 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
564 "New Max Local Clients: %d", Count
.max_loc
);
567 /* they get a reduced limit */
568 if(find_tgchange(source_p
->sockhost
))
569 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL_LOW
;
571 source_p
->localClient
->targets_free
= TGCHANGE_INITIAL
;
573 monitor_signon(source_p
);
574 user_welcome(source_p
);
576 free_pre_client(source_p
);
578 return (introduce_client(client_p
, source_p
, user
, source_p
->name
, 1));
586 * side effects - This common function introduces a client to the rest
587 * of the net, either from a local client connect or
588 * from a remote connect.
591 introduce_client(struct Client
*client_p
, struct Client
*source_p
, struct User
*user
, const char *nick
, int use_euid
)
594 struct Client
*identifyservice_p
;
596 hook_data_umode_changed hdata
;
597 hook_data_client hdata2
;
599 if(MyClient(source_p
))
600 send_umode(source_p
, source_p
, 0, ubuf
);
602 send_umode(NULL
, source_p
, 0, ubuf
);
610 s_assert(has_id(source_p
));
613 sendto_server(client_p
, NULL
, CAP_EUID
| CAP_TS6
, NOCAPS
,
614 ":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
615 source_p
->servptr
->id
, nick
,
616 source_p
->hopcount
+ 1,
617 (long) source_p
->tsinfo
, ubuf
,
618 source_p
->username
, source_p
->host
,
619 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
621 IsDynSpoof(source_p
) ? source_p
->orighost
: "*",
622 EmptyString(source_p
->user
->suser
) ? "*" : source_p
->user
->suser
,
625 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
,
626 ":%s UID %s %d %ld %s %s %s %s %s :%s",
627 source_p
->servptr
->id
, nick
,
628 source_p
->hopcount
+ 1,
629 (long) source_p
->tsinfo
, ubuf
,
630 source_p
->username
, source_p
->host
,
631 IsIPSpoof(source_p
) ? "0" : source_p
->sockhost
,
632 source_p
->id
, source_p
->info
);
634 if(!EmptyString(source_p
->certfp
))
635 sendto_server(client_p
, NULL
, CAP_TS6
, NOCAPS
,
636 ":%s ENCAP * CERTFP :%s",
637 use_id(source_p
), source_p
->certfp
);
639 if (IsDynSpoof(source_p
))
641 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * REALHOST %s",
642 use_id(source_p
), source_p
->orighost
);
645 if (!EmptyString(source_p
->user
->suser
))
647 sendto_server(client_p
, NULL
, CAP_TS6
, use_euid
? CAP_EUID
: NOCAPS
, ":%s ENCAP * LOGIN %s",
648 use_id(source_p
), source_p
->user
->suser
);
651 if(MyConnect(source_p
) && source_p
->localClient
->passwd
)
653 if (!EmptyString(ConfigFileEntry
.identifyservice
) &&
654 !EmptyString(ConfigFileEntry
.identifycommand
))
656 /* use user@server */
657 p
= strchr(ConfigFileEntry
.identifyservice
, '@');
659 identifyservice_p
= find_named_client(p
+ 1);
661 identifyservice_p
= NULL
;
662 if (identifyservice_p
!= NULL
)
664 if (!EmptyString(source_p
->localClient
->auth_user
))
665 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s %s",
666 get_id(source_p
, identifyservice_p
),
667 ConfigFileEntry
.identifyservice
,
668 ConfigFileEntry
.identifycommand
,
669 source_p
->localClient
->auth_user
,
670 source_p
->localClient
->passwd
);
672 sendto_one(identifyservice_p
, ":%s PRIVMSG %s :%s %s",
673 get_id(source_p
, identifyservice_p
),
674 ConfigFileEntry
.identifyservice
,
675 ConfigFileEntry
.identifycommand
,
676 source_p
->localClient
->passwd
);
679 memset(source_p
->localClient
->passwd
, 0, strlen(source_p
->localClient
->passwd
));
680 rb_free(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
, *last_slash
= 0;
726 if(!strcmp(hostname
, "localhost"))
729 if('.' == *p
|| ':' == *p
|| '/' == *p
)
736 if(*p
== '.' || *p
== ':')
749 if(last_slash
&& IsDigit(last_slash
[1]))
756 * valid_username - check username for validity
758 * Inputs - pointer to user
759 * Output - YES if valid, NO if not
760 * Side effects - NONE
762 * Absolutely always reject any '*' '!' '?' '@' in an user name
763 * reject any odd control characters names.
764 * Allow '.' in username to allow for "first.last"
768 valid_username(const char *username
)
771 const char *p
= username
;
781 /* reject usernames that don't start with an alphanum
782 * i.e. reject jokers who have '-@somehost' or '.@somehost'
783 * or "-hi-@somehost", "h-----@somehost" would still be accepted.
790 if((*p
== '.') && ConfigFileEntry
.dots_in_ident
)
793 if(dots
> ConfigFileEntry
.dots_in_ident
)
795 if(!IsUserChar(p
[1]))
798 else if(!IsUserChar(*p
))
804 /* report_and_set_user_flags
806 * Inputs - pointer to source_p
807 * - pointer to aconf for this user
810 * Report to user any special flags they are getting, and set them.
814 report_and_set_user_flags(struct Client
*source_p
, struct ConfItem
*aconf
)
816 /* If this user is being spoofed, tell them so */
817 if(IsConfDoSpoofIp(aconf
))
819 sendto_one_notice(source_p
, ":*** Spoofing your IP");
822 /* If this user is in the exception class, Set it "E lined" */
823 if(IsConfExemptKline(aconf
))
825 SetExemptKline(source_p
);
826 sendto_one_notice(source_p
, ":*** You are exempt from K/X lines");
829 if(IsConfExemptDNSBL(aconf
))
830 /* kline exempt implies this, don't send both */
831 if(!IsConfExemptKline(aconf
))
832 sendto_one_notice(source_p
, ":*** You are exempt from DNS blacklists");
834 /* If this user is exempt from user limits set it F lined" */
835 if(IsConfExemptLimits(aconf
))
837 sendto_one_notice(source_p
, ":*** You are exempt from user limits");
840 if(IsConfExemptFlood(aconf
))
842 SetExemptFlood(source_p
);
843 sendto_one_notice(source_p
, ":*** You are exempt from flood limits");
846 if(IsConfExemptSpambot(aconf
))
848 SetExemptSpambot(source_p
);
849 sendto_one_notice(source_p
, ":*** You are exempt from spambot checks");
852 if(IsConfExemptJupe(aconf
))
854 SetExemptJupe(source_p
);
855 sendto_one_notice(source_p
, ":*** You are exempt from juped channel warnings");
858 if(IsConfExemptResv(aconf
))
860 SetExemptResv(source_p
);
861 sendto_one_notice(source_p
, ":*** You are exempt from resvs");
864 if(IsConfExemptShide(aconf
))
866 SetExemptShide(source_p
);
867 sendto_one_notice(source_p
, ":*** You are exempt from serverhiding");
870 if(IsConfExtendChans(aconf
))
872 SetExtendChans(source_p
);
873 sendto_one_notice(source_p
, ":*** You are exempt from normal channel limits");
878 show_other_user_mode(struct Client
*source_p
, struct Client
*target_p
)
887 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
888 if (target_p
->umodes
& user_modes
[i
])
892 if (MyConnect(target_p
) && target_p
->snomask
!= 0)
893 sendto_one_notice(source_p
, ":Modes for %s are %s %s",
895 construct_snobuf(target_p
->snomask
));
897 sendto_one_notice(source_p
, ":Modes for %s are %s",
898 target_p
->name
, buf
);
902 * user_mode - set get current users mode
904 * m_umode() added 15/10/91 By Darren Reed.
905 * parv[1] - username to change mode for
906 * parv[2] - modes to change
909 user_mode(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
915 struct Client
*target_p
;
917 int badflag
= NO
; /* Only send one bad flag notice */
918 int showsnomask
= NO
;
919 unsigned int setsnomask
;
921 hook_data_umode_changed hdata
;
927 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MODE");
931 if((target_p
= MyClient(source_p
) ? find_named_person(parv
[1]) : find_person(parv
[1])) == NULL
)
933 if(MyConnect(source_p
))
934 sendto_one_numeric(source_p
, ERR_NOSUCHCHANNEL
,
935 form_str(ERR_NOSUCHCHANNEL
), parv
[1]);
939 /* Dont know why these were commented out..
940 * put them back using new sendto() funcs
943 if(IsServer(source_p
))
945 sendto_realops_snomask(SNO_GENERAL
, L_ADMIN
,
946 "*** Mode for User %s from %s", parv
[1], source_p
->name
);
950 if(source_p
!= target_p
)
952 if (MyOper(source_p
) && parc
< 3)
953 show_other_user_mode(source_p
, target_p
);
955 sendto_one(source_p
, form_str(ERR_USERSDONTMATCH
), me
.name
, source_p
->name
);
964 for (i
= 0; i
< 128; i
++) /* >= 127 is extended ascii */
965 if (source_p
->umodes
& user_modes
[i
])
969 sendto_one_numeric(source_p
, RPL_UMODEIS
, form_str(RPL_UMODEIS
), buf
);
971 if (source_p
->snomask
!= 0)
972 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
973 construct_snobuf(source_p
->snomask
));
978 /* find flags already set for user */
979 setflags
= source_p
->umodes
;
980 setsnomask
= source_p
->snomask
;
983 * parse mode change string(s)
985 for (pm
= parv
[2]; *pm
; pm
++)
998 if(IsServer(client_p
) && !IsOper(source_p
))
1002 rb_dlinkAddAlloc(source_p
, &oper_list
);
1007 /* Only decrement the oper counts if an oper to begin with
1008 * found by Pat Szuta, Perly , perly@xnet.com
1011 if(!IsOper(source_p
))
1014 ClearOper(source_p
);
1018 if(MyConnect(source_p
))
1020 source_p
->umodes
&= ~ConfigFileEntry
.oper_only_umodes
;
1021 if (!(source_p
->umodes
& UMODE_SERVNOTICE
) && source_p
->snomask
!= 0)
1023 source_p
->snomask
= 0;
1026 source_p
->flags2
&= ~OPER_FLAGS
;
1028 rb_free(source_p
->localClient
->opername
);
1029 source_p
->localClient
->opername
= NULL
;
1031 rb_dlinkFindDestroy(source_p
, &local_oper_list
);
1032 privilegeset_unref(source_p
->localClient
->privset
);
1033 source_p
->localClient
->privset
= NULL
;
1036 rb_dlinkFindDestroy(source_p
, &oper_list
);
1040 /* we may not get these,
1041 * but they shouldnt be in default
1044 /* can only be set on burst */
1054 if (MyConnect(source_p
))
1056 if(!IsOper(source_p
)
1057 && (ConfigFileEntry
.oper_only_umodes
& UMODE_SERVNOTICE
))
1059 if (what
== MODE_ADD
|| source_p
->umodes
& UMODE_SERVNOTICE
)
1064 if(what
== MODE_ADD
)
1067 source_p
->snomask
= parse_snobuf_to_mask(source_p
->snomask
, parv
[3]);
1069 source_p
->snomask
|= SNO_GENERAL
;
1072 source_p
->snomask
= 0;
1073 if (source_p
->snomask
!= 0)
1074 source_p
->umodes
|= UMODE_SERVNOTICE
;
1076 source_p
->umodes
&= ~UMODE_SERVNOTICE
;
1081 if (MyConnect(source_p
) && *pm
== 'Q' && !ConfigChannel
.use_forward
)
1087 if((flag
= user_modes
[(unsigned char) *pm
]))
1089 if(MyConnect(source_p
)
1090 && ((!IsOper(source_p
)
1091 && (ConfigFileEntry
.oper_only_umodes
& flag
))
1092 || (orphaned_umodes
& flag
)))
1094 if (what
== MODE_ADD
|| source_p
->umodes
& flag
)
1099 if(what
== MODE_ADD
)
1100 source_p
->umodes
|= flag
;
1102 source_p
->umodes
&= ~flag
;
1107 if(MyConnect(source_p
))
1114 sendto_one(source_p
, form_str(ERR_UMODEUNKNOWNFLAG
), me
.name
, source_p
->name
);
1116 if(MyClient(source_p
) && (source_p
->snomask
& SNO_NCHANGE
) && !IsOperN(source_p
))
1118 sendto_one_notice(source_p
, ":*** You need oper and nick_changes flag for +s +n");
1119 source_p
->snomask
&= ~SNO_NCHANGE
; /* only tcm's really need this */
1122 if(MyClient(source_p
) && (source_p
->umodes
& UMODE_OPERWALL
) && !IsOperOperwall(source_p
))
1124 sendto_one_notice(source_p
, ":*** You need oper and operwall flag for +z");
1125 source_p
->umodes
&= ~UMODE_OPERWALL
;
1128 if(MyConnect(source_p
) && (source_p
->umodes
& UMODE_ADMIN
) &&
1129 (!IsOperAdmin(source_p
) || IsOperHiddenAdmin(source_p
)))
1131 sendto_one_notice(source_p
, ":*** You need oper and admin flag for +a");
1132 source_p
->umodes
&= ~UMODE_ADMIN
;
1135 /* let modules providing usermodes know that we've changed our usermode --nenolod */
1136 hdata
.client
= source_p
;
1137 hdata
.oldumodes
= setflags
;
1138 hdata
.oldsnomask
= setsnomask
;
1139 call_hook(h_umode_changed
, &hdata
);
1141 if(!(setflags
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1143 if((setflags
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1146 * compare new flags with old flags and send string which
1147 * will cause servers to update correctly.
1149 send_umode_out(client_p
, source_p
, setflags
);
1150 if (showsnomask
&& MyConnect(source_p
))
1151 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1152 construct_snobuf(source_p
->snomask
));
1158 * send the MODE string for user (user) to connection client_p
1162 send_umode(struct Client
*client_p
, struct Client
*source_p
, int old
, char *umode_buf
)
1170 * build a string in umode_buf to represent the change in the user's
1171 * mode between the new (source_p->flag) and 'old'.
1176 for (i
= 0; i
< 128; i
++)
1178 flag
= user_modes
[i
];
1180 if((flag
& old
) && !(source_p
->umodes
& flag
))
1182 if(what
== MODE_DEL
)
1191 else if(!(flag
& old
) && (source_p
->umodes
& flag
))
1193 if(what
== MODE_ADD
)
1205 if(*umode_buf
&& client_p
)
1206 sendto_one(client_p
, ":%s MODE %s :%s", source_p
->name
, source_p
->name
, umode_buf
);
1217 send_umode_out(struct Client
*client_p
, struct Client
*source_p
, int old
)
1219 struct Client
*target_p
;
1223 send_umode(NULL
, source_p
, old
, buf
);
1225 RB_DLINK_FOREACH(ptr
, serv_list
.head
)
1227 target_p
= ptr
->data
;
1229 if((target_p
!= client_p
) && (target_p
!= source_p
) && (*buf
))
1231 sendto_one(target_p
, ":%s MODE %s :%s",
1232 get_id(source_p
, target_p
),
1233 get_id(source_p
, target_p
), buf
);
1237 if(client_p
&& MyClient(client_p
))
1238 send_umode(client_p
, source_p
, old
, buf
);
1244 * inputs - client pointer to client to welcome
1249 user_welcome(struct Client
*source_p
)
1251 sendto_one_numeric(source_p
, RPL_WELCOME
, form_str(RPL_WELCOME
), ServerInfo
.network_name
, source_p
->name
);
1252 sendto_one_numeric(source_p
, RPL_YOURHOST
, form_str(RPL_YOURHOST
),
1253 get_listener_name(source_p
->localClient
->listener
), ircd_version
);
1254 sendto_one_numeric(source_p
, RPL_CREATED
, form_str(RPL_CREATED
), creation
);
1255 sendto_one_numeric(source_p
, RPL_MYINFO
, form_str(RPL_MYINFO
), me
.name
, ircd_version
, umodebuf
, cflagsmyinfo
);
1257 show_isupport(source_p
);
1259 show_lusers(source_p
);
1261 if(ConfigFileEntry
.short_motd
)
1263 sendto_one_notice(source_p
, ":*** Notice -- motd was last changed at %s", user_motd_changed
);
1264 sendto_one_notice(source_p
, ":*** Notice -- Please read the motd if you haven't read it");
1266 sendto_one(source_p
, form_str(RPL_MOTDSTART
),
1267 me
.name
, source_p
->name
, me
.name
);
1269 sendto_one(source_p
, form_str(RPL_MOTD
),
1270 me
.name
, source_p
->name
, "*** This is the short motd ***");
1272 sendto_one(source_p
, form_str(RPL_ENDOFMOTD
), me
.name
, source_p
->name
);
1275 send_user_motd(source_p
);
1280 * inputs - pointer to given client to oper
1281 * - pointer to ConfItem to use
1283 * side effects - opers up source_p using aconf for reference
1286 oper_up(struct Client
*source_p
, struct oper_conf
*oper_p
)
1288 unsigned int old
= source_p
->umodes
, oldsnomask
= source_p
->snomask
;
1289 hook_data_umode_changed hdata
;
1294 source_p
->umodes
|= oper_p
->umodes
;
1295 else if(ConfigFileEntry
.oper_umodes
)
1296 source_p
->umodes
|= ConfigFileEntry
.oper_umodes
;
1298 source_p
->umodes
|= DEFAULT_OPER_UMODES
;
1300 if (oper_p
->snomask
)
1302 source_p
->snomask
|= oper_p
->snomask
;
1303 source_p
->umodes
|= UMODE_SERVNOTICE
;
1305 else if (source_p
->umodes
& UMODE_SERVNOTICE
)
1307 /* Only apply these if +s is already set -- jilles */
1308 if (ConfigFileEntry
.oper_snomask
)
1309 source_p
->snomask
|= ConfigFileEntry
.oper_snomask
;
1311 source_p
->snomask
|= DEFAULT_OPER_SNOMASK
;
1316 SetExtendChans(source_p
);
1317 SetExemptKline(source_p
);
1319 source_p
->flags2
|= oper_p
->flags
;
1320 source_p
->localClient
->opername
= rb_strdup(oper_p
->name
);
1321 source_p
->localClient
->privset
= privilegeset_ref(oper_p
->privset
);
1323 rb_dlinkAddAlloc(source_p
, &local_oper_list
);
1324 rb_dlinkAddAlloc(source_p
, &oper_list
);
1326 if(IsOperAdmin(source_p
) && !IsOperHiddenAdmin(source_p
))
1327 source_p
->umodes
|= UMODE_ADMIN
;
1328 if(!IsOperN(source_p
))
1329 source_p
->snomask
&= ~SNO_NCHANGE
;
1330 if(!IsOperOperwall(source_p
))
1331 source_p
->umodes
&= ~UMODE_OPERWALL
;
1332 hdata
.client
= source_p
;
1333 hdata
.oldumodes
= old
;
1334 hdata
.oldsnomask
= oldsnomask
;
1335 call_hook(h_umode_changed
, &hdata
);
1337 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
1338 "%s (%s!%s@%s) is now an operator", oper_p
->name
, source_p
->name
,
1339 source_p
->username
, source_p
->host
);
1340 if(!(old
& UMODE_INVISIBLE
) && IsInvisible(source_p
))
1342 if((old
& UMODE_INVISIBLE
) && !IsInvisible(source_p
))
1344 send_umode_out(source_p
, source_p
, old
);
1345 sendto_one_numeric(source_p
, RPL_SNOMASK
, form_str(RPL_SNOMASK
),
1346 construct_snobuf(source_p
->snomask
));
1347 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
1348 sendto_one_notice(source_p
, ":*** Oper privilege set is %s", oper_p
->privset
->name
);
1349 sendto_one_notice(source_p
, ":*** Oper privs are %s", oper_p
->privset
->privs
);
1350 send_oper_motd(source_p
);
1359 * outputs - an available umode bitmask or
1360 * 0 if no umodes are available
1361 * side effects - NONE
1364 find_umode_slot(void)
1366 unsigned int all_umodes
= 0, my_umode
= 0, i
;
1368 for (i
= 0; i
< 128; i
++)
1369 all_umodes
|= user_modes
[i
];
1371 for (my_umode
= 1; my_umode
&& (all_umodes
& my_umode
);
1378 construct_umodebuf(void)
1381 char *ptr
= umodebuf
;
1382 static int prev_user_modes
[128];
1386 for (i
= 0; i
< 128; i
++)
1388 if (prev_user_modes
[i
] != 0 && prev_user_modes
[i
] != user_modes
[i
])
1390 if (user_modes
[i
] == 0)
1392 orphaned_umodes
|= prev_user_modes
[i
];
1393 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Umode +%c is now orphaned", i
);
1397 orphaned_umodes
&= ~prev_user_modes
[i
];
1398 sendto_realops_snomask(SNO_DEBUG
, L_ALL
, "Orphaned umode +%c is picked up by module", i
);
1400 user_modes
[i
] = prev_user_modes
[i
];
1403 prev_user_modes
[i
] = user_modes
[i
];
1412 change_nick_user_host(struct Client
*target_p
, const char *nick
, const char *user
,
1413 const char *host
, int newts
, const char *format
, ...)
1416 struct Channel
*chptr
;
1417 struct membership
*mscptr
;
1418 int changed
= irccmp(target_p
->name
, nick
);
1419 int changed_case
= strcmp(target_p
->name
, nick
);
1420 int do_qjm
= irccmp(target_p
->username
, user
) || irccmp(target_p
->host
, host
);
1421 char mode
[10], modeval
[NICKLEN
* 2 + 2], reason
[256], *mptr
;
1428 target_p
->tsinfo
= newts
;
1429 monitor_signoff(target_p
);
1431 invalidate_bancache_user(target_p
);
1435 va_start(ap
, format
);
1436 vsnprintf(reason
, 255, format
, ap
);
1439 sendto_common_channels_local_butone(target_p
, NOCAPS
, CLICAP_CHGHOST
, ":%s!%s@%s QUIT :%s",
1440 target_p
->name
, target_p
->username
, target_p
->host
,
1443 RB_DLINK_FOREACH(ptr
, target_p
->user
->channel
.head
)
1446 chptr
= mscptr
->chptr
;
1449 if(is_chanop(mscptr
))
1452 strcat(modeval
, nick
);
1453 strcat(modeval
, " ");
1456 if(is_voiced(mscptr
))
1459 strcat(modeval
, nick
);
1464 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, NOCAPS
, CLICAP_EXTENDED_JOIN
| CLICAP_CHGHOST
, chptr
,
1465 ":%s!%s@%s JOIN %s", nick
, user
, host
, chptr
->chname
);
1466 sendto_channel_local_with_capability_butone(target_p
, ALL_MEMBERS
, CLICAP_EXTENDED_JOIN
, CLICAP_CHGHOST
, chptr
,
1467 ":%s!%s@%s JOIN %s %s :%s", nick
, user
, host
, chptr
->chname
,
1468 EmptyString(target_p
->user
->suser
) ? "*" : target_p
->user
->suser
,
1472 sendto_channel_local_butone(target_p
, ALL_MEMBERS
, chptr
,
1473 ":%s MODE %s +%s %s",
1474 target_p
->servptr
->name
,
1475 chptr
->chname
, mode
, modeval
);
1480 /* Resend away message to away-notify enabled clients. */
1481 if (target_p
->user
->away
)
1482 sendto_common_channels_local_butone(target_p
, CLICAP_AWAY_NOTIFY
, CLICAP_CHGHOST
, ":%s!%s@%s AWAY :%s",
1484 target_p
->user
->away
);
1486 sendto_common_channels_local_butone(target_p
, CLICAP_CHGHOST
, NOCAPS
,
1487 ":%s!%s@%s CHGHOST %s %s",
1488 target_p
->name
, target_p
->username
, target_p
->host
, user
, host
);
1490 if(MyClient(target_p
) && changed_case
)
1491 sendto_one(target_p
, ":%s!%s@%s NICK %s",
1492 target_p
->name
, user
, host
, nick
);
1494 /* TODO: send some snotes to SNO_NCHANGE/SNO_CCONN/SNO_CCONNEXT? */
1496 else if(changed_case
)
1498 sendto_common_channels_local(target_p
, NOCAPS
, NOCAPS
, ":%s!%s@%s NICK :%s",
1499 target_p
->name
, user
, host
, nick
);
1501 if(MyConnect(target_p
))
1502 sendto_realops_snomask(SNO_NCHANGE
, L_ALL
,
1503 "Nick change: From %s to %s [%s@%s]",
1504 target_p
->name
, nick
,
1505 target_p
->username
, target_p
->host
);
1508 if (user
!= target_p
->username
)
1509 rb_strlcpy(target_p
->username
, user
, sizeof target_p
->username
);
1511 rb_strlcpy(target_p
->host
, host
, sizeof target_p
->host
);
1514 whowas_add_history(target_p
, 1);
1516 del_from_client_hash(target_p
->name
, target_p
);
1517 rb_strlcpy(target_p
->name
, nick
, NICKLEN
);
1518 add_to_client_hash(target_p
->name
, target_p
);
1522 monitor_signon(target_p
);
1523 del_all_accepts(target_p
);