libsmb: Add cli_create_send/recv
authorVolker Lendecke <vl@samba.org>
Fri, 20 Jun 2014 08:41:59 +0000 (08:41 +0000)
committerVolker Lendecke <vl@samba.org>
Sat, 21 Jun 2014 18:38:11 +0000 (20:38 +0200)
Async wrapper around smb1 and smb2 create

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/clifile.c
source3/libsmb/proto.h

index 1c527303e66f47ee00493f2813d6c859963456fe..6fd4f39e3b32bcdcd0257985f452eba28743cd5a 100644 (file)
@@ -1919,6 +1919,90 @@ NTSTATUS cli_ntcreate_recv(struct tevent_req *req,
        return NT_STATUS_OK;
 }
 
+struct cli_create_state {
+       NTSTATUS (*recv)(struct tevent_req *req, uint16_t *fnum,
+                        struct smb_create_returns *cr);
+       struct smb_create_returns cr;
+       uint16_t fnum;
+};
+
+static void cli_create_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_create_send(TALLOC_CTX *mem_ctx,
+                                  struct tevent_context *ev,
+                                  struct cli_state *cli,
+                                  const char *fname,
+                                  uint32_t create_flags,
+                                  uint32_t desired_access,
+                                  uint32_t file_attributes,
+                                  uint32_t share_access,
+                                  uint32_t create_disposition,
+                                  uint32_t create_options,
+                                  uint8_t security_flags)
+{
+       struct tevent_req *req, *subreq;
+       struct cli_create_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct cli_create_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               state->recv = cli_smb2_create_fnum_recv;
+               subreq = cli_smb2_create_fnum_send(
+                       state, ev, cli, fname, create_flags, desired_access,
+                       file_attributes, share_access, create_disposition,
+                       create_options);
+       } else {
+               state->recv = cli_ntcreate_recv;
+               subreq = cli_ntcreate_send(
+                       state, ev, cli, fname, create_flags, desired_access,
+                       file_attributes, share_access, create_disposition,
+                       create_options, security_flags);
+       }
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_create_done, req);
+       return req;
+}
+
+static void cli_create_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct cli_create_state *state = tevent_req_data(
+               req, struct cli_create_state);
+       NTSTATUS status;
+
+       status = state->recv(subreq, &state->fnum, &state->cr);
+       TALLOC_FREE(subreq);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS cli_create_recv(struct tevent_req *req, uint16_t *fnum,
+                        struct smb_create_returns *cr)
+{
+       struct cli_create_state *state = tevent_req_data(
+               req, struct cli_create_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       if (fnum != NULL) {
+               *fnum = state->fnum;
+       }
+       if (cr != NULL) {
+               *cr = state->cr;
+       }
+       return NT_STATUS_OK;
+}
+
 NTSTATUS cli_ntcreate(struct cli_state *cli,
                      const char *fname,
                      uint32_t CreatFlags,
index 63d2df4a37cd1c13a328e7c92926f06b0c36a6f4..7c09e588f68265b0e93e5f1c49a3187d102574cd 100644 (file)
@@ -359,6 +359,19 @@ struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
 NTSTATUS cli_ntcreate_recv(struct tevent_req *req,
                        uint16_t *pfnum,
                        struct smb_create_returns *cr);
+struct tevent_req *cli_create_send(TALLOC_CTX *mem_ctx,
+                                  struct tevent_context *ev,
+                                  struct cli_state *cli,
+                                  const char *fname,
+                                  uint32_t create_flags,
+                                  uint32_t desired_access,
+                                  uint32_t file_attributes,
+                                  uint32_t share_access,
+                                  uint32_t create_disposition,
+                                  uint32_t create_options,
+                                  uint8_t security_flags);
+NTSTATUS cli_create_recv(struct tevent_req *req, uint16_t *fnum,
+                        struct smb_create_returns *cr);
 NTSTATUS cli_ntcreate(struct cli_state *cli,
                      const char *fname,
                      uint32_t CreatFlags,