static void tear_down(void) { if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(FALSE); } if (p) { destroy_pool(p); p = NULL; } }
static void set_up(void) { if (p == NULL) { p = make_sub_pool(NULL); } if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(TRUE); pr_trace_set_levels("response", 0, 20); } }
static void tear_down(void) { if (p) { destroy_pool(p); p = permanent_pool = NULL; } pr_response_set_pool(NULL); if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(FALSE); } }
static void tear_down(void) { if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(FALSE); pr_trace_set_levels("timers", 0, 0); } if (p) { destroy_pool(p); p = permanent_pool = NULL; } }
static void set_up(void) { if (p == NULL) { p = make_sub_pool(NULL); } init_config(); if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(TRUE); pr_trace_set_levels("filter", 0, 20); } }
static void set_up(void) { if (p == NULL) { p = permanent_pool = make_sub_pool(NULL); } repeat_cb = FALSE; timer_triggered_count = 0; timers_init(); if (getenv("TEST_VERBOSE") != NULL) { pr_trace_use_stderr(TRUE); pr_trace_set_levels("timers", 1, 20); } }
static void set_up(void) { server_rec *s = NULL; if (p == NULL) { p = permanent_pool = make_sub_pool(NULL); } pr_trace_use_stderr(TRUE); init_stash(); init_auth(); s = pcalloc(p, sizeof(server_rec)); tests_stubs_set_main_server(s); test_pwd.pw_name = PR_TEST_AUTH_NAME; test_pwd.pw_uid = PR_TEST_AUTH_UID; test_pwd.pw_gid = PR_TEST_AUTH_GID; test_pwd.pw_dir = PR_TEST_AUTH_HOME; test_pwd.pw_shell = PR_TEST_AUTH_SHELL; test_grp.gr_name = PR_TEST_AUTH_NAME; test_grp.gr_gid = PR_TEST_AUTH_GID; /* Reset counters. */ setpwent_count = 0; endpwent_count = 0; getpwent_count = 0; getpwnam_count = 0; getpwuid_count = 0; name2uid_count = 0; uid2name_count = 0; setgrent_count = 0; endgrent_count = 0; getgrent_count = 0; getgrnam_count = 0; getgrgid_count = 0; name2gid_count = 0; gid2name_count = 0; getgroups_count = 0; pr_auth_cache_clear(); }
int main(int argc, char *argv[]) { const char *log_file = "api-tests.log"; int nfailed = 0; SRunner *runner = NULL; char *requested = NULL; runner = srunner_create(NULL); /* XXX This log name should be set outside this code, e.g. via environment * variable or command-line option. */ srunner_set_log(runner, log_file); requested = getenv("PR_TEST_SUITE"); if (requested) { Suite *suite; suite = tests_get_suite(requested); if (suite) { srunner_add_suite(runner, suite); } else { fprintf(stderr, "No such test suite ('%s') requested via PR_TEST_SUITE\n", requested); return EXIT_FAILURE; } } else { register unsigned int i; for (i = 0; suites[i].name; i++) { Suite *suite; suite = (suites[i].get_suite)(); if (suite) { srunner_add_suite(runner, suite); } } } /* Configure the Trace API to write to stderr. */ pr_trace_use_stderr(TRUE); requested = getenv("PR_TEST_NOFORK"); if (requested) { srunner_set_fork_status(runner, CK_NOFORK); } srunner_run_all(runner, CK_NORMAL); nfailed = srunner_ntests_failed(runner); if (runner) srunner_free(runner); if (nfailed != 0) { fprintf(stderr, "-------------------------------------------------\n"); fprintf(stderr, " FAILED %d %s\n\n", nfailed, nfailed != 1 ? "tests" : "test"); fprintf(stderr, " Please send email to:\n\n"); fprintf(stderr, " [email protected]\n\n"); fprintf(stderr, " containing the `%s' file (in the tests/ directory)\n", log_file); fprintf(stderr, " and the output from running `proftpd -V'\n"); fprintf(stderr, "-------------------------------------------------\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { pool *p; const char *remote_name; pr_netaddr_t *remote_addr; conn_t *client_conn, *ctrl_conn, *data_conn; unsigned int connect_timeout, remote_port; struct proxy_ftp_client *ftp; int res, timerno; char buf[1024]; /* Seed the random number generator. */ /* XXX Use random(3) in the future? */ srand((unsigned int) (time(NULL) * getpid())); init_pools(); init_privs(); init_log(); init_regexp(); init_inet(); init_netio(); init_netaddr(); init_fs(); init_class(); init_config(); init_stash(); pr_log_setdebuglevel(10); log_stderr(TRUE); pr_trace_use_stderr(TRUE); pr_trace_set_levels("DEFAULT", 1, 20); p = make_sub_pool(permanent_pool); pr_pool_tag(p, "FTP Client Pool"); remote_name = "ftp.proftpd.org"; remote_addr = pr_netaddr_get_addr(p, remote_name, NULL); if (remote_addr == NULL) { fprintf(stderr, "Failed to get addr for '%s': %s\n", remote_name, strerror(errno)); destroy_pool(p); return 1; } fprintf(stdout, "Resolved name '%s' to IP address '%s'\n", remote_name, pr_netaddr_get_ipstr(remote_addr)); remote_port = 21; connect_timeout = 5; ftp = proxy_ftp_connect(p, remote_addr, remote_port, connect_timeout, NULL); if (ftp == NULL) { fprintf(stderr, "Error connecting to FTP server: %s\n", strerror(errno)); destroy_pool(p); return 1; } fprintf(stdout, "Successfully connected to %s:%d from %s:%d\n", remote_name, remote_port, pr_netaddr_get_ipstr(client_conn->local_addr), ntohs(pr_netaddr_get_port(client_conn->local_addr))); res = proxy_ftp_disconnect(ftp); if (res < 0) { fprintf(stderr, "Error disconnecting from FTP server: %s\n", strerror(errno)); destroy_pool(p); return 1; } ctrl_conn = pr_inet_openrw(p, client_conn, NULL, PR_NETIO_STRM_OTHR, -1, -1, -1, FALSE); if (ctrl_conn == NULL) { fprintf(stderr, "Error opening control connection: %s\n", strerror(errno)); pr_inet_close(p, client_conn); destroy_pool(p); return 1; } fprintf(stdout, "Reading response from %s:%d\n", remote_name, remote_port); /* Read the response */ memset(buf, '\0', sizeof(buf)); /* XXX We need to write our own version of netio_telnet_gets(), with * the buffering to handle reassembly of a full FTP response out of * multiple TCP packets. Not sure why the existing netio_telnet_gets() * is not sufficient. But we don't need the handling of Telnet codes * in our reading. But DO generate the 'core.ctrl-read' event, so that * any event listeners get a chance to process the data we've received. * (Or maybe use 'mod_proxy.server-read', and differentiate between * client and server reads/writes?) */ if (pr_netio_read(ctrl_conn->instrm, buf, sizeof(buf)-1, 5) < 0) { fprintf(stderr, "Error reading response from server: %s\n", strerror(errno)); } else { fprintf(stdout, "Response: \"%s\"\n", buf); } /* Disconnect */ res = pr_netio_printf(ctrl_conn->outstrm, "%s\r\n", C_QUIT); if (res < 0) { fprintf(stderr, "Error writing command to server: %s", strerror(errno)); } pr_inet_close(p, ctrl_conn); pr_inet_close(p, client_conn); destroy_pool(p); return 0; }