r3574: the RAW-OPEN test changes broke a couple of the other tests. This
[ira/wip.git] / source4 / ntvfs / posix / pvfs_rename.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - rename
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 "includes.h"
24 #include "vfs_posix.h"
25
26 /*
27   rename a set of files
28 */
29 NTSTATUS pvfs_rename(struct ntvfs_module_context *ntvfs,
30                      struct smbsrv_request *req, union smb_rename *ren)
31 {
32         struct pvfs_state *pvfs = ntvfs->private_data;
33         NTSTATUS status;
34         struct pvfs_filename *name1, *name2;
35
36         if (ren->generic.level != RAW_RENAME_RENAME) {
37                 return NT_STATUS_INVALID_LEVEL;
38         }
39
40         /* resolve the cifs name to a posix name */
41         status = pvfs_resolve_name(pvfs, req, ren->rename.in.pattern1, 0, &name1);
42         if (!NT_STATUS_IS_OK(status)) {
43                 return status;
44         }
45
46         status = pvfs_resolve_name(pvfs, req, ren->rename.in.pattern2, 0, &name2);
47         if (!NT_STATUS_IS_OK(status)) {
48                 return status;
49         }
50
51         if (name1->has_wildcard || name2->has_wildcard) {
52                 DEBUG(3,("Rejecting wildcard rename '%s' -> '%s'\n", 
53                          ren->rename.in.pattern1, ren->rename.in.pattern2));
54                 return NT_STATUS_NOT_SUPPORTED;
55         }
56
57         if (!name1->exists) {
58                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
59         }
60
61         if (name2->exists) {
62                 return NT_STATUS_OBJECT_NAME_COLLISION;
63         }
64
65         status = pvfs_can_rename(pvfs, name1);
66         if (!NT_STATUS_IS_OK(status)) {
67                 return status;
68         }
69
70         if (rename(name1->full_name, name2->full_name) == -1) {
71                 return pvfs_map_errno(pvfs, errno);
72         }
73         
74         return NT_STATUS_OK;
75 }