unrealircd

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

userip.c (3372B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/userip.c
      3  *   (C) 2004 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 CMD_FUNC(cmd_userip);
     26 
     27 #define MSG_USERIP 	"USERIP"	
     28 
     29 ModuleHeader MOD_HEADER
     30   = {
     31 	"userip",
     32 	"5.0",
     33 	"command /userip", 
     34 	"UnrealIRCd Team",
     35 	"unrealircd-6",
     36     };
     37 
     38 MOD_INIT()
     39 {
     40 	CommandAdd(modinfo->handle, MSG_USERIP, cmd_userip, 1, CMD_USER);
     41 	ISupportAdd(modinfo->handle, "USERIP", NULL);
     42 	MARK_AS_OFFICIAL_MODULE(modinfo);
     43 	return MOD_SUCCESS;
     44 }
     45 
     46 MOD_LOAD()
     47 {
     48 	return MOD_SUCCESS;
     49 }
     50 
     51 MOD_UNLOAD()
     52 {
     53 	return MOD_SUCCESS;
     54 }
     55 
     56 /*
     57  * cmd_userip is based on cmd_userhost
     58  * cmd_userhost added by Darren Reed 13/8/91 to aid clients and reduce
     59  * the need for complicated requests like WHOIS. It returns user/host
     60  * information only (no spurious AWAY labels or channels).
     61  * Re-written by Dianora 1999
     62  */
     63 /* Keep this at 5!!!! */
     64 #define MAXUSERHOSTREPLIES 5
     65 CMD_FUNC(cmd_userip)
     66 {
     67 
     68 	char *p;		/* scratch end pointer */
     69 	char *cn;		/* current name */
     70 	char *ip, ipbuf[HOSTLEN+1];
     71 	Client *acptr;
     72 	char request[BUFSIZE];
     73 	char response[MAXUSERHOSTREPLIES][NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30];
     74 	int  i;			/* loop counter */
     75 	int w;
     76 
     77 	if (!MyUser(client))
     78 		return;
     79 		
     80 	if (parc < 2)
     81 	{
     82 		sendnumeric(client, ERR_NEEDMOREPARAMS, "USERIP");
     83 		return;
     84 	}
     85 
     86 	/* The idea is to build up the response string out of pieces
     87 	 * none of this strlen() nonsense.
     88 	 * MAXUSERHOSTREPLIES * (NICKLEN*2+CHANNELLEN+USERLEN+HOSTLEN+30) is still << sizeof(buf)
     89 	 * and our ircsnprintf() truncates it to fit anyway. There is
     90 	 * no danger of an overflow here. -Dianora
     91 	 */
     92 	response[0][0] = response[1][0] = response[2][0] = response[3][0] = response[4][0] = '\0';
     93 
     94 	strlcpy(request, parv[1], sizeof(request));
     95 	cn = request;
     96 
     97 	for (w = 0, i = 0; (i < MAXUSERHOSTREPLIES) && cn; i++)
     98 	{
     99 		if ((p = strchr(cn, ' ')))
    100 			*p = '\0';
    101 
    102 		if ((acptr = find_user(cn, NULL)))
    103 		{
    104 			if (!(ip = GetIP(acptr)))
    105 				ip = "<unknown>";
    106 			if (client != acptr && !ValidatePermissionsForPath("client:see:ip",client,acptr,NULL,NULL) && IsHidden(acptr))
    107 			{
    108 				make_cloakedhost(acptr, GetIP(acptr), ipbuf, sizeof(ipbuf));
    109 				ip = ipbuf;
    110 			}
    111 
    112 			ircsnprintf(response[w], NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30, "%s%s=%c%s@%s",
    113 			    acptr->name,
    114 			    (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client)))
    115 				? "*" : "",
    116 			    (acptr->user->away) ? '-' : '+',
    117 			    acptr->user->username, ip);
    118 			w++;
    119 		}
    120 		if (p)
    121 			p++;
    122 		cn = p;
    123 	}
    124 
    125 	sendnumeric(client, RPL_USERIP, response[0], response[1], response[2], response[3], response[4]);
    126 }