Esempio n. 1
0
int main( int argc, char **argv ) {
  static pthread_t sync_in_thread_id;
  static pthread_t sync_out_thread_id;
  ot_ip6 serverip;
  uint16_t tmpport;
  int scanon = 1, lbound = 0, sbound = 0;

  srandom( time(NULL) );
  g_tracker_id = random();
  noipv6=1;

  while( scanon ) {
    switch( getopt( argc, argv, ":l:c:L:h" ) ) {
    case -1: scanon = 0; break;
    case 'l':
      tmpport = 0;
      if( !scan_ip6_port( optarg, serverip, &tmpport ) || !tmpport ) { usage( argv[0] ); exit( 1 ); }
      ot_try_bind( serverip, tmpport );
      ++sbound;
      break;
    case 'c':
      if( g_connection_count > MAX_PEERS / 2 ) exerr( "Connection limit exceeded.\n" );
      tmpport = 0;
      if( !scan_ip6_port( optarg,
        g_connections[g_connection_count].ip,
        &g_connections[g_connection_count].port ) ||
        !g_connections[g_connection_count].port ) { usage( argv[0] ); exit( 1 ); }
      g_connections[g_connection_count++].state = FLAG_OUTGOING;
      break;
    case 'L':
      tmpport = 9696;
      if( !scan_ip6_port( optarg, serverip, &tmpport ) || !tmpport ) { usage( argv[0] ); exit( 1 ); }
      livesync_bind_mcast( serverip, tmpport); ++lbound; break;
    default:
    case '?': usage( argv[0] ); exit( 1 );
    }
  }

  if( !lbound ) exerr( "No livesync port bound." );
  if( !g_connection_count && !sbound ) exerr( "No streamsync port bound." );
  pthread_create( &sync_in_thread_id, NULL, livesync_worker, NULL );
  pthread_create( &sync_out_thread_id, NULL, streamsync_worker, NULL );

  server_mainloop();
  return 0;
}
Esempio n. 2
0
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;
}