コード例 #1
0
ファイル: cfgopt.c プロジェクト: cc3283/pcaputils
static void cfgopt_load_value(cfgopt_t *cfg, char *value){
	if(!value) return;
	switch(cfg->type){
	case CONFIG_STR: {
		cfg->val.str = strdup(value);
		break;
	}
	case CONFIG_DEC:
	case CONFIG_OCT: {
		int base = cfg->type == CONFIG_DEC ? 0 : 8;
		if(!cfg->val.num) NEW0(cfg->val.num);
		*cfg->val.num = strtoul(value, NULL, base);
		break;
	}
	case CONFIG_BOOL: {
		if(!cfg->val.boolean) NEW0(cfg->val.boolean);
		*cfg->val.boolean = (bool) strtoul(value, NULL, 0);
		break;
	}
	case CONFIG_IP: {
		char *ip;
		MALLOC(ip, 4);
		if(scan_ip4(value, ip) == 0)
			ERROR("invalid IPv4 literal: %s", value);
		cfg->val.ip = ip;
		break;
	}
	case CONFIG_IP6: {
		char *ip6;
		MALLOC(ip6, 16);
		if(scan_ip6(value, ip6) == 0)
			ERROR("invalid IPv6 literal: %s", value);
		cfg->val.ip6 = ip6;
		break;
	}
	case CONFIG_MAC: {
		char *mac;
		MALLOC(mac, 6);
		if(scan_mac(value, mac) != 6)
			ERROR("invalid MAC literal: %s", value);
		cfg->val.mac = mac;
		break;
	}
	case CONFIG_NONOPT: {
		if(!cfg->val.nonopt){
			cfg->val.nonopt = strdup(value);
		}else{
			size_t new_size = 2 + strlen(cfg->val.nonopt) + strlen(value);
			REALLOC(cfg->val.nonopt, new_size);
			strcat(cfg->val.nonopt, " ");
			strcat(cfg->val.nonopt, value);
		}
		break;
	}
	default:
		ERROR("invalid configuration type %d", (int) cfg->type);
	}
}
コード例 #2
0
ファイル: opentracker.c プロジェクト: mchelen/opentracker_ono
int main( int argc, char **argv ) {
  struct passwd *pws = NULL;
  char serverip[4] = {0,0,0,0}, tmpip[4];
  char *serverdir = ".";
  int bound = 0, scanon = 1;
#ifdef WANT_ACCESS_CONTROL
  char *accesslist_filename = NULL;
#endif

  while( scanon ) {
    switch( getopt( argc, argv, ":i:p:A:P:d:r:v"
#ifdef WANT_BLACKLISTING
"b:"
#elif defined( WANT_CLOSED_TRACKER )
"w:"
#endif
    "h" ) ) {
      case -1 : scanon = 0; break;
      case 'i': scan_ip4( optarg, serverip ); break;
#ifdef WANT_BLACKLISTING
      case 'b': accesslist_filename = optarg; break;
#elif defined( WANT_CLOSED_TRACKER )
      case 'w': accesslist_filename = optarg; break;
#endif
      case 'p': ot_try_bind( serverip, (uint16)atol( optarg ), 1 ); bound++; break;
      case 'P': ot_try_bind( serverip, (uint16)atol( optarg ), 0 ); bound++; break;
      case 'd': serverdir = optarg; break;
      case 'r': g_redirecturl = optarg; break;
      case 'A':
        scan_ip4( optarg, tmpip );
        accesslist_blessip( tmpip, 0xffff ); /* Allow everything for now */
        break;
      case 'h': help( argv[0] ); exit( 0 );
      case 'v': write( 2, static_inbuf, stats_return_tracker_version( static_inbuf )); exit( 0 );
      default:
      case '?': usage( argv[0] ); exit( 1 );
    }
  }

  /* Bind to our default tcp/udp ports */
  if( !bound) {
    ot_try_bind( serverip, 6969, 1 );
    ot_try_bind( serverip, 6969, 0 );
  }

  /* Drop permissions */
  pws = getpwnam( "nobody" );
  if( !pws ) {
    setegid( (gid_t)-2 ); setuid( (uid_t)-2 );
    setgid( (gid_t)-2 ); seteuid( (uid_t)-2 );
  } else {
    setegid( pws->pw_gid ); setuid( pws->pw_uid );
    setgid( pws->pw_gid ); seteuid( pws->pw_uid );
  }
  endpwent();

  accesslist_init( accesslist_filename );

  signal( SIGPIPE, SIG_IGN );
  signal( SIGINT,  signal_handler );
  signal( SIGALRM, signal_handler );

  g_now = time( NULL );

  if( trackerlogic_init( serverdir ) == -1 )
    panic( "Logic not started" );

  alarm(5);

  server_mainloop( );

  return 0;
}