modules/vfs_catia.c

説明を見る。
00001 /* 
00002  * Catia VFS module
00003  *
00004  * Implement a fixed mapping of forbidden NT characters in filenames that are
00005  * used a lot by the CAD package Catia.
00006  *
00007  * Yes, this a BAD BAD UGLY INCOMPLETE hack, but it helps quite some people
00008  * out there. Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden
00009  * under Windows...
00010  *
00011  * Copyright (C) Volker Lendecke, 2005
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  * 
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00026  */
00027 
00028 
00029 #include "includes.h"
00030 
00031 static void catia_string_replace(char *s, unsigned char oldc, unsigned 
00032                                  char newc)
00033 {
00034         static smb_ucs2_t tmpbuf[sizeof(pstring)];
00035         smb_ucs2_t *ptr = tmpbuf;
00036         smb_ucs2_t old = oldc;
00037 
00038         push_ucs2(NULL, tmpbuf, s, sizeof(tmpbuf), STR_TERMINATE);
00039 
00040         for (;*ptr;ptr++)
00041                 if (*ptr==old) *ptr=newc;
00042 
00043         pull_ucs2(NULL, s, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
00044 }
00045 
00046 static void from_unix(char *s)
00047 {
00048         catia_string_replace(s, '\x22', '\xa8');
00049         catia_string_replace(s, '\x2a', '\xa4');
00050         catia_string_replace(s, '\x2f', '\xf8');
00051         catia_string_replace(s, '\x3a', '\xf7');
00052         catia_string_replace(s, '\x3c', '\xab');
00053         catia_string_replace(s, '\x3e', '\xbb');
00054         catia_string_replace(s, '\x3f', '\xbf');
00055         catia_string_replace(s, '\x5c', '\xff');
00056         catia_string_replace(s, '\x7c', '\xa6');
00057         catia_string_replace(s, ' ', '\xb1');
00058 }
00059 
00060 static void to_unix(char *s)
00061 {
00062         catia_string_replace(s, '\xa8', '\x22');
00063         catia_string_replace(s, '\xa4', '\x2a');
00064         catia_string_replace(s, '\xf8', '\x2f');
00065         catia_string_replace(s, '\xf7', '\x3a');
00066         catia_string_replace(s, '\xab', '\x3c');
00067         catia_string_replace(s, '\xbb', '\x3e');
00068         catia_string_replace(s, '\xbf', '\x3f');
00069         catia_string_replace(s, '\xff', '\x5c');
00070         catia_string_replace(s, '\xa6', '\x7c');
00071         catia_string_replace(s, '\xb1', ' ');
00072 }
00073 
00074 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
00075                           const char *fname, const char *mask, uint32 attr)
00076 {
00077         pstring name;
00078         pstrcpy(name, fname);
00079         to_unix(name);
00080 
00081         return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr);
00082 }
00083 
00084 static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle, 
00085                                         SMB_STRUCT_DIR *dirp)
00086 {
00087         SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, dirp);
00088 
00089         if (result == NULL)
00090                 return result;
00091 
00092         from_unix(result->d_name);
00093         return result;
00094 }
00095 
00096 static int catia_open(vfs_handle_struct *handle,
00097                       const char *fname, files_struct *fsp, int flags, mode_t mode)
00098 {
00099         pstring name;
00100 
00101         pstrcpy(name, fname);
00102         to_unix(name);
00103  
00104         return SMB_VFS_NEXT_OPEN(handle, name, fsp, flags, mode);
00105 }
00106 
00107 static int catia_rename(vfs_handle_struct *handle,
00108                         const char *oldname, const char *newname)
00109 {
00110         pstring oname, nname;
00111 
00112         pstrcpy(oname, oldname);
00113         to_unix(oname);
00114         pstrcpy(nname, newname);
00115         to_unix(nname);
00116 
00117         DEBUG(10, ("converted old name: %s\n", oname));
00118         DEBUG(10, ("converted new name: %s\n", nname));
00119  
00120         return SMB_VFS_NEXT_RENAME(handle, oname, nname);
00121 }
00122 
00123 static int catia_stat(vfs_handle_struct *handle,
00124                       const char *fname, SMB_STRUCT_STAT *sbuf)
00125 {
00126         pstring name;
00127         pstrcpy(name, fname);
00128         to_unix(name);
00129 
00130         return SMB_VFS_NEXT_STAT(handle, name, sbuf);
00131 }
00132 
00133 static int catia_lstat(vfs_handle_struct *handle,
00134                        const char *path, SMB_STRUCT_STAT *sbuf)
00135 {
00136         pstring name;
00137         pstrcpy(name, path);
00138         to_unix(name);
00139 
00140         return SMB_VFS_NEXT_LSTAT(handle, name, sbuf);
00141 }
00142 
00143 static int catia_unlink(vfs_handle_struct *handle, const char *path)
00144 {
00145         pstring name;
00146         pstrcpy(name, path);
00147         to_unix(name);
00148 
00149         return SMB_VFS_NEXT_UNLINK(handle, name);
00150 }
00151 
00152 static int catia_chmod(vfs_handle_struct *handle,
00153                        const char *path, mode_t mode)
00154 {
00155         pstring name;
00156         pstrcpy(name, path);
00157         to_unix(name);
00158 
00159         return SMB_VFS_NEXT_CHMOD(handle, name, mode);
00160 }
00161 
00162 static int catia_chown(vfs_handle_struct *handle,
00163                        const char *path, uid_t uid, gid_t gid)
00164 {
00165         pstring name;
00166         pstrcpy(name, path);
00167         to_unix(name);
00168 
00169         return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
00170 }
00171 
00172 static int catia_chdir(vfs_handle_struct *handle,
00173                        const char *path)
00174 {
00175         pstring name;
00176         pstrcpy(name, path);
00177         to_unix(name);
00178 
00179         return SMB_VFS_NEXT_CHDIR(handle, name);
00180 }
00181 
00182 static char *catia_getwd(vfs_handle_struct *handle, char *buf)
00183 {
00184         return SMB_VFS_NEXT_GETWD(handle, buf);
00185 }
00186 
00187 static int catia_ntimes(vfs_handle_struct *handle,
00188                        const char *path, const struct timespec ts[2])
00189 {
00190         return SMB_VFS_NEXT_NTIMES(handle, path, ts);
00191 }
00192 
00193 static BOOL catia_symlink(vfs_handle_struct *handle,
00194                           const char *oldpath, const char *newpath)
00195 {
00196         return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
00197 }
00198 
00199 static BOOL catia_readlink(vfs_handle_struct *handle,
00200                            const char *path, char *buf, size_t bufsiz)
00201 {
00202         return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
00203 }
00204 
00205 static int catia_link(vfs_handle_struct *handle,
00206                       const char *oldpath, const char *newpath)
00207 {
00208         return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
00209 }
00210 
00211 static int catia_mknod(vfs_handle_struct *handle,
00212                        const char *path, mode_t mode, SMB_DEV_T dev)
00213 {
00214         return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
00215 }
00216 
00217 static char *catia_realpath(vfs_handle_struct *handle,
00218                             const char *path, char *resolved_path)
00219 {
00220         return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
00221 }
00222 
00223 static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
00224                                const char *name, uint32 security_info,
00225                                struct  security_descriptor_info **ppdesc)
00226 {
00227         return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info,
00228                                        ppdesc);
00229 }
00230 
00231 static BOOL catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, 
00232                              const char *name, uint32 security_info_sent,
00233                              struct security_descriptor_info *psd)
00234 {
00235         return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent,
00236                                        psd);
00237 }
00238 
00239 static int catia_chmod_acl(vfs_handle_struct *handle,
00240                            const char *name, mode_t mode)
00241 {
00242         /* If the underlying VFS doesn't have ACL support... */
00243         if (!handle->vfs_next.ops.chmod_acl) {
00244                 errno = ENOSYS;
00245                 return -1;
00246         }
00247         return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
00248 }
00249 
00250 /* VFS operations structure */
00251 
00252 static vfs_op_tuple catia_op_tuples[] = {
00253 
00254         /* Directory operations */
00255 
00256         {SMB_VFS_OP(catia_opendir), SMB_VFS_OP_OPENDIR, 
00257 SMB_VFS_LAYER_TRANSPARENT},
00258         {SMB_VFS_OP(catia_readdir), SMB_VFS_OP_READDIR, 
00259 SMB_VFS_LAYER_TRANSPARENT},
00260 
00261         /* File operations */
00262 
00263         {SMB_VFS_OP(catia_open), SMB_VFS_OP_OPEN, 
00264 SMB_VFS_LAYER_TRANSPARENT},
00265         {SMB_VFS_OP(catia_rename),                      SMB_VFS_OP_RENAME, 
00266         SMB_VFS_LAYER_TRANSPARENT},
00267         {SMB_VFS_OP(catia_stat), SMB_VFS_OP_STAT, 
00268 SMB_VFS_LAYER_TRANSPARENT},
00269         {SMB_VFS_OP(catia_lstat),                       SMB_VFS_OP_LSTAT,  
00270 SMB_VFS_LAYER_TRANSPARENT},
00271         {SMB_VFS_OP(catia_unlink),                      SMB_VFS_OP_UNLINK, 
00272         SMB_VFS_LAYER_TRANSPARENT},
00273         {SMB_VFS_OP(catia_chmod),                       SMB_VFS_OP_CHMOD,  
00274 SMB_VFS_LAYER_TRANSPARENT},
00275         {SMB_VFS_OP(catia_chown),                       SMB_VFS_OP_CHOWN,  
00276 SMB_VFS_LAYER_TRANSPARENT},
00277         {SMB_VFS_OP(catia_chdir),                       SMB_VFS_OP_CHDIR,  
00278 SMB_VFS_LAYER_TRANSPARENT},
00279         {SMB_VFS_OP(catia_getwd),                       SMB_VFS_OP_GETWD,  
00280 SMB_VFS_LAYER_TRANSPARENT},
00281         {SMB_VFS_OP(catia_ntimes),                       SMB_VFS_OP_NTIMES,  
00282 SMB_VFS_LAYER_TRANSPARENT},
00283         {SMB_VFS_OP(catia_symlink), SMB_VFS_OP_SYMLINK, 
00284 SMB_VFS_LAYER_TRANSPARENT},
00285         {SMB_VFS_OP(catia_readlink), SMB_VFS_OP_READLINK, 
00286 SMB_VFS_LAYER_TRANSPARENT},
00287         {SMB_VFS_OP(catia_link), SMB_VFS_OP_LINK, 
00288 SMB_VFS_LAYER_TRANSPARENT},
00289         {SMB_VFS_OP(catia_mknod),                       SMB_VFS_OP_MKNOD,  
00290 SMB_VFS_LAYER_TRANSPARENT},
00291         {SMB_VFS_OP(catia_realpath), SMB_VFS_OP_REALPATH, 
00292 SMB_VFS_LAYER_TRANSPARENT},
00293 
00294         /* NT File ACL operations */
00295 
00296         {SMB_VFS_OP(catia_get_nt_acl), SMB_VFS_OP_GET_NT_ACL, 
00297 SMB_VFS_LAYER_TRANSPARENT},
00298         {SMB_VFS_OP(catia_set_nt_acl), SMB_VFS_OP_SET_NT_ACL, 
00299 SMB_VFS_LAYER_TRANSPARENT},
00300 
00301         /* POSIX ACL operations */
00302 
00303         {SMB_VFS_OP(catia_chmod_acl), SMB_VFS_OP_CHMOD_ACL, 
00304 SMB_VFS_LAYER_TRANSPARENT},
00305 
00306 
00307         {NULL,                                          SMB_VFS_OP_NOOP,   
00308 SMB_VFS_LAYER_NOOP}
00309 };
00310 
00311 NTSTATUS vfs_catia_init(void);
00312 NTSTATUS vfs_catia_init(void)
00313 {
00314         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia", 
00315 catia_op_tuples);
00316 }

Sambaに対してSat Aug 29 21:23:07 2009に生成されました。  doxygen 1.4.7