unrealircd

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

vhost.c (5594B)

      1 /*
      2  *   Unreal Internet Relay Chat Daemon, src/modules/vhost.c
      3  *   (C) 2000-2001 Carsten V. Munk and the UnrealIRCd Team
      4  *
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 1, or (at your option)
      8  *   any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  *   GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program; if not, write to the Free Software
     17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  */
     19 
     20 #include "unrealircd.h"
     21 
     22 CMD_FUNC(cmd_vhost);
     23 
     24 /* Place includes here */
     25 #define MSG_VHOST       "VHOST"
     26 
     27 ModuleHeader MOD_HEADER
     28   = {
     29 	"vhost",	/* Name of module */
     30 	"5.0", /* Version */
     31 	"command /vhost", /* Short description of module */
     32 	"UnrealIRCd Team",
     33 	"unrealircd-6",
     34     };
     35 
     36 /* This is called on module init, before Server Ready */
     37 MOD_INIT()
     38 {
     39 	CommandAdd(modinfo->handle, MSG_VHOST, cmd_vhost, MAXPARA, CMD_USER);
     40 	MARK_AS_OFFICIAL_MODULE(modinfo);
     41 	return MOD_SUCCESS;
     42 }
     43 
     44 /* Is first run when server is 100% ready */
     45 MOD_LOAD()
     46 {
     47 	return MOD_SUCCESS;
     48 }
     49 
     50 
     51 /* Called when module is unloaded */
     52 MOD_UNLOAD()
     53 {
     54 	return MOD_SUCCESS;	
     55 }
     56 
     57 CMD_FUNC(cmd_vhost)
     58 {
     59 	ConfigItem_vhost *vhost;
     60 	char login[HOSTLEN+1];
     61 	const char *password;
     62 	char olduser[USERLEN+1];
     63 
     64 	if (!MyUser(client))
     65 		return;
     66 
     67 	if ((parc < 2) || BadPtr(parv[1]))
     68 	{
     69 		sendnumeric(client, ERR_NEEDMOREPARAMS, "VHOST");
     70 		return;
     71 
     72 	}
     73 
     74 	/* cut-off too long login names. HOSTLEN is arbitrary, we just don't want our
     75 	 * error messages to be cut off because the user is sending huge login names.
     76 	 */
     77 	strlcpy(login, parv[1], sizeof(login));
     78 
     79 	password = (parc > 2) ? parv[2] : "";
     80 
     81 	if (!(vhost = find_vhost(login)))
     82 	{
     83 		unreal_log(ULOG_WARNING, "vhost", "VHOST_FAILED", client,
     84 		           "Failed VHOST attempt by $client.details [reason: $reason] [vhost-block: $vhost_block]",
     85 		           log_data_string("reason", "Vhost block not found"),
     86 		           log_data_string("fail_type", "UNKNOWN_VHOST_NAME"),
     87 		           log_data_string("vhost_block", login));
     88 		sendnotice(client, "*** [\2vhost\2] Login for %s failed - password incorrect", login);
     89 		return;
     90 	}
     91 	
     92 	if (!user_allowed_by_security_group(client, vhost->match))
     93 	{
     94 		unreal_log(ULOG_WARNING, "vhost", "VHOST_FAILED", client,
     95 		           "Failed VHOST attempt by $client.details [reason: $reason] [vhost-block: $vhost_block]",
     96 		           log_data_string("reason", "Host does not match"),
     97 		           log_data_string("fail_type", "NO_HOST_MATCH"),
     98 		           log_data_string("vhost_block", login));
     99 		sendnotice(client, "*** No vHost lines available for your host");
    100 		return;
    101 	}
    102 
    103 	if (!Auth_Check(client, vhost->auth, password))
    104 	{
    105 		unreal_log(ULOG_WARNING, "vhost", "VHOST_FAILED", client,
    106 		           "Failed VHOST attempt by $client.details [reason: $reason] [vhost-block: $vhost_block]",
    107 		           log_data_string("reason", "Authentication failed"),
    108 		           log_data_string("fail_type", "AUTHENTICATION_FAILED"),
    109 		           log_data_string("vhost_block", login));
    110 		sendnotice(client, "*** [\2vhost\2] Login for %s failed - password incorrect", login);
    111 		return;
    112 	}
    113 
    114 	/* Authentication passed, but.. there could still be other restrictions: */
    115 	switch (UHOST_ALLOWED)
    116 	{
    117 		case UHALLOW_NEVER:
    118 			if (MyUser(client))
    119 			{
    120 				sendnotice(client, "*** /vhost is disabled");
    121 				return;
    122 			}
    123 			break;
    124 		case UHALLOW_ALWAYS:
    125 			break;
    126 		case UHALLOW_NOCHANS:
    127 			if (MyUser(client) && client->user->joined)
    128 			{
    129 				sendnotice(client, "*** /vhost can not be used while you are on a channel");
    130 				return;
    131 			}
    132 			break;
    133 		case UHALLOW_REJOIN:
    134 			/* join sent later when the host has been changed */
    135 			break;
    136 	}
    137 
    138 	/* All checks passed, now let's go ahead and change the host */
    139 
    140 	userhost_save_current(client);
    141 
    142 	safe_strdup(client->user->virthost, vhost->virthost);
    143 	if (vhost->virtuser)
    144 	{
    145 		strlcpy(olduser, client->user->username, sizeof(olduser));
    146 		strlcpy(client->user->username, vhost->virtuser, sizeof(client->user->username));
    147 		sendto_server(client, 0, 0, NULL, ":%s SETIDENT %s", client->id,
    148 		    client->user->username);
    149 	}
    150 	client->umodes |= UMODE_HIDE;
    151 	client->umodes |= UMODE_SETHOST;
    152 	sendto_server(client, 0, 0, NULL, ":%s SETHOST %s", client->id, client->user->virthost);
    153 	sendto_one(client, NULL, ":%s MODE %s :+tx", client->name, client->name);
    154 	if (vhost->swhois)
    155 	{
    156 		SWhois *s;
    157 		for (s = vhost->swhois; s; s = s->next)
    158 			swhois_add(client, "vhost", -100, s->line, &me, NULL);
    159 	}
    160 	sendnotice(client, "*** Your vhost is now %s%s%s",
    161 		vhost->virtuser ? vhost->virtuser : "",
    162 		vhost->virtuser ? "@" : "",
    163 		vhost->virthost);
    164 
    165 	if (vhost->virtuser)
    166 	{
    167 		/* virtuser@virthost */
    168 		unreal_log(ULOG_INFO, "vhost", "VHOST_SUCCESS", client,
    169 			   "$client.details is now using vhost $virtuser@$virthost [vhost-block: $vhost_block]",
    170 			   log_data_string("virtuser", vhost->virtuser),
    171 			   log_data_string("virthost", vhost->virthost),
    172 			   log_data_string("vhost_block", login));
    173 	} else {
    174 		/* just virthost */
    175 		unreal_log(ULOG_INFO, "vhost", "VHOST_SUCCESS", client,
    176 			   "$client.details is now using vhost $virthost [vhost-block: $vhost_block]",
    177 			   log_data_string("virthost", vhost->virthost),
    178 			   log_data_string("vhost_block", login));
    179 	}
    180 
    181 	userhost_changed(client);
    182 }