Exemple #1
0
int
main(int argc, char **argv)
{
    char *dirname;
    struct afsconf_dir *dir;
    int code, secIndex;
    pid_t serverPid;
    struct rx_securityClass *secClass;
    struct ubik_client *ubikClient = NULL;
    int ret = 0;

    /* Skip all tests if the current hostname can't be resolved */
    afstest_SkipTestsIfBadHostname();
    /* Skip all tests if the current hostname is on the loopback network */
    afstest_SkipTestsIfLoopbackNetIsDefault();

    plan(6);

    code = rx_Init(0);

    dirname = afstest_BuildTestConfig();

    dir = afsconf_Open(dirname);

    code = afstest_AddDESKeyFile(dir);
    if (code) {
	afs_com_err("vos-t", code, "while adding test DES keyfile");
	ret = 1;
	goto out;
    }

    code = afstest_StartVLServer(dirname, &serverPid);
    if (code) {
	afs_com_err("vos-t", code, "while starting the vlserver");
	ret = 1;
	goto out;
    }

    /* Let it figure itself out ... */
    sleep(5);
    code = afsconf_ClientAuthSecure(dir, &secClass, &secIndex);
    is_int(code, 0, "Successfully got security class");
    if (code) {
	afs_com_err("authname-t", code, "while getting anonymous secClass");
	ret = 1;
	goto out;
    }

    code = afstest_GetUbikClient(dir, AFSCONF_VLDBSERVICE, USER_SERVICE_ID,
				 secClass, secIndex, &ubikClient);
    is_int(code, 0, "Successfully built ubik client structure");
    if (code) {
	afs_com_err("vos-t", code, "while building ubik client");
	ret = 1;
	goto out;
    }

    TestListAddrs(ubikClient, dirname);

    code = afstest_StopServer(serverPid);
    is_int(0, code, "Server exited cleanly");

out:
    afstest_UnlinkTestConfig(dirname);
    return ret;
}
Exemple #2
0
int main(int argc, char **argv)
{
    struct afsconf_dir *dir;
    char *dirname;
    int serverPid, clientPid, waited, stat;
    int code;

    /* Start the client and the server if requested */

    if (argc == 3 ) {
        if (strcmp(argv[1], "-server") == 0) {
	    globalDir = afsconf_Open(argv[2]);
	    afstest_StartTestRPCService(argv[2], TEST_PORT, TEST_SERVICE_ID,
					TEST_ExecuteRequest);
            exit(0);
        } else if (strcmp(argv[1], "-client") == 0) {
            startClient(argv[2]);
            exit(0);
        } else {
            printf("Bad option %s\n", argv[1]);
            exit(1);
        }
    }

    /* Otherwise, do the basic configuration, then start the client and
     * server */

    dirname = afstest_BuildTestConfig();

    dir = afsconf_Open(dirname);
    if (dir == NULL) {
	fprintf(stderr, "Unable to configure directory.\n");
	exit(1);
    }

    code = afstest_AddDESKeyFile(dir);
    if (code) {
	afs_com_err("superuser-t", code, "while adding new key\n");
	exit(1);
    }

    printf("Config directory is %s\n", dirname);
    serverPid = fork();
    if (serverPid == -1) {
        /* Bang */
    } else if (serverPid == 0) {
        execl(argv[0], argv[0], "-server", dirname, NULL);
        exit(1);
    }
    clientPid = fork();
    if (clientPid == -1) {
        kill(serverPid, SIGTERM);
        waitpid(serverPid, &stat, 0);
        exit(1);
    } else if (clientPid == 0) {
        execl(argv[0], argv[0], "-client", dirname, NULL);
    }

    do {
        waited = waitpid(0, &stat, 0);
    } while(waited == -1 && errno == EINTR);

    if (waited == serverPid) {
        kill(clientPid, SIGTERM);
    } else if (waited == clientPid) {
        kill(serverPid, SIGTERM);
    }
    waitpid(0, &stat, 0);

    /* Client and server are both done, so cleanup after everything */

    /* unlinkTestConfig(dirname); */

    return 0;
}