r23138: added a raw interface for SMBecho operations
authorAndrew Tridgell <tridge@samba.org>
Fri, 25 May 2007 10:42:29 +0000 (10:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:52:55 +0000 (14:52 -0500)
(This used to be commit 590c6c21db5abd436441a9af62ee65436d6f1222)

source4/libcli/raw/clitransport.c
source4/libcli/raw/interfaces.h

index ea2aa880b657c73de3ab38acc281d8b3f86606e1..71c87e631aff87dc21f5bef17a97c71eacaf4108 100644 (file)
@@ -593,3 +593,71 @@ void smbcli_transport_send(struct smbcli_request *req)
 
        talloc_set_destructor(req, smbcli_request_destructor);
 }
+
+
+/****************************************************************************
+ Send an SMBecho (async send)
+*****************************************************************************/
+struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport,
+                                        struct smb_echo *p)
+{
+       struct smbcli_request *req;
+
+       req = smbcli_request_setup_transport(transport, SMBecho, 1, p->in.size);
+       if (!req) return NULL;
+
+       SSVAL(req->out.vwv, VWV(0), p->in.repeat_count);
+
+       memcpy(req->out.data, p->in.data, p->in.size);
+
+       ZERO_STRUCT(p->out);
+
+       if (!smbcli_request_send(req)) {
+               smbcli_request_destroy(req);
+               return NULL;
+       }
+
+       return req;
+}
+
+/****************************************************************************
+ raw echo interface (async recv)
+****************************************************************************/
+NTSTATUS smb_raw_echo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx,
+                          struct smb_echo *p)
+{
+       if (!smbcli_request_receive(req) ||
+           smbcli_request_is_error(req)) {
+               goto failed;
+       }
+
+       SMBCLI_CHECK_WCT(req, 1);
+       p->out.count++;
+       p->out.sequence_number = SVAL(req->in.vwv, VWV(0));
+       p->out.size = req->in.data_size;
+       talloc_free(p->out.data);
+       p->out.data = talloc_size(mem_ctx, p->out.size);
+       NT_STATUS_HAVE_NO_MEMORY(p->out.data);
+
+       if (!smbcli_raw_pull_data(req, req->in.data, p->out.size, p->out.data)) {
+               req->status = NT_STATUS_BUFFER_TOO_SMALL;
+       }
+
+       if (p->out.count == p->in.repeat_count) {
+               return smbcli_request_destroy(req);
+       }
+
+       return NT_STATUS_OK;
+
+failed:
+       return smbcli_request_destroy(req);
+}
+
+/****************************************************************************
+ Send a echo (sync interface)
+*****************************************************************************/
+NTSTATUS smb_raw_echo(struct smbcli_transport *transport, struct smb_echo *p)
+{
+       struct smbcli_request *req = smb_raw_echo_send(transport, p);
+       return smbcli_request_simple_recv(req);
+}
index d0c3ab2d154bceb8fd9e56baae4fe167fb0f5a24..93d8dd2c20a02de29cfe4bbbd61f0aecb74ffa55 100644 (file)
@@ -2614,4 +2614,22 @@ union smb_search_close {
        } findclose;
 };
 
+
+/*
+  struct for SMBecho call
+*/
+struct smb_echo {
+       struct {
+               uint16_t repeat_count;
+               uint16_t size;
+               uint8_t *data;
+       } in;
+       struct {
+               uint16_t count;
+               uint16_t sequence_number;
+               uint16_t size;
+               uint8_t *data;
+       } out;
+};
+
 #endif /* __LIBCLI_RAW_INTERFACES_H__ */