result->arcs = malloc(MAX_ARCS * sizeof(asn_oid_arc_t));
if (result->arcs == NULL)
- return pr_enomem();
+ enomem_panic();
count = OBJECT_IDENTIFIER_get_arcs(oid, result->arcs, MAX_ARCS);
if (count < 0) {
/* If necessary, reallocate arcs array and try again. */
if (count > MAX_ARCS) {
tmp = realloc(result->arcs, count * sizeof(asn_oid_arc_t));
- if (tmp == NULL) {
- free(result->arcs);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
result->arcs = tmp;
count2 = OBJECT_IDENTIFIER_get_arcs(oid, result->arcs, count);
static const OID oid_sta = OID_SIGNING_TIME_ATTR;
static const OID oid_bsta = OID_BINARY_SIGNING_TIME_ATTR;
-int
+void
signed_object_args_init(struct signed_object_args *args,
struct rpki_uri *uri,
STACK_OF(X509_CRL) *crls,
{
args->res = resources_create(force_inherit);
if (args->res == NULL)
- return pr_enomem();
+ enomem_panic();
args->uri = uri;
args->crls = crls;
memset(&args->refs, 0, sizeof(args->refs));
- return 0;
}
void
return error;
sdata = calloc(1, sizeof(struct SignedData));
- if (sdata == NULL) {
- error = pr_enomem();
- goto release_sdata_pkcs7;
- }
+ if (sdata == NULL)
+ enomem_panic();
/* Parse content as OCTET STRING */
error = asn1_decode_any(sdata_pkcs7->encapContentInfo.eContent,
release_sdata:
free(sdata);
-release_sdata_pkcs7:
ASN_STRUCT_FREE(asn_DEF_SignedDataPKCS7, sdata_pkcs7);
return error;
}
struct certificate_refs refs;
};
-int signed_object_args_init(struct signed_object_args *, struct rpki_uri *,
+void signed_object_args_init(struct signed_object_args *, struct rpki_uri *,
STACK_OF(X509_CRL) *, bool);
void signed_object_args_cleanup(struct signed_object_args *);
stack = malloc(sizeof(struct cert_stack));
if (stack == NULL)
- return pr_enomem();
+ enomem_panic();
stack->x509s = sk_X509_new_null();
if (stack->x509s == NULL) {
free(stack);
}
-int
+void
deferstack_push(struct cert_stack *stack, struct deferred_cert *deferred)
{
struct defer_node *node;
node = malloc(sizeof(struct defer_node));
if (node == NULL)
- return pr_enomem();
+ enomem_panic();
node->type = DNT_CERT;
node->deferred = *deferred;
uri_refget(deferred->uri);
rpp_refget(deferred->pp);
SLIST_INSERT_HEAD(&stack->defers, node, next);
- return 0;
}
static void
result = resources_create(false);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
resources_set_policy(result, policy);
error = certificate_get_resources(x509, result, type);
result = malloc(sizeof(struct defer_node));
if (result == NULL)
- return NULL;
+ enomem_panic();
result->type = DNT_SEPARATOR;
return result;
meta = malloc(sizeof(struct metadata_node));
if (meta == NULL)
- return pr_enomem();
+ enomem_panic();
meta->uri = uri;
uri_refget(uri);
goto destroy_resources;
defer_separator = create_separator();
- if (defer_separator == NULL) {
- error = pr_enomem();
- goto destroy_resources;
- }
ok = sk_X509_push(stack->x509s, x509);
if (ok <= 0) {
return (meta != NULL) ? meta->level : 0;
}
-static int
-get_current_file_name(char **_result)
+static char *
+get_current_file_name(void)
{
char const *file_name;
char *result;
result = strdup(file_name);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
- *_result = result;
- return 0;
+ return result;
}
/**
*
* This function will steal ownership of @number on success.
*/
-int
+void
x509stack_store_serial(struct cert_stack *stack, BIGNUM *number)
{
struct metadata_node *meta;
array_index i;
struct serial_number duplicate;
char *string;
- int error;
/* Remember to free @number if you return 0 but don't store it. */
meta = SLIST_FIRST(&stack->metas);
if (meta == NULL) {
BN_free(number);
- return 0; /* The TA lacks siblings, so serial is unique. */
+ return; /* The TA lacks siblings, so serial is unique. */
}
/*
string, cursor->file);
BN_free(number);
free(string);
- return 0;
+ return;
}
}
duplicate.number = number;
- error = get_current_file_name(&duplicate.file);
- if (error)
- return error;
-
- error = serial_numbers_add(&meta->serials, &duplicate);
- if (error)
- free(duplicate.file);
+ duplicate.file = get_current_file_name();
- return error;
+ serial_numbers_add(&meta->serials, &duplicate);
}
STACK_OF(X509) *
int certstack_create(struct cert_stack **);
void certstack_destroy(struct cert_stack *);
-int deferstack_push(struct cert_stack *, struct deferred_cert *cert);
+void deferstack_push(struct cert_stack *, struct deferred_cert *cert);
int deferstack_pop(struct cert_stack *, struct deferred_cert *cert);
bool deferstack_is_empty(struct cert_stack *);
struct rpki_uri *x509stack_peek_uri(struct cert_stack *);
struct resources *x509stack_peek_resources(struct cert_stack *);
unsigned int x509stack_peek_level(struct cert_stack *);
-int x509stack_store_serial(struct cert_stack *, BIGNUM *);
+void x509stack_store_serial(struct cert_stack *, BIGNUM *);
typedef int (*subject_pk_check_cb)(bool *, char const *, void *);
int x509stack_store_subject(struct cert_stack *, struct rfc5280_name *,
subject_pk_check_cb, void *);
/* Get the full file path */
tmp = strdup(dir_name);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
tmp = realloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
strcat(tmp, "/");
strcat(tmp, file_name);
localuri = strdup(path);
if (localuri == NULL)
- return pr_enomem();
+ enomem_panic();
for (i = 1; localuri[i] != '\0'; i++) {
if (localuri[i] == '/') {
config_repo = strdup(config_get_local_repository());
if (config_repo == NULL)
- return pr_enomem();
+ enomem_panic();
/* Stop dir removal when the work_dir has this length */
config_len = strlen(config_repo);
work_loc = strdup(path);
if (work_loc == NULL)
- return pr_enomem();
+ enomem_panic();
do {
tmp = strrchr(work_loc, '/');
*
* Returns 0 on success, otherwise an error code.
*/
-int
-map_uri_to_local(char const *uri, char const *uri_prefix, char const *workspace,
- char **result)
+char *
+map_uri_to_local(char const *uri, char const *uri_prefix, char const *workspace)
{
char const *repository;
char *local;
if (workspace != NULL)
workspace_len = strlen(workspace);
- local = malloc(repository_len + extra_slash + workspace_len + uri_len +
- 1);
+ local = malloc(repository_len + extra_slash + workspace_len + uri_len + 1);
if (local == NULL)
- return pr_enomem();
+ enomem_panic();
offset = 0;
strcpy(local + offset, repository);
offset += uri_len;
local[offset] = '\0';
- *result = local;
- return 0;
+ return local;
}
int get_current_time(time_t *);
-int map_uri_to_local(char const *, char const*, char const *, char **);
+char *map_uri_to_local(char const *, char const*, char const *);
#endif /* SRC_RTR_COMMON_H_ */
* "struct option" is the array that getopt expects.
* "struct args_flag" is our option metadata.
*/
-static int
+static void
construct_getopt_options(struct option **_long_opts, char **_short_opts)
{
struct option_field const *opt;
/* +1 NULL end, means end of array. */
long_opts = calloc(total_long_options + 1, sizeof(struct option));
if (long_opts == NULL)
- return pr_enomem();
+ enomem_panic();
short_opts = malloc(total_short_options + 1);
- if (short_opts == NULL) {
- free(long_opts);
- return pr_enomem();
- }
+ if (short_opts == NULL)
+ enomem_panic();
*_long_opts = long_opts;
*_short_opts = short_opts;
}
*short_opts = '\0';
- return 0;
}
static void
pr_op_info("}");
}
-static int
+static void
set_default_values(void)
{
static char const *recursive_rsync_args[] = {
"$LOCAL",
};
- int error;
-
/*
* Values that might need to be freed WILL be freed, so use heap
* duplicates.
*/
- error = string_array_init(&rpki_config.server.address, NULL, 0);
- if (error)
- return error;
+ string_array_init(&rpki_config.server.address, NULL, 0);
rpki_config.server.port = strdup("323");
- if (rpki_config.server.port == NULL) {
- error = pr_enomem();
- goto revert_address;
- }
+ if (rpki_config.server.port == NULL)
+ enomem_panic();
rpki_config.server.backlog = SOMAXCONN;
rpki_config.server.interval.validation = 3600;
rpki_config.slurm = NULL;
rpki_config.local_repository = strdup("/tmp/fort/repository");
- if (rpki_config.local_repository == NULL) {
- error = pr_enomem();
- goto revert_port;
- }
+ if (rpki_config.local_repository == NULL)
+ enomem_panic();
rpki_config.sync_strategy = RSYNC_ROOT_EXCEPT_TA;
rpki_config.shuffle_tal_uris = false;
rpki_config.rsync.retry.count = 1;
rpki_config.rsync.retry.interval = 4;
rpki_config.rsync.program = strdup("rsync");
- if (rpki_config.rsync.program == NULL) {
- error = pr_enomem();
- goto revert_repository;
- }
+ if (rpki_config.rsync.program == NULL)
+ enomem_panic();
- error = string_array_init(&rpki_config.rsync.args.recursive,
+ string_array_init(&rpki_config.rsync.args.recursive,
recursive_rsync_args, ARRAY_LEN(recursive_rsync_args));
- if (error)
- goto revert_rsync_program;
-
- error = string_array_init(&rpki_config.rsync.args.flat,
+ string_array_init(&rpki_config.rsync.args.flat,
flat_rsync_args, ARRAY_LEN(flat_rsync_args));
- if (error)
- goto revert_recursive_array;
/* By default, has a higher priority than rsync */
rpki_config.http.enabled = true;
rpki_config.http.retry.count = 1;
rpki_config.http.retry.interval = 4;
rpki_config.http.user_agent = strdup(PACKAGE_NAME "/" PACKAGE_VERSION);
- if (rpki_config.http.user_agent == NULL) {
- error = pr_enomem();
- goto revert_flat_array;
- }
+ if (rpki_config.http.user_agent == NULL)
+ enomem_panic();
rpki_config.http.connect_timeout = 30;
rpki_config.http.transfer_timeout = 0;
rpki_config.http.low_speed_limit = 100000;
rpki_config.validation_log.filename_format = FNF_GLOBAL;
rpki_config.validation_log.facility = LOG_DAEMON;
rpki_config.validation_log.tag = strdup("Validation");
- if (rpki_config.validation_log.tag == NULL) {
- error = pr_enomem();
- goto revert_validation_log_tag;
- }
+ if (rpki_config.validation_log.tag == NULL)
+ enomem_panic();
rpki_config.output.roa = NULL;
rpki_config.output.bgpsec = NULL;
rpki_config.thread_pool.server.max = 20;
/* Usually 5 TALs, let a few more available */
rpki_config.thread_pool.validation.max = 5;
-
- return 0;
-
-revert_validation_log_tag:
- free(rpki_config.http.user_agent);
-revert_flat_array:
- string_array_cleanup(&rpki_config.rsync.args.flat);
-revert_recursive_array:
- string_array_cleanup(&rpki_config.rsync.args.recursive);
-revert_rsync_program:
- free(rpki_config.rsync.program);
-revert_repository:
- free(rpki_config.local_repository);
-revert_port:
- free(rpki_config.server.port);
-revert_address:
- string_array_cleanup(&rpki_config.server.address);
- return error;
}
static bool
int error;
program_name = argv[0];
- error = set_default_values();
- if (error)
- return error;
+ set_default_values();
long_opts = NULL;
short_opts = NULL;
- error = construct_getopt_options(&long_opts, &short_opts);
- if (error)
- goto end; /* Error msg already printed. */
+ construct_getopt_options(&long_opts, &short_opts);
while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL))
!= -1) {
__string_free(result);
DEREFERENCE(result) = strdup(str);
- return (DEREFERENCE(result) != NULL) ? 0 : pr_enomem();
+ if (DEREFERENCE(result) == NULL)
+ enomem_panic();
+
+ return 0;
}
static int
#include "str_token.h"
#include "config/str.h"
-int
+void
string_array_init(struct string_array *array, char const *const *values,
size_t len)
{
if (len == 0) {
array->array = NULL;
- return 0;
+ return;
}
array->array = calloc(len, sizeof(char *));
if (array->array == NULL)
- return pr_enomem();
+ enomem_panic();
for (i = 0; i < len; i++) {
array->array[i] = strdup(values[i]);
if (array->array[i] == NULL) {
string_array_cleanup(array);
- return pr_enomem();
+ enomem_panic();
}
}
-
- return 0;
}
void
result->array = calloc(len, sizeof(char *));
if (result->array == NULL)
- return pr_enomem();
+ enomem_panic();
result->length = len;
for (i = 0; i < len; i++) {
goto fail;
result->array[i] = strdup(tmp);
- if (result->array[i] == NULL) {
- error = pr_enomem();
- goto fail;
- }
+ if (result->array[i] == NULL)
+ enomem_panic();
}
return 0;
struct string_tokenizer tokenizer;
struct string_array *result;
size_t i, len;
- int error;
result = _result;
result->array = calloc(len, sizeof(char *));
if (result->array == NULL)
- return pr_enomem();
+ enomem_panic();
result->length = len;
- for (i = 0; string_tokenizer_next(&tokenizer); i++) {
- error = token_read(&tokenizer, &result->array[i]);
- if (error)
- goto fail;
- }
+ for (i = 0; string_tokenizer_next(&tokenizer); i++)
+ result->array[i] = token_read(&tokenizer);
return 0;
-
-fail:
- __string_array_free(result);
- return error;
}
static void
extern const struct global_type gt_string_array;
-int string_array_init(struct string_array *, char const *const *, size_t);
+void string_array_init(struct string_array *, char const *const *, size_t);
void string_array_cleanup(struct string_array *);
#endif /* SRC_CONFIG_STRING_ARRAY_H_ */
b64 = BIO_new(BIO_f_base64());
if (b64 == NULL) {
error = ERR_peek_last_error();
- return error ? error_ul2i(error) : pr_enomem();
+ if (error)
+ return error_ul2i(error);
+ enomem_panic();
}
/*
str_copy = malloc(encoded_len + pad + 1);
if (str_copy == NULL)
- return pr_enomem();
+ enomem_panic();
/* Set all with pad char, then replace with the original string */
memset(str_copy, '=', encoded_len + pad);
memcpy(str_copy, str_encoded, encoded_len);
alloc_size = EVP_DECODE_LENGTH(strlen(str_copy));
*result = malloc(alloc_size + 1);
- if (*result == NULL) {
- error = pr_enomem();
- goto free_enc;
- }
+ if (*result == NULL)
+ enomem_panic();
memset(*result, 0, alloc_size);
(*result)[alloc_size] = '\0';
return 0;
free_all:
free(*result);
-free_enc:
BIO_free(encoded);
free_copy:
free(str_copy);
return error;
}
-static int
-to_base64url(char *base, size_t base_len, char **out)
+static char *
+to_base64url(char *base, size_t base_len)
{
char *pad, *tmp;
size_t len;
tmp = malloc(len + 1);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(tmp, base, len);
tmp[len] = '\0';
tmp[i] = '_';
}
- *out = tmp;
- return 0;
+ return tmp;
}
/*
mem = BIO_new(BIO_s_mem());
if (mem == NULL) {
error = ERR_peek_last_error();
- return error ? error_ul2i(error) : pr_enomem();
+ goto peeked;
}
b64 = BIO_new(BIO_f_base64());
BIO_flush(b64);
BIO_get_mem_ptr(mem, &mem_buf);
- error = to_base64url(mem_buf->data, mem_buf->length, result);
- if (error)
- goto free_mem;
+ *result = to_base64url(mem_buf->data, mem_buf->length);
BIO_free_all(b64);
return 0;
+
free_mem:
BIO_free_all(b64);
- return error ? error_ul2i(error) : pr_enomem();
+peeked:
+ if (error)
+ return error_ul2i(error);
+ enomem_panic();
}
buffer_len = stat.st_blksize;
buffer = malloc(buffer_len);
- if (buffer == NULL) {
- error = pr_enomem();
- goto end1;
- }
+ if (buffer == NULL)
+ enomem_panic();
ctx = EVP_MD_CTX_new();
- if (ctx == NULL) {
- error = pr_enomem();
- goto end2;
- }
+ if (ctx == NULL)
+ enomem_panic();
if (!EVP_DigestInit_ex(ctx, md, NULL)) {
error = val_crypto_err("EVP_DigestInit_ex() failed");
- goto end3;
+ goto end;
}
do {
if (error) {
pr_val_err("File reading error. Error message (apparently): %s",
strerror(error));
- goto end3;
+ goto end;
}
if (!EVP_DigestUpdate(ctx, buffer, consumed)) {
error = val_crypto_err("EVP_DigestUpdate() failed");
- goto end3;
+ goto end;
}
} while (!feof(file));
if (!EVP_DigestFinal_ex(ctx, result, result_len))
error = val_crypto_err("EVP_DigestFinal_ex() failed");
-end3:
+end:
EVP_MD_CTX_free(ctx);
-end2:
free(buffer);
-end1:
file_close(file);
return error;
}
ctx = EVP_MD_CTX_new();
if (ctx == NULL)
- return pr_enomem();
+ enomem_panic();
if (!EVP_DigestInit_ex(ctx, md, NULL)
|| !EVP_DigestUpdate(ctx, content, content_len)
src = malloc(strlen(str));
if (src == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(src, str, strlen(str));
/* Get the working dir, the daemon will use (and free) it later */
pwd = getcwd(NULL, 0);
if (pwd == NULL)
- return pr_enomem();
+ enomem_panic();
pid = fork();
if (pid < 0) {
#define DECLARE_ARRAY_LIST_FUNCTIONS(name, elem_type) \
void name##_init(struct name *); \
void name##_cleanup(struct name *, void (*cb)(elem_type *)); \
- int name##_add(struct name *list, elem_type *elem);
+ void name##_add(struct name *list, elem_type *elem);
#define DEFINE_ARRAY_LIST_FUNCTIONS(name, elem_type, modifiers) \
modifiers void \
} \
\
/* Will store a shallow copy, not @elem */ \
- modifiers int \
+ modifiers void \
name##_add(struct name *list, elem_type *elem) \
{ \
elem_type *tmp; \
list->array = malloc(list->capacity \
* sizeof(elem_type)); \
if (list->array == NULL) \
- return pr_enomem(); \
+ enomem_panic(); \
} \
\
list->len++; \
tmp = realloc(list->array, list->capacity \
* sizeof(elem_type)); \
if (tmp == NULL) \
- return pr_enomem(); \
+ enomem_panic(); \
list->array = tmp; \
} \
\
list->array[list->len - 1] = *elem; \
- return 0; \
}
#define ARRAY_LIST(name, elem_type) \
+++ /dev/null
-#ifndef SRC_DATA_STRUCTURE_UTHASH_NONFATAL_H_
-#define SRC_DATA_STRUCTURE_UTHASH_NONFATAL_H_
-
-#include <errno.h>
-
-/*
- * "To enable "returning a failure" if memory cannot be allocated, define the
- * macro HASH_NONFATAL_OOM before including the uthash.h header file."
- * (http://troydhanson.github.io/uthash/userguide.html#_out_of_memory)
- *
- * The errno variable will be set to ENOMEM, so that the caller can detect the
- * error.
- *
- * This validation (check for errno) must be done on ops that allocate memory,
- * so set 'errno' to 0 before this ops are made. The 'obj' won't be freed,
- * this is the caller's responsibility.
- *
- * Functions that can OOM:
- *
- * HASH_ADD_TO_TABLE
- * HASH_ADD_KEYPTR_BYHASHVALUE_INORDER
- * HASH_REPLACE_BYHASHVALUE_INORDER
- * HASH_REPLACE_INORDER
- * HASH_ADD_KEYPTR_INORDER
- * HASH_ADD_INORDER
- * HASH_ADD_BYHASHVALUE_INORDER
- * HASH_ADD_KEYPTR_BYHASHVALUE
- * HASH_REPLACE_BYHASHVALUE
- * HASH_REPLACE (*)
- * HASH_REPLACE_STR (**)
- * HASH_REPLACE_INT
- * HASH_REPLACE_PTR
- * HASH_ADD_KEYPTR
- * HASH_ADD
- * HASH_ADD_BYHASHVALUE
- * HASH_SELECT
- *
- * (*) Used by Fort
- * (**) Used by Fort, but only in its fatal uthash form.
- */
-#define HASH_NONFATAL_OOM 1
-#define uthash_nonfatal_oom(obj) \
- errno = ENOMEM; \
-
-#include "data_structure/uthash.h"
-
-#endif /* SRC_DATA_STRUCTURE_UTHASH_NONFATAL_H_ */
int error;
/* Currently, only rsync URIs are utilized */
- local_path = NULL;
- error = map_uri_to_local(rcvd, "rsync://", workspace, &local_path);
- if (error)
- return error;
+ local_path = map_uri_to_local(rcvd, "rsync://", workspace);
error = stat(local_path, &attr);
if (error) {
tmp_size--;
tmp = malloc(tmp_size + 1);
- if (tmp == NULL) {
- error = pr_enomem();
- goto release_local;
- }
+ if (tmp == NULL)
+ enomem_panic();
strncpy(tmp, local_path, tmp_size);
tmp[tmp_size] = '\0';
return error;
}
-/*
- * Soft/hard error logic utilized, beware to prepare caller:
- * - '> 0' is a soft error
- * - '< 0' is a hard error
- * - '= 0' no error
- */
static int
rename_local_path(char const *rcvd, char **result)
{
tmp_size = rcvd_size + 1 + (sizeof(RAND_MAX) * 2);
tmp = malloc(tmp_size + 1);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
/* Rename the path with a random suffix */
random_init();
snprintf(tmp, tmp_size + 1, "%s_%08lX", rcvd, random_sfx);
- error = rename(rcvd, tmp);
- if (error) {
+ if (rename(rcvd, tmp) != 0) {
+ error = errno;
free(tmp);
pr_op_debug("Couldn't rename '%s' to delete it (discarding): %s",
- rcvd, strerror(errno));
- return errno; /* Soft error */
+ rcvd, strerror(error));
+ return error;
}
*result = tmp;
delete_path = NULL;
error = rename_local_path(local_path, &delete_path);
free(local_path);
- if (error < 0)
- return error;
- if (error > 0)
+ if (error)
continue;
rem_dirs->arr[rem_dirs->arr_set++] = delete_path;
}
return 0;
}
-static int
-rem_dirs_create(size_t arr_len, struct rem_dirs **result)
+static struct rem_dirs *
+rem_dirs_create(size_t arr_len)
{
struct rem_dirs *tmp;
tmp = malloc(sizeof(struct rem_dirs));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
tmp->arr = calloc(arr_len, sizeof(char *));
- if (tmp->arr == NULL) {
- free(tmp);
- return pr_enomem();
- }
+ if (tmp->arr == NULL)
+ enomem_panic();
tmp->arr_len = arr_len;
tmp->arr_set = 0;
- *result = tmp;
- return 0;
+ return tmp;
}
static void
struct rem_dirs *arg;
int error;
- arg = NULL;
- error = rem_dirs_create(roots_len, &arg);
- if (error)
- return error;
+ arg = rem_dirs_create(roots_len);
error = rename_all_roots(arg, roots, workspace);
if (error) {
}
/* Thread arg is released at thread */
- error = internal_pool_push("Directory deleter", remove_from_root, arg);
- if (error) {
- rem_dirs_destroy(arg);
- return error;
- }
+ internal_pool_push("Directory deleter", remove_from_root, arg);
return 0;
}
fc->buffer_size = stat.st_size;
fc->buffer = malloc(fc->buffer_size);
- if (fc->buffer == NULL) {
- error = pr_enomem();
- goto end;
- }
+ if (fc->buffer == NULL)
+ enomem_panic();
fread_result = fread(fc->buffer, 1, fc->buffer_size, file);
if (fread_result < fc->buffer_size) {
}
}
-static int
+static void
http_easy_init(struct http_handler *handler)
{
CURL *result;
result = curl_easy_init();
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
setopt_str(result, CURLOPT_USERAGENT, config_get_http_user_agent());
setopt_long(result, CURLOPT_NOSIGNAL, 1L);
handler->curl = result;
- return 0;
}
static char const *
tmp_file = malloc(strlen(original_file) + strlen(tmp_suffix) + 1);
if (tmp_file == NULL)
- return pr_enomem();
+ enomem_panic();
strcpy(tmp_file, original_file);
strcat(tmp_file, tmp_suffix);
goto delete_dir;
do {
- error = http_easy_init(&handler);
- if (error)
- goto close_file;
+ http_easy_init(&handler);
/* Set "If-Modified-Since" header only if a value is specified */
if (ims_value > 0) {
end:
free(tmp_file);
return 0;
-close_file:
- file_close(out);
delete_dir:
delete_dir_recursive_bottom_up(tmp_file);
release_tmp:
tmp_file = strdup(dest);
if (tmp_file == NULL)
- return pr_enomem();
+ enomem_panic();
tmp = realloc(tmp_file, strlen(tmp_file) + strlen(tmp_suffix) + 1);
- if (tmp == NULL) {
- error = pr_enomem();
- goto release_tmp;
- }
+ if (tmp == NULL)
+ enomem_panic();
tmp_file = tmp;
strcat(tmp_file, tmp_suffix);
error = file_write(tmp_file, &out);
if (error)
- goto release_tmp;
-
- error = http_easy_init(&handler);
- if (error)
- goto close_file;
+ goto end;
+ http_easy_init(&handler);
error = http_fetch(&handler, remote, &response_code, &cond_met, true,
out);
http_easy_cleanup(&handler);
+
file_close(out);
if (error)
- goto release_tmp;
+ goto end;
/* Overwrite the original file */
error = rename(tmp_file, dest);
error = errno;
pr_val_err("Renaming temporal file from '%s' to '%s': %s",
tmp_file, dest, strerror(error));
- goto release_tmp;
+ goto end;
}
- free(tmp_file);
- return 0;
-close_file:
- file_close(out);
-release_tmp:
+end:
free(tmp_file);
return error;
}
dest = malloc(dest_dir_len + extra_slash + strlen(dest_file) + 1);
if (dest == NULL)
- return pr_enomem();
+ enomem_panic();
offset = 0;
strcpy(dest + offset, dest_dir);
return 0;
}
-int
+void
internal_pool_push(char const *task_name, thread_pool_task_cb cb, void *arg)
{
- return thread_pool_push(pool, task_name, cb, arg);
+ thread_pool_push(pool, task_name, cb, arg);
}
void
#include "thread/thread_pool.h"
int internal_pool_init(void);
-int internal_pool_push(char const *, thread_pool_task_cb, void *);
+void internal_pool_push(char const *, thread_pool_task_cb, void *);
void internal_pool_cleanup(void);
#endif /* SRC_INTERNAL_POOL_H_ */
#include "log.h"
#include "config/types.h"
-static int
-find_json(struct json_t *root, char const *full_name, json_t **result)
+static json_t *
+find_json(struct json_t *root, char const *full_name)
{
struct {
char *opt_name; /* full token sequence string */
/* strtok_r() needs a non-const string */
strtok.opt_name = strdup(full_name);
if (strtok.opt_name == NULL)
- return pr_enomem();
+ enomem_panic();
node = root;
strtok.token = strtok_r(strtok.opt_name, ".", &strtok.saveptr);
}
free(strtok.opt_name);
- *result = node;
- return 0;
+ return node;
}
static int
int error;
FOREACH_OPTION(get_option_metadatas(), opt, AVAILABILITY_JSON) {
- error = find_json(root, opt->name, &child);
- if (error)
- return error;
+ child = find_json(root, opt->name);
if (child == NULL)
continue;
lfile = malloc(sizeof(struct line_file));
if (lfile == NULL)
- return pr_enomem();
+ enomem_panic();
lfile->file = fopen(file_name, "r");
if (lfile->file == NULL) {
return crypto_err(&val_config, pr_val_err);
}
-int
-pr_enomem(void)
+__dead void
+enomem_panic(void)
{
static char const *ENOMEM_MSG = "Out of memory.\n";
ssize_t garbage;
*/
if (LOG_ERR > op_config.level)
- return -ENOMEM;
+ goto done;
if (op_config.fprintf_enabled) {
lock_mutex();
/*
* write() is AS-Safe, which implies it doesn't allocate,
* unlike printf().
+ *
+ * "garbage" prevents write()'s warn_unused_result (compiler
+ * warning).
*/
garbage = write(STDERR_FILENO, ENOMEM_MSG, strlen(ENOMEM_MSG));
unlock_mutex();
+ /* Prevents "set but not used" warning. */
garbage++;
}
unlock_mutex();
}
- return -ENOMEM;
+done: exit(ENOMEM);
}
__dead void
/* Like pr_val_err(), except it prints libcrypto's error stack as well. */
int val_crypto_err(const char *, ...) CHECK_FORMAT(1, 2);
-/* Like pr_*_err(), specific to out-of-memory situations. */
-int pr_enomem(void);
+/*
+ * Like pr_*_err(), specific to out-of-memory situations.
+ * Also terminates the program.
+ */
+__dead void enomem_panic(void);
/* Programming errors */
__dead void pr_crit(const char *, ...) CHECK_FORMAT(1, 2);
cert_spk = malloc(RK_SPKI_LEN);
if (cert_spk == NULL)
- return pr_enomem();
+ enomem_panic();
/* Use a temporal pointer, since i2d_X509_PUBKEY moves it */
tmp = cert_spk;
{
struct validation *state;
BIGNUM *number;
- int error;
state = state_retrieve();
if (state == NULL)
if (log_val_enabled(LOG_DEBUG))
debug_serial_number(number);
- error = x509stack_store_serial(validation_certstack(state), number);
- if (error)
- BN_free(number);
-
- return error;
+ x509stack_store_serial(validation_certstack(state), number);
+ return 0;
}
static int
clone = X509_CRL_dup(original_crl);
if (clone == NULL) {
ASN1_STRING_free(tm);
- return pr_enomem();
+ enomem_panic();
}
X509_CRL_set1_nextUpdate(clone, tm);
* This will return:
* rsync://<server>
*/
-static int
+static void
get_rsync_server_uri(struct rpki_uri *src, char **result, size_t *result_len)
{
char const *global;
tmp = malloc(i + 1);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
strncpy(tmp, global, i);
tmp[i] = '\0';
*result_len = i;
*result = tmp;
-
- return 0;
}
-static int
+static void
set_repository_level(bool is_ta, struct validation *state,
struct rpki_uri *cert_uri, struct sia_ca_uris *sia_uris, bool *updated)
{
size_t parent_server_len, current_server_len;
unsigned int new_level;
bool update;
- int error;
new_level = 0;
if (is_ta || cert_uri == NULL) {
working_repo_push_level(new_level);
- return 0;
+ return;
}
/* Warning killer */
current_server_len = 0;
/* Both are rsync URIs, check the server part */
- error = get_rsync_server_uri(cert_uri, &parent_server,
- &parent_server_len);
- if (error)
- return error;
-
- error = get_rsync_server_uri(sia_uris->caRepository.uri,
- ¤t_server, ¤t_server_len);
- if (error) {
- free(parent_server);
- return error;
- }
+ get_rsync_server_uri(cert_uri, &parent_server, &parent_server_len);
+ get_rsync_server_uri(sia_uris->caRepository.uri, ¤t_server,
+ ¤t_server_len);
if (parent_server_len != current_server_len) {
update = true;
free(current_server);
(*updated) = update;
- return 0;
}
/** Boilerplate code for CA certificate validation and recursive traversal. */
/* Identify if this is a new repository before fetching it */
new_level = false;
- error = set_repository_level(IS_TA, state, cert_uri, &sia_uris,
- &new_level);
- if (error)
- goto revert_uris;
+ set_repository_level(IS_TA, state, cert_uri, &sia_uris, &new_level);
/*
* RFC 6481 section 5: "when the repository publication point contents
error = rpp_crl(pp, &crl);
if (error)
goto revert_sobj;
- error = signed_object_args_init(&sobj_args, uri, crl, true);
- if (error)
- goto revert_sobj;
+ signed_object_args_init(&sobj_args, uri, crl, true);
/* Validate everything */
error = signed_object_validate(&sobj, &arcs, &sobj_args);
*pp = rpp_create();
if (*pp == NULL)
- return pr_enomem();
+ enomem_panic();
for (i = 0; i < mft->fileList.list.count; i++) {
fah = mft->fileList.list.array[i];
}
if (uri_has_extension(uri, ".cer"))
- error = rpp_add_cert(*pp, uri);
+ rpp_add_cert(*pp, uri);
else if (uri_has_extension(uri, ".roa"))
- error = rpp_add_roa(*pp, uri);
+ rpp_add_roa(*pp, uri);
else if (uri_has_extension(uri, ".crl"))
error = rpp_add_crl(*pp, uri);
else if (uri_has_extension(uri, ".gbr"))
- error = rpp_add_ghostbusters(*pp, uri);
+ rpp_add_ghostbusters(*pp, uri);
else
uri_refput(uri); /* ignore it. */
error = rpp_crl(*pp, &crl);
if (error)
goto revert_rpp;
- error = signed_object_args_init(&sobj_args, uri, crl, false);
- if (error)
- goto revert_rpp;
+ signed_object_args_init(&sobj_args, uri, crl, false);
/* Validate everything */
error = signed_object_validate(&sobj, &arcs, &sobj_args);
result = malloc(data->length + 1);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(result, data->data, data->length);
result[data->length] = '\0';
result = malloc(sizeof(struct rfc5280_name));
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
result->commonName = NULL;
result->serialNumber = NULL;
error = rpp_crl(pp, &crl);
if (error)
goto revert_roa;
- error = signed_object_args_init(&sobj_args, uri, crl, false);
- if (error)
- goto revert_roa;
+ signed_object_args_init(&sobj_args, uri, crl, false);
/* Validate and handle everything */
error = signed_object_validate(&sobj, &arcs, &sobj_args);
struct threads_list threads;
};
-static int
+static void
uris_init(struct uris *uris)
{
uris->count = 0;
uris->https_count = 0;
uris->size = 4; /* Most TALs only define one. */
uris->array = malloc(uris->size * sizeof(struct rpki_uri *));
- return (uris->array != NULL) ? 0 : pr_enomem();
+ if (uris->array == NULL)
+ enomem_panic();
}
static void
error = uri_create_mixed_str(&new, uri, strlen(uri));
if (error == ENOTSUPPORTED)
return pr_op_err("TAL has non-RSYNC/HTTPS URI.");
-
if (error)
return error;
uris->size *= 2;
tmp = realloc(uris->array,
uris->size * sizeof(struct rpki_uri *));
- if (tmp == NULL) {
- uri_refput(new);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
uris->array = tmp;
}
new_size = original_size + (original_size / BUF_SIZE);
result = malloc(new_size + 1);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
buf = malloc(BUF_SIZE);
- if (buf == NULL) {
- free(result);
- return pr_enomem();
- }
+ if (buf == NULL)
+ enomem_panic();
fd = lfile_fd(lfile);
offset = 0;
/* Reallocate to exact size and add nul char */
if (offset != new_size) {
eol = realloc(result, offset + 1);
- if (eol == NULL) {
- error = pr_enomem();
- goto free_result;
- }
+ if (eol == NULL)
+ enomem_panic();
result = eol;
}
free(buf);
alloc_size = get_spki_alloc_size(lfile);
tal->spki = malloc(alloc_size);
if (tal->spki == NULL)
- return pr_enomem();
+ enomem_panic();
tmp = NULL;
error = base64_sanitize(lfile, &tmp);
if (error) {
pr_op_err("Error opening file '%s': %s", file_name,
strerror(abs(error)));
- goto fail4;
+ return error;
}
tal = malloc(sizeof(struct tal));
- if (tal == NULL) {
- error = pr_enomem();
- goto fail3;
- }
+ if (tal == NULL)
+ enomem_panic();
tal->file_name = file_name;
- error = uris_init(&tal->uris);
- if (error)
- goto fail2;
+ uris_init(&tal->uris);
error = read_uris(lfile, &tal->uris);
if (error)
- goto fail1;
+ goto fail;
error = read_spki(lfile, tal);
if (error)
- goto fail1;
+ goto fail;
lfile_close(lfile);
*result = tal;
return 0;
-fail1:
+fail:
uris_destroy(&tal->uris);
-fail2:
free(tal);
-fail3:
lfile_close(lfile);
-fail4:
return error;
}
}
}
-static int
+static void
tal_order_uris(struct tal *tal)
{
struct rpki_uri **ordered;
tal_shuffle_uris(tal);
if (config_get_rsync_priority() == config_get_http_priority())
- return 0;
+ return;
/* Now order according to the priority */
http_first = (config_get_http_priority() > config_get_rsync_priority());
ordered = malloc(tal->uris.size * sizeof(struct rpki_uri *));
if (ordered == NULL)
- return pr_enomem();
+ enomem_panic();
last_rsync = (http_first ? tal->uris.https_count : 0);
last_https = (http_first ? 0 : tal->uris.rsync_count);
tmp = tal->uris.array;
tal->uris.array = ordered;
free(tmp);
-
- return 0;
}
char const *
if (error)
goto end;
- error = tal_order_uris(tal);
- if (error)
- goto destroy_tal;
+ tal_order_uris(tal);
error = foreach_uri(tal, __handle_tal_uri_sync, thread);
if (error > 0) {
return error;
thread = malloc(sizeof(struct validation_thread));
- if (thread == NULL) {
- error = pr_enomem();
- goto free_db_rrdp;
- }
+ if (thread == NULL)
+ enomem_panic();
thread->tal_file = strdup(tal_file);
- if (thread->tal_file == NULL) {
- error = pr_enomem();
- goto free_thread;
- }
+ if (thread->tal_file == NULL)
+ enomem_panic();
thread->arg = t_param->db;
thread->exit_status = -EINTR;
thread->retry_local = true;
thread->sync_files = true;
- error = thread_pool_push(t_param->pool, thread->tal_file,
- do_file_validation, thread);
- if (error) {
- pr_op_err("Couldn't push a thread to do files validation");
- goto free_tal_file;
- }
+ thread_pool_push(t_param->pool, thread->tal_file, do_file_validation,
+ thread);
SLIST_INSERT_HEAD(&t_param->threads, thread, next);
return 0;
-
-free_tal_file:
- free(thread->tal_file);
-free_thread:
- free(thread);
-free_db_rrdp:
- db_rrdp_rem_tal(tal_file);
- return error;
}
int
return SA_LINE_ENDED; /* \r\n<more lines> */
}
-static int
+static void
double_line_size(struct vcard_line *line)
{
uint8_t *tmp;
line->str.size *= 2;
tmp = realloc(line->str.val, line->str.size);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
line->str.val = tmp;
-
- return 0;
}
-static int
+static void
add_chara(struct vcard_line *line, uint8_t chara, bool inc_str_len)
{
- int error;
-
- if (line->str.len + 1 == line->str.size) {
- error = double_line_size(line);
- if (error)
- return error;
- }
+ if (line->str.len + 1 == line->str.size)
+ double_line_size(line);
line->str.val[line->str.len] = chara;
if (inc_str_len)
line->str.len++;
-
- return 0;
}
/**
{
struct utf8_string string;
size_t string_pos;
- int error;
if (string8->size == line->octet_string_offset)
return pr_val_err("vCard ends prematurely. (Expected an END line)");
for (string_pos = 0; string_pos < string.len; string_pos++) {
switch (analyze_pos(&string, string_pos)) {
case SA_COPY_CHARA:
- error = add_chara(line, string.val[string_pos], true);
- if (error)
- return error;
+ add_chara(line, string.val[string_pos], true);
break;
case SA_LINE_ENDED:
line->octet_string_offset += string_pos + 2;
- return add_chara(line, 0, false);
+ add_chara(line, 0, false);
+ return 0;
case SA_SKIP_THREE_CHARAS:
string_pos += 2;
line.str.len = 0;
line.str.val = malloc(line.str.size);
if (line.str.val == NULL)
- return pr_enomem();
+ enomem_panic();
line.octet_string_offset = 0;
error = __handle_ghostbusters_vcard(vcard, &line);
tmp = malloc(sizeof(struct error_uri));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
/* Needed by uthash */
memset(tmp, 0, sizeof(struct error_uri));
tmp->uri = strdup(uri);
- if (tmp->uri == NULL) {
- error = pr_enomem();
- goto release_tmp;
- }
+ if (tmp->uri == NULL)
+ enomem_panic();
error = get_current_time(&tmp->first_attempt);
if (error)
*err_uri = tmp;
return 0;
+
release_uri:
free(tmp->uri);
-release_tmp:
free(tmp);
return error;
}
if (resources->ip4s == NULL) {
resources->ip4s = res4_create();
if (resources->ip4s == NULL)
- return pr_enomem();
+ enomem_panic();
}
error = res4_add_prefix(resources->ip4s, &prefix);
if (resources->ip6s == NULL) {
resources->ip6s = res6_create();
if (resources->ip6s == NULL)
- return pr_enomem();
+ enomem_panic();
}
error = res6_add_prefix(resources->ip6s, &prefix);
if (resources->ip4s == NULL) {
resources->ip4s = res4_create();
if (resources->ip4s == NULL)
- return pr_enomem();
+ enomem_panic();
}
error = res4_add_range(resources->ip4s, &range);
if (resources->ip6s == NULL) {
resources->ip6s = res6_create();
if (resources->ip6s == NULL)
- return pr_enomem();
+ enomem_panic();
}
error = res6_add_range(resources->ip6s, &range);
if (resources->asns == NULL) {
resources->asns = rasn_create();
if (resources->asns == NULL)
- return pr_enomem();
+ enomem_panic();
}
error = rasn_add(resources->asns, min, max);
}
/** Steals ownership of @uri. */
-int
+void
rpp_add_cert(struct rpp *pp, struct rpki_uri *uri)
{
- return uris_add(&pp->certs, &uri);
+ uris_add(&pp->certs, &uri);
}
/** Steals ownership of @uri. */
-int
+void
rpp_add_roa(struct rpp *pp, struct rpki_uri *uri)
{
- return uris_add(&pp->roas, &uri);
+ uris_add(&pp->roas, &uri);
}
/** Steals ownership of @uri. */
-int
+void
rpp_add_ghostbusters(struct rpp *pp, struct rpki_uri *uri)
{
- return uris_add(&pp->ghostbusters, &uri);
+ uris_add(&pp->ghostbusters, &uri);
}
/** Steals ownership of @uri. */
/* -- Actually initialize pp->crl.stack. -- */
stack = sk_X509_CRL_new_null();
- if (stack == NULL) {
- pp->crl.error = pr_enomem();
- return pp->crl.error;
- }
+ if (stack == NULL)
+ enomem_panic();
pp->crl.error = add_crl_to_stack(pp, stack);
if (pp->crl.error) {
sk_X509_CRL_pop_free(stack, X509_CRL_free);
struct cert_stack *certstack;
ssize_t i;
struct deferred_cert deferred;
- int error;
if (pp->certs.len == 0)
return 0;
*/
for (i = pp->certs.len - 1; i >= 0; i--) {
deferred.uri = pp->certs.array[i];
- error = deferstack_push(certstack, &deferred);
- if (error)
- return error;
+ deferstack_push(certstack, &deferred);
}
return 0;
void rpp_refget(struct rpp *pp);
void rpp_refput(struct rpp *pp);
-int rpp_add_cert(struct rpp *, struct rpki_uri *);
+void rpp_add_cert(struct rpp *, struct rpki_uri *);
int rpp_add_crl(struct rpp *, struct rpki_uri *);
-int rpp_add_roa(struct rpp *, struct rpki_uri *);
-int rpp_add_ghostbusters(struct rpp *, struct rpki_uri *);
+void rpp_add_roa(struct rpp *, struct rpki_uri *);
+void rpp_add_ghostbusters(struct rpp *, struct rpki_uri *);
struct rpki_uri *rpp_get_crl(struct rpp const *);
int rpp_crl(struct rpp *, STACK_OF(X509_CRL) **);
hash = malloc(HASH_LEN * sizeof(unsigned char));
if (hash == NULL)
- return pr_enomem();
+ enomem_panic();
hash_len = 0;
error = hash_str("sha1", base, hash, &hash_len);
/* Get the first bytes + one slash + NUL char */
tmp = malloc(OUT_LEN + 2);
- if (tmp == NULL) {
- free(hash);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
ptr = tmp;
for (i = 0; i < OUT_LEN / 2; i++) {
tal_elem_create(struct tal_elem **elem, char const *name)
{
struct tal_elem *tmp;
- struct db_rrdp_uri *tmp_uris;
int error;
tmp = malloc(sizeof(struct tal_elem));
if (tmp == NULL)
- return pr_enomem();
-
- tmp_uris = NULL;
- error = db_rrdp_uris_create(&tmp_uris);
- if (error)
- goto end1;
- tmp->uris = tmp_uris;
+ enomem_panic();
+ tmp->uris = db_rrdp_uris_create();
tmp->visited = true;
tmp->file_name = strdup(name);
- if (tmp->file_name == NULL) {
- error = pr_enomem();
- goto end2;
- }
+ if (tmp->file_name == NULL)
+ enomem_panic();
error = get_workspace_path(name, &tmp->workspace);
- if (error)
- goto end3;
+ if (error) {
+ free(tmp->file_name);
+ db_rrdp_uris_destroy(tmp->uris);
+ free(tmp);
+ return error;
+ }
*elem = tmp;
return 0;
-end3:
- free(tmp->file_name);
-end2:
- db_rrdp_uris_destroy(tmp->uris);
-end1:
- free(tmp);
- return error;
}
static void
char const *current_workspace;
};
-static int
+static struct uris_table *
uris_table_create(char const *uri, char const *session_id,
- unsigned long serial, rrdp_req_status_t req_status,
- struct uris_table **result)
+ unsigned long serial, rrdp_req_status_t req_status)
{
struct uris_table *tmp;
- int error;
tmp = malloc(sizeof(struct uris_table));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
/* Needed by uthash */
memset(tmp, 0, sizeof(struct uris_table));
tmp->uri = strdup(uri);
- if (tmp->uri == NULL) {
- error = pr_enomem();
- goto release_tmp;
- }
+ if (tmp->uri == NULL)
+ enomem_panic();
tmp->data.session_id = strdup(session_id);
- if (tmp->data.session_id == NULL) {
- error = pr_enomem();
- goto release_uri;
- }
+ if (tmp->data.session_id == NULL)
+ enomem_panic();
tmp->data.serial = serial;
tmp->last_update = 0;
tmp->request_status = req_status;
tmp->visited_uris = NULL;
- *result = tmp;
- return 0;
-release_uri:
- free(tmp->uri);
-release_tmp:
- free(tmp);
- return error;
+ return tmp;
}
static void
return 0;
}
-int
-db_rrdp_uris_create(struct db_rrdp_uri **uris)
+struct db_rrdp_uri *
+db_rrdp_uris_create(void)
{
struct db_rrdp_uri *tmp;
tmp = malloc(sizeof(struct db_rrdp_uri));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
tmp->table = NULL;
tmp->current_workspace = NULL;
- *uris = tmp;
- return 0;
+ return tmp;
}
void
if (error)
return error;
- db_uri = NULL;
- error = uris_table_create(uri, session_id, serial, req_status, &db_uri);
- if (error)
- return error;
-
- /* Ownership transfered */
- db_uri->visited_uris = visited_uris;
-
+ db_uri = uris_table_create(uri, session_id, serial, req_status);
+ db_uri->visited_uris = visited_uris; /* Ownership transfered */
add_rrdp_uri(uris, db_uri);
-
return 0;
}
*/
struct db_rrdp_uri;
-int db_rrdp_uris_create(struct db_rrdp_uri **);
+struct db_rrdp_uri *db_rrdp_uris_create(void);
void db_rrdp_uris_destroy(struct db_rrdp_uri *);
int db_rrdp_uris_cmp(char const *, char const *, unsigned long,
int error;
/* Use a new allocated visited_uris struct */
- error = visited_uris_create(&tmp);
- if (error)
- return error;
+ tmp = visited_uris_create();
error = rrdp_parse_snapshot(notification, tmp, log_operation);
if (error) {
pr_val_debug("RRDP data of '%s' won't be requested again during this cycle due to previous error.",
notification_uri);
- error = visited_uris_create(&tmp);
- if (error)
- return error;
+ tmp = visited_uris_create();
error = db_rrdp_uris_update(notification_uri, "", 0,
RRDP_URI_REQ_ERROR, tmp);
free(file);
}
-int
-snapshot_create(struct snapshot **file)
+struct snapshot *
+snapshot_create(void)
{
struct snapshot *tmp;
tmp = malloc(sizeof(struct snapshot));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
global_data_init(&tmp->global_data);
- *file = tmp;
- return 0;
+ return tmp;
}
void
free(file);
}
-int
-delta_create(struct delta **file)
+struct delta *
+delta_create(void)
{
struct delta *tmp;
tmp = malloc(sizeof(struct delta));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
global_data_init(&tmp->global_data);
- *file = tmp;
- return 0;
+ return tmp;
}
void
free(file);
}
-int
-publish_create(struct publish **file)
+struct publish *
+publish_create(void)
{
struct publish *tmp;
tmp = malloc(sizeof(struct publish));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
doc_data_init(&tmp->doc_data);
tmp->content = NULL;
tmp->content_len = 0;
- *file = tmp;
- return 0;
+ return tmp;
}
void
free(file);
}
-int
-withdraw_create(struct withdraw **file)
+struct withdraw *
+withdraw_create(void)
{
struct withdraw *tmp;
tmp = malloc(sizeof(struct withdraw));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
doc_data_init(&tmp->doc_data);
- *file = tmp;
- return 0;
+ return tmp;
}
void
delta_head_cb, void *);
int deltas_head_sort(struct deltas_head *, unsigned long);
-int snapshot_create(struct snapshot **);
+struct snapshot *snapshot_create(void);
void snapshot_destroy(struct snapshot *);
-int delta_create(struct delta **);
+struct delta *delta_create(void);
void delta_destroy(struct delta *);
-int publish_create(struct publish **);
+struct publish *publish_create(void);
void publish_destroy(struct publish *);
-int withdraw_create(struct withdraw **);
+struct withdraw *withdraw_create(void);
void withdraw_destroy(struct withdraw *);
#endif /* SRC_RRDP_RRDP_OBJECTS_H_ */
bool log_operation;
};
-static int
+static void
add_mft_to_list(struct visited_uris *visited_uris, char const *uri)
{
- if (strcmp(".mft", strrchr(uri, '.')) != 0)
- return 0;
-
- return visited_uris_add(visited_uris, uri);
+ if (strcmp(".mft", strrchr(uri, '.')) == 0)
+ visited_uris_add(visited_uris, uri);
}
static int
if (original_size <= BUF_SIZE) {
result = strdup(content);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
*out = result;
return 0;
}
new_size = original_size + (original_size / BUF_SIZE);
result = malloc(new_size + 1);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
offset = 0;
while (original_size > 0){
/* Reallocate to exact size and add nul char */
if (offset != new_size + 1) {
tmp = realloc(result, offset + 1);
- if (tmp == NULL) {
- free(result);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
result = tmp;
}
alloc_size = EVP_DECODE_LENGTH(strlen(content));
result = malloc(alloc_size);
- if (result == NULL) {
- error = pr_enomem();
- goto release_bio;
- }
+ if (result == NULL)
+ enomem_panic();
error = base64_decode(encoded, result, true, alloc_size, &result_len);
if (error)
return 0;
release_result:
free(result);
-release_bio:
BIO_free(encoded);
release_sanitized:
free(sanitized);
}
tmp = malloc(xmlStrlen(xml_value) + 1);
- if (tmp == NULL) {
- xmlFree(xml_value);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
memcpy(tmp, xml_value, xmlStrlen(xml_value));
tmp[xmlStrlen(xml_value)] = '\0';
tmp_len = xmlStrlen(xml_value) / 2;
tmp = malloc(tmp_len);
- if (tmp == NULL) {
- xmlFree(xml_value);
- return pr_enomem();
- }
+ if (tmp == NULL)
+ enomem_panic();
memset(tmp, 0, tmp_len);
ptr = tmp;
char *base64_str;
int error;
- error = publish_create(&tmp);
- if (error)
- return error;
+ tmp = publish_create();
error = parse_doc_data(reader, parse_hash, hash_required,
&tmp->doc_data);
struct rpki_uri *uri;
int error;
- error = withdraw_create(&tmp);
- if (error)
- return error;
+ tmp = withdraw_create();
error = parse_doc_data(reader, true, true, &tmp->doc_data);
if (error)
uri_get_local(uri));
}
- error = add_mft_to_list(visited_uris, uri_get_global(uri));
- if (error) {
- uri_refput(uri);
- file_close(out);
- return error;
- }
+ add_mft_to_list(visited_uris, uri_get_global(uri));
uri_refput(uri);
file_close(out);
if (error)
return error;
- error = deltas_head_add(&update->deltas_list, &delta);
- if (error)
- doc_data_cleanup(&delta.doc_data);
-
- return error;
+ deltas_head_add(&update->deltas_list, &delta);
+ return 0;
}
static int
result = update_notification_create(uri_get_global(uri));
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
error = relax_ng_parse(uri_get_local(uri), xml_read_notification,
result);
parse_snapshot(struct rpki_uri *uri, struct proc_upd_args *args)
{
struct rdr_snapshot_ctx ctx;
- struct snapshot *snapshot;
int error;
fnstack_push_uri(uri);
if (error)
goto pop;
- error = snapshot_create(&snapshot);
- if (error)
- goto pop;
-
- ctx.snapshot = snapshot;
+ ctx.snapshot = snapshot_create();
ctx.parent = args->parent;
ctx.visited_uris = args->visited_uris;
+
error = relax_ng_parse(uri_get_local(uri), xml_read_snapshot, &ctx);
- /* Error 0 is ok */
- snapshot_destroy(snapshot);
-pop:
- fnstack_pop();
+ snapshot_destroy(ctx.snapshot);
+pop: fnstack_pop();
return error;
}
struct proc_upd_args *args)
{
struct rdr_delta_ctx ctx;
- struct delta *delta;
struct doc_data *expected_data;
int error;
if (error)
goto pop_fnstack;
- error = delta_create(&delta);
- if (error)
- goto pop_fnstack;
-
- ctx.delta = delta;
+ ctx.delta = delta_create();
ctx.parent = args->parent;
ctx.visited_uris = args->visited_uris;
ctx.expected_serial = parents_data->serial;
- error = relax_ng_parse(uri_get_local(uri), xml_read_delta, &ctx);
- delta_destroy(delta);
- /* Error 0 is ok */
+ error = relax_ng_parse(uri_get_local(uri), xml_read_delta, &ctx);
+ delta_destroy(ctx.delta);
pop_fnstack:
fnstack_pop();
return error;
/* static char const *const RSYNC_PREFIX = "rsync://"; */
-int
-rsync_create(struct uri_list **result)
+struct uri_list *
+rsync_create(void)
{
struct uri_list *visited_uris;
visited_uris = malloc(sizeof(struct uri_list));
if (visited_uris == NULL)
- return pr_enomem();
+ enomem_panic();
SLIST_INIT(visited_uris);
-
- *result = visited_uris;
- return 0;
+ return visited_uris;
}
void
return false;
}
-static int
+static void
mark_as_downloaded(struct rpki_uri *uri, struct uri_list *visited_uris)
{
struct uri *node;
node = malloc(sizeof(struct uri));
if (node == NULL)
- return pr_enomem();
+ enomem_panic();
node->uri = uri;
uri_refget(uri);
SLIST_INSERT_HEAD(visited_uris, node, next);
-
- return 0;
}
static int
free(args);
}
-static int
+static void
prepare_rsync(struct rpki_uri *uri, bool is_ta, char ***args, size_t *args_len)
{
struct string_array const *config_args;
*/
copy_args = calloc(config_args->length + 2, sizeof(char *));
if (copy_args == NULL)
- return pr_enomem();
+ enomem_panic();
copy_args[0] = config_get_rsync_program();
copy_args[config_args->length + 1] = NULL;
else
copy_args[i + 1] = strdup(config_args->array[i]);
- if (copy_args[i + 1] == NULL) {
- release_args(copy_args, i);
- return pr_enomem();
- }
+ if (copy_args[i + 1] == NULL)
+ enomem_panic();
}
*args = copy_args;
*args_len = config_args->length;
- return 0;
}
__dead static void
return 0;
}
-static int
+static void
log_buffer(char const *buffer, ssize_t read, int type, bool log_operation)
{
#define PRE_RSYNC "[RSYNC exec]: "
cpy = malloc(read + 1);
if (cpy == NULL)
- return pr_enomem();
+ enomem_panic();
strncpy(cpy, buffer, read);
cpy[read] = '\0';
cur = tmp + 1;
}
free(cpy);
- return 0;
#undef PRE_RSYNC
}
if (count == 0)
break;
- error = log_buffer(buffer, count, type, log_operation);
- if (error)
- return error;
+ log_buffer(buffer, count, type, log_operation);
}
+
close(fd_pipe[type][0]); /* Close read end */
return 0;
}
/* Prepare everything for the child exec */
args = NULL;
args_len = 0;
- error = prepare_rsync(uri, is_ta, &args, &args_len);
- if (error)
- return error;
+ prepare_rsync(uri, is_ta, &args, &args_len);
pr_val_info("rsync: %s", uri_get_global(uri));
if (log_val_enabled(LOG_DEBUG)) {
case 0:
/* Don't store when "force" and if its already downloaded */
if (!(force && is_already_downloaded(rsync_uri, visited_uris)))
- error = mark_as_downloaded(rsync_uri, visited_uris);
+ mark_as_downloaded(rsync_uri, visited_uris);
reqs_errors_rem_uri(uri_get_global(rsync_uri));
break;
case EREQFAILED:
error = reqs_errors_add_uri(uri_get_global(rsync_uri));
if (error)
break;
- error = mark_as_downloaded(rsync_uri, visited_uris);
- /* Everything went ok? Return the original error */
- if (!error)
- error = EREQFAILED;
+ mark_as_downloaded(rsync_uri, visited_uris);
+ error = EREQFAILED; /* Return the original error */
break;
}
struct uri_list;
int rsync_download_files(struct rpki_uri *, bool, bool);
-int rsync_create(struct uri_list **);
+struct uri_list *rsync_create(void);
void rsync_destroy(struct uri_list *);
void reset_downloaded(void);
#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
#include "log.h"
-#include "data_structure/uthash_nonfatal.h"
+#include "data_structure/uthash.h"
struct hashable_roa {
const struct vrp data;
new = malloc(sizeof(struct hashable_roa));
if (new == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(new, stack_new, sizeof(*new));
errno = 0;
key = malloc(sizeof(struct hashable_key));
if (key == NULL)
- return pr_enomem();
+ enomem_panic();
/* Needed by uthash */
memset(key, 0, sizeof(struct hashable_key));
struct deltas *deltas;
int error;
- error = deltas_create(&deltas);
- if (error)
- return error;
+ deltas = deltas_create();
error = add_roa_deltas(new->roas, old->roas, deltas, FLAG_ANNOUNCEMENT,
'n');
atomic_uint references;
};
-int
-deltas_create(struct deltas **_result)
+struct deltas *
+deltas_create(void)
{
struct deltas *result;
result = malloc(sizeof(struct deltas));
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
deltas_v4_init(&result->v4.adds);
deltas_v4_init(&result->v4.removes);
deltas_rk_init(&result->rk.removes);
atomic_init(&result->references, 1);
- *_result = result;
- return 0;
+ return result;
}
void
delta.v4.prefix.addr = vrp->prefix.v4;
delta.v4.prefix.len = vrp->prefix_length;
delta.v4.max_length = vrp->max_prefix_length;
- return deltas_v4_add(get_deltas_array4(deltas, op), &delta.v4);
+ deltas_v4_add(get_deltas_array4(deltas, op), &delta.v4);
+ return 0;
case AF_INET6:
delta.v6.as = vrp->asn;
delta.v6.prefix.addr = vrp->prefix.v6;
delta.v6.prefix.len = vrp->prefix_length;
delta.v6.max_length = vrp->max_prefix_length;
- return deltas_v6_add(get_deltas_array6(deltas, op), &delta.v6);
+ deltas_v6_add(get_deltas_array6(deltas, op), &delta.v6);
+ return 0;
}
pr_crit("Unknown protocol: [%u %s/%u-%u %u] %c %u/%u "
switch (op) {
case FLAG_ANNOUNCEMENT:
- return deltas_rk_add(&deltas->rk.adds, &delta);
+ deltas_rk_add(&deltas->rk.adds, &delta);
+ return 0;
case FLAG_WITHDRAWAL:
- return deltas_rk_add(&deltas->rk.removes, &delta);
+ deltas_rk_add(&deltas->rk.removes, &delta);
+ return 0;
}
pr_crit("Unknown delta operation: %d", op);
struct deltas;
-int deltas_create(struct deltas **);
+struct deltas *deltas_create(void);
void deltas_refget(struct deltas *);
void deltas_refput(struct deltas *);
#include <limits.h>
#include <errno.h>
#include "config.h"
+#include "log.h"
struct deltas_array {
struct deltas **array; /* It's a circular array. */
result = malloc(sizeof(struct deltas_array));
if (result == NULL)
- return NULL;
+ enomem_panic();
result->array = calloc(config_get_deltas_lifetime(),
sizeof(struct deltas *));
- if (result->array == NULL) {
- free(result);
- return NULL;
- }
+ if (result->array == NULL)
+ enomem_panic();
result->len = 0;
result->last = UINT_MAX;
state.base = NULL;
state.deltas = darray_create();
- if (state.deltas == NULL) {
- error = pr_enomem();
- goto revert_thread_pool;
- }
/*
* Use the same start serial, the session ID will avoid
revert_deltas:
darray_destroy(state.deltas);
-revert_thread_pool:
thread_pool_destroy(pool);
return error;
}
db = db_table_create();
if (db == NULL)
- return pr_enomem();
+ enomem_panic();
error = perform_standalone_validation(pool, db);
if (error) {
ptr = malloc(sizeof(struct vrp_node));
if (ptr == NULL)
- return pr_enomem();
+ enomem_panic();
ptr->delta = *delta;
SLIST_INSERT_HEAD(filtered_vrps, ptr, next);
ptr = malloc(sizeof(struct rk_node));
if (ptr == NULL)
- return pr_enomem();
+ enomem_panic();
ptr->delta = *delta;
SLIST_INSERT_HEAD(filtered_keys, ptr, next);
request->pdu = malloc(meta->length);
if (request->pdu == NULL)
/* No error report PDU on allocation failures. */
- return pr_enomem();
+ enomem_panic();
error = meta->from_stream(&header, reader, request->pdu);
if (error) {
/* https://tools.ietf.org/html/rfc6810#section-6.3 */
return send_cache_reset_pdu(fd, args.rtr_version);
case -ENOMEM: /* Memory allocation failure */
- return pr_enomem();
+ enomem_panic();
case EAGAIN: /* Too many threads */
/*
* I think this should be more of a "try again" thing, but
data = malloc(pdu.header.length);
if (data == NULL)
- return pr_enomem();
+ enomem_panic();
len = serialize_error_report_pdu(&pdu, data);
if (len != pdu.header.length)
string = malloc(string_len + 1); /* Include NULL chara. */
if (string == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(string, reader->buffer, string_len);
reader->buffer += string_len;
tmp_addr = NULL;
tmp_serv = strdup(config_get_server_port());
if (tmp_serv == NULL)
- return pr_enomem();
+ enomem_panic();
goto done;
}
if (ptr == NULL) {
tmp_addr = strdup(full_address);
if (tmp_addr == NULL)
- return pr_enomem();
+ enomem_panic();
tmp_serv = strdup(config_get_server_port());
- if (tmp_serv == NULL) {
- free(tmp_addr);
- return pr_enomem();
- }
+ if (tmp_serv == NULL)
+ enomem_panic();
goto done;
}
tmp_addr_len = strlen(full_address) - strlen(ptr);
tmp_addr = malloc(tmp_addr_len + 1);
if (tmp_addr == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(tmp_addr, full_address, tmp_addr_len);
tmp_addr[tmp_addr_len] = '\0';
tmp_serv = strdup(ptr + 1);
- if (tmp_serv == NULL) {
- free(tmp_addr);
- return pr_enomem();
- }
+ if (tmp_serv == NULL)
+ enomem_panic();
/* Fall through */
done:
server.fd = fd;
/* Ignore failure; this is just a nice-to-have. */
server.addr = (input_addr != NULL) ? strdup(input_addr) : NULL;
- error = server_arraylist_add(&servers, &server);
- if (error) {
- close(fd);
- return error;
- }
+ server_arraylist_add(&servers, &server);
return 0; /* Happy path */
}
client.rtr_version = -1;
sockaddr2str(&client_addr, client.addr);
- if (client_arraylist_add(&clients, &client) != 0) {
- close(client.fd);
- return AV_CLIENT_ERROR;
- }
+ client_arraylist_add(&clients, &client);
pr_op_info("Client accepted [FD: %d]: %s", client.fd, client.addr);
return AV_SUCCESS;
__handle_client_request(struct rtr_client *client)
{
struct client_request *request;
- int error;
request = malloc(sizeof(struct client_request));
- if (request == NULL) {
- pr_enomem();
- return false;
- }
+ if (request == NULL)
+ enomem_panic();
request->client = client;
- if (!read_until_block(client->fd, request))
- goto cancel;
+ if (!read_until_block(client->fd, request)) {
+ free(request);
+ return false;
+ }
pr_op_debug("Client sent %zu bytes.", request->nread);
- error = thread_pool_push(request_handlers, "RTR request",
- handle_client_request, request);
- if (error)
- goto cancel;
-
+ thread_pool_push(request_handlers, "RTR request", handle_client_request,
+ request);
return true;
-
-cancel:
- free(request);
- return false;
}
static void
pollfds = calloc(servers.len + clients.len, sizeof(struct pollfd));
if (pollfds == NULL) {
- pr_enomem();
+ enomem_panic();
return PV_RETRY;
}
pr_op_info("poll() was interrupted by some signal.");
goto stop;
case ENOMEM:
- pr_enomem();
+ enomem_panic();
/* Fall through */
case EAGAIN:
goto retry;
}
}
-static int
-slurm_lists_create(struct slurm_lists **result)
+static struct slurm_lists *
+slurm_lists_create(void)
{
struct slurm_lists *cache;
cache = malloc(sizeof(struct slurm_lists));
if (cache == NULL)
- return pr_enomem();
+ enomem_panic();
al_filter_prefix_init(&cache->filter_pfx_al);
al_assertion_prefix_init(&cache->assertion_pfx_al);
al_filter_bgpsec_init(&cache->filter_bgps_al);
al_assertion_bgpsec_init(&cache->assertion_bgps_al);
- *result = cache;
- return 0;
+ return cache;
}
static void
db = malloc(sizeof(struct db_slurm));
if (db == NULL)
- return pr_enomem();
+ enomem_panic();
error = get_current_time(&db->loaded_date);
if (error) {
new.element = *elem;
new.references = 1;
+ al_filter_prefix_add(&db->cache->filter_pfx_al, &new);
- return al_filter_prefix_add(&db->cache->filter_pfx_al, &new);
+ return 0;
}
int
new.element = *elem;
new.references = 1;
+ al_assertion_prefix_add(&db->cache->assertion_pfx_al, &new);
- return al_assertion_prefix_add(&db->cache->assertion_pfx_al, &new);
+ return 0;
}
static bool
new.element = *elem;
new.references = 1;
+ al_filter_bgpsec_add(&db->cache->filter_bgps_al, &new);
- return al_filter_bgpsec_add(&db->cache->filter_bgps_al, &new);
+ return 0;
}
int
new.element = *elem;
new.references = 1;
+ al_assertion_bgpsec_add(&db->cache->assertion_bgps_al, &new);
- return al_assertion_bgpsec_add(&db->cache->assertion_bgps_al, &new);
+ return 0;
}
bool
pr_op_info("}");
}
-int
+void
db_slurm_start_cache(struct db_slurm *db)
{
- struct slurm_lists *cache;
- int error;
-
- cache = NULL;
- error = slurm_lists_create(&cache);
- if (error)
- return error;
-
- db->cache = cache;
-
- return 0;
+ db->cache = slurm_lists_create();
}
-static int
+static void
persist_filter_prefix(struct db_slurm *db)
{
struct slurm_prefix_wrap *cursor;
array_index i;
- int error;
-
- ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor, i) {
- error = al_filter_prefix_add(&db->lists.filter_pfx_al, cursor);
- if (error)
- return error;
- }
- return 0;
+ ARRAYLIST_FOREACH(&db->cache->filter_pfx_al, cursor, i)
+ al_filter_prefix_add(&db->lists.filter_pfx_al, cursor);
}
-static int
+static void
persist_filter_bgpsec(struct db_slurm *db)
{
struct slurm_bgpsec_wrap *cursor;
array_index i;
- int error;
ARRAYLIST_FOREACH(&db->cache->filter_bgps_al, cursor, i) {
- error = al_filter_bgpsec_add(&db->lists.filter_bgps_al, cursor);
- if (error)
- return error;
+ al_filter_bgpsec_add(&db->lists.filter_bgps_al, cursor);
slurm_bgpsec_wrap_refget(cursor);
}
-
- return 0;
}
-static int
+static void
persist_assertion_prefix(struct db_slurm *db)
{
struct slurm_prefix_wrap *cursor;
array_index i;
- int error;
- ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor, i) {
- error = al_assertion_prefix_add(&db->lists.assertion_pfx_al,
- cursor);
- if (error)
- return error;
- }
-
- return 0;
+ ARRAYLIST_FOREACH(&db->cache->assertion_pfx_al, cursor, i)
+ al_assertion_prefix_add(&db->lists.assertion_pfx_al, cursor);
}
-static int
+static void
persist_assertion_bgpsec(struct db_slurm *db)
{
struct slurm_bgpsec_wrap *cursor;
array_index i;
- int error;
ARRAYLIST_FOREACH(&db->cache->assertion_bgps_al, cursor, i) {
- error = al_assertion_bgpsec_add(&db->lists.assertion_bgps_al,
- cursor);
- if (error)
- return error;
+ al_assertion_bgpsec_add(&db->lists.assertion_bgps_al, cursor);
slurm_bgpsec_wrap_refget(cursor);
}
-
- return 0;
}
-int
+/* Copy all data in cache to the main lists */
+void
db_slurm_flush_cache(struct db_slurm *db)
{
- /* Copy all data in cache to the main lists */
- int error;
-
- error = persist_filter_prefix(db);
- if (error)
- return error;
-
- error = persist_filter_bgpsec(db);
- if (error)
- return error;
-
- error = persist_assertion_prefix(db);
- if (error)
- return error;
-
- error = persist_assertion_bgpsec(db);
- if (error)
- return error;
+ persist_filter_prefix(db);
+ persist_filter_bgpsec(db);
+ persist_assertion_prefix(db);
+ persist_assertion_bgpsec(db);
slurm_lists_destroy(db->cache);
db->cache = NULL;
-
- return 0;
}
bool
void db_slurm_log(struct db_slurm *);
/* Start working on the cache */
-int db_slurm_start_cache(struct db_slurm *);
+void db_slurm_start_cache(struct db_slurm *);
/* Persist all the data stored at cache and erase cache */
-int db_slurm_flush_cache(struct db_slurm *);
+void db_slurm_flush_cache(struct db_slurm *);
/* Does the SLURM DB has data? */
bool db_slurm_has_data(struct db_slurm *);
csum = malloc(sizeof(struct slurm_file_csum));
if (csum == NULL)
- return pr_enomem();
+ enomem_panic();
error = hash_local_file("sha256", location, csum->csum,
&csum->csum_len);
clone = strdup(str_prefix);
if (clone == NULL)
- return pr_enomem();
+ enomem_panic();
token = strtok(clone, "/");
isv4 = strchr(token, ':') == NULL;
if (sarray->count >= sarray->len) {
tmp = realloc(sarray->array, 2 * sarray->len * sarray->size);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
sarray->array = tmp;
sarray->len *= 2;
}
result = malloc(sizeof(struct validation));
if (!result)
- return pr_enomem();
+ enomem_panic();
error = state_store(result);
if (error)
}
params = X509_VERIFY_PARAM_new();
- if (params == NULL) {
- error = pr_enomem();
- goto abort2;
- }
+ if (params == NULL)
+ enomem_panic();
X509_VERIFY_PARAM_set_flags(params, X509_V_FLAG_CRL_CHECK);
X509_STORE_set1_param(result->x509_data.store, params);
if (error)
goto abort3;
- error = rsync_create(&result->rsync_visited_uris);
- if (error)
- goto abort4;
-
+ result->rsync_visited_uris = rsync_create();
result->rrdp_uris = db_rrdp_get_uris(tal_get_file_name(tal));
result->rrdp_workspace = db_rrdp_get_workspace(tal_get_file_name(tal));
-
result->pubkey_state = PKS_UNTESTED;
result->validation_handler = *validation_handler;
result->x509_data.params = params; /* Ownership transfered */
*out = result;
return 0;
-abort4:
- certstack_destroy(result->certstack);
abort3:
X509_VERIFY_PARAM_free(params);
-abort2:
X509_STORE_free(result->x509_data.store);
abort1:
free(result);
/**
* Does not assume that @string is NULL-terminated.
*/
-static int
-string_clone(void const *string, size_t size, char **clone)
+static char *
+string_clone(void const *string, size_t size)
{
char *result;
result = malloc(size + 1);
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
memcpy(result, string, size);
result[size] = '\0';
- *clone = result;
- return 0;
+ return result;
}
int
ia5s2string(ASN1_IA5STRING *ia5, char **result)
{
- return (ia5->flags & ASN1_STRING_FLAG_BITS_LEFT)
- ? pr_val_err("CRL URI IA5String has unused bits.")
- : string_clone(ia5->data, ia5->length, result);
+ if (ia5->flags & ASN1_STRING_FLAG_BITS_LEFT)
+ return pr_val_err("CRL URI IA5String has unused bits.");
+
+ *result = string_clone(ia5->data, ia5->length);
+ return 0;
}
int
bio = BIO_new(BIO_s_mem());
if (bio == NULL)
- return pr_enomem();
+ enomem_panic();
if (BN_print(bio, bn) == 0) {
BIO_free(bio);
written = BIO_number_written(bio);
result = malloc(written + 1);
- if (result == NULL) {
- BIO_free(bio);
- return pr_enomem();
- }
+ if (result == NULL)
+ enomem_panic();
BIO_read(bio, result, written);
result[written] = '\0';
: false;
}
-int
-token_read(struct string_tokenizer *tokenizer, char **token)
+char *
+token_read(struct string_tokenizer *tokenizer)
{
return string_clone(tokenizer->str + tokenizer->start,
- tokenizer->end - tokenizer->start, token);
+ tokenizer->end - tokenizer->start);
}
size_t
unsigned char);
bool string_tokenizer_next(struct string_tokenizer *);
bool token_equals(struct string_tokenizer *, struct string_tokenizer *);
-int token_read(struct string_tokenizer *, char **);
+char *token_read(struct string_tokenizer *);
size_t token_count(struct string_tokenizer *);
#endif /* SRC_STR_TOKEN_H_ */
"pthread_cond_signal");
}
-static int
-task_create(char const *name, thread_pool_task_cb cb, void *arg,
- struct thread_pool_task **out)
+static struct thread_pool_task *
+task_create(char const *name, thread_pool_task_cb cb, void *arg)
{
struct thread_pool_task *task;
task = malloc(sizeof(struct thread_pool_task));
if (task == NULL)
- return pr_enomem();
+ enomem_panic();
task->name = name;
task->cb = cb;
task->arg = arg;
- *out = task;
- return 0;
+ return task;
}
static void
result = malloc(sizeof(struct thread_pool));
if (result == NULL)
- return pr_enomem();
+ enomem_panic();
/* Init locking */
error = pthread_mutex_init(&result->lock, NULL);
result->working_count = 0;
result->thread_count = 0;
result->thread_ids = calloc(threads, sizeof(pthread_t));
- if (result->thread_ids == NULL) {
- error = pr_enomem();
- goto free_waiting_cond;
- }
+ if (result->thread_ids == NULL)
+ enomem_panic();
result->thread_ids_len = threads;
error = spawn_threads(result);
free_thread_ids:
free(result->thread_ids);
-free_waiting_cond:
pthread_cond_destroy(&result->worker2parent);
free_working_cond:
pthread_cond_destroy(&result->parent2worker);
* Push a new task to @pool, the task to be executed is @cb with the argument
* @arg.
*/
-int
+void
thread_pool_push(struct thread_pool *pool, char const *task_name,
thread_pool_task_cb cb, void *arg)
{
struct thread_pool_task *task;
- int error;
- task = NULL;
- error = task_create(task_name, cb, arg, &task);
- if (error)
- return error;
+ task = task_create(task_name, cb, arg);
mutex_lock(&pool->lock);
task_queue_push(pool, task);
* If not, they will claim work once they spawn anyway.
*/
signal_to_worker(pool);
- return 0;
}
/* There are available threads to work? */
void thread_pool_destroy(struct thread_pool *);
typedef void (*thread_pool_task_cb)(void *);
-int thread_pool_push(struct thread_pool *, char const *, thread_pool_task_cb,
+void thread_pool_push(struct thread_pool *, char const *, thread_pool_task_cb,
void *);
bool thread_pool_avail_threads(struct thread_pool *);
files = malloc(sizeof(struct filename_stack));
if (files == NULL)
- return;
+ enomem_panic();
files->filenames = malloc(32 * sizeof(char *));
- if (files->filenames == NULL) {
- free(files);
- return;
- }
+ if (files->filenames == NULL)
+ enomem_panic();
files->len = 0;
files->size = 32;
if (files->len >= files->size) {
tmp = realloc(files->filenames, 2 * files->size * sizeof(char *));
- if (tmp == NULL) {
- /* Oh noes */
- free(files->filenames);
- files->filenames = NULL;
- return;
- }
-
+ if (tmp == NULL)
+ enomem_panic();
files->filenames = tmp;
files->size *= 2;
}
repo = malloc(sizeof(struct working_repo));
if (repo == NULL)
- return;
+ enomem_panic();
repo->uri = NULL;
repo->level = 0;
uri->global = malloc(str_len + 1);
if (uri->global == NULL)
- return pr_enomem();
+ enomem_panic();
strncpy(uri->global, str, str_len);
uri->global[str_len] = '\0';
uri->global_len = str_len;
dir_len = (slash_pos + 1) - mft;
joined = malloc(dir_len + ia5->size + 1);
if (joined == NULL)
- return pr_enomem();
+ enomem_panic();
strncpy(joined, mft, dir_len);
strncpy(joined + dir_len, (char *) ia5->buf, ia5->size);
return 0;
}
-static int
-get_local_workspace(char **result)
+static char *
+get_local_workspace(void)
{
char const *workspace;
char *tmp;
workspace = db_rrdp_uris_workspace_get();
- if (workspace == NULL) {
- *result = NULL;
- return 0;
- }
+ if (workspace == NULL)
+ return NULL;
tmp = strdup(workspace);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
- *result = tmp;
- return 0;
+ return tmp;
}
/**
if (error)
return error;
- workspace = NULL;
- if ((flags & URI_USE_RRDP_WORKSPACE) != 0) {
- error = get_local_workspace(&workspace);
- if (error)
- return error;
- }
+ workspace = ((flags & URI_USE_RRDP_WORKSPACE) != 0)
+ ? get_local_workspace()
+ : NULL;
- error = map_uri_to_local(global,
+ local = map_uri_to_local(global,
type == URI_RSYNC ? PFX_RSYNC : PFX_HTTPS,
- workspace,
- &local);
- if (error) {
- free(workspace);
- return error;
- }
+ workspace);
free(workspace);
*result = local;
uri = malloc(sizeof(struct rpki_uri));
if (uri == NULL)
- return pr_enomem();
+ enomem_panic();
error = str2global(guri, guri_len, uri);
if (error) {
uri = malloc(sizeof(struct rpki_uri));
if (uri == NULL)
- return pr_enomem();
+ enomem_panic();
error = ia5str2global(uri, mft->global, ia5);
if (error) {
DEFINE_ARRAY_LIST_STRUCT(uris_roots, char *);
DEFINE_ARRAY_LIST_FUNCTIONS(uris_roots, char *, static)
-static int
-visited_elem_create(struct visited_elem **elem, char const *uri)
+static struct visited_elem *
+visited_elem_create(char const *uri)
{
struct visited_elem *tmp;
tmp = malloc(sizeof(struct visited_elem));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
/* Needed by uthash */
memset(tmp, 0, sizeof(struct visited_elem));
tmp->uri = strdup(uri);
if (tmp->uri == NULL) {
free(tmp);
- return pr_enomem();
+ enomem_panic();
}
- *elem = tmp;
- return 0;
+ return tmp;
}
static void
free(elem);
}
-int
-visited_uris_create(struct visited_uris **uris)
+struct visited_uris *
+visited_uris_create(void)
{
struct visited_uris *tmp;
tmp = malloc(sizeof(struct visited_uris));
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
tmp->table = NULL;
tmp->refs = 1;
- *uris = tmp;
- return 0;
+ return tmp;
}
static void
return found;
}
-int
+void
visited_uris_add(struct visited_uris *uris, char const *uri)
{
- struct visited_elem *elem;
- int error;
-
- if (elem_find(uris, uri) != NULL)
- return 0; /* Exists, don't add again */
-
- elem = NULL;
- error = visited_elem_create(&elem, uri);
- if (error)
- return error;
-
- HASH_ADD_STR(uris->table, uri, elem);
- return 0;
+ if (elem_find(uris, uri) == NULL)
+ HASH_ADD_STR(uris->table, uri, visited_elem_create(uri));
}
int
return 0;
}
-static int
+static void
visited_uris_to_arr(struct visited_uris *uris, struct uris_roots *roots)
{
struct visited_elem *elem;
size = last_slash - elem->uri;
tmp = malloc(size + 1);
if (tmp == NULL)
- return pr_enomem();
+ enomem_panic();
strncpy(tmp, elem->uri, size);
tmp[size] = '\0';
uris_roots_add(roots, &tmp);
}
-
- return 0;
}
static void
int error;
uris_roots_init(&roots);
-
- error = visited_uris_to_arr(uris, &roots);
- if (error)
- goto err;
-
+ visited_uris_to_arr(uris, &roots);
if (roots.len == 0)
goto success;
error = delete_dir_daemon_start(roots.array, roots.len, workspace);
- if (error)
- goto err;
+ if (error) {
+ uris_roots_cleanup(&roots, uris_root_destroy);
+ return error;
+ }
+
success:
uris_roots_cleanup(&roots, uris_root_destroy);
return 0;
-err:
- uris_roots_cleanup(&roots, uris_root_destroy);
- return error;
}
struct visited_uris;
-int visited_uris_create(struct visited_uris **);
+struct visited_uris *visited_uris_create(void);
void visited_uris_refput(struct visited_uris *);
void visited_uris_refget(struct visited_uris *);
-int visited_uris_add(struct visited_uris *, char const *);
+void visited_uris_add(struct visited_uris *, char const *);
int visited_uris_remove(struct visited_uris *, char const *);
int visited_uris_delete_local(struct visited_uris *, char const *);
va_start(vl, deltas);
while ((delta.serial = va_arg(vl, unsigned long)) != END)
- ck_assert_int_eq(0, deltas_head_add(deltas, &delta));
+ deltas_head_add(deltas, &delta);
va_end(vl);
}
{
struct rpki_uri *uri;
ck_assert_int_eq(0, uri_create_rsync_str(&uri, uri_str, strlen(uri_str)));
- ck_assert_int_eq(mark_as_downloaded(uri, visited_uris), 0);
+ mark_as_downloaded(uri, visited_uris);
uri_refput(uri);
}
{
struct uri_list *visited_uris;
- visited_uris = NULL;
- ck_assert_int_eq(rsync_create(&visited_uris), 0);
+ visited_uris = rsync_create();
+ ck_assert_ptr_nonnull(visited_uris);
__mark_as_downloaded("rsync://example.foo/repository/", visited_uris);
__mark_as_downloaded("rsync://example.foo/member_repository/",
darray = darray_create();
ck_assert_ptr_ne(NULL, darray);
- for (i = 0; i < TOTAL_CREATED; i++)
- ck_assert_int_eq(0, deltas_create(&created[i]));
+ for (i = 0; i < TOTAL_CREATED; i++) {
+ created[i] = deltas_create();
+ ck_assert_ptr_nonnull(created[i]);
+ }
test_foreach(darray, 0, 0);
bool actual_deltas[12];
array_index i;
- ck_assert_int_eq(0, deltas_create(&deltas));
+ deltas = deltas_create();
+ ck_assert_ptr_nonnull(deltas);
ck_assert_int_eq(0, vrps_foreach_delta_since(from, &actual_serial,
vrp_add, rk_add, deltas));
/* Nothing to close */
}
-int
-map_uri_to_local(char const *uri, char const *uri_prefix, char const *workspace,
- char **result)
+char *
+map_uri_to_local(char const *uri, char const *uri_prefix, char const *workspace)
{
+ char *result;
+
/* These tests focus on global URIs, so set a dummy value */
- *result = strdup("dummy");
- if (*result == NULL)
- return -ENOMEM;
- return 0;
+ result = strdup("dummy");
+ if (result == NULL)
+ enomem_panic();
+
+ return result;
}
void
config_set_http_priority(60);
config_set_rsync_priority(50);
- ck_assert_int_eq(tal_order_uris(tal), 0);
+ tal_order_uris(tal);
ck_assert_str_eq(tal->uris.array[0]->global, "https://potato");
ck_assert_str_eq(tal->uris.array[1]->global,
config_set_http_priority(50);
config_set_rsync_priority(60);
- ck_assert_int_eq(tal_order_uris(tal), 0);
+ tal_order_uris(tal);
ck_assert_str_eq(tal->uris.array[0]->global,
"rsync://repository.lacnic.net/rpki/lacnic/rta-lacnic-rpki.cer");