LCOV - code coverage report
Current view: top level - source4/libcli/smb2 - setinfo.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 38 45 84.4 %
Date: 2024-04-21 15:09:00 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    SMB2 client setinfo calls
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2005
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "libcli/raw/libcliraw.h"
      24             : #include "libcli/raw/raw_proto.h"
      25             : #include "libcli/smb2/smb2.h"
      26             : #include "libcli/smb2/smb2_calls.h"
      27             : 
      28             : /*
      29             :   send a setinfo request
      30             : */
      31        6552 : struct smb2_request *smb2_setinfo_send(struct smb2_tree *tree, struct smb2_setinfo *io)
      32             : {
      33           4 :         NTSTATUS status;
      34           4 :         struct smb2_request *req;
      35             : 
      36        6552 :         req = smb2_request_init_tree(tree, SMB2_OP_SETINFO, 0x20, true, io->in.blob.length);
      37        6552 :         if (req == NULL) return NULL;
      38             : 
      39        6552 :         SSVAL(req->out.body, 0x02, io->in.level);
      40             : 
      41        6552 :         status = smb2_push_s32o32_blob(&req->out, 0x04, io->in.blob);
      42        6552 :         if (!NT_STATUS_IS_OK(status)) {
      43           0 :                 talloc_free(req);
      44           0 :                 return NULL;
      45             :         }
      46             : 
      47        6552 :         SIVAL(req->out.body, 0x0C, io->in.flags);
      48        6552 :         smb2_push_handle(req->out.body+0x10, &io->in.file.handle);
      49             : 
      50        6552 :         smb2_transport_send(req);
      51             : 
      52        6552 :         return req;
      53             : }
      54             : 
      55             : 
      56             : /*
      57             :   recv a setinfo reply
      58             : */
      59        6552 : NTSTATUS smb2_setinfo_recv(struct smb2_request *req)
      60             : {
      61        6556 :         if (!smb2_request_receive(req) || 
      62        6552 :             !smb2_request_is_ok(req)) {
      63         519 :                 return smb2_request_destroy(req);
      64             :         }
      65             : 
      66        6033 :         SMB2_CHECK_PACKET_RECV(req, 0x02, false);
      67             : 
      68        6033 :         return smb2_request_destroy(req);
      69             : }
      70             : 
      71             : /*
      72             :   sync setinfo request
      73             : */
      74           0 : NTSTATUS smb2_setinfo(struct smb2_tree *tree, struct smb2_setinfo *io)
      75             : {
      76           0 :         struct smb2_request *req = smb2_setinfo_send(tree, io);
      77           0 :         return smb2_setinfo_recv(req);
      78             : }
      79             : 
      80             : /*
      81             :   level specific file setinfo call - async send
      82             : */
      83        6552 : struct smb2_request *smb2_setinfo_file_send(struct smb2_tree *tree, union smb_setfileinfo *io)
      84             : {
      85           4 :         struct smb2_setinfo b;
      86        6556 :         uint16_t smb2_level = smb2_getinfo_map_level(
      87        6552 :                 io->generic.level, SMB2_0_INFO_FILE);
      88           4 :         struct smb2_request *req;
      89             :         
      90        6552 :         if (smb2_level == 0) {
      91           0 :                 return NULL;
      92             :         }
      93             : 
      94        6552 :         ZERO_STRUCT(b);
      95        6552 :         b.in.level             = smb2_level;
      96        6552 :         b.in.file.handle       = io->generic.in.file.handle;
      97             : 
      98             :         /* change levels so the parsers know it is SMB2 */
      99        6552 :         if (io->generic.level == RAW_SFILEINFO_RENAME_INFORMATION) {
     100         560 :                 io->generic.level = RAW_SFILEINFO_RENAME_INFORMATION_SMB2;
     101             :         }
     102             : 
     103        6552 :         if (!smb_raw_setfileinfo_passthru(tree, io->generic.level, io, &b.in.blob)) {
     104           0 :                 return NULL;
     105             :         }
     106             : 
     107        6552 :         if (io->generic.level == RAW_SFILEINFO_SEC_DESC) {
     108        4624 :                 b.in.flags = io->set_secdesc.in.secinfo_flags;
     109             :         }
     110             : 
     111        6552 :         req = smb2_setinfo_send(tree, &b);
     112        6552 :         data_blob_free(&b.in.blob);
     113        6552 :         return req;
     114             : }
     115             : 
     116             : /*
     117             :   level specific file setinfo call - sync
     118             : */
     119        6454 : NTSTATUS smb2_setinfo_file(struct smb2_tree *tree, union smb_setfileinfo *io)
     120             : {
     121        6454 :         struct smb2_request *req = smb2_setinfo_file_send(tree, io);
     122        6454 :         return smb2_setinfo_recv(req);
     123             : }

Generated by: LCOV version 1.14