unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

chgname.c (3744B)

      1 /*
      2  *   Unreal Internet Relay Chat Daemon, src/modules/chgname.c
      3  *   (C) 2000-2001 Carsten V. Munk and the UnrealIRCd Team
      4  *   Moved to modules by Fish (Justin Hammond)
      5  *
      6  *   This program is free software; you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 1, or (at your option)
      9  *   any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  *   GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program; if not, write to the Free Software
     18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     19  */
     20 
     21 #include "unrealircd.h"
     22 
     23 #define MSG_CHGNAME     "CHGNAME"
     24 #define MSG_SVSNAME     "SVSNAME"
     25 
     26 CMD_FUNC(cmd_chgname);
     27 
     28 ModuleHeader MOD_HEADER
     29   = {
     30 	"chgname",	/* Name of module */
     31 	"5.0", /* Version */
     32 	"command /chgname", /* Short description of module */
     33 	"UnrealIRCd Team",
     34 	"unrealircd-6",
     35     };
     36 
     37 
     38 /* This is called on module init, before Server Ready */
     39 MOD_INIT()
     40 {
     41 	CommandAdd(modinfo->handle, MSG_CHGNAME, cmd_chgname, 2, CMD_USER|CMD_SERVER);
     42 	CommandAdd(modinfo->handle, MSG_SVSNAME, cmd_chgname, 2, CMD_USER|CMD_SERVER);
     43 	MARK_AS_OFFICIAL_MODULE(modinfo);
     44 	return MOD_SUCCESS;
     45 }
     46 
     47 /* Is first run when server is 100% ready */
     48 MOD_LOAD()
     49 {
     50 	return MOD_SUCCESS;
     51 }
     52 
     53 
     54 /* Called when module is unloaded */
     55 MOD_UNLOAD()
     56 {
     57 	return MOD_SUCCESS;
     58 }
     59 
     60 
     61 /*
     62  * cmd_chgname - Tue May 23 13:06:35 BST 200 (almost a year after I made CHGIDENT) - Stskeeps
     63  * :prefix CHGNAME <nick> <new realname>
     64  * parv[1] - nickname
     65  * parv[2] - realname
     66  *
     67 */
     68 CMD_FUNC(cmd_chgname)
     69 {
     70 	Client *target;
     71 	ConfigItem_ban *bconf;
     72 
     73 	if (!ValidatePermissionsForPath("client:set:name",client,NULL,NULL,NULL))
     74 	{
     75 		sendnumeric(client, ERR_NOPRIVILEGES);
     76 		return;
     77 	}
     78 
     79 	if ((parc < 3) || !*parv[2])
     80 	{
     81 		sendnumeric(client, ERR_NEEDMOREPARAMS, "CHGNAME");
     82 		return;
     83 	}
     84 
     85 	if (strlen(parv[2]) > (REALLEN))
     86 	{
     87 		sendnotice(client, "*** ChgName Error: Requested realname too long -- rejected.");
     88 		return;
     89 	}
     90 
     91 	if (!(target = find_user(parv[1], NULL)))
     92 	{
     93 		sendnumeric(client, ERR_NOSUCHNICK, parv[1]);
     94 		return;
     95 	}
     96 
     97 	/* Let's log this first */
     98 	if (!IsULine(client))
     99 	{
    100 		const char *issuer = command_issued_by_rpc(recv_mtags);
    101 		if (issuer)
    102 		{
    103 			unreal_log(ULOG_INFO, "chgcmds", "CHGNAME_COMMAND", client,
    104 				   "CHGNAME: $issuer changed the realname of $target.details to be $new_realname",
    105 				   log_data_string("issuer", issuer),
    106 				   log_data_string("change_type", "realname"),
    107 				   log_data_client("target", target),
    108 				   log_data_string("new_realname", parv[2]));
    109 		} else {
    110 			unreal_log(ULOG_INFO, "chgcmds", "CHGNAME_COMMAND", client,
    111 				   "CHGNAME: $client changed the realname of $target.details to be $new_realname",
    112 				   log_data_string("change_type", "realname"),
    113 				   log_data_client("target", target),
    114 				   log_data_string("new_realname", parv[2]));
    115 		}
    116 	}
    117 
    118 	/* set the realname to make ban checking work */
    119 	ircsnprintf(target->info, sizeof(target->info), "%s", parv[2]);
    120 
    121 	if (MyUser(target))
    122 	{
    123 		/* only check for realname bans if the person who's name is being changed is NOT an oper */
    124 		if (!ValidatePermissionsForPath("immune:server-ban:ban-realname",target,NULL,NULL,NULL) &&
    125 		    ((bconf = find_ban(NULL, target->info, CONF_BAN_REALNAME))))
    126 		{
    127 			banned_client(target, "realname", bconf->reason?bconf->reason:"", 0, 0);
    128 			return;
    129 		}
    130 	}
    131 
    132 	sendto_server(client, 0, 0, recv_mtags, ":%s CHGNAME %s :%s",
    133 	    client->id, target->name, parv[2]);
    134 }