static void uidcache_create(void) { if ((auth_caching & PR_AUTH_CACHE_FL_UID2NAME) && !uid_tab && auth_pool) { int ok = TRUE; uid_tab = pr_table_alloc(auth_pool, 0); if (pr_table_ctl(uid_tab, PR_TABLE_CTL_SET_KEY_CMP, uid_keycmp_cb) < 0) { pr_trace_msg(trace_channel, 2, "error setting key comparison callback for uidcache: %s", strerror(errno)); ok = FALSE; } if (pr_table_ctl(uid_tab, PR_TABLE_CTL_SET_KEY_HASH, uid_hash_cb) < 0) { pr_trace_msg(trace_channel, 2, "error setting key hash callback for uidcache: %s", strerror(errno)); ok = FALSE; } if (!ok) { pr_trace_msg(trace_channel, 2, "%s", "destroying unusable uidcache table"); pr_table_free(uid_tab); uid_tab = NULL; } } }
END_TEST START_TEST (uri_parse_params_test) { int res; const char *uri; char *host = NULL, *path = NULL, *username, *password; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "sql://castaglia.org?foo"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); pr_table_empty(params); uri = "sql://castaglia.org?foo="; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); res = pr_table_count(params); fail_unless(res == 1, "Expected 1 parameter, got %d", res); mark_point(); uri = "sql://castaglia.org?foo=&"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql://castaglia.org?foo=bar&foo=baz"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); res = pr_table_count(params); fail_unless(res == 1, "Expected 1 parameter, got %d", res); mark_point(); uri = "sql://castaglia.org?foo=bar&baz=quxx&foo=baz"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); res = pr_table_count(params); fail_unless(res == 2, "Expected 2 parameters, got %d", res); pr_table_empty(params); pr_table_free(params); }
END_TEST START_TEST (uri_parse_port_test) { int res; const char *uri; char *host = NULL, *path = NULL, *username = NULL, *password = NULL; unsigned int expected, port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "sql://castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(port == 0, "Failed to parse port out of URI '%s'", uri); mark_point(); uri = "sql://castaglia.org:3567"; expected = 3567; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(port == expected, "Expected %u, got %u", expected, port); mark_point(); uri = "sql://castaglia.org:foo"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s': %s", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql://castaglia.org:0"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s': %s", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql://castaglia.org:70000"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s': %s", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); pr_table_free(params); }
END_TEST START_TEST (uri_parse_path_test) { int res; const char *uri; char *expected, *host = NULL, *path = NULL, *username, *password; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "sql://castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(path == NULL, "Expected null path, got %s", path); mark_point(); uri = "sql://castaglia.org/path"; expected = "/path"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(path != NULL, "Expected path, got null"); fail_unless(strcmp(path, expected) == 0, "Expected '%s', got '%s'", expected, path); mark_point(); uri = "sql://castaglia.org:1234/path/to/resource"; expected = "/path/to/resource"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(path != NULL, "Expected path, got null"); fail_unless(strcmp(path, expected) == 0, "Expected '%s', got '%s'", expected, path); mark_point(); uri = "sql://castaglia.org:1234/path/to/resource?key=val"; expected = "/path/to/resource"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(path != NULL, "Expected path, got null"); fail_unless(strcmp(path, expected) == 0, "Expected '%s', got '%s'", expected, path); pr_table_empty(params); pr_table_free(params); }
int var_free(void) { if (var_pool) { if (var_tab) { pr_table_empty(var_tab); pr_table_free(var_tab); } destroy_pool(var_pool); var_pool = NULL; var_tab = NULL; } return 0; }
void pr_auth_endpwent(pool *p) { cmd_rec *cmd = NULL; cmd = make_cmd(p, 0); (void) dispatch_auth(cmd, "endpwent", NULL); if (cmd->tmp_pool) { destroy_pool(cmd->tmp_pool); cmd->tmp_pool = NULL; } if (auth_tab) { pr_trace_msg(trace_channel, 5, "emptying authcache"); (void) pr_table_empty(auth_tab); (void) pr_table_free(auth_tab); auth_tab = NULL; } return; }
int pr_memcache_conn_close(pr_memcache_t *mcache) { if (mcache == NULL) { errno = EINVAL; return -1; } mcache->refcount--; if (mcache->refcount == 0) { memcached_free(mcache->mc); if (mcache->namespace_tab != NULL) { (void) pr_table_empty(mcache->namespace_tab); (void) pr_table_free(mcache->namespace_tab); mcache->namespace_tab = NULL; } } return 0; }
END_TEST START_TEST (uri_parse_scheme_test) { int res; const char *uri; char *host = NULL, *path = NULL, *username = NULL, *password = NULL; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "foo"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "foobarbaz"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql://"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); pr_table_free(params); }
END_TEST START_TEST (uri_parse_real_uris_test) { int res; const char *uri; char *host = NULL, *path = NULL, *username = NULL, *password = NULL; char *expected; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); host = path = username = password = NULL; port = 0; pr_table_empty(params); uri = "sql://*****:*****@server:12345/dbname"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "server"; fail_unless(host != NULL, "Expected host, got null"); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); expected = "/dbname"; fail_unless(path != NULL, "Expected path, got null"); fail_unless(strcmp(path, expected) == 0, "Expected '%s', got '%s'", expected, path); expected = "user"; fail_unless(username != NULL, "Expected username, got null"); fail_unless(strcmp(username, expected) == 0, "Expected '%s', got '%s'", expected, username); expected = "pass"; fail_unless(password != NULL, "Expected password, got null"); fail_unless(strcmp(password, expected) == 0, "Expected '%s', got '%s'", expected, password); fail_unless(port == 12345, "Expected 12345, got %u", port); res = pr_table_count(params); fail_unless(res == 0, "Expected 0 parameters, got %d", res); mark_point(); host = path = username = password = NULL; port = 0; pr_table_empty(params); uri = "sql:///path/to/sqlite.db?database=dbname"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "/path/to/sqlite.db"; fail_unless(host != NULL, "Expected host, got null"); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); fail_unless(path == NULL, "Expected null, got path '%s'", path); fail_unless(username == NULL, "Expected null, got username '%s'", username); fail_unless(password == NULL, "Expected null, got password '%s'", password); fail_unless(port == 0, "Expected 0, got %u", port); res = pr_table_count(params); fail_unless(res == 1, "Expected 1 parameter, got %d", res); /* Note that this will not parse as expected. Using an absolute path as * the hostname makes it hard to determine the URL path, as the same * path separators are used. */ mark_point(); host = path = username = password = NULL; port = 0; pr_table_empty(params); uri = "sql:///path/to/sqlite.db/dbname"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "/path/to/sqlite.db/dbname"; fail_unless(host != NULL, "Expected host, got null"); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); fail_unless(path == NULL, "Expected null, got path '%s'", path); fail_unless(username == NULL, "Expected null, got username '%s'", username); fail_unless(password == NULL, "Expected null, got password '%s'", password); fail_unless(port == 0, "Expected 0, got %u", port); res = pr_table_count(params); fail_unless(res == 0, "Expected 0 parameters, got %d", res); mark_point(); host = path = username = password = NULL; port = 0; pr_table_empty(params); uri = "sql://*****:*****@localhost?database=proftpd&ctx=vhostctx&conf=vhostconf&map=vhostmap&base_id=7"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "localhost"; fail_unless(host != NULL, "Expected host, got null"); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); fail_unless(path == NULL, "Expected null, got path '%s'", path); expected = "foo"; fail_unless(username != NULL, "Expected username, got null"); fail_unless(strcmp(username, expected) == 0, "Expected '%s', got '%s'", expected, username); expected = "bar"; fail_unless(password != NULL, "Expected password, got null"); fail_unless(strcmp(password, expected) == 0, "Expected '%s', got '%s'", expected, password); fail_unless(port == 0, "Expected 0, got %u", port); res = pr_table_count(params); fail_unless(res == 5, "Expected 5 parameters, got %d", res); mark_point(); host = path = username = password = NULL; port = 0; pr_table_empty(params); uri = "sql:///Users/tj/git/proftpd-mod_conf_sql/proftpd.db?ctx=ftpctx:id,parent_id,name,type,value&conf=ftpconf:id,type,value"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "/Users/tj/git/proftpd-mod_conf_sql/proftpd.db"; fail_unless(host != NULL, "Expected host, got null"); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); fail_unless(path == NULL, "Expected null, got path '%s'", path); fail_unless(username == NULL, "Expected null, got username"); fail_unless(password == NULL, "Expected null, got password"); fail_unless(port == 0, "Expected 0, got %u", port); res = pr_table_count(params); fail_unless(res == 2, "Expected 2 parameters, got %d", res); pr_table_empty(params); pr_table_free(params); }
END_TEST START_TEST (uri_parse_userinfo_test) { int res; const char *uri; char *expected, *host = NULL, *path, *username = NULL, *password = NULL; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "sql://castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(username == NULL, "Expected null username, got %s", username); fail_unless(password == NULL, "Expected null password, got %s", password); mark_point(); uri = "sql://[email protected]"; expected = "user"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(username == NULL, "Expected null username, got %s", username); fail_unless(password == NULL, "Expected null password, got %s", password); mark_point(); uri = "sql://*****:*****@castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "user"; fail_unless(username != NULL, "Expected username, got null"); fail_unless(strcmp(username, expected) == 0, "Expected '%s', got '%s'", expected, username); expected = "pass"; fail_unless(password != NULL, "Expected password, got null"); fail_unless(strcmp(password, expected) == 0, "Expected '%s', got '%s'", expected, password); mark_point(); uri = "sql://user:@castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); expected = "user"; fail_unless(username != NULL, "Expected username, got null"); fail_unless(strcmp(username, expected) == 0, "Expected '%s', got '%s'", expected, username); expected = ""; fail_unless(password != NULL, "Expected password, got null"); fail_unless(strcmp(password, expected) == 0, "Expected '%s', got '%s'", expected, password); mark_point(); uri = "sql://@castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to handle parse URI '%s': %s", uri, strerror(errno)); fail_unless(username == NULL, "Expected null username, got %s", username); fail_unless(password == NULL, "Expected null password, got %s", password); pr_table_free(params); }
END_TEST START_TEST (uri_parse_host_test) { int res; const char *uri; char *expected, *host = NULL, *path, *username = NULL, *password = NULL; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "sql://castaglia.org"; expected = "castaglia.org"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(host != NULL, "Failed to parse host out of URI '%s'", uri); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); mark_point(); uri = "sql://127.0.0.1"; expected = "127.0.0.1"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(host != NULL, "Failed to parse host out of URI '%s'", uri); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); mark_point(); uri = "sql://[::1]"; expected = "::1"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(host != NULL, "Failed to parse host out of URI '%s'", uri); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); mark_point(); uri = "sql://[::1"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Parsed URI '%s' unexpectedly", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql:///path/to/some/file"; expected = "/path/to/some/file"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res == 0, "Failed to parse URI '%s': %s", uri, strerror(errno)); fail_unless(host != NULL, "Failed to parse host out of URI '%s'", uri); fail_unless(strcmp(host, expected) == 0, "Expected '%s', got '%s'", expected, host); pr_table_free(params); }
static int log_failure_mkfields(pool *p) { pr_table_t *fields; fields = pr_table_alloc(p, 0); if (pr_table_ctl(fields, PR_TABLE_CTL_SET_KEY_CMP, (void *) field_id_cmp) < 0) { int xerrno = errno; pr_log_pri(PR_LOG_INFO, "error setting key comparison callback for " "field ID/names: %s", strerror(errno)); pr_table_free(fields); errno = xerrno; return -1; } if (pr_table_ctl(fields, PR_TABLE_CTL_SET_KEY_HASH, (void *) field_id_hash) < 0) { int xerrno = errno; pr_log_pri(PR_LOG_INFO, "error setting key hash callback for " "field ID/names: %s", strerror(errno)); pr_table_free(fields); errno = xerrno; return -1; } /* Now populate the table with the ID/name values. The key is the * LogFormat "meta" ID, and the value is the corresponding name string, * for use e.g. as JSON object member names. */ field_add(p, fields, LOGFMT_META_BYTES_SENT, "bytes_sent", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_FILENAME, "file", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_ENV_VAR, "ENV:", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_REMOTE_HOST, "remote_dns", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_REMOTE_IP, "remote_ip", LOG_FAILURE_FIELD_TYPE_STRING); #if defined(LOGFMT_META_REMOTE_PORT) field_add(p, fields, LOGFMT_META_REMOTE_PORT, "remote_port", LOG_FAILURE_FIELD_TYPE_NUMBER); #endif /* LOGFMT_META_REMOTE_PORT */ field_add(p, fields, LOGFMT_META_IDENT_USER, "identd_user", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_PID, "pid", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_TIME, "local_time", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_SECONDS, "transfer_secs", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_COMMAND, "raw_command", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_LOCAL_NAME, "server_name", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_LOCAL_PORT, "local_port", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_LOCAL_IP, "local_ip", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_LOCAL_FQDN, "server_dns", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_USER, "user", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_ORIGINAL_USER, "original_user", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_RESPONSE_CODE, "response_code", LOG_FAILURE_FIELD_TYPE_NUMBER); #if defined(LOGFMT_META_RESPONSE_MS) field_add(p, fields, LOGFMT_META_RESPONSE_MS, "response_ms", LOG_FAILURE_FIELD_TYPE_NUMBER); #endif /* LOGFMT_META_RESPONSE_MS */ field_add(p, fields, LOGFMT_META_CLASS, "connection_class", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_ANON_PASS, "anon_password", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_METHOD, "command", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_XFER_PATH, "transfer_path", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_DIR_NAME, "dir_name", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_DIR_PATH, "dir_path", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_CMD_PARAMS, "command_params", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_RESPONSE_STR, "response_msg", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_PROTOCOL, "protocol", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_VERSION, "server_version", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_RENAME_FROM, "rename_from", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_FILE_MODIFIED, "file_modified", LOG_FAILURE_FIELD_TYPE_BOOLEAN); field_add(p, fields, LOGFMT_META_UID, "uid", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_GID, "gid", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_RAW_BYTES_IN, "session_bytes_rcvd", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_RAW_BYTES_OUT, "session_bytes_sent", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_EOS_REASON, "session_end_reason", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_VHOST_IP, "server_ip", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_NOTE_VAR, "NOTE:", LOG_FAILURE_FIELD_TYPE_STRING); #if defined(LOGFMT_META_XFER_MS) field_add(p, fields, LOGFMT_META_XFER_MS, "transfer_ms", LOG_FAILURE_FIELD_TYPE_NUMBER); #endif /* LOGFMT_META_XFER_MS */ field_add(p, fields, LOGFMT_META_XFER_STATUS, "transfer_status", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_XFER_FAILURE, "transfer_failure", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_MICROSECS, "microsecs", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_MILLISECS, "millisecs", LOG_FAILURE_FIELD_TYPE_NUMBER); field_add(p, fields, LOGFMT_META_ISO8601, "timestamp", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOGFMT_META_GROUP, "group", LOG_FAILURE_FIELD_TYPE_STRING); field_add(p, fields, LOG_FAILURE_META_CONNECT, "connecting", LOG_FAILURE_FIELD_TYPE_BOOLEAN); field_add(p, fields, LOG_FAILURE_META_DISCONNECT, "disconnecting", LOG_FAILURE_FIELD_TYPE_BOOLEAN); log_failure_fields = fields; return 0; }
int proxy_db_close(pool *p, const char *schema_name) { if (p == NULL) { errno = EINVAL; return -1; } if (proxy_dbh != NULL) { pool *tmp_pool; sqlite3_stmt *pstmt; int res; tmp_pool = make_sub_pool(p); /* If we're given a schema name, then just detach that schema from the * database handle. */ if (schema_name != NULL) { const char *stmt; stmt = pstrcat(tmp_pool, "DETACH DATABASE ", schema_name, ";", NULL); res = sqlite3_exec(proxy_dbh, stmt, NULL, NULL, NULL); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error detaching '%s' from existing SQLite handle using '%s': %s", schema_name, stmt, sqlite3_errmsg(proxy_dbh)); destroy_pool(tmp_pool); errno = EPERM; return -1; } destroy_pool(tmp_pool); return 0; } /* Make sure to close/finish any prepared statements associated with * the database. */ pstmt = sqlite3_next_stmt(proxy_dbh, NULL); while (pstmt != NULL) { sqlite3_stmt *next; const char *sql; pr_signals_handle(); next = sqlite3_next_stmt(proxy_dbh, pstmt); sql = pstrdup(tmp_pool, sqlite3_sql(pstmt)); res = sqlite3_finalize(pstmt); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error finishing prepared statement '%s': %s", sql, sqlite3_errmsg(proxy_dbh)); } else { pr_trace_msg(trace_channel, 18, "finished prepared statement '%s'", sql); } pstmt = next; } destroy_pool(tmp_pool); res = sqlite3_close(proxy_dbh); if (res != SQLITE_OK) { pr_trace_msg(trace_channel, 2, "error closing SQLite database: %s", sqlite3_errmsg(proxy_dbh)); errno = EPERM; return -1; } pr_trace_msg(trace_channel, 18, "%s", "closed SQLite database"); proxy_dbh = NULL; } pr_table_empty(prepared_stmts); pr_table_free(prepared_stmts); prepared_stmts = NULL; return 0; }