s3: lib: Add file_ploadv_send().
authorJeremy Allison <jra@samba.org>
Sat, 18 May 2019 18:18:19 +0000 (11:18 -0700)
committerJeremy Allison <jra@samba.org>
Fri, 24 May 2019 19:00:05 +0000 (19:00 +0000)
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 <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/util_file.c
source3/lib/util_file.h

index 8f91f7d00fb2d3b9d2b096e002c3af02b7c783e9..6ee2d58b53203bc8c5d5e519e982b14fb8deb319 100644 (file)
@@ -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) {
index 9cf00aae8936ca98c25313f78700f81ae042d8ac..fe2782fd349c22463489d072c23063902a0bad2e 100644 (file)
@@ -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,