LCOV - code coverage report
Current view: top level - source3/smbd - smb2_getinfo.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 243 331 73.4 %
Date: 2024-04-13 12:30:31 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Core SMB2 server
       4             : 
       5             :    Copyright (C) Stefan Metzmacher 2009
       6             :    Copyright (C) Jeremy Allison 2010
       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 "smbd/smbd.h"
      24             : #include "smbd/globals.h"
      25             : #include "../libcli/smb/smb_common.h"
      26             : #include "trans2.h"
      27             : #include "../lib/util/tevent_ntstatus.h"
      28             : #include "librpc/gen_ndr/ndr_quota.h"
      29             : #include "librpc/gen_ndr/ndr_security.h"
      30             : 
      31             : #undef DBGC_CLASS
      32             : #define DBGC_CLASS DBGC_SMB2
      33             : 
      34             : static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
      35             :                                                  struct tevent_context *ev,
      36             :                                                  struct smbd_smb2_request *smb2req,
      37             :                                                  struct files_struct *in_fsp,
      38             :                                                  uint8_t in_info_type,
      39             :                                                  uint8_t in_file_info_class,
      40             :                                                  uint32_t in_output_buffer_length,
      41             :                                                  DATA_BLOB in_input_buffer,
      42             :                                                  uint32_t in_additional_information,
      43             :                                                  uint32_t in_flags);
      44             : static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
      45             :                                        TALLOC_CTX *mem_ctx,
      46             :                                        DATA_BLOB *out_output_buffer,
      47             :                                        NTSTATUS *p_call_status);
      48             : 
      49             : static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq);
      50       22896 : NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
      51             : {
      52       22896 :         struct smbXsrv_connection *xconn = req->xconn;
      53         306 :         NTSTATUS status;
      54         306 :         const uint8_t *inbody;
      55         306 :         uint8_t in_info_type;
      56         306 :         uint8_t in_file_info_class;
      57         306 :         uint32_t in_output_buffer_length;
      58         306 :         uint16_t in_input_buffer_offset;
      59         306 :         uint32_t in_input_buffer_length;
      60         306 :         DATA_BLOB in_input_buffer;
      61         306 :         uint32_t in_additional_information;
      62         306 :         uint32_t in_flags;
      63         306 :         uint64_t in_file_id_persistent;
      64         306 :         uint64_t in_file_id_volatile;
      65         306 :         struct files_struct *in_fsp;
      66         306 :         struct tevent_req *subreq;
      67             : 
      68       22896 :         status = smbd_smb2_request_verify_sizes(req, 0x29);
      69       22896 :         if (!NT_STATUS_IS_OK(status)) {
      70           0 :                 return smbd_smb2_request_error(req, status);
      71             :         }
      72       22896 :         inbody = SMBD_SMB2_IN_BODY_PTR(req);
      73             : 
      74       22896 :         in_info_type                    = CVAL(inbody, 0x02);
      75       22896 :         in_file_info_class              = CVAL(inbody, 0x03);
      76       22896 :         in_output_buffer_length         = IVAL(inbody, 0x04);
      77       22896 :         in_input_buffer_offset          = SVAL(inbody, 0x08);
      78             :         /* 0x0A 2 bytes reserved */
      79       22896 :         in_input_buffer_length          = IVAL(inbody, 0x0C);
      80       22896 :         in_additional_information       = IVAL(inbody, 0x10);
      81       22896 :         in_flags                        = IVAL(inbody, 0x14);
      82       22896 :         in_file_id_persistent           = BVAL(inbody, 0x18);
      83       22896 :         in_file_id_volatile             = BVAL(inbody, 0x20);
      84             : 
      85       22896 :         if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
      86             :                 /* This is ok */
      87          22 :         } else if (in_input_buffer_offset !=
      88          22 :                    (SMB2_HDR_BODY + SMBD_SMB2_IN_BODY_LEN(req))) {
      89           0 :                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
      90             :         }
      91             : 
      92       22896 :         if (in_input_buffer_length > SMBD_SMB2_IN_DYN_LEN(req)) {
      93           0 :                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
      94             :         }
      95             : 
      96       22896 :         in_input_buffer.data = SMBD_SMB2_IN_DYN_PTR(req);
      97       22896 :         in_input_buffer.length = in_input_buffer_length;
      98             : 
      99       22896 :         if (in_input_buffer.length > xconn->smb2.server.max_trans) {
     100           0 :                 DEBUG(2,("smbd_smb2_request_process_getinfo: "
     101             :                          "client ignored max trans: %s: 0x%08X: 0x%08X\n",
     102             :                          __location__, (unsigned)in_input_buffer.length,
     103             :                          (unsigned)xconn->smb2.server.max_trans));
     104           0 :                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
     105             :         }
     106       22896 :         if (in_output_buffer_length > xconn->smb2.server.max_trans) {
     107           0 :                 DEBUG(2,("smbd_smb2_request_process_getinfo: "
     108             :                          "client ignored max trans: %s: 0x%08X: 0x%08X\n",
     109             :                          __location__, in_output_buffer_length,
     110             :                          xconn->smb2.server.max_trans));
     111           0 :                 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
     112             :         }
     113             : 
     114       23202 :         status = smbd_smb2_request_verify_creditcharge(req,
     115       22896 :                         MAX(in_input_buffer.length,in_output_buffer_length));
     116       22896 :         if (!NT_STATUS_IS_OK(status)) {
     117           0 :                 return smbd_smb2_request_error(req, status);
     118             :         }
     119             : 
     120       22896 :         in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
     121       22896 :         if (in_fsp == NULL) {
     122           0 :                 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
     123             :         }
     124             : 
     125       22896 :         subreq = smbd_smb2_getinfo_send(req, req->sconn->ev_ctx,
     126             :                                         req, in_fsp,
     127             :                                         in_info_type,
     128             :                                         in_file_info_class,
     129             :                                         in_output_buffer_length,
     130             :                                         in_input_buffer,
     131             :                                         in_additional_information,
     132             :                                         in_flags);
     133       22896 :         if (subreq == NULL) {
     134           0 :                 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
     135             :         }
     136       22896 :         tevent_req_set_callback(subreq, smbd_smb2_request_getinfo_done, req);
     137             : 
     138       22896 :         return smbd_smb2_request_pending_queue(req, subreq, 500);
     139             : }
     140             : 
     141       22896 : static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq)
     142             : {
     143       22896 :         struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
     144             :                                         struct smbd_smb2_request);
     145         306 :         DATA_BLOB outbody;
     146         306 :         DATA_BLOB outdyn;
     147         306 :         uint16_t out_output_buffer_offset;
     148       22896 :         DATA_BLOB out_output_buffer = data_blob_null;
     149         306 :         NTSTATUS status;
     150       22896 :         NTSTATUS call_status = NT_STATUS_OK;
     151         306 :         NTSTATUS error; /* transport error */
     152             : 
     153       22896 :         status = smbd_smb2_getinfo_recv(subreq,
     154             :                                         req,
     155             :                                         &out_output_buffer,
     156             :                                         &call_status);
     157       22896 :         TALLOC_FREE(subreq);
     158       22896 :         if (!NT_STATUS_IS_OK(status)) {
     159        1826 :                 error = smbd_smb2_request_error(req, status);
     160        1826 :                 if (!NT_STATUS_IS_OK(error)) {
     161           0 :                         smbd_server_connection_terminate(req->xconn,
     162             :                                                          nt_errstr(error));
     163        1834 :                         return;
     164             :                 }
     165        1826 :                 return;
     166             :         }
     167             : 
     168             :         /* some GetInfo responses set STATUS_BUFFER_OVERFLOW and return partial,
     169             :            but valid data */
     170       21070 :         if (!(NT_STATUS_IS_OK(call_status) ||
     171         176 :               NT_STATUS_EQUAL(call_status, STATUS_BUFFER_OVERFLOW))) {
     172             :                 /* Return a specific error with data. */
     173           8 :                 error = smbd_smb2_request_error_ex(req,
     174             :                                                 call_status,
     175             :                                                 0,
     176             :                                                 &out_output_buffer,
     177             :                                                 __location__);
     178           8 :                 if (!NT_STATUS_IS_OK(error)) {
     179           0 :                         smbd_server_connection_terminate(req->xconn,
     180             :                                                          nt_errstr(error));
     181           8 :                         return;
     182             :                 }
     183           8 :                 return;
     184             :         }
     185             : 
     186       21062 :         out_output_buffer_offset = SMB2_HDR_BODY + 0x08;
     187             : 
     188       21062 :         outbody = smbd_smb2_generate_outbody(req, 0x08);
     189       21062 :         if (outbody.data == NULL) {
     190           0 :                 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
     191           0 :                 if (!NT_STATUS_IS_OK(error)) {
     192           0 :                         smbd_server_connection_terminate(req->xconn,
     193             :                                                          nt_errstr(error));
     194           0 :                         return;
     195             :                 }
     196           0 :                 return;
     197             :         }
     198             : 
     199       21062 :         SSVAL(outbody.data, 0x00, 0x08 + 1);    /* struct size */
     200       21062 :         SSVAL(outbody.data, 0x02,
     201             :               out_output_buffer_offset);        /* output buffer offset */
     202       21062 :         SIVAL(outbody.data, 0x04,
     203             :               out_output_buffer.length);        /* output buffer length */
     204             : 
     205       21062 :         outdyn = out_output_buffer;
     206             : 
     207       21062 :         error = smbd_smb2_request_done_ex(req, call_status, outbody, &outdyn, __location__);
     208       21062 :         if (!NT_STATUS_IS_OK(error)) {
     209           0 :                 smbd_server_connection_terminate(req->xconn,
     210             :                                                  nt_errstr(error));
     211           0 :                 return;
     212             :         }
     213             : }
     214             : 
     215             : struct smbd_smb2_getinfo_state {
     216             :         struct smbd_smb2_request *smb2req;
     217             :         NTSTATUS status;
     218             :         DATA_BLOB out_output_buffer;
     219             : };
     220             : 
     221           0 : static void smb2_ipc_getinfo(struct tevent_req *req,
     222             :                                 struct smbd_smb2_getinfo_state *state,
     223             :                                 struct tevent_context *ev,
     224             :                                 uint8_t in_info_type,
     225             :                                 uint8_t in_file_info_class)
     226             : {
     227             :         /* We want to reply to SMB2_GETINFO_FILE
     228             :            with a class of SMB2_FILE_STANDARD_INFO as
     229             :            otherwise a Win7 client issues this request
     230             :            twice (2xroundtrips) if we return NOT_SUPPORTED.
     231             :            NB. We do the same for SMB1 in call_trans2qpipeinfo() */
     232             : 
     233           0 :         if (in_info_type == 0x01 && /* SMB2_GETINFO_FILE */
     234           0 :                         in_file_info_class == 0x05) { /* SMB2_FILE_STANDARD_INFO */
     235           0 :                 state->out_output_buffer = data_blob_talloc(state,
     236             :                                                 NULL, 24);
     237           0 :                 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     238           0 :                         return;
     239             :                 }
     240             : 
     241           0 :                 memset(state->out_output_buffer.data,0,24);
     242           0 :                 SOFF_T(state->out_output_buffer.data,0,4096LL);
     243           0 :                 SIVAL(state->out_output_buffer.data,16,1);
     244           0 :                 SIVAL(state->out_output_buffer.data,20,1);
     245           0 :                 tevent_req_done(req);
     246             :         } else {
     247           0 :                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     248             :         }
     249             : }
     250             : 
     251       22896 : static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
     252             :                                                  struct tevent_context *ev,
     253             :                                                  struct smbd_smb2_request *smb2req,
     254             :                                                  struct files_struct *fsp,
     255             :                                                  uint8_t in_info_type,
     256             :                                                  uint8_t in_file_info_class,
     257             :                                                  uint32_t in_output_buffer_length,
     258             :                                                  DATA_BLOB in_input_buffer,
     259             :                                                  uint32_t in_additional_information,
     260             :                                                  uint32_t in_flags)
     261             : {
     262         306 :         struct tevent_req *req;
     263         306 :         struct smbd_smb2_getinfo_state *state;
     264         306 :         struct smb_request *smbreq;
     265       22896 :         connection_struct *conn = smb2req->tcon->compat;
     266         306 :         NTSTATUS status;
     267             : 
     268       22896 :         req = tevent_req_create(mem_ctx, &state,
     269             :                                 struct smbd_smb2_getinfo_state);
     270       22896 :         if (req == NULL) {
     271           0 :                 return NULL;
     272             :         }
     273       22896 :         state->smb2req = smb2req;
     274       22896 :         state->status = NT_STATUS_OK;
     275       22896 :         state->out_output_buffer = data_blob_null;
     276             : 
     277       22896 :         DEBUG(10,("smbd_smb2_getinfo_send: %s - %s\n",
     278             :                   fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
     279             : 
     280       22896 :         smbreq = smbd_smb2_fake_smb_request(smb2req, fsp);
     281       22896 :         if (tevent_req_nomem(smbreq, req)) {
     282           0 :                 return tevent_req_post(req, ev);
     283             :         }
     284             : 
     285       22896 :         if (IS_IPC(conn)) {
     286           0 :                 smb2_ipc_getinfo(req, state, ev,
     287             :                         in_info_type, in_file_info_class);
     288           0 :                 return tevent_req_post(req, ev);
     289             :         }
     290             : 
     291       22896 :         switch (in_info_type) {
     292       13368 :         case SMB2_0_INFO_FILE:
     293             :         {
     294         294 :                 uint16_t file_info_level;
     295       13368 :                 char *data = NULL;
     296       13368 :                 unsigned int data_size = 0;
     297       13368 :                 bool delete_pending = false;
     298         294 :                 struct timespec write_time_ts;
     299         294 :                 struct file_id fileid;
     300         294 :                 size_t fixed_portion;
     301             : 
     302       13368 :                 ZERO_STRUCT(write_time_ts);
     303             : 
     304             :                 /*
     305             :                  * MS-SMB2 3.3.5.20.1 "Handling SMB2_0_INFO_FILE"
     306             :                  *
     307             :                  * FileBasicInformation, FileAllInformation,
     308             :                  * FileNetworkOpenInformation, FileAttributeTagInformation
     309             :                  * require FILE_READ_ATTRIBUTES.
     310             :                  *
     311             :                  * FileFullEaInformation requires FILE_READ_EA.
     312             :                  */
     313       13368 :                 switch (in_file_info_class) {
     314        6450 :                 case FSCC_FILE_BASIC_INFORMATION:
     315             :                 case FSCC_FILE_ALL_INFORMATION:
     316             :                 case FSCC_FILE_NETWORK_OPEN_INFORMATION:
     317             :                 case FSCC_FILE_ATTRIBUTE_TAG_INFORMATION:
     318        6450 :                         status = check_any_access_fsp(fsp, SEC_FILE_READ_ATTRIBUTE);
     319        6450 :                         if (tevent_req_nterror(req, status)) {
     320        1376 :                                 return tevent_req_post(req, ev);
     321             :                         }
     322        6422 :                         break;
     323             : 
     324          30 :                 case FSCC_FILE_FULL_EA_INFORMATION:
     325          30 :                         status = check_any_access_fsp(fsp, SEC_FILE_READ_EA);
     326          30 :                         if (tevent_req_nterror(req, status)) {
     327           8 :                                 return tevent_req_post(req, ev);
     328             :                         }
     329          22 :                         break;
     330             :                 }
     331             : 
     332       13332 :                 switch (in_file_info_class) {
     333          22 :                 case FSCC_FILE_FULL_EA_INFORMATION:
     334          22 :                         file_info_level = SMB2_FILE_FULL_EA_INFORMATION;
     335          22 :                         break;
     336             : 
     337        5594 :                 case FSCC_FILE_ALL_INFORMATION:
     338        5594 :                         file_info_level = SMB2_FILE_ALL_INFORMATION;
     339        5594 :                         break;
     340             : 
     341           0 :                 case SMB2_FILE_POSIX_INFORMATION:
     342           0 :                         if (!(fsp->posix_flags & FSP_POSIX_FLAGS_OPEN)) {
     343           0 :                                 tevent_req_nterror(req, NT_STATUS_INVALID_LEVEL);
     344           0 :                                 return tevent_req_post(req, ev);
     345             :                         }
     346           0 :                         file_info_level = SMB2_FILE_POSIX_INFORMATION_INTERNAL;
     347           0 :                         break;
     348             : 
     349        7716 :                 default:
     350             :                         /* the levels directly map to the passthru levels */
     351        7716 :                         file_info_level = in_file_info_class + 1000;
     352        7716 :                         break;
     353             :                 }
     354             : 
     355       13332 :                 switch (file_info_level) {
     356         100 :                 case SMB_FILE_NORMALIZED_NAME_INFORMATION:
     357         100 :                         if (smb2req->xconn->protocol < PROTOCOL_SMB3_11) {
     358           4 :                                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     359           4 :                                 return tevent_req_post(req, ev);
     360             :                         }
     361          96 :                         break;
     362             :                 }
     363             : 
     364       13328 :                 if (fsp->fake_file_handle) {
     365             :                         /*
     366             :                          * This is actually for the QUOTA_FAKE_FILE --metze
     367             :                          */
     368             : 
     369             :                         /* We know this name is ok, it's already passed the checks. */
     370             : 
     371       13328 :                 } else if (fsp_get_pathref_fd(fsp) == -1) {
     372             :                         /*
     373             :                          * This is actually a QFILEINFO on a directory
     374             :                          * handle (returned from an NT SMB). NT5.0 seems
     375             :                          * to do this call. JRA.
     376             :                          */
     377           0 :                         int ret = vfs_stat(conn, fsp->fsp_name);
     378           0 :                         if (ret != 0) {
     379           0 :                                 DBG_NOTICE("vfs_stat of %s failed (%s)\n",
     380             :                                          fsp_str_dbg(fsp),
     381             :                                          strerror(errno));
     382           0 :                                 status = map_nt_error_from_unix(errno);
     383           0 :                                 tevent_req_nterror(req, status);
     384           0 :                                 return tevent_req_post(req, ev);
     385             :                         }
     386             : 
     387           0 :                         if (fsp_getinfo_ask_sharemode(fsp)) {
     388           0 :                                 fileid = vfs_file_id_from_sbuf(
     389           0 :                                         conn, &fsp->fsp_name->st);
     390           0 :                                 get_file_infos(fileid, fsp->name_hash,
     391             :                                                &delete_pending,
     392             :                                                &write_time_ts);
     393             :                         }
     394             :                 } else {
     395             :                         /*
     396             :                          * Original code - this is an open file.
     397             :                          */
     398             : 
     399       13328 :                         status = vfs_stat_fsp(fsp);
     400       13328 :                         if (!NT_STATUS_IS_OK(status)) {
     401           0 :                                 DEBUG(3, ("smbd_smb2_getinfo_send: "
     402             :                                           "fstat of %s failed (%s)\n",
     403             :                                           fsp_fnum_dbg(fsp), nt_errstr(status)));
     404           0 :                                 tevent_req_nterror(req, status);
     405           0 :                                 return tevent_req_post(req, ev);
     406             :                         }
     407       13328 :                         if (fsp_getinfo_ask_sharemode(fsp)) {
     408       13328 :                                 fileid = vfs_file_id_from_sbuf(
     409       13328 :                                         conn, &fsp->fsp_name->st);
     410       13328 :                                 get_file_infos(fileid, fsp->name_hash,
     411             :                                                &delete_pending,
     412             :                                                &write_time_ts);
     413             :                         }
     414             :                 }
     415             : 
     416       13328 :                 status = smbd_do_qfilepathinfo(conn, state,
     417             :                                                smbreq,
     418             :                                                file_info_level,
     419             :                                                fsp,
     420             :                                                fsp->fsp_name,
     421             :                                                delete_pending,
     422             :                                                write_time_ts,
     423             :                                                NULL,
     424             :                                                STR_UNICODE,
     425             :                                                in_output_buffer_length,
     426             :                                                &fixed_portion,
     427             :                                                &data,
     428             :                                                &data_size);
     429       13328 :                 if (!NT_STATUS_IS_OK(status)) {
     430         216 :                         SAFE_FREE(data);
     431         216 :                         if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
     432           0 :                                 status = NT_STATUS_INVALID_INFO_CLASS;
     433             :                         }
     434         216 :                         tevent_req_nterror(req, status);
     435         216 :                         return tevent_req_post(req, ev);
     436             :                 }
     437       13112 :                 if (in_output_buffer_length < fixed_portion) {
     438        1120 :                         SAFE_FREE(data);
     439        1120 :                         tevent_req_nterror(
     440             :                                 req, NT_STATUS_INFO_LENGTH_MISMATCH);
     441        1120 :                         return tevent_req_post(req, ev);
     442             :                 }
     443       11992 :                 if (data_size > 0) {
     444       11866 :                         state->out_output_buffer = data_blob_talloc(state,
     445             :                                                                     data,
     446             :                                                                     data_size);
     447       11866 :                         SAFE_FREE(data);
     448       11866 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     449           0 :                                 return tevent_req_post(req, ev);
     450             :                         }
     451       11866 :                         if (data_size > in_output_buffer_length) {
     452         152 :                                 state->out_output_buffer.length =
     453             :                                         in_output_buffer_length;
     454         152 :                                 status = STATUS_BUFFER_OVERFLOW;
     455             :                         }
     456             :                 }
     457       11992 :                 SAFE_FREE(data);
     458       11992 :                 break;
     459             :         }
     460             : 
     461        2053 :         case SMB2_0_INFO_FILESYSTEM:
     462             :         {
     463           0 :                 uint16_t file_info_level;
     464        2053 :                 char *data = NULL;
     465        2053 :                 int data_size = 0;
     466           0 :                 size_t fixed_portion;
     467             : 
     468             :                 /* the levels directly map to the passthru levels */
     469        2053 :                 file_info_level = in_file_info_class + 1000;
     470             : 
     471        2053 :                 status = smbd_do_qfsinfo(smb2req->xconn, conn, state,
     472             :                                          file_info_level,
     473             :                                          STR_UNICODE,
     474             :                                          in_output_buffer_length,
     475             :                                          &fixed_portion,
     476             :                                          fsp,
     477             :                                          fsp->fsp_name,
     478             :                                          &data,
     479             :                                          &data_size);
     480             :                 /* some responses set STATUS_BUFFER_OVERFLOW and return
     481             :                    partial, but valid data */
     482        2053 :                 if (!(NT_STATUS_IS_OK(status) ||
     483          20 :                       NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW))) {
     484           4 :                         SAFE_FREE(data);
     485           4 :                         if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
     486           0 :                                 status = NT_STATUS_INVALID_INFO_CLASS;
     487             :                         }
     488           4 :                         tevent_req_nterror(req, status);
     489           4 :                         return tevent_req_post(req, ev);
     490             :                 }
     491        2049 :                 if (in_output_buffer_length < fixed_portion) {
     492         416 :                         SAFE_FREE(data);
     493         416 :                         tevent_req_nterror(
     494             :                                 req, NT_STATUS_INFO_LENGTH_MISMATCH);
     495         416 :                         return tevent_req_post(req, ev);
     496             :                 }
     497        1633 :                 if (data_size > 0) {
     498        1633 :                         state->out_output_buffer = data_blob_talloc(state,
     499             :                                                                     data,
     500             :                                                                     data_size);
     501        1633 :                         SAFE_FREE(data);
     502        1633 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     503           0 :                                 return tevent_req_post(req, ev);
     504             :                         }
     505        1633 :                         if (data_size > in_output_buffer_length) {
     506           0 :                                 state->out_output_buffer.length =
     507             :                                         in_output_buffer_length;
     508           0 :                                 status = STATUS_BUFFER_OVERFLOW;
     509             :                         }
     510             :                 }
     511        1633 :                 SAFE_FREE(data);
     512        1633 :                 break;
     513             :         }
     514             : 
     515        7453 :         case SMB2_0_INFO_SECURITY:
     516             :         {
     517        7453 :                 uint8_t *p_marshalled_sd = NULL;
     518        7453 :                 size_t sd_size = 0;
     519             : 
     520        7453 :                 status = smbd_do_query_security_desc(conn,
     521             :                                 state,
     522             :                                 fsp,
     523             :                                 /* Security info wanted. */
     524             :                                 in_additional_information &
     525             :                                 SMB_SUPPORTED_SECINFO_FLAGS,
     526             :                                 in_output_buffer_length,
     527             :                                 &p_marshalled_sd,
     528             :                                 &sd_size);
     529             : 
     530        7453 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
     531             :                         /* Return needed size. */
     532           8 :                         state->out_output_buffer = data_blob_talloc(state,
     533             :                                                                     NULL,
     534             :                                                                     4);
     535           8 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     536           0 :                                 return tevent_req_post(req, ev);
     537             :                         }
     538           8 :                         SIVAL(state->out_output_buffer.data,0,(uint32_t)sd_size);
     539           8 :                         state->status = NT_STATUS_BUFFER_TOO_SMALL;
     540           8 :                         break;
     541             :                 }
     542        7445 :                 if (!NT_STATUS_IS_OK(status)) {
     543          22 :                         DEBUG(10,("smbd_smb2_getinfo_send: "
     544             :                                  "smbd_do_query_security_desc of %s failed "
     545             :                                  "(%s)\n", fsp_str_dbg(fsp),
     546             :                                  nt_errstr(status)));
     547          22 :                         tevent_req_nterror(req, status);
     548          22 :                         return tevent_req_post(req, ev);
     549             :                 }
     550             : 
     551        7423 :                 if (sd_size > 0) {
     552        7423 :                         state->out_output_buffer = data_blob_talloc(state,
     553             :                                                                     p_marshalled_sd,
     554             :                                                                     sd_size);
     555        7423 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     556           0 :                                 return tevent_req_post(req, ev);
     557             :                         }
     558             :                 }
     559        7411 :                 break;
     560             :         }
     561             : 
     562          22 :         case SMB2_0_INFO_QUOTA: {
     563             : #ifdef HAVE_SYS_QUOTAS
     564           0 :                 struct smb2_query_quota_info info;
     565           0 :                 enum ndr_err_code err;
     566          22 :                 uint8_t *data = NULL;
     567          22 :                 uint32_t data_size = 0;
     568          22 :                 struct ndr_pull *ndr_pull = NULL;
     569          22 :                 DATA_BLOB sid_buf = data_blob_null;
     570          22 :                 TALLOC_CTX *tmp_ctx = talloc_init("geninfo_quota");
     571           0 :                 bool ok;
     572             : 
     573          22 :                 if (!tmp_ctx) {
     574           0 :                         tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     575           0 :                         return tevent_req_post(req, ev);
     576             :                 }
     577             : 
     578          22 :                 ok = check_fsp_ntquota_handle(conn, smbreq, fsp);
     579          22 :                 if (!ok) {
     580           4 :                         DBG_INFO("no valid QUOTA HANDLE\n");
     581           4 :                         TALLOC_FREE(tmp_ctx);
     582           4 :                         tevent_req_nterror(req, NT_STATUS_INVALID_HANDLE);
     583           4 :                         return tevent_req_post(req, ev);
     584             :                 }
     585             : 
     586          18 :                 ndr_pull = ndr_pull_init_blob(&in_input_buffer, tmp_ctx);
     587          18 :                 if (!ndr_pull) {
     588           0 :                         TALLOC_FREE(tmp_ctx);
     589           0 :                         tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     590           0 :                         return tevent_req_post(req, ev);
     591             :                 }
     592             : 
     593          18 :                 err = ndr_pull_smb2_query_quota_info(ndr_pull,
     594             :                                                      NDR_SCALARS | NDR_BUFFERS,
     595             :                                                      &info);
     596             : 
     597          18 :                 if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
     598           0 :                         DBG_DEBUG("failed to pull smb2_query_quota_info\n");
     599           0 :                         TALLOC_FREE(tmp_ctx);
     600           0 :                         tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
     601           0 :                         return tevent_req_post(req, ev);
     602             :                 }
     603             : 
     604          18 :                 DBG_DEBUG("quota list returnsingle %u, restartscan %u, "
     605             :                           "sid_list_length %u, start_sid_length %u, "
     606             :                           "startsidoffset %u\n",
     607             :                           (unsigned int)info.return_single,
     608             :                           (unsigned int)info.restart_scan,
     609             :                           (unsigned int)info.sid_list_length,
     610             :                           (unsigned int)info.start_sid_length,
     611             :                           (unsigned int)info.start_sid_offset);
     612             : 
     613             :                 /* Currently we do not support the single start sid format */
     614          18 :                 if (info.start_sid_length != 0 || info.start_sid_offset != 0 ) {
     615           0 :                         DBG_INFO("illegal single sid query\n");
     616           0 :                         TALLOC_FREE(tmp_ctx);
     617           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     618           0 :                         return tevent_req_post(req, ev);
     619             :                 }
     620             : 
     621          18 :                 if (in_input_buffer.length < ndr_pull->offset) {
     622           0 :                         DBG_INFO("Invalid buffer length\n");
     623           0 :                         TALLOC_FREE(tmp_ctx);
     624           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     625           0 :                         return tevent_req_post(req, ev);
     626             :                 }
     627             : 
     628          18 :                 sid_buf.data = in_input_buffer.data + ndr_pull->offset;
     629          18 :                 sid_buf.length = in_input_buffer.length - ndr_pull->offset;
     630             : 
     631          18 :                 status = smbd_do_query_getinfo_quota(tmp_ctx,
     632             :                                   fsp,
     633          18 :                                   info.restart_scan,
     634          18 :                                   info.return_single,
     635             :                                   info.sid_list_length,
     636             :                                   &sid_buf,
     637             :                                   in_output_buffer_length,
     638             :                                   &data,
     639             :                                   &data_size);
     640             : 
     641          18 :                 if (!NT_STATUS_IS_OK(status)) {
     642           4 :                         TALLOC_FREE(tmp_ctx);
     643           4 :                         tevent_req_nterror(req, status);
     644           4 :                         return tevent_req_post(req, ev);
     645             :                 }
     646             : 
     647          14 :                 state->out_output_buffer =
     648          14 :                         data_blob_talloc(state, data, data_size);
     649          14 :                 status  = NT_STATUS_OK;
     650          14 :                 TALLOC_FREE(tmp_ctx);
     651          14 :                 break;
     652             : #else
     653             :                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     654             :                 return tevent_req_post(req, ev);
     655             : #endif
     656             :         }
     657             : 
     658           0 :         default:
     659           0 :                 DEBUG(10,("smbd_smb2_getinfo_send: "
     660             :                         "unknown in_info_type of %u "
     661             :                         " for file %s\n",
     662             :                         (unsigned int)in_info_type,
     663             :                         fsp_str_dbg(fsp) ));
     664             : 
     665           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     666           0 :                 return tevent_req_post(req, ev);
     667             :         }
     668             : 
     669       21070 :         state->status = status;
     670       21070 :         tevent_req_done(req);
     671       21070 :         return tevent_req_post(req, ev);
     672             : }
     673             : 
     674       22896 : static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
     675             :                                        TALLOC_CTX *mem_ctx,
     676             :                                        DATA_BLOB *out_output_buffer,
     677             :                                        NTSTATUS *pstatus)
     678             : {
     679         306 :         NTSTATUS status;
     680       22896 :         struct smbd_smb2_getinfo_state *state = tevent_req_data(req,
     681             :                                                 struct smbd_smb2_getinfo_state);
     682             : 
     683       22896 :         if (tevent_req_is_nterror(req, &status)) {
     684        1826 :                 tevent_req_received(req);
     685        1826 :                 return status;
     686             :         }
     687             : 
     688       21070 :         *out_output_buffer = state->out_output_buffer;
     689       21070 :         talloc_steal(mem_ctx, out_output_buffer->data);
     690       21070 :         *pstatus = state->status;
     691             : 
     692       21070 :         tevent_req_received(req);
     693       21070 :         return NT_STATUS_OK;
     694             : }

Generated by: LCOV version 1.14