Beispiel #1
0
/*
 * exit_banned_client()
 *
 * Sends an appropriate ban message and disconnects a client.
 */
int
exit_banned_client(aClient *cptr, int loc, char type, char *banmsg, int fast)
{
    char rbuf[512];
    char *target = "*";
    char *reason = "<no reason specified>";
    
    if (cptr->name[0])
        target = cptr->name;
    
    if (!BadPtr(banmsg))
        reason = banmsg;
    
    ircsnprintf(rbuf, sizeof(rbuf), "%c-banned: %s", type, reason);
    
    if (!fast)
    {
      sendto_one(&me, cptr, "NOTICE %s :*** You are banned from %s", target,
                   loc ? me.name : Network_Name);
      sendto_one(&me, cptr, "NOTICE %s :*** Reason: %s", target, reason);
      sendto_one(&me, cptr, "NOTICE %s :*** Connection info: %s [%s]", target,
                   get_client_name(cptr, FALSE),
                   cipntoa(cptr));
      sendto_one(&me, cptr, "NOTICE %s :*** Ban contact: %s", target,
                   loc ? Local_Kline_Address : Network_Kline_Address);
      sendto_one(&me, cptr, "NOTICE %s :*** When contacting %s, please include "
                   "all of the information shown above", target, Network_Name);
      sendto_one(&me, cptr, err_str(ERR_YOUREBANNEDCREEP), me.name, target, rbuf);
        
        throttle_force(cipntoa(cptr));
    }
    
    return exit_client(cptr, cptr, &me, rbuf);
}
Beispiel #2
0
/*
 * * get_client_name *      Return the name of the client for various
 * tracking and *      admin purposes. The main purpose of this
 * function is to *      return the "socket host" name of the client,
 * if that *    differs from the advertised name (other than case). *
 * But, this can be used to any client structure. *
 * 
 *      Returns: *        "name[user@ip#.port]" if 'showip' is true; *
 * "name[sockethost]", if name and sockhost are different and *
 * showip is false; else *        "name". *
 * 
 * NOTE 1: *    Watch out the allocation of "nbuf", if either
 * sptr->name * or sptr->sockhost gets changed into pointers instead of *
 * directly allocated within the structure... *
 * 
 * NOTE 2: *    Function return either a pointer to the structure
 * (sptr) or *  to internal buffer (nbuf). *NEVER* use the returned
 * pointer *    to modify what it points!!!
 */
char *
get_client_name(aClient *sptr, int showip)
{
    static char nbuf[HOSTLEN * 2 + USERLEN + 7];
    char *s = nbuf;

    if (MyConnect(sptr)) 
    {
        if (sptr->name[0])
            s += ircsprintf(s, "%s", sptr->name);
        else
            s += ircsprintf(s, "%s", "<unnamed>");

        if (IsServer(sptr))
        {
            if (showip == TRUE)
                s += ircsprintf(s, "[%s]", cipntoa(sptr));
            else if (showip != HIDEME)
                s += ircsprintf(s, "[%s]", sptr->sockhost);
        }
        else if (IsClient(sptr))
        {
            if (showip == TRUE)
                s += ircsprintf(s, "!%s@%s", sptr->user->username,
                                cipntoa(sptr));
            else if (showip != HIDEME)
                s += ircsprintf(s, "!%s@%s", sptr->user->username,
                                sptr->user->host);
        }
        else
        {
            if (showip != HIDEME)
            {
                s += ircsprintf(s, "([");

                if (DoingAuth(sptr))
                    *s++ = '?';
                else if (sptr->flags & FLAGS_GOTID)
                    *s++ = '+';
                else
                    *s++ = '-';

                if (showip == TRUE)
                    s += ircsprintf(s, "]%s@%s)", sptr->username,
                                    cipntoa(sptr));
                else
                    s += ircsprintf(s, "]%s@%s)", sptr->username,
                                    sptr->sockhost);
            }
        }

        return nbuf;
    }

    return sptr->name;
}
Beispiel #3
0
static void sendnick_TS(aClient *cptr, aClient *acptr)
{
    ServicesTag *servicestag;
    static char ubuf[30];
    int *s, flag, i;

    if (IsPerson(acptr))
    {
        send_umode(NULL, acptr, 0, SEND_UMODES, ubuf);
        if (!*ubuf)     /* trivial optimization - Dianora */
        {
            ubuf[0] = '+';
            ubuf[1] = '\0';
        }
	if (IsNickIPStr(cptr))
	{
	    sendto_one(cptr, "NICK %s %d %ld %s %s %s %s %lu %s :%s",
			   acptr->name, acptr->hopcount + 1, acptr->tsinfo, ubuf,
			   acptr->user->username, acptr->user->host,
			   acptr->user->server, acptr->user->servicestamp,
			   cipntoa(acptr), acptr->info);
	}
	else
	{
	    sendto_one(cptr, "NICK %s %d %ld %s %s %s %s %lu %u :%s",
			   acptr->name, acptr->hopcount + 1, acptr->tsinfo, ubuf,
			   acptr->user->username, acptr->user->host,
			   acptr->user->server, acptr->user->servicestamp,
			   (acptr->ip_family == AF_INET) ?
			   htonl(acptr->ip.ip4.s_addr) : 1, acptr->info);
	}
        for(servicestag = acptr->user->servicestag; servicestag; servicestag = servicestag->next)
        {
            ubuf[0] = '+';
            i = 1;
            for (s = user_modes; (flag = *s); s += 2)
                if(servicestag->umode & flag)
                {
                   ubuf[i++] = *(s + 1);
                }
            ubuf[i++] = '\0';
            sendto_one(cptr, "SVSTAG %s %ld %d %s :%s", acptr->name, acptr->tsinfo, servicestag->raw,
                       ubuf, servicestag->tag);
        }
#ifdef USER_HOSTMASKING
        if(acptr->flags & FLAGS_SPOOFED)
            sendto_one(cptr, "SVSHOST %s %s", acptr->name, acptr->user->mhost);
#endif
    }
}
Beispiel #4
0
static int
m_server_estab(aClient *cptr)
{
    aConnect *aconn;
    aClient *acptr;

    char       *inpath, *host, *s, *encr;

    inpath = get_client_name(cptr, HIDEME);  /* "refresh" inpath with host  */
    host = cptr->name;

    if (!(aconn = cptr->serv->aconn))
    {
        ircstp->is_ref++;
        sendto_one(cptr, "ERROR :Lost Connect block");
        sendto_ops_lev(ADMIN_LEV, "Lost Connect block for server %s",
                           get_client_name(cptr, TRUE));
        return exit_client(cptr, cptr, cptr, "Lost Connect block");
    }

    encr = cptr->passwd;
    if (*aconn->apasswd && !StrEq(aconn->apasswd, encr))
    {
        ircstp->is_ref++;
        sendto_one(cptr, "ERROR :Wrong link password");
        sendto_ops("Link %s dropped, wrong password", inpath);
        return exit_client(cptr, cptr, cptr, "Bad Password");
    }
    memset(cptr->passwd, '\0', sizeof(cptr->passwd));

    if ((acptr = find_client(host, NULL)))
    {
        /* Don't complain about juped servers */
        if(!IsULine(acptr) || find_aUserver(acptr->name))
        {
            sendto_gnotice("from %s: Link %s dropped, server already exists",
                           me.name, inpath);
            sendto_serv_butone(cptr, ":%s GNOTICE :Link %s dropped, server already"
                               " exists", me.name, inpath);
        }
        return exit_client(cptr, cptr, cptr, "Server Exists");
    }

    if(!(confopts & FLAGS_HUB))
    {
        int i;
        for (i = 0; i <= highest_fd; i++)
            if (local[i] && IsServer(local[i]))
            {
                ircstp->is_ref++;
                sendto_one(cptr, "ERROR :I'm a leaf not a hub");
                return exit_client(cptr, cptr, cptr, "I'm a leaf");
            }
    }

    /* aconf->port is a CAPAB field, kind-of. kludge. mm, mm. */
    /* no longer! this should still get better though */
    if((aconn->flags & CONN_ZIP))
        SetZipCapable(cptr);
    if((aconn->flags & CONN_DKEY))
        SetWantDKEY(cptr);
    if (IsUnknown(cptr))
    {
        if (aconn->cpasswd[0])
            sendto_one(cptr, "PASS %s :TS", aconn->cpasswd);

        /* Pass my info to the new server */

#ifdef HAVE_ENCRYPTION_ON
        if(!WantDKEY(cptr))
            sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT ZIP "
                       "NICKIP NICKIPSTR TSMODE");
        else
            sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT DKEY "
                       "ZIP NICKIP NICKIPSTR TSMODE");
#else
        sendto_one(cptr, "CAPAB SSJOIN NOQUIT BURST UNCONNECT ZIP NICKIP NICKIPSTR TSMODE");
#endif

        sendto_one(cptr, "SERVER %s 1 :%s",
                   my_name_for_link(me.name, aconn),
                   (me.info[0]) ? (me.info) : "IRCers United");
    }
    else 
    {
        s = (char *) strchr(aconn->host, '@');
        *s = '\0';      /* should never be NULL -- wanna bet? -Dianora */

        Debug((DEBUG_INFO, "Check Usernames [%s]vs[%s]", aconn->host,
               cptr->username));
        if (match(aconn->host, cptr->username))
        {
            *s = '@';
            ircstp->is_ref++;
            sendto_ops("Username mismatch [%s]v[%s] : %s",
                       aconn->host, cptr->username,
                       get_client_name(cptr, HIDEME));
            sendto_one(cptr, "ERROR :No Username Match");
            return exit_client(cptr, cptr, cptr, "Bad User");
        }
        *s = '@';
    }

    /* send routing notice, this should never happen anymore */
    if (!DoesTS(cptr))
    {
        sendto_gnotice("from %s: Warning: %s linked, non-TS server",
                       me.name, get_client_name(cptr, HIDEME));
        sendto_serv_butone(cptr,
                           ":%s GNOTICE :Warning: %s linked, non-TS server",
                           me.name, get_client_name(cptr, HIDEME));
    }

    sendto_one(cptr, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN,
               (ts_val) timeofday);

    /* sendto one(cptr, "CAPAB ...."); moved to after PASS but before SERVER
     * now in two places.. up above and in s_bsd.c. - lucas
     * This is to make sure we pass on our capabilities before we establish
     * a server connection
     */

    /*
     * *WARNING*
     *   In the following code in place of plain
     * server's name we send what is returned by
     * get_client_name which may add the "sockhost" after the name.
     * It's *very* *important* that there is a SPACE between
     * the name and sockhost (if present). The receiving server
     * will start the information field from this first blank and
     * thus puts the sockhost into info. ...a bit tricky, but
     * you have been warned, besides code is more neat this way...
     * --msa
     */

    cptr->serv->up = me.name;
    cptr->serv->aconn = aconn;

    throttle_remove(cipntoa(cptr));

#ifdef HAVE_ENCRYPTION_ON
    if(!CanDoDKEY(cptr) || !WantDKEY(cptr))
        return do_server_estab(cptr);
    else
    {
        SetNegoServer(cptr); /* VERY IMPORTANT THAT THIS IS HERE */
        sendto_one(cptr, "DKEY START");
    }
#else
    return do_server_estab(cptr);
#endif

    return 0;
}