root/source4/libcli/raw/rawioctl.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. smb_raw_smbioctl_send
  2. smb_raw_smbioctl_recv
  3. smb_raw_ntioctl_send
  4. smb_raw_ntioctl_recv
  5. smb_raw_ioctl_send
  6. smb_raw_ioctl_recv
  7. smb_raw_ioctl

   1 /* 
   2    Unix SMB/CIFS implementation.
   3    client file operations
   4    Copyright (C) Andrew Tridgell 2003
   5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
   6    
   7    This program is free software; you can redistribute it and/or modify
   8    it under the terms of the GNU General Public License as published by
   9    the Free Software Foundation; either version 3 of the License, or
  10    (at your option) any later version.
  11    
  12    This program is distributed in the hope that it will be useful,
  13    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15    GNU General Public License for more details.
  16    
  17    You should have received a copy of the GNU General Public License
  18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19 */
  20 
  21 #include "includes.h"
  22 #include "libcli/raw/libcliraw.h"
  23 #include "libcli/raw/raw_proto.h"
  24 
  25 #define SETUP_REQUEST(cmd, wct, buflen) do { \
  26         req = smbcli_request_setup(tree, cmd, wct, buflen); \
  27         if (!req) return NULL; \
  28 } while (0)
  29 
  30 /* 
  31    send a raw smb ioctl - async send
  32 */
  33 static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree, 
     /* [<][>][^][v][top][bottom][index][help] */
  34                                                  union smb_ioctl *parms)
  35 {
  36         struct smbcli_request *req; 
  37 
  38         SETUP_REQUEST(SMBioctl, 3, 0);
  39 
  40         SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.file.fnum);
  41         SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request);
  42 
  43         if (!smbcli_request_send(req)) {
  44                 smbcli_request_destroy(req);
  45                 return NULL;
  46         }
  47 
  48         return req;
  49 }
  50 
  51 /* 
  52    send a raw smb ioctl - async recv
  53 */
  54 static NTSTATUS smb_raw_smbioctl_recv(struct smbcli_request *req, 
     /* [<][>][^][v][top][bottom][index][help] */
  55                                       TALLOC_CTX *mem_ctx, 
  56                                       union smb_ioctl *parms)
  57 {
  58         if (!smbcli_request_receive(req) ||
  59             smbcli_request_is_error(req)) {
  60                 return smbcli_request_destroy(req);
  61         }
  62 
  63         parms->ioctl.out.blob = smbcli_req_pull_blob(&req->in.bufinfo, mem_ctx, req->in.data, -1);
  64         return smbcli_request_destroy(req);
  65 }
  66 
  67 
  68 
  69 /****************************************************************************
  70 NT ioctl (async send)
  71 ****************************************************************************/
  72 static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, 
     /* [<][>][^][v][top][bottom][index][help] */
  73                                                 union smb_ioctl *parms)
  74 {
  75         struct smb_nttrans nt;
  76         uint8_t setup[8];
  77 
  78         nt.in.max_setup = 4;
  79         nt.in.max_param = 0;
  80         nt.in.max_data = parms->ntioctl.in.max_data;
  81         nt.in.setup_count = 4;
  82         nt.in.setup = setup;
  83         SIVAL(setup, 0, parms->ntioctl.in.function);
  84         SSVAL(setup, 4, parms->ntioctl.in.file.fnum);
  85         SCVAL(setup, 6, parms->ntioctl.in.fsctl);
  86         SCVAL(setup, 7, parms->ntioctl.in.filter);
  87         nt.in.function = NT_TRANSACT_IOCTL;
  88         nt.in.params = data_blob(NULL, 0);
  89         nt.in.data = parms->ntioctl.in.blob;
  90 
  91         return smb_raw_nttrans_send(tree, &nt);
  92 }
  93 
  94 /****************************************************************************
  95 NT ioctl (async recv)
  96 ****************************************************************************/
  97 static NTSTATUS smb_raw_ntioctl_recv(struct smbcli_request *req, 
     /* [<][>][^][v][top][bottom][index][help] */
  98                                      TALLOC_CTX *mem_ctx,
  99                                      union smb_ioctl *parms)
 100 {
 101         NTSTATUS status;
 102         struct smb_nttrans nt;
 103         TALLOC_CTX *tmp_mem;
 104 
 105         tmp_mem = talloc_new(mem_ctx);
 106         NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
 107 
 108         status = smb_raw_nttrans_recv(req, tmp_mem, &nt);
 109         if (!NT_STATUS_IS_OK(status)) goto fail;
 110 
 111         parms->ntioctl.out.blob = nt.out.data;
 112         talloc_steal(mem_ctx, parms->ntioctl.out.blob.data);
 113 
 114 fail:
 115         talloc_free(tmp_mem);
 116         return status;
 117 }
 118 
 119 
 120 /* 
 121    send a raw ioctl - async send
 122 */
 123 struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms)
     /* [<][>][^][v][top][bottom][index][help] */
 124 {
 125         struct smbcli_request *req = NULL;
 126         
 127         switch (parms->generic.level) {
 128         case RAW_IOCTL_IOCTL:
 129                 req = smb_raw_smbioctl_send(tree, parms);
 130                 break;
 131                 
 132         case RAW_IOCTL_NTIOCTL:
 133                 req = smb_raw_ntioctl_send(tree, parms);
 134                 break;
 135 
 136         case RAW_IOCTL_SMB2:
 137         case RAW_IOCTL_SMB2_NO_HANDLE:
 138                 return NULL;
 139         }
 140 
 141         return req;
 142 }
 143 
 144 /* 
 145    recv a raw ioctl - async recv
 146 */
 147 NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req,
     /* [<][>][^][v][top][bottom][index][help] */
 148                             TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
 149 {
 150         switch (parms->generic.level) {
 151         case RAW_IOCTL_IOCTL:
 152                 return smb_raw_smbioctl_recv(req, mem_ctx, parms);
 153                 
 154         case RAW_IOCTL_NTIOCTL:
 155                 return smb_raw_ntioctl_recv(req, mem_ctx, parms);
 156 
 157         case RAW_IOCTL_SMB2:
 158         case RAW_IOCTL_SMB2_NO_HANDLE:
 159                 break;
 160         }
 161         return NT_STATUS_INVALID_LEVEL;
 162 }
 163 
 164 /* 
 165    send a raw ioctl - sync interface
 166 */
 167 NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, 
     /* [<][>][^][v][top][bottom][index][help] */
 168                 TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
 169 {
 170         struct smbcli_request *req;
 171         req = smb_raw_ioctl_send(tree, parms);
 172         return smb_raw_ioctl_recv(req, mem_ctx, parms);
 173 }

/* [<][>][^][v][top][bottom][index][help] */