Exemplo n.º 1
0
bool ReturnInstruction::validateContents()
{
    do_validate(QSet<typ_skladnika>() << ATOM_LICZBA << ATOM_IDENT << OPER_ARYTM << WYR_INDEKS << FUNC_CALL << LISTA_WARTOSCI << LISTA_LWYR);
    if (m_valid && statement && statement->syntacticTree()) {
        //statement->syntacticTree()->typ = ATOM_LICZBA;
    }

    return m_valid;
}
Exemplo n.º 2
0
int tools_main(error_monitor_t em) {
    struct cpe_dr_generate_ctx ctx;
    struct mem_buffer buffer;
    int rv;

    ctx.m_builder = NULL;
    ctx.m_metalib = NULL;
    ctx.m_em = em;

    rv = 0;

    ctx.m_builder = dr_metalib_builder_create(NULL, em);
    if (ctx.m_builder == NULL) {
        CPE_ERROR(em, "create metalib builder fail!");
        return -1;
    }

    prepare_input(ctx.m_builder, em);

    dr_metalib_builder_analize(ctx.m_builder);

    mem_buffer_init(&buffer, 0);
    if (dr_inbuild_build_lib(
            &buffer,
            dr_metalib_bilder_lib(ctx.m_builder),
            em) == 0)
    {
        ctx.m_metalib = (LPDRMETALIB)mem_buffer_make_continuous(&buffer, 0), mem_buffer_size(&buffer);

        if (ctx.m_metalib) {
            if (do_validate(&ctx) != 0) rv = -1;
            if (do_generate_h(&ctx) != 0) rv = -1;
            if (do_generate_lib_bin(&ctx) != 0) rv = -1;
            if (do_generate_lib_c(&ctx) != 0) rv = -1;
        }
    }
    else {
        rv = -1;
    }

    mem_buffer_clear(&buffer);
    dr_metalib_builder_free(ctx.m_builder);

    return rv;
}
/****************************************************************************
 *  * handle_request(request, clientaddr, addrlen)
 *   *   branch on code in request
 *    */
handle_request(char *req,struct sockaddr *client, socklen_t addlen)
{
	char	*response;
	int	ret;

	/* act and compose a response */
	if ( strncmp(req, "HELO", 4) == 0 )
		response = do_hello(req);
	else if ( strncmp(req, "GBYE", 4) == 0 )
		response = do_goodbye(req);
	else if ( strncmp(req, "VALD", 4) == 0 )
		response = do_validate(req);
	else
		response = "FAIL invalid request";

	/* send the response to the client */
	narrate("SAID:", response, client);
	ret = sendto(sd, response, strlen(response),0, client, addlen);
	if ( ret == -1 )
		perror("SERVER sendto failed");
}
Exemplo n.º 4
0
bool test_verify_inc(bool fast_flag, bool quiet_flag) {
    int d;
    param_set_t lm_array[MAX_D] = { LMS_SHA256_N32_H10, LMS_SHA256_N32_H5,
                                    LMS_SHA256_N32_H5, LMS_SHA256_N32_H5 };
    param_set_t lm_ots_array[MAX_D] = {
                  LMOTS_SHA256_N32_W4, LMOTS_SHA256_N32_W4,
                  LMOTS_SHA256_N32_W4, LMOTS_SHA256_N32_W4 };

    for (d=1; d<=MAX_D; d++) {
    size_t len_private_key = hss_get_private_key_len(d, lm_array, lm_ots_array );
    if (len_private_key == 0) { 
        printf( "    Len private key failed\n" );
        return false;
    }
    unsigned char private_key[len_private_key];

    unsigned len_public_key = hss_get_public_key_len(d, lm_array, lm_ots_array );
    if (len_public_key == 0) { 
        printf( "    Len public key failed\n" );
        return false;
    }

    size_t len_signature = hss_get_signature_len(d, lm_array, lm_ots_array );
    if (len_signature == 0) { 
        printf( "    Len signature failed\n" );
        return false;
    }

    unsigned char public_key[len_public_key];

    unsigned char aux_data[1000];
    
    /* Generate the public key */
    if (!hss_generate_private_key(
                generate_random,
                d, lm_array, lm_ots_array,
                NULL, private_key,
                public_key, len_public_key,
                aux_data, sizeof aux_data, 0 )) {
        printf( "    Gen private key failed\n" );
        return false;
    }

    /* Load the private key into memory */
    struct hss_working_key *w = hss_load_private_key(
                           NULL, private_key,
                           0,     /* Minimal memory */
                           aux_data, sizeof aux_data, 0 );
    if (!w) {
        printf( "    *** failed loading private key\n" );
        return false;
    }

    unsigned char signature[len_signature];
    /*
     * Try correct validations, at various step levels
     */
    int step;
    for (step = 1; step < 70; step++) {
        /* Generate a valid signature */
        static unsigned char test_message[] =
          "The powers not delegated to the United States by the Constitution, "
          "nor prohibited by it to the States, are reserved to the States "
          "respectively, or to the people";
  
        if (!hss_generate_signature( w, NULL, private_key,
                                 test_message, sizeof test_message,
                                 signature, len_signature, 0 )) {
            printf( "    *** failed signing test message\n" );
            hss_free_working_key(w);
            return false;
        }

        if (!do_validate( public_key,
                          test_message, sizeof test_message,
                          signature, len_signature, step, 0 )) {
            printf( "    *** failed valid signature\n" );
            hss_free_working_key(w);
            return false;
        }
    }

    /* Try validating the wrong message (and reuse the signature we */
    /* generated above) */
    unsigned char wrong_message[] = "Wrong message";
    enum hss_error_code error;
    if (do_validate( public_key,
                          wrong_message, sizeof wrong_message,
                          signature, len_signature, 7, &error )) {
        printf( "    *** incorrect message validated\n" );
        hss_free_working_key(w);
        return false;
    }
    if (error != hss_error_bad_signature) {
        printf( "    *** incorrect error code\n" );
        hss_free_working_key(w);
        return false;
    }

    /* Corrupt the signature; check if we detect that */
    int i;
    unsigned char test_message[] =  "The powers ...";
  
    if (!hss_generate_signature( w, NULL, private_key,
                                 test_message, sizeof test_message,
                                 signature, len_signature, 0 )) {
        printf( "    *** failed signing test message\n" );
        hss_free_working_key(w);
        return false;
    }
    int count = 0;
    for (i=0; i<len_signature; i++) {
        int b;
            /* In fast mode, check every fifth bit */
        if (fast_flag) {
            count++; if (count != 5) continue; count = 0;
        }
        for (b = 0x01; b < 0x100; b <<= 1) {
            signature[i] ^= b;
            enum hss_error_code error;
            if (do_validate( public_key,
                          test_message, sizeof test_message,
                          signature, len_signature, sizeof test_message, 
                          &error )) {
                printf( "    *** incorrect signature validated\n" );
                hss_free_working_key(w);
                return false;
            }
            if (error != hss_error_bad_signature) {
                printf( "    *** incorrect error code\n" );
                hss_free_working_key(w);
                return false;
            }
            signature[i] ^= b;
        }
    }
        /* Check a too-short signature */
    if (do_validate( public_key,
                          test_message, sizeof test_message,
                          signature, len_signature - 1, sizeof test_message,
                          &error)) {
        printf( "    *** incorrect signature validated\n" );
        hss_free_working_key(w);
        return false;
    }
    if (error != hss_error_bad_signature) {
        printf( "    *** incorrect error code\n" );
        hss_free_working_key(w);
        return false;
    }

        /* And double check that the correct signature passes */
    if (!do_validate( public_key,
                          test_message, sizeof test_message,
                          signature, len_signature, sizeof test_message, 0 )) {
        printf( "    *** error in test\n" );
        hss_free_working_key(w);
        return false;
    }

    hss_free_working_key(w);
    }

    return true;
}
Exemplo n.º 5
0
int
main (int argc, char **argv )
{
  ARGPARSE_ARGS pargs;
  assuan_context_t ctx;
  gpg_error_t err;
  unsigned char *certbuf;
  size_t certbuflen = 0;
  int cmd_ping = 0;
  int cmd_cache_cert = 0;
  int cmd_validate = 0;
  int cmd_lookup = 0;
  int cmd_loadcrl = 0;
  int cmd_squid_mode = 0;

  set_strusage (my_strusage);
  log_set_prefix ("dirmngr-client",
                  JNLIB_LOG_WITH_PREFIX);

  /* For W32 we need to initialize the socket subsystem.  Becuase we
     don't use Pth we need to do this explicit. */
#ifdef HAVE_W32_SYSTEM
 {
   WSADATA wsadat;

   WSAStartup (0x202, &wsadat);
 }
#endif /*HAVE_W32_SYSTEM*/

  /* Init Assuan.  */
  assuan_set_assuan_log_prefix (log_get_prefix (NULL));
  assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);

  /* Setup I18N. */
  i18n_init();

  /* Parse the command line.  */
  pargs.argc = &argc;
  pargs.argv = &argv;
  pargs.flags= 1;  /* Do not remove the args. */
  while (arg_parse (&pargs, opts) )
    {
      switch (pargs.r_opt)
        {
        case oVerbose: opt.verbose++; break;
        case oQuiet: opt.quiet++; break;

        case oOCSP: opt.use_ocsp++; break;
        case oPing: cmd_ping = 1; break;
        case oCacheCert: cmd_cache_cert = 1; break;
        case oValidate: cmd_validate = 1; break;
        case oLookup: cmd_lookup = 1; break;
        case oUrl: opt.url = 1; break;
        case oLocal: opt.local = 1; break;
        case oLoadCRL: cmd_loadcrl = 1; break;
        case oPEM: opt.pem = 1; break;
        case oSquidMode:
          opt.pem = 1;
          opt.escaped_pem = 1;
          cmd_squid_mode = 1;
          break;
        case oForceDefaultResponder: opt.force_default_responder = 1; break;

        default : pargs.err = 2; break;
	}
    }
  if (log_get_errorcount (0))
    exit (2);

  /* Build the helptable for radix64 to bin conversion. */
  if (opt.pem)
    {
      int i;
      unsigned char *s;

      for (i=0; i < 256; i++ )
        asctobin[i] = 255; /* Used to detect invalid characters. */
      for (s=bintoasc, i=0; *s; s++, i++)
        asctobin[*s] = i;
    }


  if (cmd_ping)
    err = 0;
  else if (cmd_lookup || cmd_loadcrl)
    {
      if (!argc)
        usage (1);
      err = 0;
    }
  else if (cmd_squid_mode)
    {
      err = 0;
      if (argc)
        usage (1);
    }
  else if (!argc)
    {
      err = read_certificate (NULL, &certbuf, &certbuflen);
      if (err)
        log_error (_("error reading certificate from stdin: %s\n"),
                   gpg_strerror (err));
    }
  else if (argc == 1)
    {
      err = read_certificate (*argv, &certbuf, &certbuflen);
      if (err)
        log_error (_("error reading certificate from '%s': %s\n"),
                   *argv, gpg_strerror (err));
    }
  else
    {
      err = 0;
      usage (1);
    }

  if (log_get_errorcount (0))
    exit (2);

  if (certbuflen > 20000)
    {
      log_error (_("certificate too large to make any sense\n"));
      exit (2);
    }

  ctx = start_dirmngr (1);
  if (!ctx)
    exit (2);

  if (cmd_ping)
    ;
  else if (cmd_squid_mode)
    {
      while (!(err = squid_loop_body (ctx)))
        ;
      if (gpg_err_code (err) == GPG_ERR_EOF)
        err = 0;
    }
  else if (cmd_lookup)
    {
      int last_err = 0;

      for (; argc; argc--, argv++)
        {
          err = do_lookup (ctx, *argv);
          if (err)
            {
              log_error (_("lookup failed: %s\n"), gpg_strerror (err));
              last_err = err;
            }
        }
      err = last_err;
    }
  else if (cmd_loadcrl)
    {
      int last_err = 0;

      for (; argc; argc--, argv++)
        {
          err = do_loadcrl (ctx, *argv);
          if (err)
            {
              log_error (_("loading CRL '%s' failed: %s\n"),
                         *argv, gpg_strerror (err));
              last_err = err;
            }
        }
      err = last_err;
    }
  else if (cmd_cache_cert)
    {
      err = do_cache (ctx, certbuf, certbuflen);
      xfree (certbuf);
    }
  else if (cmd_validate)
    {
      err = do_validate (ctx, certbuf, certbuflen);
      xfree (certbuf);
    }
  else
    {
      err = do_check (ctx, certbuf, certbuflen);
      xfree (certbuf);
    }

  assuan_release (ctx);

  if (cmd_ping)
    {
      if (!opt.quiet)
        log_info (_("a dirmngr daemon is up and running\n"));
      return 0;
    }
  else if (cmd_lookup|| cmd_loadcrl || cmd_squid_mode)
    return err? 1:0;
  else if (cmd_cache_cert)
    {
      if (err && gpg_err_code (err) == GPG_ERR_DUP_VALUE )
        {
          if (!opt.quiet)
            log_info (_("certificate already cached\n"));
        }
      else if (err)
        {
          log_error (_("error caching certificate: %s\n"),
                     gpg_strerror (err));
          return 1;
        }
      return 0;
    }
  else if (cmd_validate && err)
    {
      log_error (_("validation of certificate failed: %s\n"),
                 gpg_strerror (err));
      return 1;
    }
  else if (!err)
    {
      if (!opt.quiet)
        log_info (_("certificate is valid\n"));
      return 0;
    }
  else if (gpg_err_code (err) == GPG_ERR_CERT_REVOKED )
    {
      if (!opt.quiet)
        log_info (_("certificate has been revoked\n"));
      return 1;
    }
  else
    {
      log_error (_("certificate check failed: %s\n"), gpg_strerror (err));
      return 2;
    }
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    GError *error = NULL;
    GOptionContext *context;

    context = g_option_context_new (NULL);
    g_option_context_add_main_entries (context, entries, "seafile");

    if (argc == 1) {
        usage();
        return 0;
    }
    if (!g_option_context_parse (context, &argc, &argv, &error))
    {
        g_print ("Option parsing failed: %s\n", error->message);
        exit (1);
    }
    if (print_version) {
        show_version();
        return 0;
    }

    if (!seaf_data_dir) {
        if (!ccnet_conf_dir) {
            ccnet_conf_dir = ccnet_expand_path(DEFAULT_CONFIG_DIR);
            if (!ccnet_conf_dir) {
                fprintf (stderr, "[ERROR] Failed to get ccnet conf dir\n");
                return -1;
            }
        }
        seaf_data_dir = get_seaf_data_dir(ccnet_conf_dir);
        if (!seaf_data_dir) {
            fprintf (stderr, "[ERROR] Failed to get seafile data directory\n");
            return -1;
        }
        
        if(!seaf_data_dir_is_valid()) {
            fprintf (stderr, "[ERROR] seafile data directory is not valid.\n");
            return -1;
        }
    }

    printf ("[INFO] seafile data directory is %s\n", seaf_data_dir);
    g_type_init ();
    log_init();

    if (!worktree_dir)
        worktree_dir = g_build_filename (g_get_home_dir(), "seafile", NULL);

    seaf = seafile_session_new(seaf_data_dir, worktree_dir, NULL);
    seafile_session_prepare(seaf);
    if (!seaf) {
        fprintf (stderr, "[ERROR] Failed to initialize\n");
        return -1;
    }

    if (list_repos) {
        do_list_repos ();
    }

    if (validate_data) {
        if (do_validate_prepare() < 0)
            return -1;
        do_validate();
        return 0;
    }

    if (destroy_repo_id) {
        if (seafile_is_running()) {
            fprintf (stderr, "seafile is running, close it and try again.\n");
            return -1;
        }
        do_destroy_repo(destroy_repo_id);
        return 0;
    }

    cleanup ();
    return 0;
}
Exemplo n.º 7
0
/*
 * Entry point of pg_arman command.
 */
int
main(int argc, char *argv[])
{
	const char	   *cmd = NULL;
	const char	   *range1 = NULL;
	const char	   *range2 = NULL;
	pgBackupRange	range;
	int				i;

	/* do not buffer progress messages */
	setvbuf(stdout, 0, _IONBF, 0);	/* TODO: remove this */

	/* initialize configuration */
	catalog_init_config(&current);

	/* overwrite configuration with command line arguments */
	i = pgut_getopt(argc, argv, options);

	for (; i < argc; i++)
	{
		if (cmd == NULL)
			cmd = argv[i];
		else if (range1 == NULL)
			range1 = argv[i];
		else if (range2 == NULL)
			range2 = argv[i];
		else
			elog(ERROR, "too many arguments");
	}

	/* command argument (backup/restore/show/...) is required. */
	if (cmd == NULL)
	{
		help(false);
		return 1;
	}

	/* get object range argument if any */
	if (range1 && range2)
		parse_range(&range, range1, range2);
	else if (range1)
		parse_range(&range, range1, "");
	else
		range.begin = range.end = 0;

	/* Read default configuration from file. */
	if (backup_path)
	{
		char	path[MAXPGPATH];
		/* Check if backup_path is directory. */
		struct stat stat_buf;
		int rc = stat(backup_path, &stat_buf);

		/* If rc == -1,  there is no file or directory. So it's OK. */
		if (rc != -1 && !S_ISDIR(stat_buf.st_mode))
			elog(ERROR, "-B, --backup-path must be a path to directory");

		join_path_components(path, backup_path, PG_RMAN_INI_FILE);
		pgut_readopt(path, options, ERROR);
	}

	/* BACKUP_PATH is always required */
	if (backup_path == NULL)
		elog(ERROR, "required parameter not specified: BACKUP_PATH (-B, --backup-path)");

	/* path must be absolute */
	if (backup_path != NULL && !is_absolute_path(backup_path))
		elog(ERROR, "-B, --backup-path must be an absolute path");
	if (pgdata != NULL && !is_absolute_path(pgdata))
		elog(ERROR, "-D, --pgdata must be an absolute path");
	if (arclog_path != NULL && !is_absolute_path(arclog_path))
		elog(ERROR, "-A, --arclog-path must be an absolute path");

	/* Sanity checks with commands */
	if (pg_strcasecmp(cmd, "delete") == 0 && arclog_path == NULL)
		elog(ERROR, "delete command needs ARCLOG_PATH (-A, --arclog-path) to be set");

	/* setup exclusion list for file search */
	for (i = 0; pgdata_exclude[i]; i++)		/* find first empty slot */
		;
	if (arclog_path)
		pgdata_exclude[i++] = arclog_path;

	/* do actual operation */
	if (pg_strcasecmp(cmd, "init") == 0)
		return do_init();
	else if (pg_strcasecmp(cmd, "backup") == 0)
	{
		pgBackupOption bkupopt;
		int res;
		bkupopt.smooth_checkpoint = smooth_checkpoint;
		bkupopt.keep_data_generations = keep_data_generations;
		bkupopt.keep_data_days = keep_data_days;

		/* Do the backup */
		res = do_backup(bkupopt);
		if (res != 0)
			return res;

		/* If validation has been requested, do it */
		range.begin = current.start_time;
		range.end = current.start_time + 1;
		if (backup_validate)
			do_validate(&range);
	}
	else if (pg_strcasecmp(cmd, "restore") == 0)
		return do_restore(target_time, target_xid,
					target_inclusive, target_tli);
	else if (pg_strcasecmp(cmd, "show") == 0)
		return do_show(&range, show_all);
	else if (pg_strcasecmp(cmd, "validate") == 0)
		return do_validate(&range);
	else if (pg_strcasecmp(cmd, "delete") == 0)
		return do_delete(&range);
	else
		elog(ERROR, "invalid command \"%s\"", cmd);

	return 0;
}