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 | * Copyright (C) Aravind Srinivasan, 2009
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or modify
|
---|
15 | * it under the terms of the GNU General Public License as published by
|
---|
16 | * the Free Software Foundation; either version 3 of the License, or
|
---|
17 | * (at your option) any later version.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful,
|
---|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
22 | * GNU General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | #include "includes.h"
|
---|
30 |
|
---|
31 | #define GLOBAL_SNUM 0xFFFFFFF
|
---|
32 | #define MAP_SIZE 0xFF
|
---|
33 | #define MAP_NUM 0x101 /* max unicode charval / MAP_SIZE */
|
---|
34 | #define T_OFFSET(_v_) ((_v_ % MAP_SIZE))
|
---|
35 | #define T_START(_v_) (((_v_ / MAP_SIZE) * MAP_SIZE))
|
---|
36 | #define T_PICK(_v_) ((_v_ / MAP_SIZE))
|
---|
37 |
|
---|
38 | struct char_mappings {
|
---|
39 | smb_ucs2_t entry[MAP_SIZE][2];
|
---|
40 | };
|
---|
41 |
|
---|
42 | struct share_mapping_entry {
|
---|
43 | int snum;
|
---|
44 | struct share_mapping_entry *next;
|
---|
45 | struct char_mappings **mappings;
|
---|
46 | };
|
---|
47 |
|
---|
48 | struct share_mapping_entry *srt_head = NULL;
|
---|
49 |
|
---|
50 | static bool build_table(struct char_mappings **cmaps, int value)
|
---|
51 | {
|
---|
52 | int i;
|
---|
53 | int start = T_START(value);
|
---|
54 |
|
---|
55 | (*cmaps) = talloc_zero(NULL, struct char_mappings);
|
---|
56 |
|
---|
57 | if (!*cmaps)
|
---|
58 | return False;
|
---|
59 |
|
---|
60 | for (i = 0; i < MAP_SIZE;i++) {
|
---|
61 | (*cmaps)->entry[i][vfs_translate_to_unix] = start + i;
|
---|
62 | (*cmaps)->entry[i][vfs_translate_to_windows] = start + i;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return True;
|
---|
66 | }
|
---|
67 |
|
---|
68 | static void set_tables(struct char_mappings **cmaps,
|
---|
69 | long unix_map,
|
---|
70 | long windows_map)
|
---|
71 | {
|
---|
72 | int i;
|
---|
73 |
|
---|
74 | /* set unix -> windows */
|
---|
75 | i = T_OFFSET(unix_map);
|
---|
76 | cmaps[T_PICK(unix_map)]->entry[i][vfs_translate_to_windows] = windows_map;
|
---|
77 |
|
---|
78 | /* set windows -> unix */
|
---|
79 | i = T_OFFSET(windows_map);
|
---|
80 | cmaps[T_PICK(windows_map)]->entry[i][vfs_translate_to_unix] = unix_map;
|
---|
81 | }
|
---|
82 |
|
---|
83 | static bool build_ranges(struct char_mappings **cmaps,
|
---|
84 | long unix_map,
|
---|
85 | long windows_map)
|
---|
86 | {
|
---|
87 |
|
---|
88 | if (!cmaps[T_PICK(unix_map)]) {
|
---|
89 | if (!build_table(&cmaps[T_PICK(unix_map)], unix_map))
|
---|
90 | return False;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if (!cmaps[T_PICK(windows_map)]) {
|
---|
94 | if (!build_table(&cmaps[T_PICK(windows_map)], windows_map))
|
---|
95 | return False;
|
---|
96 | }
|
---|
97 |
|
---|
98 | set_tables(cmaps, unix_map, windows_map);
|
---|
99 |
|
---|
100 | return True;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static struct share_mapping_entry *get_srt(connection_struct *conn,
|
---|
104 | struct share_mapping_entry **global)
|
---|
105 | {
|
---|
106 | struct share_mapping_entry *share;
|
---|
107 |
|
---|
108 | for (share = srt_head; share != NULL; share = share->next) {
|
---|
109 | if (share->snum == GLOBAL_SNUM)
|
---|
110 | (*global) = share;
|
---|
111 |
|
---|
112 | if (share->snum == SNUM(conn))
|
---|
113 | return share;
|
---|
114 | }
|
---|
115 |
|
---|
116 | return share;
|
---|
117 | }
|
---|
118 |
|
---|
119 | static struct share_mapping_entry *add_srt(int snum, const char **mappings)
|
---|
120 | {
|
---|
121 |
|
---|
122 | char *tmp;
|
---|
123 | fstring mapping;
|
---|
124 | int i;
|
---|
125 | long unix_map, windows_map;
|
---|
126 | struct share_mapping_entry *ret = NULL;
|
---|
127 |
|
---|
128 | ret = (struct share_mapping_entry *)
|
---|
129 | TALLOC_ZERO(NULL, sizeof(struct share_mapping_entry) +
|
---|
130 | (mappings ? (MAP_NUM * sizeof(struct char_mappings *)) : 0));
|
---|
131 |
|
---|
132 | if (!ret)
|
---|
133 | return ret;
|
---|
134 |
|
---|
135 | ret->snum = snum;
|
---|
136 |
|
---|
137 | if (mappings) {
|
---|
138 | ret->mappings = (struct char_mappings**) ((unsigned char*) ret +
|
---|
139 | sizeof(struct share_mapping_entry));
|
---|
140 | memset(ret->mappings, 0,
|
---|
141 | MAP_NUM * sizeof(struct char_mappings *));
|
---|
142 | } else {
|
---|
143 | ret->mappings = NULL;
|
---|
144 | return ret;
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * catia mappings are of the form :
|
---|
149 | * UNIX char (in 0xnn hex) : WINDOWS char (in 0xnn hex)
|
---|
150 | *
|
---|
151 | * multiple mappings are comma seperated in smb.conf
|
---|
152 | */
|
---|
153 | for (i=0;mappings[i];i++) {
|
---|
154 | fstrcpy(mapping, mappings[i]);
|
---|
155 | unix_map = strtol(mapping, &tmp, 16);
|
---|
156 | if (unix_map == 0 && errno == EINVAL) {
|
---|
157 | DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
|
---|
158 | continue;
|
---|
159 | }
|
---|
160 | windows_map = strtol(++tmp, NULL, 16);
|
---|
161 | if (windows_map == 0 && errno == EINVAL) {
|
---|
162 | DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
|
---|
163 | continue;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if (!build_ranges(ret->mappings, unix_map, windows_map)) {
|
---|
167 | DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping));
|
---|
168 | continue;
|
---|
169 | }
|
---|
170 | }
|
---|
171 |
|
---|
172 | ret->next = srt_head;
|
---|
173 | srt_head = ret;
|
---|
174 |
|
---|
175 | return ret;
|
---|
176 | }
|
---|
177 |
|
---|
178 | static bool init_mappings(connection_struct *conn,
|
---|
179 | struct share_mapping_entry **selected_out)
|
---|
180 | {
|
---|
181 | const char **mappings = NULL;
|
---|
182 | struct share_mapping_entry *share_level = NULL;
|
---|
183 | struct share_mapping_entry *global = NULL;
|
---|
184 |
|
---|
185 | /* check srt cache */
|
---|
186 | share_level = get_srt(conn, &global);
|
---|
187 | if (share_level) {
|
---|
188 | *selected_out = share_level;
|
---|
189 | return (share_level->mappings != NULL);
|
---|
190 | }
|
---|
191 |
|
---|
192 | /* see if we have a global setting */
|
---|
193 | if (!global) {
|
---|
194 | /* global setting */
|
---|
195 | mappings = lp_parm_string_list(-1, "catia", "mappings", NULL);
|
---|
196 | global = add_srt(GLOBAL_SNUM, mappings);
|
---|
197 | }
|
---|
198 |
|
---|
199 | /* no global setting - what about share level ? */
|
---|
200 | mappings = lp_parm_string_list(SNUM(conn), "catia", "mappings", NULL);
|
---|
201 | share_level = add_srt(SNUM(conn), mappings);
|
---|
202 |
|
---|
203 | if (share_level->mappings) {
|
---|
204 | (*selected_out) = share_level;
|
---|
205 | return True;
|
---|
206 | } else if (global->mappings) {
|
---|
207 | share_level->mappings = global->mappings;
|
---|
208 | (*selected_out) = share_level;
|
---|
209 | return True;
|
---|
210 | }
|
---|
211 |
|
---|
212 | return False;
|
---|
213 | }
|
---|
214 |
|
---|
215 | static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
|
---|
216 | const char *name_in,
|
---|
217 | char **mapped_name,
|
---|
218 | int direction)
|
---|
219 | {
|
---|
220 | static smb_ucs2_t *tmpbuf = NULL;
|
---|
221 | smb_ucs2_t *ptr;
|
---|
222 | struct share_mapping_entry *selected;
|
---|
223 | struct char_mappings *map = NULL;
|
---|
224 | size_t converted_size;
|
---|
225 | TALLOC_CTX *ctx = talloc_tos();
|
---|
226 |
|
---|
227 | if (!init_mappings(conn, &selected)) {
|
---|
228 | /* No mappings found. Just use the old name */
|
---|
229 | *mapped_name = talloc_strdup(NULL, name_in);
|
---|
230 | if (!*mapped_name) {
|
---|
231 | errno = ENOMEM;
|
---|
232 | return NT_STATUS_NO_MEMORY;
|
---|
233 | }
|
---|
234 | return NT_STATUS_OK;
|
---|
235 | }
|
---|
236 |
|
---|
237 | if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
|
---|
238 | &converted_size)) == -1) {
|
---|
239 | return map_nt_error_from_unix(errno);
|
---|
240 | }
|
---|
241 | ptr = tmpbuf;
|
---|
242 | for(;*ptr;ptr++) {
|
---|
243 | if (*ptr == 0)
|
---|
244 | break;
|
---|
245 | map = selected->mappings[T_PICK((*ptr))];
|
---|
246 |
|
---|
247 | /* nothing to do */
|
---|
248 | if (!map)
|
---|
249 | continue;
|
---|
250 |
|
---|
251 | *ptr = map->entry[T_OFFSET((*ptr))][direction];
|
---|
252 | }
|
---|
253 |
|
---|
254 | if ((pull_ucs2_talloc(ctx, mapped_name, tmpbuf,
|
---|
255 | &converted_size)) == -1) {
|
---|
256 | TALLOC_FREE(tmpbuf);
|
---|
257 | return map_nt_error_from_unix(errno);
|
---|
258 | }
|
---|
259 | TALLOC_FREE(tmpbuf);
|
---|
260 | return NT_STATUS_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
|
---|
264 | const char *fname,
|
---|
265 | const char *mask,
|
---|
266 | uint32 attr)
|
---|
267 | {
|
---|
268 | char *name_mapped = NULL;
|
---|
269 | NTSTATUS status;
|
---|
270 | SMB_STRUCT_DIR *ret;
|
---|
271 |
|
---|
272 | status = catia_string_replace_allocate(handle->conn, fname,
|
---|
273 | &name_mapped, vfs_translate_to_unix);
|
---|
274 | if (!NT_STATUS_IS_OK(status)) {
|
---|
275 | errno = map_errno_from_nt_status(status);
|
---|
276 | return NULL;
|
---|
277 | }
|
---|
278 |
|
---|
279 | ret = SMB_VFS_NEXT_OPENDIR(handle, name_mapped, mask, attr);
|
---|
280 | TALLOC_FREE(name_mapped);
|
---|
281 |
|
---|
282 | return ret;
|
---|
283 | }
|
---|
284 |
|
---|
285 | /*
|
---|
286 | * TRANSLATE_NAME call which converts the given name to
|
---|
287 | * "WINDOWS displayable" name
|
---|
288 | */
|
---|
289 | static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
|
---|
290 | const char *orig_name,
|
---|
291 | enum vfs_translate_direction direction,
|
---|
292 | TALLOC_CTX *mem_ctx,
|
---|
293 | char **pmapped_name)
|
---|
294 | {
|
---|
295 | char *name = NULL;
|
---|
296 | char *mapped_name;
|
---|
297 | NTSTATUS ret;
|
---|
298 |
|
---|
299 | /*
|
---|
300 | * Copy the supplied name and free the memory for mapped_name,
|
---|
301 | * already allocated by the caller.
|
---|
302 | * We will be allocating new memory for mapped_name in
|
---|
303 | * catia_string_replace_allocate
|
---|
304 | */
|
---|
305 | name = talloc_strdup(talloc_tos(), orig_name);
|
---|
306 | if (!name) {
|
---|
307 | errno = ENOMEM;
|
---|
308 | return NT_STATUS_NO_MEMORY;
|
---|
309 | }
|
---|
310 | ret = catia_string_replace_allocate(handle->conn, name,
|
---|
311 | &mapped_name, direction);
|
---|
312 |
|
---|
313 | TALLOC_FREE(name);
|
---|
314 | if (!NT_STATUS_IS_OK(ret)) {
|
---|
315 | return ret;
|
---|
316 | }
|
---|
317 |
|
---|
318 | ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
|
---|
319 | mem_ctx, pmapped_name);
|
---|
320 |
|
---|
321 | if (NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
|
---|
322 | *pmapped_name = talloc_move(mem_ctx, &mapped_name);
|
---|
323 | } else {
|
---|
324 | TALLOC_FREE(mapped_name);
|
---|
325 | }
|
---|
326 |
|
---|
327 | return ret;
|
---|
328 | }
|
---|
329 |
|
---|
330 | static int catia_open(vfs_handle_struct *handle,
|
---|
331 | struct smb_filename *smb_fname,
|
---|
332 | files_struct *fsp,
|
---|
333 | int flags,
|
---|
334 | mode_t mode)
|
---|
335 | {
|
---|
336 | char *name_mapped = NULL;
|
---|
337 | char *tmp_base_name;
|
---|
338 | int ret;
|
---|
339 | NTSTATUS status;
|
---|
340 |
|
---|
341 | tmp_base_name = smb_fname->base_name;
|
---|
342 | status = catia_string_replace_allocate(handle->conn,
|
---|
343 | smb_fname->base_name,
|
---|
344 | &name_mapped, vfs_translate_to_unix);
|
---|
345 | if (!NT_STATUS_IS_OK(status)) {
|
---|
346 | errno = map_errno_from_nt_status(status);
|
---|
347 | return -1;
|
---|
348 | }
|
---|
349 |
|
---|
350 | smb_fname->base_name = name_mapped;
|
---|
351 | ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
---|
352 | smb_fname->base_name = tmp_base_name;
|
---|
353 | TALLOC_FREE(name_mapped);
|
---|
354 |
|
---|
355 | return ret;
|
---|
356 | }
|
---|
357 |
|
---|
358 | static int catia_rename(vfs_handle_struct *handle,
|
---|
359 | const struct smb_filename *smb_fname_src,
|
---|
360 | const struct smb_filename *smb_fname_dst)
|
---|
361 | {
|
---|
362 | TALLOC_CTX *ctx = talloc_tos();
|
---|
363 | struct smb_filename *smb_fname_src_tmp = NULL;
|
---|
364 | struct smb_filename *smb_fname_dst_tmp = NULL;
|
---|
365 | char *src_name_mapped = NULL;
|
---|
366 | char *dst_name_mapped = NULL;
|
---|
367 | NTSTATUS status;
|
---|
368 | int ret = -1;
|
---|
369 |
|
---|
370 | status = catia_string_replace_allocate(handle->conn,
|
---|
371 | smb_fname_src->base_name,
|
---|
372 | &src_name_mapped, vfs_translate_to_unix);
|
---|
373 | if (!NT_STATUS_IS_OK(status)) {
|
---|
374 | errno = map_errno_from_nt_status(status);
|
---|
375 | return -1;
|
---|
376 | }
|
---|
377 |
|
---|
378 | status = catia_string_replace_allocate(handle->conn,
|
---|
379 | smb_fname_dst->base_name,
|
---|
380 | &dst_name_mapped, vfs_translate_to_unix);
|
---|
381 | if (!NT_STATUS_IS_OK(status)) {
|
---|
382 | errno = map_errno_from_nt_status(status);
|
---|
383 | return -1;
|
---|
384 | }
|
---|
385 |
|
---|
386 | /* Setup temporary smb_filename structs. */
|
---|
387 | status = copy_smb_filename(ctx, smb_fname_src, &smb_fname_src_tmp);
|
---|
388 |
|
---|
389 | if (!NT_STATUS_IS_OK(status)) {
|
---|
390 | errno = map_errno_from_nt_status(status);
|
---|
391 | goto out;
|
---|
392 | }
|
---|
393 |
|
---|
394 | status = copy_smb_filename(ctx, smb_fname_dst, &smb_fname_dst_tmp);
|
---|
395 | if (!NT_STATUS_IS_OK(status)) {
|
---|
396 | errno = map_errno_from_nt_status(status);
|
---|
397 | goto out;
|
---|
398 | }
|
---|
399 |
|
---|
400 | smb_fname_src_tmp->base_name = src_name_mapped;
|
---|
401 | smb_fname_dst_tmp->base_name = dst_name_mapped;
|
---|
402 | DEBUG(10, ("converted old name: %s\n",
|
---|
403 | smb_fname_str_dbg(smb_fname_src_tmp)));
|
---|
404 | DEBUG(10, ("converted new name: %s\n",
|
---|
405 | smb_fname_str_dbg(smb_fname_dst_tmp)));
|
---|
406 |
|
---|
407 | ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
|
---|
408 | smb_fname_dst_tmp);
|
---|
409 | out:
|
---|
410 | TALLOC_FREE(src_name_mapped);
|
---|
411 | TALLOC_FREE(dst_name_mapped);
|
---|
412 | TALLOC_FREE(smb_fname_src_tmp);
|
---|
413 | TALLOC_FREE(smb_fname_dst_tmp);
|
---|
414 | return ret;
|
---|
415 | }
|
---|
416 |
|
---|
417 | static int catia_stat(vfs_handle_struct *handle,
|
---|
418 | struct smb_filename *smb_fname)
|
---|
419 | {
|
---|
420 | char *name = NULL;
|
---|
421 | char *tmp_base_name;
|
---|
422 | int ret;
|
---|
423 | NTSTATUS status;
|
---|
424 |
|
---|
425 | status = catia_string_replace_allocate(handle->conn,
|
---|
426 | smb_fname->base_name,
|
---|
427 | &name, vfs_translate_to_unix);
|
---|
428 | if (!NT_STATUS_IS_OK(status)) {
|
---|
429 | errno = map_errno_from_nt_status(status);
|
---|
430 | return -1;
|
---|
431 | }
|
---|
432 |
|
---|
433 | tmp_base_name = smb_fname->base_name;
|
---|
434 | smb_fname->base_name = name;
|
---|
435 |
|
---|
436 | ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
|
---|
437 | smb_fname->base_name = tmp_base_name;
|
---|
438 |
|
---|
439 | TALLOC_FREE(name);
|
---|
440 | return ret;
|
---|
441 | }
|
---|
442 |
|
---|
443 | static int catia_lstat(vfs_handle_struct *handle,
|
---|
444 | struct smb_filename *smb_fname)
|
---|
445 | {
|
---|
446 | char *name = NULL;
|
---|
447 | char *tmp_base_name;
|
---|
448 | int ret;
|
---|
449 | NTSTATUS status;
|
---|
450 |
|
---|
451 | status = catia_string_replace_allocate(handle->conn,
|
---|
452 | smb_fname->base_name,
|
---|
453 | &name, vfs_translate_to_unix);
|
---|
454 | if (!NT_STATUS_IS_OK(status)) {
|
---|
455 | errno = map_errno_from_nt_status(status);
|
---|
456 | return -1;
|
---|
457 | }
|
---|
458 |
|
---|
459 | tmp_base_name = smb_fname->base_name;
|
---|
460 | smb_fname->base_name = name;
|
---|
461 |
|
---|
462 | ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
|
---|
463 | smb_fname->base_name = tmp_base_name;
|
---|
464 | TALLOC_FREE(name);
|
---|
465 |
|
---|
466 | return ret;
|
---|
467 | }
|
---|
468 |
|
---|
469 | static int catia_unlink(vfs_handle_struct *handle,
|
---|
470 | const struct smb_filename *smb_fname)
|
---|
471 | {
|
---|
472 | struct smb_filename *smb_fname_tmp = NULL;
|
---|
473 | char *name = NULL;
|
---|
474 | NTSTATUS status;
|
---|
475 | int ret;
|
---|
476 |
|
---|
477 | status = catia_string_replace_allocate(handle->conn,
|
---|
478 | smb_fname->base_name,
|
---|
479 | &name, vfs_translate_to_unix);
|
---|
480 | if (!NT_STATUS_IS_OK(status)) {
|
---|
481 | errno = map_errno_from_nt_status(status);
|
---|
482 | return -1;
|
---|
483 | }
|
---|
484 |
|
---|
485 | /* Setup temporary smb_filename structs. */
|
---|
486 | status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
|
---|
487 | if (!NT_STATUS_IS_OK(status)) {
|
---|
488 | errno = map_errno_from_nt_status(status);
|
---|
489 | return -1;
|
---|
490 | }
|
---|
491 |
|
---|
492 | smb_fname_tmp->base_name = name;
|
---|
493 | ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
|
---|
494 | TALLOC_FREE(smb_fname_tmp);
|
---|
495 | TALLOC_FREE(name);
|
---|
496 |
|
---|
497 | return ret;
|
---|
498 | }
|
---|
499 |
|
---|
500 | static int catia_chown(vfs_handle_struct *handle,
|
---|
501 | const char *path,
|
---|
502 | uid_t uid,
|
---|
503 | gid_t gid)
|
---|
504 | {
|
---|
505 | char *name = NULL;
|
---|
506 | NTSTATUS status;
|
---|
507 | int ret;
|
---|
508 |
|
---|
509 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
510 | &name, vfs_translate_to_unix);
|
---|
511 | if (!NT_STATUS_IS_OK(status)) {
|
---|
512 | errno = map_errno_from_nt_status(status);
|
---|
513 | return -1;
|
---|
514 | }
|
---|
515 |
|
---|
516 | ret = SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
|
---|
517 | TALLOC_FREE(name);
|
---|
518 |
|
---|
519 | return ret;
|
---|
520 | }
|
---|
521 |
|
---|
522 | static int catia_lchown(vfs_handle_struct *handle,
|
---|
523 | const char *path,
|
---|
524 | uid_t uid,
|
---|
525 | gid_t gid)
|
---|
526 | {
|
---|
527 | char *name = NULL;
|
---|
528 | NTSTATUS status;
|
---|
529 | int ret;
|
---|
530 |
|
---|
531 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
532 | &name, vfs_translate_to_unix);
|
---|
533 | if (!NT_STATUS_IS_OK(status)) {
|
---|
534 | errno = map_errno_from_nt_status(status);
|
---|
535 | return -1;
|
---|
536 | }
|
---|
537 |
|
---|
538 | ret = SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
|
---|
539 | TALLOC_FREE(name);
|
---|
540 |
|
---|
541 | return ret;
|
---|
542 | }
|
---|
543 |
|
---|
544 | static int catia_rmdir(vfs_handle_struct *handle,
|
---|
545 | const char *path)
|
---|
546 | {
|
---|
547 | char *name = NULL;
|
---|
548 | NTSTATUS status;
|
---|
549 | int ret;
|
---|
550 |
|
---|
551 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
552 | &name, vfs_translate_to_unix);
|
---|
553 | if (!NT_STATUS_IS_OK(status)) {
|
---|
554 | errno = map_errno_from_nt_status(status);
|
---|
555 | return -1;
|
---|
556 | }
|
---|
557 |
|
---|
558 | ret = SMB_VFS_NEXT_RMDIR(handle, name);
|
---|
559 | TALLOC_FREE(name);
|
---|
560 |
|
---|
561 | return ret;
|
---|
562 | }
|
---|
563 |
|
---|
564 | static int catia_mkdir(vfs_handle_struct *handle,
|
---|
565 | const char *path,
|
---|
566 | mode_t mode)
|
---|
567 | {
|
---|
568 | char *name = NULL;
|
---|
569 | NTSTATUS status;
|
---|
570 | int ret;
|
---|
571 |
|
---|
572 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
573 | &name, vfs_translate_to_unix);
|
---|
574 | if (!NT_STATUS_IS_OK(status)) {
|
---|
575 | errno = map_errno_from_nt_status(status);
|
---|
576 | return -1;
|
---|
577 | }
|
---|
578 |
|
---|
579 | ret = SMB_VFS_NEXT_MKDIR(handle, name, mode);
|
---|
580 | TALLOC_FREE(name);
|
---|
581 |
|
---|
582 | return ret;
|
---|
583 | }
|
---|
584 |
|
---|
585 | static int catia_chdir(vfs_handle_struct *handle,
|
---|
586 | const char *path)
|
---|
587 | {
|
---|
588 | char *name = NULL;
|
---|
589 | NTSTATUS status;
|
---|
590 | int ret;
|
---|
591 |
|
---|
592 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
593 | &name, vfs_translate_to_unix);
|
---|
594 | if (!NT_STATUS_IS_OK(status)) {
|
---|
595 | errno = map_errno_from_nt_status(status);
|
---|
596 | return -1;
|
---|
597 | }
|
---|
598 |
|
---|
599 | ret = SMB_VFS_NEXT_CHDIR(handle, name);
|
---|
600 | TALLOC_FREE(name);
|
---|
601 |
|
---|
602 | return ret;
|
---|
603 | }
|
---|
604 |
|
---|
605 | static int catia_ntimes(vfs_handle_struct *handle,
|
---|
606 | const struct smb_filename *smb_fname,
|
---|
607 | struct smb_file_time *ft)
|
---|
608 | {
|
---|
609 | struct smb_filename *smb_fname_tmp = NULL;
|
---|
610 | char *name = NULL;
|
---|
611 | NTSTATUS status;
|
---|
612 | int ret;
|
---|
613 |
|
---|
614 | status = catia_string_replace_allocate(handle->conn,
|
---|
615 | smb_fname->base_name,
|
---|
616 | &name, vfs_translate_to_unix);
|
---|
617 | if (!NT_STATUS_IS_OK(status)) {
|
---|
618 | errno = map_errno_from_nt_status(status);
|
---|
619 | return -1;
|
---|
620 | }
|
---|
621 |
|
---|
622 | status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
|
---|
623 | if (!NT_STATUS_IS_OK(status)) {
|
---|
624 | errno = map_errno_from_nt_status(status);
|
---|
625 | return -1;
|
---|
626 | }
|
---|
627 |
|
---|
628 | smb_fname_tmp->base_name = name;
|
---|
629 | ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
|
---|
630 | TALLOC_FREE(name);
|
---|
631 | TALLOC_FREE(smb_fname_tmp);
|
---|
632 |
|
---|
633 | return ret;
|
---|
634 | }
|
---|
635 |
|
---|
636 | static char *
|
---|
637 | catia_realpath(vfs_handle_struct *handle, const char *path,
|
---|
638 | char *resolved_path)
|
---|
639 | {
|
---|
640 | char *mapped_name = NULL;
|
---|
641 | NTSTATUS status;
|
---|
642 | char *ret = NULL;
|
---|
643 |
|
---|
644 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
645 | &mapped_name, vfs_translate_to_unix);
|
---|
646 | if (!NT_STATUS_IS_OK(status)) {
|
---|
647 | errno = map_errno_from_nt_status(status);
|
---|
648 | return NULL;
|
---|
649 | }
|
---|
650 |
|
---|
651 | ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name, resolved_path);
|
---|
652 | TALLOC_FREE(mapped_name);
|
---|
653 |
|
---|
654 | return ret;
|
---|
655 | }
|
---|
656 |
|
---|
657 | static int catia_chflags(struct vfs_handle_struct *handle,
|
---|
658 | const char *path, unsigned int flags)
|
---|
659 | {
|
---|
660 | char *mapped_name = NULL;
|
---|
661 | NTSTATUS status;
|
---|
662 | int ret;
|
---|
663 |
|
---|
664 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
665 | &mapped_name, vfs_translate_to_unix);
|
---|
666 | if (!NT_STATUS_IS_OK(status)) {
|
---|
667 | errno = map_errno_from_nt_status(status);
|
---|
668 | return -1;
|
---|
669 | }
|
---|
670 |
|
---|
671 | ret = SMB_VFS_NEXT_CHFLAGS(handle, mapped_name, flags);
|
---|
672 | TALLOC_FREE(mapped_name);
|
---|
673 |
|
---|
674 | return ret;
|
---|
675 | }
|
---|
676 |
|
---|
677 | static NTSTATUS
|
---|
678 | catia_streaminfo(struct vfs_handle_struct *handle,
|
---|
679 | struct files_struct *fsp,
|
---|
680 | const char *path,
|
---|
681 | TALLOC_CTX *mem_ctx,
|
---|
682 | unsigned int *num_streams,
|
---|
683 | struct stream_struct **streams)
|
---|
684 | {
|
---|
685 | char *mapped_name = NULL;
|
---|
686 | NTSTATUS status;
|
---|
687 |
|
---|
688 | status = catia_string_replace_allocate(handle->conn, path,
|
---|
689 | &mapped_name, vfs_translate_to_unix);
|
---|
690 | if (!NT_STATUS_IS_OK(status)) {
|
---|
691 | errno = map_errno_from_nt_status(status);
|
---|
692 | return status;
|
---|
693 | }
|
---|
694 |
|
---|
695 | status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, mapped_name,
|
---|
696 | mem_ctx, num_streams,streams);
|
---|
697 | TALLOC_FREE(mapped_name);
|
---|
698 |
|
---|
699 | return status;
|
---|
700 | }
|
---|
701 |
|
---|
702 | static NTSTATUS
|
---|
703 | catia_get_nt_acl(struct vfs_handle_struct *handle,
|
---|
704 | const char *path,
|
---|
705 | uint32 security_info,
|
---|
706 | struct security_descriptor **ppdesc)
|
---|
707 | {
|
---|
708 | char *mapped_name = NULL;
|
---|
709 | NTSTATUS status;
|
---|
710 |
|
---|
711 | status = catia_string_replace_allocate(handle->conn,
|
---|
712 | path, &mapped_name, vfs_translate_to_unix);
|
---|
713 | if (!NT_STATUS_IS_OK(status)) {
|
---|
714 | errno = map_errno_from_nt_status(status);
|
---|
715 | return status;
|
---|
716 | }
|
---|
717 | status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_name,
|
---|
718 | security_info, ppdesc);
|
---|
719 | TALLOC_FREE(mapped_name);
|
---|
720 |
|
---|
721 | return status;
|
---|
722 | }
|
---|
723 |
|
---|
724 | static int
|
---|
725 | catia_chmod_acl(vfs_handle_struct *handle,
|
---|
726 | const char *path,
|
---|
727 | mode_t mode)
|
---|
728 | {
|
---|
729 | char *mapped_name = NULL;
|
---|
730 | NTSTATUS status;
|
---|
731 | int ret;
|
---|
732 |
|
---|
733 | status = catia_string_replace_allocate(handle->conn,
|
---|
734 | path, &mapped_name, vfs_translate_to_unix);
|
---|
735 | if (!NT_STATUS_IS_OK(status)) {
|
---|
736 | errno = map_errno_from_nt_status(status);
|
---|
737 | return -1;
|
---|
738 | }
|
---|
739 |
|
---|
740 | ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_name, mode);
|
---|
741 | TALLOC_FREE(mapped_name);
|
---|
742 | return ret;
|
---|
743 | }
|
---|
744 |
|
---|
745 | static SMB_ACL_T
|
---|
746 | catia_sys_acl_get_file(vfs_handle_struct *handle,
|
---|
747 | const char *path,
|
---|
748 | SMB_ACL_TYPE_T type)
|
---|
749 | {
|
---|
750 | char *mapped_name = NULL;
|
---|
751 | NTSTATUS status;
|
---|
752 | SMB_ACL_T ret;
|
---|
753 |
|
---|
754 | status = catia_string_replace_allocate(handle->conn,
|
---|
755 | path, &mapped_name, vfs_translate_to_unix);
|
---|
756 | if (!NT_STATUS_IS_OK(status)) {
|
---|
757 | errno = map_errno_from_nt_status(status);
|
---|
758 | return NULL;
|
---|
759 | }
|
---|
760 |
|
---|
761 | ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_name, type);
|
---|
762 | TALLOC_FREE(mapped_name);
|
---|
763 |
|
---|
764 | return ret;
|
---|
765 | }
|
---|
766 |
|
---|
767 | static int
|
---|
768 | catia_sys_acl_set_file(vfs_handle_struct *handle,
|
---|
769 | const char *path,
|
---|
770 | SMB_ACL_TYPE_T type,
|
---|
771 | SMB_ACL_T theacl)
|
---|
772 | {
|
---|
773 | char *mapped_name = NULL;
|
---|
774 | NTSTATUS status;
|
---|
775 | int ret;
|
---|
776 |
|
---|
777 | status = catia_string_replace_allocate(handle->conn,
|
---|
778 | path, &mapped_name, vfs_translate_to_unix);
|
---|
779 | if (!NT_STATUS_IS_OK(status)) {
|
---|
780 | errno = map_errno_from_nt_status(status);
|
---|
781 | return -1;
|
---|
782 | }
|
---|
783 |
|
---|
784 | ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_name, type, theacl);
|
---|
785 | TALLOC_FREE(mapped_name);
|
---|
786 |
|
---|
787 | return ret;
|
---|
788 | }
|
---|
789 |
|
---|
790 | static int
|
---|
791 | catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
|
---|
792 | const char *path)
|
---|
793 | {
|
---|
794 | char *mapped_name = NULL;
|
---|
795 | NTSTATUS status;
|
---|
796 | int ret;
|
---|
797 |
|
---|
798 | status = catia_string_replace_allocate(handle->conn,
|
---|
799 | path, &mapped_name, vfs_translate_to_unix);
|
---|
800 | if (!NT_STATUS_IS_OK(status)) {
|
---|
801 | errno = map_errno_from_nt_status(status);
|
---|
802 | return -1;
|
---|
803 | }
|
---|
804 |
|
---|
805 | ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_name);
|
---|
806 | TALLOC_FREE(mapped_name);
|
---|
807 |
|
---|
808 | return ret;
|
---|
809 | }
|
---|
810 |
|
---|
811 | static ssize_t
|
---|
812 | catia_getxattr(vfs_handle_struct *handle, const char *path,
|
---|
813 | const char *name, void *value, size_t size)
|
---|
814 | {
|
---|
815 | char *mapped_name = NULL;
|
---|
816 | NTSTATUS status;
|
---|
817 | ssize_t ret;
|
---|
818 |
|
---|
819 | status = catia_string_replace_allocate(handle->conn,
|
---|
820 | name, &mapped_name, vfs_translate_to_unix);
|
---|
821 | if (!NT_STATUS_IS_OK(status)) {
|
---|
822 | errno = map_errno_from_nt_status(status);
|
---|
823 | return -1;
|
---|
824 | }
|
---|
825 |
|
---|
826 |
|
---|
827 | ret = SMB_VFS_NEXT_GETXATTR(handle, path, mapped_name, value, size);
|
---|
828 | TALLOC_FREE(mapped_name);
|
---|
829 |
|
---|
830 | return ret;
|
---|
831 | }
|
---|
832 |
|
---|
833 | static ssize_t
|
---|
834 | catia_lgetxattr(vfs_handle_struct *handle, const char *path,
|
---|
835 | const char *name, void *value, size_t size)
|
---|
836 | {
|
---|
837 | char *mapped_name = NULL;
|
---|
838 | NTSTATUS status;
|
---|
839 | ssize_t ret;
|
---|
840 |
|
---|
841 | status = catia_string_replace_allocate(handle->conn,
|
---|
842 | name, &mapped_name, vfs_translate_to_unix);
|
---|
843 | if (!NT_STATUS_IS_OK(status)) {
|
---|
844 | errno = map_errno_from_nt_status(status);
|
---|
845 | return -1;
|
---|
846 | }
|
---|
847 |
|
---|
848 |
|
---|
849 | ret = SMB_VFS_NEXT_LGETXATTR(handle, path, mapped_name, value, size);
|
---|
850 | TALLOC_FREE(mapped_name);
|
---|
851 |
|
---|
852 | return ret;
|
---|
853 | }
|
---|
854 |
|
---|
855 | static ssize_t
|
---|
856 | catia_listxattr(vfs_handle_struct *handle, const char *path,
|
---|
857 | char *list, size_t size)
|
---|
858 | {
|
---|
859 | char *mapped_name = NULL;
|
---|
860 | NTSTATUS status;
|
---|
861 | ssize_t ret;
|
---|
862 |
|
---|
863 | status = catia_string_replace_allocate(handle->conn,
|
---|
864 | path, &mapped_name, vfs_translate_to_unix);
|
---|
865 | if (!NT_STATUS_IS_OK(status)) {
|
---|
866 | errno = map_errno_from_nt_status(status);
|
---|
867 | return -1;
|
---|
868 | }
|
---|
869 |
|
---|
870 |
|
---|
871 | ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_name, list, size);
|
---|
872 | TALLOC_FREE(mapped_name);
|
---|
873 |
|
---|
874 | return ret;
|
---|
875 | }
|
---|
876 |
|
---|
877 | static ssize_t
|
---|
878 | catia_llistxattr(vfs_handle_struct *handle, const char *path,
|
---|
879 | char *list, size_t size)
|
---|
880 | {
|
---|
881 | char *mapped_name = NULL;
|
---|
882 | NTSTATUS status;
|
---|
883 | ssize_t ret;
|
---|
884 |
|
---|
885 | status = catia_string_replace_allocate(handle->conn,
|
---|
886 | path, &mapped_name, vfs_translate_to_unix);
|
---|
887 | if (!NT_STATUS_IS_OK(status)) {
|
---|
888 | errno = map_errno_from_nt_status(status);
|
---|
889 | return -1;
|
---|
890 | }
|
---|
891 |
|
---|
892 |
|
---|
893 | ret = SMB_VFS_NEXT_LLISTXATTR(handle, mapped_name, list, size);
|
---|
894 | TALLOC_FREE(mapped_name);
|
---|
895 |
|
---|
896 | return ret;
|
---|
897 | }
|
---|
898 |
|
---|
899 | static int
|
---|
900 | catia_removexattr(vfs_handle_struct *handle, const char *path,
|
---|
901 | const char *name)
|
---|
902 | {
|
---|
903 | char *mapped_name = NULL;
|
---|
904 | NTSTATUS status;
|
---|
905 | ssize_t ret;
|
---|
906 |
|
---|
907 | status = catia_string_replace_allocate(handle->conn,
|
---|
908 | name, &mapped_name, vfs_translate_to_unix);
|
---|
909 | if (!NT_STATUS_IS_OK(status)) {
|
---|
910 | errno = map_errno_from_nt_status(status);
|
---|
911 | return -1;
|
---|
912 | }
|
---|
913 |
|
---|
914 |
|
---|
915 | ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path, mapped_name);
|
---|
916 | TALLOC_FREE(mapped_name);
|
---|
917 |
|
---|
918 | return ret;
|
---|
919 | }
|
---|
920 |
|
---|
921 | static int
|
---|
922 | catia_lremovexattr(vfs_handle_struct *handle, const char *path,
|
---|
923 | const char *name)
|
---|
924 | {
|
---|
925 | char *mapped_name = NULL;
|
---|
926 | NTSTATUS status;
|
---|
927 | ssize_t ret;
|
---|
928 |
|
---|
929 | status = catia_string_replace_allocate(handle->conn,
|
---|
930 | name, &mapped_name, vfs_translate_to_unix);
|
---|
931 | if (!NT_STATUS_IS_OK(status)) {
|
---|
932 | errno = map_errno_from_nt_status(status);
|
---|
933 | return -1;
|
---|
934 | }
|
---|
935 |
|
---|
936 |
|
---|
937 | ret = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, mapped_name);
|
---|
938 | TALLOC_FREE(mapped_name);
|
---|
939 |
|
---|
940 | return ret;
|
---|
941 | }
|
---|
942 |
|
---|
943 | static int
|
---|
944 | catia_setxattr(vfs_handle_struct *handle, const char *path,
|
---|
945 | const char *name, const void *value, size_t size,
|
---|
946 | int flags)
|
---|
947 | {
|
---|
948 | char *mapped_name = NULL;
|
---|
949 | NTSTATUS status;
|
---|
950 | ssize_t ret;
|
---|
951 |
|
---|
952 | status = catia_string_replace_allocate(handle->conn,
|
---|
953 | name, &mapped_name, vfs_translate_to_unix);
|
---|
954 | if (!NT_STATUS_IS_OK(status)) {
|
---|
955 | errno = map_errno_from_nt_status(status);
|
---|
956 | return -1;
|
---|
957 | }
|
---|
958 |
|
---|
959 |
|
---|
960 | ret = SMB_VFS_NEXT_SETXATTR(handle, path, mapped_name, value, size, flags);
|
---|
961 | TALLOC_FREE(mapped_name);
|
---|
962 |
|
---|
963 | return ret;
|
---|
964 | }
|
---|
965 |
|
---|
966 | static int
|
---|
967 | catia_lsetxattr(vfs_handle_struct *handle, const char *path,
|
---|
968 | const char *name, const void *value, size_t size,
|
---|
969 | int flags)
|
---|
970 | {
|
---|
971 | char *mapped_name = NULL;
|
---|
972 | NTSTATUS status;
|
---|
973 | ssize_t ret;
|
---|
974 |
|
---|
975 | status = catia_string_replace_allocate(handle->conn,
|
---|
976 | name, &mapped_name, vfs_translate_to_unix);
|
---|
977 | if (!NT_STATUS_IS_OK(status)) {
|
---|
978 | errno = map_errno_from_nt_status(status);
|
---|
979 | return -1;
|
---|
980 | }
|
---|
981 |
|
---|
982 |
|
---|
983 | ret = SMB_VFS_NEXT_LSETXATTR(handle, path, mapped_name, value, size, flags);
|
---|
984 | TALLOC_FREE(mapped_name);
|
---|
985 |
|
---|
986 | return ret;
|
---|
987 | }
|
---|
988 |
|
---|
989 | static struct vfs_fn_pointers vfs_catia_fns = {
|
---|
990 | .mkdir = catia_mkdir,
|
---|
991 | .rmdir = catia_rmdir,
|
---|
992 | .opendir = catia_opendir,
|
---|
993 | .open = catia_open,
|
---|
994 | .rename = catia_rename,
|
---|
995 | .stat = catia_stat,
|
---|
996 | .lstat = catia_lstat,
|
---|
997 | .unlink = catia_unlink,
|
---|
998 | .chown = catia_chown,
|
---|
999 | .lchown = catia_lchown,
|
---|
1000 | .chdir = catia_chdir,
|
---|
1001 | .ntimes = catia_ntimes,
|
---|
1002 | .realpath = catia_realpath,
|
---|
1003 | .chflags = catia_chflags,
|
---|
1004 | .streaminfo = catia_streaminfo,
|
---|
1005 | .translate_name = catia_translate_name,
|
---|
1006 | .get_nt_acl = catia_get_nt_acl,
|
---|
1007 | .chmod_acl = catia_chmod_acl,
|
---|
1008 | .sys_acl_get_file = catia_sys_acl_get_file,
|
---|
1009 | .sys_acl_set_file = catia_sys_acl_set_file,
|
---|
1010 | .sys_acl_delete_def_file = catia_sys_acl_delete_def_file,
|
---|
1011 | .getxattr = catia_getxattr,
|
---|
1012 | .lgetxattr = catia_lgetxattr,
|
---|
1013 | .listxattr = catia_listxattr,
|
---|
1014 | .llistxattr = catia_llistxattr,
|
---|
1015 | .removexattr = catia_removexattr,
|
---|
1016 | .lremovexattr = catia_lremovexattr,
|
---|
1017 | .setxattr = catia_setxattr,
|
---|
1018 | .lsetxattr = catia_lsetxattr,
|
---|
1019 | };
|
---|
1020 |
|
---|
1021 | NTSTATUS vfs_catia_init(void)
|
---|
1022 | {
|
---|
1023 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
|
---|
1024 | &vfs_catia_fns);
|
---|
1025 | }
|
---|