| 1 | /*
|
|---|
| 2 | * CAP VFS module for Samba 3.x Version 0.3
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) Tim Potter, 1999-2000
|
|---|
| 5 | * Copyright (C) Alexander Bokovoy, 2002-2003
|
|---|
| 6 | * Copyright (C) Stefan (metze) Metzmacher, 2003
|
|---|
| 7 | * Copyright (C) TAKAHASHI Motonobu (monyo), 2003
|
|---|
| 8 | * Copyright (C) Jeremy Allison, 2007
|
|---|
| 9 | *
|
|---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 11 | * it under the terms of the GNU General Public License as published by
|
|---|
| 12 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 13 | * (at your option) any later version.
|
|---|
| 14 | *
|
|---|
| 15 | * This program is distributed in the hope that it will be useful,
|
|---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 18 | * GNU General Public License for more details.
|
|---|
| 19 | *
|
|---|
| 20 | * You should have received a copy of the GNU General Public License
|
|---|
| 21 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | #include "includes.h"
|
|---|
| 26 | #include "smbd/smbd.h"
|
|---|
| 27 |
|
|---|
| 28 | /* cap functions */
|
|---|
| 29 | static char *capencode(TALLOC_CTX *ctx, const char *from);
|
|---|
| 30 | static char *capdecode(TALLOC_CTX *ctx, const char *from);
|
|---|
| 31 |
|
|---|
| 32 | static uint64_t cap_disk_free(vfs_handle_struct *handle, const char *path,
|
|---|
| 33 | bool small_query, uint64_t *bsize,
|
|---|
| 34 | uint64_t *dfree, uint64_t *dsize)
|
|---|
| 35 | {
|
|---|
| 36 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 37 |
|
|---|
| 38 | if (!cappath) {
|
|---|
| 39 | errno = ENOMEM;
|
|---|
| 40 | return (uint64_t)-1;
|
|---|
| 41 | }
|
|---|
| 42 | return SMB_VFS_NEXT_DISK_FREE(handle, cappath, small_query, bsize,
|
|---|
| 43 | dfree, dsize);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | static SMB_STRUCT_DIR *cap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
|
|---|
| 47 | {
|
|---|
| 48 | char *capname = capencode(talloc_tos(), fname);
|
|---|
| 49 |
|
|---|
| 50 | if (!capname) {
|
|---|
| 51 | errno = ENOMEM;
|
|---|
| 52 | return NULL;
|
|---|
| 53 | }
|
|---|
| 54 | return SMB_VFS_NEXT_OPENDIR(handle, capname, mask, attr);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | static SMB_STRUCT_DIRENT *cap_readdir(vfs_handle_struct *handle,
|
|---|
| 58 | SMB_STRUCT_DIR *dirp,
|
|---|
| 59 | SMB_STRUCT_STAT *sbuf)
|
|---|
| 60 | {
|
|---|
| 61 | SMB_STRUCT_DIRENT *result;
|
|---|
| 62 | SMB_STRUCT_DIRENT *newdirent;
|
|---|
| 63 | char *newname;
|
|---|
| 64 | size_t newnamelen;
|
|---|
| 65 | DEBUG(3,("cap: cap_readdir\n"));
|
|---|
| 66 |
|
|---|
| 67 | result = SMB_VFS_NEXT_READDIR(handle, dirp, NULL);
|
|---|
| 68 | if (!result) {
|
|---|
| 69 | return NULL;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | newname = capdecode(talloc_tos(), result->d_name);
|
|---|
| 73 | if (!newname) {
|
|---|
| 74 | return NULL;
|
|---|
| 75 | }
|
|---|
| 76 | DEBUG(3,("cap: cap_readdir: %s\n", newname));
|
|---|
| 77 | newnamelen = strlen(newname)+1;
|
|---|
| 78 | newdirent = (SMB_STRUCT_DIRENT *)TALLOC_ARRAY(talloc_tos(),
|
|---|
| 79 | char,
|
|---|
| 80 | sizeof(SMB_STRUCT_DIRENT)+
|
|---|
| 81 | newnamelen);
|
|---|
| 82 | if (!newdirent) {
|
|---|
| 83 | return NULL;
|
|---|
| 84 | }
|
|---|
| 85 | memcpy(newdirent, result, sizeof(SMB_STRUCT_DIRENT));
|
|---|
| 86 | memcpy(&newdirent->d_name, newname, newnamelen);
|
|---|
| 87 | return newdirent;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | static int cap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
|
|---|
| 91 | {
|
|---|
| 92 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 93 |
|
|---|
| 94 | if (!cappath) {
|
|---|
| 95 | errno = ENOMEM;
|
|---|
| 96 | return -1;
|
|---|
| 97 | }
|
|---|
| 98 | return SMB_VFS_NEXT_MKDIR(handle, cappath, mode);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | static int cap_rmdir(vfs_handle_struct *handle, const char *path)
|
|---|
| 102 | {
|
|---|
| 103 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 104 |
|
|---|
| 105 | if (!cappath) {
|
|---|
| 106 | errno = ENOMEM;
|
|---|
| 107 | return -1;
|
|---|
| 108 | }
|
|---|
| 109 | return SMB_VFS_NEXT_RMDIR(handle, cappath);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | static int cap_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
|
|---|
| 113 | files_struct *fsp, int flags, mode_t mode)
|
|---|
| 114 | {
|
|---|
| 115 | char *cappath;
|
|---|
| 116 | char *tmp_base_name = NULL;
|
|---|
| 117 | int ret;
|
|---|
| 118 |
|
|---|
| 119 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
|---|
| 120 |
|
|---|
| 121 | if (!cappath) {
|
|---|
| 122 | errno = ENOMEM;
|
|---|
| 123 | return -1;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | tmp_base_name = smb_fname->base_name;
|
|---|
| 127 | smb_fname->base_name = cappath;
|
|---|
| 128 |
|
|---|
| 129 | DEBUG(3,("cap: cap_open for %s\n", smb_fname_str_dbg(smb_fname)));
|
|---|
| 130 | ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
|---|
| 131 |
|
|---|
| 132 | smb_fname->base_name = tmp_base_name;
|
|---|
| 133 | TALLOC_FREE(cappath);
|
|---|
| 134 |
|
|---|
| 135 | return ret;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | static int cap_rename(vfs_handle_struct *handle,
|
|---|
| 139 | const struct smb_filename *smb_fname_src,
|
|---|
| 140 | const struct smb_filename *smb_fname_dst)
|
|---|
| 141 | {
|
|---|
| 142 | char *capold = NULL;
|
|---|
| 143 | char *capnew = NULL;
|
|---|
| 144 | struct smb_filename *smb_fname_src_tmp = NULL;
|
|---|
| 145 | struct smb_filename *smb_fname_dst_tmp = NULL;
|
|---|
| 146 | NTSTATUS status;
|
|---|
| 147 | int ret = -1;
|
|---|
| 148 |
|
|---|
| 149 | capold = capencode(talloc_tos(), smb_fname_src->base_name);
|
|---|
| 150 | capnew = capencode(talloc_tos(), smb_fname_dst->base_name);
|
|---|
| 151 | if (!capold || !capnew) {
|
|---|
| 152 | errno = ENOMEM;
|
|---|
| 153 | goto out;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | /* Setup temporary smb_filename structs. */
|
|---|
| 157 | status = copy_smb_filename(talloc_tos(), smb_fname_src,
|
|---|
| 158 | &smb_fname_src_tmp);
|
|---|
| 159 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 160 | errno = map_errno_from_nt_status(status);
|
|---|
| 161 | goto out;
|
|---|
| 162 | }
|
|---|
| 163 | status = copy_smb_filename(talloc_tos(), smb_fname_dst,
|
|---|
| 164 | &smb_fname_dst_tmp);
|
|---|
| 165 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 166 | errno = map_errno_from_nt_status(status);
|
|---|
| 167 | goto out;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | smb_fname_src_tmp->base_name = capold;
|
|---|
| 171 | smb_fname_dst_tmp->base_name = capnew;
|
|---|
| 172 |
|
|---|
| 173 | ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
|
|---|
| 174 | smb_fname_dst_tmp);
|
|---|
| 175 | out:
|
|---|
| 176 | TALLOC_FREE(capold);
|
|---|
| 177 | TALLOC_FREE(capnew);
|
|---|
| 178 | TALLOC_FREE(smb_fname_src_tmp);
|
|---|
| 179 | TALLOC_FREE(smb_fname_dst_tmp);
|
|---|
| 180 |
|
|---|
| 181 | return ret;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | static int cap_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
|
|---|
| 185 | {
|
|---|
| 186 | char *cappath;
|
|---|
| 187 | char *tmp_base_name = NULL;
|
|---|
| 188 | int ret;
|
|---|
| 189 |
|
|---|
| 190 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
|---|
| 191 |
|
|---|
| 192 | if (!cappath) {
|
|---|
| 193 | errno = ENOMEM;
|
|---|
| 194 | return -1;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | tmp_base_name = smb_fname->base_name;
|
|---|
| 198 | smb_fname->base_name = cappath;
|
|---|
| 199 |
|
|---|
| 200 | ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
|
|---|
| 201 |
|
|---|
| 202 | smb_fname->base_name = tmp_base_name;
|
|---|
| 203 | TALLOC_FREE(cappath);
|
|---|
| 204 |
|
|---|
| 205 | return ret;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | static int cap_lstat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
|
|---|
| 209 | {
|
|---|
| 210 | char *cappath;
|
|---|
| 211 | char *tmp_base_name = NULL;
|
|---|
| 212 | int ret;
|
|---|
| 213 |
|
|---|
| 214 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
|---|
| 215 |
|
|---|
| 216 | if (!cappath) {
|
|---|
| 217 | errno = ENOMEM;
|
|---|
| 218 | return -1;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | tmp_base_name = smb_fname->base_name;
|
|---|
| 222 | smb_fname->base_name = cappath;
|
|---|
| 223 |
|
|---|
| 224 | ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
|
|---|
| 225 |
|
|---|
| 226 | smb_fname->base_name = tmp_base_name;
|
|---|
| 227 | TALLOC_FREE(cappath);
|
|---|
| 228 |
|
|---|
| 229 | return ret;
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | static int cap_unlink(vfs_handle_struct *handle,
|
|---|
| 233 | const struct smb_filename *smb_fname)
|
|---|
| 234 | {
|
|---|
| 235 | struct smb_filename *smb_fname_tmp = NULL;
|
|---|
| 236 | char *cappath = NULL;
|
|---|
| 237 | NTSTATUS status;
|
|---|
| 238 | int ret;
|
|---|
| 239 |
|
|---|
| 240 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
|---|
| 241 | if (!cappath) {
|
|---|
| 242 | errno = ENOMEM;
|
|---|
| 243 | return -1;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | /* Setup temporary smb_filename structs. */
|
|---|
| 247 | status = copy_smb_filename(talloc_tos(), smb_fname,
|
|---|
| 248 | &smb_fname_tmp);
|
|---|
| 249 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 250 | errno = map_errno_from_nt_status(status);
|
|---|
| 251 | return -1;
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | smb_fname_tmp->base_name = cappath;
|
|---|
| 255 |
|
|---|
| 256 | ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
|
|---|
| 257 |
|
|---|
| 258 | TALLOC_FREE(smb_fname_tmp);
|
|---|
| 259 | return ret;
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | static int cap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
|
|---|
| 263 | {
|
|---|
| 264 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 265 |
|
|---|
| 266 | if (!cappath) {
|
|---|
| 267 | errno = ENOMEM;
|
|---|
| 268 | return -1;
|
|---|
| 269 | }
|
|---|
| 270 | return SMB_VFS_NEXT_CHMOD(handle, cappath, mode);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | static int cap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
|
|---|
| 274 | {
|
|---|
| 275 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 276 |
|
|---|
| 277 | if (!cappath) {
|
|---|
| 278 | errno = ENOMEM;
|
|---|
| 279 | return -1;
|
|---|
| 280 | }
|
|---|
| 281 | return SMB_VFS_NEXT_CHOWN(handle, cappath, uid, gid);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | static int cap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
|
|---|
| 285 | {
|
|---|
| 286 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 287 |
|
|---|
| 288 | if (!cappath) {
|
|---|
| 289 | errno = ENOMEM;
|
|---|
| 290 | return -1;
|
|---|
| 291 | }
|
|---|
| 292 | return SMB_VFS_NEXT_LCHOWN(handle, cappath, uid, gid);
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | static int cap_chdir(vfs_handle_struct *handle, const char *path)
|
|---|
| 296 | {
|
|---|
| 297 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 298 |
|
|---|
| 299 | if (!cappath) {
|
|---|
| 300 | errno = ENOMEM;
|
|---|
| 301 | return -1;
|
|---|
| 302 | }
|
|---|
| 303 | DEBUG(3,("cap: cap_chdir for %s\n", path));
|
|---|
| 304 | return SMB_VFS_NEXT_CHDIR(handle, cappath);
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | static int cap_ntimes(vfs_handle_struct *handle,
|
|---|
| 308 | const struct smb_filename *smb_fname,
|
|---|
| 309 | struct smb_file_time *ft)
|
|---|
| 310 | {
|
|---|
| 311 | struct smb_filename *smb_fname_tmp = NULL;
|
|---|
| 312 | char *cappath = NULL;
|
|---|
| 313 | NTSTATUS status;
|
|---|
| 314 | int ret;
|
|---|
| 315 |
|
|---|
| 316 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
|---|
| 317 |
|
|---|
| 318 | if (!cappath) {
|
|---|
| 319 | errno = ENOMEM;
|
|---|
| 320 | return -1;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | /* Setup temporary smb_filename structs. */
|
|---|
| 324 | status = copy_smb_filename(talloc_tos(), smb_fname,
|
|---|
| 325 | &smb_fname_tmp);
|
|---|
| 326 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 327 | errno = map_errno_from_nt_status(status);
|
|---|
| 328 | return -1;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | smb_fname_tmp->base_name = cappath;
|
|---|
| 332 |
|
|---|
| 333 | ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
|
|---|
| 334 |
|
|---|
| 335 | TALLOC_FREE(smb_fname_tmp);
|
|---|
| 336 | return ret;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 | static int cap_symlink(vfs_handle_struct *handle, const char *oldpath,
|
|---|
| 341 | const char *newpath)
|
|---|
| 342 | {
|
|---|
| 343 | char *capold = capencode(talloc_tos(), oldpath);
|
|---|
| 344 | char *capnew = capencode(talloc_tos(), newpath);
|
|---|
| 345 |
|
|---|
| 346 | if (!capold || !capnew) {
|
|---|
| 347 | errno = ENOMEM;
|
|---|
| 348 | return -1;
|
|---|
| 349 | }
|
|---|
| 350 | return SMB_VFS_NEXT_SYMLINK(handle, capold, capnew);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | static int cap_readlink(vfs_handle_struct *handle, const char *path,
|
|---|
| 354 | char *buf, size_t bufsiz)
|
|---|
| 355 | {
|
|---|
| 356 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 357 |
|
|---|
| 358 | if (!cappath) {
|
|---|
| 359 | errno = ENOMEM;
|
|---|
| 360 | return -1;
|
|---|
| 361 | }
|
|---|
| 362 | return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz);
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
|
|---|
| 366 | {
|
|---|
| 367 | char *capold = capencode(talloc_tos(), oldpath);
|
|---|
| 368 | char *capnew = capencode(talloc_tos(), newpath);
|
|---|
| 369 |
|
|---|
| 370 | if (!capold || !capnew) {
|
|---|
| 371 | errno = ENOMEM;
|
|---|
| 372 | return -1;
|
|---|
| 373 | }
|
|---|
| 374 | return SMB_VFS_NEXT_LINK(handle, capold, capnew);
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev)
|
|---|
| 378 | {
|
|---|
| 379 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 380 |
|
|---|
| 381 | if (!cappath) {
|
|---|
| 382 | errno = ENOMEM;
|
|---|
| 383 | return -1;
|
|---|
| 384 | }
|
|---|
| 385 | return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | static char *cap_realpath(vfs_handle_struct *handle, const char *path)
|
|---|
| 389 | {
|
|---|
| 390 | /* monyo need capencode'ed and capdecode'ed? */
|
|---|
| 391 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 392 |
|
|---|
| 393 | if (!cappath) {
|
|---|
| 394 | errno = ENOMEM;
|
|---|
| 395 | return NULL;
|
|---|
| 396 | }
|
|---|
| 397 | return SMB_VFS_NEXT_REALPATH(handle, cappath);
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | static int cap_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
|
|---|
| 401 | {
|
|---|
| 402 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 403 |
|
|---|
| 404 | /* If the underlying VFS doesn't have ACL support... */
|
|---|
| 405 | if (!cappath) {
|
|---|
| 406 | errno = ENOMEM;
|
|---|
| 407 | return -1;
|
|---|
| 408 | }
|
|---|
| 409 | return SMB_VFS_NEXT_CHMOD_ACL(handle, cappath, mode);
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle, const char *path, SMB_ACL_TYPE_T type)
|
|---|
| 413 | {
|
|---|
| 414 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 415 |
|
|---|
| 416 | if (!cappath) {
|
|---|
| 417 | errno = ENOMEM;
|
|---|
| 418 | return (SMB_ACL_T)NULL;
|
|---|
| 419 | }
|
|---|
| 420 | return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, cappath, type);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | static int cap_sys_acl_set_file(vfs_handle_struct *handle, const char *path, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
|
|---|
| 424 | {
|
|---|
| 425 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 426 |
|
|---|
| 427 | if (!cappath) {
|
|---|
| 428 | errno = ENOMEM;
|
|---|
| 429 | return -1;
|
|---|
| 430 | }
|
|---|
| 431 | return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, cappath, acltype, theacl);
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path)
|
|---|
| 435 | {
|
|---|
| 436 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 437 |
|
|---|
| 438 | if (!cappath) {
|
|---|
| 439 | errno = ENOMEM;
|
|---|
| 440 | return -1;
|
|---|
| 441 | }
|
|---|
| 442 | return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, cappath);
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | static ssize_t cap_getxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size)
|
|---|
| 446 | {
|
|---|
| 447 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 448 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 449 |
|
|---|
| 450 | if (!cappath || !capname) {
|
|---|
| 451 | errno = ENOMEM;
|
|---|
| 452 | return -1;
|
|---|
| 453 | }
|
|---|
| 454 | return SMB_VFS_NEXT_GETXATTR(handle, cappath, capname, value, size);
|
|---|
| 455 | }
|
|---|
| 456 |
|
|---|
| 457 | static ssize_t cap_lgetxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t
|
|---|
| 458 | size)
|
|---|
| 459 | {
|
|---|
| 460 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 461 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 462 |
|
|---|
| 463 | if (!cappath || !capname) {
|
|---|
| 464 | errno = ENOMEM;
|
|---|
| 465 | return -1;
|
|---|
| 466 | }
|
|---|
| 467 | return SMB_VFS_NEXT_LGETXATTR(handle, cappath, capname, value, size);
|
|---|
| 468 | }
|
|---|
| 469 |
|
|---|
| 470 | static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, void *value, size_t size)
|
|---|
| 471 | {
|
|---|
| 472 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 473 |
|
|---|
| 474 | if (!cappath) {
|
|---|
| 475 | errno = ENOMEM;
|
|---|
| 476 | return -1;
|
|---|
| 477 | }
|
|---|
| 478 | return SMB_VFS_NEXT_FGETXATTR(handle, fsp, cappath, value, size);
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | static ssize_t cap_listxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
|
|---|
| 482 | {
|
|---|
| 483 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 484 |
|
|---|
| 485 | if (!cappath) {
|
|---|
| 486 | errno = ENOMEM;
|
|---|
| 487 | return -1;
|
|---|
| 488 | }
|
|---|
| 489 | return SMB_VFS_NEXT_LISTXATTR(handle, cappath, list, size);
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | static ssize_t cap_llistxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
|
|---|
| 493 | {
|
|---|
| 494 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 495 |
|
|---|
| 496 | if (!cappath) {
|
|---|
| 497 | errno = ENOMEM;
|
|---|
| 498 | return -1;
|
|---|
| 499 | }
|
|---|
| 500 | return SMB_VFS_NEXT_LLISTXATTR(handle, cappath, list, size);
|
|---|
| 501 | }
|
|---|
| 502 |
|
|---|
| 503 | static int cap_removexattr(vfs_handle_struct *handle, const char *path, const char *name)
|
|---|
| 504 | {
|
|---|
| 505 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 506 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 507 |
|
|---|
| 508 | if (!cappath || !capname) {
|
|---|
| 509 | errno = ENOMEM;
|
|---|
| 510 | return -1;
|
|---|
| 511 | }
|
|---|
| 512 | return SMB_VFS_NEXT_REMOVEXATTR(handle, cappath, capname);
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | static int cap_lremovexattr(vfs_handle_struct *handle, const char *path, const char *name)
|
|---|
| 516 | {
|
|---|
| 517 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 518 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 519 |
|
|---|
| 520 | if (!cappath || !capname) {
|
|---|
| 521 | errno = ENOMEM;
|
|---|
| 522 | return -1;
|
|---|
| 523 | }
|
|---|
| 524 | return SMB_VFS_NEXT_LREMOVEXATTR(handle, cappath, capname);
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path)
|
|---|
| 528 | {
|
|---|
| 529 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 530 |
|
|---|
| 531 | if (!cappath) {
|
|---|
| 532 | errno = ENOMEM;
|
|---|
| 533 | return -1;
|
|---|
| 534 | }
|
|---|
| 535 | return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, cappath);
|
|---|
| 536 | }
|
|---|
| 537 |
|
|---|
| 538 | static int cap_setxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
|
|---|
| 539 | {
|
|---|
| 540 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 541 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 542 |
|
|---|
| 543 | if (!cappath || !capname) {
|
|---|
| 544 | errno = ENOMEM;
|
|---|
| 545 | return -1;
|
|---|
| 546 | }
|
|---|
| 547 | return SMB_VFS_NEXT_SETXATTR(handle, cappath, capname, value, size, flags);
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | static int cap_lsetxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
|
|---|
| 551 | {
|
|---|
| 552 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 553 | char *capname = capencode(talloc_tos(), name);
|
|---|
| 554 |
|
|---|
| 555 | if (!cappath || !capname) {
|
|---|
| 556 | errno = ENOMEM;
|
|---|
| 557 | return -1;
|
|---|
| 558 | }
|
|---|
| 559 | return SMB_VFS_NEXT_LSETXATTR(handle, cappath, capname, value, size, flags);
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, const void *value, size_t size, int flags)
|
|---|
| 563 | {
|
|---|
| 564 | char *cappath = capencode(talloc_tos(), path);
|
|---|
| 565 |
|
|---|
| 566 | if (!cappath) {
|
|---|
| 567 | errno = ENOMEM;
|
|---|
| 568 | return -1;
|
|---|
| 569 | }
|
|---|
| 570 | return SMB_VFS_NEXT_FSETXATTR(handle, fsp, cappath, value, size, flags);
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | static struct vfs_fn_pointers vfs_cap_fns = {
|
|---|
| 574 | .disk_free = cap_disk_free,
|
|---|
| 575 | .opendir = cap_opendir,
|
|---|
| 576 | .readdir = cap_readdir,
|
|---|
| 577 | .mkdir = cap_mkdir,
|
|---|
| 578 | .rmdir = cap_rmdir,
|
|---|
| 579 | .open_fn = cap_open,
|
|---|
| 580 | .rename = cap_rename,
|
|---|
| 581 | .stat = cap_stat,
|
|---|
| 582 | .lstat = cap_lstat,
|
|---|
| 583 | .unlink = cap_unlink,
|
|---|
| 584 | .chmod = cap_chmod,
|
|---|
| 585 | .chown = cap_chown,
|
|---|
| 586 | .lchown = cap_lchown,
|
|---|
| 587 | .chdir = cap_chdir,
|
|---|
| 588 | .ntimes = cap_ntimes,
|
|---|
| 589 | .symlink = cap_symlink,
|
|---|
| 590 | .vfs_readlink = cap_readlink,
|
|---|
| 591 | .link = cap_link,
|
|---|
| 592 | .mknod = cap_mknod,
|
|---|
| 593 | .realpath = cap_realpath,
|
|---|
| 594 | .chmod_acl = cap_chmod_acl,
|
|---|
| 595 | .sys_acl_get_file = cap_sys_acl_get_file,
|
|---|
| 596 | .sys_acl_set_file = cap_sys_acl_set_file,
|
|---|
| 597 | .sys_acl_delete_def_file = cap_sys_acl_delete_def_file,
|
|---|
| 598 | .getxattr = cap_getxattr,
|
|---|
| 599 | .lgetxattr = cap_lgetxattr,
|
|---|
| 600 | .fgetxattr = cap_fgetxattr,
|
|---|
| 601 | .listxattr = cap_listxattr,
|
|---|
| 602 | .llistxattr = cap_llistxattr,
|
|---|
| 603 | .removexattr = cap_removexattr,
|
|---|
| 604 | .lremovexattr = cap_lremovexattr,
|
|---|
| 605 | .fremovexattr = cap_fremovexattr,
|
|---|
| 606 | .setxattr = cap_setxattr,
|
|---|
| 607 | .lsetxattr = cap_lsetxattr,
|
|---|
| 608 | .fsetxattr = cap_fsetxattr
|
|---|
| 609 | };
|
|---|
| 610 |
|
|---|
| 611 | NTSTATUS vfs_cap_init(void);
|
|---|
| 612 | NTSTATUS vfs_cap_init(void)
|
|---|
| 613 | {
|
|---|
| 614 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "cap",
|
|---|
| 615 | &vfs_cap_fns);
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | /* For CAP functions */
|
|---|
| 619 | #define hex_tag ':'
|
|---|
| 620 | #define hex2bin(c) hex2bin_table[(unsigned char)(c)]
|
|---|
| 621 | #define bin2hex(c) bin2hex_table[(unsigned char)(c)]
|
|---|
| 622 | #define is_hex(s) ((s)[0] == hex_tag)
|
|---|
| 623 |
|
|---|
| 624 | static unsigned char hex2bin_table[256] = {
|
|---|
| 625 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
|
|---|
| 626 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
|
|---|
| 627 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
|
|---|
| 628 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
|
|---|
| 629 | 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x40 */
|
|---|
| 630 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
|
|---|
| 631 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
|
|---|
| 632 | 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x60 */
|
|---|
| 633 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
|
|---|
| 634 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 */
|
|---|
| 635 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 */
|
|---|
| 636 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 */
|
|---|
| 637 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */
|
|---|
| 638 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */
|
|---|
| 639 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */
|
|---|
| 640 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */
|
|---|
| 641 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */
|
|---|
| 642 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xf0 */
|
|---|
| 643 | };
|
|---|
| 644 | static unsigned char bin2hex_table[256] = "0123456789abcdef";
|
|---|
| 645 |
|
|---|
| 646 | /*******************************************************************
|
|---|
| 647 | original code -> ":xx" - CAP format
|
|---|
| 648 | ********************************************************************/
|
|---|
| 649 |
|
|---|
| 650 | static char *capencode(TALLOC_CTX *ctx, const char *from)
|
|---|
| 651 | {
|
|---|
| 652 | char *out = NULL;
|
|---|
| 653 | const char *p1;
|
|---|
| 654 | char *to = NULL;
|
|---|
| 655 | size_t len = 0;
|
|---|
| 656 |
|
|---|
| 657 | for (p1 = from; *p1; p1++) {
|
|---|
| 658 | if ((unsigned char)*p1 >= 0x80) {
|
|---|
| 659 | len += 3;
|
|---|
| 660 | } else {
|
|---|
| 661 | len++;
|
|---|
| 662 | }
|
|---|
| 663 | }
|
|---|
| 664 | len++;
|
|---|
| 665 |
|
|---|
| 666 | to = TALLOC_ARRAY(ctx, char, len);
|
|---|
| 667 | if (!to) {
|
|---|
| 668 | return NULL;
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | for (out = to; *from;) {
|
|---|
| 672 | /* buffer husoku error */
|
|---|
| 673 | if ((unsigned char)*from >= 0x80) {
|
|---|
| 674 | *out++ = hex_tag;
|
|---|
| 675 | *out++ = bin2hex (((*from)>>4)&0x0f);
|
|---|
| 676 | *out++ = bin2hex ((*from)&0x0f);
|
|---|
| 677 | from++;
|
|---|
| 678 | } else {
|
|---|
| 679 | *out++ = *from++;
|
|---|
| 680 | }
|
|---|
| 681 | }
|
|---|
| 682 | *out = '\0';
|
|---|
| 683 | return to;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | /*******************************************************************
|
|---|
| 687 | CAP -> original code
|
|---|
| 688 | ********************************************************************/
|
|---|
| 689 | /* ":xx" -> a byte */
|
|---|
| 690 |
|
|---|
| 691 | static char *capdecode(TALLOC_CTX *ctx, const char *from)
|
|---|
| 692 | {
|
|---|
| 693 | const char *p1;
|
|---|
| 694 | char *out = NULL;
|
|---|
| 695 | char *to = NULL;
|
|---|
| 696 | size_t len = 0;
|
|---|
| 697 |
|
|---|
| 698 | for (p1 = from; *p1; len++) {
|
|---|
| 699 | if (is_hex(p1)) {
|
|---|
| 700 | p1 += 3;
|
|---|
| 701 | } else {
|
|---|
| 702 | p1++;
|
|---|
| 703 | }
|
|---|
| 704 | }
|
|---|
| 705 | len++;
|
|---|
| 706 |
|
|---|
| 707 | to = TALLOC_ARRAY(ctx, char, len);
|
|---|
| 708 | if (!to) {
|
|---|
| 709 | return NULL;
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | for (out = to; *from;) {
|
|---|
| 713 | if (is_hex(from)) {
|
|---|
| 714 | *out++ = (hex2bin(from[1])<<4) | (hex2bin(from[2]));
|
|---|
| 715 | from += 3;
|
|---|
| 716 | } else {
|
|---|
| 717 | *out++ = *from++;
|
|---|
| 718 | }
|
|---|
| 719 | }
|
|---|
| 720 | *out = '\0';
|
|---|
| 721 | return to;
|
|---|
| 722 | }
|
|---|