1 | /*
|
---|
2 | * Catia VFS module
|
---|
3 | *
|
---|
4 | * Implement a fixed mapping of forbidden NT characters in filenames that are
|
---|
5 | * used a lot by the CAD package Catia.
|
---|
6 | *
|
---|
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...
|
---|
10 | *
|
---|
11 | * Copyright (C) Volker Lendecke, 2005
|
---|
12 | *
|
---|
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.
|
---|
17 | *
|
---|
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.
|
---|
22 | *
|
---|
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/>.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | #include "includes.h"
|
---|
29 |
|
---|
30 | static char *catia_string_replace(TALLOC_CTX *ctx,
|
---|
31 | const char *s,
|
---|
32 | unsigned char oldc,
|
---|
33 | unsigned char newc)
|
---|
34 | {
|
---|
35 | smb_ucs2_t *tmpbuf = NULL;
|
---|
36 | smb_ucs2_t *ptr = NULL;
|
---|
37 | smb_ucs2_t old = oldc;
|
---|
38 | char *ret = NULL;
|
---|
39 |
|
---|
40 | if (!s) {
|
---|
41 | return NULL;
|
---|
42 | }
|
---|
43 |
|
---|
44 | if (push_ucs2_talloc(ctx, &tmpbuf, s) == -1) {
|
---|
45 | return NULL;
|
---|
46 | }
|
---|
47 |
|
---|
48 | ptr = tmpbuf;
|
---|
49 |
|
---|
50 | for (;*ptr;ptr++) {
|
---|
51 | if (*ptr==old) {
|
---|
52 | *ptr=newc;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (pull_ucs2_talloc(ctx, &ret, tmpbuf) == -1) {
|
---|
57 | TALLOC_FREE(tmpbuf);
|
---|
58 | return NULL;
|
---|
59 | }
|
---|
60 | TALLOC_FREE(tmpbuf);
|
---|
61 | return ret;
|
---|
62 | }
|
---|
63 |
|
---|
64 | static char *from_unix(TALLOC_CTX *ctx, const char *s)
|
---|
65 | {
|
---|
66 | char *ret = catia_string_replace(ctx, s, '\x22', '\xa8');
|
---|
67 | ret = catia_string_replace(ctx, ret, '\x2a', '\xa4');
|
---|
68 | ret = catia_string_replace(ctx, ret, '\x2f', '\xf8');
|
---|
69 | ret = catia_string_replace(ctx, ret, '\x3a', '\xf7');
|
---|
70 | ret = catia_string_replace(ctx, ret, '\x3c', '\xab');
|
---|
71 | ret = catia_string_replace(ctx, ret, '\x3e', '\xbb');
|
---|
72 | ret = catia_string_replace(ctx, ret, '\x3f', '\xbf');
|
---|
73 | ret = catia_string_replace(ctx, ret, '\x5c', '\xff');
|
---|
74 | ret = catia_string_replace(ctx, ret, '\x7c', '\xa6');
|
---|
75 | return catia_string_replace(ctx, ret, ' ', '\xb1');
|
---|
76 | }
|
---|
77 |
|
---|
78 | static char *to_unix(TALLOC_CTX *ctx, const char *s)
|
---|
79 | {
|
---|
80 | char *ret = catia_string_replace(ctx, s, '\xa8', '\x22');
|
---|
81 | ret = catia_string_replace(ctx, ret, '\xa4', '\x2a');
|
---|
82 | ret = catia_string_replace(ctx, ret, '\xf8', '\x2f');
|
---|
83 | ret = catia_string_replace(ctx, ret, '\xf7', '\x3a');
|
---|
84 | ret = catia_string_replace(ctx, ret, '\xab', '\x3c');
|
---|
85 | ret = catia_string_replace(ctx, ret, '\xbb', '\x3e');
|
---|
86 | ret = catia_string_replace(ctx, ret, '\xbf', '\x3f');
|
---|
87 | ret = catia_string_replace(ctx, ret, '\xff', '\x5c');
|
---|
88 | ret = catia_string_replace(ctx, ret, '\xa6', '\x7c');
|
---|
89 | return catia_string_replace(ctx, ret, '\xb1', ' ');
|
---|
90 | }
|
---|
91 |
|
---|
92 | static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
|
---|
93 | const char *fname, const char *mask, uint32 attr)
|
---|
94 | {
|
---|
95 | char *name = to_unix(talloc_tos(), fname);
|
---|
96 |
|
---|
97 | if (!name) {
|
---|
98 | errno = ENOMEM;
|
---|
99 | return NULL;
|
---|
100 | }
|
---|
101 | return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr);
|
---|
102 | }
|
---|
103 |
|
---|
104 | static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle,
|
---|
105 | SMB_STRUCT_DIR *dirp)
|
---|
106 | {
|
---|
107 | SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, dirp);
|
---|
108 | SMB_STRUCT_DIRENT *newdirent;
|
---|
109 | char *newname;
|
---|
110 | size_t newnamelen;
|
---|
111 |
|
---|
112 | if (result == NULL) {
|
---|
113 | return result;
|
---|
114 | }
|
---|
115 |
|
---|
116 | newname = from_unix(talloc_tos(), result->d_name);
|
---|
117 | if (!newname) {
|
---|
118 | return NULL;
|
---|
119 | }
|
---|
120 | newnamelen = strlen(newname)+1;
|
---|
121 | newdirent = (SMB_STRUCT_DIRENT *)TALLOC_ARRAY(talloc_tos(),
|
---|
122 | char,
|
---|
123 | sizeof(SMB_STRUCT_DIRENT)+
|
---|
124 | newnamelen);
|
---|
125 | if (!newdirent) {
|
---|
126 | return NULL;
|
---|
127 | }
|
---|
128 | memcpy(newdirent, result, sizeof(SMB_STRUCT_DIRENT));
|
---|
129 | memcpy(&newdirent->d_name, newname, newnamelen);
|
---|
130 | return newdirent;
|
---|
131 | }
|
---|
132 |
|
---|
133 | static int catia_open(vfs_handle_struct *handle,
|
---|
134 | const char *fname,
|
---|
135 | files_struct *fsp,
|
---|
136 | int flags,
|
---|
137 | mode_t mode)
|
---|
138 | {
|
---|
139 | char *name = to_unix(talloc_tos(), fname);
|
---|
140 |
|
---|
141 | if (!name) {
|
---|
142 | errno = ENOMEM;
|
---|
143 | return -1;
|
---|
144 | }
|
---|
145 | return SMB_VFS_NEXT_OPEN(handle, name, fsp, flags, mode);
|
---|
146 | }
|
---|
147 |
|
---|
148 | static int catia_rename(vfs_handle_struct *handle,
|
---|
149 | const char *oldname, const char *newname)
|
---|
150 | {
|
---|
151 | TALLOC_CTX *ctx = talloc_tos();
|
---|
152 | char *oname = to_unix(ctx, oldname);
|
---|
153 | char *nname = to_unix(ctx, newname);
|
---|
154 |
|
---|
155 | if (!oname || !nname) {
|
---|
156 | errno = ENOMEM;
|
---|
157 | return -1;
|
---|
158 | }
|
---|
159 | DEBUG(10, ("converted old name: %s\n", oname));
|
---|
160 | DEBUG(10, ("converted new name: %s\n", nname));
|
---|
161 |
|
---|
162 | return SMB_VFS_NEXT_RENAME(handle, oname, nname);
|
---|
163 | }
|
---|
164 |
|
---|
165 | static int catia_stat(vfs_handle_struct *handle,
|
---|
166 | const char *fname, SMB_STRUCT_STAT *sbuf)
|
---|
167 | {
|
---|
168 | char *name = to_unix(talloc_tos(), fname);
|
---|
169 |
|
---|
170 | if (!name) {
|
---|
171 | errno = ENOMEM;
|
---|
172 | return -1;
|
---|
173 | }
|
---|
174 | return SMB_VFS_NEXT_STAT(handle, name, sbuf);
|
---|
175 | }
|
---|
176 |
|
---|
177 | static int catia_lstat(vfs_handle_struct *handle,
|
---|
178 | const char *path, SMB_STRUCT_STAT *sbuf)
|
---|
179 | {
|
---|
180 | char *name = to_unix(talloc_tos(), path);
|
---|
181 |
|
---|
182 | if (!name) {
|
---|
183 | errno = ENOMEM;
|
---|
184 | return -1;
|
---|
185 | }
|
---|
186 | return SMB_VFS_NEXT_LSTAT(handle, name, sbuf);
|
---|
187 | }
|
---|
188 |
|
---|
189 | static int catia_unlink(vfs_handle_struct *handle, const char *path)
|
---|
190 | {
|
---|
191 | char *name = to_unix(talloc_tos(), path);
|
---|
192 |
|
---|
193 | if (!name) {
|
---|
194 | errno = ENOMEM;
|
---|
195 | return -1;
|
---|
196 | }
|
---|
197 | return SMB_VFS_NEXT_UNLINK(handle, name);
|
---|
198 | }
|
---|
199 |
|
---|
200 | static int catia_chmod(vfs_handle_struct *handle,
|
---|
201 | const char *path, mode_t mode)
|
---|
202 | {
|
---|
203 | char *name = to_unix(talloc_tos(), path);
|
---|
204 |
|
---|
205 | if (!name) {
|
---|
206 | errno = ENOMEM;
|
---|
207 | return -1;
|
---|
208 | }
|
---|
209 | return SMB_VFS_NEXT_CHMOD(handle, name, mode);
|
---|
210 | }
|
---|
211 |
|
---|
212 | static int catia_chown(vfs_handle_struct *handle,
|
---|
213 | const char *path, uid_t uid, gid_t gid)
|
---|
214 | {
|
---|
215 | char *name = to_unix(talloc_tos(), path);
|
---|
216 |
|
---|
217 | if (!name) {
|
---|
218 | errno = ENOMEM;
|
---|
219 | return -1;
|
---|
220 | }
|
---|
221 | return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
|
---|
222 | }
|
---|
223 |
|
---|
224 | static int catia_lchown(vfs_handle_struct *handle,
|
---|
225 | const char *path, uid_t uid, gid_t gid)
|
---|
226 | {
|
---|
227 | char *name = to_unix(talloc_tos(), path);
|
---|
228 |
|
---|
229 | if (!name) {
|
---|
230 | errno = ENOMEM;
|
---|
231 | return -1;
|
---|
232 | }
|
---|
233 | return SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
|
---|
234 | }
|
---|
235 |
|
---|
236 | static int catia_chdir(vfs_handle_struct *handle,
|
---|
237 | const char *path)
|
---|
238 | {
|
---|
239 | char *name = to_unix(talloc_tos(), path);
|
---|
240 |
|
---|
241 | if (!name) {
|
---|
242 | errno = ENOMEM;
|
---|
243 | return -1;
|
---|
244 | }
|
---|
245 | return SMB_VFS_NEXT_CHDIR(handle, name);
|
---|
246 | }
|
---|
247 |
|
---|
248 | static char *catia_getwd(vfs_handle_struct *handle, char *buf)
|
---|
249 | {
|
---|
250 | return SMB_VFS_NEXT_GETWD(handle, buf);
|
---|
251 | }
|
---|
252 |
|
---|
253 | static int catia_ntimes(vfs_handle_struct *handle,
|
---|
254 | const char *path, const struct timespec ts[2])
|
---|
255 | {
|
---|
256 | return SMB_VFS_NEXT_NTIMES(handle, path, ts);
|
---|
257 | }
|
---|
258 |
|
---|
259 | static bool catia_symlink(vfs_handle_struct *handle,
|
---|
260 | const char *oldpath, const char *newpath)
|
---|
261 | {
|
---|
262 | return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
|
---|
263 | }
|
---|
264 |
|
---|
265 | static bool catia_readlink(vfs_handle_struct *handle,
|
---|
266 | const char *path, char *buf, size_t bufsiz)
|
---|
267 | {
|
---|
268 | return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
|
---|
269 | }
|
---|
270 |
|
---|
271 | static int catia_link(vfs_handle_struct *handle,
|
---|
272 | const char *oldpath, const char *newpath)
|
---|
273 | {
|
---|
274 | return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
|
---|
275 | }
|
---|
276 |
|
---|
277 | static int catia_mknod(vfs_handle_struct *handle,
|
---|
278 | const char *path, mode_t mode, SMB_DEV_T dev)
|
---|
279 | {
|
---|
280 | return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
|
---|
281 | }
|
---|
282 |
|
---|
283 | static char *catia_realpath(vfs_handle_struct *handle,
|
---|
284 | const char *path, char *resolved_path)
|
---|
285 | {
|
---|
286 | return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
|
---|
287 | }
|
---|
288 |
|
---|
289 | static NTSTATUS catia_get_nt_acl(vfs_handle_struct *handle,
|
---|
290 | const char *name, uint32 security_info,
|
---|
291 | struct security_descriptor **ppdesc)
|
---|
292 | {
|
---|
293 | return SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info, ppdesc);
|
---|
294 | }
|
---|
295 |
|
---|
296 | static NTSTATUS catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
|
---|
297 | const char *name, uint32 security_info_sent,
|
---|
298 | struct security_descriptor *psd)
|
---|
299 | {
|
---|
300 | return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
|
---|
301 | psd);
|
---|
302 | }
|
---|
303 |
|
---|
304 | static int catia_chmod_acl(vfs_handle_struct *handle,
|
---|
305 | const char *name, mode_t mode)
|
---|
306 | {
|
---|
307 | /* If the underlying VFS doesn't have ACL support... */
|
---|
308 | if (!handle->vfs_next.ops.chmod_acl) {
|
---|
309 | errno = ENOSYS;
|
---|
310 | return -1;
|
---|
311 | }
|
---|
312 | return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
|
---|
313 | }
|
---|
314 |
|
---|
315 | /* VFS operations structure */
|
---|
316 |
|
---|
317 | static vfs_op_tuple catia_op_tuples[] = {
|
---|
318 |
|
---|
319 | /* Directory operations */
|
---|
320 |
|
---|
321 | {SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR,
|
---|
322 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
323 | {SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR,
|
---|
324 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
325 |
|
---|
326 | /* File operations */
|
---|
327 |
|
---|
328 | {SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN,
|
---|
329 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
330 | {SMB_VFS_OP(catia_rename), SMB_VFS_OP_RENAME,
|
---|
331 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
332 | {SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT,
|
---|
333 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
334 | {SMB_VFS_OP(catia_lstat), SMB_VFS_OP_LSTAT,
|
---|
335 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
336 | {SMB_VFS_OP(catia_unlink), SMB_VFS_OP_UNLINK,
|
---|
337 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
338 | {SMB_VFS_OP(catia_chmod), SMB_VFS_OP_CHMOD,
|
---|
339 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
340 | {SMB_VFS_OP(catia_chown), SMB_VFS_OP_CHOWN,
|
---|
341 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
342 | {SMB_VFS_OP(catia_lchown), SMB_VFS_OP_LCHOWN,
|
---|
343 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
344 | {SMB_VFS_OP(catia_chdir), SMB_VFS_OP_CHDIR,
|
---|
345 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
346 | {SMB_VFS_OP(catia_getwd), SMB_VFS_OP_GETWD,
|
---|
347 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
348 | {SMB_VFS_OP(catia_ntimes), SMB_VFS_OP_NTIMES,
|
---|
349 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
350 | {SMB_VFS_OP(catia_symlink), SMB_VFS_OP_SYMLINK,
|
---|
351 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
352 | {SMB_VFS_OP(catia_readlink), SMB_VFS_OP_READLINK,
|
---|
353 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
354 | {SMB_VFS_OP(catia_link), SMB_VFS_OP_LINK,
|
---|
355 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
356 | {SMB_VFS_OP(catia_mknod), SMB_VFS_OP_MKNOD,
|
---|
357 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
358 | {SMB_VFS_OP(catia_realpath), SMB_VFS_OP_REALPATH,
|
---|
359 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
360 |
|
---|
361 | /* NT File ACL operations */
|
---|
362 |
|
---|
363 | {SMB_VFS_OP(catia_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
|
---|
364 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
365 | {SMB_VFS_OP(catia_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
|
---|
366 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
367 |
|
---|
368 | /* POSIX ACL operations */
|
---|
369 |
|
---|
370 | {SMB_VFS_OP(catia_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
|
---|
371 | SMB_VFS_LAYER_TRANSPARENT},
|
---|
372 |
|
---|
373 |
|
---|
374 | {NULL, SMB_VFS_OP_NOOP,
|
---|
375 | SMB_VFS_LAYER_NOOP}
|
---|
376 | };
|
---|
377 |
|
---|
378 | NTSTATUS vfs_catia_init(void);
|
---|
379 | NTSTATUS vfs_catia_init(void)
|
---|
380 | {
|
---|
381 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
|
---|
382 | catia_op_tuples);
|
---|
383 | }
|
---|