Example #1
0
inline int main2(const size_t &argc, const char * const argv[]) {
    std::srand(static_cast<unsigned int>(std::time(0)));

    std::vector<std::string> args(argc - 1u);
    for(size_t i = 1u; i < argc; ++i)
        args[i - 1u] = argv[i];

    try {
        // Load config
        const bool user_config = load_config();

        // Initialize Game
        Zeni::Game &gr = Zeni::get_Game(&args);

        // Check Rendering Options on Firstrun
        if(!user_config && Zeni::Video::is_enabled())
            gr.push_state(new Zeni::Configurator_Video::Check_State(true));

        // Run Game
        gr.run();
    }
    catch(Zeni::Quit_Event &) {
        std::cerr << "Exiting normally." << std::endl;
    }
#ifdef _WINDOWS
#pragma warning( push )
#pragma warning( disable : 4130 )
#endif
    catch(Zeni::Error &error) {
        std::cerr << error.msg << std::endl;

        print_errors();

        assert("Zeni::Error caught in main - Please see stderr.txt" == 0);
        return 1;
    }
    catch(std::exception &except) {
        std::cerr << except.what() << std::endl;

        print_errors();

        assert("std::exception caught in main - Please see stderr.txt" == 0);
        return 1;
    }
    catch(...) {
        std::cerr << "Unknown Error (Neither Zeni::Error nor std::exception)";

        print_errors();

        assert("Unknown Error caught in main" == 0);
        throw;
    }
#ifdef _WINDOWS
#pragma warning( pop )
#endif

    print_errors();

    return 0;
}
Example #2
0
int create_passive_socket(int port, char * host)
{
    int psocket, flag = 1;
    struct sockaddr_in serv_addr;
    if((psocket = socket(AF_INET, SOCK_STREAM, 0))<0)
    {
        print_errors(0,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
    }
    if(setsockopt( psocket, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)) < 0 )
    {
        print_errors(6,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
    }
    
    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr(host);
    serv_addr.sin_port = htons(port);

    if(bind(psocket, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
    {
        print_errors(1,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
    }
    print_errors(2,NOTICE_TYPE,CHILD_SERVER_PREFIX,0);
    
    if(listen(psocket, 20)<0)
    { 
        print_errors(3,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
    }  
    return psocket;
}
Example #3
0
int       
__bro_openssl_read(BroConn *bc, uchar *buf, uint buf_size)
{
  int n;

  D_ENTER;
  
  /* It's important here to use <= for comparison, since, as the
   * invaluable O'Reilly OpenSSL book reports, "for each of the four
   * reading and writing functions, a 0 or -1 return value may or may
   * not necessarily indicate that an error has occurred." This may or
   * may not necessarily be indicative of the incredible PITA that
   * OpenSSL is. --cpk
   */
  if ( (n = BIO_read(bc->bio, buf, buf_size)) <= 0)
    {
      if (BIO_should_retry(bc->bio))
	D_RETURN_(0);
      
      __bro_openssl_shutdown(bc);
      D(("Connection closed, BIO_read() returned %i.\n", n));      
      print_errors();
      D_RETURN_(-1);
    }
    
  D_RETURN_(n);
}
Example #4
0
bool
ssl_connect_wget (int fd, const char *hostname)
{
  SSL *conn;
  struct scwt_context scwt_ctx;
  struct openssl_transport_context *ctx;

  DEBUGP (("Initiating SSL handshake.\n"));

  assert (ssl_ctx != NULL);
  conn = SSL_new (ssl_ctx);
  if (!conn)
    goto error;
#if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
  /* If the SSL library was build with support for ServerNameIndication
     then use it whenever we have a hostname.  If not, don't, ever. */
  if (! is_valid_ip_address (hostname))
    {
      if (! SSL_set_tlsext_host_name (conn, hostname))
        {
          DEBUGP (("Failed to set TLS server-name indication."));
          goto error;
        }
    }
#endif

#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)
#endif
  if (!SSL_set_fd (conn, FD_TO_SOCKET (fd)))
    goto error;
  SSL_set_connect_state (conn);

  scwt_ctx.ssl = conn;
  if (run_with_timeout(opt.read_timeout, ssl_connect_with_timeout_callback,
                       &scwt_ctx)) {
    DEBUGP (("SSL handshake timed out.\n"));
    goto timeout;
  }
  if (scwt_ctx.result <= 0 || conn->state != SSL_ST_OK)
    goto error;

  ctx = xnew0 (struct openssl_transport_context);
  ctx->conn = conn;

  /* Register FD with Wget's transport layer, i.e. arrange that our
     functions are used for reading, writing, and polling.  */
  fd_register_transport (fd, &openssl_transport, ctx);
  DEBUGP (("Handshake successful; connected socket %d to SSL handle 0x%0*lx\n",
           fd, PTR_FORMAT (conn)));
  return true;

 error:
  DEBUGP (("SSL handshake failed.\n"));
  print_errors ();
 timeout:
  if (conn)
    SSL_free (conn);
  return false;
}
Example #5
0
/* Perform the SSL handshake on file descriptor FD, which is assumed
   to be connected to an SSL server.  The SSL handle provided by
   OpenSSL is registered with the file descriptor FD using
   fd_register_transport, so that subsequent calls to fd_read,
   fd_write, etc., will use the corresponding SSL functions.

   Returns 1 on success, 0 on failure.  */
int HttpsRetriever::ssl_connect(int fd )
{
	  SSL *ssl;

	  DEBUGP (("Initiating SSL handshake.\n"));

	  assert (ssl_ctx != NULL);
	  ssl = SSL_new (ssl_ctx);
	  if (!ssl)
	    goto error;
	  if (!SSL_set_fd (ssl, fd))
	    goto error;
	  SSL_set_connect_state (ssl);
	  if (SSL_connect (ssl) <= 0 || ssl->state != SSL_ST_OK)
	    goto error;

	  /* Register FD with Wget's transport layer, i.e. arrange that our
	     functions are used for reading, writing, and polling.  */
	     
	  //fd_register_transport (fd, openssl_read, openssl_write, openssl_poll,
		//			 openssl_peek, openssl_close, ssl);
		
		//DEBUGP (("Handshake successful; connected socket %d to SSL handle 0x%0*lx\n",
		   //fd, PTR_FORMAT (ssl)));
	  return 1;

	 error:
	  DEBUGP (("SSL handshake failed.\n"));
	  print_errors ();
	  if (ssl)
	    SSL_free (ssl);
	  return 0;
	return  -1 ;
}
Example #6
0
/********************************************//**
 *
 * This is the main method which will start the compiler.
 * 1) Check if the file name contains .ps, if not it will exit.
 * 2) Do the first Transition.
 * 3) Do the second transition.
 * 4) Check for errors, if errors exist it will print them and exit the program
 *    before writing the files.
 * 5) Generate the required files.
 *
 ***********************************************/
int main(int argc, char *argv[]) {
	Compiler *compiler = NULL;
	int curFileIdx = 1;

	if (argc == 1) {
		printf("No input files to compile!\n");
		exit(0);
	} else {
		while (--argc) {

			if (is_valid_filename(argv[curFileIdx]) == FALSE)
				exit(0);

			init_compiler(&compiler, BASE_OFFSET, argv[curFileIdx]);
			first_transition(compiler);
			second_transition(compiler);

			if (check_errors(compiler)) {
				//printf("errors\n");
				print_errors(compiler);
				exit(0);
			} else
				generate_files(compiler);

			free(compiler);
			curFileIdx++;
		}
	}

	printf("Compilation finished successfully.\n");
	return 0;
}
Example #7
0
SSL_CTX *init_ssl_ctx(){
  //Allow ssl3, tls1, 1.1 or 1.2
  const SSL_METHOD* method = SSLv23_method();
  if(method == NULL){goto err;}
  ctx = SSL_CTX_new(method);
  if(ctx == NULL){goto err;}
  //Disable ssl2, ssl3 and forbid compression, ssl2 should already be disabled
  //but there's no harm in making sure
  const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION;
  SSL_CTX_set_options(ctx, flags);//can't fail
  //make sure that we actually verify the certificate
  //this uses the default verification prodecure (thus the NULL)
  SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
  //Load the CA certificates file
  if(SSL_CTX_load_verify_locations(ctx, certificates_location, NULL) == 0){
    goto err;
  }
  if(SSL_CTX_set_cipher_list(ctx, prefered_ciphers) == 0){
    goto err;
  }
  return ctx;
 err:
  print_errors();//this might not actually print anything
  //There's no function to explicitly free an SSL_METHOD, I'm assuming they're
  //probably static anyway and we just get a pointer.
  SSL_CTX_free(ctx);
  return NULL;
}
Example #8
0
bool
ssl_connect (int fd) 
{
  SSL *conn;
  struct openssl_transport_context *ctx;

  DEBUGP (("Initiating SSL handshake.\n"));

  assert (ssl_ctx != NULL);
  conn = SSL_new (ssl_ctx);
  if (!conn)
    goto error;
  if (!SSL_set_fd (conn, fd))
    goto error;
  SSL_set_connect_state (conn);
  if (SSL_connect (conn) <= 0 || conn->state != SSL_ST_OK)
    goto error;

  ctx = xnew0 (struct openssl_transport_context);
  ctx->conn = conn;

  /* Register FD with Wget's transport layer, i.e. arrange that our
     functions are used for reading, writing, and polling.  */
  fd_register_transport (fd, &openssl_transport, ctx);
  DEBUGP (("Handshake successful; connected socket %d to SSL handle 0x%0*lx\n",
           fd, PTR_FORMAT (conn)));
  return true;

 error:
  DEBUGP (("SSL handshake failed.\n"));
  print_errors ();
  if (conn)
    SSL_free (conn);
  return false;
}
Example #9
0
t_list		*args_process(char *options, char **argv, int argc)
{
	int			i;
	t_list		*dirlst;
	t_list		*errors;

	dirlst = NULL;
	errors = NULL;
	i = get_options(options, argv, argc);
	if (i == argc)
	{
		if (!(make_content(options, &dirlst, ".")))
			return (NULL);
	}
	while (i < argc)
	{
		if (!(make_content(options, &dirlst, argv[i])))
			if (!(make_error(&errors, argv[i])))
				return (NULL);
		i++;
	}
	if (errors != NULL)
		print_errors(errors);
	return (dirlst);
}
Example #10
0
int main(void) {
	if (sodium_init() == -1) {
		return -1;
	}

	return_status status = return_status_init();

	//create buffers
	buffer_t *master_key = buffer_create_on_heap(50, 50);
	buffer_t *subkey1 = buffer_create_on_heap(60, 60);
	buffer_t *subkey2 = buffer_create_on_heap(60, 60);
	buffer_t *subkey1_copy = buffer_create_on_heap(60, 60);

	int status_int = 0;
	status_int = buffer_fill_random(master_key, master_key->buffer_length);
	if (status_int != 0) {
		throw(KEYDERIVATION_FAILED, "Failed to generate master key.");
	}
	printf("Master key:\n");
	print_hex(master_key);
	putchar('\n');

	status = derive_key(subkey1, subkey1->buffer_length, master_key, 0);
	throw_on_error(KEYDERIVATION_FAILED, "Failed to derive first subkey.");
	printf("First subkey:\n");
	print_hex(subkey1);
	putchar('\n');

	status = derive_key(subkey2, subkey2->buffer_length, master_key, 1);
	throw_on_error(KEYDERIVATION_FAILED, "Failed to derive the second subkey.");
	printf("Second subkey:\n");
	print_hex(subkey2);
	putchar('\n');

	if (buffer_compare(subkey1, subkey2) == 0) {
		throw(KEYGENERATION_FAILED, "Both subkeys are the same.");
	}

	status = derive_key(subkey1_copy, subkey1_copy->buffer_length, master_key, 0);
	throw_on_error(KEYDERIVATION_FAILED, "Failed to derive copy of the first subkey.");

	if (buffer_compare(subkey1, subkey1_copy) != 0) {
		throw(INCORRECT_DATA, "Failed to reproduce subkey.");
	}

cleanup:
	buffer_destroy_from_heap_and_null_if_valid(master_key);
	buffer_destroy_from_heap_and_null_if_valid(subkey1);
	buffer_destroy_from_heap_and_null_if_valid(subkey2);
	buffer_destroy_from_heap_and_null_if_valid(subkey1_copy);

	on_error {
		print_errors(&status);
	}
	return_status_destroy_errors(&status);

	return status.status;
}
Example #11
0
/*
 * Finish --
 *	Called when aborting due to errors in command or fatal signal
 *
 * Side Effects:
 *	The program exits
 */
void
Finish()
{
	Job_Wait();
	print_errors();
	if (DEBUG(GRAPH2))
		post_mortem();
	exit(2);		/* Not 1 so -q can distinguish error */
}
Example #12
0
/********************************************************************
*                                                                   *
*                       FUNCTION main                               *
*                                                                   *
*********************************************************************/
int main (int argc, char *argv[])
{
    status_t           res;
    boolean            showver = FALSE;
    boolean            done = FALSE;
    help_mode_t        showhelpmode;

#ifdef MEMORY_DEBUG
    mtrace();
#endif

    /* this loop is used to implement the restart command the sw image is not 
     * reloaded; instead everything is cleaned up and re-initialized from 
     * scratch. If the shutdown operation (or Ctl-C exit) is used instead of 
     * restart, then the loop will only be executed once */
    while (!done) {
        res = cmn_init( argc, argv, &showver, &showhelpmode );
    
        if (res != NO_ERR) {
            log_error( "\nnetconfd: init returned (%s)", 
                       get_error_string(res) );
            agt_request_shutdown(NCX_SHUT_EXIT);
        } else {
            if (showver) {
                show_version();
            } else if (showhelpmode != HELP_MODE_NONE) {
                help_program_module( NETCONFD_MOD, NETCONFD_CLI, showhelpmode );
                agt_request_shutdown(NCX_SHUT_EXIT);
            } else {
                res = netconfd_run();
                if (res != NO_ERR) {
                    agt_request_shutdown(NCX_SHUT_EXIT);
                }
            }
        }

        netconfd_cleanup();
        print_error_count();

        if ( NCX_SHUT_EXIT == agt_shutdown_mode_requested() ) {
            done = TRUE;
        }
    }

    print_errors();
    print_error_count();

    if ( !log_is_open() ) {
        printf("\n");
    }

#ifdef MEMORY_DEBUG
    muntrace();
#endif

    return 0;
} /* main */
Example #13
0
static void
add_error(char *str)
{
	if (no_errs > 100) {
		print_errors();
		fprintf(stderr, "100 errors exceeded\n");
		exit(1);
	}
	parse_errors[no_errs++] = strdup(str);
}
Example #14
0
int
main(int argc, char **argv)
{
	FILE *datafile;

	grok_args(argc, argv);

	datafile = stdout;

	initialize();
	report_input(datafile);
	record_data_init(0., datafile);
	sim_loop();
	record_data_term();
	print_errors(stderr);
	fprintf(datafile, "SECTION,errors\n");
	print_errors(datafile);
	fprintf(datafile, "\n");
	exit(0);
}
Example #15
0
static void fatal(const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    fprintf(stderr, "Fatal: ");
    vfprintf(stderr, fmt, ap);
    va_end(ap);

    print_errors();
    exit(1);
}
Example #16
0
File: menus.c Project: lyuts/vifm
int
capture_output_to_menu(FileView *view, const char cmd[], menu_info *m)
{
	FILE *file, *err;
	char *line = NULL;
	int x;
	pid_t pid;

	LOG_INFO_MSG("Capturing output of the command to a menu: %s", cmd);

	pid = background_and_capture((char *)cmd, &file, &err);
	if(pid == (pid_t)-1)
	{
		show_error_msgf("Trouble running command", "Unable to run: %s", cmd);
		return 0;
	}

	show_progress("", 0);

	ui_cancellation_reset();
	ui_cancellation_enable();

	wait_for_data_from(pid, file, 0);

	x = 0;
	while((line = read_line(file, line)) != NULL)
	{
		char *expanded_line;
		show_progress("Loading menu", 1000);
		m->items = realloc(m->items, sizeof(char *)*(x + 1));
		expanded_line = expand_tabulation_a(line, cfg.tab_stop);
		if(expanded_line != NULL)
		{
			m->items[x++] = expanded_line;
		}

		wait_for_data_from(pid, file, 0);
	}
	m->len = x;

	ui_cancellation_disable();

	fclose(file);
	print_errors(err);

	if(ui_cancellation_requested())
	{
		append_to_string(&m->title, "(cancelled) ");
		append_to_string(&m->empty_msg, " (cancelled)");
	}

	return display_menu(m, view);
}
Example #17
0
/*
 * Finish --
 *	Called when aborting due to errors in child shell to signal
 *	abnormal exit.
 *
 * Side Effects:
 *	The program exits
 */
void
Finish(int errors) /* number of errors encountered in Make_Make */
{
	Job_Wait();
	if (errors != 0) {
		Error("Stop in %s:", Var_Value(".CURDIR"));
	}
	print_errors();
	if (DEBUG(GRAPH2))
		Targ_PrintGraph(2);
	exit(2);		/* Not 1 so -q can distinguish error */
}
Example #18
0
void process_status(const char *fcn_name, CURL *session, const CURLcode res, 
        const long response_code, const long elapsed_time, const int iter, 
        const char *path, bool tmp_session) {

    stats_counter("attempts", 1);

    if (res != CURLE_OK) {
        print_errors(iter, "curl_failures", fcn_name, res, response_code, elapsed_time, path);
        increment_node_failure(nodeaddr, res, response_code, elapsed_time);
        delete_session(session, tmp_session);
        return;
    }

    if (response_code >= 500) {
        print_errors(iter, "status500_failures", fcn_name, res, response_code, elapsed_time, path);
        increment_node_failure(nodeaddr, res, response_code, elapsed_time);
        delete_session(session, tmp_session);
        return;
    }

    if (elapsed_time > time_limit) {
        print_errors(iter, "slow_requests", fcn_name, res, response_code, elapsed_time, path);
        increment_node_failure(nodeaddr, res, response_code, elapsed_time);
        if (health_status_all_nodes() == UNHEALTHY) {
            trigger_saint_event(CLUSTER_FAILURE);
            set_dynamic_logging();
        }
        delete_session(session, tmp_session);
        return;
    }

    // If it wasn't an error, and it isn't the 0'th iter, then we must have failed previously and now recovered
    if (iter > 0) {
        stats_counter("recoveries", 1);
        log_print(LOG_NOTICE, SECTION_SESSION_DEFAULT,
            "%s: curl iter %d on path %s -- fusedav.%s.server-%s.recoveries", fcn_name, iter, path, filesystem_cluster, nodeaddr);
        increment_node_success(nodeaddr);
    }
}
Example #19
0
int connect_to_active_port(int port, char * host)
{
    struct sockaddr_in addr;
    int asock;
    if((asock = socket(AF_INET, SOCK_STREAM, 0))<0)
    {
        print_errors(0,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
        return -1;
    }
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(host);
    addr.sin_port = htons(port);
    print_errors(2,NOTICE_TYPE,CHILD_SERVER_PREFIX,0);
    if(connect(asock, (struct sockaddr *)&addr, sizeof(addr))<0)
    {
        print_errors(12,ERROR_TYPE,CHILD_SERVER_PREFIX,0);
        close(asock);
        return -1;
    }
    return asock;
}
Example #20
0
int main(int argc, const char *argv[])
{
    STACK_OF(X509) *chain;
    SSL_CTX *sctx;
    SSL *ssl;
    long ok;

    if (argc < 8)
	usage(argv[0]);

    /* SSL library and DANE library initialization */
#if OPENSSL_VERSION_NUMBER < 0x10100000L
    SSL_load_error_strings();
    SSL_library_init();
#endif

    if (DANESSL_library_init() <= 0)
	fatal("error initializing DANE library\n");

    /* Initialize context for DANE connections */
    if ((sctx = SSL_CTX_new(SSLv23_client_method())) == 0)
	fatal("error allocating SSL_CTX\n");
    SSL_CTX_set_verify(sctx, SSL_VERIFY_NONE, verify_callback);
    if (*argv[5] && (SSL_CTX_load_verify_locations(sctx, argv[5], 0)) <= 0)
	fatal("error loading CAfile\n");
    if (DANESSL_CTX_init(sctx) <= 0)
	fatal("error initializing SSL_CTX DANE state\n");

    /* Create a connection handle */
    if ((ssl = SSL_new(sctx)) == 0)
	fatal("error allocating SSL handle\n");
    if (DANESSL_init(ssl, argv[7], argv+7) <= 0)
	fatal("error initializing SSL handle DANE state\n");
    if (!add_tlsa(ssl, argv))
	fatal("error adding TLSA RR\n");

    /* Verify saved server chain */
    chain = load_chain(argv[6]);
    SSL_set_connect_state(ssl);
    DANESSL_verify_chain(ssl, chain);
    print_errors();
    printf("verify status: %ld\n", ok = SSL_get_verify_result(ssl));

    /* Cleanup */
    DANESSL_cleanup(ssl);
    SSL_free(ssl);
    SSL_CTX_free(sctx);

    return ok == X509_V_OK ? 0 : 1;
}
Example #21
0
int
main(int argc, char *argv[])
{
	int			 ch, i, r;
	uint16_t		 type = T_A;
	char			 buf[1024], *host;

	while((ch = getopt(argc, argv, "R:et:")) !=  -1) {
		switch(ch) {
		case 'R':
			parseresopt(optarg);
			break;
		case 'e':
			long_err += 1;
			break;
		case 't':
			if ((type = strtotype(optarg)) == 0)
				usage();
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	for (i = 0; i < argc; i++) {

		if (i)
			printf("\n");

		printf("===> \"%s\"\n", argv[i]);
		host = gethostarg(argv[i]);

		errno = 0;
		h_errno = 0;
		gai_errno = 0;
		rrset_errno = 0;

		r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf));
		if (r != -1) {
			dump_packet(buf, r);
			printf(";; MSG SIZE %i\n", r);
		}
		print_errors();
	}

	return (0);
}
Example #22
0
void package_done(pass_opt_t* opt)
{
  codegen_shutdown(opt);

  strlist_free(search);
  search = NULL;

  strlist_free(safe);
  safe = NULL;

  package_clear_magic();

  print_errors();
  free_errors();
}
Example #23
0
int
main(int argc, char *argv[])
{
	int			 i, ch, nflag = 0;
	struct netent		*n;
	char			*host;

	while((ch = getopt(argc, argv, "en")) !=  -1) {
		switch(ch) {
		case 'e':
			long_err += 1;
			break;
		case 'n':
			nflag = 1;
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	for(i = 0; i < argc; i++) {

		if (i)
			printf("\n");
		printf("===> \"%s\"\n", argv[i]);
		host = gethostarg(argv[i]);

		errno = 0;
		h_errno = 0;
		gai_errno = 0;
		rrset_errno = 0;

		if (nflag)
			n = getnetbyname(host);
		else
			n = getnetbyaddr(inet_network(host), AF_INET);
		if (n)
			print_netent(n);
		print_errors();
	}

	return (0);
}
Example #24
0
/*
** a t t e m p t _ t o _ p r i n t _ e r r o r s
**
** This routine is established as an exception handler with the base system
** such that we always attempt to print out error messages even in the case of
** an error in the compiler.  The print_errors routine, which we call is coded
** such that we cannot get into an infinite loop.
*/
static long attempt_to_print_errors()
{
#if !defined(vms)
#ifndef _MSDOS
    signal(SIGBUS,SIG_DFL);
#endif
    signal(SIGSEGV,SIG_DFL);
    signal(SIGFPE,SIG_DFL);
    signal(SIGILL,SIG_DFL);
#endif
    /*
     * Try printing out the errors, if there are none, or it was
     * attempted before, this call will just return.
     */
    print_errors();
    return 0;
}
void SSLBufferTryWrite(struct sslbuffer_t *sslbuffer)
{
	int res;
	unsigned long error;

	if (!sslbuffer->fl_writing)
	{
		if (BufferSize(sslbuffer->write_buffer_1) > 0)
			BufferCopy(sslbuffer->write_buffer_2, sslbuffer->write_buffer_1);
	}
	if (BufferSize(sslbuffer->write_buffer_2) > 0)
	{
		res = SSL_write(
			sslbuffer->ssl,
			BufferStart(sslbuffer->write_buffer_2),
			BufferSize(sslbuffer->write_buffer_2));
		if (res <= 0)
		{
			error = SSL_get_error(sslbuffer->ssl, res);
			sslbuffer->fl_writing = 1;
			if (error == SSL_ERROR_WANT_READ)
				sslbuffer->fl_want_read = 1;
			else if (error == SSL_ERROR_WANT_WRITE)
				sslbuffer->fl_want_write = 1;
			else
			{
				printf("%s:%d: unknown error %lu\n", __FILE__, __LINE__, error);
				print_errors();
				event_base_loopbreak(sslbuffer->base);
			}
			return;
		}

		BufferRemove(sslbuffer->write_buffer_2, (size_t) res);
		sslbuffer->fl_writing = 0;
		sslbuffer->fl_want_write = 0;
		sslbuffer->fl_want_read = 0;
	}

	if ( (BufferSize(sslbuffer->write_buffer_1) == 0) &&
		 (BufferSize(sslbuffer->write_buffer_2) == 0))
	{
		event_del(sslbuffer->ev_write);
	}
}
void SSLBufferTryRead(struct sslbuffer_t *sslbuffer)
{
	int res;
	static uint8_t buffer[256];
	unsigned long error;
	int errno_keep;

	do
	{
		res = SSL_read(sslbuffer->ssl, buffer, sizeof(buffer));
		errno_keep = errno;
		if (res <= 0)
		{
			error = SSL_get_error(sslbuffer->ssl, res);
			sslbuffer->fl_reading = 1;
			if (error == SSL_ERROR_WANT_READ)
				sslbuffer->fl_want_read = 1;
			else if (error == SSL_ERROR_WANT_WRITE)
				sslbuffer->fl_want_write = 1;
			else if (error == SSL_ERROR_ZERO_RETURN)
			{
				printf("%s:%d: SSL_read got SSL_ERROR_ZERO_RETURN\n", __FILE__,
					__LINE__);
				event_base_loopbreak(sslbuffer->base);
			}
			else if (error == SSL_ERROR_SYSCALL)
			{
				printf("%s:%d: SSL_read got SSL_ERROR_SYSCALL (%s)\n", __FILE__,
					 __LINE__, strerror(errno_keep));
				event_base_loopbreak(sslbuffer->base);
			}
			else
			{
				printf("%s:%d: other error %lu\n", __FILE__, __LINE__, error);
				print_errors();
				event_base_loopbreak(sslbuffer->base);
			}
			return;
		}
		(sslbuffer->readcb)(sslbuffer, buffer, res, sslbuffer->cb_ctx);
		sslbuffer->fl_reading = 0;
		sslbuffer->fl_want_write = 0;
		sslbuffer->fl_want_read = 0;
	} while (SSL_pending(sslbuffer->ssl));
}
Example #27
0
void rtos_system_test(void) {
	print("\n\n==============RTOS System Test==============\n");
	#ifndef RTOS_SYSTEM_TEST_SUMMARY
	print_cur_data_buf(_get_cur_data_buf());
	print_equistacks();
	int max_num_errors = -1;
	#else
	int max_num_errors = 10;
	#endif
	print("\n\n==============System Info==============\n");
	print("timestamp: \t%ds \t(%dmin)\n", get_current_timestamp(), get_current_timestamp()/60);
	print("ticks:	  \t%d\n", xTaskGetTickCount());
	print("sat state: \t%s\n", get_sat_state_str(get_sat_state()));
	print("reboot #:  \t%d\n", cache_get_reboot_count());
	print("num errors:\t%d\n", error_equistack.cur_size);
	print("most recent errs: ");
	print_errors(max_num_errors);
	print_task_info();
	print("====================End=====================\n\n");
}
Example #28
0
int main(int argc, char **argv)
{
	int fd = STDIN_FILENO;
//	int fd = open("rgnpkg/a.rgn", O_RDONLY);

	init_options (&options);
	parse_args (argc, argv, &options);

	if (!parse_vir (fd))
		return 0;
	cond_print("\n");

	while (parse_data_record(fd)){
		cond_print("\n");
	}

	print_errors ();

//	close(fd);
	return 0;
}
Example #29
0
/*
  Connect to host on the given port using tls and return the BIO object
  representing the connection.
*/
BIO* connect_tls(const char *host, const char *port){
  init_ssl_lib();
  //the assignment is redundant, but it's weird not having it
  ctx = init_ssl_ctx();
  if(!ctx){return NULL;}

  BIO *bio = BIO_new_ssl_connect(ctx);
  if(!bio){goto err;}

  if(BIO_set_conn_hostname(bio, host) == 0){
    goto err;
  }
  if(BIO_set_conn_port(bio, port) == 0){
    goto err;
  }

  SSL *ssl;
  BIO_get_ssl(bio, &ssl);
  //Handle renegotiation transparently
  SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
  //this is to let the server know what name we used to connect to it
  SSL_set_tlsext_host_name(ssl, host);
  if(BIO_do_connect(bio) == 0){
    goto err;
  }
  if(BIO_do_handshake(bio) == 0){
    goto err;
  }
  //make sure that the certificate was valid
  if(SSL_get_verify_result(ssl) != X509_V_OK){
    goto err;
  }

  return bio;
 err:
  print_errors();
  BIO_free_all(bio);
  SSL_CTX_free(ctx);
  return NULL;
}
Example #30
-1
int
main(int argc, char *argv[])
{
	int			 i, ch, aflag, family = AF_INET;
	struct hostent		*h;
	char			*host;
	char			 addr[16];
	int			 addrlen;

	aflag = 0;
	while((ch = getopt(argc, argv, "46ae")) !=  -1) {
		switch(ch) {
		case '4':
			family = AF_INET;
			break;
		case '6':
			family = AF_INET6;
			break;
		case 'a':
			aflag = 1;
			break;
		case 'e':
			long_err += 1;
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	for(i = 0; i < argc; i++) {

		if (i)
			printf("\n");
		printf("===> \"%s\"\n", argv[i]);
		host = gethostarg(argv[i]);

		if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1)
			errx(1, "bad address");

		errno = 0;
		h_errno = 0;
		gai_errno = 0;
		rrset_errno = 0;

		if (aflag == 0)
			h = gethostbyname2(host, family);
		else
			h = gethostbyaddr(addr, addrlen, family);
		if (h)
			print_hostent(h);
		print_errors();
	}

	return (0);
}