modules/vfs_cap.c

説明を見る。
00001 /* 
00002  * CAP VFS module for Samba 3.x Version 0.3
00003  *
00004  * Copyright (C) Tim Potter, 1999-2000
00005  * Copyright (C) Alexander Bokovoy, 2002-2003
00006  * Copyright (C) Stefan (metze) Metzmacher, 2003
00007  * Copyright (C) TAKAHASHI Motonobu (monyo), 2003
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *  
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *  
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022  */
00023 
00024 
00025 #include "includes.h"
00026 
00027 /* cap functions */
00028 static char *capencode(char *to, const char *from);
00029 static char *capdecode(char *to, const char *from);
00030 
00031 static SMB_BIG_UINT cap_disk_free(vfs_handle_struct *handle, const char *path,
00032         BOOL small_query, SMB_BIG_UINT *bsize,
00033         SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
00034 {
00035         pstring cappath;
00036         capencode(cappath, path);
00037         return SMB_VFS_NEXT_DISK_FREE(handle, cappath, small_query, bsize,
00038                                          dfree, dsize);
00039 }
00040 
00041 static SMB_STRUCT_DIR *cap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
00042 {
00043         pstring capname;
00044         capencode(capname, fname);
00045         return SMB_VFS_NEXT_OPENDIR(handle, capname, mask, attr);
00046 }
00047 
00048 static SMB_STRUCT_DIRENT *cap_readdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp)
00049 {
00050         SMB_STRUCT_DIRENT *result;
00051         DEBUG(3,("cap: cap_readdir\n"));
00052         result = SMB_VFS_NEXT_READDIR(handle, dirp);
00053         if (result) {
00054           DEBUG(3,("cap: cap_readdir: %s\n", result->d_name));
00055           capdecode(result->d_name, result->d_name);
00056         }
00057         return result;
00058 }
00059 
00060 static int cap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
00061 {
00062         pstring cappath;
00063         capencode(cappath, path);
00064         return SMB_VFS_NEXT_MKDIR(handle, cappath, mode);
00065 }
00066 
00067 static int cap_rmdir(vfs_handle_struct *handle, const char *path)
00068 {
00069         pstring cappath;
00070         capencode(cappath, path);
00071         return SMB_VFS_NEXT_RMDIR(handle, cappath);
00072 }
00073 
00074 static int cap_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode)
00075 {
00076         pstring capname;
00077         DEBUG(3,("cap: cap_open for %s\n", fname));
00078         capencode(capname, fname);
00079         return SMB_VFS_NEXT_OPEN(handle, capname, fsp, flags, mode);
00080 }
00081 
00082 static int cap_rename(vfs_handle_struct *handle, const char *oldname, const char *newname)
00083 {
00084         pstring capold, capnew;
00085         capencode(capold, oldname);
00086         capencode(capnew, newname);
00087 
00088         return SMB_VFS_NEXT_RENAME(handle, capold, capnew);
00089 }
00090 
00091 static int cap_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf)
00092 {
00093         pstring capname;
00094         capencode(capname, fname);
00095         return SMB_VFS_NEXT_STAT(handle, capname, sbuf);
00096 }
00097 
00098 static int cap_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
00099 {
00100         pstring cappath;
00101         capencode(cappath, path);
00102         return SMB_VFS_NEXT_LSTAT(handle, cappath, sbuf);
00103 }
00104 
00105 static int cap_unlink(vfs_handle_struct *handle, const char *path)
00106 {
00107         pstring cappath;
00108         capencode(cappath, path);
00109         return SMB_VFS_NEXT_UNLINK(handle, cappath);
00110 }
00111 
00112 static int cap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
00113 {
00114         pstring cappath;
00115         capencode(cappath, path);
00116         return SMB_VFS_NEXT_CHMOD(handle, cappath, mode);
00117 }
00118 
00119 static int cap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
00120 {
00121         pstring cappath;
00122         capencode(cappath, path);
00123         return SMB_VFS_NEXT_CHOWN(handle, cappath, uid, gid);
00124 }
00125 
00126 static int cap_chdir(vfs_handle_struct *handle, const char *path)
00127 {
00128         pstring cappath;
00129         DEBUG(3,("cap: cap_chdir for %s\n", path));
00130         capencode(cappath, path);
00131         return SMB_VFS_NEXT_CHDIR(handle, cappath);
00132 }
00133 
00134 static int cap_ntimes(vfs_handle_struct *handle, const char *path, const struct timespec ts[2])
00135 {
00136         pstring cappath;
00137         capencode(cappath, path);
00138         return SMB_VFS_NEXT_NTIMES(handle, cappath, ts);
00139 }
00140 
00141 
00142 static BOOL cap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
00143 {
00144         pstring capoldpath, capnewpath;
00145         capencode(capoldpath, oldpath);
00146         capencode(capnewpath, newpath);
00147         return SMB_VFS_NEXT_SYMLINK(handle, capoldpath, capnewpath);
00148 }
00149 
00150 static BOOL cap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz)
00151 {
00152         pstring cappath;
00153         capencode(cappath, path);
00154         return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz);
00155 }
00156 
00157 static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
00158 {
00159         pstring capoldpath, capnewpath;
00160         capencode(capoldpath, oldpath);
00161         capencode(capnewpath, newpath);
00162         return SMB_VFS_NEXT_LINK(handle, capoldpath, capnewpath);
00163 }
00164 
00165 static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev)
00166 {
00167         pstring cappath;
00168         capencode(cappath, path);
00169         return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
00170 }
00171 
00172 static char *cap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path)
00173 {
00174         /* monyo need capencode'ed and capdecode'ed? */
00175         pstring cappath;
00176         capencode(cappath, path);
00177         return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
00178 }
00179 
00180 static BOOL cap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, struct security_descriptor_info *psd)
00181 {
00182         pstring capname;
00183         capencode(capname, name);
00184         return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, capname, security_info_sent, psd);
00185 }
00186 
00187 static int cap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode)
00188 {
00189         pstring capname;
00190         capencode(capname, name);
00191 
00192         /* If the underlying VFS doesn't have ACL support... */
00193         if (!handle->vfs_next.ops.chmod_acl) {
00194                 errno = ENOSYS;
00195                 return -1;
00196         }
00197         return SMB_VFS_NEXT_CHMOD_ACL(handle, capname, mode);
00198 }
00199 
00200 static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle, const char *path_p, SMB_ACL_TYPE_T type)
00201 {
00202         pstring cappath_p;
00203         capencode(cappath_p, path_p);
00204         return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, cappath_p, type);
00205 }
00206 
00207 static int cap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
00208 {
00209         pstring capname;
00210         capencode(capname, name);
00211         return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, capname, acltype, theacl);
00212 }
00213 
00214 static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path)
00215 {
00216         pstring cappath;
00217         capencode(cappath, path);
00218         return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, cappath);
00219 }
00220 
00221 static ssize_t cap_getxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size)
00222 {
00223         pstring cappath, capname;
00224         capencode(cappath, path);
00225         capencode(capname, name);
00226         return SMB_VFS_NEXT_GETXATTR(handle, cappath, capname, value, size);
00227 }
00228 
00229 static ssize_t cap_lgetxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t
00230 size)
00231 {
00232         pstring cappath, capname;
00233         capencode(cappath, path);
00234         capencode(capname, name);
00235         return SMB_VFS_NEXT_LGETXATTR(handle, cappath, capname, value, size);
00236 }
00237 
00238 static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, void *value, size_t size)
00239 {
00240         pstring capname;
00241         capencode(capname, name);
00242         return SMB_VFS_NEXT_FGETXATTR(handle, fsp, fd, capname, value, size);
00243 }
00244 
00245 static ssize_t cap_listxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
00246 {
00247         pstring cappath;
00248         capencode(cappath, path);
00249         return SMB_VFS_NEXT_LISTXATTR(handle, cappath, list, size);
00250 }
00251 
00252 static ssize_t cap_llistxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
00253 {
00254         pstring cappath;
00255         capencode(cappath, path);
00256         return SMB_VFS_NEXT_LLISTXATTR(handle, cappath, list, size);
00257 }
00258 
00259 static int cap_removexattr(vfs_handle_struct *handle, const char *path, const char *name)
00260 {
00261         pstring cappath, capname;
00262         capencode(cappath, path);
00263         capencode(capname, name);
00264         return SMB_VFS_NEXT_REMOVEXATTR(handle, cappath, capname);
00265 }
00266 
00267 static int cap_lremovexattr(vfs_handle_struct *handle, const char *path, const char *name)
00268 {
00269         pstring cappath, capname;
00270         capencode(cappath, path);
00271         capencode(capname, name);
00272         return SMB_VFS_NEXT_LREMOVEXATTR(handle, cappath, capname);
00273 }
00274 
00275 static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name)
00276 {
00277         pstring capname;
00278         capencode(capname, name);
00279         return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, fd, capname);
00280 }
00281 
00282 static int cap_setxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
00283 {
00284         pstring cappath, capname;
00285         capencode(cappath, path);
00286         capencode(capname, name);
00287         return SMB_VFS_NEXT_SETXATTR(handle, cappath, capname, value, size, flags);
00288 }
00289 
00290 static int cap_lsetxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
00291 {
00292         pstring cappath, capname;
00293         capencode(cappath, path);
00294         capencode(capname, name);
00295         return SMB_VFS_NEXT_LSETXATTR(handle, cappath, capname, value, size, flags);
00296 }
00297 
00298 static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, const void *value, size_t size, int flags)
00299 {
00300         pstring capname;
00301         capencode(capname, name);
00302         return SMB_VFS_NEXT_FSETXATTR(handle, fsp, fd, capname, value, size, flags);
00303 }
00304 
00305 /* VFS operations structure */
00306 
00307 static vfs_op_tuple cap_op_tuples[] = {
00308 
00309         /* Disk operations */
00310 
00311         {SMB_VFS_OP(cap_disk_free),                     SMB_VFS_OP_DISK_FREE,           SMB_VFS_LAYER_TRANSPARENT},
00312         
00313         /* Directory operations */
00314 
00315         {SMB_VFS_OP(cap_opendir),                       SMB_VFS_OP_OPENDIR,             SMB_VFS_LAYER_TRANSPARENT},
00316         {SMB_VFS_OP(cap_readdir),                       SMB_VFS_OP_READDIR,             SMB_VFS_LAYER_TRANSPARENT},
00317         {SMB_VFS_OP(cap_mkdir),                 SMB_VFS_OP_MKDIR,               SMB_VFS_LAYER_TRANSPARENT},
00318         {SMB_VFS_OP(cap_rmdir),                 SMB_VFS_OP_RMDIR,               SMB_VFS_LAYER_TRANSPARENT},
00319 
00320         /* File operations */
00321 
00322         {SMB_VFS_OP(cap_open),                          SMB_VFS_OP_OPEN,                SMB_VFS_LAYER_TRANSPARENT},
00323         {SMB_VFS_OP(cap_rename),                        SMB_VFS_OP_RENAME,              SMB_VFS_LAYER_TRANSPARENT},
00324         {SMB_VFS_OP(cap_stat),                          SMB_VFS_OP_STAT,                SMB_VFS_LAYER_TRANSPARENT},
00325         {SMB_VFS_OP(cap_lstat),                 SMB_VFS_OP_LSTAT,               SMB_VFS_LAYER_TRANSPARENT},
00326         {SMB_VFS_OP(cap_unlink),                        SMB_VFS_OP_UNLINK,              SMB_VFS_LAYER_TRANSPARENT},
00327         {SMB_VFS_OP(cap_chmod),                 SMB_VFS_OP_CHMOD,               SMB_VFS_LAYER_TRANSPARENT},
00328         {SMB_VFS_OP(cap_chown),                 SMB_VFS_OP_CHOWN,               SMB_VFS_LAYER_TRANSPARENT},
00329         {SMB_VFS_OP(cap_chdir),                 SMB_VFS_OP_CHDIR,               SMB_VFS_LAYER_TRANSPARENT},
00330         {SMB_VFS_OP(cap_ntimes),                        SMB_VFS_OP_NTIMES,              SMB_VFS_LAYER_TRANSPARENT},
00331         {SMB_VFS_OP(cap_symlink),                       SMB_VFS_OP_SYMLINK,             SMB_VFS_LAYER_TRANSPARENT},
00332         {SMB_VFS_OP(cap_readlink),                      SMB_VFS_OP_READLINK,            SMB_VFS_LAYER_TRANSPARENT},
00333         {SMB_VFS_OP(cap_link),                          SMB_VFS_OP_LINK,                SMB_VFS_LAYER_TRANSPARENT},
00334         {SMB_VFS_OP(cap_mknod),                 SMB_VFS_OP_MKNOD,               SMB_VFS_LAYER_TRANSPARENT},
00335         {SMB_VFS_OP(cap_realpath),                      SMB_VFS_OP_REALPATH,            SMB_VFS_LAYER_TRANSPARENT},
00336 
00337         /* NT File ACL operations */
00338 
00339         {SMB_VFS_OP(cap_set_nt_acl),                    SMB_VFS_OP_SET_NT_ACL,          SMB_VFS_LAYER_TRANSPARENT},
00340 
00341         /* POSIX ACL operations */
00342 
00343         {SMB_VFS_OP(cap_chmod_acl),                     SMB_VFS_OP_CHMOD_ACL,           SMB_VFS_LAYER_TRANSPARENT},
00344 
00345         {SMB_VFS_OP(cap_sys_acl_get_file),              SMB_VFS_OP_SYS_ACL_GET_FILE,            SMB_VFS_LAYER_TRANSPARENT},
00346         {SMB_VFS_OP(cap_sys_acl_set_file),              SMB_VFS_OP_SYS_ACL_SET_FILE,            SMB_VFS_LAYER_TRANSPARENT},
00347         {SMB_VFS_OP(cap_sys_acl_delete_def_file),       SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,     SMB_VFS_LAYER_TRANSPARENT},
00348         
00349         /* EA operations. */
00350         {SMB_VFS_OP(cap_getxattr),                      SMB_VFS_OP_GETXATTR,                    SMB_VFS_LAYER_TRANSPARENT},
00351         {SMB_VFS_OP(cap_lgetxattr),                     SMB_VFS_OP_LGETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
00352         {SMB_VFS_OP(cap_fgetxattr),                     SMB_VFS_OP_FGETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
00353         {SMB_VFS_OP(cap_listxattr),                     SMB_VFS_OP_LISTXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
00354         {SMB_VFS_OP(cap_llistxattr),                    SMB_VFS_OP_LLISTXATTR,                  SMB_VFS_LAYER_TRANSPARENT},
00355         {SMB_VFS_OP(cap_removexattr),                   SMB_VFS_OP_REMOVEXATTR,                 SMB_VFS_LAYER_TRANSPARENT},
00356         {SMB_VFS_OP(cap_lremovexattr),                  SMB_VFS_OP_LREMOVEXATTR,                SMB_VFS_LAYER_TRANSPARENT},
00357         {SMB_VFS_OP(cap_fremovexattr),                  SMB_VFS_OP_FREMOVEXATTR,                SMB_VFS_LAYER_TRANSPARENT},
00358         {SMB_VFS_OP(cap_setxattr),                      SMB_VFS_OP_SETXATTR,                    SMB_VFS_LAYER_TRANSPARENT},
00359         {SMB_VFS_OP(cap_lsetxattr),                     SMB_VFS_OP_LSETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
00360         {SMB_VFS_OP(cap_fsetxattr),                     SMB_VFS_OP_FSETXATTR,                   SMB_VFS_LAYER_TRANSPARENT},
00361 
00362         {NULL,                                          SMB_VFS_OP_NOOP,                        SMB_VFS_LAYER_NOOP}
00363 };
00364 
00365 NTSTATUS vfs_cap_init(void);
00366 NTSTATUS vfs_cap_init(void)
00367 {
00368         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "cap", cap_op_tuples);
00369 }
00370 
00371 /* For CAP functions */
00372 #define hex_tag ':'
00373 #define hex2bin(c)              hex2bin_table[(unsigned char)(c)]
00374 #define bin2hex(c)              bin2hex_table[(unsigned char)(c)]
00375 #define is_hex(s)               ((s)[0] == hex_tag)
00376 
00377 static unsigned char hex2bin_table[256] = {
00378 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
00379 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
00380 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
00381 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
00382 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x40 */
00383 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
00384 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
00385 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x60 */
00386 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
00387 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 */
00388 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 */
00389 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 */
00390 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */
00391 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */
00392 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */
00393 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */
00394 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */
00395 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0  /* 0xf0 */
00396 };
00397 static unsigned char bin2hex_table[256] = "0123456789abcdef";
00398 
00399 /*******************************************************************
00400   original code -> ":xx"  - CAP format
00401 ********************************************************************/
00402 static char *capencode(char *to, const char *from)
00403 {
00404   pstring cvtbuf;
00405   char *out;
00406 
00407   if (to == from) {
00408     from = pstrcpy ((char *) cvtbuf, from);
00409   }
00410 
00411   for (out = to; *from && (out - to < sizeof(pstring)-7);) {
00412     /* buffer husoku error */
00413     if ((unsigned char)*from >= 0x80) {
00414       *out++ = hex_tag;
00415       *out++ = bin2hex (((*from)>>4)&0x0f);
00416       *out++ = bin2hex ((*from)&0x0f);
00417       from++;
00418     } 
00419     else {
00420       *out++ = *from++;
00421     }
00422   }
00423   *out = '\0';
00424   return to;
00425 }
00426 
00427 /*******************************************************************
00428   CAP -> original code
00429 ********************************************************************/
00430 /* ":xx" -> a byte */
00431 static char *capdecode(char *to, const char *from)
00432 {
00433   pstring cvtbuf;
00434   char *out;
00435 
00436   if (to == from) {
00437     from = pstrcpy ((char *) cvtbuf, from);
00438   }
00439   for (out = to; *from && (out - to < sizeof(pstring)-3);) {
00440     if (is_hex(from)) {
00441       *out++ = (hex2bin (from[1])<<4) | (hex2bin (from[2]));
00442       from += 3;
00443     } else {
00444       *out++ = *from++;
00445     }
00446   }
00447   *out = '\0';
00448   return to;
00449 }

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