root/source3/modules/vfs_streams_depot.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. hash_fn
  2. file_is_valid
  3. mark_file_valid
  4. stream_dir
  5. stream_name
  6. walk_streams
  7. streams_depot_stat
  8. streams_depot_lstat
  9. streams_depot_open
  10. streams_depot_unlink
  11. streams_depot_rename
  12. add_one_stream
  13. collect_one_stream
  14. streams_depot_streaminfo
  15. streams_depot_fs_capabilities
  16. vfs_streams_depot_init

   1 /*
   2  * Store streams in a separate subdirectory
   3  *
   4  * Copyright (C) Volker Lendecke, 2007
   5  *
   6  * This program is free software; you can redistribute it and/or modify
   7  * it under the terms of the GNU General Public License as published by
   8  * the Free Software Foundation; either version 3 of the License, or
   9  * (at your option) any later version.
  10  *
  11  * This program is distributed in the hope that it will be useful,
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  * GNU General Public License for more details.
  15  *
  16  * You should have received a copy of the GNU General Public License
  17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18  */
  19 
  20 #include "includes.h"
  21 
  22 #undef DBGC_CLASS
  23 #define DBGC_CLASS DBGC_VFS
  24 
  25 /*
  26  * Excerpt from a mail from tridge:
  27  *
  28  * Volker, what I'm thinking of is this:
  29  * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream1
  30  * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream2
  31  *
  32  * where XX/YY is a 2 level hash based on the fsid/inode. "aaaa.bbbb"
  33  * is the fsid/inode. "namedstreamX" is a file named after the stream
  34  * name.
  35  */
  36 
  37 static uint32_t hash_fn(DATA_BLOB key)
     /* [<][>][^][v][top][bottom][index][help] */
  38 {
  39         uint32_t value; /* Used to compute the hash value.  */
  40         uint32_t i;     /* Used to cycle through random values. */
  41 
  42         /* Set the initial value from the key size. */
  43         for (value = 0x238F13AF * key.length, i=0; i < key.length; i++)
  44                 value = (value + (key.data[i] << (i*5 % 24)));
  45 
  46         return (1103515243 * value + 12345);
  47 }
  48 
  49 /*
  50  * With the hashing scheme based on the inode we need to protect against
  51  * streams showing up on files with re-used inodes. This can happen if we
  52  * create a stream directory from within Samba, and a local process or NFS
  53  * client deletes the file without deleting the streams directory. When the
  54  * inode is re-used and the stream directory is still around, the streams in
  55  * there would be show up as belonging to the new file.
  56  *
  57  * There are several workarounds for this, probably the easiest one is on
  58  * systems which have a true birthtime stat element: When the file has a later
  59  * birthtime than the streams directory, then we have to recreate the
  60  * directory.
  61  *
  62  * The other workaround is to somehow mark the file as generated by Samba with
  63  * something that a NFS client would not do. The closest one is a special
  64  * xattr value being set. On systems which do not support xattrs, it might be
  65  * an option to put in a special ACL entry for a non-existing group.
  66  */
  67 
  68 #define SAMBA_XATTR_MARKER "user.SAMBA_STREAMS"
  69 
  70 static bool file_is_valid(vfs_handle_struct *handle, const char *path,
     /* [<][>][^][v][top][bottom][index][help] */
  71                           bool check_valid)
  72 {
  73         char buf;
  74 
  75         if (!check_valid) {
  76                 return true;
  77         }
  78 
  79         DEBUG(10, ("file_is_valid (%s) called\n", path));
  80 
  81         if (SMB_VFS_GETXATTR(handle->conn, path, SAMBA_XATTR_MARKER,
  82                                   &buf, sizeof(buf)) != sizeof(buf)) {
  83                 DEBUG(10, ("GETXATTR failed: %s\n", strerror(errno)));
  84                 return false;
  85         }
  86 
  87         if (buf != '1') {
  88                 DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
  89                 return false;
  90         }
  91 
  92         return true;
  93 }
  94 
  95 static bool mark_file_valid(vfs_handle_struct *handle, const char *path,
     /* [<][>][^][v][top][bottom][index][help] */
  96                             bool check_valid)
  97 {
  98         char buf = '1';
  99         int ret;
 100 
 101         if (!check_valid) {
 102                 return true;
 103         }
 104 
 105         DEBUG(10, ("marking file %s as valid\n", path));
 106 
 107         ret = SMB_VFS_SETXATTR(handle->conn, path, SAMBA_XATTR_MARKER,
 108                                     &buf, sizeof(buf), 0);
 109 
 110         if (ret == -1) {
 111                 DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno)));
 112                 return false;
 113         }
 114 
 115         return true;
 116 }
 117 
 118 static char *stream_dir(vfs_handle_struct *handle, const char *base_path,
     /* [<][>][^][v][top][bottom][index][help] */
 119                         const SMB_STRUCT_STAT *base_sbuf, bool create_it)
 120 {
 121         uint32_t hash;
 122         char *result = NULL;
 123         SMB_STRUCT_STAT sbuf;
 124         uint8_t first, second;
 125         char *tmp;
 126         char *id_hex;
 127         struct file_id id;
 128         uint8 id_buf[16];
 129         bool check_valid;
 130         const char *rootdir;
 131 
 132         check_valid = lp_parm_bool(SNUM(handle->conn),
 133                       "streams_depot", "check_valid", true);
 134 
 135         tmp = talloc_asprintf(talloc_tos(), "%s/.streams", handle->conn->connectpath);
 136 
 137         if (tmp == NULL) {
 138                 errno = ENOMEM;
 139                 goto fail;
 140         }
 141 
 142         rootdir = lp_parm_const_string(
 143                 SNUM(handle->conn), "streams_depot", "directory",
 144                 tmp);
 145 
 146         if (base_sbuf == NULL) {
 147                 if (SMB_VFS_NEXT_STAT(handle, base_path, &sbuf) == -1) {
 148                         /*
 149                          * base file is not there
 150                          */
 151                         goto fail;
 152                 }
 153                 base_sbuf = &sbuf;
 154         }
 155 
 156         id = SMB_VFS_FILE_ID_CREATE(handle->conn, base_sbuf);
 157 
 158         push_file_id_16((char *)id_buf, &id);
 159 
 160         hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
 161 
 162         first = hash & 0xff;
 163         second = (hash >> 8) & 0xff;
 164 
 165         id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
 166 
 167         if (id_hex == NULL) {
 168                 errno = ENOMEM;
 169                 goto fail;
 170         }
 171 
 172         result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
 173                                  first, second, id_hex);
 174 
 175         TALLOC_FREE(id_hex);
 176 
 177         if (result == NULL) {
 178                 errno = ENOMEM;
 179                 return NULL;
 180         }
 181 
 182         if (SMB_VFS_NEXT_STAT(handle, result, &sbuf) == 0) {
 183                 char *newname;
 184 
 185                 if (!S_ISDIR(sbuf.st_mode)) {
 186                         errno = EINVAL;
 187                         goto fail;
 188                 }
 189 
 190                 if (file_is_valid(handle, base_path, check_valid)) {
 191                         return result;
 192                 }
 193 
 194                 /*
 195                  * Someone has recreated a file under an existing inode
 196                  * without deleting the streams directory. For now, just move
 197                  * it away.
 198                  */
 199 
 200         again:
 201                 newname = talloc_asprintf(talloc_tos(), "lost-%lu", random());
 202                 if (newname == NULL) {
 203                         errno = ENOMEM;
 204                         goto fail;
 205                 }
 206 
 207                 if (SMB_VFS_NEXT_RENAME(handle, result, newname) == -1) {
 208                         if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
 209                                 TALLOC_FREE(newname);
 210                                 goto again;
 211                         }
 212                         goto fail;
 213                 }
 214 
 215                 TALLOC_FREE(newname);
 216         }
 217 
 218         if (!create_it) {
 219                 errno = ENOENT;
 220                 goto fail;
 221         }
 222 
 223         if ((SMB_VFS_NEXT_MKDIR(handle, rootdir, 0755) != 0)
 224             && (errno != EEXIST)) {
 225                 goto fail;
 226         }
 227 
 228         tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
 229         if (tmp == NULL) {
 230                 errno = ENOMEM;
 231                 goto fail;
 232         }
 233 
 234         if ((SMB_VFS_NEXT_MKDIR(handle, tmp, 0755) != 0)
 235             && (errno != EEXIST)) {
 236                 goto fail;
 237         }
 238 
 239         TALLOC_FREE(tmp);
 240 
 241         tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
 242                               second);
 243         if (tmp == NULL) {
 244                 errno = ENOMEM;
 245                 goto fail;
 246         }
 247 
 248         if ((SMB_VFS_NEXT_MKDIR(handle, tmp, 0755) != 0)
 249             && (errno != EEXIST)) {
 250                 goto fail;
 251         }
 252 
 253         TALLOC_FREE(tmp);
 254 
 255         if ((SMB_VFS_NEXT_MKDIR(handle, result, 0755) != 0)
 256             && (errno != EEXIST)) {
 257                 goto fail;
 258         }
 259 
 260         if (!mark_file_valid(handle, base_path, check_valid)) {
 261                 goto fail;
 262         }
 263 
 264         return result;
 265 
 266  fail:
 267         TALLOC_FREE(result);
 268         return NULL;
 269 }
 270 
 271 static char *stream_name(vfs_handle_struct *handle, const char *fname,
     /* [<][>][^][v][top][bottom][index][help] */
 272                          bool create_dir)
 273 {
 274         char *base = NULL;
 275         char *sname = NULL;
 276         char *id_hex = NULL;
 277         char *dirname, *stream_fname;
 278 
 279         if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
 280                                                     &base, &sname))) {
 281                 DEBUG(10, ("split_ntfs_stream_name failed\n"));
 282                 errno = ENOMEM;
 283                 goto fail;
 284         }
 285 
 286         /* if it's the ::$DATA stream just return the base file name */
 287         if (!sname) {
 288                 return base;
 289         }
 290 
 291         dirname = stream_dir(handle, base, NULL, create_dir);
 292 
 293         if (dirname == NULL) {
 294                 goto fail;
 295         }
 296 
 297         stream_fname = talloc_asprintf(talloc_tos(), "%s/:%s", dirname, sname);
 298 
 299         if (stream_fname == NULL) {
 300                 errno = ENOMEM;
 301                 goto fail;
 302         }
 303 
 304         DEBUG(10, ("stream filename = %s\n", stream_fname));
 305 
 306         TALLOC_FREE(base);
 307         TALLOC_FREE(sname);
 308         TALLOC_FREE(id_hex);
 309 
 310         return stream_fname;
 311 
 312  fail:
 313         DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
 314         TALLOC_FREE(base);
 315         TALLOC_FREE(sname);
 316         TALLOC_FREE(id_hex);
 317         return NULL;
 318 }
 319 
 320 static NTSTATUS walk_streams(vfs_handle_struct *handle,
     /* [<][>][^][v][top][bottom][index][help] */
 321                              const char *fname,
 322                              const SMB_STRUCT_STAT *sbuf,
 323                              char **pdirname,
 324                              bool (*fn)(const char *dirname,
 325                                         const char *dirent,
 326                                         void *private_data),
 327                              void *private_data)
 328 {
 329         char *dirname;
 330         SMB_STRUCT_DIR *dirhandle = NULL;
 331         char *dirent;
 332 
 333         dirname = stream_dir(handle, fname, sbuf, false);
 334 
 335         if (dirname == NULL) {
 336                 if (errno == ENOENT) {
 337                         /*
 338                          * no stream around
 339                          */
 340                         return NT_STATUS_OK;
 341                 }
 342                 return map_nt_error_from_unix(errno);
 343         }
 344 
 345         DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
 346 
 347         dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dirname, NULL, 0);
 348 
 349         if (dirhandle == NULL) {
 350                 TALLOC_FREE(dirname);
 351                 return map_nt_error_from_unix(errno);
 352         }
 353 
 354         while ((dirent = vfs_readdirname(handle->conn, dirhandle, NULL)) != NULL) {
 355 
 356                 if (ISDOT(dirent) || ISDOTDOT(dirent)) {
 357                         continue;
 358                 }
 359 
 360                 DEBUG(10, ("walk_streams: dirent=%s\n", dirent));
 361 
 362                 if (!fn(dirname, dirent, private_data)) {
 363                         break;
 364                 }
 365         }
 366 
 367         SMB_VFS_NEXT_CLOSEDIR(handle, dirhandle);
 368 
 369         if (pdirname != NULL) {
 370                 *pdirname = dirname;
 371         }
 372         else {
 373                 TALLOC_FREE(dirname);
 374         }
 375 
 376         return NT_STATUS_OK;
 377 }
 378 
 379 static int streams_depot_stat(vfs_handle_struct *handle, const char *fname,
     /* [<][>][^][v][top][bottom][index][help] */
 380                               SMB_STRUCT_STAT *sbuf)
 381 {
 382         char *stream_fname;
 383         int ret = -1;
 384 
 385         DEBUG(10, ("streams_depot_stat called for [%s]\n", fname));
 386 
 387         if (!is_ntfs_stream_name(fname)) {
 388                 return SMB_VFS_NEXT_STAT(handle, fname, sbuf);
 389         }
 390 
 391         stream_fname = stream_name(handle, fname, false);
 392         if (stream_fname == NULL) {
 393                 goto done;
 394         }
 395 
 396         ret = SMB_VFS_NEXT_STAT(handle, stream_fname, sbuf);
 397 
 398  done:
 399         TALLOC_FREE(stream_fname);
 400         return ret;
 401 }
 402 
 403 static int streams_depot_lstat(vfs_handle_struct *handle, const char *fname,
     /* [<][>][^][v][top][bottom][index][help] */
 404                                SMB_STRUCT_STAT *sbuf)
 405 {
 406         char *stream_fname;
 407         int ret = -1;
 408 
 409         if (!is_ntfs_stream_name(fname)) {
 410                 return SMB_VFS_NEXT_LSTAT(handle, fname, sbuf);
 411         }
 412 
 413         stream_fname = stream_name(handle, fname, false);
 414         if (stream_fname == NULL) {
 415                 goto done;
 416         }
 417 
 418         ret = SMB_VFS_NEXT_LSTAT(handle, stream_fname, sbuf);
 419 
 420  done:
 421         TALLOC_FREE(stream_fname);
 422         return ret;
 423 }
 424 
 425 static int streams_depot_open(vfs_handle_struct *handle,  const char *fname,
     /* [<][>][^][v][top][bottom][index][help] */
 426                               files_struct *fsp, int flags, mode_t mode)
 427 {
 428         TALLOC_CTX *frame;
 429         char *base = NULL;
 430         char *sname = NULL;
 431         SMB_STRUCT_STAT base_sbuf;
 432         char *stream_fname;
 433         int ret = -1;
 434 
 435         if (!is_ntfs_stream_name(fname)) {
 436                 return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
 437         }
 438 
 439         frame = talloc_stackframe();
 440 
 441         if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
 442                                                     &base, &sname))) {
 443                 errno = ENOMEM;
 444                 goto done;
 445         }
 446 
 447         if (!sname) {
 448                 ret = SMB_VFS_NEXT_OPEN(handle, base, fsp, flags, mode);
 449                 goto done;
 450         }
 451 
 452         ret = SMB_VFS_NEXT_STAT(handle, base, &base_sbuf);
 453 
 454         if (ret == -1) {
 455                 goto done;
 456         }
 457 
 458         TALLOC_FREE(base);
 459 
 460         stream_fname = stream_name(handle, fname, true);
 461         if (stream_fname == NULL) {
 462                 goto done;
 463         }
 464 
 465         ret = SMB_VFS_NEXT_OPEN(handle, stream_fname, fsp, flags, mode);
 466 
 467  done:
 468         TALLOC_FREE(frame);
 469         return ret;
 470 }
 471 
 472 static int streams_depot_unlink(vfs_handle_struct *handle,  const char *fname)
     /* [<][>][^][v][top][bottom][index][help] */
 473 {
 474         int ret = -1;
 475         SMB_STRUCT_STAT sbuf;
 476 
 477         DEBUG(10, ("streams_depot_unlink called for %s\n", fname));
 478 
 479         if (is_ntfs_stream_name(fname)) {
 480                 char *stream_fname;
 481 
 482                 stream_fname = stream_name(handle, fname, false);
 483                 if (stream_fname == NULL) {
 484                         return -1;
 485                 }
 486 
 487                 ret = SMB_VFS_NEXT_UNLINK(handle, stream_fname);
 488 
 489                 TALLOC_FREE(stream_fname);
 490                 return ret;
 491         }
 492 
 493         /*
 494          * We potentially need to delete the per-inode streams directory
 495          */
 496 
 497         if (lp_posix_pathnames()) {
 498                 ret = SMB_VFS_NEXT_LSTAT(handle, fname, &sbuf);
 499         } else {
 500                 ret = SMB_VFS_NEXT_STAT(handle, fname, &sbuf);
 501         }
 502 
 503         if (ret == -1) {
 504                 return -1;
 505         }
 506 
 507         if (sbuf.st_nlink == 1) {
 508                 char *dirname = stream_dir(handle, fname, &sbuf, false);
 509 
 510                 if (dirname != NULL) {
 511                         SMB_VFS_NEXT_RMDIR(handle, dirname);
 512                 }
 513                 TALLOC_FREE(dirname);
 514         }
 515 
 516         return SMB_VFS_NEXT_UNLINK(handle, fname);
 517 }
 518 
 519 static int streams_depot_rename(vfs_handle_struct *handle,
     /* [<][>][^][v][top][bottom][index][help] */
 520                                 const char *oldname,
 521                                 const char *newname)
 522 {
 523         TALLOC_CTX *frame = NULL;
 524         int ret = -1;
 525         bool old_is_stream;
 526         bool new_is_stream;
 527         char *obase = NULL;
 528         char *osname = NULL;
 529         char *nbase = NULL;
 530         char *nsname = NULL;
 531         char *ostream_fname = NULL;
 532         char *nstream_fname = NULL;
 533         char *newname_full = NULL;
 534 
 535         DEBUG(10, ("streams_depot_rename called for %s => %s\n",
 536                    oldname, newname));
 537 
 538         old_is_stream = is_ntfs_stream_name(oldname);
 539         new_is_stream = is_ntfs_stream_name(newname);
 540 
 541         if (!old_is_stream && !new_is_stream) {
 542                 return SMB_VFS_NEXT_RENAME(handle, oldname, newname);
 543         }
 544 
 545         frame = talloc_stackframe();
 546 
 547         if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), oldname,
 548                                                     &obase, &osname))) {
 549                 errno = ENOMEM;
 550                 goto done;
 551         }
 552 
 553         if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), newname,
 554                                                     &nbase, &nsname))) {
 555                 errno = ENOMEM;
 556                 goto done;
 557         }
 558 
 559         /* for now don't allow renames from or to the default stream */
 560         if (!osname || !nsname) {
 561                 errno = ENOSYS;
 562                 goto done;
 563         }
 564 
 565         ostream_fname = stream_name(handle, oldname, false);
 566         if (ostream_fname == NULL) {
 567                 return -1;
 568         }
 569 
 570         /*
 571          * Handle passing in a stream name without the base file.  This is
 572          * exercised by the NTRENAME streams rename path.
 573          */
 574         if (StrCaseCmp(nbase, "./") == 0) {
 575                 newname_full = talloc_asprintf(talloc_tos(), "%s:%s", obase,
 576                                                nsname);
 577                 if (newname_full == NULL) {
 578                         errno = ENOMEM;
 579                         goto done;
 580                 }
 581         }
 582 
 583         nstream_fname = stream_name(handle,
 584                                     newname_full ? newname_full : newname,
 585                                     false);
 586         if (nstream_fname == NULL) {
 587                 return -1;
 588         }
 589 
 590         ret = SMB_VFS_NEXT_RENAME(handle, ostream_fname, nstream_fname);
 591 
 592 done:
 593         TALLOC_FREE(frame);
 594         return ret;
 595 }
 596 
 597 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
     /* [<][>][^][v][top][bottom][index][help] */
 598                            struct stream_struct **streams,
 599                            const char *name, SMB_OFF_T size,
 600                            SMB_OFF_T alloc_size)
 601 {
 602         struct stream_struct *tmp;
 603 
 604         tmp = TALLOC_REALLOC_ARRAY(mem_ctx, *streams, struct stream_struct,
 605                                    (*num_streams)+1);
 606         if (tmp == NULL) {
 607                 return false;
 608         }
 609 
 610         tmp[*num_streams].name = talloc_strdup(tmp, name);
 611         if (tmp[*num_streams].name == NULL) {
 612                 return false;
 613         }
 614 
 615         tmp[*num_streams].size = size;
 616         tmp[*num_streams].alloc_size = alloc_size;
 617 
 618         *streams = tmp;
 619         *num_streams += 1;
 620         return true;
 621 }
 622 
 623 struct streaminfo_state {
 624         TALLOC_CTX *mem_ctx;
 625         vfs_handle_struct *handle;
 626         unsigned int num_streams;
 627         struct stream_struct *streams;
 628         NTSTATUS status;
 629 };
 630 
 631 static bool collect_one_stream(const char *dirname,
     /* [<][>][^][v][top][bottom][index][help] */
 632                                const char *dirent,
 633                                void *private_data)
 634 {
 635         struct streaminfo_state *state =
 636                 (struct streaminfo_state *)private_data;
 637         char *full_sname;
 638         SMB_STRUCT_STAT sbuf;
 639 
 640         if (asprintf(&full_sname, "%s/%s", dirname, dirent) == -1) {
 641                 state->status = NT_STATUS_NO_MEMORY;
 642                 return false;
 643         }
 644         if (SMB_VFS_NEXT_STAT(state->handle, full_sname, &sbuf) == -1) {
 645                 DEBUG(10, ("Could not stat %s: %s\n", full_sname,
 646                            strerror(errno)));
 647                 SAFE_FREE(full_sname);
 648                 return true;
 649         }
 650 
 651         SAFE_FREE(full_sname);
 652 
 653         if (!add_one_stream(state->mem_ctx,
 654                             &state->num_streams, &state->streams,
 655                             dirent, sbuf.st_size,
 656                             SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
 657                                                    &sbuf))) {
 658                 state->status = NT_STATUS_NO_MEMORY;
 659                 return false;
 660         }
 661 
 662         return true;
 663 }
 664 
 665 static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
     /* [<][>][^][v][top][bottom][index][help] */
 666                                          struct files_struct *fsp,
 667                                          const char *fname,
 668                                          TALLOC_CTX *mem_ctx,
 669                                          unsigned int *pnum_streams,
 670                                          struct stream_struct **pstreams)
 671 {
 672         SMB_STRUCT_STAT sbuf;
 673         int ret;
 674         NTSTATUS status;
 675         struct streaminfo_state state;
 676 
 677         if ((fsp != NULL) && (fsp->fh->fd != -1)) {
 678                 if (is_ntfs_stream_name(fsp->fsp_name)) {
 679                         return NT_STATUS_INVALID_PARAMETER;
 680                 }
 681                 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &sbuf);
 682         }
 683         else {
 684                 if (is_ntfs_stream_name(fname)) {
 685                         return NT_STATUS_INVALID_PARAMETER;
 686                 }
 687                 if (lp_posix_pathnames()) {
 688                         ret = SMB_VFS_NEXT_LSTAT(handle, fname, &sbuf);
 689                 } else {
 690                         ret = SMB_VFS_NEXT_STAT(handle, fname, &sbuf);
 691                 }
 692         }
 693 
 694         if (ret == -1) {
 695                 return map_nt_error_from_unix(errno);
 696         }
 697 
 698         state.streams = NULL;
 699         state.num_streams = 0;
 700 
 701         if (!S_ISDIR(sbuf.st_mode)) {
 702                 if (!add_one_stream(mem_ctx,
 703                                     &state.num_streams, &state.streams,
 704                                     "::$DATA", sbuf.st_size,
 705                                     SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp,
 706                                                            &sbuf))) {
 707                         return NT_STATUS_NO_MEMORY;
 708                 }
 709         }
 710 
 711         state.mem_ctx = mem_ctx;
 712         state.handle = handle;
 713         state.status = NT_STATUS_OK;
 714 
 715         status = walk_streams(handle, fname, &sbuf, NULL, collect_one_stream,
 716                               &state);
 717 
 718         if (!NT_STATUS_IS_OK(status)) {
 719                 TALLOC_FREE(state.streams);
 720                 return status;
 721         }
 722 
 723         if (!NT_STATUS_IS_OK(state.status)) {
 724                 TALLOC_FREE(state.streams);
 725                 return state.status;
 726         }
 727 
 728         *pnum_streams = state.num_streams;
 729         *pstreams = state.streams;
 730         return NT_STATUS_OK;
 731 }
 732 
 733 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle)
     /* [<][>][^][v][top][bottom][index][help] */
 734 {
 735         return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
 736 }
 737 
 738 /* VFS operations structure */
 739 
 740 static vfs_op_tuple streams_depot_ops[] = {
 741         {SMB_VFS_OP(streams_depot_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
 742          SMB_VFS_LAYER_TRANSPARENT},
 743         {SMB_VFS_OP(streams_depot_open), SMB_VFS_OP_OPEN,
 744          SMB_VFS_LAYER_TRANSPARENT},
 745         {SMB_VFS_OP(streams_depot_stat), SMB_VFS_OP_STAT,
 746          SMB_VFS_LAYER_TRANSPARENT},
 747         {SMB_VFS_OP(streams_depot_lstat), SMB_VFS_OP_LSTAT,
 748          SMB_VFS_LAYER_TRANSPARENT},
 749         {SMB_VFS_OP(streams_depot_unlink), SMB_VFS_OP_UNLINK,
 750          SMB_VFS_LAYER_TRANSPARENT},
 751         {SMB_VFS_OP(streams_depot_rename), SMB_VFS_OP_RENAME,
 752          SMB_VFS_LAYER_TRANSPARENT},
 753         {SMB_VFS_OP(streams_depot_streaminfo), SMB_VFS_OP_STREAMINFO,
 754          SMB_VFS_LAYER_OPAQUE},
 755         {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
 756 };
 757 
 758 NTSTATUS vfs_streams_depot_init(void);
 759 NTSTATUS vfs_streams_depot_init(void)
     /* [<][>][^][v][top][bottom][index][help] */
 760 {
 761         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
 762                                 streams_depot_ops);
 763 }

/* [<][>][^][v][top][bottom][index][help] */