示例#1
0
static int
test_file_server_serv_connect()
{
    test_start("fs serv_connect");
    for (int i = 0; i < 5; i++) {
        serv_connection_t c = serv_connect("/fileserv/*");
        test_assert(c.error == ESUCCESS);
        test_assert(c.paramBuffer.err == ESUCCESS);
        strcpy(c.paramBuffer.vaddr, "test");
        serv_disconnect(&c);
    }
    return test_success();
}
示例#2
0
/*
 * mo_connect - CONNECT command handler
 *
 * Added by Jto 11 Feb 1989
 *
 * m_connect
 *      parv[1] = servername
 *      parv[2] = port number
 *      parv[3] = remote server
 */
static int
mo_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	int port;
	int tmpport;
	struct server_conf *server_p;
	struct Client *target_p;

	/* always privileged with handlers */

	if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
	{
		sendto_one(source_p, form_str(ERR_NOPRIVS),
			   me.name, source_p->name, "remote");
		return 0;
	}

	if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
		return 0;

	if((target_p = find_server(source_p, parv[1])))
	{
		sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.", parv[1],
			target_p->from->name);
		return 0;
	}

	/*
	 * try to find the name, then host, if both fail notify ops and bail
	 */
	if((server_p = find_server_conf(parv[1])) == NULL)
	{
		sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf", parv[1]);
		return 0;
	}

	if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))
	{
		sendto_one_notice(source_p,
				  ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",
				  parv[1]);
		return 0;
	}

	/*
	 * Get port number from user, if given. If not specified,
	 * use the default form configuration structure. If missing
	 * from there, then use the precompiled default.
	 */
	tmpport = port = 0;
	if(parc > 2 && !EmptyString(parv[2]))
		port = atoi(parv[2]);
	if(port == 0 && server_p->port)
		port = server_p->port;
	else if(port <= 0)
	{
		sendto_one_notice(source_p, ":Connect: illegal port number");
		return 0;
	}
	
	/*
	 * Notify all operators about remote connect requests
	 */

	ilog(L_SERVER, "CONNECT From %s : %s %s", source_p->name, parv[1], parc > 2 ? parv[2] : "");

	server_p->port = port;
	/*
	 * at this point we should be calling connect_server with a valid
	 * C:line and a valid port in the C:line
	 */
	if(serv_connect(server_p, source_p))
	{
			sendto_one_notice(source_p, ":*** Connecting to %s.%d",
				server_p->name, server_p->port);
	}
	else
	{
		sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
			server_p->name, server_p->port);
	}

	/*
	 * client is either connecting with all the data it needs or has been
	 * destroyed
	 */
	server_p->port = tmpport;
	return 0;
}
示例#3
0
/*
 * ms_connect - CONNECT command handler
 *
 * Added by Jto 11 Feb 1989
 *
 * m_connect
 *      parv[1] = servername
 *      parv[2] = port number
 *      parv[3] = remote server
 */
static int
ms_connect(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
{
	int port;
	int tmpport;
	struct server_conf *server_p;
	struct Client *target_p;

	if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
		return 0;

	if((target_p = find_server(NULL, parv[1])))
	{
		sendto_one_notice(source_p, ":Connect: Server %s already exists from %s.",
				  parv[1], target_p->from->name);
		return 0;
	}

	/*
	 * try to find the name, then host, if both fail notify ops and bail
	 */
	if((server_p = find_server_conf(parv[1])) == NULL)
	{
		sendto_one_notice(source_p, ":Connect: Host %s not listed in ircd.conf",
				  parv[1]);
		return 0;
	}

	if(ServerConfSSL(server_p) && (!ssl_ok || !get_ssld_count()))
	{
		sendto_one_notice(source_p,
				  ":Connect: Server %s is set to use SSL/TLS but SSL/TLS is not configured.",
				  parv[1]);
		return 0;
	}

	/*
	 * Get port number from user, if given. If not specified,
	 * use the default form configuration structure. If missing
	 * from there, then use the precompiled default.
	 */
	tmpport = server_p->port;

	port = atoi(parv[2]);

	/* if someone sends port 0, and we have a config port.. use it */
	if(port == 0 && server_p->port)
		port = server_p->port;
	else if(port <= 0)
	{
		sendto_one_notice(source_p, ":Connect: Illegal port number");
		return 0;
	}

	/*
	 * Notify all operators about remote connect requests
	 */
	sendto_wallops_flags(UMODE_WALLOP, &me,
			     "Remote CONNECT %s %d from %s",
			     parv[1], port, source_p->name);
	sendto_server(NULL, NULL, CAP_TS6, NOCAPS,
		      ":%s WALLOPS :Remote CONNECT %s %d from %s",
		      me.id, parv[1], port, source_p->name);

	ilog(L_SERVER, "CONNECT From %s : %s %d", source_p->name, parv[1], port);

	server_p->port = port;
	/*
	 * at this point we should be calling connect_server with a valid
	 * C:line and a valid port in the C:line
	 */
	if(serv_connect(server_p, source_p))
		sendto_one_notice(source_p, ":*** Connecting to %s.%d",
				  server_p->name, server_p->port);
	else
		sendto_one_notice(source_p, ":*** Couldn't connect to %s.%d",
				  server_p->name, server_p->port);
	/*
	 * client is either connecting with all the data it needs or has been
	 * destroyed
	 */
	server_p->port = tmpport;
	return 0;
}
示例#4
0
文件: client.c 项目: twonly/mis
int	ppfs_write (const char *path, const char *buf, size_t st, off_t off, struct fuse_file_info *fi){
  fprintf(stderr,"\n\n\nppfs_write:%s,size:%d,offset:%d\n\n\n",path,st,off);

  int nwrite = 0;

  int ost,ooff;
  ost = st;
  ooff = off;

  ppacket* p = createpacket_s(4+strlen(path),CLTOMD_READ_CHUNK_INFO,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;
  int plen = strlen(path);
  uint32_t ip;
  uint64_t* chunklist = NULL;
  int clen,calloc;
  const char* wbuf = buf;

  put32bit(&ptr,plen);
  memcpy(ptr,path,plen);
  ptr += plen;

  fprintf(stderr,"just to be clear\n");
  const uint8_t* tmpptr = p->startptr + HEADER_LEN;
  int i;
  for(i=0;i<p->size;i+=1){
    int x = get8bit(&tmpptr);
    fprintf(stderr,"%X\t",x);
  }
  fprintf(stderr,"\n");

  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);
  fprintf(stderr,"status:%d\n",status);
  if(status == 0){
    ip = get32bit(&ptr2);
    if(ip == -1){
      fprintf(stderr,"local mds\n");
    } else {
      fprintf(stderr,"remote mds:%X\n",ip);
    }

    int chunks = get32bit(&ptr2);
    fprintf(stderr,"chunks=%d\n",chunks);
    int i;

    chunklist = (uint64_t*)malloc(sizeof(uint64_t)*(chunks+20));
    clen = 0;
    calloc = chunks+20;

    for(i=0;i<chunks;i++){
      uint64_t chunkid = get64bit(&ptr2);
      fprintf(stderr,"(%d):id=%lld\n",i,chunkid);

      chunklist[clen++] = chunkid;
    }

    ppfs_conn_entry* e = NULL;
    if(ip != -1){
      if(remote_mds.sockfd != -1 && remote_mds.peerip != ip){
        tcpclose(remote_mds.sockfd);
        remote_mds.sockfd = -1;
      }

      if(remote_mds.sockfd == -1){
        if(serv_connect(&remote_mds,ip,MDS_PORT) < 0){
          return -1;
        }
      }

      e = &remote_mds;
    } else {
      e = &local_mds;
    }

    fprintf(stderr,"connected\n");

    if(chunks * CHUNKSIZE <= off + st){
      fprintf(stderr,"clearing cache\n");

      chunk_cache* cc;
      attr_cache* ac;
      if(lookup_chunk_cache(path,&cc) == 0){
        remove_chunk_cache(cc);
        free_chunk_cache(cc);
      }
      if(lookup_attr_cache(path,&ac) == 0){
        remove_attr_cache(ac);
        free_attr_cache(ac);
      }

      fprintf(stderr,"appending chunk\n");
      while(chunks * CHUNKSIZE <= off + st){
        ppacket* p = createpacket_s(4+plen,CLTOMD_APPEND_CHUNK,-1);
        uint8_t* ptr = p->startptr + HEADER_LEN;
        put32bit(&ptr,plen);
        memcpy(ptr,path,plen);
        sendpacket(e->sockfd,p);
        free(p);

        ppacket* rp = receivepacket(e->sockfd);
        const uint8_t* ptr2 = rp->startptr;
        int status = get32bit(&ptr2);
        printf("status:%d\n",status);
        if(status == 0){
          uint64_t chunkid = get64bit(&ptr2);
          printf("chunkid=%lld\n",chunkid);

          if(clen < calloc){
            chunklist[clen++] = chunkid;
          } else {
            chunklist = (uint64_t*)realloc(chunklist,calloc<<1);
            chunklist[clen++] = chunkid;
          }
        } else {
          free(rp);
          return status;
        }
        free(rp);

        chunks++;
      }
    }

    fprintf(stderr,"chunklist now:\n");
    for(i=0;i<clen;i++){
      fprintf(stderr,"\t(%d):%lld\n",i,chunklist[i]);
    }

    ppacket* p = createpacket_s(4+plen+4+4,CLTOMD_WRITE,-1);
    ptr = p->startptr + HEADER_LEN;
    put32bit(&ptr,plen);
    memcpy(ptr,path,plen);
    ptr += plen;
    put32bit(&ptr,ooff);
    put32bit(&ptr,ost);
    sendpacket(e->sockfd,p);
    free(p);

    int starti = off/CHUNKSIZE;
    int buflen = min(st,CHUNKSIZE - off % CHUNKSIZE);
    ppfs_conn_entry cs;
    cs.sockfd = -1;

    fprintf(stderr,"off=%d,st=%lld\n",off,st);

    while(st > 0){
      uint64_t chunkid = chunklist[starti];

      ppacket* p = createpacket_s(8,CLTOMD_LOOKUP_CHUNK,-1);
      uint8_t* ptr = p->startptr + HEADER_LEN;
      put64bit(&ptr,chunkid);
      sendpacket(e->sockfd,p);
      free(p);

      p = receivepacket(e->sockfd);
      const uint8_t* ptr2 = p->startptr;
      int status = get32bit(&ptr2);
      printf("status:%d\n",status);
      if(status == 0){
        int csip = get32bit(&ptr2);
        printf("cid:%lld,csip:%X\n",chunkid,csip);

        if(cs.sockfd != -1 && cs.peerip != csip){
          tcpclose(cs.sockfd);
        }

        if(cs.sockfd == -1){
          if(serv_connect(&cs,csip,CS_PORT) < 0){
            return -1;
          }
        }
      } else {
        return -1;
      }

      p = createpacket_s(8+4+4+buflen,CLTOCS_WRITE_CHUNK,-1);
      ptr = p->startptr + HEADER_LEN;
      put64bit(&ptr,chunkid);
      put32bit(&ptr,off % CHUNKSIZE);
      put32bit(&ptr,buflen);
      memcpy(ptr,wbuf,buflen);

      fprintf(stderr,"starti=%d,chunkid=%lld,off=%d,buflen=%d\n",starti,chunkid,off % CHUNKSIZE,buflen);

      sendpacket(cs.sockfd,p);
      free(p);

      p = receivepacket(cs.sockfd);
      ptr2 = p->startptr;
      status = get32bit(&ptr2);
      printf("status=%d\n",status);
      if(status == 0){
        int wlen =  get32bit(&ptr2);
        nwrite += wlen;
        printf("wlen=%d,nwrite=%d\n",wlen,nwrite);
        wbuf += wlen;
      }

      st -= buflen;
      off += buflen;

      starti = off/CHUNKSIZE;
      buflen = min(st,CHUNKSIZE - off % CHUNKSIZE);
    }
  } else {
    return status;
  }

  fprintf(stderr,"off=%d,st=%d,nwrite=%d\n",ooff,ost,nwrite);
  return nwrite;
}
示例#5
0
文件: client.c 项目: twonly/mis
int	ppfs_read(const char * path, char * buf, size_t st, off_t off, struct fuse_file_info *fi){
  int nread = 0;
  int ooff = off;
  int ost = st;
  char* rbuf = buf;

  chunk_cache* cc;
  if(lookup_chunk_cache(path,&cc) != 0){
    ppacket* p = createpacket_s(4+strlen(path),CLTOMD_READ_CHUNK_INFO,-1);
    uint8_t* ptr = p->startptr + HEADER_LEN;
    int plen = strlen(path);
    uint64_t* chunklist = NULL;
    int clen,calloc;

    put32bit(&ptr,plen);
    memcpy(ptr,path,plen);
    ptr += plen;

    fprintf(stderr,"just to be clear\n");
    const uint8_t* tmpptr = p->startptr + HEADER_LEN;
    int i;
    for(i=0;i<p->size;i+=1){
      int x = get8bit(&tmpptr);
      fprintf(stderr,"%X\t",x);
    }
    fprintf(stderr,"\n");

    sendpacket(fd,p);
    free(p);

    p = receivepacket(fd);
    const uint8_t* ptr2 = p->startptr;
    int status = get32bit(&ptr2);
    fprintf(stderr,"status:%d\n",status);
    if(status != 0){
      return -1;
    }

    uint32_t ip = get32bit(&ptr2);
    if(ip == -1){
      fprintf(stderr,"local mds\n");
    } else {
      fprintf(stderr,"remote mds:%X\n",ip);
    }

    int chunks = get32bit(&ptr2);
    fprintf(stderr,"chunks=%d\n",chunks);

    chunklist = (uint64_t*)malloc(sizeof(uint64_t)*(chunks+20));
    clen = 0;
    calloc = chunks+20;

    for(i=0;i<chunks;i++){
      uint64_t chunkid = get64bit(&ptr2);
      fprintf(stderr,"(%d):id=%lld\n",i,chunkid);

      chunklist[clen++] = chunkid;
    }

    cc = chunk_cache_add(path,chunklist,clen,ip);
  } else {
    fprintf(stderr,"\n\n\n\nfound chunk_cache\n\n\n\n");
  }

  fprintf(stderr,"preparing mds connection:%X\n",ip);

  ppfs_conn_entry* e = NULL;
  uint32_t ip = cc->mdsid;

  if(ip != -1){
    if(remote_mds.sockfd != -1 && remote_mds.peerip != ip){
      tcpclose(remote_mds.sockfd);
      remote_mds.sockfd = -1;
    }

    if(remote_mds.sockfd == -1){
      fprintf(stderr,"connecting\n");
      if(serv_connect(&remote_mds,ip,MDS_PORT) < 0){
        return -1;
      }
    }

    e = &remote_mds;
  } else {
    e = &local_mds;
  }

  fprintf(stderr,"done\n");

  fprintf(stderr,"off=%d,st=%d\n",ooff,ost);

  if(cc->chunks * CHUNKSIZE < off + st){
    return 0;
  }

  fprintf(stderr,"start reading now\n");

  int starti = off/CHUNKSIZE;
  int buflen = min(st,CHUNKSIZE - off % CHUNKSIZE);
  ppfs_conn_entry cs;
  cs.sockfd = -1;

  while(st > 0){
    uint64_t chunkid = cc->chunklist[starti];

    ppacket* p = createpacket_s(8,CLTOMD_LOOKUP_CHUNK,-1);
    uint8_t* ptr = p->startptr + HEADER_LEN;
    put64bit(&ptr,chunkid);
    sendpacket(e->sockfd,p);
    free(p);

    p = receivepacket(e->sockfd);
    const uint8_t* ptr2 = p->startptr;
    int status = get32bit(&ptr2);
    printf("status:%d\n",status);
    if(status == 0){
      int csip = get32bit(&ptr2);
      printf("cid:%lld,csip:%X\n",chunkid,csip);

      if(cs.sockfd != -1 && cs.peerip != csip){
        tcpclose(cs.sockfd);
      }

      if(cs.sockfd == -1){
        if(serv_connect(&cs,csip,CS_PORT) < 0){
          return -1;
        }
      }
    } else {
      return -1;
    }

    fprintf(stderr,"chunkid=%lld,off=%d,buflen=%d\n",chunkid,off,buflen);

    p = createpacket_s(8+4+4,CLTOCS_READ_CHUNK,-1);
    ptr = p->startptr + HEADER_LEN;
    put64bit(&ptr,chunkid);
    put32bit(&ptr,off % CHUNKSIZE);
    put32bit(&ptr,buflen);

    sendpacket(cs.sockfd,p);
    free(p);

    p = receivepacket(cs.sockfd);
    ptr2 = p->startptr;
    status = get32bit(&ptr2);
    printf("status=%d\n",status);
    if(status == 0){
      int rlen =  get32bit(&ptr2);
      nread += rlen;
      printf("rlen=%d\n",rlen);

      memcpy(rbuf,ptr2,rlen);
      rbuf += rlen;
    } else {
      return -1;
    }

    st -= buflen;
    off += buflen;

    starti = off/CHUNKSIZE;
    buflen = min(st,CHUNKSIZE - off % CHUNKSIZE);
  }

  return nread;
}
示例#6
0
文件: client.c 项目: twonly/mis
int ppfs_truncate(const char* path,off_t off){
  fprintf(stderr,"\n\n\n+ppfs_truncate\n\n\n");

  chunk_cache* cc;
  if(lookup_chunk_cache(path,&cc) == 0){
    remove_chunk_cache(cc);
    free_chunk_cache(cc);
  }

  ppacket* p = createpacket_s(4+strlen(path)+4+4,CLTOMD_READ_CHUNK_INFO,-1);
  uint8_t* ptr = p->startptr + HEADER_LEN;
  int len = strlen(path);
  uint32_t ip;
  int chunks;

  put32bit(&ptr,len);
  memcpy(ptr,path,len);
  ptr += len;
  sendpacket(fd,p);
  free(p);

  p = receivepacket(fd);
  const uint8_t* ptr2 = p->startptr;
  int status = get32bit(&ptr2);
  fprintf(stderr,"status:%d\n",status);
  if(status == 0){
    ip = get32bit(&ptr2);
    if(ip == -1){
      fprintf(stderr,"local mds\n");
    } else {
      fprintf(stderr,"remote mds:%X\n",ip);
    }

    chunks = get32bit(&ptr2);
    fprintf(stderr,"chunks=%d\n",chunks);
  } else {
    free(p);
    return status;
  }
  free(p);

  ppfs_conn_entry* e = NULL;
  if(ip != -1){
    if(remote_mds.sockfd != -1 && remote_mds.peerip != ip){
      tcpclose(remote_mds.sockfd);
      remote_mds.sockfd = -1;
    }

    if(remote_mds.sockfd == -1){
      if(serv_connect(&remote_mds,ip,MDS_PORT) < 0){
        return -1;
      }
    }

    e = &remote_mds;
  } else {
    e = &local_mds;
  }

  off_t size = chunks * CHUNKSIZE;

  while(size >= off + CHUNKSIZE){
    p = createpacket_s(4+len,CLTOMD_POP_CHUNK,-1);
    ptr = p->startptr + HEADER_LEN;
    put32bit(&ptr,len);
    memcpy(ptr,path,len);
    sendpacket(e->sockfd,p);
    free(p);

    ppacket* rp = receivepacket(e->sockfd);
    ptr2 = rp->startptr;
    status = get32bit(&ptr2);
    printf("status:%d\n",status);
    if(status != 0){
      return status;
    }
    free(rp);

    size -= CHUNKSIZE;
  }

  p = createpacket_s(4+len,CLTOMD_APPEND_CHUNK,-1);
  ptr = p->startptr + HEADER_LEN;
  put32bit(&ptr,len);
  memcpy(ptr,path,len);
  while(size < off){
    sendpacket(e->sockfd,p);

    ppacket* rp = receivepacket(e->sockfd);
    ptr2 = rp->startptr;
    status = get32bit(&ptr2);
    printf("status:%d\n",status);
    if(status != 0){
      return status;
    }
    free(rp);

    size += CHUNKSIZE;
  }
  free(p);

  return 0;
}
示例#7
0
/*! \brief CONNECT command handler
 *
 * \param source_p Pointer to allocated Client struct from which the message
 *                 originally comes from.  This can be a local or remote client.
 * \param parc     Integer holding the number of supplied arguments.
 * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
 *                 pointers.
 * \note Valid arguments for this command are:
 *      - parv[0] = command
 *      - parv[1] = target server
 *      - parv[2] = port number
 *      - parv[3] = nickname/servername
 */
static int
mo_connect(struct Client *source_p, int parc, char *parv[])
{
  int port = 0, tmpport = 0;
  struct MaskItem *conf = NULL;
  const struct Client *target_p = NULL;

  if (EmptyString(parv[1]))
  {
    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
    return 0;
  }

  if (parc > 3)
  {
    if (!HasOFlag(source_p, OPER_FLAG_CONNECT_REMOTE))
    {
      sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect:remote");
      return 0;
    }

    if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
      return 0;
  }
  else if (!HasOFlag(source_p, OPER_FLAG_CONNECT))
  {
    sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "connect");
    return 0;
  }

  /*
   * Try to find the name, then host, if both fail notify ops and bail
   */
  if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
      !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
  {
    sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
    return 0;
  }

  if ((target_p = hash_find_server(conf->name)))
  {
    sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s.",
                      target_p->name, target_p->from->name);
    return 0;
  }

  /*
   * Get port number from user, if given. If not specified,
   * use the default from configuration structure. If missing
   * from there, then use the precompiled default.
   */
  tmpport = port = conf->port;

  if (parc > 2 && !EmptyString(parv[2]))
  {
    if ((port = atoi(parv[2])) <= 0)
    {
      sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
      return 0;
    }
  }
  else if (port <= 0 && (port = PORTNUM) <= 0)
  {
    sendto_one_notice(source_p, &me, ":Connect: missing port number");
    return 0;
  }

  if (find_servconn_in_progress(conf->name))
  {
    sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
                      "is already in progress.", conf->name);
    return 0;
  }

  /*
   * Notify all operators about remote connect requests
   */
  ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %s",
       source_p->name, parv[1], parv[2] ? parv[2] : "");

  conf->port = port;

  /*
   * At this point we should be calling connect_server with a valid
   * connect{} block and a valid port in the connect{} block
   */
  if (serv_connect(conf, source_p))
  {
    if (!ConfigServerHide.hide_server_ips && HasUMode(source_p, UMODE_ADMIN))
      sendto_one_notice(source_p, &me, ":*** Connecting to %s[%s].%d",
                        conf->host, conf->name, conf->port);
    else
      sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
                        conf->name, conf->port);
  }
  else
    sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
                      conf->name, conf->port);

  /*
   * Client is either connecting with all the data it needs or has been
   * destroyed
   */
  conf->port = tmpport;
  return 0;
}
示例#8
0
/*! \brief CONNECT command handler
 *
 * \param source_p Pointer to allocated Client struct from which the message
 *                 originally comes from.  This can be a local or remote client.
 * \param parc     Integer holding the number of supplied arguments.
 * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
 *                 pointers.
 * \note Valid arguments for this command are:
 *      - parv[0] = command
 *      - parv[1] = target server
 *      - parv[2] = port number
 *      - parv[3] = nickname/servername
 */
static int
ms_connect(struct Client *source_p, int parc, char *parv[])
{
  int port = 0, tmpport = 0;
  struct MaskItem *conf = NULL;
  const struct Client *target_p = NULL;

  if (parc < 4 || EmptyString(parv[3]))
  {
    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "CONNECT");
    return 0;
  }

  if (hunt_server(source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
    return 0;

  /*
   * Try to find the name, then host, if both fail notify ops and bail
   */
  if (!(conf = find_matching_name_conf(CONF_SERVER, parv[1], NULL, NULL, 0)) &&
      !(conf = find_matching_name_conf(CONF_SERVER, NULL, NULL, parv[1], 0)))
  {
    sendto_one_notice(source_p, &me, ":Connect: Host %s not listed in configuration file", parv[1]);
    return 0;
  }

  if ((target_p = hash_find_server(conf->name)))
  {
    sendto_one_notice(source_p, &me, ":Connect: Server %s already exists from %s.",
                      target_p->name, target_p->from->name);
    return 0;
  }

  /*
   * Get port number from user, if given. If not specified,
   * use the default from configuration structure. If missing
   * from there, then use the precompiled default.
   */
  tmpport = port = conf->port;

  if (parc > 2 && !EmptyString(parv[2]))
  {
    port = atoi(parv[2]);

    /*
     * If someone sends port 0, and we have a config port.. use it
     */
    if (port == 0 && conf->port)
      port = conf->port;
    else if (port <= 0)
    {
      sendto_one_notice(source_p, &me, ":Connect: Illegal port number");
      return 0;
    }
  }
  else if (port <= 0 && (port = PORTNUM) <= 0)
  {
    sendto_one_notice(source_p, &me, ":Connect: missing port number");
    return 0;
  }

  if (find_servconn_in_progress(conf->name))
  {
    sendto_one_notice(source_p, &me, ":Connect: a connection to %s "
                      "is already in progress.", conf->name);
    return 0;
  }

  /*
   * Notify all operators about remote connect requests
   */
  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_GLOBAL, "from %s: Remote CONNECT %s %d from %s",
                       me.name, parv[1], port, source_p->name);
  sendto_server(NULL, 0, 0,
                ":%s GLOBOPS :Remote CONNECT %s %d from %s",
                me.id, parv[1], port, source_p->name);

  ilog(LOG_TYPE_IRCD, "CONNECT From %s : %s %d",
       source_p->name, parv[1], port);

  conf->port = port;

  /*
   * At this point we should be calling connect_server with a valid
   * connect{} block and a valid port in the connect{} block
   */
  if (serv_connect(conf, source_p))
    sendto_one_notice(source_p, &me, ":*** Connecting to %s.%d",
                      conf->name, conf->port);
  else
    sendto_one_notice(source_p, &me, ":*** Couldn't connect to %s.%d",
                      conf->name, conf->port);
  /*
   * Client is either connecting with all the data it needs or has been
   * destroyed
   */
  conf->port = tmpport;
  return 0;
}
示例#9
0
/*
 * mo_connect - CONNECT command handler
 * 
 * Added by Jto 11 Feb 1989
 *
 * m_connect
 *      parv[0] = sender prefix
 *      parv[1] = servername
 *      parv[2] = port number
 *      parv[3] = remote server
 */
static void
mo_connect(struct Client* client_p, struct Client* source_p,
           int parc, char* parv[])
{
  int port;
  int tmpport;
  struct ConfItem *conf = NULL;
  struct AccessItem *aconf = NULL;
  struct Client *target_p;

  /* always privileged with handlers */
  if (MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
  {
    sendto_one(source_p, form_str(ERR_NOPRIVS),
               me.name, source_p->name, "connect");
    return;
  }

  if (hunt_server(client_p, source_p,
                  ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
    return;

  if (*parv[1] == '\0')
  {
    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
               me.name, source_p->name, "CONNECT");
    return;
  }

  if ((target_p = find_server(parv[1])))
  {
    sendto_one(source_p,
	       ":%s NOTICE %s :Connect: Server %s already exists from %s.",
               me.name, source_p->name, parv[1], target_p->from->name);
    return;
  }

  /*
   * try to find the name, then host, if both fail notify ops and bail
   */
  if ((conf = find_matching_name_conf(SERVER_TYPE,
				      parv[1], NULL, NULL, 0)) != NULL)
    aconf = (struct AccessItem *)map_to_conf(conf);
  else if ((conf = find_matching_name_conf(SERVER_TYPE,
					   NULL, NULL, parv[1], 0)) != NULL)
    aconf = (struct AccessItem *)map_to_conf(conf);
  
  if (conf == NULL)
  {
    sendto_one(source_p,
	       ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
	       me.name, source_p->name, parv[1]);
    return;
  }
    
  /* Get port number from user, if given. If not specified,
   * use the default form configuration structure. If missing
   * from there, then use the precompiled default.
   */
  tmpport = port = aconf->port;

  if (parc > 2 && !EmptyString(parv[2]))
  {
    if ((port = atoi(parv[2])) <= 0)
    {
      sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
                 me.name, source_p->name);
      return;
    }
  }
  else if (port <= 0 && (port = PORTNUM) <= 0)
  {
    sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
               me.name, source_p->name);
    return;
  }

  if (find_servconn_in_progress(conf->name))
  {
    sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
               "is already in progress.", me.name, source_p->name, conf->name);
    return;
  }

  /*
   * Notify all operators about remote connect requests
   */
  ilog(L_TRACE, "CONNECT From %s : %s %s", 
       source_p->name, parv[1], parv[2] ? parv[2] : "");

  aconf->port = port;

  /* at this point we should be calling connect_server with a valid
   * C:line and a valid port in the C:line
   */
  if (serv_connect(aconf, source_p))
  {
    if (!ConfigServerHide.hide_server_ips && IsAdmin(source_p))
      sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
                 me.name, source_p->name, aconf->host,
                 conf->name, aconf->port);
    else
      sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
                 me.name, source_p->name, conf->name, aconf->port);
  }
  else
  {
    sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
               me.name, source_p->name, conf->name, aconf->port);
  }

  /* client is either connecting with all the data it needs or has been
   * destroyed
   */
  aconf->port = tmpport;
}
示例#10
0
/*
 * ms_connect - CONNECT command handler
 * 
 * Added by Jto 11 Feb 1989
 *
 * m_connect
 *      parv[0] = sender prefix
 *      parv[1] = servername
 *      parv[2] = port number
 *      parv[3] = remote server
 */
static void
ms_connect(struct Client *client_p, struct Client *source_p,
           int parc, char *parv[])
{
  int port;
  int tmpport;
  struct ConfItem *conf = NULL;
  struct AccessItem *aconf = NULL;
  struct Client *target_p;

  if (hunt_server(client_p, source_p,
                  ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
    return;

  if (*parv[1] == '\0')
  {
    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
               me.name, source_p->name, "CONNECT");
    return;
  }

  if ((target_p = find_server(parv[1])))
  {
    sendto_one(source_p,
	       ":%s NOTICE %s :Connect: Server %s already exists from %s.",
               me.name, source_p->name, parv[1], target_p->from->name);
    return;
  }

  /*
   * try to find the name, then host, if both fail notify ops and bail
   */
  if ((conf = find_matching_name_conf(SERVER_TYPE,
				      parv[1], NULL, NULL, 0)) != NULL)
    aconf = (struct AccessItem *)map_to_conf(conf);
  else if ((conf = find_matching_name_conf(SERVER_TYPE,
					   NULL, NULL, parv[1], 0)) != NULL)
    aconf = (struct AccessItem *)map_to_conf(conf);

  if (aconf == NULL)
  {
    sendto_one(source_p,
	       ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf",
	       me.name, source_p->name, parv[1]);
    return;
  }

  assert(aconf != NULL);

  /* Get port number from user, if given. If not specified,
   * use the default form configuration structure. If missing
   * from there, then use the precompiled default.
   */
  tmpport = port = aconf->port;

  if (parc > 2 && !EmptyString(parv[2]))
  {
    port = atoi(parv[2]);

    /* if someone sends port 0, and we have a config port.. use it */
    if (port == 0 && aconf->port)
      port = aconf->port;
    else if (port <= 0)
    {
      sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number",
                 me.name, source_p->name);
      return;
    }
  }
  else if (port <= 0 && (port = PORTNUM) <= 0)
  {
    sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
               me.name, source_p->name);
    return;
  }

  if (find_servconn_in_progress(conf->name))
  {
    sendto_one(source_p, ":%s NOTICE %s :Connect: a connection to %s "
               "is already in progress.", me.name, source_p->name, conf->name);
    return;
  }

  /*
   * Notify all operators about remote connect requests
   */
  sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s",
                       parv[1], port, source_p->name);
  sendto_server(NULL, NULL, NULL, NOCAPS, NOCAPS, NOFLAGS,
                ":%s WALLOPS :Remote CONNECT %s %d from %s",
                me.name, parv[1], port, source_p->name);

  ilog(L_TRACE, "CONNECT From %s : %s %d", 
       source_p->name, parv[1], port);

  aconf->port = port;

  /* at this point we should be calling connect_server with a valid
   * C:line and a valid port in the C:line
   */
  if (serv_connect(aconf, source_p))
    sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
               me.name, source_p->name, conf->name, aconf->port);
  else
    sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
               me.name, source_p->name, conf->name, aconf->port);
  /* client is either connecting with all the data it needs or has been
   * destroyed
   */
  aconf->port = tmpport;
}
示例#11
0
/*
 * mo_connect - CONNECT command handler
 * 
 * Added by Jto 11 Feb 1989
 *
 * m_connect
 *      parv[0] = sender prefix
 *      parv[1] = servername
 *      parv[2] = port number
 *      parv[3] = remote server
 */
static void
mo_connect(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	int port;
	int tmpport;
	struct ConfItem *aconf;
	struct Client *target_p;

	/* always privileged with handlers */

	if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3)
	{
		sendto_one(source_p, ":%s NOTICE %s :You need remote = yes;", me.name, parv[0]);
		return;
	}

	if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME)
	{
		return;
	}

	if(*parv[1] == '\0')
	{
		sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "CONNECT");
		return;
	}

	if((target_p = find_server(parv[1])))
	{
		sendto_one(source_p, ":%s NOTICE %s :Connect: Server %s already exists from %s.",
			   me.name, parv[0], parv[1], target_p->from->name);
		return;
	}

	/*
	 * try to find the name, then host, if both fail notify ops and bail
	 */
	if(!(aconf = find_conf_by_name(parv[1], CONF_SERVER)))
	{
		if(!(aconf = find_conf_by_host(parv[1], CONF_SERVER)))
		{
			sendto_one(source_p,
				   "NOTICE %s :Connect: Host %s not listed in ircd.conf",
				   parv[0], parv[1]);
			return;
		}
	}
	s_assert(0 != aconf);
	/*
	 * Get port number from user, if given. If not specified,
	 * use the default form configuration structure. If missing
	 * from there, then use the precompiled default.
	 */
	tmpport = port = aconf->port;
	if(parc > 2 && !EmptyString(parv[2]))
	{
		if((port = atoi(parv[2])) <= 0)
		{
			sendto_one(source_p, "NOTICE %s :Connect: Illegal port number", parv[0]);
			return;
		}
	}
	else if(port <= 0 && (port = PORTNUM) <= 0)
	{
		sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number",
			   me.name, parv[0]);
		return;
	}
	/*
	 * Notify all operators about remote connect requests
	 */

	ilog(L_TRACE, "CONNECT From %s : %s %s", parv[0], parv[1], parv[2] ? parv[2] : "");

	aconf->port = port;
	/*
	 * at this point we should be calling connect_server with a valid
	 * C:line and a valid port in the C:line
	 */
	if(serv_connect(aconf, source_p))
	{
#ifndef HIDE_SERVERS_IPS
		if(IsOperAdmin(source_p))
			sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d",
				   me.name, parv[0], aconf->host, aconf->name, aconf->port);
		else
#endif
			sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d",
				   me.name, parv[0], aconf->name, aconf->port);

	}
	else
	{
		sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d",
			   me.name, parv[0], aconf->name, aconf->port);

	}
	/*
	 * client is either connecting with all the data it needs or has been
	 * destroyed
	 */
	aconf->port = tmpport;
}