libsmb: Add cli_setfileinfo_send/recv()
authorVolker Lendecke <vl@samba.org>
Mon, 30 Mar 2020 13:12:48 +0000 (15:12 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 8 Apr 2020 14:46:39 +0000 (14:46 +0000)
Encapsulate TRANSACT2_SETFILEINFO like cli_setpathinfo_send() does for
TRANSACT2_SETPATHINFO.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/libsmb/clifile.c
source3/libsmb/proto.h

index dd08b0e30f35fa3fe8347c4f7d0ce026a51ac900..1f1a757f7bbb7c2333dcb7e98290fd5e700f2c8f 100644 (file)
@@ -149,6 +149,83 @@ NTSTATUS cli_setpathinfo(struct cli_state *cli,
        return status;
 }
 
+struct cli_setfileinfo_state {
+       uint16_t setup;
+       uint8_t param[6];
+};
+
+static void cli_setfileinfo_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_setfileinfo_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       uint16_t fnum,
+       uint16_t level,
+       uint8_t *data,
+       size_t data_len)
+{
+       struct tevent_req *req = NULL, *subreq = NULL;
+       struct cli_setfileinfo_state *state = NULL;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_setfileinfo_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       PUSH_LE_U16(&state->setup, 0, TRANSACT2_SETFILEINFO);
+
+       PUSH_LE_U16(state->param, 0, fnum);
+       PUSH_LE_U16(state->param, 2, level);
+
+       subreq = cli_trans_send(state,          /* mem ctx. */
+                               ev,             /* event ctx. */
+                               cli,            /* cli_state. */
+                               0,              /* additional_flags2 */
+                               SMBtrans2,      /* cmd. */
+                               NULL,           /* pipe name. */
+                               -1,             /* fid. */
+                               0,              /* function. */
+                               0,              /* flags. */
+                               &state->setup,  /* setup. */
+                               1,              /* num setup uint16_t words. */
+                               0,              /* max returned setup. */
+                               state->param,   /* param. */
+                               6,              /* num param. */
+                               2,              /* max returned param. */
+                               data,           /* data. */
+                               data_len,       /* num data. */
+                               0);             /* max returned data. */
+
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_setfileinfo_done, req);
+       return req;
+}
+
+static void cli_setfileinfo_done(struct tevent_req *subreq)
+{
+       NTSTATUS status = cli_trans_recv(
+               subreq,         /* req */
+               NULL,           /* mem_ctx */
+               NULL,           /* recv_flags2 */
+               NULL,           /* setup */
+               0,              /* min_setup */
+               NULL,           /* num_setup */
+               NULL,           /* param */
+               0,              /* min_param */
+               NULL,           /* num_param */
+               NULL,           /* data */
+               0,              /* min_data */
+               NULL);          /* num_data */
+       tevent_req_simple_finish_ntstatus(subreq, status);
+}
+
+NTSTATUS cli_setfileinfo_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
 /****************************************************************************
  Hard/Symlink a file (UNIX extensions).
  Creates new name (sym)linked to link_target.
index 0e2c1adb4ae2890185c0bedfdeaa0eaf304900c9..879a9dae8efee4f10cf8327f0c3110e262cc8246 100644 (file)
@@ -251,6 +251,15 @@ NTSTATUS cli_setpathinfo(struct cli_state *cli,
                         const char *path,
                         uint8_t *data,
                         size_t data_len);
+struct tevent_req *cli_setfileinfo_send(
+       TALLOC_CTX *mem_ctx,
+       struct tevent_context *ev,
+       struct cli_state *cli,
+       uint16_t fnum,
+       uint16_t level,
+       uint8_t *data,
+       size_t data_len);
+NTSTATUS cli_setfileinfo_recv(struct tevent_req *req);
 
 struct tevent_req *cli_posix_symlink_send(TALLOC_CTX *mem_ctx,
                                        struct tevent_context *ev,