Advertisement
Guest User

m_webirc.c (12/10/2012)

a guest
Dec 10th, 2012
88
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.  *  ph0x@freequest.net
  30.  *
  31.  *  NOTE: This compiles, and it seems to work. If you find any bugs
  32.  *        or other odd stuff, please let me know! -ph0x
  33.  *
  34.  *  HOW?: hybrid has some functions that ratbox hasn't got.
  35.  *        the find_address_conf() functions uses the password parsed
  36.  *        from cgiirc, so there is no need to verify that the auth
  37.  *        block has "webirc." as spoof, since we need the password
  38.  *        to get our AccessItem. Don't remove the spoof in config,
  39.  *        else IsConfDoSpoofIp will return false and CGI:IRC wont
  40.  *        work. (yes, this text probably doesnt make sence, it's
  41.  *        just some mental notes from my side -ph0x)
  42.  * ----------------------------------------------------------------------
  43.  *  NOTE:  As of hybrid 8.x a few module structures have changed
  44.  *         I have taken the liberty to update the include members
  45.  *         and redefine the module as to be seen by ircd-hybrid.
  46.  *         This has been tested and everythign appears to be running
  47.  *         smoothly. -Neo ,o/ (Last modified 12/10/2012)
  48.  * -----------------------------------------------------------------------
  49.  */
  50.  
  51. /* Usage:
  52.  * auth {
  53.  *   user = "webirc@<cgiirc ip>"; # if identd used, put ident username instead
  54.  *   password = "<password>"; # encryption possible
  55.  *   spoof = "webirc."
  56.  *   class = "users";
  57.  * };
  58.  * excempt {
  59.  *   ip = "<cgiirc ip>";
  60.  * };
  61.  * Possible flags:
  62.  *   encrypted - password is encrypted (recommended)
  63.  *   kline_exempt - k/g lines on the cgiirc ip are ignored
  64.  *   gline_exempt - glines on the cgiirc ip are ignored
  65.  * dlines are checked on the cgiirc ip (of course).
  66.  * k/d/g/x lines, auth blocks, user limits, etc are checked using the
  67.  * real host/ip.
  68.  * The password should be specified unencrypted in webirc_password in
  69.  * cgiirc.config
  70.  */
  71.  
  72. #include "stdinc.h"
  73. #include "client.h"     /* client struct */
  74. #include "send.h"       /* sendto_one */
  75. #include "hash.h"
  76. #include "ircd.h"       /* me */
  77. #include "numeric.h"        /* ERR_xxx */
  78. #include "parse.h"
  79. #include "modules.h"
  80. #include "irc_string.h"
  81. #include "hostmask.h"
  82. #include "s_serv.h"
  83. #include "conf.h"
  84.  
  85. /* A few of the above include members have been updated. ,o/ */
  86.  
  87. static void mr_webirc(struct Client *, struct Client *, int, char *[]);
  88.  
  89. struct Message webirc_msgtab = {
  90.     "WEBIRC", 0, 0, 4, 4, MFLG_SLOW, 0,
  91.     { mr_webirc, m_ignore, m_ignore, m_ignore, m_ignore, m_ignore }
  92. };
  93.  
  94.  
  95. /*
  96.  * mr_webirc - webirc message handler
  97.  *      parv[0] = sender prefix
  98.  *      parv[1] = password
  99.  *      parv[2] = fake username (we ignore this)
  100.  *  parv[3] = fake hostname
  101.  *  parv[4] = fake ip
  102.  */
  103. static void
  104. mr_webirc(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
  105. {
  106.     struct AccessItem *aconf;
  107.     const char *encr;
  108.  
  109.     if (!strchr(parv[4], '.') && !strchr(parv[4], ':'))
  110.     {
  111.         sendto_one(source_p, "NOTICE %s :Invalid IP", me.name);
  112.         return;
  113.     }
  114.  
  115.     aconf = find_address_conf(client_p->host,
  116.                 IsGotId(client_p) ? client_p->username : "webirc",
  117.                 (struct irc_ssaddr *) &client_p->localClient->ip,
  118.                 client_p->localClient->ip.ss.ss_family, (char *)parv[1]);
  119.  
  120.     if (aconf == NULL || !(aconf->status & CONF_CLIENT))
  121.         return;
  122.  
  123.     if (!IsConfDoSpoofIp(aconf))
  124.     {
  125.         /* XXX */
  126.         sendto_one(source_p, "NOTICE * :Not a CGI:IRC auth block");
  127.         return;
  128.     }
  129.     if (EmptyString(aconf->passwd))
  130.     {
  131.         sendto_one(source_p, "NOTICE * :CGI:IRC auth blocks must have a password");
  132.         return;
  133.     }
  134.  
  135.     /*
  136.      * This probably isn't necessary, because we are using the password
  137.      * to get our aconf object, which will exit in !IsConfDoSpoofIp(aconf)
  138.      * if not correct. I'm not touching this yet. -ph0x
  139.      */
  140.     if (EmptyString(parv[1]))
  141.         encr = "";
  142.     else if (IsConfEncrypted(aconf))
  143.         encr = crypt(parv[1], aconf->passwd);
  144.     else
  145.         encr = parv[1];
  146.  
  147.     if (strcmp(encr, aconf->passwd))
  148.     {
  149.         sendto_one(source_p, "NOTICE * :CGI:IRC password incorrect");
  150.         return;
  151.     }
  152.  
  153.     /* rest would be necessary */
  154.  
  155.     strlcpy(source_p->sockhost, parv[4], sizeof(source_p->sockhost));
  156.  
  157.     if(strlen(parv[3]) <= HOSTLEN)
  158.         strlcpy(source_p->host, parv[3], sizeof(source_p->host));
  159.     else
  160.         strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host));
  161.    
  162.     /* Check dlines now, k/glines will be checked on registration */
  163.     if((aconf = find_dline_conf((struct irc_ssaddr *)&source_p->localClient->ip,
  164.                    source_p->localClient->ip.ss.ss_family)))
  165.     {
  166.         if(!(aconf->status & CONF_EXEMPTDLINE))
  167.         {
  168.             exit_client(client_p, &me, "D-lined");
  169.             return;
  170.         }
  171.     }
  172.  
  173.     sendto_one(source_p, ":%s NOTICE AUTH :*** CGI:IRC host/IP set to %s %s", me.name, parv[3], parv[4]);
  174.     return;
  175. }
  176.  
  177. /* Begin new code ,o/ */
  178. #ifndef STATIC_MODULES
  179. /* Here we tell it what to do when the module is loaded */
  180. static void
  181. module_init(void)
  182. {
  183.   /* This will add the commands in webirc_msgtab (which is above) */
  184.   mod_add_cmd(&webirc_msgtab);
  185. }
  186.  
  187. /* here we tell it what to do when the module is unloaded */
  188. static void
  189. module_exit(void)
  190. {
  191.   /* This will remove the commands in webirc_msgtab (which is above) */
  192.   mod_del_cmd(&webirc_msgtab);
  193. }
  194.  
  195. /* When we last modified the file (shown in /modlist), this is usually:
  196.  */
  197.  
  198. struct module module_entry = {
  199.   .node    = { NULL, NULL, NULL },
  200.   .name    = NULL,
  201.   .version = "$Revision: 1543$",
  202.   .handle  = NULL,
  203.   .modinit = module_init,
  204.   .modexit = module_exit,
  205.   .flags   = 0
  206. };
  207. #endif
  208. /* End new code ,o/ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement