LCOV - code coverage report
Current view: top level - source4/libcli - clitrans2.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 83 95 87.4 %
Date: 2024-06-13 04:01:37 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    client trans2 calls
       4             :    Copyright (C) James J Myers 2003     <myersjj@samba.org>
       5             :    
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "libcli/raw/libcliraw.h"
      22             : #include "libcli/libcli.h"
      23             : 
      24             : /****************************************************************************
      25             : send a qpathinfo call
      26             : ****************************************************************************/
      27         164 : NTSTATUS smbcli_qpathinfo(struct smbcli_tree *tree, const char *fname, 
      28             :                        time_t *c_time, time_t *a_time, time_t *m_time, 
      29             :                        size_t *size, uint16_t *mode)
      30             : {
      31             :         union smb_fileinfo parms;
      32             :         TALLOC_CTX *mem_ctx;
      33             :         NTSTATUS status;
      34             : 
      35         164 :         mem_ctx = talloc_init("smbcli_qpathinfo");
      36         164 :         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
      37             : 
      38         164 :         parms.standard.level = RAW_FILEINFO_STANDARD;
      39         164 :         parms.standard.in.file.path = fname;
      40             : 
      41         164 :         status = smb_raw_pathinfo(tree, mem_ctx, &parms);
      42         164 :         talloc_free(mem_ctx);
      43         164 :         if (!NT_STATUS_IS_OK(status))
      44          32 :                 return status;
      45             : 
      46         132 :         if (c_time) {
      47         132 :                 *c_time = parms.standard.out.create_time;
      48             :         }
      49         132 :         if (a_time) {
      50         132 :                 *a_time = parms.standard.out.access_time;
      51             :         }
      52         132 :         if (m_time) {
      53         132 :                 *m_time = parms.standard.out.write_time;
      54             :         }
      55         132 :         if (size) {
      56         132 :                 *size = parms.standard.out.size;
      57             :         }
      58         132 :         if (mode) {
      59         130 :                 *mode = parms.standard.out.attrib;
      60             :         }
      61             : 
      62         132 :         return status;
      63             : }
      64             : 
      65             : /****************************************************************************
      66             : send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level
      67             : ****************************************************************************/
      68           6 : NTSTATUS smbcli_qpathinfo2(struct smbcli_tree *tree, const char *fname, 
      69             :                         time_t *c_time, time_t *a_time, time_t *m_time, 
      70             :                         time_t *w_time, size_t *size, uint16_t *mode,
      71             :                         ino_t *ino)
      72             : {
      73             :         union smb_fileinfo parms;
      74             :         TALLOC_CTX *mem_ctx;
      75             :         NTSTATUS status;
      76             : 
      77           6 :         mem_ctx = talloc_init("smbcli_qfilename");
      78           6 :         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
      79             : 
      80           6 :         parms.all_info.level = RAW_FILEINFO_ALL_INFO;
      81           6 :         parms.all_info.in.file.path = fname;
      82             : 
      83           6 :         status = smb_raw_pathinfo(tree, mem_ctx, &parms);
      84           6 :         talloc_free(mem_ctx);
      85           6 :         if (!NT_STATUS_IS_OK(status))
      86           0 :                 return status;
      87             : 
      88           6 :         if (c_time) {
      89           6 :                 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
      90             :         }
      91           6 :         if (a_time) {
      92           6 :                 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
      93             :         }
      94           6 :         if (m_time) {
      95           6 :                 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
      96             :         }
      97           6 :         if (w_time) {
      98           6 :                 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
      99             :         }
     100           6 :         if (size) {
     101           6 :                 *size = parms.all_info.out.size;
     102             :         }
     103           6 :         if (mode) {
     104           0 :                 *mode = parms.all_info.out.attrib;
     105             :         }
     106             : 
     107           6 :         return status;
     108             : }
     109             : 
     110             : 
     111             : /****************************************************************************
     112             : send a qfileinfo QUERY_FILE_NAME_INFO call
     113             : ****************************************************************************/
     114           2 : NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name)
     115             : {
     116             :         union smb_fileinfo parms;
     117             :         TALLOC_CTX *mem_ctx;
     118             :         NTSTATUS status;
     119             : 
     120           2 :         mem_ctx = talloc_init("smbcli_qfilename");
     121           2 :         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
     122             : 
     123           2 :         parms.name_info.level = RAW_FILEINFO_NAME_INFO;
     124           2 :         parms.name_info.in.file.fnum = fnum;
     125             : 
     126           2 :         status = smb_raw_fileinfo(tree, mem_ctx, &parms);
     127           2 :         if (!NT_STATUS_IS_OK(status)) {
     128           0 :                 talloc_free(mem_ctx);
     129           0 :                 *name = NULL;
     130           0 :                 return status;
     131             :         }
     132             : 
     133           2 :         *name = strdup(parms.name_info.out.fname.s);
     134             : 
     135           2 :         talloc_free(mem_ctx);
     136             : 
     137           2 :         return status;
     138             : }
     139             : 
     140             : 
     141             : /****************************************************************************
     142             : send a qfileinfo call
     143             : ****************************************************************************/
     144          10 : NTSTATUS smbcli_qfileinfo(struct smbcli_tree *tree, int fnum, 
     145             :                        uint16_t *mode, size_t *size,
     146             :                        time_t *c_time, time_t *a_time, time_t *m_time, 
     147             :                        time_t *w_time, ino_t *ino)
     148             : {
     149             :         union smb_fileinfo parms;
     150             :         TALLOC_CTX *mem_ctx;
     151             :         NTSTATUS status;
     152             : 
     153          10 :         mem_ctx = talloc_init("smbcli_qfileinfo");
     154          10 :         if (!mem_ctx) 
     155           0 :                 return NT_STATUS_NO_MEMORY;
     156             : 
     157          10 :         parms.all_info.level = RAW_FILEINFO_ALL_INFO;
     158          10 :         parms.all_info.in.file.fnum = fnum;
     159             : 
     160          10 :         status = smb_raw_fileinfo(tree, mem_ctx, &parms);
     161          10 :         talloc_free(mem_ctx);
     162          10 :         if (!NT_STATUS_IS_OK(status)) {
     163           2 :                 return status;
     164             :         }
     165             : 
     166           8 :         if (c_time) {
     167           2 :                 *c_time = nt_time_to_unix(parms.all_info.out.create_time);
     168             :         }
     169           8 :         if (a_time) {
     170           2 :                 *a_time = nt_time_to_unix(parms.all_info.out.access_time);
     171             :         }
     172           8 :         if (m_time) {
     173           2 :                 *m_time = nt_time_to_unix(parms.all_info.out.change_time);
     174             :         }
     175           8 :         if (w_time) {
     176           0 :                 *w_time = nt_time_to_unix(parms.all_info.out.write_time);
     177             :         }
     178           8 :         if (mode) {
     179           6 :                 *mode = parms.all_info.out.attrib;
     180             :         }
     181           8 :         if (size) {
     182           8 :                 *size = (size_t)parms.all_info.out.size;
     183             :         }
     184           8 :         if (ino) {
     185           0 :                 *ino = 0;
     186             :         }
     187             : 
     188           8 :         return status;
     189             : }
     190             : 
     191             : 
     192             : /****************************************************************************
     193             : send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call
     194             : ****************************************************************************/
     195          22 : NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname, 
     196             :                                 const char **alt_name)
     197             : {
     198             :         union smb_fileinfo parms;
     199             :         TALLOC_CTX *mem_ctx;
     200             :         NTSTATUS status;
     201             : 
     202          22 :         parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO;
     203          22 :         parms.alt_name_info.in.file.path = fname;
     204             : 
     205          22 :         mem_ctx = talloc_init("smbcli_qpathinfo_alt_name");
     206          22 :         if (!mem_ctx) return NT_STATUS_NO_MEMORY;
     207             : 
     208          22 :         status = smb_raw_pathinfo(tree, mem_ctx, &parms);
     209          22 :         if (!NT_STATUS_IS_OK(status)) {
     210           0 :                 talloc_free(mem_ctx);
     211           0 :                 *alt_name = NULL;
     212           0 :                 return smbcli_nt_error(tree);
     213             :         }
     214             : 
     215          22 :         if (!parms.alt_name_info.out.fname.s) {
     216           0 :                 *alt_name = strdup("");
     217             :         } else {
     218          22 :                 *alt_name = strdup(parms.alt_name_info.out.fname.s);
     219             :         }
     220             : 
     221          22 :         talloc_free(mem_ctx);
     222             : 
     223          22 :         return NT_STATUS_OK;
     224             : }

Generated by: LCOV version 1.13