LCOV - code coverage report
Current view: top level - source3/smbd - smb2_getinfo.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 206 289 71.3 %
Date: 2021-08-25 13:27:56 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       21650 : NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req)
      51             : {
      52       21650 :         struct smbXsrv_connection *xconn = req->xconn;
      53             :         NTSTATUS status;
      54             :         const uint8_t *inbody;
      55             :         uint8_t in_info_type;
      56             :         uint8_t in_file_info_class;
      57             :         uint32_t in_output_buffer_length;
      58             :         uint16_t in_input_buffer_offset;
      59             :         uint32_t in_input_buffer_length;
      60             :         DATA_BLOB in_input_buffer;
      61             :         uint32_t in_additional_information;
      62             :         uint32_t in_flags;
      63             :         uint64_t in_file_id_persistent;
      64             :         uint64_t in_file_id_volatile;
      65             :         struct files_struct *in_fsp;
      66             :         struct tevent_req *subreq;
      67             : 
      68       21650 :         status = smbd_smb2_request_verify_sizes(req, 0x29);
      69       21650 :         if (!NT_STATUS_IS_OK(status)) {
      70           0 :                 return smbd_smb2_request_error(req, status);
      71             :         }
      72       21650 :         inbody = SMBD_SMB2_IN_BODY_PTR(req);
      73             : 
      74       21650 :         in_info_type                    = CVAL(inbody, 0x02);
      75       21650 :         in_file_info_class              = CVAL(inbody, 0x03);
      76       21650 :         in_output_buffer_length         = IVAL(inbody, 0x04);
      77       21650 :         in_input_buffer_offset          = SVAL(inbody, 0x08);
      78             :         /* 0x0A 2 bytes reserved */
      79       21650 :         in_input_buffer_length          = IVAL(inbody, 0x0C);
      80       21650 :         in_additional_information       = IVAL(inbody, 0x10);
      81       21650 :         in_flags                        = IVAL(inbody, 0x14);
      82       21650 :         in_file_id_persistent           = BVAL(inbody, 0x18);
      83       21650 :         in_file_id_volatile             = BVAL(inbody, 0x20);
      84             : 
      85       21650 :         if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
      86             :                 /* This is ok */
      87          44 :         } 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       21650 :         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       21650 :         in_input_buffer.data = SMBD_SMB2_IN_DYN_PTR(req);
      97       21650 :         in_input_buffer.length = in_input_buffer_length;
      98             : 
      99       21650 :         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       21650 :         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       21650 :         status = smbd_smb2_request_verify_creditcharge(req,
     115       21650 :                         MAX(in_input_buffer.length,in_output_buffer_length));
     116       21650 :         if (!NT_STATUS_IS_OK(status)) {
     117           0 :                 return smbd_smb2_request_error(req, status);
     118             :         }
     119             : 
     120       21650 :         in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
     121       21650 :         if (in_fsp == NULL) {
     122           0 :                 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
     123             :         }
     124             : 
     125       21650 :         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       21650 :         if (subreq == NULL) {
     134           0 :                 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
     135             :         }
     136       21650 :         tevent_req_set_callback(subreq, smbd_smb2_request_getinfo_done, req);
     137             : 
     138       21650 :         return smbd_smb2_request_pending_queue(req, subreq, 500);
     139             : }
     140             : 
     141       21650 : static void smbd_smb2_request_getinfo_done(struct tevent_req *subreq)
     142             : {
     143       21650 :         struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
     144             :                                         struct smbd_smb2_request);
     145             :         DATA_BLOB outbody;
     146             :         DATA_BLOB outdyn;
     147             :         uint16_t out_output_buffer_offset;
     148       21650 :         DATA_BLOB out_output_buffer = data_blob_null;
     149             :         NTSTATUS status;
     150       21650 :         NTSTATUS call_status = NT_STATUS_OK;
     151             :         NTSTATUS error; /* transport error */
     152             : 
     153       21650 :         status = smbd_smb2_getinfo_recv(subreq,
     154             :                                         req,
     155             :                                         &out_output_buffer,
     156             :                                         &call_status);
     157       21650 :         TALLOC_FREE(subreq);
     158       21650 :         if (!NT_STATUS_IS_OK(status)) {
     159        1778 :                 error = smbd_smb2_request_error(req, status);
     160        1778 :                 if (!NT_STATUS_IS_OK(error)) {
     161           0 :                         smbd_server_connection_terminate(req->xconn,
     162             :                                                          nt_errstr(error));
     163           0 :                         return;
     164             :                 }
     165        1778 :                 return;
     166             :         }
     167             : 
     168             :         /* some GetInfo responses set STATUS_BUFFER_OVERFLOW and return partial,
     169             :            but valid data */
     170       20048 :         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             :                                                 &out_output_buffer,
     176             :                                                 __location__);
     177           8 :                 if (!NT_STATUS_IS_OK(error)) {
     178           0 :                         smbd_server_connection_terminate(req->xconn,
     179             :                                                          nt_errstr(error));
     180           0 :                         return;
     181             :                 }
     182           8 :                 return;
     183             :         }
     184             : 
     185       19864 :         out_output_buffer_offset = SMB2_HDR_BODY + 0x08;
     186             : 
     187       19864 :         outbody = smbd_smb2_generate_outbody(req, 0x08);
     188       19864 :         if (outbody.data == NULL) {
     189           0 :                 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
     190           0 :                 if (!NT_STATUS_IS_OK(error)) {
     191           0 :                         smbd_server_connection_terminate(req->xconn,
     192             :                                                          nt_errstr(error));
     193           0 :                         return;
     194             :                 }
     195           0 :                 return;
     196             :         }
     197             : 
     198       19864 :         SSVAL(outbody.data, 0x00, 0x08 + 1);    /* struct size */
     199       19864 :         SSVAL(outbody.data, 0x02,
     200             :               out_output_buffer_offset);        /* output buffer offset */
     201       19864 :         SIVAL(outbody.data, 0x04,
     202             :               out_output_buffer.length);        /* output buffer length */
     203             : 
     204       19864 :         outdyn = out_output_buffer;
     205             : 
     206       19864 :         error = smbd_smb2_request_done_ex(req, call_status, outbody, &outdyn, __location__);
     207       19864 :         if (!NT_STATUS_IS_OK(error)) {
     208           0 :                 smbd_server_connection_terminate(req->xconn,
     209             :                                                  nt_errstr(error));
     210           0 :                 return;
     211             :         }
     212             : }
     213             : 
     214             : struct smbd_smb2_getinfo_state {
     215             :         struct smbd_smb2_request *smb2req;
     216             :         NTSTATUS status;
     217             :         DATA_BLOB out_output_buffer;
     218             : };
     219             : 
     220           0 : static void smb2_ipc_getinfo(struct tevent_req *req,
     221             :                                 struct smbd_smb2_getinfo_state *state,
     222             :                                 struct tevent_context *ev,
     223             :                                 uint8_t in_info_type,
     224             :                                 uint8_t in_file_info_class)
     225             : {
     226             :         /* We want to reply to SMB2_GETINFO_FILE
     227             :            with a class of SMB2_FILE_STANDARD_INFO as
     228             :            otherwise a Win7 client issues this request
     229             :            twice (2xroundtrips) if we return NOT_SUPPORTED.
     230             :            NB. We do the same for SMB1 in call_trans2qpipeinfo() */
     231             : 
     232           0 :         if (in_info_type == 0x01 && /* SMB2_GETINFO_FILE */
     233           0 :                         in_file_info_class == 0x05) { /* SMB2_FILE_STANDARD_INFO */
     234           0 :                 state->out_output_buffer = data_blob_talloc(state,
     235             :                                                 NULL, 24);
     236           0 :                 if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     237           0 :                         return;
     238             :                 }
     239             : 
     240           0 :                 memset(state->out_output_buffer.data,0,24);
     241           0 :                 SOFF_T(state->out_output_buffer.data,0,4096LL);
     242           0 :                 SIVAL(state->out_output_buffer.data,16,1);
     243           0 :                 SIVAL(state->out_output_buffer.data,20,1);
     244           0 :                 tevent_req_done(req);
     245             :         } else {
     246           0 :                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     247             :         }
     248             : }
     249             : 
     250       21650 : static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx,
     251             :                                                  struct tevent_context *ev,
     252             :                                                  struct smbd_smb2_request *smb2req,
     253             :                                                  struct files_struct *fsp,
     254             :                                                  uint8_t in_info_type,
     255             :                                                  uint8_t in_file_info_class,
     256             :                                                  uint32_t in_output_buffer_length,
     257             :                                                  DATA_BLOB in_input_buffer,
     258             :                                                  uint32_t in_additional_information,
     259             :                                                  uint32_t in_flags)
     260             : {
     261             :         struct tevent_req *req;
     262             :         struct smbd_smb2_getinfo_state *state;
     263             :         struct smb_request *smbreq;
     264       21650 :         connection_struct *conn = smb2req->tcon->compat;
     265             :         NTSTATUS status;
     266             : 
     267       21650 :         req = tevent_req_create(mem_ctx, &state,
     268             :                                 struct smbd_smb2_getinfo_state);
     269       21650 :         if (req == NULL) {
     270           0 :                 return NULL;
     271             :         }
     272       21650 :         state->smb2req = smb2req;
     273       21650 :         state->status = NT_STATUS_OK;
     274       21650 :         state->out_output_buffer = data_blob_null;
     275             : 
     276       21650 :         DEBUG(10,("smbd_smb2_getinfo_send: %s - %s\n",
     277             :                   fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
     278             : 
     279       21650 :         smbreq = smbd_smb2_fake_smb_request(smb2req);
     280       21650 :         if (tevent_req_nomem(smbreq, req)) {
     281           0 :                 return tevent_req_post(req, ev);
     282             :         }
     283             : 
     284       21650 :         if (IS_IPC(conn)) {
     285           0 :                 smb2_ipc_getinfo(req, state, ev,
     286             :                         in_info_type, in_file_info_class);
     287           0 :                 return tevent_req_post(req, ev);
     288             :         }
     289             : 
     290       21650 :         switch (in_info_type) {
     291       12762 :         case SMB2_0_INFO_FILE:
     292             :         {
     293             :                 uint16_t file_info_level;
     294       12762 :                 char *data = NULL;
     295       12762 :                 unsigned int data_size = 0;
     296       12762 :                 bool delete_pending = false;
     297             :                 struct timespec write_time_ts;
     298             :                 struct file_id fileid;
     299       12762 :                 struct ea_list *ea_list = NULL;
     300       12762 :                 int lock_data_count = 0;
     301       12762 :                 char *lock_data = NULL;
     302             :                 size_t fixed_portion;
     303             : 
     304       12762 :                 ZERO_STRUCT(write_time_ts);
     305             : 
     306       12762 :                 switch (in_file_info_class) {
     307           8 :                 case FSCC_FILE_FULL_EA_INFORMATION:
     308           8 :                         file_info_level = SMB2_FILE_FULL_EA_INFORMATION;
     309           8 :                         break;
     310             : 
     311        5608 :                 case FSCC_FILE_ALL_INFORMATION:
     312        5608 :                         file_info_level = SMB2_FILE_ALL_INFORMATION;
     313        5608 :                         break;
     314             : 
     315        7146 :                 default:
     316             :                         /* the levels directly map to the passthru levels */
     317        7146 :                         file_info_level = in_file_info_class + 1000;
     318        7146 :                         break;
     319             :                 }
     320             : 
     321       12762 :                 switch (file_info_level) {
     322          92 :                 case SMB_FILE_NORMALIZED_NAME_INFORMATION:
     323          92 :                         if (smb2req->xconn->protocol < PROTOCOL_SMB3_11) {
     324           4 :                                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     325        1340 :                                 return tevent_req_post(req, ev);
     326             :                         }
     327          88 :                         break;
     328             :                 }
     329             : 
     330       12758 :                 if (fsp->fake_file_handle) {
     331             :                         /*
     332             :                          * This is actually for the QUOTA_FAKE_FILE --metze
     333             :                          */
     334             : 
     335             :                         /* We know this name is ok, it's already passed the checks. */
     336             : 
     337       12758 :                 } else if (fsp_get_pathref_fd(fsp) == -1) {
     338             :                         /*
     339             :                          * This is actually a QFILEINFO on a directory
     340             :                          * handle (returned from an NT SMB). NT5.0 seems
     341             :                          * to do this call. JRA.
     342             :                          */
     343             : 
     344           0 :                         if (fsp->fsp_name->flags & SMB_FILENAME_POSIX_PATH) {
     345             :                                 /* Always do lstat for UNIX calls. */
     346           0 :                                 if (SMB_VFS_LSTAT(conn, fsp->fsp_name)) {
     347           0 :                                         DEBUG(3,("smbd_smb2_getinfo_send: "
     348             :                                                  "SMB_VFS_LSTAT of %s failed "
     349             :                                                  "(%s)\n", fsp_str_dbg(fsp),
     350             :                                                  strerror(errno)));
     351           0 :                                         status = map_nt_error_from_unix(errno);
     352           0 :                                         tevent_req_nterror(req, status);
     353           0 :                                         return tevent_req_post(req, ev);
     354             :                                 }
     355           0 :                         } else if (SMB_VFS_STAT(conn, fsp->fsp_name)) {
     356           0 :                                 DEBUG(3,("smbd_smb2_getinfo_send: "
     357             :                                          "SMB_VFS_STAT of %s failed (%s)\n",
     358             :                                          fsp_str_dbg(fsp),
     359             :                                          strerror(errno)));
     360           0 :                                 status = map_nt_error_from_unix(errno);
     361           0 :                                 tevent_req_nterror(req, status);
     362           0 :                                 return tevent_req_post(req, ev);
     363             :                         }
     364             : 
     365           0 :                         if (lp_smbd_getinfo_ask_sharemode(SNUM(conn))) {
     366           0 :                                 fileid = vfs_file_id_from_sbuf(
     367           0 :                                         conn, &fsp->fsp_name->st);
     368           0 :                                 get_file_infos(fileid, fsp->name_hash,
     369             :                                                &delete_pending,
     370             :                                                &write_time_ts);
     371             :                         }
     372             :                 } else {
     373             :                         /*
     374             :                          * Original code - this is an open file.
     375             :                          */
     376             : 
     377       12758 :                         if (SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st) != 0) {
     378           0 :                                 DEBUG(3, ("smbd_smb2_getinfo_send: "
     379             :                                           "fstat of %s failed (%s)\n",
     380             :                                           fsp_fnum_dbg(fsp), strerror(errno)));
     381           0 :                                 status = map_nt_error_from_unix(errno);
     382           0 :                                 tevent_req_nterror(req, status);
     383           0 :                                 return tevent_req_post(req, ev);
     384             :                         }
     385       12758 :                         if (lp_smbd_getinfo_ask_sharemode(SNUM(conn))) {
     386       12758 :                                 fileid = vfs_file_id_from_sbuf(
     387       12758 :                                         conn, &fsp->fsp_name->st);
     388       12758 :                                 get_file_infos(fileid, fsp->name_hash,
     389             :                                                &delete_pending,
     390             :                                                &write_time_ts);
     391             :                         }
     392             :                 }
     393             : 
     394       12758 :                 status = smbd_do_qfilepathinfo(conn, state,
     395             :                                                smbreq,
     396             :                                                file_info_level,
     397             :                                                fsp,
     398             :                                                fsp->fsp_name,
     399             :                                                delete_pending,
     400             :                                                write_time_ts,
     401             :                                                ea_list,
     402             :                                                lock_data_count,
     403             :                                                lock_data,
     404             :                                                STR_UNICODE,
     405             :                                                in_output_buffer_length,
     406             :                                                &fixed_portion,
     407             :                                                &data,
     408             :                                                &data_size);
     409       12758 :                 if (!NT_STATUS_IS_OK(status)) {
     410         212 :                         SAFE_FREE(data);
     411         212 :                         if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
     412           0 :                                 status = NT_STATUS_INVALID_INFO_CLASS;
     413             :                         }
     414         212 :                         tevent_req_nterror(req, status);
     415         212 :                         return tevent_req_post(req, ev);
     416             :                 }
     417       12546 :                 if (in_output_buffer_length < fixed_portion) {
     418        1120 :                         SAFE_FREE(data);
     419        1120 :                         tevent_req_nterror(
     420             :                                 req, NT_STATUS_INFO_LENGTH_MISMATCH);
     421        1120 :                         return tevent_req_post(req, ev);
     422             :                 }
     423       11426 :                 if (data_size > 0) {
     424       11300 :                         state->out_output_buffer = data_blob_talloc(state,
     425             :                                                                     data,
     426             :                                                                     data_size);
     427       11300 :                         SAFE_FREE(data);
     428       11300 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     429           0 :                                 return tevent_req_post(req, ev);
     430             :                         }
     431       11300 :                         if (data_size > in_output_buffer_length) {
     432         152 :                                 state->out_output_buffer.length =
     433             :                                         in_output_buffer_length;
     434         152 :                                 status = STATUS_BUFFER_OVERFLOW;
     435             :                         }
     436             :                 }
     437       11426 :                 SAFE_FREE(data);
     438       11426 :                 break;
     439             :         }
     440             : 
     441        1765 :         case SMB2_0_INFO_FILESYSTEM:
     442             :         {
     443             :                 uint16_t file_info_level;
     444        1765 :                 char *data = NULL;
     445        1765 :                 int data_size = 0;
     446             :                 size_t fixed_portion;
     447             : 
     448             :                 /* the levels directly map to the passthru levels */
     449        1765 :                 file_info_level = in_file_info_class + 1000;
     450             : 
     451        1765 :                 status = smbd_do_qfsinfo(smb2req->xconn, conn, state,
     452             :                                          file_info_level,
     453             :                                          STR_UNICODE,
     454             :                                          in_output_buffer_length,
     455             :                                          &fixed_portion,
     456             :                                          fsp->fsp_name,
     457             :                                          &data,
     458             :                                          &data_size);
     459             :                 /* some responses set STATUS_BUFFER_OVERFLOW and return
     460             :                    partial, but valid data */
     461        1785 :                 if (!(NT_STATUS_IS_OK(status) ||
     462          20 :                       NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW))) {
     463           4 :                         SAFE_FREE(data);
     464           4 :                         if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
     465           0 :                                 status = NT_STATUS_INVALID_INFO_CLASS;
     466             :                         }
     467           4 :                         tevent_req_nterror(req, status);
     468         424 :                         return tevent_req_post(req, ev);
     469             :                 }
     470        1761 :                 if (in_output_buffer_length < fixed_portion) {
     471         416 :                         SAFE_FREE(data);
     472         416 :                         tevent_req_nterror(
     473             :                                 req, NT_STATUS_INFO_LENGTH_MISMATCH);
     474         416 :                         return tevent_req_post(req, ev);
     475             :                 }
     476        1345 :                 if (data_size > 0) {
     477        1345 :                         state->out_output_buffer = data_blob_talloc(state,
     478             :                                                                     data,
     479             :                                                                     data_size);
     480        1345 :                         SAFE_FREE(data);
     481        1345 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     482           0 :                                 return tevent_req_post(req, ev);
     483             :                         }
     484        1345 :                         if (data_size > in_output_buffer_length) {
     485           0 :                                 state->out_output_buffer.length =
     486             :                                         in_output_buffer_length;
     487           0 :                                 status = STATUS_BUFFER_OVERFLOW;
     488             :                         }
     489             :                 }
     490        1345 :                 SAFE_FREE(data);
     491        1345 :                 break;
     492             :         }
     493             : 
     494        7101 :         case SMB2_0_INFO_SECURITY:
     495             :         {
     496        7101 :                 uint8_t *p_marshalled_sd = NULL;
     497        7101 :                 size_t sd_size = 0;
     498             : 
     499        7101 :                 status = smbd_do_query_security_desc(conn,
     500             :                                 state,
     501             :                                 fsp,
     502             :                                 /* Security info wanted. */
     503             :                                 in_additional_information &
     504             :                                 SMB_SUPPORTED_SECINFO_FLAGS,
     505             :                                 in_output_buffer_length,
     506             :                                 &p_marshalled_sd,
     507             :                                 &sd_size);
     508             : 
     509        7101 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
     510             :                         /* Return needed size. */
     511           8 :                         state->out_output_buffer = data_blob_talloc(state,
     512             :                                                                     NULL,
     513             :                                                                     4);
     514           8 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     515          14 :                                 return tevent_req_post(req, ev);
     516             :                         }
     517           8 :                         SIVAL(state->out_output_buffer.data,0,(uint32_t)sd_size);
     518           8 :                         state->status = NT_STATUS_BUFFER_TOO_SMALL;
     519        7095 :                         break;
     520             :                 }
     521        7093 :                 if (!NT_STATUS_IS_OK(status)) {
     522          14 :                         DEBUG(10,("smbd_smb2_getinfo_send: "
     523             :                                  "smbd_do_query_security_desc of %s failed "
     524             :                                  "(%s)\n", fsp_str_dbg(fsp),
     525             :                                  nt_errstr(status)));
     526          14 :                         tevent_req_nterror(req, status);
     527          14 :                         return tevent_req_post(req, ev);
     528             :                 }
     529             : 
     530        7079 :                 if (sd_size > 0) {
     531        7079 :                         state->out_output_buffer = data_blob_talloc(state,
     532             :                                                                     p_marshalled_sd,
     533             :                                                                     sd_size);
     534        7079 :                         if (tevent_req_nomem(state->out_output_buffer.data, req)) {
     535           0 :                                 return tevent_req_post(req, ev);
     536             :                         }
     537             :                 }
     538        7079 :                 break;
     539             :         }
     540             : 
     541          22 :         case SMB2_0_INFO_QUOTA: {
     542             : #ifdef HAVE_SYS_QUOTAS
     543             :                 struct smb2_query_quota_info info;
     544             :                 enum ndr_err_code err;
     545          22 :                 uint8_t *data = NULL;
     546          22 :                 uint32_t data_size = 0;
     547          22 :                 struct ndr_pull *ndr_pull = NULL;
     548          22 :                 DATA_BLOB sid_buf = data_blob_null;
     549          22 :                 TALLOC_CTX *tmp_ctx = talloc_init("geninfo_quota");
     550             :                 bool ok;
     551             : 
     552          22 :                 if (!tmp_ctx) {
     553           0 :                         tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     554           8 :                         return tevent_req_post(req, ev);
     555             :                 }
     556             : 
     557          22 :                 ok = check_fsp_ntquota_handle(conn, smbreq, fsp);
     558          22 :                 if (!ok) {
     559           4 :                         DBG_INFO("no valid QUOTA HANDLE\n");
     560           4 :                         TALLOC_FREE(tmp_ctx);
     561           4 :                         tevent_req_nterror(req, NT_STATUS_INVALID_HANDLE);
     562           4 :                         return tevent_req_post(req, ev);
     563             :                 }
     564             : 
     565          18 :                 ndr_pull = ndr_pull_init_blob(&in_input_buffer, tmp_ctx);
     566          18 :                 if (!ndr_pull) {
     567           0 :                         TALLOC_FREE(tmp_ctx);
     568           0 :                         tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     569           0 :                         return tevent_req_post(req, ev);
     570             :                 }
     571             : 
     572          18 :                 err = ndr_pull_smb2_query_quota_info(ndr_pull,
     573             :                                                      NDR_SCALARS | NDR_BUFFERS,
     574             :                                                      &info);
     575             : 
     576          18 :                 if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
     577           0 :                         DBG_DEBUG("failed to pull smb2_query_quota_info\n");
     578           0 :                         TALLOC_FREE(tmp_ctx);
     579           0 :                         tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
     580           0 :                         return tevent_req_post(req, ev);
     581             :                 }
     582             : 
     583          18 :                 DBG_DEBUG("quota list returnsingle %u, restartscan %u, "
     584             :                           "sid_list_length %u, start_sid_length %u, "
     585             :                           "startsidoffset %u\n",
     586             :                           (unsigned int)info.return_single,
     587             :                           (unsigned int)info.restart_scan,
     588             :                           (unsigned int)info.sid_list_length,
     589             :                           (unsigned int)info.start_sid_length,
     590             :                           (unsigned int)info.start_sid_offset);
     591             : 
     592             :                 /* Currently we do not support the single start sid format */
     593          18 :                 if (info.start_sid_length != 0 || info.start_sid_offset != 0 ) {
     594           0 :                         DBG_INFO("illegal single sid query\n");
     595           0 :                         TALLOC_FREE(tmp_ctx);
     596           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     597           0 :                         return tevent_req_post(req, ev);
     598             :                 }
     599             : 
     600          18 :                 if (in_input_buffer.length < ndr_pull->offset) {
     601           0 :                         DBG_INFO("Invalid buffer length\n");
     602           0 :                         TALLOC_FREE(tmp_ctx);
     603           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     604           0 :                         return tevent_req_post(req, ev);
     605             :                 }
     606             : 
     607          18 :                 sid_buf.data = in_input_buffer.data + ndr_pull->offset;
     608          18 :                 sid_buf.length = in_input_buffer.length - ndr_pull->offset;
     609             : 
     610          54 :                 status = smbd_do_query_getinfo_quota(tmp_ctx,
     611             :                                   fsp,
     612          18 :                                   info.restart_scan,
     613          18 :                                   info.return_single,
     614             :                                   info.sid_list_length,
     615             :                                   &sid_buf,
     616             :                                   in_output_buffer_length,
     617             :                                   &data,
     618             :                                   &data_size);
     619             : 
     620          18 :                 if (!NT_STATUS_IS_OK(status)) {
     621           4 :                         TALLOC_FREE(tmp_ctx);
     622           4 :                         tevent_req_nterror(req, status);
     623           4 :                         return tevent_req_post(req, ev);
     624             :                 }
     625             : 
     626          14 :                 state->out_output_buffer =
     627          14 :                         data_blob_talloc(state, data, data_size);
     628          14 :                 status  = NT_STATUS_OK;
     629          14 :                 TALLOC_FREE(tmp_ctx);
     630          14 :                 break;
     631             : #else
     632             :                 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
     633             :                 return tevent_req_post(req, ev);
     634             : #endif
     635             :         }
     636             : 
     637           0 :         default:
     638           0 :                 DEBUG(10,("smbd_smb2_getinfo_send: "
     639             :                         "unknown in_info_type of %u "
     640             :                         " for file %s\n",
     641             :                         (unsigned int)in_info_type,
     642             :                         fsp_str_dbg(fsp) ));
     643             : 
     644           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     645           0 :                 return tevent_req_post(req, ev);
     646             :         }
     647             : 
     648       19872 :         state->status = status;
     649       19872 :         tevent_req_done(req);
     650       19872 :         return tevent_req_post(req, ev);
     651             : }
     652             : 
     653       21650 : static NTSTATUS smbd_smb2_getinfo_recv(struct tevent_req *req,
     654             :                                        TALLOC_CTX *mem_ctx,
     655             :                                        DATA_BLOB *out_output_buffer,
     656             :                                        NTSTATUS *pstatus)
     657             : {
     658             :         NTSTATUS status;
     659       21650 :         struct smbd_smb2_getinfo_state *state = tevent_req_data(req,
     660             :                                                 struct smbd_smb2_getinfo_state);
     661             : 
     662       21650 :         if (tevent_req_is_nterror(req, &status)) {
     663        1778 :                 tevent_req_received(req);
     664        1778 :                 return status;
     665             :         }
     666             : 
     667       19872 :         *out_output_buffer = state->out_output_buffer;
     668       19872 :         talloc_steal(mem_ctx, out_output_buffer->data);
     669       19872 :         *pstatus = state->status;
     670             : 
     671       19872 :         tevent_req_received(req);
     672       19872 :         return NT_STATUS_OK;
     673             : }

Generated by: LCOV version 1.13