Exemplo n.º 1
0
/* check for a match with unlimitedhost */
void t_unlmited(transfer * const tr, const char *hostmask)
{
    char *qhostmask;

    if (hostmask != NULL) {
        t_unlmited2(tr, hostmask);
        return;
    }

    qhostmask = to_hostmask(tr->nick, tr->hostname);
    t_unlmited2(tr, qhostmask);
    mydelete(qhostmask);
}
Exemplo n.º 2
0
/* check if a transfer will use more  connections per user than allowed */
static void t_check_duplicateip(transfer *const newtr)
{
    igninfo *ignore;
    char *bhostmask;
    transfer *tr;
    unsigned int found;
    unsigned int num;

    if (gdata.ignore_duplicate_ip == 0)
        return;

    if (gdata.maxtransfersperperson == 0)
        return;

    updatecontext();

    if (newtr->con.family != AF_INET)
        return;

    found = 0;
    for (tr = irlist_get_head(&gdata.trans);
            tr;
            tr = irlist_get_next(tr)) {
        if (tr->tr_status != TRANSFER_STATUS_SENDING)
            continue;
        if (tr->remoteip != newtr->remoteip)
            continue;
        if (!strcmp(tr->hostname, "man")) /* NOTRANSLATE */
            continue;

        ++found;
    }

    if (found <= gdata.maxtransfersperperson)
        return;

    num = gdata.ignore_duplicate_ip * 60; /* n hours */
    for (tr = irlist_get_head(&gdata.trans);
            tr;
            tr = irlist_get_next(tr)) {
        if (tr->tr_status != TRANSFER_STATUS_SENDING)
            continue;
        if (tr->remoteip != newtr->remoteip)
            continue;
        if (!strcmp(tr->hostname, "man")) /* NOTRANSLATE */
            continue;

        t_closeconn(tr, "You are being punished for parallel downloads", 0);
        queue_punish_abuse( "You are being punished for parallel downloads", tr->net, tr->nick);

        bhostmask = to_hostmask( "*", tr->hostname); /* NOTRANSLATE */
        ignore = get_ignore(bhostmask);
        ignore->flags |= IGN_IGNORING;
        ignore->flags |= IGN_MANUAL;
        ignore->bucket = (num*60)/gdata.autoignore_threshold;

        ioutput(OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR,
                "same IP detected, Ignore activated for %s which will last %u min",
                bhostmask, num);
        mydelete(bhostmask);
    }

    write_statefile();
}
Exemplo n.º 3
0
void t_checkminspeed(transfer * const t) {
   char *hostmask;
   char *tempstr2;

   updatecontext();

   if (t->tr_status != TRANSFER_STATUS_SENDING)      return; /* no checking unless we're sending */
   if (t->con.connecttime+MIN_TL > gdata.curtime)    return; /* no checking until time has passed */
   if (t->nomin || (t->xpack->minspeed) == 0.0)      return; /* no minspeed for this transfer */
   if ( t->lastspeed+0.11 > t->xpack->minspeed )     return; /* over minspeed */
   
   if (gdata.no_minspeed_on_free)
     {
        if (irlist_size(&gdata.trans) < gdata.slotsmax) return; /* free slots */
     }
   
   tempstr2 = mymalloc(maxtextlength);
   snprintf(tempstr2, maxtextlength,
        "Under Min Speed Requirement, %2.1fK/sec is less than %2.1fK/sec",
         t->lastspeed,t->xpack->minspeed);
   t_closeconn(t,tempstr2,0);
   mydelete(tempstr2);
   
   if (gdata.punishslowusers)
     {
       igninfo *ignore;
       transfer *tr;
       gnetwork_t *backup;
       
       for (tr = irlist_get_head(&gdata.trans); tr; tr = irlist_get_next(tr))
         {
           if ((tr->tr_status != TRANSFER_STATUS_DONE) &&
               (strcasecmp(tr->nick,t->nick) == 0))
             {
               t_closeconn(tr, "You are being punished for your slowness", 0);
             }
         }
       
       queue_punish_abuse("You are being punished for your slowness", t->net, t->nick);
       
       hostmask = to_hostmask( "*", t->hostname);
       ignore = get_ignore(hostmask);
       mydelete(hostmask);
       ignore->flags |= IGN_IGNORING;
       ignore->bucket = (gdata.punishslowusers*60)/gdata.autoignore_threshold;
       
       backup = gnetwork;
       gnetwork = &(gdata.networks[t->net]);
       ioutput(OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR,
               "Punish-ignore activated for (%s on %s) (%s) %u minutes",
               t->nick, gdata.networks[ t->net ].name,
               ignore->hostmask,
               gdata.punishslowusers);
       
       notice(t->nick, "Punish-ignore activated for %s (%s) %u minutes",
              t->nick,
              ignore->hostmask,
              gdata.punishslowusers);
       
       gnetwork = backup;
       write_statefile();
     }
   
   }
Exemplo n.º 4
0
/* accept incoming connection */
static void telnet_accept(unsigned int i)
{
  gnetwork_t *backup;
  char *msg;
  dccchat_t *chat;
  SIGNEDSOCK int addrlen;

  updatecontext();

  chat = irlist_add(&gdata.dccchats, sizeof(dccchat_t));
  chat->name = "telnet"; /* NOTRANSLATE */
  chat->status = DCCCHAT_UNUSED;
  chat->con.family = telnet_family[i];
  if (chat->con.family != AF_INET) {
    addrlen = sizeof (struct sockaddr_in6);
    chat->con.clientsocket = accept(telnet_listen[i], &(chat->con.remote.sa), &addrlen);
  } else {
    addrlen = sizeof (struct sockaddr_in);
    chat->con.clientsocket = accept(telnet_listen[i], &(chat->con.remote.sa), &addrlen);
  }
  if (chat->con.clientsocket < 0) {
    outerror(OUTERROR_TYPE_WARN, "Accept Error, Aborting: %s", strerror(errno));
    return;
  }

  if (set_socket_nonblocking(chat->con.clientsocket, 1) < 0 ) {
    outerror(OUTERROR_TYPE_WARN, "Couldn't Set Non-Blocking");
  }

  addrlen = sizeof(chat->con.local);
  if (getsockname(chat->con.clientsocket, &(chat->con.local.sa), &addrlen) < 0) {
    outerror(OUTERROR_TYPE_WARN_LOUD, "Couldn't get sock name: %s", strerror(errno));
    shutdown_close(chat->con.clientsocket);
    chat->con.clientsocket = FD_UNUSED;
    return;
  }

  ++(gdata.num_dccchats);
  chat->status = DCCCHAT_AUTHENTICATING;
  chat->net = 0;
  chat->nick = mystrdup("telnet"); /* NOTRANSLATE */
  chat->hostmask = to_hostmask(chat->nick, "telnet"); /* NOTRANSLATE */
  chat->con.localport = gdata.telnet_port;
  chat->con.connecttime = gdata.curtime;
  chat->con.lastcontact = gdata.curtime;

  msg = mymalloc(maxtextlength);
  my_getnameinfo(msg, maxtextlength -1, &(chat->con.remote.sa));
  chat->con.localaddr = mystrdup(msg);
  my_getnameinfo(msg, maxtextlength -1, &(chat->con.local.sa));
  chat->con.remoteaddr = mystrdup(msg);
  ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA,
          "Telnet connection received from %s",  msg);
  mydelete(msg);

  if (is_in_badip(&(chat->con.remote))) {
    shutdowndccchat(chat, 0);
    return;
  }

  if (irlist_size(&gdata.telnet_allow) > 0) {
    if (!verify_cidr(&gdata.telnet_allow, &(chat->con.remote))) {
      shutdowndccchat(chat, 0);
      return;
    }
  }

  if (verify_cidr(&gdata.telnet_deny, &(chat->con.remote))) {
    shutdowndccchat(chat, 0);
    return;
  }

  ir_boutput_init(&chat->boutput, chat->con.clientsocket, 0);

  backup = gnetwork;
  gnetwork = &(gdata.networks[chat->net]);
  setup_chat_banner(chat);
  gnetwork = backup;
}