s3:lib: add is_named_stream()
authorRalph Boehme <slow@samba.org>
Thu, 26 Sep 2019 17:05:40 +0000 (10:05 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 2 Oct 2019 08:01:40 +0000 (08:01 +0000)
Add a new utility functions that checks whether a struct smb_filename points to
a real named stream, excluding the default stream "::$DATA".

  foo           -> false
  foo::$DATA    -> false
  foo:bar       -> true
  foo:bar:$DATA -> true

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14137

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/filename_util.c

index 0d02f38fc8be22977decb21f2f6fc35fa301a520..91a7c00fef293b8833bb77acd948625274947362 100644 (file)
@@ -985,6 +985,7 @@ struct smb_filename *cp_smb_filename_nostream(TALLOC_CTX *mem_ctx,
                                     const struct smb_filename *in);
 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname);
 bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname);
+bool is_named_stream(const struct smb_filename *smb_fname);
 bool is_invalid_windows_ea_name(const char *name);
 bool ea_list_has_invalid_name(struct ea_list *ea_list);
 bool split_stream_filename(TALLOC_CTX *ctx,
index 2917481c8bfa91e6dd25f257ee728f678f99704a..66c07001eba273b0424ad03f31cc8312040b0ff6 100644 (file)
@@ -267,6 +267,32 @@ bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
        return true;
 }
 
+/****************************************************************************
+ Simple check to determine if a smb_fname is pointing to a normal file or
+ a named stream that is not the default stream "::$DATA".
+
+  foo           -> false
+  foo::$DATA    -> false
+  foo:bar       -> true
+  foo:bar:$DATA -> true
+
+ ***************************************************************************/
+
+bool is_named_stream(const struct smb_filename *smb_fname)
+{
+       assert_valid_stream_smb_fname(smb_fname);
+
+       if (smb_fname->stream_name == NULL) {
+               return false;
+       }
+
+       if (strequal_m(smb_fname->stream_name, "::$DATA")) {
+               return false;
+       }
+
+       return true;
+}
+
 /****************************************************************************
  Returns true if the filename's stream == "::$DATA"
  ***************************************************************************/