Exemple #1
0
static int
run_tests(const char *snapshot_file, enum test_methods method)
{
	struct group_test_data td, td_snap, td_2pass;
	int rv;

	TEST_DATA_INIT(group, &td, clone_group, free_group);
	TEST_DATA_INIT(group, &td_snap, clone_group, free_group);
	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				printf("can't access the file %s\n",
				    snapshot_file);

				rv = -1;
				goto fin;
			}
		} else {
			if (method == TEST_BUILD_SNAPSHOT) {
				rv = 0;
				goto fin;
			}

			TEST_SNAPSHOT_FILE_READ(group, snapshot_file,
				&td_snap, group_read_snapshot_func);
		}
	}

	rv = group_fill_test_data(&td);
	if (rv == -1)
		return (-1);
	switch (method) {
	case TEST_GETGRNAM:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td,
				group_test_getgrnam, (void *)&td);
		else
			rv = DO_1PASS_TEST(group, &td_snap,
				group_test_getgrnam, (void *)&td_snap);
		break;
	case TEST_GETGRGID:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td,
				group_test_getgrgid, (void *)&td);
		else
			rv = DO_1PASS_TEST(group, &td_snap,
				group_test_getgrgid, (void *)&td_snap);
		break;
	case TEST_GETGRENT:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td, group_test_getgrent,
				(void *)&td);
		else
			rv = DO_2PASS_TEST(group, &td, &td_snap,
				compare_group, NULL);
		break;
	case TEST_GETGRENT_2PASS:
			TEST_DATA_INIT(group, &td_2pass, clone_group, free_group);
			rv = group_fill_test_data(&td_2pass);
			if (rv != -1)
				rv = DO_2PASS_TEST(group, &td, &td_2pass,
					compare_group, NULL);
			TEST_DATA_DESTROY(group, &td_2pass);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL)
			rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td,
			    sdump_group);
		break;
	default:
		rv = 0;
		break;
	}

fin:
	TEST_DATA_DESTROY(group, &td_snap);
	TEST_DATA_DESTROY(group, &td);

	return (rv);
}
Exemple #2
0
int
main(int argc, char **argv)
{
    struct protoent_test_data td, td_snap, td_2pass;
    char *snapshot_file;
    int rv;
    int c;

    if (argc < 2)
        usage();

    snapshot_file = NULL;
    while ((c = getopt(argc, argv, "nve2ds:")) != -1)
        switch (c) {
        case 'd':
            debug++;
            break;
        case 'n':
            method = TEST_GETPROTOBYNAME;
            break;
        case 'v':
            method = TEST_GETPROTOBYNUMBER;
            break;
        case 'e':
            method = TEST_GETPROTOENT;
            break;
        case '2':
            method = TEST_GETPROTOENT_2PASS;
            break;
        case 's':
            snapshot_file = strdup(optarg);
            break;
        default:
            usage();
        }

    TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
    TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
    if (snapshot_file != NULL) {
        if (access(snapshot_file, W_OK | R_OK) != 0) {
            if (errno == ENOENT)
                method = TEST_BUILD_SNAPSHOT;
            else {
                if (debug)
                    printf("can't access the file %s\n",
                           snapshot_file);

                rv = -1;
                goto fin;
            }
        } else {
            if (method == TEST_BUILD_SNAPSHOT) {
                rv = 0;
                goto fin;
            }

            TEST_SNAPSHOT_FILE_READ(protoent, snapshot_file,
                                    &td_snap, protoent_read_snapshot_func);
        }
    }

    rv = protoent_fill_test_data(&td);
    if (rv == -1)
        return (-1);
    switch (method) {
    case TEST_GETPROTOBYNAME:
        if (snapshot_file == NULL)
            rv = DO_1PASS_TEST(protoent, &td,
                               protoent_test_getprotobyname, (void *)&td);
        else
            rv = DO_1PASS_TEST(protoent, &td_snap,
                               protoent_test_getprotobyname, (void *)&td_snap);
        break;
    case TEST_GETPROTOBYNUMBER:
        if (snapshot_file == NULL)
            rv = DO_1PASS_TEST(protoent, &td,
                               protoent_test_getprotobynumber, (void *)&td);
        else
            rv = DO_1PASS_TEST(protoent, &td_snap,
                               protoent_test_getprotobynumber, (void *)&td_snap);
        break;
    case TEST_GETPROTOENT:
        if (snapshot_file == NULL)
            rv = DO_1PASS_TEST(protoent, &td,
                               protoent_test_getprotoent, (void *)&td);
        else
            rv = DO_2PASS_TEST(protoent, &td, &td_snap,
                               compare_protoent, NULL);
        break;
    case TEST_GETPROTOENT_2PASS:
        TEST_DATA_INIT(protoent, &td_2pass, clone_protoent,
                       free_protoent);
        rv = protoent_fill_test_data(&td_2pass);
        if (rv != -1)
            rv = DO_2PASS_TEST(protoent, &td, &td_2pass,
                               compare_protoent, NULL);
        TEST_DATA_DESTROY(protoent, &td_2pass);
        break;
    case TEST_BUILD_SNAPSHOT:
        if (snapshot_file != NULL)
            rv = TEST_SNAPSHOT_FILE_WRITE(protoent, snapshot_file, &td,
                                          sdump_protoent);
        break;
    default:
        rv = 0;
        break;
    };

fin:
    TEST_DATA_DESTROY(protoent, &td_snap);
    TEST_DATA_DESTROY(protoent, &td);
    free(snapshot_file);
    return (rv);
}
Exemple #3
0
int
main(int argc, char **argv)
{
	struct hostent_test_data td, td_addr, td_snap;
	char *snapshot_file, *hostlist_file;
	res_state statp;	
	int rv;
	int c;
	
	if (argc < 2)
		usage();
		
	snapshot_file = NULL;
	hostlist_file = NULL;
	while ((c = getopt(argc, argv, "nad2iod46mAcMs:f:")) != -1)
		switch (c) {
		case '4':
			af_type = AF_INET;
			break;
		case '6':
			af_type = AF_INET6;
			break;
		case 'M':
			af_type = AF_INET6;
			use_ipv6_mapping = 1;
			ipnode_flags |= AI_V4MAPPED_CFG;
			break;
		case 'm':
			af_type = AF_INET6;
			use_ipv6_mapping = 1;
			ipnode_flags |= AI_V4MAPPED;
			break;
		case 'c':
			ipnode_flags |= AI_ADDRCONFIG;
			break;
		case 'A':
			ipnode_flags |= AI_ALL;
			break;
		case 'o':
			use_ipnode_functions = 1;
			break;
		case 'd':
			debug = 1;
			break;
		case 'n':
			method = TEST_GETHOSTBYNAME2;
			break;
		case 'a':
			method = TEST_GETHOSTBYADDR;
			break;
		case '2':
			method = TEST_GETHOSTBYNAME2_GETADDRINFO;
			break;
		case 'i':
			method = TEST_GETHOSTBYADDR_GETNAMEINFO;
			break;
		case 's':
			snapshot_file = strdup(optarg);
			break;
		case 'f':
			hostlist_file = strdup(optarg);
			break;
		default:
			usage();
		}

	if (use_ipnode_functions == 0) {
		statp = __res_state();
		if ((statp == NULL) || ((statp->options & RES_INIT) == 0 && 
			res_ninit(statp) == -1)) {
			if (debug)
			    printf("error: can't init res_state\n");
			
			free(snapshot_file);
			free(hostlist_file);
			return (-1);
		}
	
		if (use_ipv6_mapping == 0)	
			statp->options &= ~RES_USE_INET6;
		else
			statp->options |= RES_USE_INET6;
	}
	
	TEST_DATA_INIT(hostent, &td, clone_hostent, free_hostent);
	TEST_DATA_INIT(hostent, &td_addr, clone_hostent, free_hostent);
	TEST_DATA_INIT(hostent, &td_snap, clone_hostent, free_hostent);
			
	if (hostlist_file == NULL)
		usage();
	
	if (access(hostlist_file, R_OK) != 0) {
		if (debug)
			printf("can't access the hostlist file %s\n",
				hostlist_file);
		
		usage();
	}
	
	if (debug)
		printf("building host lists from %s\n", hostlist_file);

	rv = TEST_SNAPSHOT_FILE_READ(hostent, hostlist_file, &td,
		hostent_read_hostlist_func);
	if (rv != 0)
		goto fin;
	
	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {		
			if (errno == ENOENT) {
				if (method != TEST_GETHOSTBYADDR)
					method = TEST_BUILD_SNAPSHOT;
				else
					method = TEST_BUILD_ADDR_SNAPSHOT;
			} else {
				if (debug)
				    printf("can't access the snapshot file %s\n",
				    snapshot_file);
			
				rv = -1;
				goto fin;
			}
		} else {
			rv = TEST_SNAPSHOT_FILE_READ(hostent, snapshot_file,
				&td_snap, hostent_read_snapshot_func);
			if (rv != 0) {
				if (debug)
					printf("error reading snapshot file\n");
				goto fin;
			}
		}
	}
		
	switch (method) {
	case TEST_GETHOSTBYNAME2:
		if (snapshot_file != NULL)
			rv = DO_2PASS_TEST(hostent, &td, &td_snap,
				compare_hostent, NULL);
		break;
	case TEST_GETHOSTBYADDR:
		rv = DO_1PASS_TEST(hostent, &td,
			hostent_test_gethostbyaddr, (void *)&td_addr);

		if (snapshot_file != NULL)
			rv = DO_2PASS_TEST(hostent, &td_addr, &td_snap, 
				compare_hostent, NULL);
		break;
	case TEST_GETHOSTBYNAME2_GETADDRINFO:
		rv = DO_1PASS_TEST(hostent, &td,
			hostent_test_getaddrinfo_eq, NULL);
		break;
	case TEST_GETHOSTBYADDR_GETNAMEINFO:
		rv = DO_1PASS_TEST(hostent, &td,
			hostent_test_getnameinfo_eq, NULL);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL) {
		    rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, &td, 
			sdump_hostent);
		}
		break;
	case TEST_BUILD_ADDR_SNAPSHOT:
		if (snapshot_file != NULL) {
			rv = DO_1PASS_TEST(hostent, &td,
				hostent_test_gethostbyaddr, (void *)&td_addr);
			
		    rv = TEST_SNAPSHOT_FILE_WRITE(hostent, snapshot_file, 
			&td_addr, sdump_hostent);
		}
		break;
	default:
		rv = 0;
		break;
	};

fin:
	TEST_DATA_DESTROY(hostent, &td_snap);
	TEST_DATA_DESTROY(hostent, &td_addr);
	TEST_DATA_DESTROY(hostent, &td);
	free(hostlist_file);
	free(snapshot_file);

	return (rv);
}
Exemple #4
0
int
run_tests(const char *snapshot_file, enum test_methods method)
{
	struct usershell_test_data td, td_snap;
	struct usershell ushell;
	int rv;

	rv = 0;

	TEST_DATA_INIT(usershell, &td, clone_usershell, free_usershell);
	TEST_DATA_INIT(usershell, &td_snap, clone_usershell, free_usershell);

	setusershell();
	while ((ushell.path = getusershell()) != NULL) {
		printf("usershell found:\n");
		dump_usershell(&ushell);
		TEST_DATA_APPEND(usershell, &td, &ushell);
	}
	endusershell();

	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				printf("can't access the snapshot file %s\n",
				    snapshot_file);

				rv = -1;
				goto fin;
			}
		} else {
			rv = TEST_SNAPSHOT_FILE_READ(usershell, snapshot_file,
				&td_snap, usershell_read_snapshot_func);
			if (rv != 0) {
				printf("error reading snapshot file\n");
				goto fin;
			}
		}
	}

	switch (method) {
	case TEST_GETUSERSHELL:
		rv = DO_2PASS_TEST(usershell, &td, &td_snap,
			compare_usershell, NULL);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL) {
			rv = TEST_SNAPSHOT_FILE_WRITE(usershell, snapshot_file,
			    &td, sdump_usershell);
		}
		break;
	default:
		rv = 0;
		break;
	}

fin:
	TEST_DATA_DESTROY(usershell, &td_snap);
	TEST_DATA_DESTROY(usershell, &td);

	return (rv);
}
Exemple #5
0
int
main(int argc, char **argv)
{
	struct group_test_data td, td_snap, td_2pass;
	char *snapshot_file;
	int rv;
	int c;
	
	if (argc < 2)
		usage();
		
	snapshot_file = NULL;
	while ((c = getopt(argc, argv, "nge2ds:")) != -1)
		switch (c) {
		case 'd':
			debug++;
			break;
		case 'n':
			method = TEST_GETGRNAM;
			break;
		case 'g':
			method = TEST_GETGRGID;
			break;
		case 'e':
			method = TEST_GETGRENT;
			break;
		case '2':
			method = TEST_GETGRENT_2PASS;
			break;
		case 's':
			snapshot_file = strdup(optarg);
			break;
		default:
			usage();
		}
	
	TEST_DATA_INIT(group, &td, clone_group, free_group);
	TEST_DATA_INIT(group, &td_snap, clone_group, free_group);
	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {		
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				if (debug)
					printf("can't access the file %s\n",
				snapshot_file);
			
				rv = -1;
				goto fin;
			}
		} else {
			if (method == TEST_BUILD_SNAPSHOT) {
				rv = 0;
				goto fin;
			}
			
			TEST_SNAPSHOT_FILE_READ(group, snapshot_file,
				&td_snap, group_read_snapshot_func);
		}
	}
		
	rv = group_fill_test_data(&td);
	if (rv == -1)
		return (-1);
	switch (method) {
	case TEST_GETGRNAM:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td,
				group_test_getgrnam, (void *)&td);
		else
			rv = DO_1PASS_TEST(group, &td_snap, 
				group_test_getgrnam, (void *)&td_snap);
		break;
	case TEST_GETGRGID:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td,
				group_test_getgrgid, (void *)&td);
		else
			rv = DO_1PASS_TEST(group, &td_snap, 
				group_test_getgrgid, (void *)&td_snap);
		break;
	case TEST_GETGRENT:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(group, &td, group_test_getgrent,
				(void *)&td);
		else
			rv = DO_2PASS_TEST(group, &td, &td_snap,
				compare_group, NULL);
		break;
	case TEST_GETGRENT_2PASS:
			TEST_DATA_INIT(group, &td_2pass, clone_group, free_group);
			rv = group_fill_test_data(&td_2pass);			
			if (rv != -1)
				rv = DO_2PASS_TEST(group, &td, &td_2pass,
					compare_group, NULL);
			TEST_DATA_DESTROY(group, &td_2pass);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL)
		    rv = TEST_SNAPSHOT_FILE_WRITE(group, snapshot_file, &td, 
			sdump_group);
		break;
	default:
		rv = 0;
		break;
	};

fin:
	TEST_DATA_DESTROY(group, &td_snap);
	TEST_DATA_DESTROY(group, &td);
	free(snapshot_file);	
	return (rv);
}
Exemple #6
0
int
run_tests(const char *snapshot_file, enum test_methods method)
{
	struct rpcent_test_data td, td_snap, td_2pass;
	int rv;

	TEST_DATA_INIT(rpcent, &td, clone_rpcent, free_rpcent);
	TEST_DATA_INIT(rpcent, &td_snap, clone_rpcent, free_rpcent);
	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				printf("can't access the file %s\n",
				    snapshot_file);

				rv = -1;
				goto fin;
			}
		} else {
			if (method == TEST_BUILD_SNAPSHOT) {
				rv = 0;
				goto fin;
			}

			TEST_SNAPSHOT_FILE_READ(rpcent, snapshot_file,
				&td_snap, rpcent_read_snapshot_func);
		}
	}

	rv = rpcent_fill_test_data(&td);
	if (rv == -1)
		return (-1);
	switch (method) {
	case TEST_GETRPCBYNAME:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(rpcent, &td,
				rpcent_test_getrpcbyname, (void *)&td);
		else
			rv = DO_1PASS_TEST(rpcent, &td_snap,
				rpcent_test_getrpcbyname, (void *)&td_snap);
		break;
	case TEST_GETRPCBYNUMBER:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(rpcent, &td,
				rpcent_test_getrpcbynumber, (void *)&td);
		else
			rv = DO_1PASS_TEST(rpcent, &td_snap,
				rpcent_test_getrpcbynumber, (void *)&td_snap);
		break;
	case TEST_GETRPCENT:
		if (snapshot_file == NULL)
			rv = DO_1PASS_TEST(rpcent, &td, rpcent_test_getrpcent,
				(void *)&td);
		else
			rv = DO_2PASS_TEST(rpcent, &td, &td_snap,
				compare_rpcent, NULL);
		break;
	case TEST_GETRPCENT_2PASS:
			TEST_DATA_INIT(rpcent, &td_2pass, clone_rpcent, free_rpcent);
			rv = rpcent_fill_test_data(&td_2pass);
			if (rv != -1)
				rv = DO_2PASS_TEST(rpcent, &td, &td_2pass,
					compare_rpcent, NULL);
			TEST_DATA_DESTROY(rpcent, &td_2pass);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL)
		    rv = TEST_SNAPSHOT_FILE_WRITE(rpcent, snapshot_file, &td,
			sdump_rpcent);
		break;
	default:
		rv = 0;
		break;
	}

fin:
	TEST_DATA_DESTROY(rpcent, &td_snap);
	TEST_DATA_DESTROY(rpcent, &td);

	return (rv);
}
int
main(int argc, char **argv)
{
	struct addrinfo_test_data td, td_snap;
	char *snapshot_file, *hostlist_file;
	int rv;
	int c;

	if (argc < 2)
		usage();

	snapshot_file = NULL;
	hostlist_file = NULL;
	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = PF_UNSPEC;
	hints.ai_flags = AI_CANONNAME;
	while ((c = getopt(argc, argv, "46dns:f:")) != -1)
		switch (c) {
		case '4':
			hints.ai_family = PF_INET;
			break;
		case '6':
			hints.ai_family = PF_INET6;
			break;
		case 'd':
			debug = 1;
			break;
		case 's':
			snapshot_file = strdup(optarg);
			method = TEST_BUILD_SNAPSHOT;
			break;
		case 'f':
			hostlist_file = strdup(optarg);
			break;
		default:
			usage();
		}

	TEST_DATA_INIT(addrinfo, &td, clone_addrinfo, free_addrinfo);
	TEST_DATA_INIT(addrinfo, &td_snap, clone_addrinfo, free_addrinfo);

	if (hostlist_file == NULL)
		usage();

	if (access(hostlist_file, R_OK) != 0) {
		if (debug)
			printf("can't access the hostlist file %s\n",
				hostlist_file);

		usage();
	}

	if (debug)
		printf("building host lists from %s\n", hostlist_file);

	rv = TEST_SNAPSHOT_FILE_READ(addrinfo, hostlist_file, &td,
		addrinfo_read_hostlist_func);
	if (rv != 0)
		goto fin;

	if (snapshot_file != NULL) {
		if (access(snapshot_file, W_OK | R_OK) != 0) {
			if (errno == ENOENT)
				method = TEST_BUILD_SNAPSHOT;
			else {
				if (debug)
				    printf("can't access the snapshot file %s\n",
				    snapshot_file);

				rv = -1;
				goto fin;
			}
		} else {
			rv = TEST_SNAPSHOT_FILE_READ(addrinfo, snapshot_file,
				&td_snap, addrinfo_read_snapshot_func);
			if (rv != 0) {
				if (debug)
					printf("error reading snapshot file\n");
				goto fin;
			}
		}
	}

	switch (method) {
	case TEST_GETADDRINFO:
		if (snapshot_file != NULL)
			rv = DO_2PASS_TEST(addrinfo, &td, &td_snap,
				compare_addrinfo, NULL);
		break;
	case TEST_BUILD_SNAPSHOT:
		if (snapshot_file != NULL) {
		    rv = TEST_SNAPSHOT_FILE_WRITE(addrinfo, snapshot_file, &td,
			sdump_addrinfo);
		}
		break;
	default:
		rv = 0;
		break;
	};

fin:
	TEST_DATA_DESTROY(addrinfo, &td_snap);
	TEST_DATA_DESTROY(addrinfo, &td);
	free(hostlist_file);
	free(snapshot_file);
	return (rv);

}