Exemple #1
0
/*
* Return the subgroup
*/
const BigInt& DL_Group::get_q() const
   {
   init_check();
   if(m_q == 0)
      throw Invalid_State("DLP group has no q prime specified");
   return m_q;
   }
Exemple #2
0
t_match		*check_space_pvp(t_match *match, int flag)
{
  int		check;

  check = 0;
  if (check_list(match) == 1)
    {
      flag = 1;
      return (match);
    }
  check = init_check(match);
  if (is_ok(match, check) == 1)
    {
      flag = 1;
      return (match);
    }
  flag = burn_select(&match, flag);
  if (flag != 0)
    {
      is_finished(match);
      if (who_play == 0)
	who_play = 42;
      else
	who_play = 0;
    }
  return (match);
}
Exemple #3
0
/*
 * main:
 *        The main program, of course
 */
int main(int argc, char **argv)
{
    md_init();
    initJedi();

    /*
     * get home and options from environment
     */

#ifdef __linux__
    strcpy(file_name, "/var/lib/griffin/rogue.save");
#else
    strcpy(file_name, "rogue.save");
#endif

    open_score();

    /*
     * check for print-score option
     */

    if (argc == 2)
    {
        if (strcmp(argv[1], "-s") == 0)
        {
            score(0, -1, 0);
            exit(0);
        }
    }

    init_check();                        /* check for legal startup */
    restore("-r");

    init_probs();                        /* Set up prob tables for objects */
    init_player();                        /* Set up initial player stats */
    init_names();                        /* Set up names of scrolls */
    init_colors();                        /* Set up colors of potions */
    init_stones();                        /* Set up stone settings of rings */
    init_materials();                        /* Set up materials of wands */
    setup();

    displayMessage("WELCOME TO THE DUNGEONS OF DOOM");
    new_level();                        /* Draw current level */
    /*
     * Start up daemons and fuses
     */
    start_daemon(runners, 0, AFTER);
    start_daemon(doctor, 0, AFTER);
    fuse(swander, 0, WANDERTIME, AFTER);
    start_daemon(stomach, 0, AFTER);
    playit();
    return(0);
}
Exemple #4
0
/*
* Verify the parameters
*/
bool DL_Group::verify_group(RandomNumberGenerator& rng,
                            bool strong) const
   {
   init_check();

   if(m_g < 2 || m_p < 3 || m_q < 0)
      return false;
   if((m_q != 0) && ((m_p - 1) % m_q != 0))
      return false;

   const size_t prob = (strong) ? 56 : 10;

   if(!is_prime(m_p, rng, prob))
      return false;
   if((m_q > 0) && !is_prime(m_q, rng, prob))
      return false;
   return true;
   }
Exemple #5
0
int		main(int ac, char **av, char **env)
{
  t_shell	*shell;
  t_check	check[4];
  int		return_value;

  if ((shell = malloc(sizeof(t_shell))) == NULL)
    return (1);
  if (env[0] != NULL)
    copy_env(shell, env);
  shell->status = 0;
  init_check(check);
  return_value = my_core(shell, check);
  (void)ac;
  (void)av;
  my_putstr("exit\n");
  free_all_on_exit(shell);
  return (return_value);
}
Exemple #6
0
/*
* DER encode the parameters
*/
std::vector<byte> DL_Group::DER_encode(Format format) const
   {
   init_check();

   if((m_q == 0) && (format != PKCS_3))
      throw Encoding_Error("The ANSI DL parameter formats require a subgroup");

   if(format == ANSI_X9_57)
      {
      return DER_Encoder()
         .start_cons(SEQUENCE)
            .encode(m_p)
            .encode(m_q)
            .encode(m_g)
         .end_cons()
      .get_contents_unlocked();
      }
   else if(format == ANSI_X9_42)
      {
      return DER_Encoder()
         .start_cons(SEQUENCE)
            .encode(m_p)
            .encode(m_g)
            .encode(m_q)
         .end_cons()
      .get_contents_unlocked();
      }
   else if(format == PKCS_3)
      {
      return DER_Encoder()
         .start_cons(SEQUENCE)
            .encode(m_p)
            .encode(m_g)
         .end_cons()
      .get_contents_unlocked();
      }

   throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
   }
Exemple #7
0
int32_t main (int32_t argc, char *argv[])
{
	int32_t i, j;
	prog_name = argv[0];
	if (pthread_key_create(&getclient, NULL)) {
		fprintf(stderr, "Could not create getclient, exiting...");
		exit(1);
	}

  void (*mod_def[])(struct s_module *)=
  {
#ifdef MODULE_MONITOR
           module_monitor,
#endif
#ifdef MODULE_CAMD33
           module_camd33,
#endif
#ifdef MODULE_CAMD35
           module_camd35,
#endif
#ifdef MODULE_CAMD35_TCP
           module_camd35_tcp,
#endif
#ifdef MODULE_NEWCAMD
           module_newcamd,
#endif
#ifdef MODULE_CCCAM
           module_cccam,
#endif
#ifdef MODULE_PANDORA
           module_pandora,
#endif
#ifdef MODULE_GHTTP
           module_ghttp,
#endif
#ifdef CS_CACHEEX
           module_csp,
#endif
#ifdef MODULE_GBOX
           module_gbox,
#endif
#ifdef MODULE_CONSTCW
           module_constcw,
#endif
#ifdef MODULE_RADEGAST
           module_radegast,
#endif
#ifdef MODULE_SERIAL
           module_serial,
#endif
#ifdef HAVE_DVBAPI
	   module_dvbapi,
#endif
           0
  };

  void (*cardsystem_def[])(struct s_cardsystem *)=
  {
#ifdef READER_NAGRA
	reader_nagra,
#endif
#ifdef READER_IRDETO
	reader_irdeto,
#endif
#ifdef READER_CONAX
	reader_conax,
#endif
#ifdef READER_CRYPTOWORKS
	reader_cryptoworks,
#endif
#ifdef READER_SECA
	reader_seca,
#endif
#ifdef READER_VIACCESS
	reader_viaccess,
#endif
#ifdef READER_VIDEOGUARD
	reader_videoguard1,
	reader_videoguard2,
	reader_videoguard12,
#endif
#ifdef READER_DRE
	reader_dre,
#endif
#ifdef READER_TONGFANG
	reader_tongfang,
#endif
#ifdef READER_BULCRYPT
	reader_bulcrypt,
#endif
#ifdef READER_GRIFFIN
	reader_griffin,
#endif
#ifdef READER_DGCRYPT
	reader_dgcrypt,
#endif
	0
  };

  void (*cardreader_def[])(struct s_cardreader *)=
  {
#ifdef CARDREADER_DB2COM
	cardreader_db2com,
#endif
#if defined(CARDREADER_INTERNAL_AZBOX)
	cardreader_internal_azbox,
#elif defined(CARDREADER_INTERNAL_COOLAPI)
	cardreader_internal_cool,
#elif defined(CARDREADER_INTERNAL_SCI)
	cardreader_internal_sci,
#endif
#ifdef CARDREADER_PHOENIX
	cardreader_mouse,
#endif
#ifdef CARDREADER_MP35
	cardreader_mp35,
#endif
#ifdef CARDREADER_PCSC
	cardreader_pcsc,
#endif
#ifdef CARDREADER_SC8IN1
	cardreader_sc8in1,
#endif
#ifdef CARDREADER_SMARGO
	cardreader_smargo,
#endif
#ifdef CARDREADER_SMART
	cardreader_smartreader,
#endif
#ifdef CARDREADER_STAPI
	cardreader_stapi,
#endif
	0
  };

  parse_cmdline_params(argc, argv);

  if (bg && do_daemon(1,0))
  {
    printf("Error starting in background (errno=%d: %s)", errno, strerror(errno));
    cs_exit(1);
  }

  get_random_bytes_init();

#ifdef WEBIF
  if (cs_restart_mode)
    restart_daemon();
#endif

  memset(&cfg, 0, sizeof(struct s_config));
  cfg.max_pending = max_pending;

  if (cs_confdir[strlen(cs_confdir) - 1] != '/') strcat(cs_confdir, "/");
  init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first
  init_first_client();
  cs_lock_create(&system_lock, 5, "system_lock");
  cs_lock_create(&config_lock, 10, "config_lock");
  cs_lock_create(&gethostbyname_lock, 10, "gethostbyname_lock");
  cs_lock_create(&clientlist_lock, 5, "clientlist_lock");
  cs_lock_create(&readerlist_lock, 5, "readerlist_lock");
  cs_lock_create(&fakeuser_lock, 5, "fakeuser_lock");
  cs_lock_create(&ecmcache_lock, 5, "ecmcache_lock");
  cs_lock_create(&readdir_lock, 5, "readdir_lock");
  cs_lock_create(&cwcycle_lock, 5, "cwcycle_lock");
  cs_lock_create(&hitcache_lock, 5, "hitcache_lock");
  coolapi_open_all();
  init_config();
  cs_init_log();
  if (!oscam_pidfile && cfg.pidfile)
    oscam_pidfile = cfg.pidfile;
  if (!oscam_pidfile) {
    oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid");
  }
  if (oscam_pidfile)
    pidfile_create(oscam_pidfile);
  cs_init_statistics();
  init_check();
  init_stat();

  // These initializations *MUST* be called after init_config()
  // because modules depend on config values.
  for (i=0; mod_def[i]; i++)
  {
	struct s_module *module = &modules[i];
	mod_def[i](module);
  }
  for (i=0; cardsystem_def[i]; i++)
  {
	memset(&cardsystems[i], 0, sizeof(struct s_cardsystem));
	cardsystem_def[i](&cardsystems[i]);
  }
  for (i=0; cardreader_def[i]; i++)
  {
	memset(&cardreaders[i], 0, sizeof(struct s_cardreader));
	cardreader_def[i](&cardreaders[i]);
  }

  init_sidtab();
  init_readerdb();
  cfg.account = init_userdb();
  init_signal();
  init_srvid();
  init_tierid();
  init_provid();

  start_garbage_collector(gbdb);

  cacheex_init();

  init_len4caid();
  init_irdeto_guess_tab();

  write_versionfile(false);

  led_init();
  led_status_default();

  azbox_init();

  mca_init();

  global_whitelist_read();
  cacheex_load_config_file();

	for (i = 0; i < CS_MAX_MOD; i++) {
		struct s_module *module = &modules[i];
		if ((module->type & MOD_CONN_NET)) {
			for (j = 0; j < module->ptab.nports; j++) {
				start_listener(module, &module->ptab.ports[j]);
			}
		}
	}

	//set time for server to now to avoid 0 in monitor/webif
	first_client->last=time((time_t *)0);

	webif_init();

	start_thread((void *) &reader_check, "reader check");
	cw_process_thread_start();

	lcd_thread_start();

	do_report_emm_support();

	init_cardreader();

	cs_waitforcardinit();

	led_status_starting();

	ac_init();

	for (i = 0; i < CS_MAX_MOD; i++) {
		struct s_module *module = &modules[i];
		if ((module->type & MOD_CONN_SERIAL) && module->s_handler)
			module->s_handler(NULL, NULL, i);
	}

	// main loop function
	process_clients();

	cw_process_thread_wakeup(); // Stop cw_process thread
	pthread_cond_signal(&reader_check_sleep_cond); // Stop reader_check thread

	// Cleanup
	webif_close();
	azbox_close();
	coolapi_close_all();
	mca_close();

	led_status_stopping();
	led_stop();
	lcd_thread_stop();

	remove_versionfile();

	stat_finish();
	cccam_done_share();

	kill_all_clients();
	kill_all_readers();

	if (oscam_pidfile)
		unlink(oscam_pidfile);

	webif_tpls_free();
	init_free_userdb(cfg.account);
	cfg.account = NULL;
	init_free_sidtab();
	free_readerdb();
	free_irdeto_guess_tab();
	config_free();

	cs_log("cardserver down");
	log_free();

	stop_garbage_collector();

	free(first_client->account);
	free(first_client);

	// This prevents the compiler from removing config_mak from the final binary
	syslog_ident = config_mak;

	return exit_oscam;
}
void main()
{

 int i=0,j=0;//,k=0;
 int l=0;
 char c;
 char *a,*b,*d,*ptr,fx[100];
 printf("\n\nPlease input file name : ");
 gets(fx);
 l=strlen(fx);
 fx[l]='\0';

 /* request auto detection */
 int gdriver = DETECT, gmode, errorcode;
 //int left, top, right, bottom;

 /* initialize graphics and local variables */
 initgraph(&gdriver, &gmode, "");

 /* read result of initialization */
 errorcode = graphresult();
 if (errorcode != grOk)  /* an error occurred */
 {
  printf("Graphics error: %s\n", grapherrormsg(errorcode));
  printf("Press any key to halt:");
  getch();
  exit(1); /* terminate with an error code */
 }
 
  fp=fopen(fx,"r");

 if(fp==NULL)
 {
  printf("\n No Such file exists. \n\r");
 }

 else
 {
  d[0]=getc(fp);
  ptr=strstr(d,"void main()");
  j++;
  while(ptr==NULL)
  {
   c=getc(fp);
   d[j]=c;
   ptr=strstr(d,"void main()");
   j++;
  }
  ellipse(250,y,0,360,50,10);
  outtextxy(230,y,"START");
  line(250,y+10,250,y+50);
  y=y+50;
  delay(400);
  c=getc(fp);
  c=getc(fp);
  c=getc(fp);
 fscanf(fp,"%s",a);
 c=getc(fp);
 c=getc(fp);
 c=getc(fp);


  while(c!=EOF)
  {
  c=getc(fp);
   while(c!='\n'&& c!=EOF && c!='}')
   {/*
    if(c=='{')
    {
     while(c!='}')
     {
      b[i]=getc(fp);
      i++;
     }
     }     outtextxy(200,y+10,b);
     }
     b[i]='\0';
     rectangle(200,y,300,y+40);
     line(250,y+30,250,y+60);
     y=y+60;
     delay(400);
    }
    else*/
    {
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}
     a[i]=c;
     c=getc(fp);
     i++;
    }



   }
  a[i]='\0';
  init_check(a);
  i=0;
 // a=NULL;

  }
  /*
   else if((c=='('))
   {
    while(c!=')')
    {
     b[j]=c;
     c=getc(fp);
     j++;
    }
   }

   else
   {
    if(c==' ')
    {
     while(c!=';')
     {
      c=getc(fp);
      d[k]=c;
      k++;
     }
    }
   }*/
  }
	   ellipse(250,y+10,0,360,50,10);
	   outtextxy(230,y+10,"end");
	   delay(400);

 getch();
 closegraph();
}
void init_check(char a[])
{
 int i=0,x,xa,d=0,j=0;//i1,i2,i3;
 char b[10],*g,*h,*k,z[2],w[100],c;
 b[0]='\0';
 x=0;
 while((a[x]!=' ') && (a[x]!='(') && a[x]!=';')
 {
  b[d]=a[x];
  d++;
  x++;
 }
 b[d]='\0';
 if(strcmp(b,"int")==0)
 {
  xa=1;
 }

 else if(strcmp(b,"char")==0)
 {
  xa=2;
 }

 else if(strcmp(b,"float")==0)
 {
  xa=3;
 }

 else if(strcmp(b,"scanf")==0)
 {
  xa=4;
 }

 else if(strcmp(b,"printf")==0)
 {
  xa=5;
 }

 else if(strcmp(b,"for")==0)
 {
  xa=6;
 }

 else if(strcmp(b,"while")==0)
 {
  xa=7;
 }

 else if(strcmp(b,"if")==0)
 {
  xa=8;
 }

  /*else if(strcmp(b,"else")==0)
 {
  xa=10;
 }*/

 else if(strcmp(b,"}")==0)
 {
  xa=11;
 }
 else
 {
  xa=9;
 }

 switch(xa)
 {
  case 1:{
	  z[0]=a[4];
	  z[1]='\0';
	  outtextxy(200,y+10,"initialize");
	  outtextxy(290,y+10,z);
	  rectangle(200,y,300,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  break;
	  }

  case 2: {
	  z[0]=a[5];
	  z[1]='\0';
	  outtextxy(200,y+10,"initialize");
	  outtextxy(290,y+10,z);
	  rectangle(200,y,300,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  break;
	  }

  case 3: {
	  z[0]=a[6];
	  z[1]='\0';
	  outtextxy(200,y+10,"initialize");
	  outtextxy(290,y+10,z);
	  rectangle(200,y,300,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  break;
	  }

   case 4:{
	   i=6;
	   do
	   {
	    i++;
	   }while(a[i]!='"');
	   i=i+2;
	   z[0]=a[i];
	   z[1]='\0';
	   if(a[i]=='&')
	   {
	    z[0]=a[i+1];
	   }
	   outtextxy(200,y+10,"input");
	   outtextxy(260,y+10,z);
	   line(200,y,300,y);
line(180,y+30,280,y+30);
line(200,y,180,y+30);
line(300,y,280,y+30);

	   line(250,y+30,250,y+60);
	   y=y+60;
	   delay(400);
	   break;
	  }


  case 5:{
	  i=7;
	  do
	  {
	   i++;
	  }while(a[i]!='"');
	  i=i+2;
	  z[0]=a[i];
	  z[1]='\0';
	  /*if(a[i]=='&')
	  {
	   z[0]=a[i]+1;
	  }*/
	  outtextxy(200,y+10,"print");
	  outtextxy(260,y+10,z);
	 line(200,y,300,y);
line(180,y+30,280,y+30);
line(200,y,180,y+30);
line(300,y,280,y+30);

	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  break;
	  }

  case 6:{
	  //outtextxy(200,y+10,"for(");
	  /*for(i=3;i<strlen(a);i++)
	  {
	   if(a[i]!=')')
	   {
	    g[j]=a[i];
	    j++;
	    outtextxy(210+i,y+10,g);
	   }
	  }
	  g[j]='/0'; */
	  z0=y;
	  i=strlen(a);
	  //a[i-1]='\0';
	  outtextxy(210,y+10,a);
	  rectangle(200,y,400,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  c=getc(fp);  c=getc(fp);
	  //do{c=getc(fp);}while(c!="{");
  i=0;
	   while(c!=EOF  && c!='}')
  {
  c=getc(fp);
  //i=0;
   while(c!='\n'&& c!=EOF && c!='}')
    {
     w[i]=c;
     c=getc(fp);
     i++;
   }
  w[i]='\0';
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}

  init_check(w);
  i=0;    }
  line(200,z0,150,z0);
  line(150,z0,150,y-30);
  line(150,y-30,250,y-30);
	  break;
	 }


   case 7: {
	  int z0=y;
	  i=strlen(a);
	  //a[i-1]='\0';
	  outtextxy(210,y+10,a);
	  rectangle(200,y,400,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);
	  c=getc(fp);  c=getc(fp);
	  //do{c=getc(fp);}while(c!="{");
  i=0;
	   while(c!=EOF  && c!='}')
  {
  c=getc(fp);
  //i=0;
   while(c!='\n'&& c!=EOF && c!='}')
    {
     w[i]=c;
     c=getc(fp);
     i++;
   }
  w[i]='\0';
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}
  init_check(w);
  i=0;    }
  line(200,z0,150,z0);
  line(150,z0,150,y-30);
  line(150,y-30,250,y-30);
	  break;
	 }



  case 8: {//if
    int ie0=y;
	  //i=strlen(a);
	  //a[i-1]='\0';
	  outtextxy(210,y+10,a);
	  line(190,y+15,250,y);
line(310,y+15,250,y);
line(190,y+15,250,y+30);
line(310,y+15,250,y+30);
	  line(250,y+30,250,y+60);
	  outtextxy(250,y+45,"Y");
	  y=y+60;
	  delay(400);
	  c=getc(fp);  c=getc(fp);
	  //do{c=getc(fp);}while(c!="{");
  i=0;
	   while(c!=EOF  && c!='}')
  {
  c=getc(fp);
  //i=0;
   while(c!='\n'&& c!=EOF && c!='}')
    {
     w[i]=c;
     c=getc(fp);
     i++;
   }
  w[i]='\0';
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}
  init_check(w);
  i=0;    }
  //ie1=y;
  line(200,ie0+15,150,ie0+15);
  line(150,ie0+15,150,y+15);
  line(150,y+15,200,y+15);
  setcolor(0);
  line(250,y-30,250,y);
  setcolor(15);
  outtextxy(150,ie0+20,"N");
  fscanf(fp,"%s",w);
  c=getc(fp);  c=getc(fp);
 i=0;
	   while(c!=EOF  && c!='}')
  {
  c=getc(fp);
  //i=0;
   while(c!='\n'&& c!=EOF && c!='}')
    {
     w[i]=c;
     c=getc(fp);
     i++;
   }
  w[i]='\0';
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}
  init_check(w);
  i=0;    }
  line(300,ie0+60,350,ie0+60);
  line(350,ie0+60,350,y+15);
  line(350,y+15,300,y+15);
	  break;
	 }
/*
  case 10: {//else
	  c=getc(fp);  c=getc(fp);
	  //do{c=getc(fp);}while(c!="{");
  i=0;
	   while(c!=EOF  && c!='}')
  {
  c=getc(fp);
  //i=0;
   while(c!='\n'&& c!=EOF && c!='}')
    {
     w[i]=c;
     c=getc(fp);
     i++;
   }
  w[i]='\0';
     if(y>480)
     {getch(); cleardevice();
      y=20;z0=20;}
  init_check(w);
  i=0;    }
  ie1=y;
  line(350,ie0+60,350,ie1+60);
  line(300,ie0+60,300,ie0+60);
  line(350,ie1+60,300,ie1+60);
  //outtextxy(150,ie0+20,"N");
	  break;
	 }
*/

  case 9:{ if(strlen(a)>4)
  {
	  outtextxy(200,y+10,a);
	  rectangle(200,y,300,y+30);
	  line(250,y+30,250,y+60);
	  y=y+60;
	  delay(400);  }
	  break;
	 }
     /*
  case 11:{
	   ellipse(250,y+10,0,360,50,10);
	   outtextxy(230,y+10,"end");
	   delay(400);
	   break;
	  }   */

 }
}
/*
 * main:
 *	The main program, of course
 */
int
main(int argc, char **argv)
{
    char *env;
    time_t lowtime;

    md_init();

#ifdef MASTER
    /*
     * Check to see if he is a wizard
     */
    if (argc >= 2 && argv[1][0] == '\0')
	if (strcmp(PASSWD, md_crypt(md_getpass("wizard's password: "******"mT")) == 0)
	{
	    wizard = TRUE;
	    player.t_flags |= SEEMONST;
	    argv++;
	    argc--;
	}

#endif

    /*
     * get home and options from environment
     */

    strcpy(home, md_gethomedir());

	if (strlen(home) > MAXSTR - strlen("rogue.save") - 1)
		*home = 0;

    strcpy(file_name, home);
    strcat(file_name, "rogue.save");

    if ((env = getenv("ROGUEOPTS")) != NULL)
	parse_opts(env);
    if (env == NULL || whoami[0] == '\0')
        strucpy(whoami, md_getusername(), strlen(md_getusername()));
    lowtime = time(NULL);
    if (getenv("SEED") != NULL)
    {
	dnum = atoi(getenv("SEED"));
	noscore = 1;
    }
    else
	dnum = (unsigned int) lowtime + md_getpid();
    seed = dnum;

    open_score();

	/* 
     * Drop setuid/setgid after opening the scoreboard file. 
     */ 

    md_normaluser();

    /*
     * check for print-score option
     */

	md_normaluser(); /* we drop any setgid/setuid priveldges here */

    if (argc == 2)
    {
	if (strcmp(argv[1], "-s") == 0)
	{
	    noscore = TRUE;
	    score(0, -1, 0);
	    exit(0);
	}
	else if (strcmp(argv[1], "-d") == 0)
	{
	    dnum = rnd(100);	/* throw away some rnd()s to break patterns */
	    while (--dnum)
		rnd(100);
	    purse = rnd(100) + 1;
	    level = rnd(100) + 1;
	    initscr();
	    getltchars();
	    death(death_monst());
	    exit(0);
	}
    }

    init_check();			/* check for legal startup */
    if (argc == 2)
	if (!restore(argv[1]))	/* Note: restore will never return */
	    my_exit(1);
#ifdef MASTER
    if (wizard)
	printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
#endif
	printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    fflush(stdout);

    initscr();				/* Start up cursor package */
    init_probs();			/* Set up prob tables for objects */
    init_player();			/* Set up initial player stats */
    init_names();			/* Set up names of scrolls */
    init_colors();			/* Set up colors of potions */
    init_stones();			/* Set up stone settings of rings */
    init_materials();			/* Set up materials of wands */
    setup();

    /*
     * The screen must be at least NUMLINES x NUMCOLS
     */
    if (LINES < NUMLINES || COLS < NUMCOLS)
    {
	printf("\nSorry, the screen must be at least %dx%d\n", NUMLINES, NUMCOLS);
	endwin();
	my_exit(1);
    }

    /*
     * Set up windows
     */
    hw = newwin(LINES, COLS, 0, 0);
    idlok(stdscr, TRUE);
    idlok(hw, TRUE);
#ifdef MASTER
    noscore = wizard;
#endif
    new_level();			/* Draw current level */
    /*
     * Start up daemons and fuses
     */
    start_daemon(runners, 0, AFTER);
    start_daemon(doctor, 0, AFTER);
    fuse(swander, 0, WANDERTIME, AFTER);
    start_daemon(stomach, 0, AFTER);
    playit();
    return(0);
}
Exemple #11
0
/*
* Return the generator
*/
const BigInt& DL_Group::get_g() const
   {
   init_check();
   return m_g;
   }
Exemple #12
0
int32_t main(int32_t argc, char *argv[])
{
	fix_stacksize();
		
	run_tests();
	int32_t i, j;
	prog_name = argv[0];
	struct timespec start_ts;
	cs_gettime(&start_ts); // Initialize clock_type

	if(pthread_key_create(&getclient, NULL))
	{
		fprintf(stderr, "Could not create getclient, exiting...");
		exit(1);
	}

	void (*mod_def[])(struct s_module *) =
	{
#ifdef MODULE_MONITOR
		module_monitor,
#endif
#ifdef MODULE_CAMD33
		module_camd33,
#endif
#ifdef MODULE_CAMD35
		module_camd35,
#endif
#ifdef MODULE_CAMD35_TCP
		module_camd35_tcp,
#endif
#ifdef MODULE_NEWCAMD
		module_newcamd,
#endif
#ifdef MODULE_CCCAM
		module_cccam,
#endif
#ifdef MODULE_PANDORA
		module_pandora,
#endif
#ifdef MODULE_GHTTP
		module_ghttp,
#endif
#ifdef CS_CACHEEX
		module_csp,
#endif
#ifdef MODULE_GBOX
		module_gbox,
#endif
#ifdef MODULE_CONSTCW
		module_constcw,
#endif
#ifdef MODULE_RADEGAST
		module_radegast,
#endif
#ifdef MODULE_SCAM
		module_scam,
#endif
#ifdef MODULE_SERIAL
		module_serial,
#endif
#ifdef HAVE_DVBAPI
		module_dvbapi,
#endif
		0
	};
	
	find_conf_dir();

	parse_cmdline_params(argc, argv);

	if(bg && do_daemon(1, 0))
	{
		printf("Error starting in background (errno=%d: %s)", errno, strerror(errno));
		cs_exit(1);
	}

	get_random_bytes_init();

#ifdef WEBIF
	if(cs_restart_mode)
		{ restart_daemon(); }
#endif

	memset(&cfg, 0, sizeof(struct s_config));
	cfg.max_pending = max_pending;

	if(cs_confdir[strlen(cs_confdir) - 1] != '/') { strcat(cs_confdir, "/"); }
	init_signal_pre(); // because log could cause SIGPIPE errors, init a signal handler first
	init_first_client();
	cs_lock_create(__func__, &system_lock, "system_lock", 5000);
	cs_lock_create(__func__, &config_lock, "config_lock", 10000);
	cs_lock_create(__func__, &gethostbyname_lock, "gethostbyname_lock", 10000);
	cs_lock_create(__func__, &clientlist_lock, "clientlist_lock", 5000);
	cs_lock_create(__func__, &readerlist_lock, "readerlist_lock", 5000);
	cs_lock_create(__func__, &fakeuser_lock, "fakeuser_lock", 5000);
	cs_lock_create(__func__, &ecmcache_lock, "ecmcache_lock", 5000);
	cs_lock_create(__func__, &ecm_pushed_deleted_lock, "ecm_pushed_deleted_lock", 5000);
	cs_lock_create(__func__, &readdir_lock, "readdir_lock", 5000);
	cs_lock_create(__func__, &cwcycle_lock, "cwcycle_lock", 5000);
	init_cache();
	cacheex_init_hitcache();
	init_config();
	cs_init_log();
	init_machine_info();
	init_check();
	if(!oscam_pidfile && cfg.pidfile)
		{ oscam_pidfile = cfg.pidfile; }
	if(!oscam_pidfile)
	{
		oscam_pidfile = get_tmp_dir_filename(default_pidfile, sizeof(default_pidfile), "oscam.pid");
	}
	if(oscam_pidfile)
		{ pidfile_create(oscam_pidfile); }
	cs_init_statistics();
	coolapi_open_all();
	init_stat();
	ssl_init();

	// These initializations *MUST* be called after init_config()
	// because modules depend on config values.
	for(i = 0; mod_def[i]; i++)
	{
		struct s_module *module = &modules[i];
		mod_def[i](module);
	}

	init_sidtab();
	init_readerdb();
	cfg.account = init_userdb();
	init_signal();
	init_provid();
	init_srvid();
	init_tierid();
	init_fakecws();

	start_garbage_collector(gbdb);

	cacheex_init();

	init_len4caid();
	init_irdeto_guess_tab();

	write_versionfile(false);

	led_init();
	led_status_default();

	azbox_init();

	mca_init();

	global_whitelist_read();
	ratelimit_read();

	for(i = 0; i < CS_MAX_MOD; i++)
	{
		struct s_module *module = &modules[i];
		if((module->type & MOD_CONN_NET))
		{
			for(j = 0; j < module->ptab.nports; j++)
			{
				start_listener(module, &module->ptab.ports[j]);
			}
		}
	}

	//set time for server to now to avoid 0 in monitor/webif
	first_client->last = time((time_t *)0);

	webif_init();

	start_thread("reader check", (void *) &reader_check, NULL, NULL, 1, 1);
	cw_process_thread_start();
	checkcache_process_thread_start();

	lcd_thread_start();

	do_report_emm_support();

	init_cardreader();

	cs_waitforcardinit();
	
	emm_load_cache();
	load_emmstat_from_file();

	led_status_starting();

	ac_init();

	start_thread("card poll", (void *) &card_poll, NULL, NULL, 1, 1);

	for(i = 0; i < CS_MAX_MOD; i++)
	{
		struct s_module *module = &modules[i];
		if((module->type & MOD_CONN_SERIAL) && module->s_handler)
			{ module->s_handler(NULL, NULL, i); }
	}

	// main loop function
	process_clients();

	SAFE_COND_SIGNAL(&card_poll_sleep_cond); // Stop card_poll thread
	cw_process_thread_wakeup(); // Stop cw_process thread
	SAFE_COND_SIGNAL(&reader_check_sleep_cond); // Stop reader_check thread

	// Cleanup
#ifdef MODULE_GBOX	
	stop_sms_sender();
#endif
	webif_close();
	azbox_close();
	coolapi_close_all();
	mca_close();

	led_status_stopping();
	led_stop();
	lcd_thread_stop();

	remove_versionfile();

	stat_finish();
	dvbapi_stop_all_descrambling();
	dvbapi_save_channel_cache();
	emm_save_cache();
	save_emmstat_to_file();
	
	cccam_done_share();
	gbox_send_good_night(); 

	kill_all_clients();
	kill_all_readers();
	for(i = 0; i < CS_MAX_MOD; i++)
	{
		struct s_module *module = &modules[i];
		if((module->type & MOD_CONN_NET))
		{
			for(j = 0; j < module->ptab.nports; j++)
			{
				struct s_port *port = &module->ptab.ports[j];
				if(port->fd)
				{
					shutdown(port->fd, SHUT_RDWR);
					close(port->fd);
					port->fd = 0;
				}
			}
		}
	}

	if(oscam_pidfile)
		{ unlink(oscam_pidfile); }

	// sleep a bit, so hopefully all threads are stopped when we continue
	cs_sleepms(200);

	free_cache();
	cacheex_free_hitcache();
	webif_tpls_free();
	init_free_userdb(cfg.account);
	cfg.account = NULL;
	init_free_sidtab();
	free_readerdb();
	free_irdeto_guess_tab();
	config_free();
	ssl_done();

	detect_valgrind();
	if (!running_under_valgrind)
		cs_log("cardserver down");
	else
		cs_log("running under valgrind, waiting 5 seconds before stopping cardserver");
	log_free();

	if (running_under_valgrind) sleep(5); // HACK: Wait a bit for things to settle

	stop_garbage_collector();

	NULLFREE(first_client->account);
	NULLFREE(first_client);
	free(stb_boxtype);
	free(stb_boxname);

	// This prevents the compiler from removing config_mak from the final binary
	syslog_ident = config_mak;

	return exit_oscam;
}