Beispiel #1
0
// Initialize address constraints from whitelist and blacklist files.
// Either can be set to NULL to omit.
int blacklist_init(char *whitelist_filename, char *blacklist_filename,
		char **whitelist_entries, size_t whitelist_entries_len,
		char **blacklist_entries, size_t blacklist_entries_len)
{
	assert(!constraint);
	if (whitelist_filename && whitelist_entries) {
		log_warn("whitelist", "both a whitelist file and destination addresses "
					"were specified. The union of these two sources "
					"will be utilized.");
	}
	if (whitelist_filename || whitelist_entries) {
		// using a whitelist, so default to allowing nothing
		constraint = constraint_init(ADDR_DISALLOWED);
		log_trace("whitelist", "blacklisting 0.0.0.0/0");
		if (whitelist_filename) {
			init_from_file(whitelist_filename, "whitelist", ADDR_ALLOWED);
		}
		if (whitelist_entries) {
			init_from_array(whitelist_entries,
					whitelist_entries_len, ADDR_ALLOWED);
		}
	} else {
		// no whitelist, so default to allowing everything
		constraint = constraint_init(ADDR_ALLOWED);
	}
	if (blacklist_filename) {
		init_from_file(blacklist_filename, "blacklist", ADDR_DISALLOWED);
	}
	if (blacklist_entries) {
		init_from_array(blacklist_entries, blacklist_entries_len, ADDR_DISALLOWED);
	}
	constraint_paint_value(constraint, ADDR_ALLOWED);
	uint64_t allowed = blacklist_count_allowed();
	log_debug("blacklist", "%lu addresses allowed to be scanned (%0.0f%% of address space)", 
			  allowed, allowed*100./((long long int)1 << 32));
	return EXIT_SUCCESS;
}
Beispiel #2
0
// Initialize address constraints from whitelist and blacklist files.
// Either can be set to NULL to omit.
int blacklist_init_from_files(char *whitelist_filename, char *blacklist_filename)
{
	assert(!constraint);
	if (whitelist_filename) {
		// using a whitelist, so default to allowing nothing
		constraint = constraint_init(ADDR_DISALLOWED);
		log_trace("whitelist", "blacklisting 0.0.0.0/0");
		init(whitelist_filename, "whitelist", ADDR_ALLOWED);
	} else {
		// no whitelist, so default to allowing everything
		constraint = constraint_init(ADDR_ALLOWED);
	}
	if (blacklist_filename) {
		init(blacklist_filename, "blacklist", ADDR_DISALLOWED);
	}
	constraint_paint_value(constraint, ADDR_ALLOWED);
	uint64_t allowed = blacklist_count_allowed();
	log_debug("blacklist", "%lu addresses allowed to be scanned (%0.0f%% of address space)", 
			  allowed, allowed*100./((long long int)1 << 32));

	/*
	// test
	log_debug("blacklist", "testing started");
	uint64_t count = constraint_count_ips(constraint, ADDR_ALLOWED);
	for (unsigned int i=0; i < count; i++) {
		int ip = constraint_lookup_index(constraint, i, ADDR_ALLOWED);
		if ((i & 0xFFFFFF) == 0)
			log_info("blacklist", "%x", i & 0xFF000000);
		if (constraint_lookup_ip(constraint, ip) != ADDR_ALLOWED) {
			log_error("blacklist", "test failed for index %d", i);
		}
	}
	log_debug("blacklist", "testing complete");
	*/
	return 0;
}
Beispiel #3
0
problem_t *problem_init(const char *filename) {

    problem_t *p = NULL;
    FILE *f = NULL;
//    char *str = NULL;
	constraint_t *tmpConstraint = NULL;
	long temp = 0;
	long tmp1 = 0, tmp2 = 0, tmp3 = 0;
	list_t *tmpList = NULL;
	var_t *tmpVar = NULL;
	size_t i = 0;

    if (filename == NULL)
        return NULL;

    f = fopen(filename, "r");
	if (f == NULL) {
		printf("Impossible d'ouvrir le fichier");
		return NULL;
	}

	printf("Le fichier a bien ete ouvert");

    p = (problem_t*) malloc(sizeof(problem_t));
    if (p == NULL) {
        fclose(f);

        return NULL;
    }


    p->name = string_init(NULL);
    if (p->name == NULL) {
        fclose(f);
        free(p);
        return NULL;
    }

    p->name->str = (char*) malloc((strlen(filename) - 3) * sizeof(char));
    if (p->name->str == NULL) {
        string_free(p->name);
        fclose(f);
        free(p);

        return NULL;
    }

    p->n_vars = 0;
    p->vars = NULL;
    p->n_constraints = 0;
    p->constraints = NULL;

	fscanf(f, "%ld", &temp);
	// Lecture des variables/domaines de définitions
	do
	{
		if (temp > 0)
		{
			tmpVar = var_init((u64) temp);						// On Récupère le nom
			fscanf(f, "%ld", &temp);							// On lit le suivant

            do {											//
				var_add_to_definition(tmpVar, (u64) temp);		//
				fscanf(f, "%ld", &temp);						// On lit le suivant
			} while (temp != -1);							// On continue jusqu'à -1 (fin de la ligne)

			problem_add_var(p, tmpVar);						// On ajoute au problème
            fscanf(f, "%ld", &temp);
		}
	} while (temp != -2);
	
	for (i = 0; i < p->n_vars; i++)
		fprintf(stdout, "%lu ; ", p->vars[i]->name);
	fprintf(stdout, "\n");

	// On termine la lecture des variables par un -2
	fscanf(f, "%ld", &temp);									// Puis on commence la lecture des contraintes

	do
	{
		fscanf(f, "%ld", &tmp1);								// On lit l'operateur
		fscanf(f, "%ld", &tmp2);								// On lit la 2ème opérande
		fscanf(f, "%ld", &tmp3);								// Et on récupère son type (var ou scalaire)

		tmpConstraint = constraint_init(var_init(temp), (u64) tmp1, (u64) tmp2, (u64) tmp3);

		problem_add_constraint(p, tmpConstraint);			// Puis on l'ajoute au problème
		
        fscanf(f, "%ld", &temp);
	} while (temp != -3);									// Et ça se termine par un -3


    fclose(f);
	fprintf(stdout, " \nLe fichier a bien ete ferme\n");

	free(tmpConstraint);
	free(tmpList);
	free(tmpVar);

    return p;
}