r4243: a sniff from kukks showed that the ea_set interface in trans2 setfileinfo...
[samba.git] / source4 / ntvfs / posix / pvfs_mkdir.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - mkdir and rmdir
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   create a directory with EAs
28 */
29 static NTSTATUS pvfs_t2mkdir(struct pvfs_state *pvfs,
30                              struct smbsrv_request *req, union smb_mkdir *md)
31 {
32         NTSTATUS status;
33         struct pvfs_filename *name;
34         mode_t mode;
35
36         /* resolve the cifs name to a posix name */
37         status = pvfs_resolve_name(pvfs, req, md->t2mkdir.in.path, 0, &name);
38         if (!NT_STATUS_IS_OK(status)) {
39                 return status;
40         }
41
42         if (name->exists) {
43                 return NT_STATUS_OBJECT_NAME_COLLISION;
44         }
45
46         mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);
47
48         if (mkdir(name->full_name, mode) == -1) {
49                 return pvfs_map_errno(pvfs, errno);
50         }
51
52         status = pvfs_resolve_name(pvfs, req, md->t2mkdir.in.path, 0, &name);
53         if (!NT_STATUS_IS_OK(status)) {
54                 return status;
55         }
56         if (!name->exists ||
57             !(name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
58                 return NT_STATUS_INTERNAL_ERROR;
59         }
60
61         /* setup any EAs that were asked for */
62         status = pvfs_setfileinfo_ea_set(pvfs, name, -1, 
63                                          md->t2mkdir.in.num_eas,
64                                          md->t2mkdir.in.eas);
65         if (!NT_STATUS_IS_OK(status)) {
66                 rmdir(name->full_name);
67                 return status;
68         }
69
70         return NT_STATUS_OK;
71 }
72
73 /*
74   create a directory
75 */
76 NTSTATUS pvfs_mkdir(struct ntvfs_module_context *ntvfs,
77                     struct smbsrv_request *req, union smb_mkdir *md)
78 {
79         struct pvfs_state *pvfs = ntvfs->private_data;
80         NTSTATUS status;
81         struct pvfs_filename *name;
82         mode_t mode;
83
84         if (md->generic.level == RAW_MKDIR_T2MKDIR) {
85                 return pvfs_t2mkdir(pvfs, req, md);
86         }
87
88         if (md->generic.level != RAW_MKDIR_MKDIR) {
89                 return NT_STATUS_INVALID_LEVEL;
90         }
91
92         /* resolve the cifs name to a posix name */
93         status = pvfs_resolve_name(pvfs, req, md->mkdir.in.path, 0, &name);
94         if (!NT_STATUS_IS_OK(status)) {
95                 return status;
96         }
97
98         if (name->exists) {
99                 return NT_STATUS_OBJECT_NAME_COLLISION;
100         }
101
102         mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);
103
104         if (mkdir(name->full_name, mode) == -1) {
105                 return pvfs_map_errno(pvfs, errno);
106         }
107
108         return NT_STATUS_OK;
109 }
110
111 /*
112   remove a directory
113 */
114 NTSTATUS pvfs_rmdir(struct ntvfs_module_context *ntvfs,
115                     struct smbsrv_request *req, struct smb_rmdir *rd)
116 {
117         struct pvfs_state *pvfs = ntvfs->private_data;
118         NTSTATUS status;
119         struct pvfs_filename *name;
120
121         /* resolve the cifs name to a posix name */
122         status = pvfs_resolve_name(pvfs, req, rd->in.path, 0, &name);
123         if (!NT_STATUS_IS_OK(status)) {
124                 return status;
125         }
126
127         if (!name->exists) {
128                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
129         }
130
131         status = pvfs_xattr_unlink_hook(pvfs, name->full_name);
132         if (!NT_STATUS_IS_OK(status)) {
133                 return status;
134         }
135
136         if (rmdir(name->full_name) == -1) {
137                 return pvfs_map_errno(pvfs, errno);
138         }
139
140         return NT_STATUS_OK;
141 }