~vcs-imports/samba/main

« back to all changes in this revision

Viewing changes to source/modules/vfs_catia.c

  • Committer: jerry
  • Date: 2006-07-14 21:48:39 UTC
  • Revision ID: vcs-imports@canonical.com-20060714214839-586d8c489a8fcead
gutting trunk to move to svn:externals

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 2 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, write to the Free Software
25
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
 
 */
27
 
 
28
 
 
29
 
#include "includes.h"
30
 
 
31
 
static void catia_string_replace(char *s, unsigned char oldc, unsigned 
32
 
                                 char newc)
33
 
{
34
 
        static smb_ucs2_t tmpbuf[sizeof(pstring)];
35
 
        smb_ucs2_t *ptr = tmpbuf;
36
 
        smb_ucs2_t old = oldc;
37
 
 
38
 
        push_ucs2(NULL, tmpbuf, s, sizeof(tmpbuf), STR_TERMINATE);
39
 
 
40
 
        for (;*ptr;ptr++)
41
 
                if (*ptr==old) *ptr=newc;
42
 
 
43
 
        pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
44
 
}
45
 
 
46
 
static void from_unix(char *s)
47
 
{
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');
58
 
}
59
 
 
60
 
static void to_unix(char *s)
61
 
{
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', ' ');
72
 
}
73
 
 
74
 
static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
75
 
                          const char *fname, const char *mask, uint32 attr)
76
 
{
77
 
        pstring name;
78
 
        pstrcpy(name, fname);
79
 
        to_unix(name);
80
 
 
81
 
        return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr);
82
 
}
83
 
 
84
 
static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle, 
85
 
                                        SMB_STRUCT_DIR *dirp)
86
 
{
87
 
        SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, dirp);
88
 
 
89
 
        if (result == NULL)
90
 
                return result;
91
 
 
92
 
        from_unix(result->d_name);
93
 
        return result;
94
 
}
95
 
 
96
 
static int catia_open(vfs_handle_struct *handle,
97
 
                      const char *fname, files_struct *fsp, int flags, mode_t mode)
98
 
{
99
 
        pstring name;
100
 
 
101
 
        pstrcpy(name, fname);
102
 
        to_unix(name);
103
 
 
104
 
        return SMB_VFS_NEXT_OPEN(handle, name, fsp, flags, mode);
105
 
}
106
 
 
107
 
static int catia_rename(vfs_handle_struct *handle,
108
 
                        const char *oldname, const char *newname)
109
 
{
110
 
        pstring oname, nname;
111
 
 
112
 
        pstrcpy(oname, oldname);
113
 
        to_unix(oname);
114
 
        pstrcpy(nname, newname);
115
 
        to_unix(nname);
116
 
 
117
 
        DEBUG(10, ("converted old name: %s\n", oname));
118
 
        DEBUG(10, ("converted new name: %s\n", nname));
119
 
 
120
 
        return SMB_VFS_NEXT_RENAME(handle, oname, nname);
121
 
}
122
 
 
123
 
static int catia_stat(vfs_handle_struct *handle,
124
 
                      const char *fname, SMB_STRUCT_STAT *sbuf)
125
 
{
126
 
        pstring name;
127
 
        pstrcpy(name, fname);
128
 
        to_unix(name);
129
 
 
130
 
        return SMB_VFS_NEXT_STAT(handle, name, sbuf);
131
 
}
132
 
 
133
 
static int catia_lstat(vfs_handle_struct *handle,
134
 
                       const char *path, SMB_STRUCT_STAT *sbuf)
135
 
{
136
 
        pstring name;
137
 
        pstrcpy(name, path);
138
 
        to_unix(name);
139
 
 
140
 
        return SMB_VFS_NEXT_LSTAT(handle, name, sbuf);
141
 
}
142
 
 
143
 
static int catia_unlink(vfs_handle_struct *handle, const char *path)
144
 
{
145
 
        pstring name;
146
 
        pstrcpy(name, path);
147
 
        to_unix(name);
148
 
 
149
 
        return SMB_VFS_NEXT_UNLINK(handle, name);
150
 
}
151
 
 
152
 
static int catia_chmod(vfs_handle_struct *handle,
153
 
                       const char *path, mode_t mode)
154
 
{
155
 
        pstring name;
156
 
        pstrcpy(name, path);
157
 
        to_unix(name);
158
 
 
159
 
        return SMB_VFS_NEXT_CHMOD(handle, name, mode);
160
 
}
161
 
 
162
 
static int catia_chown(vfs_handle_struct *handle,
163
 
                       const char *path, uid_t uid, gid_t gid)
164
 
{
165
 
        pstring name;
166
 
        pstrcpy(name, path);
167
 
        to_unix(name);
168
 
 
169
 
        return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
170
 
}
171
 
 
172
 
static int catia_chdir(vfs_handle_struct *handle,
173
 
                       const char *path)
174
 
{
175
 
        pstring name;
176
 
        pstrcpy(name, path);
177
 
        to_unix(name);
178
 
 
179
 
        return SMB_VFS_NEXT_CHDIR(handle, name);
180
 
}
181
 
 
182
 
static char *catia_getwd(vfs_handle_struct *handle, char *buf)
183
 
{
184
 
        return SMB_VFS_NEXT_GETWD(handle, buf);
185
 
}
186
 
 
187
 
static int catia_utime(vfs_handle_struct *handle,
188
 
                       const char *path, struct utimbuf *times)
189
 
{
190
 
        return SMB_VFS_NEXT_UTIME(handle, path, times);
191
 
}
192
 
 
193
 
static BOOL catia_symlink(vfs_handle_struct *handle,
194
 
                          const char *oldpath, const char *newpath)
195
 
{
196
 
        return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
197
 
}
198
 
 
199
 
static BOOL catia_readlink(vfs_handle_struct *handle,
200
 
                           const char *path, char *buf, size_t bufsiz)
201
 
{
202
 
        return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
203
 
}
204
 
 
205
 
static int catia_link(vfs_handle_struct *handle,
206
 
                      const char *oldpath, const char *newpath)
207
 
{
208
 
        return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
209
 
}
210
 
 
211
 
static int catia_mknod(vfs_handle_struct *handle,
212
 
                       const char *path, mode_t mode, SMB_DEV_T dev)
213
 
{
214
 
        return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
215
 
}
216
 
 
217
 
static char *catia_realpath(vfs_handle_struct *handle,
218
 
                            const char *path, char *resolved_path)
219
 
{
220
 
        return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
221
 
}
222
 
 
223
 
static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
224
 
                               const char *name, uint32 security_info,
225
 
                               struct  security_descriptor_info **ppdesc)
226
 
{
227
 
        return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info,
228
 
                                       ppdesc);
229
 
}
230
 
 
231
 
static BOOL catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, 
232
 
                             const char *name, uint32 security_info_sent,
233
 
                             struct security_descriptor_info *psd)
234
 
{
235
 
        return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
236
 
                                       psd);
237
 
}
238
 
 
239
 
static int catia_chmod_acl(vfs_handle_struct *handle,
240
 
                           const char *name, mode_t mode)
241
 
{
242
 
        /* If the underlying VFS doesn't have ACL support... */
243
 
        if (!handle->vfs_next.ops.chmod_acl) {
244
 
                errno = ENOSYS;
245
 
                return -1;
246
 
        }
247
 
        return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
248
 
}
249
 
 
250
 
/* VFS operations structure */
251
 
 
252
 
static vfs_op_tuple catia_op_tuples[] = {
253
 
 
254
 
        /* Directory operations */
255
 
 
256
 
        {SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR, 
257
 
SMB_VFS_LAYER_TRANSPARENT},
258
 
        {SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR, 
259
 
SMB_VFS_LAYER_TRANSPARENT},
260
 
 
261
 
        /* File operations */
262
 
 
263
 
        {SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN, 
264
 
SMB_VFS_LAYER_TRANSPARENT},
265
 
        {SMB_VFS_OP(catia_rename),                      SMB_VFS_OP_RENAME, 
266
 
        SMB_VFS_LAYER_TRANSPARENT},
267
 
        {SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT, 
268
 
SMB_VFS_LAYER_TRANSPARENT},
269
 
        {SMB_VFS_OP(catia_lstat),                       SMB_VFS_OP_LSTAT,  
270
 
SMB_VFS_LAYER_TRANSPARENT},
271
 
        {SMB_VFS_OP(catia_unlink),                      SMB_VFS_OP_UNLINK, 
272
 
        SMB_VFS_LAYER_TRANSPARENT},
273
 
        {SMB_VFS_OP(catia_chmod),                       SMB_VFS_OP_CHMOD,  
274
 
SMB_VFS_LAYER_TRANSPARENT},
275
 
        {SMB_VFS_OP(catia_chown),                       SMB_VFS_OP_CHOWN,  
276
 
SMB_VFS_LAYER_TRANSPARENT},
277
 
        {SMB_VFS_OP(catia_chdir),                       SMB_VFS_OP_CHDIR,  
278
 
SMB_VFS_LAYER_TRANSPARENT},
279
 
        {SMB_VFS_OP(catia_getwd),                       SMB_VFS_OP_GETWD,  
280
 
SMB_VFS_LAYER_TRANSPARENT},
281
 
        {SMB_VFS_OP(catia_utime),                       SMB_VFS_OP_UTIME,  
282
 
SMB_VFS_LAYER_TRANSPARENT},
283
 
        {SMB_VFS_OP(catia_symlink), SMB_VFS_OP_SYMLINK, 
284
 
SMB_VFS_LAYER_TRANSPARENT},
285
 
        {SMB_VFS_OP(catia_readlink), SMB_VFS_OP_READLINK, 
286
 
SMB_VFS_LAYER_TRANSPARENT},
287
 
        {SMB_VFS_OP(catia_link), SMB_VFS_OP_LINK, 
288
 
SMB_VFS_LAYER_TRANSPARENT},
289
 
        {SMB_VFS_OP(catia_mknod),                       SMB_VFS_OP_MKNOD,  
290
 
SMB_VFS_LAYER_TRANSPARENT},
291
 
        {SMB_VFS_OP(catia_realpath), SMB_VFS_OP_REALPATH, 
292
 
SMB_VFS_LAYER_TRANSPARENT},
293
 
 
294
 
        /* NT File ACL operations */
295
 
 
296
 
        {SMB_VFS_OP(catia_get_nt_acl), SMB_VFS_OP_GET_NT_ACL, 
297
 
SMB_VFS_LAYER_TRANSPARENT},
298
 
        {SMB_VFS_OP(catia_set_nt_acl), SMB_VFS_OP_SET_NT_ACL, 
299
 
SMB_VFS_LAYER_TRANSPARENT},
300
 
 
301
 
        /* POSIX ACL operations */
302
 
 
303
 
        {SMB_VFS_OP(catia_chmod_acl), SMB_VFS_OP_CHMOD_ACL, 
304
 
SMB_VFS_LAYER_TRANSPARENT},
305
 
 
306
 
 
307
 
        {NULL,                                          SMB_VFS_OP_NOOP,   
308
 
SMB_VFS_LAYER_NOOP}
309
 
};
310
 
 
311
 
NTSTATUS vfs_catia_init(void)
312
 
{
313
 
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia", 
314
 
catia_op_tuples);
315
 
}