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 598 : 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 86 : union smb_fileinfo parms; 32 86 : TALLOC_CTX *mem_ctx; 33 86 : NTSTATUS status; 34 : 35 598 : mem_ctx = talloc_init("smbcli_qpathinfo"); 36 598 : if (!mem_ctx) return NT_STATUS_NO_MEMORY; 37 : 38 598 : parms.standard.level = RAW_FILEINFO_STANDARD; 39 598 : parms.standard.in.file.path = fname; 40 : 41 598 : status = smb_raw_pathinfo(tree, mem_ctx, &parms); 42 598 : talloc_free(mem_ctx); 43 598 : if (!NT_STATUS_IS_OK(status)) 44 147 : return status; 45 : 46 451 : if (c_time) { 47 451 : *c_time = parms.standard.out.create_time; 48 : } 49 451 : if (a_time) { 50 451 : *a_time = parms.standard.out.access_time; 51 : } 52 451 : if (m_time) { 53 451 : *m_time = parms.standard.out.write_time; 54 : } 55 451 : if (size) { 56 451 : *size = parms.standard.out.size; 57 : } 58 451 : if (mode) { 59 445 : *mode = parms.standard.out.attrib; 60 : } 61 : 62 451 : return status; 63 : } 64 : 65 : /**************************************************************************** 66 : send a qpathinfo call with the SMB_QUERY_FILE_ALL_INFO info level 67 : ****************************************************************************/ 68 18 : 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 0 : union smb_fileinfo parms; 74 0 : TALLOC_CTX *mem_ctx; 75 0 : NTSTATUS status; 76 : 77 18 : mem_ctx = talloc_init("smbcli_qfilename"); 78 18 : if (!mem_ctx) return NT_STATUS_NO_MEMORY; 79 : 80 18 : parms.all_info.level = RAW_FILEINFO_ALL_INFO; 81 18 : parms.all_info.in.file.path = fname; 82 : 83 18 : status = smb_raw_pathinfo(tree, mem_ctx, &parms); 84 18 : talloc_free(mem_ctx); 85 18 : if (!NT_STATUS_IS_OK(status)) 86 0 : return status; 87 : 88 18 : if (c_time) { 89 18 : *c_time = nt_time_to_unix(parms.all_info.out.create_time); 90 : } 91 18 : if (a_time) { 92 18 : *a_time = nt_time_to_unix(parms.all_info.out.access_time); 93 : } 94 18 : if (m_time) { 95 18 : *m_time = nt_time_to_unix(parms.all_info.out.change_time); 96 : } 97 18 : if (w_time) { 98 18 : *w_time = nt_time_to_unix(parms.all_info.out.write_time); 99 : } 100 18 : if (size) { 101 18 : *size = parms.all_info.out.size; 102 : } 103 18 : if (mode) { 104 0 : *mode = parms.all_info.out.attrib; 105 : } 106 : 107 18 : return status; 108 : } 109 : 110 : 111 : /**************************************************************************** 112 : send a qfileinfo QUERY_FILE_NAME_INFO call 113 : ****************************************************************************/ 114 6 : NTSTATUS smbcli_qfilename(struct smbcli_tree *tree, int fnum, const char **name) 115 : { 116 0 : union smb_fileinfo parms; 117 0 : TALLOC_CTX *mem_ctx; 118 0 : NTSTATUS status; 119 : 120 6 : mem_ctx = talloc_init("smbcli_qfilename"); 121 6 : if (!mem_ctx) return NT_STATUS_NO_MEMORY; 122 : 123 6 : parms.name_info.level = RAW_FILEINFO_NAME_INFO; 124 6 : parms.name_info.in.file.fnum = fnum; 125 : 126 6 : status = smb_raw_fileinfo(tree, mem_ctx, &parms); 127 6 : if (!NT_STATUS_IS_OK(status)) { 128 0 : talloc_free(mem_ctx); 129 0 : *name = NULL; 130 0 : return status; 131 : } 132 : 133 6 : *name = strdup(parms.name_info.out.fname.s); 134 : 135 6 : talloc_free(mem_ctx); 136 : 137 6 : return status; 138 : } 139 : 140 : 141 : /**************************************************************************** 142 : send a qfileinfo call 143 : ****************************************************************************/ 144 18 : 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 0 : union smb_fileinfo parms; 150 0 : TALLOC_CTX *mem_ctx; 151 0 : NTSTATUS status; 152 : 153 18 : mem_ctx = talloc_init("smbcli_qfileinfo"); 154 18 : if (!mem_ctx) 155 0 : return NT_STATUS_NO_MEMORY; 156 : 157 18 : parms.all_info.level = RAW_FILEINFO_ALL_INFO; 158 18 : parms.all_info.in.file.fnum = fnum; 159 : 160 18 : status = smb_raw_fileinfo(tree, mem_ctx, &parms); 161 18 : talloc_free(mem_ctx); 162 18 : if (!NT_STATUS_IS_OK(status)) { 163 6 : return status; 164 : } 165 : 166 12 : if (c_time) { 167 6 : *c_time = nt_time_to_unix(parms.all_info.out.create_time); 168 : } 169 12 : if (a_time) { 170 6 : *a_time = nt_time_to_unix(parms.all_info.out.access_time); 171 : } 172 12 : if (m_time) { 173 6 : *m_time = nt_time_to_unix(parms.all_info.out.change_time); 174 : } 175 12 : if (w_time) { 176 0 : *w_time = nt_time_to_unix(parms.all_info.out.write_time); 177 : } 178 12 : if (mode) { 179 6 : *mode = parms.all_info.out.attrib; 180 : } 181 12 : if (size) { 182 12 : *size = (size_t)parms.all_info.out.size; 183 : } 184 12 : if (ino) { 185 0 : *ino = 0; 186 : } 187 : 188 12 : return status; 189 : } 190 : 191 : 192 : /**************************************************************************** 193 : send a qpathinfo SMB_QUERY_FILE_ALT_NAME_INFO call 194 : ****************************************************************************/ 195 62 : NTSTATUS smbcli_qpathinfo_alt_name(struct smbcli_tree *tree, const char *fname, 196 : const char **alt_name) 197 : { 198 0 : union smb_fileinfo parms; 199 0 : TALLOC_CTX *mem_ctx; 200 0 : NTSTATUS status; 201 : 202 62 : parms.alt_name_info.level = RAW_FILEINFO_ALT_NAME_INFO; 203 62 : parms.alt_name_info.in.file.path = fname; 204 : 205 62 : mem_ctx = talloc_init("smbcli_qpathinfo_alt_name"); 206 62 : if (!mem_ctx) return NT_STATUS_NO_MEMORY; 207 : 208 62 : status = smb_raw_pathinfo(tree, mem_ctx, &parms); 209 62 : 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 62 : if (!parms.alt_name_info.out.fname.s) { 216 0 : *alt_name = strdup(""); 217 : } else { 218 62 : *alt_name = strdup(parms.alt_name_info.out.fname.s); 219 : } 220 : 221 62 : talloc_free(mem_ctx); 222 : 223 62 : return NT_STATUS_OK; 224 : }