diff options
author | David Timber <mieabby@gmail.com> | 2021-07-25 18:40:16 +1000 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2021-07-25 18:40:16 +1000 |
commit | a72b876cf8f7c01ab2d3808a168ef16620498298 (patch) | |
tree | 43b259cf3a20636f52aebd2d777f89cf95d66673 /src/proone-htbthost.c | |
parent | d875ed3b36f2a3fb5d6ceb3c37f6749603e4d0d3 (diff) |
Impl htbt M2M binary update and bug fixes ...
* Change signature of tmpfile() cb
* Add PRNE_DATA_KEY_VER_MAT
* Add prne_try_alloc_iobuf()
* Fix htbt: don't run cncp when both resolv and cnc_txtrec are not passed
* Impl upbin cb on proone-bne
* Fix proone-htbtclient: content of status frame was discarded
* htbt is now responsible for setting FD_CLOEXEC on temp files
* Changes in mttools for valgrind run
* Add proone-test_iobuf
* Fix event leak in resolv
* src/test-resolv.sh: run proone-resolv on valgrind
* Add prne_cmp_uuid_asc() and prne_cmp_uuid_desc() for version matrix
*
Diffstat (limited to 'src/proone-htbthost.c')
-rw-r--r-- | src/proone-htbthost.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/proone-htbthost.c b/src/proone-htbthost.c index fdf7c1e..4aee540 100644 --- a/src/proone-htbthost.c +++ b/src/proone-htbthost.c @@ -292,10 +292,17 @@ static bool parse_param (const char *arg) { return true; } -static char *mktmpfile (void *ctx, size_t req_size, const mode_t mode) { +static int mktmpfile ( + void *ctx, + const int flags, + const mode_t mode, + size_t req_size, + char **opath) +{ static int ctr = 0; - char *path = NULL, *ret = NULL; + char *path = NULL; int fd = -1, len; + bool ret = false; len = snprintf(NULL, 0, "htbthost-tmp.%d", ctr); if (len < 0) { @@ -309,27 +316,33 @@ static char *mktmpfile (void *ctx, size_t req_size, const mode_t mode) { if (len != snprintf(path, len + 1, "htbthost-tmp.%d", ctr)) { goto END; } + ctr += 1; - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); + fd = open(path, flags, mode); if (fd < 0) { goto END; } - fcntl(fd, F_SETFD, FD_CLOEXEC); - if (ftruncate(fd, (off_t)req_size) != 0) { goto END; } + ret = true; - ret = path; - path = NULL; - ctr += 1; END: - if (path != NULL && fd >= 0) { - unlink(path); + if (ret) { + if (opath != NULL) { + *opath = path; + path = NULL; + } + } + else { + if (fd >= 0) { + unlink(path); + } + prne_close(fd); + fd = -1; } prne_free(path); - prne_close(fd); - return ret; + return fd; } static void do_run_upbin (void) { @@ -540,11 +553,11 @@ int main (const int argc, const char **args) { free_htbthost_param(&htbthost_param); regfree(&re_ns4); regfree(&re_ns6); + regfree(&re_hc); prne_free(hostcred); if (prne_nstrlen(m_upbin_path) > 0) { do_run_upbin(); - return 3; } return 0; |