0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-03 12:28:52 +01:00
construct/ircd/s_user.cc

1423 lines
39 KiB
C++
Raw Normal View History

/*
* ircd-ratbox: A slightly useful ircd.
* s_user.c: User related functions.
*
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
* Copyright (C) 1996-2002 Hybrid Development Team
* Copyright (C) 2002-2005 ircd-ratbox development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
2016-08-13 05:05:54 +02:00
namespace ircd {
static void report_and_set_user_flags(client::client *, struct ConfItem *);
void user_welcome(client::client *source_p);
/*
* show_lusers -
*
* inputs - pointer to client
* output -
* side effects - display to client user counts etc.
*/
void
show_lusers(client::client *source_p)
{
2008-04-01 22:41:52 +02:00
if(rb_dlink_list_length(&lclient_list) > (unsigned long)MaxClientCount)
MaxClientCount = rb_dlink_list_length(&lclient_list);
2008-04-01 22:41:52 +02:00
if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) >
(unsigned long)MaxConnectionCount)
MaxConnectionCount = rb_dlink_list_length(&lclient_list) +
2008-04-01 22:41:52 +02:00
rb_dlink_list_length(&serv_list);
sendto_one_numeric(source_p, RPL_LUSERCLIENT, form_str(RPL_LUSERCLIENT),
(Count.total - Count.invisi),
Count.invisi,
(int)rb_dlink_list_length(&global_serv_list));
2008-04-01 22:41:52 +02:00
if(rb_dlink_list_length(&oper_list) > 0)
sendto_one_numeric(source_p, RPL_LUSEROP,
2014-02-23 22:46:06 +01:00
form_str(RPL_LUSEROP),
(int)rb_dlink_list_length(&oper_list));
2008-04-01 22:41:52 +02:00
if(rb_dlink_list_length(&unknown_list) > 0)
sendto_one_numeric(source_p, RPL_LUSERUNKNOWN,
form_str(RPL_LUSERUNKNOWN),
(int)rb_dlink_list_length(&unknown_list));
2016-08-20 04:51:37 +02:00
if(!chan::chans.empty())
sendto_one_numeric(source_p, RPL_LUSERCHANNELS,
form_str(RPL_LUSERCHANNELS),
2016-08-20 04:51:37 +02:00
chan::chans.size());
sendto_one_numeric(source_p, RPL_LUSERME, form_str(RPL_LUSERME),
(int)rb_dlink_list_length(&lclient_list),
(int)rb_dlink_list_length(&serv_list));
sendto_one_numeric(source_p, RPL_LOCALUSERS,
form_str(RPL_LOCALUSERS),
(int)rb_dlink_list_length(&lclient_list),
Count.max_loc,
(int)rb_dlink_list_length(&lclient_list),
Count.max_loc);
sendto_one_numeric(source_p, RPL_GLOBALUSERS, form_str(RPL_GLOBALUSERS),
Count.total, Count.max_tot,
Count.total, Count.max_tot);
sendto_one_numeric(source_p, RPL_STATSCONN,
form_str(RPL_STATSCONN),
MaxConnectionCount, MaxClientCount,
Count.totalrestartcount);
}
2016-04-10 17:02:33 +02:00
/* check if we should exit a client due to authd decision
* inputs - client server, client connecting
* outputs - true if exited, false if not
* side effects - messages/exits client if authd rejected and not exempt
*/
static bool
authd_check(client::client *client_p, client::client *source_p)
2016-04-10 17:02:33 +02:00
{
struct ConfItem *aconf = source_p->localClient->att_conf;
rb_dlink_list varlist = { NULL, NULL, 0 };
bool reject = false;
char *reason;
if(source_p->preClient->auth.accepted == true)
return reject;
substitution_append_var(&varlist, "nick", source_p->name);
substitution_append_var(&varlist, "ip", source_p->sockhost);
substitution_append_var(&varlist, "host", source_p->host);
substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->auth.data);
substitution_append_var(&varlist, "network-name", ServerInfo.network_name);
reason = substitution_parse(source_p->preClient->auth.reason, &varlist);
switch(source_p->preClient->auth.cause)
{
case 'B': /* Blacklists */
{
struct BlacklistStats *stats;
2016-04-10 17:02:33 +02:00
char *blacklist = source_p->preClient->auth.data;
if(bl_stats != NULL)
if((stats = (BlacklistStats *)rb_dictionary_retrieve(bl_stats, blacklist)) != NULL)
stats->hits++;
2016-04-10 17:02:33 +02:00
2016-08-23 04:33:36 +02:00
if(is_exempt_kline(*source_p) || IsConfExemptDNSBL(aconf))
2016-04-10 17:02:33 +02:00
{
sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s, but you are exempt",
source_p->sockhost, blacklist);
break;
}
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::REJ, L_NETWIDE,
2016-04-10 17:02:33 +02:00
"Listed on DNSBL %s: %s (%s@%s) [%s] [%s]",
blacklist, source_p->name, source_p->username, source_p->host,
2016-08-23 04:33:36 +02:00
is_ip_spoof(*source_p) ? "255.255.255.255" : source_p->sockhost,
2016-04-10 17:02:33 +02:00
source_p->info);
sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
me.name, source_p->name, reason);
sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s",
source_p->sockhost, blacklist);
add_reject(source_p, NULL, NULL);
exit_client(client_p, source_p, &me, "Banned (DNS blacklist)");
reject = true;
}
break;
case 'O': /* OPM */
{
char *proxy = source_p->preClient->auth.data;
char *port = strrchr(proxy, ':');
if(port == NULL)
{
/* This shouldn't happen, better tell the ops... */
ierror("authd sent us a malformed OPM string %s", proxy);
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::GENERAL, L_ALL,
2016-04-10 17:02:33 +02:00
"authd sent us a malformed OPM string %s", proxy);
break;
}
/* Terminate the proxy type */
*(port++) = '\0';
2016-08-23 04:33:36 +02:00
if(is_exempt_kline(*source_p) || IsConfExemptProxy(aconf))
2016-04-10 17:02:33 +02:00
{
sendto_one_notice(source_p,
":*** Your IP address %s has been detected as an open proxy (type %s, port %s), but you are exempt",
source_p->sockhost, proxy, port);
break;
}
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::REJ, L_NETWIDE,
2016-04-10 17:02:33 +02:00
"Open proxy %s/%s: %s (%s@%s) [%s] [%s]",
proxy, port,
source_p->name,
source_p->username, source_p->host,
2016-08-23 04:33:36 +02:00
is_ip_spoof(*source_p) ? "255.255.255.255" : source_p->sockhost,
2016-04-10 17:02:33 +02:00
source_p->info);
sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
me.name, source_p->name, reason);
sendto_one_notice(source_p,
":*** Your IP address %s has been detected as an open proxy (type %s, port %s)",
source_p->sockhost, proxy, port);
add_reject(source_p, NULL, NULL);
exit_client(client_p, source_p, &me, "Banned (Open proxy)");
reject = true;
}
break;
default: /* Unknown, but handle the case properly */
2016-08-23 04:33:36 +02:00
if(is_exempt_kline(*source_p))
2016-04-10 17:02:33 +02:00
{
sendto_one_notice(source_p,
":*** You were rejected, but you are exempt (reason: %s)",
reason);
break;
}
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::REJ, L_NETWIDE,
2016-04-10 17:02:33 +02:00
"Rejected by authentication system (reason %s): %s (%s@%s) [%s] [%s]",
reason, source_p->name, source_p->username, source_p->host,
2016-08-23 04:33:36 +02:00
is_ip_spoof(*source_p) ? "255.255.255.255" : source_p->sockhost,
2016-04-10 17:02:33 +02:00
source_p->info);
sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP),
me.name, source_p->name, reason);
sendto_one_notice(source_p, ":*** Rejected by authentication system: %s",
reason);
add_reject(source_p, NULL, NULL);
exit_client(client_p, source_p, &me, "Banned (authentication system)");
reject = true;
break;
}
if(reject)
ServerStats.is_ref++;
substitution_free(&varlist);
return reject;
}
/*
** register_local_user
** This function is called when both NICK and USER messages
** have been accepted for the client, in whatever order. Only
** after this, is the USER message propagated.
**
** NICK's must be propagated at once when received, although
** it would be better to delay them too until full info is
** available. Doing it is not so simple though, would have
** to implement the following:
**
** (actually it has been implemented already for a while) -orabidoo
**
** 1) user telnets in and gives only "NICK foobar" and waits
** 2) another user far away logs in normally with the nick
** "foobar" (quite legal, as this server didn't propagate
** it).
** 3) now this server gets nick "foobar" from outside, but
** has alread the same defined locally. Current server
** would just issue "KILL foobar" to clean out dups. But,
** this is not fair. It should actually request another
** nick from local user or kill him/her...
*/
int
register_local_user(client::client *client_p, client::client *source_p)
{
struct ConfItem *aconf, *xconf;
char tmpstr2[BUFSIZE];
char ipaddr[HOSTIPLEN];
char myusername[USERLEN+1];
int status;
s_assert(NULL != source_p);
2016-08-23 04:33:36 +02:00
s_assert(my_connect(*source_p));
if(source_p == NULL)
return -1;
2016-08-23 04:33:36 +02:00
if(is_any_dead(*source_p))
return -1;
if(ConfigFileEntry.ping_cookie)
{
2016-08-23 04:33:36 +02:00
if(!(source_p->flags & client::flags::PINGSENT) && source_p->localClient->random_ping == 0)
{
source_p->localClient->random_ping = (uint32_t)(((rand() * rand()) << 1) | 1);
sendto_one(source_p, "PING :%08X",
(unsigned int) source_p->localClient->random_ping);
2016-08-23 04:33:36 +02:00
source_p->flags |= client::flags::PINGSENT;
return -1;
}
2016-08-23 04:33:36 +02:00
if(!(source_p->flags & client::flags::PING_COOKIE))
{
return -1;
}
}
/* hasnt finished client cap negotiation */
2016-08-23 04:33:36 +02:00
if(source_p->flags & client::flags::CLICAP)
return -1;
/* Waiting on authd */
if(source_p->preClient->auth.cid)
return -1;
2008-04-02 01:53:20 +02:00
client_p->localClient->last = rb_current_time();
/* XXX - fixme. we shouldnt have to build a users buffer twice.. */
2016-08-23 04:33:36 +02:00
if(!is_got_id(*source_p) && (strchr(source_p->username, '[') != NULL))
{
const char *p;
int i = 0;
p = source_p->username;
while(*p && i < USERLEN)
{
if(*p != '[')
myusername[i++] = *p;
p++;
}
myusername[i] = '\0';
}
else
2015-10-01 22:54:29 +02:00
rb_strlcpy(myusername, source_p->username, sizeof myusername);
if((status = check_client(client_p, source_p, myusername)) < 0)
return (CLIENT_EXITED);
/* Apply nick override */
if(*source_p->preClient->spoofnick)
{
2008-04-02 03:36:50 +02:00
char note[NICKLEN + 10];
del_from_client_hash(source_p->name, source_p);
2008-04-20 06:40:40 +02:00
rb_strlcpy(source_p->name, source_p->preClient->spoofnick, NICKLEN + 1);
add_to_client_hash(source_p->name, source_p);
2008-04-02 03:36:50 +02:00
snprintf(note, NICKLEN + 10, "Nick: %s", source_p->name);
2008-04-02 03:36:50 +02:00
rb_note(source_p->localClient->F, note);
}
if(!valid_hostname(source_p->host))
{
[svn] Backport from early 3.x: -- nenolod 2006/09/27 16:39:14 UTC (20060927-2178) Log: - remove "Processing connection to foobar.net" message Changes: Modified: +0 -3 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:34:26 UTC (20060927-2176) Log: - missed the processing connection one (actually, we can probably nuke this one) Changes: Modified: +1 -2 trunk/src/s_auth.c (File Modified) river 2006/09/27 16:33:05 UTC (20060927-2174) Log: get_client_name = stupid Changes: Modified: +10 -7 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:32:37 UTC (20060927-2172) Log: - remove excessive arguments Changes: Modified: +1 -2 trunk/src/s_conf.c (File Modified) +1 -1 trunk/src/s_user.c (File Modified) nenolod 2006/09/27 16:30:59 UTC (20060927-2170) Log: - use sendto_one_notice() for on-connect notices too. Changes: Modified: +10 -10 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:27:01 UTC (20060927-2168) Log: - use sendto_one_notice() in the core, too. Changes: Modified: +2 -2 trunk/src/chmode.c (File Modified) +8 -15 trunk/src/modules.c (File Modified) +3 -5 trunk/src/s_conf.c (File Modified) +1 -2 trunk/src/s_newconf.c (File Modified) +20 -57 trunk/src/s_user.c (File Modified) river 2006/09/27 16:19:25 UTC (20060927-2166) Log: the KILL command will use get_client_name(, SHOW_IP) instead of target->name, and will show a more useful error for local opers Changes: Modified: +6 -4 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:09:48 UTC (20060927-2164) Log: - fix bugs in sendto_one_notice()/sendto_one_numeric() where a client identifier won't be sent to unregistered clients Changes: Modified: +4 -2 trunk/src/send.c (File Modified) nenolod 2006/09/27 16:05:46 UTC (20060927-2161) Log: - back out r2159 Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:04:05 UTC (20060927-2159) Log: - get_id(): fall back to "*" if client has no known name Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:01:29 UTC (20060927-2157) Log: - convert to sendto_one_notice(). Changes: Modified: +2 -3 trunk/unsupported/m_clearchan.c (File Modified) +4 -6 trunk/unsupported/m_force.c (File Modified) nenolod 2006/09/27 15:57:11 UTC (20060927-2155) Log: - use sendto_one_notice() in many places instead of sendto_one(source_p, ":%s NOTICE %s :", ...); Changes: Modified: +10 -25 trunk/extensions/example_module.c (File Modified) +5 -14 trunk/extensions/hurt.c (File Modified) +1 -2 trunk/extensions/m_42.c (File Modified) +7 -12 trunk/extensions/m_mkpasswd.c (File Modified) +1 -2 trunk/extensions/m_ojoin.c (File Modified) +1 -2 trunk/extensions/m_opme.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice_global.c (File Modified) +3 -7 trunk/modules/core/m_die.c (File Modified) +2 -4 trunk/modules/core/m_kill.c (File Modified) +2 -2 trunk/modules/core/m_squit.c (File Modified) +1 -2 trunk/modules/m_challenge.c (File Modified) +11 -15 trunk/modules/m_connect.c (File Modified) +20 -28 trunk/modules/m_dline.c (File Modified) +2 -2 trunk/modules/m_etrace.c (File Modified) +11 -21 trunk/modules/m_gline.c (File Modified) +2 -4 trunk/modules/m_kline.c (File Modified) +1 -2 trunk/modules/m_rehash.c (File Modified) +3 -7 trunk/modules/m_restart.c (File Modified) +31 -45 trunk/modules/m_set.c (File Modified) +2 -4 trunk/modules/m_testmask.c (File Modified) +5 -8 trunk/modules/m_unreject.c (File Modified) +2 -5 trunk/modules/m_xline.c (File Modified) --
2007-01-25 08:23:01 +01:00
sendto_one_notice(source_p, ":*** Notice -- You have an illegal character in your hostname");
2008-04-20 06:40:40 +02:00
rb_strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
}
aconf = source_p->localClient->att_conf;
if(aconf == NULL)
{
exit_client(client_p, source_p, &me, "*** Not Authorised");
return (CLIENT_EXITED);
}
if(IsConfSSLNeeded(aconf) && !IsSSL(source_p))
{
ServerStats.is_ref++;
sendto_one_notice(source_p, ":*** Notice -- You need to use SSL/TLS to use this server");
exit_client(client_p, source_p, &me, "Use SSL/TLS");
return (CLIENT_EXITED);
}
2016-08-23 04:33:36 +02:00
if(!is_got_id(*source_p))
{
const char *p;
int i = 0;
if(IsNeedIdentd(aconf))
{
ServerStats.is_ref++;
[svn] Backport from early 3.x: -- nenolod 2006/09/27 16:39:14 UTC (20060927-2178) Log: - remove "Processing connection to foobar.net" message Changes: Modified: +0 -3 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:34:26 UTC (20060927-2176) Log: - missed the processing connection one (actually, we can probably nuke this one) Changes: Modified: +1 -2 trunk/src/s_auth.c (File Modified) river 2006/09/27 16:33:05 UTC (20060927-2174) Log: get_client_name = stupid Changes: Modified: +10 -7 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:32:37 UTC (20060927-2172) Log: - remove excessive arguments Changes: Modified: +1 -2 trunk/src/s_conf.c (File Modified) +1 -1 trunk/src/s_user.c (File Modified) nenolod 2006/09/27 16:30:59 UTC (20060927-2170) Log: - use sendto_one_notice() for on-connect notices too. Changes: Modified: +10 -10 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:27:01 UTC (20060927-2168) Log: - use sendto_one_notice() in the core, too. Changes: Modified: +2 -2 trunk/src/chmode.c (File Modified) +8 -15 trunk/src/modules.c (File Modified) +3 -5 trunk/src/s_conf.c (File Modified) +1 -2 trunk/src/s_newconf.c (File Modified) +20 -57 trunk/src/s_user.c (File Modified) river 2006/09/27 16:19:25 UTC (20060927-2166) Log: the KILL command will use get_client_name(, SHOW_IP) instead of target->name, and will show a more useful error for local opers Changes: Modified: +6 -4 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:09:48 UTC (20060927-2164) Log: - fix bugs in sendto_one_notice()/sendto_one_numeric() where a client identifier won't be sent to unregistered clients Changes: Modified: +4 -2 trunk/src/send.c (File Modified) nenolod 2006/09/27 16:05:46 UTC (20060927-2161) Log: - back out r2159 Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:04:05 UTC (20060927-2159) Log: - get_id(): fall back to "*" if client has no known name Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:01:29 UTC (20060927-2157) Log: - convert to sendto_one_notice(). Changes: Modified: +2 -3 trunk/unsupported/m_clearchan.c (File Modified) +4 -6 trunk/unsupported/m_force.c (File Modified) nenolod 2006/09/27 15:57:11 UTC (20060927-2155) Log: - use sendto_one_notice() in many places instead of sendto_one(source_p, ":%s NOTICE %s :", ...); Changes: Modified: +10 -25 trunk/extensions/example_module.c (File Modified) +5 -14 trunk/extensions/hurt.c (File Modified) +1 -2 trunk/extensions/m_42.c (File Modified) +7 -12 trunk/extensions/m_mkpasswd.c (File Modified) +1 -2 trunk/extensions/m_ojoin.c (File Modified) +1 -2 trunk/extensions/m_opme.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice_global.c (File Modified) +3 -7 trunk/modules/core/m_die.c (File Modified) +2 -4 trunk/modules/core/m_kill.c (File Modified) +2 -2 trunk/modules/core/m_squit.c (File Modified) +1 -2 trunk/modules/m_challenge.c (File Modified) +11 -15 trunk/modules/m_connect.c (File Modified) +20 -28 trunk/modules/m_dline.c (File Modified) +2 -2 trunk/modules/m_etrace.c (File Modified) +11 -21 trunk/modules/m_gline.c (File Modified) +2 -4 trunk/modules/m_kline.c (File Modified) +1 -2 trunk/modules/m_rehash.c (File Modified) +3 -7 trunk/modules/m_restart.c (File Modified) +31 -45 trunk/modules/m_set.c (File Modified) +2 -4 trunk/modules/m_testmask.c (File Modified) +5 -8 trunk/modules/m_unreject.c (File Modified) +2 -5 trunk/modules/m_xline.c (File Modified) --
2007-01-25 08:23:01 +01:00
sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server");
exit_client(client_p, source_p, &me, "Install identd");
return (CLIENT_EXITED);
}
/* dont replace username if its supposed to be spoofed --fl */
if(!IsConfDoSpoofIp(aconf) || !strchr(aconf->info.name, '@'))
{
p = myusername;
if(!IsNoTilde(aconf))
source_p->username[i++] = '~';
while (*p && i < USERLEN)
{
if(*p != '[')
source_p->username[i++] = *p;
p++;
}
source_p->username[i] = '\0';
}
}
if(IsNeedSasl(aconf) && suser(user(*source_p)).empty())
{
ServerStats.is_ref++;
[svn] Backport from early 3.x: -- nenolod 2006/09/27 16:39:14 UTC (20060927-2178) Log: - remove "Processing connection to foobar.net" message Changes: Modified: +0 -3 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:34:26 UTC (20060927-2176) Log: - missed the processing connection one (actually, we can probably nuke this one) Changes: Modified: +1 -2 trunk/src/s_auth.c (File Modified) river 2006/09/27 16:33:05 UTC (20060927-2174) Log: get_client_name = stupid Changes: Modified: +10 -7 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:32:37 UTC (20060927-2172) Log: - remove excessive arguments Changes: Modified: +1 -2 trunk/src/s_conf.c (File Modified) +1 -1 trunk/src/s_user.c (File Modified) nenolod 2006/09/27 16:30:59 UTC (20060927-2170) Log: - use sendto_one_notice() for on-connect notices too. Changes: Modified: +10 -10 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:27:01 UTC (20060927-2168) Log: - use sendto_one_notice() in the core, too. Changes: Modified: +2 -2 trunk/src/chmode.c (File Modified) +8 -15 trunk/src/modules.c (File Modified) +3 -5 trunk/src/s_conf.c (File Modified) +1 -2 trunk/src/s_newconf.c (File Modified) +20 -57 trunk/src/s_user.c (File Modified) river 2006/09/27 16:19:25 UTC (20060927-2166) Log: the KILL command will use get_client_name(, SHOW_IP) instead of target->name, and will show a more useful error for local opers Changes: Modified: +6 -4 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:09:48 UTC (20060927-2164) Log: - fix bugs in sendto_one_notice()/sendto_one_numeric() where a client identifier won't be sent to unregistered clients Changes: Modified: +4 -2 trunk/src/send.c (File Modified) nenolod 2006/09/27 16:05:46 UTC (20060927-2161) Log: - back out r2159 Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:04:05 UTC (20060927-2159) Log: - get_id(): fall back to "*" if client has no known name Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:01:29 UTC (20060927-2157) Log: - convert to sendto_one_notice(). Changes: Modified: +2 -3 trunk/unsupported/m_clearchan.c (File Modified) +4 -6 trunk/unsupported/m_force.c (File Modified) nenolod 2006/09/27 15:57:11 UTC (20060927-2155) Log: - use sendto_one_notice() in many places instead of sendto_one(source_p, ":%s NOTICE %s :", ...); Changes: Modified: +10 -25 trunk/extensions/example_module.c (File Modified) +5 -14 trunk/extensions/hurt.c (File Modified) +1 -2 trunk/extensions/m_42.c (File Modified) +7 -12 trunk/extensions/m_mkpasswd.c (File Modified) +1 -2 trunk/extensions/m_ojoin.c (File Modified) +1 -2 trunk/extensions/m_opme.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice_global.c (File Modified) +3 -7 trunk/modules/core/m_die.c (File Modified) +2 -4 trunk/modules/core/m_kill.c (File Modified) +2 -2 trunk/modules/core/m_squit.c (File Modified) +1 -2 trunk/modules/m_challenge.c (File Modified) +11 -15 trunk/modules/m_connect.c (File Modified) +20 -28 trunk/modules/m_dline.c (File Modified) +2 -2 trunk/modules/m_etrace.c (File Modified) +11 -21 trunk/modules/m_gline.c (File Modified) +2 -4 trunk/modules/m_kline.c (File Modified) +1 -2 trunk/modules/m_rehash.c (File Modified) +3 -7 trunk/modules/m_restart.c (File Modified) +31 -45 trunk/modules/m_set.c (File Modified) +2 -4 trunk/modules/m_testmask.c (File Modified) +5 -8 trunk/modules/m_unreject.c (File Modified) +2 -5 trunk/modules/m_xline.c (File Modified) --
2007-01-25 08:23:01 +01:00
sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server");
exit_client(client_p, source_p, &me, "SASL access only");
return (CLIENT_EXITED);
}
/* password check */
if(!EmptyString(aconf->passwd))
{
const char *encr;
if(EmptyString(source_p->localClient->passwd))
encr = "";
else if(IsConfEncrypted(aconf))
2008-07-27 12:52:46 +02:00
encr = rb_crypt(source_p->localClient->passwd, aconf->passwd);
else
encr = source_p->localClient->passwd;
2013-02-02 00:54:32 +01:00
if(encr == NULL || strcmp(encr, aconf->passwd))
{
ServerStats.is_ref++;
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
exit_client(client_p, source_p, &me, "Bad Password");
return (CLIENT_EXITED);
}
/* clear password only if used now, otherwise send it
* to services -- jilles */
if(source_p->localClient->passwd)
{
memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
rb_free(source_p->localClient->passwd);
source_p->localClient->passwd = NULL;
}
}
2016-04-10 17:02:33 +02:00
/* report and set flags (kline exempt etc.) as needed in source_p */
report_and_set_user_flags(source_p, aconf);
/* Limit clients */
/*
* We want to be able to have servers and F-line clients
* connect, so save room for "buffer" connections.
* Smaller servers may want to decrease this, and it should
* probably be just a percentage of the MAXCLIENTS...
* -Taner
*/
/* Except "F:" clients */
2008-04-01 22:41:52 +02:00
if(rb_dlink_list_length(&lclient_list) >=
(unsigned long)GlobalSetOptions.maxclients && !IsConfExemptLimits(aconf))
{
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::FULL, L_ALL,
"Too many clients, rejecting %s[%s].", source_p->name, source_p->host);
ServerStats.is_ref++;
exit_client(client_p, source_p, &me, "Sorry, server is full - try later");
return (CLIENT_EXITED);
}
/* kline exemption extends to xline too */
2016-08-23 04:33:36 +02:00
if(!is_exempt_kline(*source_p) &&
(xconf = find_xline(source_p->info, 1)) != NULL)
{
ServerStats.is_ref++;
add_reject(source_p, xconf->host, NULL);
exit_client(client_p, source_p, &me, "Bad user info");
return CLIENT_EXITED;
}
/* authd rejection check */
2016-04-10 17:02:33 +02:00
if(authd_check(client_p, source_p))
return CLIENT_EXITED;
/* valid user name check */
if(!valid_username(source_p->username))
{
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::REJ, L_ALL,
"Invalid username: %s (%s@%s)",
source_p->name, source_p->username, source_p->host);
ServerStats.is_ref++;
sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains "
"only alphanumeric characters.");
sprintf(tmpstr2, "Invalid username [%s]", source_p->username);
exit_client(client_p, source_p, &me, tmpstr2);
return (CLIENT_EXITED);
}
/* end of valid user name check */
/* Store original hostname -- jilles */
2008-04-20 06:40:40 +02:00
rb_strlcpy(source_p->orighost, source_p->host, HOSTLEN + 1);
/* Spoof user@host */
if(*source_p->preClient->spoofuser)
2008-04-20 06:40:40 +02:00
rb_strlcpy(source_p->username, source_p->preClient->spoofuser, USERLEN + 1);
if(*source_p->preClient->spoofhost)
{
2008-04-20 06:40:40 +02:00
rb_strlcpy(source_p->host, source_p->preClient->spoofhost, HOSTLEN + 1);
if (irccmp(source_p->host, source_p->orighost))
2016-08-23 04:33:36 +02:00
set_dyn_spoof(*source_p);
}
source_p->mode |= (ConfigFileEntry.default_umodes & ~ConfigFileEntry.oper_only_umodes);
call_hook(h_new_local_user, source_p);
/* If they have died in send_* or were thrown out by the
* new_local_user hook don't do anything. */
2016-08-23 04:33:36 +02:00
if(is_any_dead(*source_p))
return CLIENT_EXITED;
/* To avoid inconsistencies, do not abort the registration
* starting from this point -- jilles
*/
2008-04-20 06:55:41 +02:00
rb_inet_ntop_sock((struct sockaddr *)&source_p->localClient->ip, ipaddr, sizeof(ipaddr));
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::CCONN, L_ALL,
"Client connecting: %s (%s@%s) [%s] {%s} [%s]",
source_p->name, source_p->username, source_p->orighost,
show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
get_client_class(source_p), source_p->info);
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::CCONNEXT, L_ALL,
"CLICONN %s %s %s %s %s %s 0 %s",
source_p->name, source_p->username, source_p->orighost,
show_ip(NULL, source_p) ? ipaddr : "255.255.255.255",
get_client_class(source_p),
/* mirc can sometimes send ips here */
show_ip(NULL, source_p) ? source_p->localClient->fullcaps : "<hidden> <hidden>",
source_p->info);
add_to_hostname_hash(source_p->orighost, source_p);
/* Allocate a UID if it was not previously allocated.
* If this already occured, it was probably during SASL auth...
*/
if(!*source_p->id)
{
rb_strlcpy(source_p->id, client::generate_uid(), sizeof(source_p->id));
add_to_id_hash(source_p->id, source_p);
}
if (IsSSL(source_p))
2016-08-24 00:25:09 +02:00
source_p->mode |= umode::SSLCLIENT;
2016-08-24 00:25:09 +02:00
if (source_p->mode & umode::INVISIBLE)
Count.invisi++;
2016-08-23 04:33:36 +02:00
s_assert(!is_client(*source_p));
2008-04-01 22:41:52 +02:00
rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list);
2016-08-23 04:33:36 +02:00
set_client(*source_p);
source_p->servptr = &me;
2016-08-24 01:08:40 +02:00
source_p->lnode = users(serv(*source_p->servptr)).emplace(end(users(serv(*source_p->servptr))), source_p);
/* Increment our total user count here */
if(++Count.total > Count.max_tot)
Count.max_tot = Count.total;
Count.totalrestartcount++;
s_assert(source_p->localClient != NULL);
2008-04-01 22:41:52 +02:00
if(rb_dlink_list_length(&lclient_list) > (unsigned long)Count.max_loc)
{
2008-04-01 22:41:52 +02:00
Count.max_loc = rb_dlink_list_length(&lclient_list);
if(!(Count.max_loc % 10))
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::GENERAL, L_ALL,
"New Max Local Clients: %d", Count.max_loc);
}
/* they get a reduced limit */
if(find_tgchange(source_p->sockhost))
source_p->localClient->targets_free = tgchange::INITIAL_LOW;
else
source_p->localClient->targets_free = tgchange::INITIAL;
monitor_signon(source_p);
user_welcome(source_p);
free_pre_client(source_p);
introduce_client(client_p, source_p, source_p->name, 1);
return 0;
}
/*
* introduce_clients
*
* inputs -
* output -
* side effects - This common function introduces a client to the rest
* of the net, either from a local client connect or
* from a remote connect.
*/
void
introduce_client(client::client *client_p, client::client *source_p, const char *nick, int use_euid)
{
char ubuf[BUFSIZE];
client::client *identifyservice_p;
char *p;
hook_data_umode_changed hdata;
hook_data_client hdata2;
delta(umode::table, 0, source_p->mode, ubuf);
if(my(*source_p))
send_umode(*source_p, *source_p, ubuf);
2008-06-08 08:29:26 +02:00
s_assert(has_id(source_p));
if (use_euid)
sendto_server(client_p, NULL, CAP_EUID | CAP_TS6, NOCAPS,
":%s EUID %s %d %ld %s %s %s %s %s %s %s :%s",
source_p->servptr->id, nick,
source_p->hopcount + 1,
(long) source_p->tsinfo, ubuf,
source_p->username, source_p->host,
2016-08-23 04:33:36 +02:00
is_ip_spoof(*source_p) ? "0" : source_p->sockhost,
2008-06-08 08:29:26 +02:00
source_p->id,
2016-08-23 04:33:36 +02:00
is_dyn_spoof(*source_p) ? source_p->orighost : "*",
suser(user(*source_p)).empty()? "*" : suser(user(*source_p)).c_str(),
2008-06-08 08:29:26 +02:00
source_p->info);
sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS,
":%s UID %s %d %ld %s %s %s %s %s :%s",
source_p->servptr->id, nick,
source_p->hopcount + 1,
(long) source_p->tsinfo, ubuf,
source_p->username, source_p->host,
2016-08-23 04:33:36 +02:00
is_ip_spoof(*source_p) ? "0" : source_p->sockhost,
2008-06-08 08:29:26 +02:00
source_p->id, source_p->info);
if(!EmptyString(source_p->certfp))
sendto_server(client_p, NULL, CAP_TS6, NOCAPS,
":%s ENCAP * CERTFP :%s",
use_id(source_p), source_p->certfp);
2016-08-23 04:33:36 +02:00
if (is_dyn_spoof(*source_p))
{
sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * REALHOST %s",
use_id(source_p), source_p->orighost);
}
2008-06-08 08:29:26 +02:00
if (!suser(user(*source_p)).empty())
{
sendto_server(client_p, NULL, CAP_TS6, use_euid ? CAP_EUID : NOCAPS, ":%s ENCAP * LOGIN %s",
use_id(source_p), suser(user(*source_p)).c_str());
}
2016-08-23 04:33:36 +02:00
if(my_connect(*source_p) && source_p->localClient->passwd)
{
if (!EmptyString(ConfigFileEntry.identifyservice) &&
!EmptyString(ConfigFileEntry.identifycommand))
{
/* use user@server */
p = strchr(ConfigFileEntry.identifyservice, '@');
if (p != NULL)
identifyservice_p = find_named_client(p + 1);
else
identifyservice_p = NULL;
if (identifyservice_p != NULL)
{
if (!EmptyString(source_p->localClient->auth_user))
sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s %s",
get_id(source_p, identifyservice_p),
ConfigFileEntry.identifyservice,
ConfigFileEntry.identifycommand,
source_p->localClient->auth_user,
source_p->localClient->passwd);
else
sendto_one(identifyservice_p, ":%s PRIVMSG %s :%s %s",
get_id(source_p, identifyservice_p),
ConfigFileEntry.identifyservice,
ConfigFileEntry.identifycommand,
source_p->localClient->passwd);
}
}
memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd));
rb_free(source_p->localClient->passwd);
source_p->localClient->passwd = NULL;
}
/* let modules providing usermodes know that we've got a new user,
* why is this here? -- well, some modules need to be able to send out new
* information about a client, so this was the best place to do it
* --nenolod
*/
hdata.client = source_p;
hdata.oldumodes = 0;
hdata.oldsnomask = 0;
call_hook(h_umode_changed, &hdata);
/* On the other hand, some modules need to know when a client is
* being introduced, period.
* --gxti
*/
hdata2.client = client_p;
hdata2.target = source_p;
call_hook(h_introduce_client, &hdata2);
}
/*
* valid_hostname - check hostname for validity
*
* Inputs - pointer to user
* Output - true if valid, false if not
* Side effects - NONE
*
* NOTE: this doesn't allow a hostname to begin with a dot and
* will not allow more dots than chars.
*/
bool
valid_hostname(const char *hostname)
{
2009-04-20 15:37:13 +02:00
const char *p = hostname, *last_slash = 0;
int found_sep = 0;
s_assert(NULL != p);
if(hostname == NULL)
return false;
if(!strcmp(hostname, "localhost"))
return true;
2009-04-20 15:37:13 +02:00
if('.' == *p || ':' == *p || '/' == *p)
return false;
while (*p)
{
if(!rfc1459::is_host(*p))
return false;
if(*p == '.' || *p == ':')
found_sep++;
2009-04-20 15:37:13 +02:00
else if(*p == '/')
{
found_sep++;
last_slash = p;
}
p++;
}
if(found_sep == 0)
return false;
2009-04-20 15:37:13 +02:00
if(last_slash && rfc1459::is_digit(last_slash[1]))
return false;
return true;
}
/*
* valid_username - check username for validity
*
* Inputs - pointer to user
* Output - true if valid, false if not
* Side effects - NONE
*
* Absolutely always reject any '*' '!' '?' '@' in an user name
* reject any odd control characters names.
* Allow '.' in username to allow for "first.last"
* style of username
*/
bool
valid_username(const char *username)
{
int dots = 0;
const char *p = username;
s_assert(NULL != p);
if(username == NULL)
return false;
if('~' == *p)
++p;
/* reject usernames that don't start with an alphanum
* i.e. reject jokers who have '-@somehost' or '.@somehost'
* or "-hi-@somehost", "h-----@somehost" would still be accepted.
*/
if(!rfc1459::is_alnum(*p))
return false;
while (*++p)
{
if((*p == '.') && ConfigFileEntry.dots_in_ident)
{
dots++;
if(dots > ConfigFileEntry.dots_in_ident)
return false;
if(!rfc1459::is_user(p[1]))
return false;
}
else if(!rfc1459::is_user(*p))
return false;
}
return true;
}
/* report_and_set_user_flags
*
* Inputs - pointer to source_p
* - pointer to aconf for this user
* Output - NONE
* Side effects -
* Report to user any special flags they are getting, and set them.
*/
static void
report_and_set_user_flags(client::client *source_p, struct ConfItem *aconf)
{
/* If this user is being spoofed, tell them so */
if(IsConfDoSpoofIp(aconf))
{
sendto_one_notice(source_p, ":*** Spoofing your IP");
}
/* If this user is in the exception class, Set it "E lined" */
if(IsConfExemptKline(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_kline(*source_p);
2008-11-26 21:38:49 +01:00
sendto_one_notice(source_p, ":*** You are exempt from K/X lines");
}
if(IsConfExemptDNSBL(aconf))
/* kline exempt implies this, don't send both */
if(!IsConfExemptKline(aconf))
sendto_one_notice(source_p, ":*** You are exempt from DNS blacklists");
/* If this user is exempt from user limits set it F lined" */
if(IsConfExemptLimits(aconf))
{
sendto_one_notice(source_p, ":*** You are exempt from user limits");
}
if(IsConfExemptFlood(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_flood(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from flood limits");
}
if(IsConfExemptSpambot(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_spambot(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from spambot checks");
}
if(IsConfExemptJupe(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_jupe(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from juped channel warnings");
}
if(IsConfExemptResv(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_resv(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from resvs");
}
if(IsConfExemptShide(aconf))
{
2016-08-23 04:33:36 +02:00
set_exempt_shide(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from serverhiding");
}
if(IsConfExtendChans(aconf))
{
2016-08-23 04:33:36 +02:00
set_extend_chans(*source_p);
sendto_one_notice(source_p, ":*** You are exempt from normal channel limits");
}
}
static void
show_other_user_mode(client::client &source,
client::client &target)
{
char ubuf[128];
mask(umode::table, target.mode, ubuf);
if(my_connect(target) && target.snomask)
2016-08-26 13:50:12 +02:00
{
char sbuf[128];
mask(sno::table, target.snomask, sbuf);
sendto_one_notice(&source, ":Modes for %s are %s %s",
target.name,
ubuf,
sbuf);
2016-08-26 13:50:12 +02:00
}
else
sendto_one_notice(&source, ":Modes for %s are %s",
target.name,
ubuf);
}
/*
* user_mode - set get current users mode
*
* m_umode() added 15/10/91 By Darren Reed.
* parv[1] - username to change mode for
* parv[2] - modes to change
*/
int
user_mode(client::client *client_p, client::client *source_p, int parc, const char *parv[])
{
int flag;
int i;
char *m;
const char *pm;
client::client *target_p;
int what, setflags;
bool badflag = false; /* Only send one bad flag notice */
bool showsnomask = false;
unsigned int setsnomask;
char buf[BUFSIZE];
hook_data_umode_changed hdata;
what = MODE_ADD;
if(parc < 2)
{
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE");
return 0;
}
2016-08-23 04:33:36 +02:00
if((target_p = my(*source_p) ? client::find_named_person(parv[1]) : client::find_person(parv[1])) == NULL)
{
2016-08-23 04:33:36 +02:00
if(my_connect(*source_p))
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
form_str(ERR_NOSUCHCHANNEL), parv[1]);
return 0;
}
/* Dont know why these were commented out..
* put them back using new sendto() funcs
*/
2016-08-23 04:33:36 +02:00
if(is_server(*source_p))
{
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::GENERAL, L_ADMIN,
"*** Mode for User %s from %s", parv[1], source_p->name);
return 0;
}
if(source_p != target_p)
{
2016-08-24 00:25:09 +02:00
if (my_oper(*source_p) && parc < 3)
show_other_user_mode(*source_p, *target_p);
else
sendto_one(source_p, form_str(ERR_USERSDONTMATCH), me.name, source_p->name);
return 0;
}
if(parc < 3)
{
mask(umode::table, source_p->mode, buf);
sendto_one_numeric(source_p, RPL_UMODEIS, form_str(RPL_UMODEIS), buf);
if(source_p->snomask)
2016-08-26 13:50:12 +02:00
{
char buf[128];
mask(sno::table, source_p->snomask, buf);
sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK), buf);
2016-08-26 13:50:12 +02:00
}
return 0;
}
/* find flags already set for user */
2016-08-24 00:25:09 +02:00
setflags = source_p->mode;
setsnomask = source_p->snomask;
/*
* parse mode change string(s)
*/
for (pm = parv[2]; *pm; pm++)
switch (*pm)
{
case '+':
what = MODE_ADD;
break;
case '-':
what = MODE_DEL;
break;
case 'o':
if(what == MODE_ADD)
{
2016-08-24 00:25:09 +02:00
if(is_server(*client_p) && !is_oper(*source_p))
{
++Count.oper;
2016-08-24 00:25:09 +02:00
set_oper(*source_p);
2008-04-01 22:41:52 +02:00
rb_dlinkAddAlloc(source_p, &oper_list);
}
}
else
{
/* Only decrement the oper counts if an oper to begin with
* found by Pat Szuta, Perly , perly@xnet.com
*/
2016-08-24 00:25:09 +02:00
if(!is_oper(*source_p))
break;
2016-08-24 00:25:09 +02:00
clear_oper(*source_p);
Count.oper--;
2016-08-23 04:33:36 +02:00
if(my_connect(*source_p))
{
clear(*source_p, ConfigFileEntry.oper_only_umodes);
2016-08-24 00:25:09 +02:00
if (!is(*source_p, umode::SERVNOTICE) && source_p->snomask != 0)
{
source_p->snomask = 0;
showsnomask = true;
}
source_p->flags &= ~OPER_FLAGS;
rb_free(source_p->localClient->opername);
source_p->localClient->opername = NULL;
2008-04-01 22:41:52 +02:00
rb_dlinkFindDestroy(source_p, &local_oper_list);
2008-08-25 18:24:24 +02:00
privilegeset_unref(source_p->localClient->privset);
source_p->localClient->privset = NULL;
}
2008-04-01 22:41:52 +02:00
rb_dlinkFindDestroy(source_p, &oper_list);
}
break;
/* we may not get these,
* but they shouldnt be in default
*/
/* can only be set on burst */
case 'S':
case 'Z':
case ' ':
case '\n':
case '\r':
case '\t':
break;
case 's':
2016-08-23 04:33:36 +02:00
if (my_connect(*source_p))
{
2016-08-24 00:25:09 +02:00
if(!is_oper(*source_p)
&& (ConfigFileEntry.oper_only_umodes & umode::SERVNOTICE))
{
2016-08-24 00:25:09 +02:00
if (what == MODE_ADD || is(*source_p, umode::SERVNOTICE))
badflag = true;
continue;
}
showsnomask = true;
if(what == MODE_ADD)
{
if (parc > 3)
2016-08-26 13:50:12 +02:00
source_p->snomask = delta(sno::table, source_p->snomask, parv[3]);
else
2016-08-26 13:50:12 +02:00
source_p->snomask |= sno::GENERAL;
}
else
source_p->snomask = 0;
if (source_p->snomask != 0)
2016-08-24 00:25:09 +02:00
set(*source_p, umode::SERVNOTICE);
else
2016-08-24 00:25:09 +02:00
clear(*source_p, umode::SERVNOTICE);
break;
}
/* FALLTHROUGH */
default:
2016-08-23 04:33:36 +02:00
if (my_connect(*source_p) && *pm == 'Q' && !ConfigChannel.use_forward)
2011-09-25 16:22:29 +02:00
{
badflag = true;
2011-09-25 16:22:29 +02:00
break;
}
if((flag = umode::table[(unsigned char) *pm]))
{
2016-08-23 04:33:36 +02:00
if(my_connect(*source_p)
2016-08-24 00:25:09 +02:00
&& ((!is_oper(*source_p)
&& (ConfigFileEntry.oper_only_umodes & flag))))
{
2016-08-24 00:25:09 +02:00
if (what == MODE_ADD || source_p->mode & flag)
badflag = true;
}
else
{
if(what == MODE_ADD)
set(*source_p, flag);
else
clear(*source_p, flag);
}
}
else
{
2016-08-23 04:33:36 +02:00
if(my_connect(*source_p))
badflag = true;
}
break;
}
if(badflag)
sendto_one(source_p, form_str(ERR_UMODEUNKNOWNFLAG), me.name, source_p->name);
2016-08-26 13:50:12 +02:00
if(my(*source_p) && (source_p->snomask & sno::NCHANGE) && !IsOperN(source_p))
{
sendto_one_notice(source_p, ":*** You need oper and nick_changes flag for +s +n");
2016-08-26 13:50:12 +02:00
source_p->snomask &= ~sno::NCHANGE; /* only tcm's really need this */
}
2016-08-24 00:25:09 +02:00
if(my(*source_p) && is(*source_p, umode::OPERWALL) && !IsOperOperwall(source_p))
{
[svn] Backport from early 3.x: -- nenolod 2006/09/27 16:39:14 UTC (20060927-2178) Log: - remove "Processing connection to foobar.net" message Changes: Modified: +0 -3 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:34:26 UTC (20060927-2176) Log: - missed the processing connection one (actually, we can probably nuke this one) Changes: Modified: +1 -2 trunk/src/s_auth.c (File Modified) river 2006/09/27 16:33:05 UTC (20060927-2174) Log: get_client_name = stupid Changes: Modified: +10 -7 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:32:37 UTC (20060927-2172) Log: - remove excessive arguments Changes: Modified: +1 -2 trunk/src/s_conf.c (File Modified) +1 -1 trunk/src/s_user.c (File Modified) nenolod 2006/09/27 16:30:59 UTC (20060927-2170) Log: - use sendto_one_notice() for on-connect notices too. Changes: Modified: +10 -10 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:27:01 UTC (20060927-2168) Log: - use sendto_one_notice() in the core, too. Changes: Modified: +2 -2 trunk/src/chmode.c (File Modified) +8 -15 trunk/src/modules.c (File Modified) +3 -5 trunk/src/s_conf.c (File Modified) +1 -2 trunk/src/s_newconf.c (File Modified) +20 -57 trunk/src/s_user.c (File Modified) river 2006/09/27 16:19:25 UTC (20060927-2166) Log: the KILL command will use get_client_name(, SHOW_IP) instead of target->name, and will show a more useful error for local opers Changes: Modified: +6 -4 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:09:48 UTC (20060927-2164) Log: - fix bugs in sendto_one_notice()/sendto_one_numeric() where a client identifier won't be sent to unregistered clients Changes: Modified: +4 -2 trunk/src/send.c (File Modified) nenolod 2006/09/27 16:05:46 UTC (20060927-2161) Log: - back out r2159 Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:04:05 UTC (20060927-2159) Log: - get_id(): fall back to "*" if client has no known name Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:01:29 UTC (20060927-2157) Log: - convert to sendto_one_notice(). Changes: Modified: +2 -3 trunk/unsupported/m_clearchan.c (File Modified) +4 -6 trunk/unsupported/m_force.c (File Modified) nenolod 2006/09/27 15:57:11 UTC (20060927-2155) Log: - use sendto_one_notice() in many places instead of sendto_one(source_p, ":%s NOTICE %s :", ...); Changes: Modified: +10 -25 trunk/extensions/example_module.c (File Modified) +5 -14 trunk/extensions/hurt.c (File Modified) +1 -2 trunk/extensions/m_42.c (File Modified) +7 -12 trunk/extensions/m_mkpasswd.c (File Modified) +1 -2 trunk/extensions/m_ojoin.c (File Modified) +1 -2 trunk/extensions/m_opme.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice_global.c (File Modified) +3 -7 trunk/modules/core/m_die.c (File Modified) +2 -4 trunk/modules/core/m_kill.c (File Modified) +2 -2 trunk/modules/core/m_squit.c (File Modified) +1 -2 trunk/modules/m_challenge.c (File Modified) +11 -15 trunk/modules/m_connect.c (File Modified) +20 -28 trunk/modules/m_dline.c (File Modified) +2 -2 trunk/modules/m_etrace.c (File Modified) +11 -21 trunk/modules/m_gline.c (File Modified) +2 -4 trunk/modules/m_kline.c (File Modified) +1 -2 trunk/modules/m_rehash.c (File Modified) +3 -7 trunk/modules/m_restart.c (File Modified) +31 -45 trunk/modules/m_set.c (File Modified) +2 -4 trunk/modules/m_testmask.c (File Modified) +5 -8 trunk/modules/m_unreject.c (File Modified) +2 -5 trunk/modules/m_xline.c (File Modified) --
2007-01-25 08:23:01 +01:00
sendto_one_notice(source_p, ":*** You need oper and operwall flag for +z");
2016-08-24 00:25:09 +02:00
source_p->mode &= ~umode::OPERWALL;
}
2016-08-24 00:25:09 +02:00
if(my_connect(*source_p) && (source_p->mode & umode::ADMIN) &&
(!IsOperAdmin(source_p) || IsOperHiddenAdmin(source_p)))
{
sendto_one_notice(source_p, ":*** You need oper and admin flag for +a");
2016-08-24 00:25:09 +02:00
clear(*source_p, umode::ADMIN);
}
/* let modules providing usermodes know that we've changed our usermode --nenolod */
hdata.client = source_p;
hdata.oldumodes = setflags;
hdata.oldsnomask = setsnomask;
call_hook(h_umode_changed, &hdata);
2016-08-24 00:25:09 +02:00
if(!(setflags & umode::INVISIBLE) && is(*source_p, umode::INVISIBLE))
++Count.invisi;
2016-08-24 00:25:09 +02:00
if((setflags & umode::INVISIBLE) && !is(*source_p, umode::INVISIBLE))
--Count.invisi;
/*
* compare new flags with old flags and send string which
* will cause servers to update correctly.
*/
send_umode_out(*client_p, *source_p, setflags);
2016-08-23 04:33:36 +02:00
if (showsnomask && my_connect(*source_p))
2016-08-26 13:50:12 +02:00
{
char snobuf[128];
sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
2016-08-26 13:50:12 +02:00
mask(sno::table, source_p->snomask, snobuf));
}
return (0);
}
/*
* send the MODE string for user (user) to connection client_p
* -avalon
*/
void
send_umode(client::client &to,
const client::client &source,
const char *const &buf)
{
sendto_one(&to, ":%s MODE %s :%s",
source.name,
source.name,
buf);
}
void
send_umode(client::client &to,
const client::client &after,
const umode::mask &before)
{
char buf[128];
delta(umode::table, before, after.mode, buf);
send_umode(to, after, buf);
}
/*
* send_umode_out
*
* inputs -
* output - NONE
* side effects -
*/
void
send_umode_out(client::client &client,
const client::client &source,
const umode::mask &before)
{
char buf[BUFSIZE];
delta(umode::table, before, source.mode, buf);
rb_dlink_node *ptr;
2008-04-01 22:43:10 +02:00
RB_DLINK_FOREACH(ptr, serv_list.head)
{
auto &target(*reinterpret_cast<client::client *>(ptr->data));
if((target != client) && (target != source))
sendto_one(&target, ":%s MODE %s :%s",
get_id(source, target),
get_id(source, target),
buf);
}
if(my(client))
send_umode(client, source, buf);
}
/*
* user_welcome
*
* inputs - client pointer to client to welcome
* output - NONE
* side effects -
*/
void
user_welcome(client::client *source_p)
{
sendto_one_numeric(source_p, RPL_WELCOME, form_str(RPL_WELCOME), ServerInfo.network_name, source_p->name);
sendto_one_numeric(source_p, RPL_YOURHOST, form_str(RPL_YOURHOST),
get_listener_name(source_p->localClient->listener), info::version.c_str());
sendto_one_numeric(source_p, RPL_CREATED, form_str(RPL_CREATED), info::compiled.c_str());
sendto_one_numeric(source_p, RPL_MYINFO, form_str(RPL_MYINFO),
me.name,
info::version.c_str(),
client::mode::available,
chan::mode::arity[0],
chan::mode::arity[1]);
2016-08-25 09:59:58 +02:00
supported::show(*source_p);
show_lusers(source_p);
if(ConfigFileEntry.short_motd)
{
sendto_one_notice(source_p, ":*** Notice -- motd was last changed at %s", cache::motd::user_motd_changed);
[svn] Backport from early 3.x: -- nenolod 2006/09/27 16:39:14 UTC (20060927-2178) Log: - remove "Processing connection to foobar.net" message Changes: Modified: +0 -3 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:34:26 UTC (20060927-2176) Log: - missed the processing connection one (actually, we can probably nuke this one) Changes: Modified: +1 -2 trunk/src/s_auth.c (File Modified) river 2006/09/27 16:33:05 UTC (20060927-2174) Log: get_client_name = stupid Changes: Modified: +10 -7 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:32:37 UTC (20060927-2172) Log: - remove excessive arguments Changes: Modified: +1 -2 trunk/src/s_conf.c (File Modified) +1 -1 trunk/src/s_user.c (File Modified) nenolod 2006/09/27 16:30:59 UTC (20060927-2170) Log: - use sendto_one_notice() for on-connect notices too. Changes: Modified: +10 -10 trunk/src/s_auth.c (File Modified) nenolod 2006/09/27 16:27:01 UTC (20060927-2168) Log: - use sendto_one_notice() in the core, too. Changes: Modified: +2 -2 trunk/src/chmode.c (File Modified) +8 -15 trunk/src/modules.c (File Modified) +3 -5 trunk/src/s_conf.c (File Modified) +1 -2 trunk/src/s_newconf.c (File Modified) +20 -57 trunk/src/s_user.c (File Modified) river 2006/09/27 16:19:25 UTC (20060927-2166) Log: the KILL command will use get_client_name(, SHOW_IP) instead of target->name, and will show a more useful error for local opers Changes: Modified: +6 -4 trunk/modules/core/m_kill.c (File Modified) nenolod 2006/09/27 16:09:48 UTC (20060927-2164) Log: - fix bugs in sendto_one_notice()/sendto_one_numeric() where a client identifier won't be sent to unregistered clients Changes: Modified: +4 -2 trunk/src/send.c (File Modified) nenolod 2006/09/27 16:05:46 UTC (20060927-2161) Log: - back out r2159 Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:04:05 UTC (20060927-2159) Log: - get_id(): fall back to "*" if client has no known name Changes: Modified: +1 -1 trunk/include/client.h (File Modified) nenolod 2006/09/27 16:01:29 UTC (20060927-2157) Log: - convert to sendto_one_notice(). Changes: Modified: +2 -3 trunk/unsupported/m_clearchan.c (File Modified) +4 -6 trunk/unsupported/m_force.c (File Modified) nenolod 2006/09/27 15:57:11 UTC (20060927-2155) Log: - use sendto_one_notice() in many places instead of sendto_one(source_p, ":%s NOTICE %s :", ...); Changes: Modified: +10 -25 trunk/extensions/example_module.c (File Modified) +5 -14 trunk/extensions/hurt.c (File Modified) +1 -2 trunk/extensions/m_42.c (File Modified) +7 -12 trunk/extensions/m_mkpasswd.c (File Modified) +1 -2 trunk/extensions/m_ojoin.c (File Modified) +1 -2 trunk/extensions/m_opme.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice.c (File Modified) +3 -3 trunk/extensions/spy_whois_notice_global.c (File Modified) +3 -7 trunk/modules/core/m_die.c (File Modified) +2 -4 trunk/modules/core/m_kill.c (File Modified) +2 -2 trunk/modules/core/m_squit.c (File Modified) +1 -2 trunk/modules/m_challenge.c (File Modified) +11 -15 trunk/modules/m_connect.c (File Modified) +20 -28 trunk/modules/m_dline.c (File Modified) +2 -2 trunk/modules/m_etrace.c (File Modified) +11 -21 trunk/modules/m_gline.c (File Modified) +2 -4 trunk/modules/m_kline.c (File Modified) +1 -2 trunk/modules/m_rehash.c (File Modified) +3 -7 trunk/modules/m_restart.c (File Modified) +31 -45 trunk/modules/m_set.c (File Modified) +2 -4 trunk/modules/m_testmask.c (File Modified) +5 -8 trunk/modules/m_unreject.c (File Modified) +2 -5 trunk/modules/m_xline.c (File Modified) --
2007-01-25 08:23:01 +01:00
sendto_one_notice(source_p, ":*** Notice -- Please read the motd if you haven't read it");
sendto_one(source_p, form_str(RPL_MOTDSTART),
me.name, source_p->name, me.name);
sendto_one(source_p, form_str(RPL_MOTD),
me.name, source_p->name, "*** This is the short motd ***");
sendto_one(source_p, form_str(RPL_ENDOFMOTD), me.name, source_p->name);
}
else
cache::motd::send_user(*source_p);
}
/* oper_up()
*
* inputs - pointer to given client to oper
* - pointer to ConfItem to use
* output - none
* side effects - opers up source_p using aconf for reference
*/
void
oper_up(client::client *source_p, struct oper_conf *oper_p)
{
2016-08-24 00:25:09 +02:00
unsigned int old = source_p->mode, oldsnomask = source_p->snomask;
hook_data_umode_changed hdata;
2016-08-24 00:25:09 +02:00
set_oper(*source_p);
if(oper_p->umodes)
source_p->mode |= oper_p->umodes;
else if(ConfigFileEntry.oper_umodes)
source_p->mode |= ConfigFileEntry.oper_umodes;
else
2016-08-24 00:25:09 +02:00
source_p->mode |= client::mode::DEFAULT_OPER_UMODES;
if (oper_p->snomask)
{
source_p->snomask |= oper_p->snomask;
2016-08-24 00:25:09 +02:00
source_p->mode |= umode::SERVNOTICE;
}
2016-08-24 00:25:09 +02:00
else if (source_p->mode & umode::SERVNOTICE)
{
/* Only apply these if +s is already set -- jilles */
if (ConfigFileEntry.oper_snomask)
source_p->snomask |= ConfigFileEntry.oper_snomask;
else
2016-08-26 13:50:12 +02:00
source_p->snomask |= sno::DEFAULT_OPER_SNOMASK;
}
Count.oper++;
2016-08-23 04:33:36 +02:00
set_extend_chans(*source_p);
set_exempt_kline(*source_p);
source_p->flags |= oper_p->flags;
2008-04-02 01:26:34 +02:00
source_p->localClient->opername = rb_strdup(oper_p->name);
source_p->localClient->privset = privilegeset_ref(oper_p->privset);
2008-04-01 22:41:52 +02:00
rb_dlinkAddAlloc(source_p, &local_oper_list);
rb_dlinkAddAlloc(source_p, &oper_list);
if(IsOperAdmin(source_p) && !IsOperHiddenAdmin(source_p))
2016-08-24 00:25:09 +02:00
source_p->mode |= umode::ADMIN;
if(!IsOperN(source_p))
2016-08-26 13:50:12 +02:00
source_p->snomask &= ~sno::NCHANGE;
if(!IsOperOperwall(source_p))
2016-08-24 00:25:09 +02:00
source_p->mode &= ~umode::OPERWALL;
hdata.client = source_p;
hdata.oldumodes = old;
hdata.oldsnomask = oldsnomask;
call_hook(h_umode_changed, &hdata);
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::GENERAL, L_ALL,
"%s (%s!%s@%s) is now an operator", oper_p->name, source_p->name,
source_p->username, source_p->host);
2016-08-24 00:25:09 +02:00
if(!(old & umode::INVISIBLE) && is(*source_p, umode::INVISIBLE))
++Count.invisi;
2016-08-24 00:25:09 +02:00
if((old & umode::INVISIBLE) && !is(*source_p, umode::INVISIBLE))
--Count.invisi;
send_umode_out(*source_p, *source_p, old);
2016-08-26 13:50:12 +02:00
char snobuf[128];
sendto_one_numeric(source_p, RPL_SNOMASK, form_str(RPL_SNOMASK),
2016-08-26 13:50:12 +02:00
mask(sno::table, source_p->snomask, snobuf));
sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
sendto_one_notice(source_p, ":*** Oper privilege set is %s", oper_p->privset->name);
sendto_one_notice(source_p, ":*** Oper privs are %s", oper_p->privset->privs);
cache::motd::send_oper(*source_p);
}
void
change_nick_user_host(client::client *target_p, const char *nick, const char *username,
const char *host, int newts, const char *format, ...)
{
2008-04-01 22:41:52 +02:00
rb_dlink_node *ptr;
chan::chan *chptr;
int changed = irccmp(target_p->name, nick);
int changed_case = strcmp(target_p->name, nick);
int do_qjm = irccmp(target_p->username, username) || irccmp(target_p->host, host);
2016-08-20 02:32:26 +02:00
char mode[10], modeval[NICKLEN * 2 + 2], reason[256];
va_list ap;
modeval[0] = '\0';
if(changed)
{
target_p->tsinfo = newts;
monitor_signoff(target_p);
}
chan::invalidate_bancache_user(target_p);
if(do_qjm)
{
va_start(ap, format);
vsnprintf(reason, 255, format, ap);
va_end(ap);
2015-11-20 05:53:55 +01:00
sendto_common_channels_local_butone(target_p, NOCAPS, CLICAP_CHGHOST, ":%s!%s@%s QUIT :%s",
target_p->name, target_p->username, target_p->host,
reason);
for(const auto &pit : chans(user(*target_p)))
{
2016-08-20 02:32:26 +02:00
auto &chan(*pit.first);
auto &member(*pit.second);
char *mptr(mode);
2016-08-20 02:32:26 +02:00
if(is_chanop(member))
{
*mptr++ = 'o';
strcat(modeval, nick);
strcat(modeval, " ");
}
2016-08-20 02:32:26 +02:00
if(is_voiced(member))
{
*mptr++ = 'v';
strcat(modeval, nick);
}
*mptr = '\0';
2016-08-20 02:32:26 +02:00
sendto_channel_local_with_capability_butone(target_p, chan::ALL_MEMBERS, NOCAPS, CLICAP_EXTENDED_JOIN | CLICAP_CHGHOST, &chan,
":%s!%s@%s JOIN %s", nick, username, host, chan.name.c_str());
2016-08-20 02:32:26 +02:00
sendto_channel_local_with_capability_butone(target_p, chan::ALL_MEMBERS, CLICAP_EXTENDED_JOIN, CLICAP_CHGHOST, &chan,
":%s!%s@%s JOIN %s %s :%s", nick, username, host, chan.name.c_str(),
suser(user(*target_p)).empty()? "*" : suser(user(*target_p)).c_str(),
target_p->info);
if(*mode)
2016-08-20 02:32:26 +02:00
sendto_channel_local_with_capability_butone(target_p, chan::ALL_MEMBERS, NOCAPS, CLICAP_CHGHOST, &chan,
":%s MODE %s +%s %s", target_p->servptr->name, chan.name.c_str(), mode, modeval);
*modeval = '\0';
}
2012-02-14 15:15:44 +01:00
/* Resend away message to away-notify enabled clients. */
if (away(user(*target_p)).size())
2015-11-20 05:53:55 +01:00
sendto_common_channels_local_butone(target_p, CLICAP_AWAY_NOTIFY, CLICAP_CHGHOST, ":%s!%s@%s AWAY :%s",
nick, username, host,
away(user(*target_p)).c_str());
2012-02-14 15:15:44 +01:00
2015-11-20 05:53:55 +01:00
sendto_common_channels_local_butone(target_p, CLICAP_CHGHOST, NOCAPS,
":%s!%s@%s CHGHOST %s %s",
target_p->name, target_p->username, target_p->host, username, host);
2015-11-20 05:53:55 +01:00
2016-08-23 04:33:36 +02:00
if(my(*target_p) && changed_case)
sendto_one(target_p, ":%s!%s@%s NICK %s",
target_p->name, username, host, nick);
2016-08-26 13:50:12 +02:00
/* TODO: send some snotes to sno::NCHANGE/sno::CCONN/sno::CCONNEXT? */
}
else if(changed_case)
{
sendto_common_channels_local(target_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s",
target_p->name, username, host, nick);
2016-08-23 04:33:36 +02:00
if(my_connect(*target_p))
2016-08-26 13:50:12 +02:00
sendto_realops_snomask(sno::NCHANGE, L_ALL,
"Nick change: From %s to %s [%s@%s]",
target_p->name, nick,
target_p->username, target_p->host);
}
if (username != target_p->username)
rb_strlcpy(target_p->username, username, sizeof target_p->username);
2008-04-20 06:40:40 +02:00
rb_strlcpy(target_p->host, host, sizeof target_p->host);
if (changed)
2016-08-25 04:52:37 +02:00
whowas::add(*target_p);
del_from_client_hash(target_p->name, target_p);
2008-04-20 06:40:40 +02:00
rb_strlcpy(target_p->name, nick, NICKLEN);
add_to_client_hash(target_p->name, target_p);
if(changed)
{
monitor_signon(target_p);
del_all_accepts(target_p);
}
}
2016-08-13 05:05:54 +02:00
}