unrealircd

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

setname.c (4731B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/setname.c
      3  *   (c) 1999-2001 Dominick Meglio (codemastr) <codemastr@unrealircd.com>
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers. 
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 CMD_FUNC(cmd_setname);
     26 char *setname_isupport_param(void);
     27 
     28 #define MSG_SETNAME 	"SETNAME"	/* setname */
     29 #define STR_HELPER(x) #x
     30 #define STR(x) STR_HELPER(x)
     31 
     32 long CAP_SETNAME = 0L;
     33 
     34 ModuleHeader MOD_HEADER
     35   = {
     36 	"setname",	/* Name of module */
     37 	"5.0", /* Version */
     38 	"command /setname", /* Short description of module */
     39 	"UnrealIRCd Team",
     40 	"unrealircd-6",
     41     };
     42 
     43 MOD_INIT()
     44 {
     45 	ClientCapabilityInfo cap;
     46 	ClientCapability *c;
     47 	MARK_AS_OFFICIAL_MODULE(modinfo);
     48 
     49 	CommandAdd(modinfo->handle, MSG_SETNAME, cmd_setname, 1, CMD_USER);
     50 
     51 	memset(&cap, 0, sizeof(cap));
     52 	cap.name = "setname";
     53 	c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_SETNAME);
     54 	if (!c)
     55 	{
     56 		config_error("[%s] Failed to request setname cap: %s", MOD_HEADER.name, ModuleGetErrorStr(modinfo->handle));
     57 		return MOD_FAILED;
     58 	}
     59 
     60 	return MOD_SUCCESS;
     61 }
     62 
     63 MOD_LOAD()
     64 {
     65 	ISupportAdd(modinfo->handle, "NAMELEN", setname_isupport_param());
     66 	return MOD_SUCCESS;
     67 }
     68 
     69 MOD_UNLOAD()
     70 {
     71 	return MOD_SUCCESS;
     72 }
     73 
     74 char *setname_isupport_param(void){
     75 	return STR(REALLEN);
     76 }
     77 
     78 /* cmd_setname - 12/05/1999 - Stskeeps
     79  * :prefix SETNAME :gecos
     80  * parv[1] - gecos
     81  * D: This will set your gecos to be <x> (like (/setname :The lonely wanderer))
     82    this is now compatible with IRCv3 SETNAME --k4be
     83 */ 
     84 CMD_FUNC(cmd_setname)
     85 {
     86 	int xx;
     87 	char oldinfo[REALLEN + 1];
     88 	char spamfilter_user[NICKLEN + USERLEN + HOSTLEN + REALLEN + 64];
     89 	ConfigItem_ban *bconf;
     90 	MessageTag *mtags = NULL;
     91 
     92 	if ((parc < 2) || BadPtr(parv[1]))
     93 	{
     94 		sendnumeric(client, ERR_NEEDMOREPARAMS, "SETNAME");
     95 		return;
     96 	}
     97 
     98 	if (strlen(parv[1]) > REALLEN)
     99 	{
    100 		if (!MyConnect(client))
    101 			return;
    102 		if (HasCapabilityFast(client, CAP_SETNAME))
    103 		{
    104 			new_message(client, recv_mtags, &mtags);
    105 			sendto_one(client, mtags, ":%s FAIL SETNAME INVALID_REALNAME :\"Real names\" may maximum be %i characters of length", me.name, REALLEN);
    106 			free_message_tags(mtags);
    107 		}
    108 		else
    109 		{
    110 			sendnotice(client, "*** /SetName Error: \"Real names\" may maximum be %i characters of length", REALLEN);
    111 		}
    112 		return;
    113 	}
    114 
    115 	strlcpy(oldinfo, client->info, sizeof(oldinfo));
    116 
    117 	if (MyUser(client))
    118 	{
    119 		/* set the new name before we check, but don't send to servers unless it is ok */
    120 		strlcpy(client->info, parv[1], sizeof(client->info));
    121 		spamfilter_build_user_string(spamfilter_user, client->name, client);
    122 		if (match_spamfilter(client, spamfilter_user, SPAMF_USER, "SETNAME", NULL, 0, NULL))
    123 		{
    124 			/* Was rejected by spamfilter, restore the realname */
    125 			if (HasCapabilityFast(client, CAP_SETNAME))
    126 			{
    127 				new_message(client, recv_mtags, &mtags);
    128 				sendto_one(client, mtags, "%s FAIL SETNAME CANNOT_CHANGE_REALNAME :Rejected by server", me.name);
    129 				free_message_tags(mtags);
    130 			}
    131 			strlcpy(client->info, oldinfo, sizeof(client->info));
    132 			return;
    133 		}
    134 
    135 		/* Check for realname bans here too */
    136 		if (!ValidatePermissionsForPath("immune:server-ban:ban-realname",client,NULL,NULL,NULL) &&
    137 		    ((bconf = find_ban(NULL, client->info, CONF_BAN_REALNAME))))
    138 		{
    139 			banned_client(client, "realname", bconf->reason?bconf->reason:"", 0, 0);
    140 			return;
    141 		}
    142 	} else {
    143 		/* remote user */
    144 		strlcpy(client->info, parv[1], sizeof(client->info));
    145 	}
    146 
    147 	new_message(client, recv_mtags, &mtags);
    148 	sendto_local_common_channels(client, client, CAP_SETNAME, mtags, ":%s SETNAME :%s", client->name, client->info);
    149 	sendto_server(client, 0, 0, mtags, ":%s SETNAME :%s", client->id, parv[1]);
    150 
    151 	/* notify the sender */
    152 	if (MyConnect(client))
    153 	{
    154 		if (HasCapabilityFast(client, CAP_SETNAME))
    155 			sendto_prefix_one(client, client, mtags, ":%s SETNAME :%s", client->name, client->info);
    156 		else
    157 			sendnotice(client, "Your \"real name\" is now set to be %s - you have to set it manually to undo it", parv[1]);
    158 	}
    159 	free_message_tags(mtags);
    160 	
    161 	RunHook(HOOKTYPE_REALNAME_CHANGE, client, oldinfo);
    162 }