2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - read
6 Copyright (C) Andrew Tridgell 2004
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.
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.
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/>.
23 #include "vfs_posix.h"
24 #include "librpc/gen_ndr/xattr.h"
28 determine what access bits are needed for a call
30 static uint32_t pvfs_fileinfo_access(union smb_fileinfo *info)
34 switch (info->generic.level) {
35 case RAW_FILEINFO_EA_LIST:
36 case RAW_FILEINFO_ALL_EAS:
37 needed = SEC_FILE_READ_EA;
40 case RAW_FILEINFO_IS_NAME_VALID:
44 case RAW_FILEINFO_SEC_DESC:
46 if (info->query_secdesc.in.secinfo_flags & (SECINFO_OWNER|SECINFO_GROUP)) {
47 needed |= SEC_STD_READ_CONTROL;
49 if (info->query_secdesc.in.secinfo_flags & SECINFO_DACL) {
50 needed |= SEC_STD_READ_CONTROL;
52 if (info->query_secdesc.in.secinfo_flags & SECINFO_SACL) {
53 needed |= SEC_FLAG_SYSTEM_SECURITY;
58 needed = SEC_FILE_READ_ATTRIBUTE;
66 reply to a RAW_FILEINFO_EA_LIST call
68 NTSTATUS pvfs_query_ea_list(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
69 struct pvfs_filename *name, int fd,
71 struct ea_name *names,
72 struct smb_ea_list *eas)
76 struct xattr_DosEAs *ealist = talloc(mem_ctx, struct xattr_DosEAs);
79 status = pvfs_doseas_load(pvfs, name, fd, ealist);
80 if (!NT_STATUS_IS_OK(status)) {
83 eas->eas = talloc_array(mem_ctx, struct ea_struct, num_names);
84 if (eas->eas == NULL) {
85 return NT_STATUS_NO_MEMORY;
87 eas->num_eas = num_names;
88 for (i=0;i<num_names;i++) {
90 eas->eas[i].flags = 0;
91 eas->eas[i].name.s = names[i].name.s;
92 eas->eas[i].value = data_blob(NULL, 0);
93 for (j=0;j<ealist->num_eas;j++) {
94 if (strcasecmp_m(eas->eas[i].name.s,
95 ealist->eas[j].name) == 0) {
96 eas->eas[i].value = ealist->eas[j].value;
105 reply to a RAW_FILEINFO_ALL_EAS call
107 static NTSTATUS pvfs_query_all_eas(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
108 struct pvfs_filename *name, int fd,
109 struct smb_ea_list *eas)
113 struct xattr_DosEAs *ealist = talloc(mem_ctx, struct xattr_DosEAs);
116 status = pvfs_doseas_load(pvfs, name, fd, ealist);
117 if (!NT_STATUS_IS_OK(status)) {
120 eas->eas = talloc_array(mem_ctx, struct ea_struct, ealist->num_eas);
121 if (eas->eas == NULL) {
122 return NT_STATUS_NO_MEMORY;
125 for (i=0;i<ealist->num_eas;i++) {
126 eas->eas[eas->num_eas].flags = 0;
127 eas->eas[eas->num_eas].name.s = ealist->eas[i].name;
128 eas->eas[eas->num_eas].value = ealist->eas[i].value;
135 approximately map a struct pvfs_filename to a generic fileinfo struct
137 static NTSTATUS pvfs_map_fileinfo(struct pvfs_state *pvfs,
138 struct ntvfs_request *req,
139 struct pvfs_filename *name, union smb_fileinfo *info,
142 switch (info->generic.level) {
143 case RAW_FILEINFO_GENERIC:
144 return NT_STATUS_INVALID_LEVEL;
146 case RAW_FILEINFO_GETATTR:
147 info->getattr.out.attrib = name->dos.attrib;
148 info->getattr.out.size = name->st.st_size;
149 info->getattr.out.write_time = nt_time_to_unix(name->dos.write_time);
152 case RAW_FILEINFO_GETATTRE:
153 case RAW_FILEINFO_STANDARD:
154 info->standard.out.create_time = nt_time_to_unix(name->dos.create_time);
155 info->standard.out.access_time = nt_time_to_unix(name->dos.access_time);
156 info->standard.out.write_time = nt_time_to_unix(name->dos.write_time);
157 info->standard.out.size = name->st.st_size;
158 info->standard.out.alloc_size = name->dos.alloc_size;
159 info->standard.out.attrib = name->dos.attrib;
162 case RAW_FILEINFO_EA_SIZE:
163 info->ea_size.out.create_time = nt_time_to_unix(name->dos.create_time);
164 info->ea_size.out.access_time = nt_time_to_unix(name->dos.access_time);
165 info->ea_size.out.write_time = nt_time_to_unix(name->dos.write_time);
166 info->ea_size.out.size = name->st.st_size;
167 info->ea_size.out.alloc_size = name->dos.alloc_size;
168 info->ea_size.out.attrib = name->dos.attrib;
169 info->ea_size.out.ea_size = name->dos.ea_size;
172 case RAW_FILEINFO_EA_LIST:
173 return pvfs_query_ea_list(pvfs, req, name, fd,
174 info->ea_list.in.num_names,
175 info->ea_list.in.ea_names,
178 case RAW_FILEINFO_ALL_EAS:
179 return pvfs_query_all_eas(pvfs, req, name, fd, &info->all_eas.out);
181 case RAW_FILEINFO_IS_NAME_VALID:
184 case RAW_FILEINFO_BASIC_INFO:
185 case RAW_FILEINFO_BASIC_INFORMATION:
186 info->basic_info.out.create_time = name->dos.create_time;
187 info->basic_info.out.access_time = name->dos.access_time;
188 info->basic_info.out.write_time = name->dos.write_time;
189 info->basic_info.out.change_time = name->dos.change_time;
190 info->basic_info.out.attrib = name->dos.attrib;
193 case RAW_FILEINFO_STANDARD_INFO:
194 case RAW_FILEINFO_STANDARD_INFORMATION:
195 info->standard_info.out.alloc_size = name->dos.alloc_size;
196 info->standard_info.out.size = name->st.st_size;
197 info->standard_info.out.nlink = name->dos.nlink;
198 info->standard_info.out.delete_pending = 0; /* only for qfileinfo */
199 info->standard_info.out.directory =
200 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0;
203 case RAW_FILEINFO_EA_INFO:
204 case RAW_FILEINFO_EA_INFORMATION:
205 info->ea_info.out.ea_size = name->dos.ea_size;
208 case RAW_FILEINFO_NAME_INFO:
209 case RAW_FILEINFO_NAME_INFORMATION:
210 info->name_info.out.fname.s = name->original_name;
213 case RAW_FILEINFO_ALL_INFO:
214 case RAW_FILEINFO_ALL_INFORMATION:
215 info->all_info.out.create_time = name->dos.create_time;
216 info->all_info.out.access_time = name->dos.access_time;
217 info->all_info.out.write_time = name->dos.write_time;
218 info->all_info.out.change_time = name->dos.change_time;
219 info->all_info.out.attrib = name->dos.attrib;
220 info->all_info.out.alloc_size = name->dos.alloc_size;
221 info->all_info.out.size = name->st.st_size;
222 info->all_info.out.nlink = name->dos.nlink;
223 info->all_info.out.delete_pending = 0; /* only set by qfileinfo */
224 info->all_info.out.directory =
225 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0;
226 info->all_info.out.ea_size = name->dos.ea_size;
227 info->all_info.out.fname.s = name->original_name;
230 case RAW_FILEINFO_ALT_NAME_INFO:
231 case RAW_FILEINFO_ALT_NAME_INFORMATION:
232 info->name_info.out.fname.s = pvfs_short_name(pvfs, name, name);
235 case RAW_FILEINFO_STREAM_INFO:
236 case RAW_FILEINFO_STREAM_INFORMATION:
237 return pvfs_stream_information(pvfs, req, name, fd, &info->stream_info.out);
239 case RAW_FILEINFO_COMPRESSION_INFO:
240 case RAW_FILEINFO_COMPRESSION_INFORMATION:
241 info->compression_info.out.compressed_size = name->st.st_size;
242 info->compression_info.out.format = 0;
243 info->compression_info.out.unit_shift = 0;
244 info->compression_info.out.chunk_shift = 0;
245 info->compression_info.out.cluster_shift = 0;
248 case RAW_FILEINFO_INTERNAL_INFORMATION:
249 info->internal_information.out.file_id = name->dos.file_id;
252 case RAW_FILEINFO_ACCESS_INFORMATION:
253 info->access_information.out.access_flags = 0; /* only set by qfileinfo */
256 case RAW_FILEINFO_POSITION_INFORMATION:
257 info->position_information.out.position = 0; /* only set by qfileinfo */
260 case RAW_FILEINFO_MODE_INFORMATION:
261 info->mode_information.out.mode = 0; /* only set by qfileinfo */
264 case RAW_FILEINFO_ALIGNMENT_INFORMATION:
265 info->alignment_information.out.alignment_requirement = 0;
268 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
269 info->network_open_information.out.create_time = name->dos.create_time;
270 info->network_open_information.out.access_time = name->dos.access_time;
271 info->network_open_information.out.write_time = name->dos.write_time;
272 info->network_open_information.out.change_time = name->dos.change_time;
273 info->network_open_information.out.alloc_size = name->dos.alloc_size;
274 info->network_open_information.out.size = name->st.st_size;
275 info->network_open_information.out.attrib = name->dos.attrib;
278 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
279 info->attribute_tag_information.out.attrib = name->dos.attrib;
280 info->attribute_tag_information.out.reparse_tag = 0;
283 case RAW_FILEINFO_SEC_DESC:
284 return pvfs_acl_query(pvfs, req, name, fd, info);
286 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
287 info->all_info2.out.create_time = name->dos.create_time;
288 info->all_info2.out.access_time = name->dos.access_time;
289 info->all_info2.out.write_time = name->dos.write_time;
290 info->all_info2.out.change_time = name->dos.change_time;
291 info->all_info2.out.attrib = name->dos.attrib;
292 info->all_info2.out.unknown1 = 0;
293 info->all_info2.out.alloc_size = name->dos.alloc_size;
294 info->all_info2.out.size = name->st.st_size;
295 info->all_info2.out.nlink = name->dos.nlink;
296 info->all_info2.out.delete_pending = 0; /* only set by qfileinfo */
297 info->all_info2.out.directory =
298 (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)? 1 : 0;
299 info->all_info2.out.file_id = name->dos.file_id;
300 info->all_info2.out.ea_size = name->dos.ea_size;
301 if (info->all_info2.out.ea_size == 4) {
302 /* SMB2 uses zero for a empty EA set */
303 info->all_info2.out.ea_size = 0;
305 info->all_info2.out.access_mask = 0; /* only set by qfileinfo */
306 info->all_info2.out.position = 0; /* only set by qfileinfo */
307 info->all_info2.out.mode = 0; /* only set by qfileinfo */
308 /* windows wants the full path on disk for this
309 result, but I really don't want to expose that on
310 the wire, so I'll give the path with a share
311 prefix, which is a good approximation */
312 info->all_info2.out.fname.s = talloc_asprintf(req, "\\%s\\%s",
314 name->original_name);
315 NT_STATUS_HAVE_NO_MEMORY(info->all_info2.out.fname.s);
319 return NT_STATUS_INVALID_LEVEL;
323 return info on a pathname
325 NTSTATUS pvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
326 struct ntvfs_request *req, union smb_fileinfo *info)
328 struct pvfs_state *pvfs = ntvfs->private_data;
329 struct pvfs_filename *name;
332 /* resolve the cifs name to a posix name */
333 status = pvfs_resolve_name(pvfs, req, info->generic.in.file.path, PVFS_RESOLVE_STREAMS, &name);
334 if (!NT_STATUS_IS_OK(status)) {
338 if (!name->stream_exists) {
339 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
342 status = pvfs_can_stat(pvfs, req, name);
343 if (!NT_STATUS_IS_OK(status)) {
347 status = pvfs_access_check_simple(pvfs, req, name,
348 pvfs_fileinfo_access(info));
349 if (!NT_STATUS_IS_OK(status)) {
353 status = pvfs_map_fileinfo(pvfs, req, name, info, -1);
359 query info on a open file
361 NTSTATUS pvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
362 struct ntvfs_request *req, union smb_fileinfo *info)
364 struct pvfs_state *pvfs = ntvfs->private_data;
366 struct pvfs_file_handle *h;
368 uint32_t access_needed;
370 f = pvfs_find_fd(pvfs, req, info->generic.in.file.ntvfs);
372 return NT_STATUS_INVALID_HANDLE;
376 access_needed = pvfs_fileinfo_access(info);
377 if ((f->access_mask & access_needed) != access_needed) {
378 return NT_STATUS_ACCESS_DENIED;
381 /* update the file information */
382 status = pvfs_resolve_name_handle(pvfs, h);
383 if (!NT_STATUS_IS_OK(status)) {
387 status = pvfs_map_fileinfo(pvfs, req, h->name, info, h->fd);
389 /* a qfileinfo can fill in a bit more info than a qpathinfo -
390 now modify the levels that need to be fixed up */
391 switch (info->generic.level) {
392 case RAW_FILEINFO_STANDARD_INFO:
393 case RAW_FILEINFO_STANDARD_INFORMATION:
394 if (pvfs_delete_on_close_set(pvfs, h)) {
395 info->standard_info.out.delete_pending = 1;
396 info->standard_info.out.nlink--;
400 case RAW_FILEINFO_ALL_INFO:
401 case RAW_FILEINFO_ALL_INFORMATION:
402 if (pvfs_delete_on_close_set(pvfs, h)) {
403 info->all_info.out.delete_pending = 1;
404 info->all_info.out.nlink--;
408 case RAW_FILEINFO_POSITION_INFORMATION:
409 info->position_information.out.position = h->position;
412 case RAW_FILEINFO_ACCESS_INFORMATION:
413 info->access_information.out.access_flags = f->access_mask;
416 case RAW_FILEINFO_MODE_INFORMATION:
417 info->mode_information.out.mode = h->mode;
420 case RAW_FILEINFO_SMB2_ALL_INFORMATION:
421 if (pvfs_delete_on_close_set(pvfs, h)) {
422 info->all_info2.out.delete_pending = 1;
423 info->all_info2.out.nlink--;
425 info->all_info2.out.position = h->position;
426 info->all_info2.out.access_mask = f->access_mask;
427 info->all_info2.out.mode = h->mode;