r3153: pvfs now passes the first 9 of the BASE-DELETE tests
[bbaumbach/samba-autobuild/.git] / source4 / ntvfs / posix / pvfs_setfileinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - setfileinfo
5
6    Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "include/includes.h"
24 #include "vfs_posix.h"
25
26 /*
27   set info on a open file
28 */
29 NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
30                           struct smbsrv_request *req, 
31                           union smb_setfileinfo *info)
32 {
33         struct pvfs_state *pvfs = ntvfs->private_data;
34         struct utimbuf unix_times;
35         struct pvfs_file *f;
36         uint32_t create_options;
37
38         f = pvfs_find_fd(pvfs, req, info->generic.file.fnum);
39         if (!f) {
40                 return NT_STATUS_INVALID_HANDLE;
41         }
42
43         switch (info->generic.level) {
44         case RAW_SFILEINFO_END_OF_FILE_INFO:
45         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
46                 if (ftruncate(f->fd,
47                               info->end_of_file_info.in.size) == -1) {
48                         return pvfs_map_errno(pvfs, errno);
49                 }
50                 break;
51         case RAW_SFILEINFO_SETATTRE:
52                 unix_times.actime = info->setattre.in.access_time;
53                 unix_times.modtime = info->setattre.in.write_time;
54         
55                 if (unix_times.actime == 0 && unix_times.modtime == 0) {
56                         break;
57                 } 
58
59                 /* set modify time = to access time if modify time was 0 */
60                 if (unix_times.actime != 0 && unix_times.modtime == 0) {
61                         unix_times.modtime = unix_times.actime;
62                 }
63
64                 /* Set the date on this file */
65                 if (utime(f->name->full_name, &unix_times) == -1) {
66                         return NT_STATUS_ACCESS_DENIED;
67                 }
68                 break;
69         case RAW_SFILEINFO_DISPOSITION_INFO:
70                 if (!(f->access_mask & STD_RIGHT_DELETE_ACCESS)) {
71                         return NT_STATUS_ACCESS_DENIED;
72                 }
73                 create_options = f->create_options;
74                 if (info->disposition_info.in.delete_on_close) {
75                         create_options |= NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
76                 } else {
77                         create_options &= ~NTCREATEX_OPTIONS_DELETE_ON_CLOSE;
78                 }
79                 return pvfs_change_create_options(pvfs, req, f, create_options);
80         }
81
82         return NT_STATUS_OK;
83 }