コード例 #1
0
/* limit connection to the configured interface */
unsigned int bind_irc_vhost(int family, int clientsocket)
{
  const char *vhost;
  ir_sockaddr_union_t localaddr;
  SIGNEDSOCK int addrlen;
  int e;

  vhost = get_local_vhost();
  if (!vhost)
    return 0;

  bzero((char*)&localaddr, sizeof(ir_sockaddr_union_t));
  if (family == AF_INET ) {
    addrlen = sizeof(struct sockaddr_in);
    localaddr.sin.sin_family = AF_INET;
    localaddr.sin.sin_port = 0;
    e = inet_pton(family, vhost, &(localaddr.sin.sin_addr));
  } else {
    addrlen = sizeof(struct sockaddr_in6);
    localaddr.sin6.sin6_family = AF_INET6;
    localaddr.sin6.sin6_port = 0;
    e = inet_pton(family, vhost, &(localaddr.sin6.sin6_addr));
  }

  if (e != 1) {
    outerror(OUTERROR_TYPE_WARN_LOUD, "Invalid IP: %s", vhost);
    return 1;
  }

  if (bind(clientsocket, &(localaddr.sa), addrlen) < 0)
    return 1;

  return 0;
}
コード例 #2
0
/* start normal or passive DCC download */
void t_setup_dcc(transfer *tr)
{
    char *vhost;
    int e = 1;

    updatecontext();

    vhost = get_local_vhost();
    if (tr->passive_dcc) {
        bzero((char *) &(tr->con.local), sizeof(tr->con.local));
        if (tr->con.family == AF_INET) {
            tr->con.local.sin.sin_family = AF_INET;
            tr->con.local.sin.sin_port = htons(0);
            if (vhost) {
                e = inet_pton(tr->con.family, vhost, &(tr->con.local.sin.sin_addr));
            } else {
                tr->con.local.sin.sin_addr.s_addr = gnetwork->myip.sin.sin_addr.s_addr;
            }
        } else {
            tr->con.local.sin6.sin6_family = AF_INET6;
            tr->con.local.sin6.sin6_port = htons(0);
            if (vhost) {
                e = inet_pton(tr->con.family, vhost, &(tr->con.local.sin6.sin6_addr));
            }
        }
        if (e != 1) {
            outerror(OUTERROR_TYPE_WARN_LOUD, "Invalid IP: %s", vhost);
        }
        tr->tr_status = TRANSFER_STATUS_RESUME;
        tr->con.localport = 0;
    } else {
        t_setuplisten(tr);

        if (tr->tr_status != TRANSFER_STATUS_LISTENING)
            return;
    }

    t_start_dcc_send(tr);
}
コード例 #3
0
static unsigned int curl_fetch(const userinput *const u, fetch_curl_t *ft)
{
  char *vhost;
  CURL *ch;
  CURLcode ces;
  CURLcode cms;

  updatecontext();

  ch = curl_easy_init();
  if (ch == NULL) {
    a_respond(u, "Curl not ready");
    return 1;
  }
  ft->curlhandle = ch;

  ces = curl_easy_setopt(ch, CURLOPT_ERRORBUFFER, ft->errorbuf);
  if (ces != 0) {
    curl_respond( u, "ERRORBUFFER", ces); /* NOTRANSLATE */
    return 1;
  }

  vhost = get_local_vhost();
  if (vhost) {
    ft->vhosttext = mystrdup(vhost);
    ces = curl_easy_setopt(ch, CURLOPT_INTERFACE, ft->vhosttext);
    if (ces != 0) {
      a_respond(u, "curl_easy_setopt INTERFACE for %s failed with %d", ft->vhosttext, ces);
      return 1;
    }
  }

  ces = curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1);
  if (ces != 0) {
    curl_respond( u, "NOPROGRESS", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1);
  if (ces != 0) {
    curl_respond( u, "NOSIGNAL", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1);
  if (ces != 0) {
    curl_respond( u, "FAILONERROR", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_SSL_VERIFYHOST, 0);
  if (ces != 0) {
    curl_respond( u, "SSL_VERIFYHOST", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 0);
  if (ces != 0) {
    curl_respond( u, "SSL_VERIFYPEER", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_REFERER, ft->url);
  if (ces != 0) {
    curl_respond( u, "REFERER", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1);
  if (ces != 0) {
    curl_respond( u, "FOLLOWLOCATION", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1);
  if (ces != 0) {
    curl_respond( u, "AUTOREFERER", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_FILETIME, 1);
  if (ces != 0) {
    curl_respond( u, "FILETIME", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_URL, ft->url);
  if (ces != 0) {
    curl_respond( u, "URL", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_WRITEDATA, ft->writefd);
  if (ces != 0) {
    curl_respond( u, "WRITEDATA", ces); /* NOTRANSLATE */
    return 1;
  }

  ces = curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, fetch_header_cb);
  if (ces != 0) {
    curl_respond( u, "HEADERFUNCTION", ces); /* NOTRANSLATE */
    return 1;
  }
  ces = curl_easy_setopt(ch, CURLOPT_HEADERDATA, ft);
  if (ces != 0) {
    curl_respond( u, "HEADERDATA", ces); /* NOTRANSLATE */
    return 1;
  }

  if (ft->resumesize > 0L) {
#if LIBCURL_VERSION_NUM <= 0x70b01
    ces = curl_easy_setopt(ch, CURLOPT_RESUME_FROM, ft->resumesize);
#else
    ces = curl_easy_setopt(ch, CURLOPT_RESUME_FROM_LARGE, ft->resumesize);
#endif
    if (ces != 0) {
      curl_respond( u, "RESUME_FROM", ces); /* NOTRANSLATE */
      return 1;
    }
  }

  cms = curl_multi_add_handle(cm, ch);
  if (cms != 0) {
    a_respond(u, "curl_multi_add_handle failed with %d", cms);
    return 1;
  }

  return 0;
}
コード例 #4
0
/* find a free port and open a new socket for an incoming connection */
unsigned int irc_open_listen(ir_connection_t *con)
{
  unsigned int rc;

  rc = open_listen(con->family, &(con->local), &(con->listensocket), gdata.tcprangestart, 0, 1, get_local_vhost());
  if (rc != 0)
    return rc;

  con->connecttime = gdata.curtime;
  con->lastcontact = gdata.curtime;
  con->localport = get_port(&(con->local));
  return 0;
}