Пример #1
0
/* Verify that required actual IPv4 header fields are as the script expected. */
static int verify_ipv4(
	const struct packet *actual_packet,
	const struct packet *script_packet,
	int layer, char **error)
{
	const struct ipv4 *actual_ipv4 = actual_packet->headers[layer].h.ipv4;
	const struct ipv4 *script_ipv4 = script_packet->headers[layer].h.ipv4;

	if (check_field("ipv4_version",
			script_ipv4->version,
			actual_ipv4->version, error) ||
	    check_field("ipv4_protocol",
			script_ipv4->protocol,
			actual_ipv4->protocol, error) ||
	    check_field("ipv4_header_length",
			script_ipv4->ihl,
			actual_ipv4->ihl, error) ||
	    check_field("ipv4_total_length",
			(ntohs(script_ipv4->tot_len) +
			 tcp_options_allowance(actual_packet,
					       script_packet)),
			ntohs(actual_ipv4->tot_len), error))
		return STATUS_ERR;

	if (verify_outbound_live_ecn(script_packet->ecn,
				     ipv4_ecn_bits(actual_ipv4),
				     ipv4_ecn_bits(script_ipv4),
				     error))
		return STATUS_ERR;

	return STATUS_OK;
}
Пример #2
0
/* Verify that required actual IPv6 header fields are as the script expected. */
static int verify_ipv6(
	const struct packet *actual_packet,
	const struct packet *script_packet,
	int layer, char **error)
{
	const struct ipv6 *actual_ipv6 = actual_packet->headers[layer].h.ipv6;
	const struct ipv6 *script_ipv6 = script_packet->headers[layer].h.ipv6;

	if (check_field("ipv6_version",
			script_ipv6->version,
			actual_ipv6->version, error) ||
	    check_field("ipv6_payload_len",
			(ntohs(script_ipv6->payload_len) +
			 tcp_options_allowance(actual_packet,
					       script_packet)),
			ntohs(actual_ipv6->payload_len), error) ||
	    check_field("ipv6_next_header",
			script_ipv6->next_header,
			actual_ipv6->next_header, error))
		return STATUS_ERR;

	if (verify_outbound_live_ecn(script_packet->ecn,
				     ipv6_ecn_bits(actual_ipv6),
				     ipv6_ecn_bits(script_ipv6),
				     error))
		return STATUS_ERR;

	return STATUS_OK;
}
Пример #3
0
int	dispvar(char **format, va_list ap)
{
	int		wr;
	t_args	*arg;

	wr = 0;
	arg = (t_args*)malloc(sizeof(t_args));
	*format += 1;
	if (**format != 0)
	{
		init_arg(&arg);
		while (is_flag(**format))
		{
			check_flags(format, &arg);
			check_field(format, &arg, ap);
			check_prec(format, &arg, ap);
			check_length(format, &arg);
		}
		wr += print_char(format, &arg, ap);
		wr += print_hexa(format, &arg, ap);
		wr += print_decimal(format, &arg, ap);
		wr += print_octal(format, &arg, ap);
	}
	free(arg);
	return (wr);
}
Пример #4
0
int flatcc_verify_table_vector_field(flatcc_table_verifier_descriptor_t *td,
        voffset_t id, int required, flatcc_table_verifier_f tvf)
{
    uoffset_t base;

    check_field(td, id, required, base);
    return verify_table_vector(td->buf, td->end, base, read_uoffset(td->buf, base), td->ttl, tvf);
}
Пример #5
0
/*
 * pool_init creates a named pool and opens connections to the database
 */
static TDS_POOL *
pool_init(const char *name)
{
	TDS_POOL *pool;
	char *err = NULL;

	/* initialize the pool */

	pool = (TDS_POOL *) calloc(1, sizeof(TDS_POOL));

	pool->event_fd = INVALID_SOCKET;
	if (tds_mutex_init(&pool->events_mtx)) {
		fprintf(stderr, "Error initializing pool mutex\n");
		exit(EXIT_FAILURE);
	}

	/* FIXME -- read this from the conf file */
	if (!pool_read_conf_file(name, pool, &err)) {
		fprintf(stderr, "Configuration for pool ``%s'' not found.\n", name);
		exit(EXIT_FAILURE);
	}

	if (err) {
		fprintf(stderr, "%s\n", err);
		exit(EXIT_FAILURE);
	}
	check_field(name, pool->user,   "user");
	check_field(name, pool->server, "server");
	check_field(name, pool->port,   "port");

	if (pool->max_open_conn < pool->min_open_conn) {
		fprintf(stderr, "Max connections less than minimum\n");
		exit(EXIT_FAILURE);
	}

	pool->name = strdup(name);

	pool_open_logfile(pool);

	pool_mbr_init(pool);
	pool_user_init(pool);

	pool_socket_init(pool);

	return pool;
}
Пример #6
0
int flatcc_verify_string_field(flatcc_table_verifier_descriptor_t *td,
        voffset_t id, int required)
{
    uoffset_t base;

    check_field(td, id, required, base);
    return verify_string(td->buf, td->end, base, read_uoffset(td->buf, base));
}
Пример #7
0
int flatcc_verify_vector_field(flatcc_table_verifier_descriptor_t *td,
        voffset_t id, int required, uint16_t align, size_t elem_size, size_t max_count)
{
    uoffset_t base;

    check_field(td, id, required, base);
    return verify_vector(td->buf, td->end, base, read_uoffset(td->buf, base),
        align, (uoffset_t)elem_size, (uoffset_t)max_count);
}
Пример #8
0
static bool comparecomponent(enum term_comparison c, const struct compare_with *v, UNUSED(const void *d1), const void *d2) {
	const struct target *target = d2;

	if (c == tc_equal)
		return v->number == target->component;
	else if (c == tc_notequal)
		return v->number != target->component;
	else
		return check_field(c,
				atoms_components[target->component],
				v->pointer);
}
Пример #9
0
/* Verify that required actual UDP header fields are as the script expected. */
static int verify_udp(
	const struct packet *actual_packet,
	const struct packet *script_packet,
	int layer, char **error)
{
	const struct udp *actual_udp = actual_packet->headers[layer].h.udp;
	const struct udp *script_udp = script_packet->headers[layer].h.udp;

	if (check_field("udp_len",
			ntohs(script_udp->len),
			ntohs(actual_udp->len), error))
		return STATUS_ERR;
	return STATUS_OK;
}
Пример #10
0
/* Verify that required actual GRE header fields are as the script expected. */
static int verify_gre(
	const struct packet *actual_packet,
	const struct packet *script_packet,
	int layer, char **error)
{
	const struct gre *actual_gre = actual_packet->headers[layer].h.gre;
	const struct gre *script_gre = script_packet->headers[layer].h.gre;

	/* TODO(ncardwell) check all fields of GRE header */
	if (check_field("gre_len",
			gre_len(script_gre),
			gre_len(actual_gre), error))
		return STATUS_ERR;
	return STATUS_OK;
}
Пример #11
0
void next_turn(){
	//cell_q=NULL;
	cell_q_size=0;
	int i;
	coord x, y, j;
	cell * it;
	death=birth=0;
	//printf("next turn\n");
	for(i=0;i<NUM2*(NUM1+1);i++){
		it=hash_t[i].head;
	//	printf("\t i=%d\n",i);
		if(it==NULL){
			continue;
		}
		while(it!=NULL ){
			x=it->x;
			y=it->y;
			check_field(x+1,y);
			check_field(x+1,y+1);
			check_field(x+1,y-1);
			check_field(x-1,y);
			check_field(x-1,y+1);
			check_field(x-1,y-1);
			check_field(x,y+1);
			check_field(x,y-1);
			check_field(x,y);
			it=it->next;
		}
	}
	print_que();
	for(j=0;j<cell_q_size;j++)
		if(cell_q[j].alive==1)
			add_cell(cell_q[j].x,cell_q[j].y);
		else
			del_cell(cell_q[j].x,cell_q[j].y);
	//free(cell_q);
	turn++;
}
Пример #12
0
void next_turn(){
	q=NULL;
	max_q=0;
	int i;
	coord x, y, j;
	cell_list * it;
	death=birth=0;
	//printf("next turn\n");
	for(i=0;i<NUM2*(NUM1+1);i++){
		it=ht[i].head;
	//	printf("\t i=%d\n",i);
		if(it==NULL){
			continue;
		}
		while(it!=NULL ){
			x=it->x;
			y=it->y;
			check_field(x+1,y);
			check_field(x+1,y+1);
			check_field(x+1,y-1);
			check_field(x-1,y);
			check_field(x-1,y+1);
			check_field(x-1,y-1);
			check_field(x,y+1);
			check_field(x,y-1);
			check_field(x,y);
			it=it->next;
		}
	}
	print_que();
	for(j=0;j<max_q;j++)
		if(q[j].alive==1)
			add_cell(q[j].x,q[j].y);
		else
			del_live(q[j].x,q[j].y);
	free(q);
	turn++;
}
Пример #13
0
Файл: init.c Проект: chaos/nph
/* verify that a list of fields exists on the server */
int
check_fields(PH *newph, char *string)
{
	char buf[NPH_BUF_SIZE];
	char *wordp, *nextp;

	strlcpy(buf, string, sizeof(buf));
	nextp = buf;
	while ((wordp = strsep(&nextp, " ")) != NULL)
	{
		if (*wordp == '\0')
			continue;

		if (check_field(newph, wordp) == -1)
			return -1;
	}

	return 0;
}
Пример #14
0
retvalue term_decidechunk(const term *condition, const char *controlchunk, const void *privdata) {
	const struct term_atom *atom = condition;

	while (atom != NULL) {
		bool correct; char *value;
		enum term_comparison c = atom->comparison;
		retvalue r;

		if (atom->isspecial) {
			correct = atom->special.type->compare(c,
					&atom->special.comparewith,
					controlchunk, privdata);
		} else {
			r = chunk_getvalue(controlchunk,
					atom->generic.key, &value);
			if (RET_WAS_ERROR(r))
				return r;
			if (r == RET_NOTHING) {
				correct = (c == tc_notequal
						|| c == tc_notglobmatch);
			} else {
				correct = check_field(c, value,
						atom->generic.comparewith);
				free(value);
			}
		}
		if (atom->negated)
			correct = !correct;
		if (correct) {
			atom = atom->nextiftrue;
		} else {
			atom = atom->nextiffalse;
			if (atom == NULL) {
				/* do not include */
				return RET_NOTHING;
			}
		}

	}
	/* do include */
	return RET_OK;
}
Пример #15
0
static bool comparesource(enum term_comparison c, const struct compare_with *v, const void *d1, const void *d2) {
	const char *control = d1;
	const struct target *target = d2;
	char *package, *source, *version;
	retvalue r;
	bool matches;

	// TODO: make more efficient
	r = chunk_getvalue(control, "Package", &package);
	if (!RET_IS_OK(r))
		return false;
	r = target->getsourceandversion(control, package, &source, &version);
	free(package);
	if (!RET_IS_OK(r))
		return false;
	free(version);
	matches = check_field(c, source, v->pointer);
	free(source);
	return matches;
}
Пример #16
0
static inline bool compare_dpkgversions(enum term_comparison c, const char *version, const char *param) {
	if (c != tc_globmatch && c != tc_notglobmatch) {
		int cmp;
		retvalue r;

		r = dpkgversions_cmp(version, param, &cmp);
		if (RET_IS_OK(r)) {
			if (cmp < 0)
				return c == tc_strictless
					|| c == tc_lessorequal
					|| c == tc_notequal;
			else if (cmp > 0)
				return c == tc_strictmore
					|| c == tc_moreorequal
					|| c == tc_notequal;
			else
				return c == tc_lessorequal
					|| c == tc_moreorequal
					|| c == tc_equal;
		} else
			return false;
	} else
		return check_field(c, version, param);
}
Пример #17
0
/* Verify that the actual ECN bits are as the script expected. */
static int verify_outbound_live_ecn(enum ip_ecn_t ecn,
				    u8 actual_ecn_bits,
				    u8 script_ecn_bits,
				    char **error)
{
	if (ecn == ECN_NOCHECK)
		return STATUS_OK;

	if (ecn == ECN_ECT01) {
		if ((actual_ecn_bits != IP_ECN_ECT0) &&
		    (actual_ecn_bits != IP_ECN_ECT1)) {
			asprintf(error, "live packet field ip_ecn: "
				 "expected: 0x1 or 0x2 vs actual: 0x%x",
				 actual_ecn_bits);
			return STATUS_ERR;
		}
	} else if (check_field("ip_ecn",
			       script_ecn_bits,
			       actual_ecn_bits, error)) {
		return STATUS_ERR;
	}

	return STATUS_OK;
}
int main(int argc, char **argv)
{
#if (__GNUC__ >= 4)
	int cur_offset = 0;

	printf("%8s %-30s %3s\n", "offset", "field", "size");
	check_field(s_inodes_count, 4);
	check_field(s_blocks_count, 4);
	check_field(s_r_blocks_count, 4);
	check_field(s_free_blocks_count, 4);
	check_field(s_free_inodes_count, 4);
	check_field(s_first_data_block, 4);
	check_field(s_log_block_size, 4);
	check_field(s_log_cluster_size, 4);
	check_field(s_blocks_per_group, 4);
	check_field(s_clusters_per_group, 4);
	check_field(s_inodes_per_group, 4);
	check_field(s_mtime, 4);
	check_field(s_wtime, 4);
	check_field(s_mnt_count, 2);
	check_field(s_max_mnt_count, 2);
	check_field(s_magic, 2);
	check_field(s_state, 2);
	check_field(s_errors, 2);
	check_field(s_minor_rev_level, 2);
	check_field(s_lastcheck, 4);
	check_field(s_checkinterval, 4);
	check_field(s_creator_os, 4);
	check_field(s_rev_level, 4);
	check_field(s_def_resuid, 2);
	check_field(s_def_resgid, 2);
	check_field(s_first_ino, 4);
	check_field(s_inode_size, 2);
	check_field(s_block_group_nr, 2);
	check_field(s_feature_compat, 4);
	check_field(s_feature_incompat, 4);
	check_field(s_feature_ro_compat, 4);
	check_field(s_uuid, 16);
	check_field(s_volume_name, 16);
	check_field(s_last_mounted, 64);
	check_field(s_algorithm_usage_bitmap, 4);
	check_field(s_prealloc_blocks, 1);
	check_field(s_prealloc_dir_blocks, 1);
	check_field(s_reserved_gdt_blocks, 2);
	check_field(s_journal_uuid, 16);
	check_field(s_journal_inum, 4);
	check_field(s_journal_dev, 4);
	check_field(s_last_orphan, 4);
	check_field(s_hash_seed, 4 * 4);
	check_field(s_def_hash_version, 1);
	check_field(s_jnl_backup_type, 1);
	check_field(s_desc_size, 2);
	check_field(s_default_mount_opts, 4);
	check_field(s_first_meta_bg, 4);
	check_field(s_mkfs_time, 4);
	check_field(s_jnl_blocks, 17 * 4);
	check_field(s_blocks_count_hi, 4);
	check_field(s_r_blocks_count_hi, 4);
	check_field(s_free_blocks_hi, 4);
	check_field(s_min_extra_isize, 2);
	check_field(s_want_extra_isize, 2);
	check_field(s_flags, 4);
	check_field(s_raid_stride, 2);
	check_field(s_mmp_update_interval, 2);
	check_field(s_mmp_block, 8);
	check_field(s_raid_stripe_width, 4);
	check_field(s_log_groups_per_flex, 1);
	check_field(s_checksum_type, 1);
	check_field(s_encryption_level, 1);
	check_field(s_reserved_pad, 1);
	check_field(s_kbytes_written, 8);
	check_field(s_snapshot_inum, 4);
	check_field(s_snapshot_id, 4);
	check_field(s_snapshot_r_blocks_count, 8);
	check_field(s_snapshot_list, 4);
	check_field(s_error_count, 4);
	check_field(s_first_error_time, 4);
	check_field(s_first_error_ino, 4);
	check_field(s_first_error_block, 8);
	check_field(s_first_error_func, 32);
	check_field(s_first_error_line, 4);
	check_field(s_last_error_time, 4);
	check_field(s_last_error_ino, 4);
	check_field(s_last_error_line, 4);
	check_field(s_last_error_block, 8);
	check_field(s_last_error_func, 32);
	check_field(s_mount_opts, 64);
	check_field(s_usr_quota_inum, 4);
	check_field(s_grp_quota_inum, 4);
	check_field(s_overhead_blocks, 4);
 	check_field(s_backup_bgs, 8);
	check_field(s_encrypt_algos, 4);
	check_field(s_encrypt_pw_salt, 16);
	check_field(s_lpf_ino, 4);
	check_field(s_reserved, 100 * 4);
	check_field(s_checksum, 4);
	do_field("Superblock end", 0, 0, cur_offset, 1024);
#endif
	return 0;
}
Пример #19
0
void init_fields(){
	
	for(int i=0;i<100;i++){
		field.my_fields[i/10][i%10]=0;
		field.enemy_fields[i/10][i%10]=0;
	}
	
	#ifdef DEBUG
	for(int i=0;i<10;i++){
		for(int j=0; j<10; j++)
			field.my_fields[i][j] = debug_fields[i][j];
	}
	print_board();
	#endif
	
	#ifndef DEBUG
	int x,y,begin_x,begin_y;
	char bufor[2];
	print_board();
	for(int i=1;i<5;i++){
		for(int j=0;j<i;j++){	
			printf("Podaj poczatek statku nr:%d o dlugosci %d: ",j+1,5-i);		
			do{		
				scanf("%s",bufor);	
				if(parse_field(bufor,&x,&y)!=0){
					if(check_field(y, x)!=0)
						break;
				}
				
				
			}while(1);

			begin_x=x;
			begin_y=y;
			printf("Podaj koniec statku nr:%d o dlugosci %d: ",j+1,5-i);		
			if(5-i!=1){	
				do{		
					scanf("%s",bufor);	
					
					if(parse_field(bufor,&x,&y)!=0){
						if(check_field(y, x)!=0){
							if(check_fields(begin_x,begin_y,x,y,5-i)!=0)
								break;
						}
						
					}	
				}while(1);
			}
			place_vessel(begin_x,begin_y,x,y,5-i);
			print_board();
		}
		
	}
	#endif

	request_t response;
	strcpy(response.name,client_name);
	response.lobby = GAME;
	response.action = PLAYER_READY;
	response.opponent_socket=opponent_socket;	
	pthread_mutex_lock(&mutex);
	if(send(socket_fd, (void*) &response, sizeof(response), 0) == -1)
			error("send() redy");
	pthread_mutex_unlock(&mutex);


}
Пример #20
0
void check_superblock_fields()
{
#if (__GNUC__ >= 4)
	int cur_offset = 0;

	printf("%8s %-30s %3s\n", "offset", "field", "size");
	check_field(s_inodes_count);
	check_field(s_blocks_count);
	check_field(s_r_blocks_count);
	check_field(s_free_blocks_count);
	check_field(s_free_inodes_count);
	check_field(s_first_data_block);
	check_field(s_log_block_size);
	check_field(s_log_cluster_size);
	check_field(s_blocks_per_group);
	check_field(s_clusters_per_group);
	check_field(s_inodes_per_group);
	check_field(s_mtime);
	check_field(s_wtime);
	check_field(s_mnt_count);
	check_field(s_max_mnt_count);
	check_field(s_magic);
	check_field(s_state);
	check_field(s_errors);
	check_field(s_minor_rev_level);
	check_field(s_lastcheck);
	check_field(s_checkinterval);
	check_field(s_creator_os);
	check_field(s_rev_level);
	check_field(s_def_resuid);
	check_field(s_def_resgid);
	check_field(s_first_ino);
	check_field(s_inode_size);
	check_field(s_block_group_nr);
	check_field(s_feature_compat);
	check_field(s_feature_incompat);
	check_field(s_feature_ro_compat);
	check_field(s_uuid);
	check_field(s_volume_name);
	check_field(s_last_mounted);
	check_field(s_algorithm_usage_bitmap);
	check_field(s_prealloc_blocks);
	check_field(s_prealloc_dir_blocks);
	check_field(s_reserved_gdt_blocks);
	check_field(s_journal_uuid);
	check_field(s_journal_inum);
	check_field(s_journal_dev);
	check_field(s_last_orphan);
	check_field(s_hash_seed);
	check_field(s_def_hash_version);
	check_field(s_jnl_backup_type);
	check_field(s_desc_size);
	check_field(s_default_mount_opts);
	check_field(s_first_meta_bg);
	check_field(s_mkfs_time);
	check_field(s_jnl_blocks);
	check_field(s_blocks_count_hi);
	check_field(s_r_blocks_count_hi);
	check_field(s_free_blocks_hi);
	check_field(s_min_extra_isize);
	check_field(s_want_extra_isize);
	check_field(s_flags);
	check_field(s_raid_stride);
	check_field(s_mmp_interval);
	check_field(s_mmp_block);
	check_field(s_raid_stripe_width);
	check_field(s_log_groups_per_flex);
	check_field(s_reserved_char_pad);
	check_field(s_reserved_pad);
	check_field(s_kbytes_written);
	check_field(s_snapshot_inum);
	check_field(s_snapshot_id);
	check_field(s_snapshot_r_blocks_count);
	check_field(s_snapshot_list);
	check_field(s_error_count);
	check_field(s_first_error_time);
	check_field(s_first_error_ino);
	check_field(s_first_error_block);
	check_field(s_first_error_func);
	check_field(s_first_error_line);
	check_field(s_last_error_time);
	check_field(s_last_error_ino);
	check_field(s_last_error_line);
	check_field(s_last_error_block);
	check_field(s_last_error_func);
	check_field(s_mount_opts);
	check_field(s_usr_quota_inum);
	check_field(s_grp_quota_inum);
	check_field(s_overhead_blocks);
	check_field(s_reserved);
	check_field(s_checksum);
	printf("Ending offset is %d\n\n", cur_offset);
#endif
}
int main(int argc, char **argv)
{
#if (__GNUC__ >= 4)
	int cur_offset = 0;

	printf("%8s %-30s %3s\n", "offset", "field", "size");
	check_field(magic);
	check_field(io);
	check_field(flags);
	check_field(device_name);
	check_field(super);
	check_field(blocksize);
	check_field(fragsize);
	check_field(group_desc_count);
	check_field(desc_blocks);
	check_field(group_desc);
	check_field(inode_blocks_per_group);
	check_field(inode_map);
	check_field(block_map);
	check_field(get_blocks);
	check_field(check_directory);
	check_field(write_bitmaps);
	check_field(read_inode);
	check_field(write_inode);
	check_field(badblocks);
	check_field(dblist);
	check_field(stride);
	check_field(orig_super);
	check_field(image_header);
	check_field(umask);
	check_field(now);
	check_field(cluster_ratio_bits);
	check_field(reserved);
	check_field(priv_data);
	check_field(icache);
	check_field(image_io);
	check_field(get_alloc_block);
	check_field(block_alloc_stats);
	check_field(mmp_buf);
	check_field(mmp_cmp);
	check_field(mmp_fd);
	check_field(mmp_last_written);
	printf("Ending offset is %d\n\n", cur_offset);
#endif
	exit(0);
}
Пример #22
0
/* Verify that required actual TCP header fields are as the script expected. */
static int verify_tcp(
	const struct packet *actual_packet,
	const struct packet *script_packet,
	int layer, char **error)
{
	const struct tcp *actual_tcp = actual_packet->headers[layer].h.tcp;
	const struct tcp *script_tcp = script_packet->headers[layer].h.tcp;

	if (check_field("tcp_data_offset",
			(script_tcp->doff +
			 tcp_options_allowance(actual_packet,
					       script_packet)/sizeof(u32)),
			actual_tcp->doff, error) ||
	    check_field("tcp_fin",
			script_tcp->fin,
			actual_tcp->fin, error) ||
	    check_field("tcp_syn",
			script_tcp->syn,
			actual_tcp->syn, error) ||
	    check_field("tcp_rst",
			script_tcp->rst,
			actual_tcp->rst, error) ||
	    check_field("tcp_psh",
			script_tcp->psh,
			actual_tcp->psh, error) ||
	    check_field("tcp_ack",
			script_tcp->ack,
			actual_tcp->ack, error) ||
	    check_field("tcp_urg",
			script_tcp->urg,
			actual_tcp->urg, error) ||
	    check_field("tcp_ece",
			script_tcp->ece,
			actual_tcp->ece, error) ||
	    check_field("tcp_cwr",
			script_tcp->cwr,
			actual_tcp->cwr, error) ||
	    check_field("tcp_reserved_bits",
			script_tcp->res1,
			actual_tcp->res1, error) ||
	    check_field("tcp_seq",
			ntohl(script_tcp->seq),
			ntohl(actual_tcp->seq), error) ||
	    check_field("tcp_ack_seq",
			ntohl(script_tcp->ack_seq),
			ntohl(actual_tcp->ack_seq), error) ||
	    (script_packet->flags & FLAG_WIN_NOCHECK ? STATUS_OK :
		check_field("tcp_window",
			    ntohs(script_tcp->window),
			    ntohs(actual_tcp->window), error))  ||
	    check_field("tcp_urg_ptr",
			ntohs(script_tcp->urg_ptr),
			ntohs(actual_tcp->urg_ptr), error))
		return STATUS_ERR;

	return STATUS_OK;
}
Пример #23
0
static int do_upg(void *buf, long size)
{
    struct upg_md5_t *md5 = buf;
    cprintf(BLUE, "Preliminary\n");
    cprintf(GREEN, "  MD5: ");
    for(int i = 0; i < 16; i++)
        cprintf(YELLOW, "%02x", md5->md5[i]);
    printf(" ");

    uint8_t actual_md5[MD5_DIGEST_LENGTH];
    {
        MD5_CTX c;
        MD5_Init(&c);
        MD5_Update(&c, md5 + 1, size - sizeof(struct upg_header_t));
        MD5_Final(actual_md5, &c);
    }
    check_field(memcmp(actual_md5, md5->md5, 16), 0, "Ok\n", "Mismatch\n");

    int ret = get_key_and_sig(true, md5 + 1);
    if(ret != 0)
        return ret;

    struct upg_header_t *hdr = (void *)(md5 + 1);
    ret = fwp_read(hdr, sizeof(struct upg_header_t), hdr, (void *)g_key);
    if(ret)
        return ret;

    cprintf(BLUE, "Header\n");
    cprintf_field("  Signature:", " ");
    for(int i = 0; i < 8; i++)
        cprintf(YELLOW, "%c", isprint(hdr->sig[i]) ? hdr->sig[i] : '.');
    if(g_sig)
    {
        check_field(memcmp(hdr->sig, g_sig, 8), 0, " OK\n", " Mismatch\n");
    }
    else
        cprintf(RED, " Can't check\n");
    cprintf_field("  Files: ", "%d\n", hdr->nr_files);
    cprintf_field("  Pad: ", "0x%x\n", hdr->pad);

    cprintf(BLUE, "Files\n");
    struct upg_entry_t *entry = (void *)(hdr + 1);
    for(unsigned i = 0; i < hdr->nr_files; i++, entry++)
    {
        int ret = fwp_read(entry, sizeof(struct upg_entry_t), entry, (void *)g_key);
        if(ret)
            return ret;
        cprintf(GREY, "  File");
        cprintf(RED, " %d\n", i);
        cprintf_field("    Offset: ", "0x%x\n", entry->offset);
        cprintf_field("    Size: ", "0x%x\n", entry->size);

        if(g_out_prefix)
        {
            char *str = malloc(strlen(g_out_prefix) + 32);
            sprintf(str, "%s%d.bin", g_out_prefix, i);
            FILE *f = fopen(str, "wb");
            if(f)
            {
                // round up size, there is some padding done with random data
                int crypt_size = ROUND_UP(entry->size, 8);
                int ret = fwp_read(buf + entry->offset, crypt_size,
                    buf + entry->offset, (void *)g_key);
                if(ret)
                    return ret;
                // but write the *good* amount of data
                fwrite(buf + entry->offset, 1, entry->size, f);
                fclose(f);
            }
            else
                cprintf(GREY, "Cannot open '%s' for writing\n", str);
        }
    }

    return 0;
}