unrealircd

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

userip-tag.c (2885B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/userip-tag.c
      3  *   (C) 2020 Syzop & The UnrealIRCd Team
      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 ModuleHeader MOD_HEADER
     26   = {
     27 	"userip-tag",
     28 	"5.0",
     29 	"userip message tag",
     30 	"UnrealIRCd Team",
     31 	"unrealircd-6",
     32 	};
     33 
     34 /* Variables */
     35 long CAP_ACCOUNT_TAG = 0L;
     36 
     37 int userip_mtag_is_ok(Client *client, const char *name, const char *value);
     38 int userip_mtag_should_send_to_client(Client *target);
     39 void mtag_add_userip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
     40 
     41 MOD_INIT()
     42 {
     43 	MessageTagHandlerInfo mtag;
     44 
     45 	MARK_AS_OFFICIAL_MODULE(modinfo);
     46 
     47 	memset(&mtag, 0, sizeof(mtag));
     48 	mtag.name = "unrealircd.org/userip";
     49 	mtag.is_ok = userip_mtag_is_ok;
     50 	mtag.should_send_to_client = userip_mtag_should_send_to_client;
     51 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     52 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     53 
     54 	HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_userip);
     55 
     56 	return MOD_SUCCESS;
     57 }
     58 
     59 MOD_LOAD()
     60 {
     61 	return MOD_SUCCESS;
     62 }
     63 
     64 MOD_UNLOAD()
     65 {
     66 	return MOD_SUCCESS;
     67 }
     68 
     69 /** This function verifies if the client sending
     70  * 'userip-tag' is permitted to do so and uses a permitted
     71  * syntax.
     72  * We simply allow userip-tag ONLY from servers and with any syntax.
     73  */
     74 int userip_mtag_is_ok(Client *client, const char *name, const char *value)
     75 {
     76 	if (IsServer(client))
     77 		return 1;
     78 
     79 	return 0;
     80 }
     81 
     82 void mtag_add_userip(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
     83 {
     84 	MessageTag *m;
     85 
     86 	if (IsUser(client) && client->ip)
     87 	{
     88 		MessageTag *m = find_mtag(recv_mtags, "unrealircd.org/userip");
     89 		if (m)
     90 		{
     91 			m = duplicate_mtag(m);
     92 		} else {
     93 			char nuh[USERLEN+HOSTLEN+1];
     94 
     95 			snprintf(nuh, sizeof(nuh), "%s@%s", client->user->username, GetIP(client));
     96 
     97 			m = safe_alloc(sizeof(MessageTag));
     98 			safe_strdup(m->name, "unrealircd.org/userip");
     99 			safe_strdup(m->value, nuh);
    100 		}
    101 		AddListItem(m, *mtag_list);
    102 	}
    103 }
    104 
    105 /** Outgoing filter for this message tag */
    106 int userip_mtag_should_send_to_client(Client *target)
    107 {
    108 	if (IsServer(target) || IsOper(target))
    109 		return 1;
    110 	return 0;
    111 }