Add missing recvfile_bytes element - noticed by Kukks.
[Samba/nascimento.git] / source3 / modules / vfs_catia.c
blob1f5a0163bccfb4d57610719feb334cd6bc1694b8
1 /*
2 * Catia VFS module
4 * Implement a fixed mapping of forbidden NT characters in filenames that are
5 * used a lot by the CAD package Catia.
7 * Yes, this a BAD BAD UGLY INCOMPLETE hack, but it helps quite some people
8 * out there. Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden
9 * under Windows...
11 * Copyright (C) Volker Lendecke, 2005
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #include "includes.h"
30 static void catia_string_replace(char *s, unsigned char oldc, unsigned
31 char newc)
33 static smb_ucs2_t tmpbuf[sizeof(pstring)];
34 smb_ucs2_t *ptr = tmpbuf;
35 smb_ucs2_t old = oldc;
37 push_ucs2(NULL, tmpbuf, s, sizeof(tmpbuf), STR_TERMINATE);
39 for (;*ptr;ptr++)
40 if (*ptr==old) *ptr=newc;
42 pull_ucs2(NULL, s, tmpbuf, sizeof(pstring), sizeof(tmpbuf), STR_TERMINATE);
45 static void from_unix(char *s)
47 catia_string_replace(s, '\x22', '\xa8');
48 catia_string_replace(s, '\x2a', '\xa4');
49 catia_string_replace(s, '\x2f', '\xf8');
50 catia_string_replace(s, '\x3a', '\xf7');
51 catia_string_replace(s, '\x3c', '\xab');
52 catia_string_replace(s, '\x3e', '\xbb');
53 catia_string_replace(s, '\x3f', '\xbf');
54 catia_string_replace(s, '\x5c', '\xff');
55 catia_string_replace(s, '\x7c', '\xa6');
56 catia_string_replace(s, ' ', '\xb1');
59 static void to_unix(char *s)
61 catia_string_replace(s, '\xa8', '\x22');
62 catia_string_replace(s, '\xa4', '\x2a');
63 catia_string_replace(s, '\xf8', '\x2f');
64 catia_string_replace(s, '\xf7', '\x3a');
65 catia_string_replace(s, '\xab', '\x3c');
66 catia_string_replace(s, '\xbb', '\x3e');
67 catia_string_replace(s, '\xbf', '\x3f');
68 catia_string_replace(s, '\xff', '\x5c');
69 catia_string_replace(s, '\xa6', '\x7c');
70 catia_string_replace(s, '\xb1', ' ');
73 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
74 const char *fname, const char *mask, uint32 attr)
76 pstring name;
77 pstrcpy(name, fname);
78 to_unix(name);
80 return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr);
83 static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle,
84 SMB_STRUCT_DIR *dirp)
86 SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, dirp);
88 if (result == NULL)
89 return result;
91 from_unix(result->d_name);
92 return result;
95 static int catia_open(vfs_handle_struct *handle,
96 const char *fname, files_struct *fsp, int flags, mode_t mode)
98 pstring name;
100 pstrcpy(name, fname);
101 to_unix(name);
103 return SMB_VFS_NEXT_OPEN(handle, name, fsp, flags, mode);
106 static int catia_rename(vfs_handle_struct *handle,
107 const char *oldname, const char *newname)
109 pstring oname, nname;
111 pstrcpy(oname, oldname);
112 to_unix(oname);
113 pstrcpy(nname, newname);
114 to_unix(nname);
116 DEBUG(10, ("converted old name: %s\n", oname));
117 DEBUG(10, ("converted new name: %s\n", nname));
119 return SMB_VFS_NEXT_RENAME(handle, oname, nname);
122 static int catia_stat(vfs_handle_struct *handle,
123 const char *fname, SMB_STRUCT_STAT *sbuf)
125 pstring name;
126 pstrcpy(name, fname);
127 to_unix(name);
129 return SMB_VFS_NEXT_STAT(handle, name, sbuf);
132 static int catia_lstat(vfs_handle_struct *handle,
133 const char *path, SMB_STRUCT_STAT *sbuf)
135 pstring name;
136 pstrcpy(name, path);
137 to_unix(name);
139 return SMB_VFS_NEXT_LSTAT(handle, name, sbuf);
142 static int catia_unlink(vfs_handle_struct *handle, const char *path)
144 pstring name;
145 pstrcpy(name, path);
146 to_unix(name);
148 return SMB_VFS_NEXT_UNLINK(handle, name);
151 static int catia_chmod(vfs_handle_struct *handle,
152 const char *path, mode_t mode)
154 pstring name;
155 pstrcpy(name, path);
156 to_unix(name);
158 return SMB_VFS_NEXT_CHMOD(handle, name, mode);
161 static int catia_chown(vfs_handle_struct *handle,
162 const char *path, uid_t uid, gid_t gid)
164 pstring name;
165 pstrcpy(name, path);
166 to_unix(name);
168 return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
171 static int catia_lchown(vfs_handle_struct *handle,
172 const char *path, uid_t uid, gid_t gid)
174 pstring name;
175 pstrcpy(name, path);
176 to_unix(name);
178 return SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
181 static int catia_chdir(vfs_handle_struct *handle,
182 const char *path)
184 pstring name;
185 pstrcpy(name, path);
186 to_unix(name);
188 return SMB_VFS_NEXT_CHDIR(handle, name);
191 static char *catia_getwd(vfs_handle_struct *handle, char *buf)
193 return SMB_VFS_NEXT_GETWD(handle, buf);
196 static int catia_ntimes(vfs_handle_struct *handle,
197 const char *path, const struct timespec ts[2])
199 return SMB_VFS_NEXT_NTIMES(handle, path, ts);
202 static bool catia_symlink(vfs_handle_struct *handle,
203 const char *oldpath, const char *newpath)
205 return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
208 static bool catia_readlink(vfs_handle_struct *handle,
209 const char *path, char *buf, size_t bufsiz)
211 return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
214 static int catia_link(vfs_handle_struct *handle,
215 const char *oldpath, const char *newpath)
217 return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
220 static int catia_mknod(vfs_handle_struct *handle,
221 const char *path, mode_t mode, SMB_DEV_T dev)
223 return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
226 static char *catia_realpath(vfs_handle_struct *handle,
227 const char *path, char *resolved_path)
229 return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
232 static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
233 const char *name, uint32 security_info,
234 struct security_descriptor **ppdesc)
236 return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info,
237 ppdesc);
240 static NTSTATUS catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
241 const char *name, uint32 security_info_sent,
242 struct security_descriptor *psd)
244 return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
245 psd);
248 static int catia_chmod_acl(vfs_handle_struct *handle,
249 const char *name, mode_t mode)
251 /* If the underlying VFS doesn't have ACL support... */
252 if (!handle->vfs_next.ops.chmod_acl) {
253 errno = ENOSYS;
254 return -1;
256 return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
259 /* VFS operations structure */
261 static vfs_op_tuple catia_op_tuples[] = {
263 /* Directory operations */
265 {SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR,
266 SMB_VFS_LAYER_TRANSPARENT},
267 {SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR,
268 SMB_VFS_LAYER_TRANSPARENT},
270 /* File operations */
272 {SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN,
273 SMB_VFS_LAYER_TRANSPARENT},
274 {SMB_VFS_OP(catia_rename), SMB_VFS_OP_RENAME,
275 SMB_VFS_LAYER_TRANSPARENT},
276 {SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT,
277 SMB_VFS_LAYER_TRANSPARENT},
278 {SMB_VFS_OP(catia_lstat), SMB_VFS_OP_LSTAT,
279 SMB_VFS_LAYER_TRANSPARENT},
280 {SMB_VFS_OP(catia_unlink), SMB_VFS_OP_UNLINK,
281 SMB_VFS_LAYER_TRANSPARENT},
282 {SMB_VFS_OP(catia_chmod), SMB_VFS_OP_CHMOD,
283 SMB_VFS_LAYER_TRANSPARENT},
284 {SMB_VFS_OP(catia_chown), SMB_VFS_OP_CHOWN,
285 SMB_VFS_LAYER_TRANSPARENT},
286 {SMB_VFS_OP(catia_lchown), SMB_VFS_OP_LCHOWN,
287 SMB_VFS_LAYER_TRANSPARENT},
288 {SMB_VFS_OP(catia_chdir), SMB_VFS_OP_CHDIR,
289 SMB_VFS_LAYER_TRANSPARENT},
290 {SMB_VFS_OP(catia_getwd), SMB_VFS_OP_GETWD,
291 SMB_VFS_LAYER_TRANSPARENT},
292 {SMB_VFS_OP(catia_ntimes), SMB_VFS_OP_NTIMES,
293 SMB_VFS_LAYER_TRANSPARENT},
294 {SMB_VFS_OP(catia_symlink), SMB_VFS_OP_SYMLINK,
295 SMB_VFS_LAYER_TRANSPARENT},
296 {SMB_VFS_OP(catia_readlink), SMB_VFS_OP_READLINK,
297 SMB_VFS_LAYER_TRANSPARENT},
298 {SMB_VFS_OP(catia_link), SMB_VFS_OP_LINK,
299 SMB_VFS_LAYER_TRANSPARENT},
300 {SMB_VFS_OP(catia_mknod), SMB_VFS_OP_MKNOD,
301 SMB_VFS_LAYER_TRANSPARENT},
302 {SMB_VFS_OP(catia_realpath), SMB_VFS_OP_REALPATH,
303 SMB_VFS_LAYER_TRANSPARENT},
305 /* NT File ACL operations */
307 {SMB_VFS_OP(catia_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
308 SMB_VFS_LAYER_TRANSPARENT},
309 {SMB_VFS_OP(catia_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
310 SMB_VFS_LAYER_TRANSPARENT},
312 /* POSIX ACL operations */
314 {SMB_VFS_OP(catia_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
315 SMB_VFS_LAYER_TRANSPARENT},
318 {NULL, SMB_VFS_OP_NOOP,
319 SMB_VFS_LAYER_NOOP}
322 NTSTATUS vfs_catia_init(void);
323 NTSTATUS vfs_catia_init(void)
325 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
326 catia_op_tuples);