LCOV - code coverage report
Current view: top level - source4/libcli/raw - rawioctl.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 59 69 85.5 %
Date: 2023-11-21 12:31:41 Functions: 7 7 100.0 %

          Line data    Source code
       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           3 : static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree,
      34             :                                                  union smb_ioctl *parms)
      35             : {
      36           0 :         struct smbcli_request *req;
      37             : 
      38           3 :         SETUP_REQUEST(SMBioctl, 3, 0);
      39             : 
      40           3 :         SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.file.fnum);
      41           3 :         SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request);
      42             : 
      43           3 :         if (!smbcli_request_send(req)) {
      44           0 :                 smbcli_request_destroy(req);
      45           0 :                 return NULL;
      46             :         }
      47             : 
      48           3 :         return req;
      49             : }
      50             : 
      51             : /*
      52             :    send a raw smb ioctl - async recv
      53             : */
      54           3 : static NTSTATUS smb_raw_smbioctl_recv(struct smbcli_request *req,
      55             :                                       TALLOC_CTX *mem_ctx,
      56             :                                       union smb_ioctl *parms)
      57             : {
      58           6 :         if (!smbcli_request_receive(req) ||
      59           3 :             smbcli_request_is_error(req)) {
      60           3 :                 return smbcli_request_destroy(req);
      61             :         }
      62             : 
      63           0 :         parms->ioctl.out.blob = smbcli_req_pull_blob(&req->in.bufinfo, mem_ctx, req->in.data, -1);
      64           0 :         return smbcli_request_destroy(req);
      65             : }
      66             : 
      67             : 
      68             : 
      69             : /****************************************************************************
      70             : NT ioctl (async send)
      71             : ****************************************************************************/
      72          30 : static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree,
      73             :                                                 union smb_ioctl *parms)
      74             : {
      75           4 :         struct smb_nttrans nt;
      76           4 :         uint8_t setup[8];
      77             : 
      78          30 :         nt.in.max_setup = 4;
      79          30 :         nt.in.max_param = 0;
      80          30 :         nt.in.max_data = parms->ntioctl.in.max_data;
      81          30 :         nt.in.setup_count = 4;
      82          30 :         nt.in.setup = setup;
      83          30 :         SIVAL(setup, 0, parms->ntioctl.in.function);
      84          30 :         SSVAL(setup, 4, parms->ntioctl.in.file.fnum);
      85          30 :         SCVAL(setup, 6, parms->ntioctl.in.fsctl);
      86          30 :         SCVAL(setup, 7, parms->ntioctl.in.filter);
      87          30 :         nt.in.function = NT_TRANSACT_IOCTL;
      88          30 :         nt.in.params = data_blob(NULL, 0);
      89          30 :         nt.in.data = parms->ntioctl.in.blob;
      90             : 
      91          30 :         return smb_raw_nttrans_send(tree, &nt);
      92             : }
      93             : 
      94             : /****************************************************************************
      95             : NT ioctl (async recv)
      96             : ****************************************************************************/
      97          30 : static NTSTATUS smb_raw_ntioctl_recv(struct smbcli_request *req,
      98             :                                      TALLOC_CTX *mem_ctx,
      99             :                                      union smb_ioctl *parms)
     100             : {
     101           4 :         NTSTATUS status;
     102           4 :         struct smb_nttrans nt;
     103           4 :         TALLOC_CTX *tmp_mem;
     104             : 
     105          30 :         tmp_mem = talloc_new(mem_ctx);
     106          30 :         NT_STATUS_HAVE_NO_MEMORY(tmp_mem);
     107             : 
     108          30 :         status = smb_raw_nttrans_recv(req, tmp_mem, &nt);
     109          30 :         if (!NT_STATUS_IS_OK(status)) goto fail;
     110             : 
     111          25 :         parms->ntioctl.out.blob = nt.out.data;
     112          25 :         talloc_steal(mem_ctx, parms->ntioctl.out.blob.data);
     113             : 
     114          30 : fail:
     115          30 :         talloc_free(tmp_mem);
     116          30 :         return status;
     117             : }
     118             : 
     119             : 
     120             : /*
     121             :    send a raw ioctl - async send
     122             : */
     123          33 : struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms)
     124             : {
     125          33 :         struct smbcli_request *req = NULL;
     126             : 
     127          33 :         switch (parms->generic.level) {
     128           3 :         case RAW_IOCTL_IOCTL:
     129           3 :                 req = smb_raw_smbioctl_send(tree, parms);
     130           3 :                 break;
     131             : 
     132          30 :         case RAW_IOCTL_NTIOCTL:
     133          30 :                 req = smb_raw_ntioctl_send(tree, parms);
     134          30 :                 break;
     135             : 
     136           0 :         case RAW_IOCTL_SMB2:
     137             :         case RAW_IOCTL_SMB2_NO_HANDLE:
     138           0 :                 return NULL;
     139             :         }
     140             : 
     141          29 :         return req;
     142             : }
     143             : 
     144             : /*
     145             :    recv a raw ioctl - async recv
     146             : */
     147          33 : NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req,
     148             :                             TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
     149             : {
     150          33 :         switch (parms->generic.level) {
     151           3 :         case RAW_IOCTL_IOCTL:
     152           3 :                 return smb_raw_smbioctl_recv(req, mem_ctx, parms);
     153             : 
     154          30 :         case RAW_IOCTL_NTIOCTL:
     155          30 :                 return smb_raw_ntioctl_recv(req, mem_ctx, parms);
     156             : 
     157           0 :         case RAW_IOCTL_SMB2:
     158             :         case RAW_IOCTL_SMB2_NO_HANDLE:
     159           0 :                 break;
     160             :         }
     161           0 :         return NT_STATUS_INVALID_LEVEL;
     162             : }
     163             : 
     164             : /*
     165             :    send a raw ioctl - sync interface
     166             : */
     167          33 : NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree,
     168             :                 TALLOC_CTX *mem_ctx, union smb_ioctl *parms)
     169             : {
     170           4 :         struct smbcli_request *req;
     171          33 :         req = smb_raw_ioctl_send(tree, parms);
     172          33 :         return smb_raw_ioctl_recv(req, mem_ctx, parms);
     173             : }

Generated by: LCOV version 1.14