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
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 2 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, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 static void catia_string_replace(char *s, unsigned char oldc, unsigned
34 static smb_ucs2_t tmpbuf[sizeof(pstring)];
35 smb_ucs2_t *ptr = tmpbuf;
36 smb_ucs2_t old = oldc;
38 push_ucs2(NULL, tmpbuf, s, sizeof(tmpbuf), STR_TERMINATE);
41 if (*ptr==old) *ptr=newc;
43 pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
46 static void from_unix(char *s)
48 catia_string_replace(s, '\x22', '\xa8');
49 catia_string_replace(s, '\x2a', '\xa4');
50 catia_string_replace(s, '\x2f', '\xf8');
51 catia_string_replace(s, '\x3a', '\xf7');
52 catia_string_replace(s, '\x3c', '\xab');
53 catia_string_replace(s, '\x3e', '\xbb');
54 catia_string_replace(s, '\x3f', '\xbf');
55 catia_string_replace(s, '\x5c', '\xff');
56 catia_string_replace(s, '\x7c', '\xa6');
57 catia_string_replace(s, ' ', '\xb1');
60 static void to_unix(char *s)
62 catia_string_replace(s, '\xa8', '\x22');
63 catia_string_replace(s, '\xa4', '\x2a');
64 catia_string_replace(s, '\xf8', '\x2f');
65 catia_string_replace(s, '\xf7', '\x3a');
66 catia_string_replace(s, '\xab', '\x3c');
67 catia_string_replace(s, '\xbb', '\x3e');
68 catia_string_replace(s, '\xbf', '\x3f');
69 catia_string_replace(s, '\xff', '\x5c');
70 catia_string_replace(s, '\xa6', '\x7c');
71 catia_string_replace(s, '\xb1', ' ');
74 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle, connection_struct
75 *conn, const char *fname, const char *mask, uint32 attr)
81 return SMB_VFS_NEXT_OPENDIR(handle, conn, name, mask, attr);
84 static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle,
85 connection_struct *conn, SMB_STRUCT_DIR *dirp)
87 SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, conn, dirp);
92 from_unix(result->d_name);
96 static int catia_open(vfs_handle_struct *handle, connection_struct *conn,
97 const char *fname, int flags, mode_t mode)
101 pstrcpy(name, fname);
104 return SMB_VFS_NEXT_OPEN(handle, conn, name, flags, mode);
107 static int catia_rename(vfs_handle_struct *handle, connection_struct *conn,
108 const char *oldname, const char *newname)
110 pstring oname, nname;
112 pstrcpy(oname, oldname);
114 pstrcpy(nname, newname);
117 DEBUG(10, ("converted old name: %s\n", oname));
118 DEBUG(10, ("converted new name: %s\n", nname));
120 return SMB_VFS_NEXT_RENAME(handle, conn, oname, nname);
123 static int catia_stat(vfs_handle_struct *handle, connection_struct *conn,
124 const char *fname, SMB_STRUCT_STAT *sbuf)
127 pstrcpy(name, fname);
130 return SMB_VFS_NEXT_STAT(handle, conn, name, sbuf);
133 static int catia_lstat(vfs_handle_struct *handle, connection_struct *conn,
134 const char *path, SMB_STRUCT_STAT *sbuf)
140 return SMB_VFS_NEXT_LSTAT(handle, conn, name, sbuf);
143 static int catia_unlink(vfs_handle_struct *handle, connection_struct *conn,
150 return SMB_VFS_NEXT_UNLINK(handle, conn, name);
153 static int catia_chmod(vfs_handle_struct *handle, connection_struct *conn,
154 const char *path, mode_t mode)
160 return SMB_VFS_NEXT_CHMOD(handle, conn, name, mode);
163 static int catia_chown(vfs_handle_struct *handle, connection_struct *conn,
164 const char *path, uid_t uid, gid_t gid)
170 return SMB_VFS_NEXT_CHOWN(handle, conn, name, uid, gid);
173 static int catia_chdir(vfs_handle_struct *handle, connection_struct *conn,
180 return SMB_VFS_NEXT_CHDIR(handle, conn, name);
183 static char *catia_getwd(vfs_handle_struct *handle, connection_struct *conn,
186 return SMB_VFS_NEXT_GETWD(handle, conn, buf);
189 static int catia_utime(vfs_handle_struct *handle, connection_struct *conn,
190 const char *path, struct utimbuf *times)
192 return SMB_VFS_NEXT_UTIME(handle, conn, path, times);
195 static BOOL catia_symlink(vfs_handle_struct *handle, connection_struct *conn,
196 const char *oldpath, const char *newpath)
198 return SMB_VFS_NEXT_SYMLINK(handle, conn, oldpath, newpath);
201 static BOOL catia_readlink(vfs_handle_struct *handle, connection_struct *conn,
202 const char *path, char *buf, size_t bufsiz)
204 return SMB_VFS_NEXT_READLINK(handle, conn, path, buf, bufsiz);
207 static int catia_link(vfs_handle_struct *handle, connection_struct *conn,
208 const char *oldpath, const char *newpath)
210 return SMB_VFS_NEXT_LINK(handle, conn, oldpath, newpath);
213 static int catia_mknod(vfs_handle_struct *handle, connection_struct *conn,
214 const char *path, mode_t mode, SMB_DEV_T dev)
216 return SMB_VFS_NEXT_MKNOD(handle, conn, path, mode, dev);
219 static char *catia_realpath(vfs_handle_struct *handle, connection_struct *conn,
220 const char *path, char *resolved_path)
222 return SMB_VFS_NEXT_REALPATH(handle, conn, path, resolved_path);
225 static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
226 const char *name, uint32 security_info,
227 struct security_descriptor_info **ppdesc)
229 return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info,
233 static BOOL catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
234 const char *name, uint32 security_info_sent,
235 struct security_descriptor_info *psd)
237 return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
241 static int catia_chmod_acl(vfs_handle_struct *handle, connection_struct *conn,
242 const char *name, mode_t mode)
244 /* If the underlying VFS doesn't have ACL support... */
245 if (!handle->vfs_next.ops.chmod_acl) {
249 return SMB_VFS_NEXT_CHMOD_ACL(handle, conn, name, mode);
252 /* VFS operations structure */
254 static vfs_op_tuple catia_op_tuples[] = {
256 /* Directory operations */
258 {SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR,
259 SMB_VFS_LAYER_TRANSPARENT},
260 {SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR,
261 SMB_VFS_LAYER_TRANSPARENT},
263 /* File operations */
265 {SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN,
266 SMB_VFS_LAYER_TRANSPARENT},
267 {SMB_VFS_OP(catia_rename), SMB_VFS_OP_RENAME,
268 SMB_VFS_LAYER_TRANSPARENT},
269 {SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT,
270 SMB_VFS_LAYER_TRANSPARENT},
271 {SMB_VFS_OP(catia_lstat), SMB_VFS_OP_LSTAT,
272 SMB_VFS_LAYER_TRANSPARENT},
273 {SMB_VFS_OP(catia_unlink), SMB_VFS_OP_UNLINK,
274 SMB_VFS_LAYER_TRANSPARENT},
275 {SMB_VFS_OP(catia_chmod), SMB_VFS_OP_CHMOD,
276 SMB_VFS_LAYER_TRANSPARENT},
277 {SMB_VFS_OP(catia_chown), SMB_VFS_OP_CHOWN,
278 SMB_VFS_LAYER_TRANSPARENT},
279 {SMB_VFS_OP(catia_chdir), SMB_VFS_OP_CHDIR,
280 SMB_VFS_LAYER_TRANSPARENT},
281 {SMB_VFS_OP(catia_getwd), SMB_VFS_OP_GETWD,
282 SMB_VFS_LAYER_TRANSPARENT},
283 {SMB_VFS_OP(catia_utime), SMB_VFS_OP_UTIME,
284 SMB_VFS_LAYER_TRANSPARENT},
285 {SMB_VFS_OP(catia_symlink), SMB_VFS_OP_SYMLINK,
286 SMB_VFS_LAYER_TRANSPARENT},
287 {SMB_VFS_OP(catia_readlink), SMB_VFS_OP_READLINK,
288 SMB_VFS_LAYER_TRANSPARENT},
289 {SMB_VFS_OP(catia_link), SMB_VFS_OP_LINK,
290 SMB_VFS_LAYER_TRANSPARENT},
291 {SMB_VFS_OP(catia_mknod), SMB_VFS_OP_MKNOD,
292 SMB_VFS_LAYER_TRANSPARENT},
293 {SMB_VFS_OP(catia_realpath), SMB_VFS_OP_REALPATH,
294 SMB_VFS_LAYER_TRANSPARENT},
296 /* NT File ACL operations */
298 {SMB_VFS_OP(catia_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
299 SMB_VFS_LAYER_TRANSPARENT},
300 {SMB_VFS_OP(catia_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
301 SMB_VFS_LAYER_TRANSPARENT},
303 /* POSIX ACL operations */
305 {SMB_VFS_OP(catia_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
306 SMB_VFS_LAYER_TRANSPARENT},
309 {NULL, SMB_VFS_OP_NOOP,
313 NTSTATUS init_module(void)
315 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",