LCOV - code coverage report
Current view: top level - libcli/smb - smb2cli_set_info.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 52 72 72.2 %
Date: 2024-04-21 15:09:00 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    smb2 lib
       4             :    Copyright (C) Stefan Metzmacher 2012
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "system/network.h"
      22             : #include "lib/util/tevent_ntstatus.h"
      23             : #include "smb_common.h"
      24             : #include "smbXcli_base.h"
      25             : 
      26             : struct smb2cli_set_info_state {
      27             :         uint8_t fixed[0x20];
      28             :         uint8_t dyn_pad[1];
      29             : };
      30             : 
      31             : static void smb2cli_set_info_done(struct tevent_req *subreq);
      32             : 
      33        7596 : struct tevent_req *smb2cli_set_info_send(TALLOC_CTX *mem_ctx,
      34             :                                          struct tevent_context *ev,
      35             :                                          struct smbXcli_conn *conn,
      36             :                                          uint32_t timeout_msec,
      37             :                                          struct smbXcli_session *session,
      38             :                                          struct smbXcli_tcon *tcon,
      39             :                                          uint8_t in_info_type,
      40             :                                          uint8_t in_file_info_class,
      41             :                                          const DATA_BLOB *in_input_buffer,
      42             :                                          uint32_t in_additional_info,
      43             :                                          uint64_t in_fid_persistent,
      44             :                                          uint64_t in_fid_volatile)
      45             : {
      46           0 :         struct tevent_req *req, *subreq;
      47           0 :         struct smb2cli_set_info_state *state;
      48           0 :         uint8_t *fixed;
      49           0 :         uint8_t *dyn;
      50           0 :         size_t dyn_len;
      51        7596 :         uint16_t input_buffer_offset = 0;
      52        7596 :         uint32_t input_buffer_length = 0;
      53             : 
      54        7596 :         req = tevent_req_create(mem_ctx, &state,
      55             :                                 struct smb2cli_set_info_state);
      56        7596 :         if (req == NULL) {
      57           0 :                 return NULL;
      58             :         }
      59             : 
      60        7596 :         if (in_input_buffer) {
      61        7596 :                 input_buffer_offset = SMB2_HDR_BODY+0x20;
      62        7596 :                 input_buffer_length = in_input_buffer->length;
      63             :         }
      64             : 
      65        7596 :         fixed = state->fixed;
      66             : 
      67        7596 :         SSVAL(fixed, 0x00, 0x21);
      68        7596 :         SCVAL(fixed, 0x02, in_info_type);
      69        7596 :         SCVAL(fixed, 0x03, in_file_info_class);
      70        7596 :         SIVAL(fixed, 0x04, input_buffer_length);
      71        7596 :         SSVAL(fixed, 0x08, input_buffer_offset);
      72        7596 :         SSVAL(fixed, 0x0A, 0); /* reserved */
      73        7596 :         SIVAL(fixed, 0x0C, in_additional_info);
      74        7596 :         SBVAL(fixed, 0x10, in_fid_persistent);
      75        7596 :         SBVAL(fixed, 0x18, in_fid_volatile);
      76             : 
      77        7596 :         if (input_buffer_length > 0) {
      78        7596 :                 dyn = in_input_buffer->data;
      79        7596 :                 dyn_len = in_input_buffer->length;
      80             :         } else {
      81           0 :                 dyn = state->dyn_pad;
      82           0 :                 dyn_len = sizeof(state->dyn_pad);
      83             :         }
      84             : 
      85        7596 :         subreq = smb2cli_req_send(state, ev, conn, SMB2_OP_SETINFO,
      86             :                                   0, 0, /* flags */
      87             :                                   timeout_msec,
      88             :                                   tcon,
      89             :                                   session,
      90        7596 :                                   state->fixed, sizeof(state->fixed),
      91             :                                   dyn, dyn_len,
      92             :                                   0); /* max_dyn_len */
      93        7596 :         if (tevent_req_nomem(subreq, req)) {
      94           0 :                 return tevent_req_post(req, ev);
      95             :         }
      96        7596 :         tevent_req_set_callback(subreq, smb2cli_set_info_done, req);
      97        7596 :         return req;
      98             : }
      99             : 
     100        7596 : static void smb2cli_set_info_done(struct tevent_req *subreq)
     101             : {
     102           0 :         struct tevent_req *req =
     103        7596 :                 tevent_req_callback_data(subreq,
     104             :                 struct tevent_req);
     105           0 :         NTSTATUS status;
     106           0 :         static const struct smb2cli_req_expected_response expected[] = {
     107             :         {
     108             :                 .status = NT_STATUS_OK,
     109             :                 .body_size = 0x02
     110             :         },
     111             :         };
     112             : 
     113        7596 :         status = smb2cli_req_recv(subreq, NULL, NULL,
     114             :                                   expected, ARRAY_SIZE(expected));
     115        7596 :         TALLOC_FREE(subreq);
     116        7596 :         if (tevent_req_nterror(req, status)) {
     117         205 :                 return;
     118             :         }
     119             : 
     120        7391 :         tevent_req_done(req);
     121             : }
     122             : 
     123        7596 : NTSTATUS smb2cli_set_info_recv(struct tevent_req *req)
     124             : {
     125           0 :         NTSTATUS status;
     126             : 
     127        7596 :         if (tevent_req_is_nterror(req, &status)) {
     128         205 :                 tevent_req_received(req);
     129         205 :                 return status;
     130             :         }
     131             : 
     132        7391 :         tevent_req_received(req);
     133        7391 :         return NT_STATUS_OK;
     134             : }
     135             : 
     136          26 : NTSTATUS smb2cli_set_info(struct smbXcli_conn *conn,
     137             :                           uint32_t timeout_msec,
     138             :                           struct smbXcli_session *session,
     139             :                           struct smbXcli_tcon *tcon,
     140             :                           uint8_t in_info_type,
     141             :                           uint8_t in_file_info_class,
     142             :                           const DATA_BLOB *in_input_buffer,
     143             :                           uint32_t in_additional_info,
     144             :                           uint64_t in_fid_persistent,
     145             :                           uint64_t in_fid_volatile)
     146             : {
     147          26 :         TALLOC_CTX *frame = talloc_stackframe();
     148           0 :         struct tevent_context *ev;
     149           0 :         struct tevent_req *req;
     150          26 :         NTSTATUS status = NT_STATUS_NO_MEMORY;
     151             : 
     152          26 :         if (smbXcli_conn_has_async_calls(conn)) {
     153             :                 /*
     154             :                  * Can't use sync call while an async call is in flight
     155             :                  */
     156           0 :                 status = NT_STATUS_INVALID_PARAMETER_MIX;
     157           0 :                 goto fail;
     158             :         }
     159          26 :         ev = samba_tevent_context_init(frame);
     160          26 :         if (ev == NULL) {
     161           0 :                 goto fail;
     162             :         }
     163          26 :         req = smb2cli_set_info_send(frame, ev,
     164             :                                     conn, timeout_msec,
     165             :                                     session, tcon,
     166             :                                     in_info_type,
     167             :                                     in_file_info_class,
     168             :                                     in_input_buffer,
     169             :                                     in_additional_info,
     170             :                                     in_fid_persistent,
     171             :                                     in_fid_volatile);
     172          26 :         if (req == NULL) {
     173           0 :                 goto fail;
     174             :         }
     175          26 :         if (!tevent_req_poll_ntstatus(req, ev, &status)) {
     176           0 :                 goto fail;
     177             :         }
     178          26 :         status = smb2cli_set_info_recv(req);
     179             : 
     180          26 :  fail:
     181          26 :         TALLOC_FREE(frame);
     182          26 :         return status;
     183             : }

Generated by: LCOV version 1.14