1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
/*
* Catia VFS module
*
* Implement a fixed mapping of forbidden NT characters in filenames that are
* used a lot by the CAD package Catia.
*
* Yes, this a BAD BAD UGLY INCOMPLETE hack, but it helps quite some people
* out there. Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden
* under Windows...
*
* Copyright (C) Volker Lendecke, 2005
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
static char *catia_string_replace(TALLOC_CTX *ctx,
const char *s,
unsigned char oldc,
unsigned char newc)
{
smb_ucs2_t *tmpbuf = NULL;
smb_ucs2_t *ptr = NULL;
smb_ucs2_t old = oldc;
char *ret = NULL;
size_t converted_size;
if (!s) {
return NULL;
}
if (!push_ucs2_talloc(ctx, &tmpbuf, s, &converted_size)) {
return NULL;
}
ptr = tmpbuf;
for (;*ptr;ptr++) {
if (*ptr==old) {
*ptr=newc;
}
}
if (!pull_ucs2_talloc(ctx, &ret, tmpbuf, &converted_size)) {
TALLOC_FREE(tmpbuf);
return NULL;
}
TALLOC_FREE(tmpbuf);
return ret;
}
static char *from_unix(TALLOC_CTX *ctx, const char *s)
{
char *ret = catia_string_replace(ctx, s, '\x22', '\xa8');
ret = catia_string_replace(ctx, ret, '\x2a', '\xa4');
ret = catia_string_replace(ctx, ret, '\x2f', '\xf8');
ret = catia_string_replace(ctx, ret, '\x3a', '\xf7');
ret = catia_string_replace(ctx, ret, '\x3c', '\xab');
ret = catia_string_replace(ctx, ret, '\x3e', '\xbb');
ret = catia_string_replace(ctx, ret, '\x3f', '\xbf');
ret = catia_string_replace(ctx, ret, '\x5c', '\xff');
ret = catia_string_replace(ctx, ret, '\x7c', '\xa6');
return catia_string_replace(ctx, ret, ' ', '\xb1');
}
static char *to_unix(TALLOC_CTX *ctx, const char *s)
{
char *ret = catia_string_replace(ctx, s, '\xa8', '\x22');
ret = catia_string_replace(ctx, ret, '\xa4', '\x2a');
ret = catia_string_replace(ctx, ret, '\xf8', '\x2f');
ret = catia_string_replace(ctx, ret, '\xf7', '\x3a');
ret = catia_string_replace(ctx, ret, '\xab', '\x3c');
ret = catia_string_replace(ctx, ret, '\xbb', '\x3e');
ret = catia_string_replace(ctx, ret, '\xbf', '\x3f');
ret = catia_string_replace(ctx, ret, '\xff', '\x5c');
ret = catia_string_replace(ctx, ret, '\xa6', '\x7c');
return catia_string_replace(ctx, ret, '\xb1', ' ');
}
static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
const char *fname, const char *mask, uint32 attr)
{
char *name = to_unix(talloc_tos(), fname);
if (!name) {
errno = ENOMEM;
return NULL;
}
return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr);
}
static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle,
SMB_STRUCT_DIR *dirp,
SMB_STRUCT_STAT *sbuf)
{
SMB_STRUCT_DIRENT *result = NULL;
SMB_STRUCT_DIRENT *newdirent = NULL;
char *newname;
size_t newnamelen;
result = SMB_VFS_NEXT_READDIR(handle, dirp, NULL);
if (result == NULL) {
return result;
}
newname = from_unix(talloc_tos(), result->d_name);
if (!newname) {
return NULL;
}
newnamelen = strlen(newname)+1;
newdirent = (SMB_STRUCT_DIRENT *)TALLOC_ARRAY(talloc_tos(),
char,
sizeof(SMB_STRUCT_DIRENT)+
newnamelen);
if (!newdirent) {
return NULL;
}
memcpy(newdirent, result, sizeof(SMB_STRUCT_DIRENT));
memcpy(&newdirent->d_name, newname, newnamelen);
return newdirent;
}
static int catia_open(vfs_handle_struct *handle,
struct smb_filename *smb_fname,
files_struct *fsp,
int flags,
mode_t mode)
{
char *name;
char *tmp_base_name;
int ret;
name = to_unix(talloc_tos(), smb_fname->base_name);
if (!name) {
errno = ENOMEM;
return -1;
}
tmp_base_name = smb_fname->base_name;
smb_fname->base_name = name;
ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
smb_fname->base_name = tmp_base_name;
TALLOC_FREE(name);
return ret;
}
static int catia_rename(vfs_handle_struct *handle,
const struct smb_filename *smb_fname_src,
const struct smb_filename *smb_fname_dst)
{
TALLOC_CTX *ctx = talloc_tos();
char *oname = NULL;
char *nname = NULL;
struct smb_filename *smb_fname_src_tmp = NULL;
struct smb_filename *smb_fname_dst_tmp = NULL;
NTSTATUS status;
int ret = -1;
oname = to_unix(ctx, smb_fname_src->base_name);
nname = to_unix(ctx, smb_fname_dst->base_name);
if (!oname || !nname) {
errno = ENOMEM;
goto out;
}
/* Setup temporary smb_filename structs. */
status = copy_smb_filename(talloc_tos(), smb_fname_src,
&smb_fname_src_tmp);
if (!NT_STATUS_IS_OK(status)) {
errno = map_errno_from_nt_status(status);
goto out;
}
status = copy_smb_filename(talloc_tos(), smb_fname_dst,
&smb_fname_dst_tmp);
if (!NT_STATUS_IS_OK(status)) {
errno = map_errno_from_nt_status(status);
goto out;
}
smb_fname_src_tmp->base_name = oname;
smb_fname_dst_tmp->base_name = nname;
DEBUG(10, ("converted old name: %s\n",
smb_fname_str_dbg(smb_fname_src_tmp)));
DEBUG(10, ("converted new name: %s\n",
smb_fname_str_dbg(smb_fname_dst_tmp)));
ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
smb_fname_dst_tmp);
out:
TALLOC_FREE(oname);
TALLOC_FREE(nname);
TALLOC_FREE(smb_fname_src_tmp);
TALLOC_FREE(smb_fname_dst_tmp);
return ret;
}
static int catia_stat(vfs_handle_struct *handle,
struct smb_filename *smb_fname)
{
char *name;
char *tmp_base_name;
int ret;
name = to_unix(talloc_tos(), smb_fname->base_name);
if (!name) {
errno = ENOMEM;
return -1;
}
tmp_base_name = smb_fname->base_name;
smb_fname->base_name = name;
ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
smb_fname->base_name = tmp_base_name;
TALLOC_FREE(name);
return ret;
}
static int catia_lstat(vfs_handle_struct *handle,
struct smb_filename *smb_fname)
{
char *name;
char *tmp_base_name;
int ret;
name = to_unix(talloc_tos(), smb_fname->base_name);
if (!name) {
errno = ENOMEM;
return -1;
}
tmp_base_name = smb_fname->base_name;
smb_fname->base_name = name;
ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
smb_fname->base_name = tmp_base_name;
TALLOC_FREE(name);
return ret;
}
static int catia_unlink(vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
{
struct smb_filename *smb_fname_tmp = NULL;
char *name = NULL;
NTSTATUS status;
int ret;
name = to_unix(talloc_tos(), smb_fname->base_name);
if (!name) {
errno = ENOMEM;
return -1;
}
/* Setup temporary smb_filename structs. */
status = copy_smb_filename(talloc_tos(), smb_fname,
&smb_fname_tmp);
if (!NT_STATUS_IS_OK(status)) {
errno = map_errno_from_nt_status(status);
return -1;
}
smb_fname_tmp->base_name = name;
ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
TALLOC_FREE(smb_fname_tmp);
return ret;
}
static int catia_chmod(vfs_handle_struct *handle,
const char *path, mode_t mode)
{
char *name = to_unix(talloc_tos(), path);
if (!name) {
errno = ENOMEM;
return -1;
}
return SMB_VFS_NEXT_CHMOD(handle, name, mode);
}
static int catia_chown(vfs_handle_struct *handle,
const char *path, uid_t uid, gid_t gid)
{
char *name = to_unix(talloc_tos(), path);
if (!name) {
errno = ENOMEM;
return -1;
}
return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
}
static int catia_lchown(vfs_handle_struct *handle,
const char *path, uid_t uid, gid_t gid)
{
char *name = to_unix(talloc_tos(), path);
if (!name) {
errno = ENOMEM;
return -1;
}
return SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
}
static int catia_chdir(vfs_handle_struct *handle,
const char *path)
{
char *name = to_unix(talloc_tos(), path);
if (!name) {
errno = ENOMEM;
return -1;
}
return SMB_VFS_NEXT_CHDIR(handle, name);
}
/* VFS operations structure */
static vfs_op_tuple catia_op_tuples[] = {
/* Directory operations */
{SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR,
SMB_VFS_LAYER_TRANSPARENT},
/* File operations */
{SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_rename), SMB_VFS_OP_RENAME,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_lstat), SMB_VFS_OP_LSTAT,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_unlink), SMB_VFS_OP_UNLINK,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_chmod), SMB_VFS_OP_CHMOD,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_chown), SMB_VFS_OP_CHOWN,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_lchown), SMB_VFS_OP_LCHOWN,
SMB_VFS_LAYER_TRANSPARENT},
{SMB_VFS_OP(catia_chdir), SMB_VFS_OP_CHDIR,
SMB_VFS_LAYER_TRANSPARENT},
{NULL, SMB_VFS_OP_NOOP,
SMB_VFS_LAYER_NOOP}
};
NTSTATUS vfs_catia_init(void);
NTSTATUS vfs_catia_init(void)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
catia_op_tuples);
}
|