Guest User

m_webirc.c (12/10/2012)

a guest
Dec 10th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.71 KB | None | 0 0
  1. /*
  2.  *  m_webirc.c: Makes CGI:IRC users appear as coming from their real host
  3.  *              ported from ircd-ratbox to ircd-hybrid by ph0x
  4.  *
  5.  *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
  6.  *  Copyright (C) 1996-2002 Hybrid Development Team
  7.  *  Copyright (C) 2002-2006 ircd-ratbox development team
  8.  *  Copyright (C) 2007 FreeQuest IRC Network Coders
  9.  *  Copyright (C) 2012 Neo Anderson of IRCur Networks
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation; either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program; if not, write to the Free Software
  23.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  24.  *  USA
  25.  *
  26.  *  $Id: m_webirc.c 23014 2006-08-31 20:47:45Z androsyn $
  27.  * ---------------------------------------------------------------------
  28.  *  I hacked this for hybrid 7.2.3, email questions / comments to
  29.  *
  30.  *  NOTE: This compiles, and it seems to work. If you find any bugs
  31.  *        or other odd stuff, please let me know! -ph0x
  32.  *
  33.  *  HOW?: hybrid has some functions that ratbox hasn't got.
  34.  *        the find_address_conf() functions uses the password parsed
  35.  *        from cgiirc, so there is no need to verify that the auth
  36.  *        block has "webirc." as spoof, since we need the password
  37.  *        to get our AccessItem. Don't remove the spoof in config,
  38.  *        else IsConfDoSpoofIp will return false and CGI:IRC wont
  39.  *        work. (yes, this text probably doesnt make sence, it's
  40.  *        just some mental notes from my side -ph0x)
  41.  * ----------------------------------------------------------------------
  42.  *  NOTE:  As of hybrid 8.x a few module structures have changed
  43.  *         I have taken the liberty to update the include members
  44.  *         and redefine the module as to be seen by ircd-hybrid.
  45.  *         This has been tested and everythign appears to be running
  46.  *         smoothly. -Neo ,o/ (Last modified 12/10/2012)
  47.  * -----------------------------------------------------------------------
  48.  */
  49.  
  50. /* Usage:
  51.  * auth {
  52.  *   user = "webirc@<cgiirc ip>"; # if identd used, put ident username instead
  53.  *   password = "<password>"; # encryption possible
  54.  *   spoof = "webirc."
  55.  *   class = "users";
  56.  * };
  57.  * excempt {
  58.  *   ip = "<cgiirc ip>";
  59.  * };
  60.  * Possible flags:
  61.  *   encrypted - password is encrypted (recommended)
  62.  *   kline_exempt - k/g lines on the cgiirc ip are ignored
  63.  *   gline_exempt - glines on the cgiirc ip are ignored
  64.  * dlines are checked on the cgiirc ip (of course).
  65.  * k/d/g/x lines, auth blocks, user limits, etc are checked using the
  66.  * real host/ip.
  67.  * The password should be specified unencrypted in webirc_password in
  68.  * cgiirc.config
  69.  */
  70.  
  71. #include "stdinc.h"
  72. #include "client.h"     /* client struct */
  73. #include "send.h"       /* sendto_one */
  74. #include "hash.h"
  75. #include "ircd.h"       /* me */
  76. #include "numeric.h"        /* ERR_xxx */
  77. #include "parse.h"
  78. #include "modules.h"
  79. #include "irc_string.h"
  80. #include "hostmask.h"
  81. #include "s_serv.h"
  82. #include "conf.h"
  83.  
  84. /* A few of the above include members have been updated. ,o/ */
  85.  
  86. static void mr_webirc(struct Client *, struct Client *, int, char *[]);
  87.  
  88. struct Message webirc_msgtab = {
  89.     "WEBIRC", 0, 0, 4, 4, MFLG_SLOW, 0,
  90.     { mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore }
  91. };
  92.  
  93.  
  94. /*
  95.  * mr_webirc - webirc message handler
  96.  *      parv[0] = sender prefix
  97.  *      parv[1] = password
  98.  *      parv[2] = fake username (we ignore this)
  99.  *  parv[3] = fake hostname
  100.  *  parv[4] = fake ip
  101.  */
  102. static void
  103. mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
  104. {
  105.     struct AccessItem *aconf;
  106.     const char *encr;
  107.  
  108.     if (!strchr(parv[4], '.') && !strchr(parv[4], ':'))
  109.     {
  110.         sendto_one(source_p, "NOTICE %s :Invalid IP", me.name);
  111.         return;
  112.     }
  113.  
  114.     aconf = find_address_conf(client_p->host,
  115.                 IsGotId(client_p) ? client_p->username : "webirc",
  116.                 (struct irc_ssaddr *) &client_p->localClient->ip,
  117.                 client_p->localClient->ip.ss.ss_family, (char *)parv[1]);
  118.  
  119.     if (aconf == NULL || !(aconf->status & CONF_CLIENT))
  120.         return;
  121.  
  122.     if (!IsConfDoSpoofIp(aconf))
  123.     {
  124.         /* XXX */
  125.         sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block");
  126.         return;
  127.     }
  128.     if (EmptyString(aconf->passwd))
  129.     {
  130.         sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password");
  131.         return;
  132.     }
  133.  
  134.     /*
  135.      * This probably isn't necessary, because we are using the password
  136.      * to get our aconf object, which will exit in !IsConfDoSpoofIp(aconf)
  137.      * if not correct. I'm not touching this yet. -ph0x
  138.      */
  139.     if (EmptyString(parv[1]))
  140.         encr = "";
  141.     else if (IsConfEncrypted(aconf))
  142.         encr = crypt(parv[1], aconf->passwd);
  143.     else
  144.         encr = parv[1];
  145.  
  146.     if (strcmp(encr, aconf->passwd))
  147.     {
  148.         sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect");
  149.         return;
  150.     }
  151.  
  152.     /* rest would be necessary */
  153.  
  154.     strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost));
  155.  
  156.     if(strlen(parv[3]) <= HOSTLEN)
  157.         strlcpy(source_p->host, parv[3], sizeof(source_p->host));
  158.     else
  159.         strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
  160.    
  161.     /* Check dlines now, k/glines will be checked on registration */
  162.     if((aconf = find_dline_conf((struct irc_ssaddr *)&source_p->localClient->ip,
  163.                    source_p->localClient->ip.ss.ss_family)))
  164.     {
  165.         if(!(aconf->status & CONF_EXEMPTDLINE))
  166.         {
  167.             exit_client(client_p, &me, "D-lined");
  168.             return;
  169.         }
  170.     }
  171.  
  172.     sendto_one(source_p, ":%s NOTICE AUTH :*** CGI:IRC host/IP set to %s %s", me.name, parv[3], parv[4]);
  173.     return;
  174. }
  175.  
  176. /* Begin new code ,o/ */
  177. #ifndef STATIC_MODULES
  178. /* Here we tell it what to do when the module is loaded */
  179. static void
  180. module_init(void)
  181. {
  182.   /* This will add the commands in webirc_msgtab (which is above) */
  183.   mod_add_cmd(&webirc_msgtab);
  184. }
  185.  
  186. /* here we tell it what to do when the module is unloaded */
  187. static void
  188. module_exit(void)
  189. {
  190.   /* This will remove the commands in webirc_msgtab (which is above) */
  191.   mod_del_cmd(&webirc_msgtab);
  192. }
  193.  
  194. /* When we last modified the file (shown in /modlist), this is usually:
  195.  */
  196.  
  197. struct module module_entry = {
  198.   .node    = { NULL, NULL, NULL },
  199.   .name    = NULL,
  200.   .version = "$Revision: 1543$",
  201.   .handle  = NULL,
  202.   .modinit = module_init,
  203.   .modexit = module_exit,
  204.   .flags   = 0
  205. };
  206. #endif
  207. /* End new code ,o/ */
Advertisement
Add Comment
Please, Sign In to add comment