//Calculate exact position
static void netfpga_set_hw_position_exact(netfpga_device_t* nfpga, netfpga_flow_entry_t* hw_entry){
	
	uint32_t hash;
	uint32_t pos; 
	struct crc32 crc;

	crc32_init(&crc, NETFPGA_POLYNOMIAL1);
	hash = crc32_calculate(&crc, hw_entry->matches, sizeof(*hw_entry->matches));

	//Calculate the index based on the hash.  The last bits of hash is the index in the table
	pos = (NETFPGA_OPENFLOW_EXACT_TABLE_SIZE-1) & hash;

	if (nfpga->hw_exact_table[pos] == NULL) {
		hw_entry->hw_pos = pos;
		nfpga->hw_exact_table[pos] = hw_entry;
		return;
	}

	//Use fallback polynomial
	crc32_init(&crc, NETFPGA_POLYNOMIAL2);
	hash = crc32_calculate(&crc, hw_entry->matches, sizeof(*hw_entry->matches));
	
	// the bottom fixed bits of hash == the index into the table
	pos = (NETFPGA_OPENFLOW_EXACT_TABLE_SIZE-1) & hash;

	//Check existing entry
	if (nfpga->hw_exact_table[pos] != NULL) {
		//FIXME: if is the same, the previous entry should be removed... Which is the collision probability?
	}
	
	hw_entry->hw_pos = pos;
	nfpga->hw_exact_table[pos] = hw_entry;
	ROFL_DEBUG("HW position is %d \n", pos);
}
Beispiel #2
0
//! @brief Calculate crc on a range of flash, specified in the bootloader configuration area.
static uint32_t calculate_application_crc32(bootloader_configuration_data_t * config)
{
    uint32_t crc32;

    // Initialize the CRC32 information
    crc32_data_t crcInfo;
    crc32_init(&crcInfo);

    // Run CRC, Considering skip crcExpectedValue address
    uint32_t bypassStartAddress = kBootloaderConfigAreaAddress + ((uint32_t)&config->crcExpectedValue - (uint32_t)&config->tag);
    uint32_t bypassEndAddress = bypassStartAddress + sizeof(config->crcExpectedValue);

    if ((config->crcStartAddress >= bypassEndAddress) || (config->crcStartAddress + config->crcByteCount <= bypassStartAddress))
    {
        crc32_update(&crcInfo, (uint8_t *)config->crcStartAddress, config->crcByteCount);
    }
    else
    {
        // Assume that crcExpectedValue address (4 byte) resides in crc addresses completely
        crc32_update(&crcInfo, (uint8_t *)config->crcStartAddress, bypassStartAddress - config->crcStartAddress);
        crc32_update(&crcInfo, (uint8_t *)bypassEndAddress, config->crcStartAddress + config->crcByteCount - bypassEndAddress);
    }

    // Finalize the CRC calculations
    crc32_finalize(&crcInfo, &crc32);

    return crc32;
}
Beispiel #3
0
/* One start -----------------------------------------------------------------*/
static void startup()
{
    unsigned char err = 0;

    init_hardware();
    dbg_init();
    dbg_print_app_ver();
    crc32_init();
    pins_init();
    //spi0_init();    // used in m25pexx.c (FLASH)
    spi1_init();
    adc_init();
    err = memory_init();  // memory initialization, external EEPROM (used in pref.c, orion.c), external FLASH, internal FLASH
    if (err)
       goto err;
    pref_init();
    ds1390_init();
    evt_fifo_init();
    GPS_init();
    //SIM900_init();
    light_init();
    saveDatePorojectIP();//новые параметры связи
    vpu_init();  /*VPU start*/
    //Init_USB();
    //if (PROJ.jornal.power_on)
   //Event_Push_Str("СТАРТ");
    return;
err:
  Err_led(err);
}
Beispiel #4
0
static void
instance_init(
    XferElement *elt)
{
    make_crc_table();
    crc32_init(&elt->crc);
}
Beispiel #5
0
static void
instance_init(
    XferElement *elt)
{
    elt->can_generate_eof = TRUE;
    crc32_init(&elt->crc);
}
Beispiel #6
0
static int
test_size(
    size_t size)
{
    crc_t crc1;
    crc_t crc16;
#if defined __GNUC__ && GCC_VERSION > 40300 && (defined __x86_64__ || defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__)
    crc_t crchw;
#endif

    crc32_init(&crc1);
    crc32_init(&crc16);
#if defined __GNUC__ && GCC_VERSION > 40300 && (defined __x86_64__ || defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__)
    crc32_init(&crchw);
#endif

    crc32_add_1byte(test_buf, size, &crc1);
    crc32_add_16bytes(test_buf, size, &crc16);
#if defined __GNUC__ && GCC_VERSION > 40300 && (defined __x86_64__ || defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__)
    if (have_sse42) {
	crc32c_add_hw(test_buf, size, &crchw);
    }
#endif

#if defined __GNUC__ && GCC_VERSION > 40300 && (defined __x86_64__ || defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__)
    g_fprintf(stderr, " %08x:%lld  %08x:%lld  %08x:%lld\n", crc32_finish(&crc1), (long long)crc1.size, crc32_finish(&crc16), (long long)crc16.size, crc32_finish(&crchw), (long long)crchw.size);
#else
    g_fprintf(stderr, " %08x:%lld  %08x:%lld\n", crc32_finish(&crc1), (long long)crc1.size, crc32_finish(&crc16), (long long)crc16.size);
#endif

    if (crc1.crc != crc16.crc ||
	crc1.size != crc16.size) {
	g_fprintf(stderr, " CRC16 %zu %08x:%lld != %08x:%lld\n", size, crc32_finish(&crc1), (long long)crc1.size, crc32_finish(&crc16), (long long)crc16.size);
	return FALSE;
    }
#if defined __GNUC__ && GCC_VERSION > 40300 && (defined __x86_64__ || defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__)
    if (have_sse42) {
	if (crc1.crc != crchw.crc ||
	    crc1.size != crchw.size) {
	    g_fprintf(stderr, " CRChw %zu %08x:%lld != %08x:%lld\n", size, crc32_finish(&crc1), (long long)crc1.size, crc32_finish(&crchw), (long long)crchw.size);
	    return FALSE;
	}
    }
#endif
    return TRUE;
}
Beispiel #7
0
bool cpld_xc2c64a_jtag_checksum(
	const jtag_t* const jtag,
	const cpld_xc2c64a_verify_t* const verify,
	uint32_t* const crc_value
) {
	cpld_xc2c_jtag_reset_and_idle(jtag);

	if( cpld_xc2c64a_jtag_idcode_ok(jtag) && cpld_xc2c_jtag_read_write_protect(jtag) &&
		cpld_xc2c64a_jtag_idcode_ok(jtag) && cpld_xc2c_jtag_read_write_protect(jtag) ) {
		
		cpld_xc2c_jtag_bypass(jtag, false);

		cpld_xc2c_jtag_enable(jtag);
		cpld_xc2c_jtag_enable(jtag);
		cpld_xc2c_jtag_enable(jtag);

		cpld_xc2c_jtag_read(jtag);

		crc32_t crc;
		crc32_init(&crc);

		uint8_t dr[CPLD_XC2C64A_BYTES_IN_ROW];
		for(size_t row=0; row<CPLD_XC2C64A_ROWS; row++) {
			const size_t address = cpld_hackrf_row_addresses.address[row];
			cpld_xc2c64a_jtag_read_row(jtag, address, dr);

			const size_t mask_index = verify->mask_index[row];
			for(size_t i=0; i<CPLD_XC2C64A_BYTES_IN_ROW; i++) {
				dr[i] &= verify->mask[mask_index].value[i];
			}

			/* Important checksum calculation NOTE:
			 * Do checksum of all bits in row bytes, but ensure that invalid bits
			 * are set to zero by masking. This subtlety just wasted several hours
			 * of my life...
			 */
			crc32_update(&crc, dr, CPLD_XC2C64A_BYTES_IN_ROW);
		}

		*crc_value = crc32_digest(&crc);

		cpld_xc2c_jtag_init_special(jtag);
		cpld_xc2c_jtag_conld(jtag);

		if( cpld_xc2c64a_jtag_idcode_ok(jtag) && cpld_xc2c_jtag_is_done(jtag) ) {
			cpld_xc2c_jtag_conld(jtag);
			cpld_xc2c_jtag_bypass(jtag, false);
			cpld_xc2c_jtag_bypass(jtag, true);

			return true;
		}
	}

	cpld_xc2c_jtag_reset_and_idle(jtag);

	return false;
}
int main(int argc, char ** argv){
	if(argc != 2){
		return 1;
	}
	char * str = argv[1];
	uint8_t crc_val[4];
	{
		// generating CRC
		struct CRC32 crc;
		crc32_init(&crc, GENPOLY);
		uint8_t * p;
		for(p = str; *p; p += 1){
			crc32_update(&crc, *p);
		}
		crc32_finalize(&crc);
		uint8_t i;
		for(i=0;i<4;i+=1){
			crc_val[i] = crc32_get_reversed(&crc, i);
		}
	}
	int _return;
	{
		// checking crc
		struct CRC32 crc;
		crc32_init(&crc, GENPOLY);
		uint8_t * p;
		for(p = str; *p; p += 1){
			crc32_update(&crc, *p);
		}
		uint8_t i;
		for(i=0;i<4;i+=1){
			crc32_update(&crc, crc_val[i]);
		}
		if(crc32_check_zero(&crc)){
			fprintf(stderr, "success!\n");
			_return = 0;
		}else{
			fprintf(stderr, "fail =(\n");
			_return = 1;
		}
	}
	return _return;
}
Beispiel #9
0
static void
read_and_push(
    XferElementGlue *self)
{
    XferElement *elt = XFER_ELEMENT(self);
    int fd = get_read_fd(self);
    XMsg *msg;

    crc32_init(&elt->crc);

    while (!elt->cancelled) {
	char *buf = g_malloc(GLUE_BUFFER_SIZE);
	gsize len;
	int read_error;

	/* read a buffer from upstream */
	len = read_fully(fd, buf, GLUE_BUFFER_SIZE, &read_error);
	if (len < GLUE_BUFFER_SIZE) {
	    if (read_error) {
		if (!elt->cancelled) {
		    xfer_cancel_with_error(elt,
			_("Error reading from fd %d: %s"), fd, strerror(read_error));
		    g_debug("element-glue: error reading from fd %d: %s",
                         fd, strerror(read_error));
		    wait_until_xfer_cancelled(elt->xfer);
		}
                amfree(buf);
		break;
	    } else if (len == 0) { /* we only count a zero-length read as EOF */
		amfree(buf);
		break;
	    }
	}
	crc32_add((uint8_t *)buf, len, &elt->crc);

	xfer_element_push_buffer(elt->downstream, buf, len);
    }

    if (elt->cancelled && elt->expect_eof)
	xfer_element_drain_fd(fd);

    /* send an EOF indication downstream */
    xfer_element_push_buffer(elt->downstream, NULL, 0);

    /* close the read fd, since it's at EOF */
    close_read_fd(self);

    g_debug("sending XMSG_CRC message");
    g_debug("read_and_push CRC: %08x      size %lld",
	    crc32_finish(&elt->crc), (long long)elt->crc.size);
    msg = xmsg_new(elt->upstream, XMSG_CRC, 0);
    msg->crc = crc32_finish(&elt->crc);
    msg->size = elt->crc.size;
    xfer_queue_message(elt->xfer, msg);
}
Beispiel #10
0
static void
instance_init(
    XferElement *elt)
{
    XferSourceRecovery *self = XFER_SOURCE_RECOVERY(elt);

    self->paused = TRUE;
    self->start_part_cond = g_cond_new();
    self->abort_cond = g_cond_new();
    self->start_part_mutex = g_mutex_new();
    crc32_init(&elt->crc);
}
Beispiel #11
0
static void
instance_init(
    XferElementGlue *self)
{
    XferElement *elt = (XferElement *)self;
    elt->can_generate_eof = TRUE;
    self->pipe[0] = self->pipe[1] = -1;
    self->input_listen_socket = -1;
    self->output_listen_socket = -1;
    self->input_data_socket = -1;
    self->output_data_socket = -1;
    self->read_fd = -1;
    self->write_fd = -1;
    crc32_init(&elt->crc);
}
Beispiel #12
0
/*
 * Generate ID for FIDO messages without ^AMSGID, using date and CRC over
 * From, To and Subject.
 */
char *s_msgid_default(Message *msg)
{
    /*
     * Compute CRC for strings from, to, subject
     */
    crc32_init();
    crc32_compute(msg->name_from, strlen(msg->name_from));
    crc32_compute(msg->name_to  , strlen(msg->name_to  ));
    crc32_compute(msg->subject  , strlen(msg->subject  ));

    return s_printf("<NOMSGID_%d=3A%d=2F%d.%d_%s_%08lx@%s>",
		    msg->node_orig.zone, msg->node_orig.net,
		    msg->node_orig.node, msg->node_orig.point,
		    date("%y%m%d_%H%M%S", &msg->date), crc32_value(),
		    msgid_domain(msg->node_orig.zone));
}
Beispiel #13
0
/* create an element of this class; prototype is in xfer-element.h */
XferElement *
xfer_dest_null(
    guint32 prng_seed)
{
    XferDestNull *self = (XferDestNull *)g_object_new(XFER_DEST_NULL_TYPE, NULL);
    XferElement *elt = XFER_ELEMENT(self);

    if (prng_seed) {
	self->do_verify = TRUE;
	simpleprng_seed(&self->prng, prng_seed);
    } else {
	self->do_verify = FALSE;
    }
    crc32_init(&elt->crc);

    return elt;
}
Beispiel #14
0
void smi_init() {
	smram_state_t smram;
	pci_driver_t **driver;
	
	smram = smram_save_state();
	smram_tseg_set_state(SMRAM_TSEG_OPEN);

	outputf("NetWatch running");

	/* Turn on the SMIs we want */
	smi_disable();
	
	eth_init();
	
	crc32_init();
	
	/* After everything is initialized, load drivers. */
	for (driver = drivers; *driver; driver++)
	{
		outputf("Probing driver: %s", (*driver)->name);
		if (pci_probe_driver(*driver))
			output("Found a card");
	}
	outputf("Driver probe complete");
	
	/* Load in fonts. */
	text_init();

	smi_register_handler(SMI_EVENT_FAST_TIMER, timer_handler);
	smi_enable_event(SMI_EVENT_FAST_TIMER);

	smi_register_handler(SMI_EVENT_DEVTRAP_KBC, kbc_handler);
	smi_enable_event(SMI_EVENT_DEVTRAP_KBC);
	
	smi_register_handler(SMI_EVENT_GBL_RLS, gbl_rls_handler);
	smi_enable_event(SMI_EVENT_GBL_RLS);

	smi_enable();
	
	vga_flush_imm(1);
	
	smram_restore_state(smram);
}
Beispiel #15
0
static void simulate_rx_msg(int port, uint16_t header, int cnt,
			    const uint32_t *data)
{
	int i;

	pd_test_rx_set_preamble(port, 1);
	pd_test_rx_msg_append_sop(port);
	pd_test_rx_msg_append_short(port, header);

	crc32_init();
	crc32_hash16(header);
	for (i = 0; i < cnt; ++i) {
		pd_test_rx_msg_append_word(port, data[i]);
		crc32_hash32(data[i]);
	}
	pd_test_rx_msg_append_word(port, crc32_result());

	pd_test_rx_msg_append_eop(port);
	pd_test_rx_msg_append_last_edge(port);

	pd_simulate_rx(port);
}
Beispiel #16
0
/* mode    = 0/1/2  0=init, 1=update, 2=finalize */
uint32_t update_crc_ne(uint32_t old_crc, int crclen, void *data, int datasiz, int datalen, int mode)
{
  uint32_t seed=old_crc;
  uint32_t new_crc;
  crc16_t crc16;
  crc24_t crc24;
  crc32_t crc32;
  unsigned int mask=0 ;
  int data_len=datasiz*datalen ;
  
  new_crc = seed ;
    
  if( (*little_endian) & (datasiz>1)){  /* multibyte tokens on little endian machine */
    mask = datasiz-1 ; /* 0/1/3/7 magic mask to get stitching order count on little endian machines */
  }
  if (crclen==16) {
    crc16 = seed & 0xFFFF ;
    if(mode==0) crc16 = crc16_init() ;
    crc16 = crc16_update_le(crc16, (const unsigned char *) data, data_len, mask) ;
    if(mode==2) crc16 = crc16_finalize(crc16) ;
    new_crc = crc16 ;
  } else if (crclen==24) {
    crc24 = seed & 0xFFFFFF ;
    if(mode==0) crc24 = crc24_init() ;
    crc24 = crc24_update_le(crc24, (const unsigned char *) data, data_len, mask) ;
    if(mode==2) crc24 = crc24_finalize(crc24) ;
    new_crc = crc24 ;
  } else if (crclen==32) {
    crc32 = seed & 0xFFFFFFFF ;
    if(mode==0) crc32 = crc32_init() ;
    crc32 = crc32_update_le(crc32, (const unsigned char *) data, data_len, mask) ;
    if(mode==2) crc32 = crc32_finalize(crc32) ;
    new_crc = crc32 ;
  } else {
    new_crc = seed ;
  }
  return new_crc;
}
Beispiel #17
0
int crc32_test(void)
{
#ifndef LTC_TEST
   return CRYPT_NOP;
#else
   const void* in = "libtomcrypt";
   const unsigned char crc32[] = { 0xef, 0x76, 0x73, 0xb3 };
   unsigned char out[4];
   crc32_state ctx;
   crc32_init(&ctx);
   crc32_update(&ctx, in, strlen(in));
   crc32_finish(&ctx, out, 4);
   if (XMEMCMP(crc32, out, 4)) {
#ifdef LTC_TEST_DBG
      ulong32 _out, _crc32;
      LOAD32H(_out, out);
      LOAD32H(_crc32, crc32);
      printf("crc32 fail! Is: 0x%x Should: 0x%x\n", _out, _crc32);
#endif
      return CRYPT_FAIL_TESTVECTOR;
   }
   return CRYPT_OK;
#endif
}
Beispiel #18
0
static void
instance_init(
    XferElement *elt)
{
    XferDestHolding *self = XFER_DEST_HOLDING(elt);
    elt->can_generate_eof = FALSE;

    self->state_mutex = g_mutex_new();
    self->state_cond = g_cond_new();
    self->ring_mutex = g_mutex_new();
    self->ring_add_cond = g_cond_new();
    self->ring_free_cond = g_cond_new();

    self->fd = -1;
    self->use_bytes = 0;
    self->paused = TRUE;
    self->chunk_header = NULL;
    self->filename = NULL;
    self->first_filename = NULL;
    self->new_filename = NULL;
    self->data_bytes_written = 0;
    self->header_bytes_written = 0;
    crc32_init(&elt->crc);
}
Beispiel #19
0
static void
read_and_write(XferElementGlue *self)
{
    XferElement *elt = XFER_ELEMENT(self);
    /* dynamically allocate a buffer, in case this thread has
     * a limited amount of stack allocated */
    char *buf = g_malloc(GLUE_BUFFER_SIZE);
    int rfd = get_read_fd(self);
    int wfd = get_write_fd(self);
    XMsg *msg;
    crc32_init(&elt->crc);

    g_debug("read_and_write: read from %d, write to %d", rfd, wfd);
    while (!elt->cancelled) {
	size_t len;

	/* read from upstream */
	len = read_fully(rfd, buf, GLUE_BUFFER_SIZE, NULL);
	if (len < GLUE_BUFFER_SIZE) {
	    if (errno) {
		if (!elt->cancelled) {
		    xfer_cancel_with_error(elt,
			_("Error reading from fd %d: %s"), rfd, strerror(errno));
		    wait_until_xfer_cancelled(elt->xfer);
		}
		break;
	    } else if (len == 0) { /* we only count a zero-length read as EOF */
		break;
	    }
	}

	/* write the buffer fully */
	if (!elt->downstream->drain_mode && full_write(wfd, buf, len) < len) {
	    if (elt->downstream->must_drain) {
		g_debug("Could not write to fd %d: %s",  wfd, strerror(errno));
	    } else if (elt->downstream->ignore_broken_pipe && errno == EPIPE) {
	    } else {
		if (!elt->cancelled) {
		    xfer_cancel_with_error(elt,
			_("Could not write to fd %d: %s"),
			wfd, strerror(errno));
		    wait_until_xfer_cancelled(elt->xfer);
		}
		break;
	    }
	}
	crc32_add((uint8_t *)buf, len, &elt->crc);
    }

    if (elt->cancelled && elt->expect_eof)
	xfer_element_drain_fd(rfd);

    /* close the read fd.  If it's not at EOF, then upstream will get EPIPE, which will hopefully
     * kill it and complete the cancellation */
    close_read_fd(self);

    /* close the fd we've been writing, as an EOF signal to downstream */
    close_write_fd(self);

    g_debug("read_and_write upstream CRC: %08x      size %lld",
	    crc32_finish(&elt->crc), (long long)elt->crc.size);
    g_debug("sending XMSG_CRC message");
    msg = xmsg_new(elt->upstream, XMSG_CRC, 0);
    msg->crc = crc32_finish(&elt->crc);
    msg->size = elt->crc.size;
    xfer_queue_message(elt->xfer, msg);

    g_debug("read_and_write downstream CRC: %08x      size %lld",
	    crc32_finish(&elt->crc), (long long)elt->crc.size);
    g_debug("sending XMSG_CRC message");
    msg = xmsg_new(elt->downstream, XMSG_CRC, 0);
    msg->crc = crc32_finish(&elt->crc);
    msg->size = elt->crc.size;
    xfer_queue_message(elt->xfer, msg);

    amfree(buf);
}
Beispiel #20
0
void ogg_init(void) {
  crc32_init(&ogg_crc32, OGG_CRC32_POLY, 0, 0);
}
Beispiel #21
0
/*
 * Convert RFC Message-ID/References to FIDO ^AMSGID/^AREPLY
 */
char *s_msgid_rfc_to_fido(int *origid_flag, char *message_id,
			  int part, int split, char *area)
    /* origid_flag - Flag for ^AORIGID */
    /* message_id  - Original RFC-ID */
    /* part        - part number */
    /* split       - != 0 # of parts */
    /* area        - FTN AREA */
{
    char *id, *host, *p;
    char *savep;
    Node node, *n;
    int hexflag, i;
    char hexid[16];
    unsigned long crc32;
    TmpS *tmps;

    /****** Extract id and host from <id@host> *****/

    savep = strsave(message_id);
    /*
     * Format of message_id is "<*****@*****.**> ..."
     * We want the the last one in the chain, which is the message id
     * of the article replied to.
     */
    id = strrchr(savep, '<');
    if(!id)
    {
	xfree(savep);
	return NULL;
    }
    id++;
    host = strchr(id, '@');
    if(!host)
    {
	xfree(savep);
	return NULL;
    }
    *host++ = 0;
    p = strchr(host, '>');
    if(!p)  
    {
	xfree(savep);
	return NULL;
    }
    *p = 0;

    /*
     * Don't convert <funpack....@...> and <NOMSGID-...@...> IDs
     * generated by FIDOGATE
     */
    if(!strncmp(id, "funpack", 7) || !strncmp(id, "NOMSGID_", 8))
    {
	xfree(savep);
	return NULL;
    }

    /***** Check for old style FTN Message-IDs <abcd1234%[email protected]> *****/
    if(!split)
    {
	/*
	 * First check ID. A FIDO Message-ID is a hex number with an
	 * optional %Domain string. The hex number must not start with
	 * `0' and it's length must be no more then 8 digits.
	 */
	node.domain[0] = 0;
	p = id;
	hexflag = isxdigit(*p) && *p!='0';
	for(p++, i=0; i<7 && *p && *p!='%'; i++, p++)
	    if(!isxdigit(*p))
		hexflag = FALSE;
	if(hexflag && *p=='%')		/* Domain part follows */
	{
	    *p++ = 0;
	    BUF_COPY(node.domain, p);
	}
	else if(*p)
	    hexflag = FALSE;
	if(hexflag) {
	    /* Pad with leading 0's */
	    str_copy(hexid, sizeof(hexid), "00000000");
	    str_copy(hexid+8-strlen(id), sizeof(hexid)-8+strlen(id), id);
	    
	    /* host must be an FTN address */
	    if( (n = inet_to_ftn(host)) )
	    {
		/* YEP! This is an old-style FTN Message-ID!!! */
		node.zone  = n->zone;
		node.net   = n->net;
		node.node  = n->node;
		node.point = n->point;
		tmps = tmps_printf("%s %s", znfp1(&node), hexid);
		xfree(savep);
		if(origid_flag)
		    *origid_flag = FALSE;
		return tmps->s;
	    }
	}
    } /**if(!split)**/


    /***** Check for new-style <MSGID_mimeanything@domain> *****/
    if(!strncmp(id, "MSGID_", 6))
    {
	p = id + strlen("MSGID_");
	tmps = tmps_alloc(strlen(id)+1);
	mime_dequote(tmps->s, tmps->len, p, MIME_QP|MIME_US);
	xfree(savep);
	if(origid_flag)
	    *origid_flag = FALSE;
	return tmps->s;
    }

    /***** Generate ^AMSGID according to msgid.doc specs *****/
    /*
     * New-style FIDO-Gatebau '94 ^AMSGID
     */
    xfree(savep);
    savep = strsave(message_id);
    id = strrchr(savep, '<');
    if(!id)
	id = savep;
    p = strchr(id, '>');
    if(!p)
	p = id;
    else
	p++;
    *p = 0;

    crc32_init();
    crc32_compute((unsigned char *)id, strlen(id));
    if(area)
	crc32_compute((unsigned char *)area, strlen(area));
    crc32 = crc32_value();
    if(split)
	crc32 += part - 1;

    tmps = tmps_alloc(strlen(id)+1+/**Extra**/20);
    msgid_fts9_quote(tmps->s, id, tmps->len);
    str_printf(tmps->s + strlen(tmps->s), tmps->len - strlen(tmps->s),
	       " %08lx", crc32);
    
    xfree(savep);
    if(origid_flag)
	*origid_flag = TRUE;
    return tmps->s;
}
Beispiel #22
0
int compression_test(void)
{
    unsigned int    size, tsize, compsize, tcompsize;
    char**          filenames;

    
    char* canterbury[] = {
        "canterbury/alice29.txt",
        "canterbury/asyoulik.txt",
        "canterbury/cp.html",
        "canterbury/fields.c",
        "canterbury/grammar.lsp",
        "canterbury/kennedy.xls",
        "canterbury/lcet10.txt",
        "canterbury/plrabn12.txt",
        "canterbury/ptt5",
        "canterbury/sum",
        "canterbury/xargs.1",
        NULL
    };

    char* artificial[] = {
        "artificial/a.txt",
        "artificial/aaa.txt",
        "artificial/alphabet.txt",
        "artificial/random.txt",
        NULL
    };

    char* large[] = {
        "large/bible.txt",
        "large/E.coli",
        "large/world192.txt",
        NULL
    };

    char* misc[] = {
        "misc/pi.txt",
        NULL
    };

    char* calgary[] = {
        "calgary/bib",
        "calgary/book1",
        "calgary/book2",
        "calgary/geo",
        "calgary/news",
        "calgary/obj1",
        "calgary/obj2",
        "calgary/paper1",
        "calgary/paper2",
        "calgary/paper3",
        "calgary/paper4",
        "calgary/paper5",
        "calgary/paper6",
        "calgary/pic",
        "calgary/progc",
        "calgary/progl",
        "calgary/progp",
        "calgary/trans",
        NULL
    };

    char** corpus[] = {canterbury, artificial, large, misc, calgary, NULL};


#if 0
    lzss_test(argv[1], &size, &compsize);
    return 0;
#endif

    filenames = corpus[4];
    tsize = 0;
    tcompsize = 0;

    crc32_init();

    while(*filenames)
    {
        if(!lzss_test(*filenames++, &size, &compsize))
            return -1;

        tsize += size;
        tcompsize += compsize;
    }

    print("Grand total:\n");
    print("  Size:       %d bytes\n", tsize);
    print("  Compressed: %d bytes\n", tcompsize);
    print("  Ratio:      %d%%\n", (tcompsize * 100) / tsize);

    return 0;
}
Beispiel #23
0
bool CExeFile::readData(const char episode, const std::string& datadirectory)
{
	crc32_init();

	std::string filename = datadirectory + "/keen" + itoa(episode) + ".exe";

	std::ifstream File;
	OpenGameFileR(File, filename, std::ios::binary);

	if(!File)
	{
		// try another filename (Used in Episode 4-6)
		filename = datadirectory + "/keen" + itoa(episode) + "e.exe";
		OpenGameFileR(File, filename, std::ios::binary);
	}

	if(!File)
	{
		// try another filename (Used in Episode 4-6) for demo versions
		filename = datadirectory + "/k" + itoa(episode) + "demo.exe";
		OpenGameFileR(File, filename, std::ios::binary);
	}
	
	if(!File)
		return false;	

	m_filename = filename;
	m_episode = episode;
	m_datadirectory = datadirectory;
	if( m_datadirectory != "") if(*(m_datadirectory.end()-1) != '/') m_datadirectory += "/";
		
	File.seekg(0,std::ios::end);
	m_datasize = File.tellg();
	File.seekg(0,std::ios::beg);

	SAFE_DELETE_ARRAY(m_data);
	unsigned char* m_data_temp = new unsigned char[m_datasize];
	File.read((char*)m_data_temp, m_datasize);

	File.close();

	Cunlzexe UnLZEXE;

	std::vector<unsigned char> decdata;
	if(UnLZEXE.decompress(m_data_temp, decdata))
	{
		m_datasize = decdata.size();
		m_data = new unsigned char[m_datasize];
		m_headersize = UnLZEXE.HeaderSize();
		memcpy(m_data, &decdata[0], m_datasize);
	}
	else
	{
		m_data = new unsigned char[m_datasize];
		memcpy(m_data, m_data_temp,m_datasize);
	}

	m_headerdata = m_data;
	m_headersize = UnLZEXE.HeaderSize();
	if(!m_headersize) m_headersize = 512;
	m_rawdata = m_data + m_headersize;

	const size_t offset_map[] = {
			/*Dummy:*/ 0x0,
			/*Keen 1:*/ 0x13050,
			/*Keen 2:*/ 0x17780,
			/*Keen 3:*/ 0x19820,
			/*Keen 4:*/ 0x2EE70,
			/*Keen 5:*/ 0x30340,
			/*Keen 6:*/ 0x30D30,
			/*Keen D:*/ 0x23A70
	};
	m_data_segment = m_rawdata+offset_map[m_episode];

	delete[] m_data_temp;

	m_crc = getcrc32( m_data, m_datasize );

	g_pLogFile->ftextOut( "EXE processed with size of %d and crc of %X\n", m_datasize, m_crc );

	return true;
}
Beispiel #24
0
/* loads the next level from open file fd. returns 0 on success, 1 on success with end of file reached, or -1 on error. */
static int loadlevelfromfile(struct sokgame *game, unsigned char **memptr, char *comment, int maxcommentlen) {
  int leveldatastarted = 0, endoffile = 0;
  int x, y, bytebuff;
  int commentfound = 0;
  char *origcomment = comment;
  game->positionx = -1;
  game->positiony = -1;
  game->field_width = 0;
  game->field_height = 0;
  game->solution = NULL;
  if ((comment != NULL) && (maxcommentlen > 0)) *comment = 0;

  /* Fill the area with floor */
  for (y = 0; y < 64; y++) {
    for (x = 0; x < 64; x++) {
      game->field[x][y] = field_floor;
    }
  }

  x = 0;
  y = 0;

  for (;;) {
    int rleprefix;
    rleprefix = readRLEbyte(memptr, &bytebuff);
    if (rleprefix < 0) endoffile = 1;
    if (endoffile != 0) break;
    for (; rleprefix > 0; rleprefix--) {
      switch (bytebuff) {
        case ' ': /* empty space */
        case '-': /* dash (-) and underscore (_) are sometimes used to denote empty spaces */
        case '_':
          game->field[x + 1][y + 1] |= field_floor;
          x += 1;
          break;
        case '#': /* wall */
          game->field[x + 1][y + 1] |= field_wall;
          x += 1;
          break;
        case '@': /* player */
          game->field[x + 1][y + 1] |= field_floor;
          game->positionx = x;
          game->positiony = y;
          x += 1;
          break;
        case '*': /* atom on goal */
          game->field[x + 1][y + 1] |= field_goal;
        case '$': /* atom */
          game->field[x + 1][y + 1] |= field_atom;
          x += 1;
          break;
        case '+': /* player on goal */
          game->positionx = x;
          game->positiony = y;
        case '.': /* goal */
          game->field[x + 1][y + 1] |= field_goal;
          x += 1;
          break;
        case '\n': /* next row */
        case '|':  /* some variants of the xsb format use | as the 'new row' separator (mostly when used with RLE) */
          if (leveldatastarted != 0) y += 1;
          x = 0;
          break;
        case '\r': /* CR - ignore those */
          break;
        default: /* anything else is a comment -> skip until end of line or end of file */
          if (leveldatastarted != 0) leveldatastarted = -1;
          if ((commentfound == 0) && (comment != NULL)) commentfound = -1;
          for (;;) {
            bytebuff = readbytefrommem(memptr);
            if (bytebuff == '\r') continue;
            if (bytebuff == '\n') break;
            if (bytebuff < 0) {
              endoffile = 1;
              break;
            }
            if (commentfound == -1) {
              if (maxcommentlen > 1) {
                  maxcommentlen--;
                  *comment = bytebuff;
                  comment += 1;
                } else {
                  commentfound = -2;
              }
            }
          }
          if (commentfound < 0) {
            commentfound = 1;
            *comment = 0;
            trim(origcomment);
          }
          break;
      }
      if ((leveldatastarted < 0) || (endoffile != 0)) break;
      if (x > 0) leveldatastarted = 1;
      if (x >= 62) return(ERR_LEVEL_TOO_LARGE);
      if (y >= 62) return(ERR_LEVEL_TOO_HIGH);
      if (x > game->field_width) game->field_width = x;
      if ((y >= game->field_height) && (x > 0)) game->field_height = y + 1;
    }
    if ((leveldatastarted < 0) || (endoffile != 0)) break;
  }

  /* check if the loaded game looks sane */
  if (game->positionx < 0) return(ERR_PLAYER_POS_UNDEFINED);
  if (game->field_height < 1) return(ERR_LEVEL_TOO_SMALL);
  if (game->field_width < 1) return(ERR_LEVEL_TOO_SMALL);
  if (leveldatastarted == 0) return(ERR_NO_LEVEL_DATA_FOUND);

  /* remove floors around the level */
  floodFillField(game, 63, 63);

  /* move the field by -1 vertically and horizontally to remove the additional row and column added for the fill function to be able to get around the field. */
  for (y = 0; y < 63; y++) {
    for (x = 0; x < 63; x++) {
      game->field[x][y] = game->field[x + 1][y + 1];
    }
  }
  /* compute the CRC32 of the field */
  game->crc32 = crc32_init();
  for (y = 0; y < game->field_width; y++) {
    for (x = 0; x < game->field_height; x++) {
      crc32_feed(&(game->crc32), &(game->field[x][y]), 1);
    }
  }
  crc32_finish(&(game->crc32));

  if (endoffile != 0) return(1);
  return(0);
}
Beispiel #25
0
/*
 *  doing similar to $ gtar | compression | encryption 
 */
static void
start_backup(
    dle_t      *dle,
    char       *host,
    int		dataf,
    int		mesgf,
    int		indexf)
{
    char tmppath[PATH_MAX];
    int dumpin, dumpout, compout;
    char *cmd = NULL;
    char *indexcmd = NULL;
    char *dirname = NULL;
    int l;
    char dumptimestr[80] = "UNUSED";
    struct tm *gmtm;
    amandates_t *amdates = NULL;
    time_t prev_dumptime = 0;
    char *error_pn = NULL;
    char *compopt  = NULL;
    char *encryptopt = skip_argument;
    char *tquoted;
    char *fquoted;
    char *qdisk;
    int infd, outfd;
    ssize_t nb;
    char buf[32768];
    char *amandates_file = NULL;
    am_level_t *alevel = (am_level_t *)dle->levellist->data;
    int      level  = alevel->level;
    int        native_pipe[2];
    int        client_pipe[2];
    int        data_out;

    have_filter = FALSE;
    crc32_init(&native_crc.crc);
    crc32_init(&client_crc.crc);

    /* create pipes to compute the native CRC */
    if (pipe(native_pipe) < 0) {
	char  *errmsg;
	char  *qerrmsg;
	errmsg = g_strdup_printf(_("Program '%s': can't create pipe"),
				 dle->program);
	qerrmsg = quote_string(errmsg);
	fdprintf(mesgf, _("sendbackup: error [%s]\n"), errmsg);
	dbprintf(_("ERROR %s\n"), qerrmsg);
	amfree(qerrmsg);
	amfree(errmsg);
	return;
    }

    if (dle->encrypt == ENCRYPT_CUST ||
        dle->compress == COMP_FAST ||
        dle->compress == COMP_BEST ||
        dle->compress == COMP_CUST) {

        have_filter = TRUE;

        /* create pipes to compute the client CRC */
        if (pipe(client_pipe) < 0) {
            char  *errmsg;
            char  *qerrmsg;
            errmsg = g_strdup_printf(_("Application '%s': can't create pipe"),
                                     dle->program);
            qerrmsg = quote_string(errmsg);
            fdprintf(mesgf, _("sendbackup: error [%s]\n"), errmsg);
            dbprintf(_("ERROR %s\n"), qerrmsg);
            amfree(qerrmsg);
            amfree(errmsg);
            return;
        }
        data_out = client_pipe[1];
	client_pipe[1] = -1;
    } else {
        data_out = dataf;
	dataf = -1;
    }

    error_pn = g_strconcat(get_pname(), "-smbclient", NULL);

    qdisk = quote_string(dle->disk);
    dbprintf(_("start: %s:%s lev %d\n"), host, qdisk, level);

    g_fprintf(stderr, _("%s: start [%s:%s level %d]\n"),
	    get_pname(), host, qdisk, level);

     /*  apply client-side encryption here */
     if ( dle->encrypt == ENCRYPT_CUST ) {
        encpid = pipespawn(dle->clnt_encrypt, STDIN_PIPE, 0,
			&compout, &data_out, &mesgf,
			dle->clnt_encrypt, encryptopt, NULL);
        dbprintf(_("gnutar: pid %ld: %s\n"), (long)encpid, dle->clnt_encrypt);
	aclose(data_out);
    } else {
        compout = data_out;
	data_out = -1;
        encpid = -1;
    }
    /*  now do the client-side compression */
    if (dle->compress == COMP_FAST || dle->compress == COMP_BEST) {
        compopt = skip_argument;
#if defined(COMPRESS_BEST_OPT) && defined(COMPRESS_FAST_OPT)
	if(dle->compress == COMP_BEST) {
	    compopt = COMPRESS_BEST_OPT;
	} else {
	    compopt = COMPRESS_FAST_OPT;
	}
#endif
	comppid = pipespawn(COMPRESS_PATH, STDIN_PIPE, 0,
			    &dumpout, &compout, &mesgf,
			    COMPRESS_PATH, compopt, NULL);
	dbprintf(_("gnutar: pid %ld: %s"), (long)comppid, COMPRESS_PATH);
	if(compopt != skip_argument) {
	    dbprintf(_("pid %ld: %s %s\n"),
			(long)comppid, COMPRESS_PATH, compopt);
	} else {
	    dbprintf(_("pid %ld: %s\n"), (long)comppid, COMPRESS_PATH);
	}
	aclose(compout);
     } else if (dle->compress == COMP_CUST) {
        compopt = skip_argument;
	comppid = pipespawn(dle->compprog, STDIN_PIPE, 0,
			    &dumpout, &compout, &mesgf,
			    dle->compprog, compopt, NULL);
	if(compopt != skip_argument) {
	    dbprintf(_("pid %ld: %s %s\n"),
		     (long)comppid, dle->compprog, compopt);
	} else {
	    dbprintf(_("pid %ld: %s\n"), (long)comppid, dle->compprog);
	}
	aclose(compout);
    } else {
	dumpout = compout;
	compout = -1;
	comppid = -1;
    }

    gnutar_list_dir = getconf_str(CNF_GNUTAR_LIST_DIR);
    if (strlen(gnutar_list_dir) == 0)
	gnutar_list_dir = NULL;

#ifdef SAMBA_CLIENT							/* { */
    if (dle->device[0] == '/' && dle->device[1]=='/')
	amfree(incrname);
    else
#endif									/* } */
    if (gnutar_list_dir) {
	char *basename = NULL;
	char number[NUM_STR_SIZE];
	char *inputname = NULL;
	int baselevel;
	char *sdisk = sanitise_filename(dle->disk);

	basename = g_strjoin(NULL, gnutar_list_dir,
			     "/",
			     host,
			     sdisk,
			     NULL);
	amfree(sdisk);

	g_snprintf(number, sizeof(number), "%d", level);
	incrname = g_strjoin(NULL, basename, "_", number, ".new", NULL);
	unlink(incrname);

	/*
	 * Open the listed incremental file from the previous level.  Search
	 * backward until one is found.  If none are found (which will also
	 * be true for a level 0), arrange to read from /dev/null.
	 */
	baselevel = level;
	infd = -1;
	while (infd == -1) {
	    if (--baselevel >= 0) {
		g_snprintf(number, sizeof(number), "%d", baselevel);
		g_free(inputname);
		inputname = g_strconcat(basename, "_", number, NULL);
	    } else {
		g_free(inputname);
		inputname = g_strdup("/dev/null");
	    }
	    if ((infd = open(inputname, O_RDONLY)) == -1) {
		int save_errno = errno;
		char *qname = quote_string(inputname);

		dbprintf(_("gnutar: error opening '%s': %s\n"),
			  qname,
			  strerror(save_errno));
		if (baselevel < 0) {
		    error(_("error [opening '%s': %s]"), qname, strerror(save_errno));
		    /*NOTREACHED*/
		}
		amfree(qname);
	    }
	}

	/*
	 * Copy the previous listed incremental file to the new one.
	 */
	if ((outfd = open(incrname, O_WRONLY|O_CREAT, 0600)) == -1) {
	    error(_("error [opening '%s': %s]"), incrname, strerror(errno));
	    /*NOTREACHED*/
	}

	while ((nb = read(infd, &buf, sizeof(buf))) > 0) {
	    if (full_write(outfd, &buf, (size_t)nb) < (size_t)nb) {
		error(_("error [writing to '%s': %s]"), incrname,
		       strerror(errno));
		/*NOTREACHED*/
	    }
	}

	if (nb < 0) {
	    error(_("error [reading from '%s': %s]"), inputname, strerror(errno));
	    /*NOTREACHED*/
	}

	if (close(infd) != 0) {
	    error(_("error [closing '%s': %s]"), inputname, strerror(errno));
	    /*NOTREACHED*/
	}
	if (close(outfd) != 0) {
	    error(_("error [closing '%s': %s]"), incrname, strerror(errno));
	    /*NOTREACHED*/
	}

	tquoted = quote_string(incrname);
	if(baselevel >= 0) {
	    fquoted = quote_string(inputname);
	    dbprintf(_("doing level %d dump as listed-incremental from '%s' to '%s'\n"),
		     level, fquoted, tquoted);
	    amfree(fquoted);
	} else {
	    dbprintf(_("doing level %d dump as listed-incremental to '%s'\n"),
		     level, tquoted);
	}
	amfree(tquoted);
	amfree(inputname);
	amfree(basename);
    } else {
	/* no gnutar-listdir, so we're using amandates */

	/* find previous dump time, failing completely if there's a problem */
	amandates_file = getconf_str(CNF_AMANDATES);
	if(!start_amandates(amandates_file, 0)) {
	    error(_("error [opening %s: %s]"), amandates_file, strerror(errno));
	    /*NOTREACHED*/
	}

	amdates = amandates_lookup(dle->disk);

	prev_dumptime = EPOCH;
	for(l = 0; l < level; l++) {
	    if(amdates->dates[l] > prev_dumptime)
		prev_dumptime = amdates->dates[l];
	}

	finish_amandates();
	free_amandates();

	gmtm = gmtime(&prev_dumptime);
	g_snprintf(dumptimestr, sizeof(dumptimestr),
		    "%04d-%02d-%02d %2d:%02d:%02d GMT",
		    gmtm->tm_year + 1900, gmtm->tm_mon+1, gmtm->tm_mday,
		    gmtm->tm_hour, gmtm->tm_min, gmtm->tm_sec);

	dbprintf(_("gnutar: doing level %d dump from amandates-derived date: %s\n"),
		  level, dumptimestr);
    }

    dirname = amname_to_dirname(dle->device);

    cur_dumptime = time(0);
    cur_level = level;
    cur_disk = g_strdup(dle->disk);
#ifdef GNUTAR
#  define PROGRAM_GNUTAR GNUTAR
#else
#  define PROGRAM_GNUTAR "tar"
#endif
    indexcmd = g_strjoin(NULL, 
			 PROGRAM_GNUTAR,
			 " -tf", " -",
			 " 2>/dev/null",
			 " | sed", " -e",
			 " \'s/^\\.//\'",
			 NULL);

#ifdef SAMBA_CLIENT							/* { */
    /* Use sambatar if the disk to back up is a PC disk */
    if (dle->device[0] == '/' && dle->device[1]=='/') {
	char *sharename = NULL, *user_and_password = NULL, *domain = NULL;
	char *share = NULL, *subdir = NULL;
	char *pwtext = NULL;
	char *taropt;
	int passwdf = -1;
	size_t lpass;
	size_t pwtext_len;
	char *pw_fd_env;

	parsesharename(dle->device, &share, &subdir);
	if (!share) {
	    amfree(share);
	    amfree(subdir);
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("cannot parse disk entry %s for share/subdir"), qdisk);
	    /*NOTREACHED*/
	}
	if ((subdir) && (SAMBA_VERSION < 2)) {
	    amfree(share);
	    amfree(subdir);
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("subdirectory specified for share %s but samba not v2 or better"), qdisk);
	    /*NOTREACHED*/
	}
	if ((user_and_password = findpass(share, &domain)) == NULL) {
	    if(domain) {
		memset(domain, '\0', strlen(domain));
		amfree(domain);
	    }
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("error [invalid samba host or password not found?]"));
	    /*NOTREACHED*/
	}
	lpass = strlen(user_and_password);
	if ((pwtext = strchr(user_and_password, '%')) == NULL) {
	    memset(user_and_password, '\0', lpass);
	    amfree(user_and_password);
	    if(domain) {
		memset(domain, '\0', strlen(domain));
		amfree(domain);
	    }
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("password field not \'user%%pass\' for %s"), qdisk);
	    /*NOTREACHED*/
	}
	*pwtext++ = '\0';
	pwtext_len = strlen(pwtext);
	if ((sharename = makesharename(share, 0)) == 0) {
	    memset(user_and_password, '\0', lpass);
	    amfree(user_and_password);
	    if(domain) {
		memset(domain, '\0', strlen(domain));
		amfree(domain);
	    }
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("error [can't make share name of %s]"), share);
	    /*NOTREACHED*/
	}

	taropt = g_strdup("-T");
	if(dle->exclude_file && dle->exclude_file->nb_element == 1) {
	    strappend(taropt, "X");
	}
#if SAMBA_VERSION >= 2
	strappend(taropt, "q");
#endif
	strappend(taropt, "c");
	if (level != 0) {
	    strappend(taropt, "g");
	} else if (dle->record) {
	    strappend(taropt, "a");
	}

	if (subdir) {
	    dbprintf(_("gnutar: backup of %s/%s\n"), sharename, subdir);
	} else {
	    dbprintf(_("gnutar: backup of %s\n"), sharename);
	}

	program->backup_name = program->restore_name = SAMBA_CLIENT;
	cmd = g_strdup(program->backup_name);
	info_tapeheader(dle);

	start_index(dle->create_index, native_pipe[1], mesgf, indexf, indexcmd);

	if (pwtext_len > 0) {
	    pw_fd_env = "PASSWD_FD";
	} else {
	    pw_fd_env = "dummy_PASSWD_FD";
	}
	dumppid = pipespawn(cmd, STDIN_PIPE|PASSWD_PIPE, 0,
			    &dumpin, &native_pipe[1], &mesgf,
			    pw_fd_env, &passwdf,
			    "smbclient",
			    sharename,
			    *user_and_password ? "-U" : skip_argument,
			    *user_and_password ? user_and_password : skip_argument,
			    "-E",
			    domain ? "-W" : skip_argument,
			    domain ? domain : skip_argument,
#if SAMBA_VERSION >= 2
			    subdir ? "-D" : skip_argument,
			    subdir ? subdir : skip_argument,
#endif
			    "-d0",
			    taropt,
			    "-",
			    dle->exclude_file && dle->exclude_file->nb_element == 1 ? dle->exclude_file->first->name : skip_argument,
			    NULL);
	if(domain) {
	    memset(domain, '\0', strlen(domain));
	    amfree(domain);
	}
	if(pwtext_len > 0 && full_write(passwdf, pwtext, pwtext_len) < pwtext_len) {
	    int save_errno = errno;

	    aclose(passwdf);
	    memset(user_and_password, '\0', lpass);
	    amfree(user_and_password);
	    set_pname(error_pn);
	    amfree(error_pn);
	    error(_("error [password write failed: %s]"), strerror(save_errno));
	    /*NOTREACHED*/
	}
	memset(user_and_password, '\0', lpass);
	amfree(user_and_password);
	aclose(passwdf);
	amfree(sharename);
	amfree(share);
	amfree(subdir);
	amfree(taropt);
	tarpid = dumppid;
    } else
#endif			/*end of samba */
    {

	int nb_exclude = 0;
	int nb_include = 0;
	GPtrArray *argv_ptr = g_ptr_array_new();
	char *file_exclude = NULL;
	char *file_include = NULL;
	messagelist_t mlist = NULL;

	if (dle->exclude_file) nb_exclude+=dle->exclude_file->nb_element;
	if (dle->exclude_list) nb_exclude+=dle->exclude_list->nb_element;
	if (dle->include_file) nb_include+=dle->include_file->nb_element;
	if (dle->include_list) nb_include+=dle->include_list->nb_element;

	if (nb_exclude > 0) file_exclude = build_exclude(dle, &mlist);
	if (nb_include > 0) file_include = build_include(dle, dirname, &mlist);
	g_slist_free(mlist); // MUST also free the message

	cmd = g_strjoin(NULL, amlibexecdir, "/", "runtar", NULL);
	info_tapeheader(dle);

	start_index(dle->create_index, native_pipe[1], mesgf, indexf, indexcmd);

	g_ptr_array_add(argv_ptr, g_strdup("runtar"));
	if (g_options->config)
	    g_ptr_array_add(argv_ptr, g_strdup(g_options->config));
	else
	    g_ptr_array_add(argv_ptr, g_strdup("NOCONFIG"));
#ifdef GNUTAR
	g_ptr_array_add(argv_ptr, g_strdup(GNUTAR));
#else
	g_ptr_array_add(argv_ptr, g_strdup("tar"));
#endif
	g_ptr_array_add(argv_ptr, g_strdup("--create"));
	g_ptr_array_add(argv_ptr, g_strdup("--file"));
	g_ptr_array_add(argv_ptr, g_strdup("-"));
	g_ptr_array_add(argv_ptr, g_strdup("--directory"));
	canonicalize_pathname(dirname, tmppath);
	g_ptr_array_add(argv_ptr, g_strdup(tmppath));
	g_ptr_array_add(argv_ptr, g_strdup("--one-file-system"));
	if (gnutar_list_dir && incrname) {
	    g_ptr_array_add(argv_ptr, g_strdup("--listed-incremental"));
	    g_ptr_array_add(argv_ptr, g_strdup(incrname));
	} else {
	    g_ptr_array_add(argv_ptr, g_strdup("--incremental"));
	    g_ptr_array_add(argv_ptr, g_strdup("--newer"));
	    g_ptr_array_add(argv_ptr, g_strdup(dumptimestr));
	}
#ifdef ENABLE_GNUTAR_ATIME_PRESERVE
	/* --atime-preserve causes gnutar to call
	 * utime() after reading files in order to
	 * adjust their atime.  However, utime()
	 * updates the file's ctime, so incremental
	 * dumps will think the file has changed. */
	g_ptr_array_add(argv_ptr, g_strdup("--atime-preserve"));
#endif
	g_ptr_array_add(argv_ptr, g_strdup("--sparse"));
	g_ptr_array_add(argv_ptr, g_strdup("--ignore-failed-read"));
	g_ptr_array_add(argv_ptr, g_strdup("--totals"));

	if(file_exclude) {
	    g_ptr_array_add(argv_ptr, g_strdup("--exclude-from"));
	    g_ptr_array_add(argv_ptr, g_strdup(file_exclude));
	}

	if(file_include) {
	    g_ptr_array_add(argv_ptr, g_strdup("--files-from"));
	    g_ptr_array_add(argv_ptr, g_strdup(file_include));
	}
	else {
	    g_ptr_array_add(argv_ptr, g_strdup("."));
	}
	    g_ptr_array_add(argv_ptr, NULL);
	dumppid = pipespawnv(cmd, STDIN_PIPE, 0,
			     &dumpin, &native_pipe[1], &mesgf,
			     (char **)argv_ptr->pdata);
	tarpid = dumppid;
	amfree(file_exclude);
	amfree(file_include);
	g_ptr_array_free_full(argv_ptr);
    }
    dbprintf(_("gnutar: %s: pid %ld\n"), cmd, (long)dumppid);

    amfree(qdisk);
    amfree(dirname);
    amfree(cmd);
    amfree(indexcmd);
    amfree(error_pn);

    /* close the write ends of the pipes */

    aclose(dumpin);
    aclose(native_pipe[1]);
    aclose(mesgf);
    if (dle->create_index)
	aclose(indexf);

    if (shm_control_name) {
	shm_ring = shm_ring_link(shm_control_name);
	shm_ring_producer_set_size(shm_ring, NETWORK_BLOCK_BYTES*16, NETWORK_BLOCK_BYTES*4);
	native_crc.in  = native_pipe[0];
	if (!have_filter) {
	    native_crc.out = dumpout;
	    native_crc.shm_ring = shm_ring;
	    native_crc.thread = g_thread_create(handle_crc_to_shm_ring_thread,
					(gpointer)&native_crc, TRUE, NULL);
	} else {
	    native_crc.out = dumpout;
	    native_crc.thread = g_thread_create(handle_crc_thread,
					(gpointer)&native_crc, TRUE, NULL);
	    client_crc.in  = client_pipe[0];
	    client_crc.out = dataf;
	    client_crc.shm_ring = shm_ring;
	    client_crc.thread = g_thread_create(handle_crc_to_shm_ring_thread,
					(gpointer)&client_crc, TRUE, NULL);
	}
    } else {
	native_crc.in  = native_pipe[0];
	native_crc.out = dumpout;
	native_crc.thread = g_thread_create(handle_crc_thread,
					(gpointer)&native_crc, TRUE, NULL);

	if (have_filter) {
	    client_crc.in  = client_pipe[0];
	    client_crc.out = dataf;
	    client_crc.thread = g_thread_create(handle_crc_thread,
					(gpointer)&client_crc, TRUE, NULL);
	}
    }
}
Beispiel #26
0
int lzss_test(char* filename, unsigned int* psize, unsigned int* pcompsize)
{
    int             ret;
    unsigned char*  in = NULL;
    unsigned int    insize;
    unsigned char*  out = NULL;
    unsigned int    outsize, outmaxsize;
    unsigned int    crc0, crc1;


    print("File: %s\n", filename);
    if(!file_get(filename, &in, &insize))
        goto error;

    *psize = insize;

    crc32_init();
    crc0 = crc32_buffer(in, insize);
    print("crc: %08X\n", crc0);
    print("uncompressed size: %d bytes\n", insize);

    outmaxsize = 2 * insize;
    out = memory_alloc(outmaxsize);

    outsize = lzss_compress(in, insize, out, outmaxsize);
    if(outsize == -1)
    {
        print("Compression error\n");
        goto error;
    }

    *pcompsize = outsize;

    print("compressed size: %d bytes\n", outsize);
    print("ratio: %d%%\n", (outsize * 100) / insize);

    memory_set(in, insize, 0);
    outsize = lzss_decompress(out, outsize, in, insize);

    crc1 = crc32_buffer(in, insize);
    if(crc0 != crc1)
    {
        print("CRCs do not match!\n");
        goto error;
    }

    //if(!file_put("out", in, outsize))
    //    goto error;

    print("Success.\n\n");
    ret = 1;

done:
    if(in)
        memory_free(in);
    if(out)
        memory_free(out);
    return ret;

error:
    ret = 0;
    goto done;
}
Beispiel #27
-1
int app_ok(){
    if (!APP_RANGE_VALID(APP_START, app_info->image_size)) {
        return 0;
    }

    uint32_t crc = crc32_init();
    crc = crc32_update(crc, (void*)APP_START, app_info->image_size);
    crc = crc32_finalize(crc);

    if (crc != 0) {
        return 0;
    }

    return 1;
}