From: Jeremy Allison Date: Sat, 18 May 2019 18:18:19 +0000 (-0700) Subject: s3: lib: Add file_ploadv_send(). X-Git-Tag: ldb-2.0.5~627 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=61054e53f53e5884902b566b1f9b454a3ff4741f;p=thirdparty%2Fsamba.git s3: lib: Add file_ploadv_send(). Not yet used. Preparing to remove file_pload_send() with this safer alternative. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13964 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 8f91f7d00fb..6ee2d58b532 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -65,6 +65,35 @@ struct tevent_req *file_pload_send(TALLOC_CTX *mem_ctx, return req; } +struct tevent_req *file_ploadv_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + char * const argl[], size_t maxsize) +{ + struct tevent_req *req = NULL, *subreq = NULL; + struct file_pload_state *state = NULL; + + req = tevent_req_create(mem_ctx, &state, struct file_pload_state); + if (req == NULL) { + return NULL; + } + state->ev = ev; + state->maxsize = maxsize; + + state->fd = sys_popenv(argl); + if (state->fd == -1) { + tevent_req_error(req, errno); + return tevent_req_post(req, ev); + } + talloc_set_destructor(state, file_pload_state_destructor); + + subreq = wait_for_read_send(state, state->ev, state->fd, false); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, file_pload_readable, req); + return req; +} + static int file_pload_state_destructor(struct file_pload_state *s) { if (s->fd != -1) { diff --git a/source3/lib/util_file.h b/source3/lib/util_file.h index 9cf00aae893..fe2782fd349 100644 --- a/source3/lib/util_file.h +++ b/source3/lib/util_file.h @@ -26,6 +26,9 @@ struct tevent_req *file_pload_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *syscmd, size_t maxsize); +struct tevent_req *file_ploadv_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + char * const argl[], size_t maxsize); int file_pload_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, uint8_t **buf); char **file_lines_ploadv(TALLOC_CTX *mem_ctx,