Ejemplo n.º 1
0
/**
 * Advance past the reti (or virtual reti) according to |step|.
 * Return 0 if successful, or nonzero if an unhandled trap occurred.
 */
static int exit_syscall(struct context* ctx,
			const struct rep_trace_step* step,
			int stepi)
{
	int i, emu = step->syscall.emu;

	if (!emu) {
		int ret = cont_syscall_boundary(ctx, emu, stepi);
		if (ret) {
			return ret;
		}
	}

	for (i = 0; i < step->syscall.num_emu_args; ++i) {
		set_child_data(ctx);
	}
	if (step->syscall.emu_ret) {
		set_return_value(ctx);
	}
	validate_args(step->syscall.no, STATE_SYSCALL_EXIT, ctx);

	if (emu) {
		/* XXX verify that this can't be interrupted by a
		 * breakpoint trap */
		step_exit_syscall_emu(ctx);
	}
	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
   struct arguments args;

   /* Process arguments */
   init_args(&args);
   if (parse_args(argc, argv, &args) < 0) return -1;
   validate_args(&args);
   if (args.verbose) print_args(&args);

   switch (args.mode) {
      case CLI_MODE:
         tun_cli(&args);
         break;
      case SERV_MODE:
         tun_serv(&args);
         break;
      case FULLMESH_MODE:
         tun_peer(&args);
         break;
      default:
         break;
   }

   return 0;
}
Ejemplo n.º 3
0
static void emulate_signal_delivery()
{
	/* We are now at the exact point in the child where the signal
	 * was recorded, emulate it using the next trace line (records
	 * the state at sighandler entry). */
	struct context* ctx = rep_sched_get_thread();
	pid_t tid = ctx->child_tid;
	struct trace_frame* trace = &ctx->trace;

	/* Restore the signal-hander frame data, if there was one. */
	if (!set_child_data(ctx)) {
		/* No signal handler.  Advance execution to the point
		 * we recorded. */
		reset_hpc(ctx, 0);
		/* TODO what happens if we step on a breakpoint? */
		advance_to(ctx, ctx->trace.rbc, &trace->recorded_regs,
			   /*no signal*/0, DONT_STEPI);
		/* (|advance_to()| just asserted that the registers
		 * match what was recorded.) */
	} else {
		/* Signal handler; we just set up the callframe.
		 * Continuing execution will run that code. */
		write_child_main_registers(tid, &trace->recorded_regs);
	}
	/* Delivered the signal. */
	ctx->child_sig = 0;

	validate_args(ctx->trace.stop_reason, -1, ctx);
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
	app_args_t args;

	parse_args(args, argc, argv);
	if (!validate_args(args)) {
		return -1;
	}

	tty_handle_t handle;
	int ret = tty_open_device(&handle, args.device.c_str());
	if (TTY_ERR_OK != ret) {
		PERR("failed to open TTY device.\n");
		return -1;
	}

	tty_config_t config = {
		4800,
		TTY_DATA_8,
		TTY_PARITY_NONE,
		TTY_STOP_1,
		TTY_FLOW_NONE,
		0,
	};
	ret = tty_set_config(handle, &config);
	if (TTY_ERR_OK != ret) {
		PERR("failed to set configuration.\n");
	} else {
		do_action(handle);
	}

	tty_close_device(handle);

	return 0;
}
Ejemplo n.º 5
0
int
main (int argc, char *argv[])
{
  struct args *args = parse_args (argc, argv);

  validate_args (args);

  JBDATA *data =
    classify_components (args->num_input_files, args->input_files,
			 args->thresh, args->weight);

  /* Render output of leptonica's classifier, if requested */
  if (args->debug_render_pages)
    {
      int i;
      PIXA *pa = jbDataRender (data, 0);
      for (i = 0; i < pa->n; i++)
	{
	  PIX *pix = pa->pix[i];
	  char filename[512];
	  sprintf (filename, "rendered_%05d.png", i);
	  pixWrite (filename, pix, IFF_PNG);
	}
    }

  struct mapping *maps = NULL;
  int num_fonts = register_mappings (data, &maps);

  char *tmpdirname = NULL;

  if (!args->debug_skip_font_gen)
    {
      tmpdirname = generate_fonts (data, maps, num_fonts, args->debug_tmpdir);
    }

  generate_pdf (args->outname, tmpdirname, num_fonts, args->num_input_files,
		data, maps, args->debug_draw_borders);

  /* clean up tmpdir */

  if (!args->debug_no_clean_tmpdir)
    {
      /* This may not be Windows compatible */
      if (nftw (tmpdirname, delete_file, 64, FTW_DEPTH | FTW_PHYS) == -1)
	{
	  error_quit ("Failed to clean up tmpdir.");
	}
    }

  if (args->debug_tmpdir == NULL)
    {
      free (tmpdirname);
    }

  free (maps);
  jbDataDestroy (&data);
  free (args->input_files);
  free (args);
  return 0;
}
Ejemplo n.º 6
0
/*
 * main
 */
 int
main (int argc, char **argv) 
{
	struct event_base *event_loop = NULL;

    if (!validate_args(argc, argv)) 
    	usage();

   = parse_config_file(argv[argc - 1]);	//TODO: set return type and create a variable to catch the returning value
Ejemplo n.º 7
0
/* Handle a FILE_WRITE command. */
static void process_file_write(taper_state_t * state,
                               struct cmdargs * cmdargs) {
    dump_info_t dump_state;
    char * holding_disk_file;
    guint64 splitsize;
    char * argnames[] = {"command",               /* 0 */
			 "handle",                /* 1 */
                         "filename",              /* 2 */
                         "hostname",              /* 3 */
                         "diskname",              /* 4 */
                         "level",                 /* 5 */
                         "datestamp",             /* 6 */
                         "splitsize",             /* 7 */
                          NULL };

    validate_args(cmdargs, argnames);

    dump_state.handle = g_strdup(cmdargs->argv[1]);
    holding_disk_file = g_strdup(cmdargs->argv[2]);
    dump_state.hostname = g_strdup(cmdargs->argv[3]);
    dump_state.diskname = g_strdup(cmdargs->argv[4]);
    
    errno = 0;
    dump_state.level = strtol(cmdargs->argv[5], NULL, 10);
    if (errno != 0) {
        error("error [taper FILE-WRITE: Invalid dump level %s]",
              cmdargs->argv[5]);
        g_assert_not_reached();
    }
    
    dump_state.timestamp = strdup(cmdargs->argv[6]);

    errno = 0;
    splitsize = g_ascii_strtoull(cmdargs->argv[7], NULL, 10);
    if (errno != 0) {
        error("error [taper FILE-WRITE: Invalid splitsize %s]",
              cmdargs->argv[7]);
        g_assert_not_reached();
    }

    dump_state.id_string = g_strdup_printf("%s:%s.%d", dump_state.hostname,
                                           dump_state.diskname,
					   dump_state.level);
    
    dump_state.source = taper_source_new(dump_state.handle, FILE_WRITE,
                                         holding_disk_file, -1,
                                         NULL, splitsize, -1);
    /* FIXME: This should be handled properly. */
    g_assert(dump_state.source != NULL);

    run_device_output(state, &dump_state);

    free_dump_info(&dump_state);
    amfree(holding_disk_file);
}
Ejemplo n.º 8
0
Archivo: snmp.cpp Proyecto: asir6/Colt
int Snmp::set( Pdu &pdu, UdpTarget &target, Snmp_Result * cb)
{
  ACE_TRACE("Snmp::set");
  int rc;
  if ((rc = validate_args(pdu, target)) != 0)
     return rc;

   pdu.set_type( sNMP_PDU_SET);
   check_default_port(target);
   return run_transaction(pdu, target, cb);
}
Ejemplo n.º 9
0
/**
 * Advance to the next syscall entry (or virtual entry) according to
 * |step|.  Return 0 if successful, or nonzero if an unhandled trap
 * occurred.
 */
static int enter_syscall(struct context* ctx,
			 const struct rep_trace_step* step,
			 int stepi)
{
	int ret;
	if ((ret = cont_syscall_boundary(ctx, step->syscall.emu, stepi))) {
		return ret;
	}
	validate_args(step->syscall.no, STATE_SYSCALL_ENTRY, ctx);
	return ret;
}
Ejemplo n.º 10
0
/*
 * Main
 */
int main(int argc, char * argv[]) {
    (void)initialize();
    (void)validate_args(argc, argv);

    if (!(load(argv[1]))) {
        printf("\nLoader Test Failed\n");
        return 1; /* EXIT */
    } else {
        printf("\nLoader Test Passed\n");
        return 0;
    }
}
Ejemplo n.º 11
0
/**
 *	@brief	Parses and validates the command line options of the application.
 *
 *	@param	po::variables_map& vm The destination for parsed arguments
 *	@param	int argc The number of arguments
 *	@param	char**argv The raw arguments
 *
 *	@return	Whether the arguments are valid.
 */
bool parse_args(po::variables_map& vm, int argc, char**argv)
{
	po::options_description desc("Usage");
	desc.add_options()
		("help,h", "Displays this message.")
		("version,v", "Prints the program's version.")
		("pe", po::value<std::vector<std::string> >(), "The PE to analyze. Also accepted as a positional argument. "
			"Multiple files may be specified.")
		("recursive,r", "Scan all files in a directory (subdirectories will be ignored).")
		("output,o", po::value<std::string>(), "The output format. May be 'raw' (default) or 'json'.")
		("dump,d", po::value<std::vector<std::string> >(),
			"Dump PE information. Available choices are any combination of: "
			"all, summary, dos (dos header), pe (pe header), opt (pe optional header), sections, "
			"imports, exports, resources, version, debug, tls, config (image load configuration)")
		("hashes", "Calculate various hashes of the file (may slow down the analysis!)")
		("extract,x", po::value<std::string>(), "Extract the PE resources to the target directory.")
		("plugins,p", po::value<std::vector<std::string> >(),
			"Analyze the binary with additional plugins. (may slow down the analysis!)");


	po::positional_options_description p;
	p.add("pe", -1);

	try
	{
		po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
		po::notify(vm);
	}
	catch(po::error& e)
	{
		PRINT_ERROR << "Could not parse the command line (" << e.what() << ")." << std::endl << std::endl;
		return false;
	}

	if (vm.count("version"))
	{
		std::stringstream ss;
		ss << "Manalyze " MANALYZE_VERSION " (Ivan Kwiatkowski, GPLv3 License) compiled with:" << std::endl;
		ss << "* Boost " BOOST_LIB_VERSION " (Boost.org, Boost Software License)" << std::endl;
		ss << "* Yara " << YR_MAJOR_VERSION << "." << YR_MINOR_VERSION << "." << YR_MICRO_VERSION << ". (Victor M. Alvarez, Apache 2.0 License)" << std::endl;
		ss << "* hash-library " << HASH_LIBRARY_VERSION << " (Stephan Brumme, ZLib License)." << std::endl;
		std::cout << ss.str();
		exit(0);
	}
	else if (vm.count("help") || !vm.count("pe"))
	{
		print_help(desc, argv[0]);
		exit(0);
	}

	return validate_args(vm, desc, argv);
}
Ejemplo n.º 12
0
Archivo: snmp.cpp Proyecto: asir6/Colt
// one way, best of luck, non-confirmed alert
int Snmp::trap( Pdu &pdu, UdpTarget &target)
{
  ACE_TRACE("Snmp::trap");
  int rc;
  if ((rc = validate_args(pdu, target)) != 0)
     return rc;

  pdu.set_type( sNMP_PDU_V1TRAP);
  check_default_port(target, DEF_TRAP_PORT);

  // 2. write request to agent
  transaction trans(pdu, target, iv_snmp_session_);
  if (trans.send() > 0)  // expect number of bytes sent on
    return 0;

  last_transaction_status_ = SNMP_CLASS_INTERNAL_ERROR;
  return -1;
}
Ejemplo n.º 13
0
int main(int argc, char*argv[])
{
    // create glib loop and register a ctrl+c handler
    GMainLoop* loop = g_main_loop_new(NULL, FALSE);
    handle_control_c(loop);

    int result;
    if (validate_args(argc, argv) == false)
    {
        result = 1;
    }
    else
    {
        if(platform_init() == 0)
        {
            char *json_path = argv[1];
            GATEWAY_HANDLE gateway = Gateway_CreateFromJson(json_path);
            if(gateway == NULL)
            {
                LogError("An error ocurred while creating the gateway.");
                result = 1;
            }
            else
            {
                result = 0;
                printf("Gateway is running.\r\n");
                        
                // run the glib loop
                g_main_loop_run(loop);

                printf("Gateway is quitting\r\n");
                Gateway_Destroy(gateway);
            }
            platform_deinit();
        }
        else
        {
            LogError("Failed to initialize the platform");
            result = 1;
        }
    }
    
    return result;
}
Ejemplo n.º 14
0
/* Captures requested data from archiver and saves to file. */
int main(int argc, char **argv)
{
    char *server = getenv("FA_ARCHIVE_SERVER");
    if (server != NULL)
        server_name = server;

    output_file = stdout;
    FILE *stream;
    bool ok =
        parse_args(argc, argv)  &&
        validate_args()  &&

        connect_server(&stream)  &&
        IF_(output_filename != NULL,
            TEST_NULL_(
                output_file = fopen(output_filename, "w"),
                "Unable to open output file \"%s\"", output_filename))  &&
        request_data(stream)  &&
        check_response(stream)  &&

        initialise_signal()  &&
        capture_and_save(stream);
    return ok ? 0 : 1;
}
Ejemplo n.º 15
0
int	read_stimuli(char *filename)
{
	FILE	*id;
	int	n,i;
	int	here;
	int	inada;
	int	line=0;
	char	buf[BUF_LEN+1];
	pchar	err_msg;

	if (verbose) printf("Reading stimuli from \"%s\"...\n",filename);

	if ((id=fopen(filename,"r+")) == (FILE *) 0) {
		puts("File does not exist");
		return 0;
	}
	for (n=0;n<5;++n) {
		if (!fgets(buf,BUF_LEN,id)) 
			goto end_of_file;
		++line;
	}

	if (strlen(global_msg) != strlen(buf)) {
		err_msg=global_msg;
		goto invalid_file_format;
	}

	if (!fgets(buf,BUF_LEN,id))
		goto end_of_file;
	++line;

	if (sscanf(buf,global_str,&num_trials,&num_stimuli,&num_categories,
		&num_choices_per_category,&max_same_categories,
		&ms_btwn_stim,&ms_btwn_trials,&total_ms_on) != 8)
		goto unexpected_args;

	validate_args();
	if (!init_arrays()) {
		fclose(id);
		return 0;
	}

	for (n=0;n<2;++n) {
		if (!fgets(buf,BUF_LEN,id))
			goto end_of_file;
		++line;
	}
	if (strlen(color_msg) != strlen(buf)) {
		err_msg=color_msg;
		goto invalid_file_format;
	}
	if (!fgets(buf,BUF_LEN,id))
		goto end_of_file;
	++line;

	if (get_colors_from == COLORS_FROM_STM_FILE) {
		if (sscanf(buf,color_str,&_palette[0],&_palette[1],&_palette[2],
			&_palette[3],&_palette[4],&_palette[5],&_palette[6]) != 7)
			goto unexpected_args;
	}
	/* Else use the ones parsed in from .cfg file, if at all */

	for (n=0;n<2;++n) {
		if (!fgets(buf,BUF_LEN,id))
			goto end_of_file;
		++line;
	}
	if (strlen(stm_msg) != strlen(buf)) {
		err_msg=stm_msg;
		goto invalid_file_format;
	}

	for (n=0,here=0;n<num_trials;++n) {
		for (i=0;i<num_stimuli;++i,++here) {
			if (!fgets(buf,BUF_LEN,id))
				goto end_of_file;
			++line;
			if (sscanf(buf,stm_str,&inada,&inada,
				&_color[here],&_shape[here],
				&_num[here],&_size[here],&_filled[here],&_pattern[here],
				&_matches[here],&inada) != 10)
				goto unexpected_args;

			BOUNDED(_shape[here],0,num_choices_per_category-1);
			BOUNDED(_num[here],0,num_choices_per_category-1);
			BOUNDED(_size[here],0,num_choices_per_category-1);
			BOUNDED(_filled[here],0,num_choices_per_category-1);
			if(use_many_colors) {
				BOUNDED(_color[here],0,MAX_COLORS-1);
				BOUNDED(_pattern[here],0,MAX_PATTERNS-1);
			}
			else {
				BOUNDED(_color[here],0,num_choices_per_category-1);
				BOUNDED(_pattern[here],0,num_choices_per_category-1);
			}
			_Orig_stim[here] = item_val(here);	// for randomization purposes
		}
	}
	fclose(id);

	calc_matches();

	return 1;

unexpected_args:
	if (verbose) printf("Unexpected args on line %i\n", line);
	fclose(id);
	return 0;

end_of_file:
	puts("File ended too early");
	fclose(id);
	return 0;

invalid_file_format:
	printf("Invalid file format.  Expects as line %i:\n",line);
	puts(err_msg);
	fclose(id);
	return 0;
}
Ejemplo n.º 16
0
int	read_data(FILE *id,int line)
{
	static	init=0;
	int	n,i;
	int	here;
	int	len;
	int	inada;
	char	Lbuf[BUF_LEN+1];

	if (!init) {
		init=1;
		if (!fgets(Lbuf,BUF_LEN,id))
			goto error;
	}

	for (n=0;n<23;++n,++line) {
		switch(n) {
			case 0: strcpy(user_name,&Lbuf[6]); len=strlen(user_name); user_name[len-1]='\0'; break;
			case 1: strcpy(date_str,&Lbuf[6]); len=strlen(date_str); date_str[len-1]='\0'; break;
			case 2: strcpy(time_str,&Lbuf[6]); len=strlen(time_str); time_str[len-1]='\0'; break;
			case 3: break;
			case 4:
				if (strncmp(Lbuf,"Sex:",4)!=0) {
					n= 12;
					played_before=1;
					goto Parse_Exp_Type;
				}
				if (sscanf(Lbuf,"Sex: %i\n", &sex)!=1)
					goto error;
				played_before=0;
				break;
			case 5: if (sscanf(Lbuf,"Age: %i\n", &age)!=1) goto error; break;
			case 6: if (sscanf(Lbuf,"Years_ed: %i\n", &years_ed)!=1) goto error; break;
			case 7: break;
			case 8: break;
			case 9: if (sscanf(Lbuf,"  Family data: %i %i %i %i %i %i\n",
				&familyH[0],&familyH[1],&familyH[2],&familyH[3],&familyH[4],&familyH[5])!=6)
					goto error;
				break;
			case 10: if (sscanf(Lbuf,"  Briggs data: %i %i %i %i %i %i %i %i %i %i %i %i\n",
				&indivH[0],&indivH[1],&indivH[2],&indivH[3],&indivH[4],&indivH[5],
				&indivH[6],&indivH[7],&indivH[8],&indivH[9],&indivH[10],&indivH[11])!=12)
					goto error;
				break;
			case 11: break;
Parse_Exp_Type:
			case 12: if (sscanf(Lbuf,"Experiment Type: %s",exp_type_str)!=1) goto error; break;
			case 13: strcpy(selfeval_str,&Lbuf[11]); len=strlen(selfeval_str); selfeval_str[len-1]='\0'; break;
			case 14: break;
			case 15: break;
			case 16: if (sscanf(Lbuf,global_str,
				&num_trials, &num_stimuli, &num_categories,&num_choices_per_category,
				&max_same_categories,&ms_btwn_stim,&ms_btwn_trials,&total_ms_on) != 8)
					goto error;
				break;
			case 17: break;
			case 18: break;
			case 19: if (sscanf(Lbuf,color_str,&_palette[0],&_palette[1],&_palette[2],
				&_palette[3],&_palette[4],&_palette[5],&_palette[6]) != 7)
					goto error;
				break;
			case 20: break;
			case 21: break;	// **STIMULI**
			case 22:	if (strcmp(Lbuf,stm_msg)!=0) goto error; break;
		}
		if (!fgets(Lbuf,BUF_LEN,id))
			goto error;
	}

	validate_args();
	if (!init_arrays())
		goto error;

	/** Read STIMULI **/
	for (n=0,here=0;n<num_trials;++n) {
		for (i=0;i<num_stimuli;++i,++here) {
			++line;
			if (sscanf(Lbuf,stm_str,&inada,&inada,
				&_color[here],&_shape[here],
				&_num[here],&_size[here],&_filled[here],&_pattern[here],
				&_matches[here],&inada) != 10)
				goto error;
			if (!fgets(Lbuf,BUF_LEN,id))
				goto error;
		}
	}

	/** Read RESPONSE DATA **/
	for (n=0;n<2;++n,++line)
		if (!fgets(Lbuf,BUF_LEN,id))
			goto error;

	if (strcmp(Lbuf,dat_msg)!=0)
		goto error;

	for (n=0;n<num_trials;++n,++line) {
		if (!fgets(Lbuf,BUF_LEN,id))
			goto error;
	 	if (sscanf(Lbuf,dat_str,
			&inada,&_choice[n],
			&inada,&inada,&inada,&inada,&inada,&inada,&inada,	// item descipt
			&inada,	// item_number
			&_match_min[n],
			&_match_max[n],
			&_time[n]) != 13)
		 		goto error;
	}

	/** Read and discard previous analysis, up to start of appended file **/
	while(1) {
		if (!fgets(Lbuf,BUF_LEN,id))
			return -1;	// since end of file
		if (strncmp(Lbuf,"Name:",5)==0)
			break;
		++line;
	}
	return line;	// so can print error messages in appended file

error:
	printf("Unexpected args on line %i\n", line);
	return -1;
}
Ejemplo n.º 17
0
struct neuronet *netcreat(int nl, int *nn, int ninp)
{
    int i, nperc;
    double *w;
    struct neuronet *res;

	if (validate_args(nl, nn, ninp) != 0) {
		net_errno = NET_EINVAL;
		goto exit_failure;
	}
		
	if ((res = malloc(sizeof(struct neuronet))) == NULL) {
		net_errno = NET_ENOMEM;
		goto exit_failure;
	}
    
	res->nl = nl;
	if ((res->nn = (int *)malloc(sizeof(int) * nl)) == NULL) {
		net_errno = NET_ENOMEM;
		goto free_net;
	}
	if ((res->nw = (int *)malloc(sizeof(int) * nl)) == NULL) {
		net_errno = NET_ENOMEM;
		goto free_nn;
	}
 
	memcpy(res->nn, nn, sizeof(int) * nl);
	res->nw[0] = ninp;
	srand(time(NULL));
    	for (i = 1; i < nl; i++) 
		res->nw[i] = res->nn[i - 1];

	res->total_nw = 0;
	nperc = ninp;
	for (i = 0; i < nl; i++) {
		res->total_nw += nn[i] * nperc;
		nperc = nn[i];
	}
	res->total_nn = 0;
	for (i = 0; i < nl; i++)
		res->total_nn += nn[i];	
	
	if((w = (double *)malloc(sizeof(double) * res->total_nw)) == NULL) {
		net_errno = NET_ENOMEM;
		goto free_nw;
	}
	res->g = (double *)malloc(sizeof(double) * res->total_nw);
	for (i = 0; i < res->total_nw; i++)
		*w++ = (double)rand()/(double)RAND_MAX * 2.0 - 1.0;

	res->w = w - res->total_nw;
	
	return res;

free_nw:
	free(res->nw);
free_nn:
	free(res->nn);
free_net:
	free(res);
exit_failure:
	return NULL;
}
Ejemplo n.º 18
0
/* Handle a PORT_WRITE command. */
static void process_port_write(taper_state_t * state,
                               struct cmdargs * cmdargs) {
    dump_info_t dump_state;
    guint64 splitsize;
    guint64 fallback_splitsize;
    char * split_diskbuffer;
    char * argnames[] = {"command",               /* 0 */
			 "handle",                /* 1 */
                         "hostname",              /* 2 */
                         "diskname",              /* 3 */
                         "level",                 /* 4 */
                         "datestamp",             /* 5 */
                         "splitsize",             /* 6 */
                         "split_diskbuffer",      /* 7 */
                         "fallback_splitsize",    /* 8 */
                          NULL };

    validate_args(cmdargs, argnames);

    dump_state.handle = g_strdup(cmdargs->argv[1]);
    dump_state.hostname = g_strdup(cmdargs->argv[2]);
    dump_state.diskname = g_strdup(cmdargs->argv[3]);
    
    errno = 0;
    dump_state.level = strtol(cmdargs->argv[4], NULL, 10);
    if (errno != 0) {
        error("error [taper PORT-WRITE: Invalid dump level %s]",
              cmdargs->argv[4]);
        g_assert_not_reached();
    }
    
    dump_state.timestamp = strdup(cmdargs->argv[5]);

    errno = 0;
    splitsize = g_ascii_strtoull(cmdargs->argv[6], NULL, 10);
    if (errno != 0) {
        error("error [taper PORT-WRITE: Invalid splitsize %s]",
              cmdargs->argv[6]);
        g_assert_not_reached();
    }
    
    if (strcmp(cmdargs->argv[7], "NULL") == 0) {
        split_diskbuffer = NULL;
    } else {
        split_diskbuffer = g_strdup(cmdargs->argv[7]);
    }
    
    errno = 0;
    fallback_splitsize = g_ascii_strtoull(cmdargs->argv[8], NULL, 10);
    if (errno != 0) {
        error("error [taper PORT-WRITE: Invalid fallback_splitsize %s]",
              cmdargs->argv[8]);
        g_assert_not_reached();
    }

    dump_state.id_string = g_strdup_printf("%s:%s.%d", dump_state.hostname,
                                           dump_state.diskname,
					   dump_state.level);
    
    if (!open_read_socket(&dump_state, split_diskbuffer, splitsize,
                          fallback_splitsize)) {
        free(split_diskbuffer);
        return;
    }
    free(split_diskbuffer);

    run_device_output(state, &dump_state);

    free_dump_info(&dump_state);
}
Ejemplo n.º 19
0
int main(int argc, char **argv)
{
	char temp1[100], temp2[100];
	char *url= NULL, * remotehost=NULL, * user=NULL, * password=NULL, * database=NULL, * dbpassword=NULL;
	char default_remotehost[]="127.0.0.1";
	char default_user[]="_SYSTEM";
	char default_password[]="";
	char default_database[]="";
	char default_dbpassword[]="";
	int port, itarget, sh;
	char c;		
	logo();
	if(argc<2)
	{
		usage(argv[0]);		
		return -1;
	}
	// set defaults		
	port=-1;
	itarget=0;
	sh=0;
	// ------------		
	while((c = getopt(argc, argv, "h:p:s:t:u:P:d:D:x:"))!= EOF)
	{
		switch (c)
		{
			case 'h':
				remotehost=optarg;
				break; 	
			case 's':
				sscanf(optarg, "%d", &sh);
				sh--;
				break;
			case 't':
				sscanf(optarg, "%d", &itarget);
				itarget--;
				break;
			case 'p':
				sscanf(optarg, "%d", &port);
				break;		
			case 'u':
				user=optarg;
				break; 
			case 'P':
				password=optarg;
				break; 
			case 'd':
				database=optarg;
				break; 
			case 'x':
				url=optarg;
				break;
			default:
	            usage(argv[0]);
			return -1;
		}		
	}
	if(validate_args( port, sh, itarget)==-1) return -1;
	if(remotehost == NULL) remotehost=default_remotehost;
	if(user       == NULL) user=default_user;
	if(password   == NULL) password=default_password;
	if(dbpassword == NULL) dbpassword=default_dbpassword;
	if(database   == NULL) database=default_database;
	if(url        == NULL) url="";
	memset(temp1,0,sizeof(temp1));
	memset(temp2,0,sizeof(temp2));
	memset(temp1, '\x20' , 58 - strlen(remotehost) -1);	
	printf(" #  Host    : %s%s# \n", remotehost, temp1);	
	if(port!=-1)
	{
		sprintf(temp2, "%d", port);
		memset(temp1,0,sizeof(temp1));
		memset(temp1, '\x20' , 58 - strlen(temp2) -1);
		printf(" #  Port    : %s%s# \n", temp2, temp1);
	}else
	{
		sprintf(temp2, "%s", database);
		memset(temp1,0,sizeof(temp1));
		memset(temp1, '\x20' , 58 - strlen(temp2) -1);
		printf(" #  Database: %s%s# \n", temp2, temp1);
	}
	sprintf(temp2, "%s", user);
	memset(temp1,0,sizeof(temp1));
	memset(temp1, '\x20' , 58 - strlen(temp2) -1);
	printf(" #  User    : %s%s# \n", temp2, temp1);
	memset(temp1,0,sizeof(temp1));	
	memset(temp2,0,sizeof(temp2));
	sprintf(temp2, "%s", shellcodes[sh].name );
	memset(temp1, '\x20' , 58 - strlen(temp2) -1);	
	printf(" #  Shellcde: %s%s# \n", temp2, temp1);	
	if(sh==1)
	{
		memset(temp1,0,sizeof(temp1));	
		memset(temp2,0,sizeof(temp2));
		sprintf(temp2, "%s", url );
		memset(temp1, '\x20' , 58 - strlen(temp2) -1);	
		printf(" #  URL     : %s%s# \n", temp2, temp1);	
	}
	memset(temp1,0,sizeof(temp1));	
	memset(temp1, '\x20' , 58 - strlen(targets[itarget].t) -1);	
	printf(" #  Target  : %s%s# \n", targets[itarget].t, temp1);	
	printf(" # ------------------------------------------------------------------- # \n");
	fflush(stdout);
	
	char buf[20000];
	memset(buf,0,sizeof(buf));
	printf("[+] Constructing attacking buffer... ");
	fflush(stdout);
	make_buffer((char *)buf,itarget,sh, url);
	printf("done\n");

	if(send_buffer(remotehost,port, user, password, dbpassword, database, buf)==-1)
	{
		fprintf(stdout, "[-] Cannot exploit server %s\n", remotehost);		
		return -1;
	}
	return 0;
}
Ejemplo n.º 20
0
/*
 * transform_replica -- transforming one poolset into another
 */
int
replica_transform(struct pool_set *set_in, struct pool_set *set_out,
		unsigned flags)
{
	LOG(3, "set_in %p, set_out %p", set_in, set_out);

	int ret = 0;
	/* validate user arguments */
	if (validate_args(set_in, set_out))
		return -1;

	/* check if the source poolset is healthy */
	struct poolset_health_status *set_in_hs = NULL;
	if (replica_check_poolset_health(set_in, &set_in_hs, flags)) {
		ERR("source poolset health check failed");
		return -1;
	}

	if (!replica_is_poolset_healthy(set_in_hs)) {
		ERR("source poolset is broken");
		ret = -1;
		errno = EINVAL;
		goto free_hs_in;
	}

	struct poolset_health_status *set_out_hs = NULL;
	if (replica_create_poolset_health_status(set_out, &set_out_hs)) {
		ERR("creating poolset health status failed");
		ret = -1;
		goto free_hs_in;
	}

	/* check if the poolsets are transformable */
	struct poolset_compare_status *set_in_cs = NULL;
	struct poolset_compare_status *set_out_cs = NULL;
	if (compare_poolsets(set_in, set_out, &set_in_cs, &set_out_cs)) {
		ERR("comparing poolsets failed");
		ret = -1;
		goto free_hs_out;
	}

	enum transform_op operation = identify_transform_operation(set_in_cs,
			set_out_cs, set_in_hs, set_out_hs);

	if (operation == NOT_TRANSFORMABLE) {
		LOG(1, "poolsets are not transformable");
		ret = -1;
		errno = EINVAL;
		goto free_cs;
	}

	if (operation == RM_HDRS) {
		if (!is_dry_run(flags) &&
				remove_hdrs(set_in, set_out, set_in_hs,
						flags)) {
			ERR("removing headers failed; falling back to the "
					"input poolset");
			if (replica_sync(set_in, set_in_hs,
					flags | IS_TRANSFORMED)) {
				LOG(1, "falling back to the input poolset "
						"failed");
			} else {
				LOG(1, "falling back to the input poolset "
						"succeeded");
			}
			ret = -1;
		}
		goto free_cs;
	}

	if (operation == ADD_HDRS) {
		if (!is_dry_run(flags) &&
				add_hdrs(set_in, set_out, set_in_hs, flags)) {
			ERR("adding headers failed; falling back to the "
					"input poolset");
			if (replica_sync(set_in, set_in_hs,
					flags | IS_TRANSFORMED)) {
				LOG(1, "falling back to the input poolset "
						"failed");
			} else {
				LOG(1, "falling back to the input poolset "
						"succeeded");
			}
			ret = -1;
		}
		goto free_cs;
	}

	if (operation == ADD_REPLICAS) {
		/*
		 * check if any of the parts that are to be added already exists
		 */
		if (do_added_parts_exist(set_out, set_out_hs)) {
			ERR("some parts being added already exist");
			ret = -1;
			errno = EINVAL;
			goto free_cs;
		}
	}

	/* signal that sync is called by transform */
	if (replica_sync(set_out, set_out_hs, flags | IS_TRANSFORMED)) {
		ret = -1;
		goto free_cs;
	}

	if (operation == RM_REPLICAS) {
		if (!is_dry_run(flags) && delete_replicas(set_in, set_in_cs))
			ret = -1;
	}

free_cs:
	Free(set_in_cs);
	Free(set_out_cs);
free_hs_out:
	replica_free_poolset_health_status(set_out_hs);
free_hs_in:
	replica_free_poolset_health_status(set_in_hs);
	return ret;
}
Ejemplo n.º 21
0
struct passed_args *parse_passed_arguments (int argc, char* argv[]) {
/*
    The main function for parsing the arguments passed to the program 
*/
    struct passed_args *args = malloc(sizeof(struct passed_args));
    assert(NULL != args);

    args->help_flag = 0;
    args->verbose_flag = 0;
    args->set_index_bits_num = 0;
    args->associativity_num = 0;
    args->block_bits_num = 0;
    args->trace_file = NULL;
    
    int c;  // getopt_long stores parsed short options here
    const char *short_opts = "hvs:E:b:t:";
    static int help_flag;
    opterr = 0;  // disable printing error messages by getopt_long 
    while (1) {
        static struct option long_options[] = 
            {
                {"help", no_argument, &help_flag, 1},
                {0, 0, 0, 0}
            };

        int option_index = 0;
        c = getopt_long(argc, argv, 
                            short_opts, long_options, &option_index);
        
        /* Detect the end of the options */
        if (-1 == c) {
            break;
        }
        
        switch (c) {
            /* Case for long options */
            case 0:
                break;
            
            case 'h':
                args->help_flag = 1;
                break;
            
            case 'v':
                args->verbose_flag = 1;
                break;
            
            case 's':
            case 'E':
            case 'b':
                if (NULL == optarg) no_argument_passed(c);
                store_char_param (c, optarg, args);
                break;

            case 't':
                if (NULL == optarg) no_argument_passed (c);
                store_string_param (c, optarg, args);
                break;

            case '?':
            default:
                bad_argument_passed();
                break;
        }
    }
    if (help_flag) {
        args->help_flag = 1;
    }
    
    validate_args(args);

    return args;
}
Ejemplo n.º 22
0
/*
 * sync_replica -- synchronize data across replicas within a poolset
 */
int
replica_sync(struct pool_set *set, struct poolset_health_status *s_hs,
		unsigned flags)
{
	LOG(3, "set %p, flags %u", set, flags);
	int ret = 0;
	struct poolset_health_status *set_hs = NULL;

	/* check if we already know the poolset health status */
	if (s_hs == NULL) {
		/* validate poolset before checking its health */
		if (validate_args(set))
			return -1;

		/* examine poolset's health */
		if (replica_check_poolset_health(set, &set_hs, flags)) {
			ERR("poolset health check failed");
			return -1;
		}

		/* check if poolset is broken; if not, nothing to do */
		if (replica_is_poolset_healthy(set_hs)) {
			LOG(1, "Poolset is healthy");
			goto out;
		}
	} else {
		set_hs = s_hs;
	}

	/* find one good replica; it will be the source of data */
	unsigned healthy_replica = replica_find_healthy_replica(set_hs);
	if (healthy_replica == UNDEF_REPLICA) {
		ERR("no healthy replica found");
		ret = -1;
		goto out;
	}

	/* in dry-run mode we can stop here */
	if (is_dry_run(flags)) {
		LOG(1, "Sync in dry-run mode finished successfully");
		goto out;
	}

	/* recreate broken parts */
	if (recreate_broken_parts(set, set_hs, flags)) {
		ERR("recreating broken parts failed");
		ret = -1;
		goto out;
	}

	/* open all part files */
	if (replica_open_poolset_part_files(set)) {
		ERR("opening poolset part files failed");
		ret = -1;
		goto out;
	}

	/* map all replicas */
	if (util_poolset_open(set)) {
		ERR("opening poolset failed");
		ret = -1;
		goto out;
	}

	/* this is required for opening remote pools */
	set->poolsize = set_hs->replica[healthy_replica]->pool_size;

	/* open all remote replicas */
	if (open_remote_replicas(set, set_hs)) {
		ERR("opening remote replicas failed");
		ret = -1;
		goto out;
	}

	/* update uuid fields in the set structure with part headers */
	if (fill_struct_uuids(set, healthy_replica, set_hs, flags)) {
		ERR("gathering uuids failed");
		ret = -1;
		goto out;
	}

	/* create headers for broken parts */
	if (!is_dry_run(flags)) {
		if (create_headers_for_broken_parts(set, healthy_replica,
				set_hs)) {
			ERR("creating headers for broken parts failed");
			ret = -1;
			goto out;
		}
	}

	if (is_dry_run(flags))
		goto out;

	/* create all remote replicas */
	if (create_remote_replicas(set, set_hs, flags)) {
		ERR("creating remote replicas failed");
		ret = -1;
		goto out;
	}

	/* check and copy data if possible */
	if (copy_data_to_broken_parts(set, healthy_replica,
			flags, set_hs)) {
		ERR("copying data to broken parts failed");
		ret = -1;
		goto out;
	}

	/* update uuids of replicas and parts */
	if (update_uuids(set, set_hs)) {
		ERR("updating uuids failed");
		ret = -1;
		goto out;
	}

	/* grant permissions to all created parts */
	if (grant_created_parts_perm(set, healthy_replica, set_hs)) {
		ERR("granting permissions to created parts failed");
		ret = -1;
	}

out:
	if (s_hs == NULL)
		replica_free_poolset_health_status(set_hs);
	return ret;
}
Ejemplo n.º 23
0
Archivo: main.c Proyecto: whs1787/ffs
int main(int argc, char *argv[])
{
	static const struct option long_opts[] = {
		/* commands */
		{"inject", required_argument, NULL, c_INJECT},
		{"remove", required_argument, NULL, c_REMOVE},
		{"hexdump", required_argument, NULL, c_HEXDUMP},
		/* options */
		{"output", required_argument, NULL, o_OUTPUT},
		/* flags */
		{"force", no_argument, NULL, f_FORCE},
		{"p8", no_argument, NULL, f_P8},
		{"verbose", no_argument, NULL, f_VERBOSE},
		{"help", no_argument, NULL, f_HELP},
		{0, 0, 0, 0}
	};

	static const char *short_opts = "I:R:H:o:fpvh";

	int rc = EXIT_FAILURE;

	if (argc == 1)
		usage(args.short_name, false), exit(rc);

	int opt = 0, idx = 0;
	while ((opt = getopt_long(argc, argv, short_opts, long_opts,
				  &idx)) != -1)
		if (process_argument(&args, opt, optarg) < 0)
			goto error;

	/* getopt_long doesn't know what to do with orphans, */
	/* so we'll scoop them up here, and deal with them later */

	while (optind < argc)
		if (process_option(&args, argv[optind++]) < 0)
			goto error;

	if (args.verbose == f_VERBOSE)
		args_dump(&args);

	if (validate_args(&args) < 0)
		goto error;
	if (process_args(&args) < 0)
		goto error;

	rc = EXIT_SUCCESS;

	if (false) {
		err_t *err;
error:
		err = err_get();
		assert(err != NULL);

		fprintf(stderr, "%s: %s : %s(%d) : (code=%d) %.*s\n",
			program_invocation_short_name,
			err_type_name(err), err_file(err), err_line(err),
			err_code(err), err_size(err), (char *)err_data(err));
	}

	return rc;
}