summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorAlexander Bokovoy <ab@samba.org>2008-01-24 14:06:22 +0300
committerAlexander Bokovoy <ab@samba.org>2008-01-24 14:06:22 +0300
commiteba5fbff749b84a3e1bcd1f849c3454417532454 (patch)
tree42b9da9b96fb26706f4c8486cd01821f83e318f3 /source3/lib/util.c
parentc17c64530ec479334f88679ef780691e06ccd65a (diff)
parent9344628bef74ac759197601dc5dd44514b836e3e (diff)
downloadsamba-eba5fbff749b84a3e1bcd1f849c3454417532454.tar.gz
samba-eba5fbff749b84a3e1bcd1f849c3454417532454.tar.bz2
samba-eba5fbff749b84a3e1bcd1f849c3454417532454.zip
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into ctdb-merge
(This used to be commit 42d06d41bf2e9fb094f6064dc04f549d880b5f8d)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index bc3eaa8d5e..e5ac3752f5 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2182,7 +2182,7 @@ void dump_data_pw(const char *msg, const uchar * data, size_t len)
const char *tab_depth(int level, int depth)
{
- if( DEBUGLVL(level) ) {
+ if( CHECK_DEBUGLVL(level) ) {
dbgtext("%*s", depth*4, "");
}
return "";
@@ -3273,3 +3273,93 @@ void *talloc_zeronull(const void *context, size_t size, const char *name)
return talloc_named_const(context, size, name);
}
#endif
+
+/* Split a path name into filename and stream name components. Canonicalise
+ * such that an implicit $DATA token is always explicit.
+ *
+ * The "specification" of this function can be found in the
+ * run_local_stream_name() function in torture.c, I've tried those
+ * combinations against a W2k3 server.
+ */
+
+NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
+ char **pbase, char **pstream)
+{
+ char *base = NULL;
+ char *stream = NULL;
+ char *sname; /* stream name */
+ const char *stype; /* stream type */
+
+ DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
+
+ sname = strchr_m(fname, ':');
+
+ if (lp_posix_pathnames() || (sname == NULL)) {
+ if (pbase != NULL) {
+ base = talloc_strdup(mem_ctx, fname);
+ NT_STATUS_HAVE_NO_MEMORY(base);
+ }
+ goto done;
+ }
+
+ if (pbase != NULL) {
+ base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
+ NT_STATUS_HAVE_NO_MEMORY(base);
+ }
+
+ sname += 1;
+
+ stype = strchr_m(sname, ':');
+
+ if (stype == NULL) {
+ sname = talloc_strdup(mem_ctx, sname);
+ stype = "$DATA";
+ }
+ else {
+ if (StrCaseCmp(stype, ":$DATA") != 0) {
+ /*
+ * If there is an explicit stream type, so far we only
+ * allow $DATA. Is there anything else allowed? -- vl
+ */
+ DEBUG(10, ("[%s] is an invalid stream type\n", stype));
+ TALLOC_FREE(base);
+ return NT_STATUS_OBJECT_NAME_INVALID;
+ }
+ sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
+ stype += 1;
+ }
+
+ if (sname == NULL) {
+ TALLOC_FREE(base);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (sname[0] == '\0') {
+ /*
+ * no stream name, so no stream
+ */
+ goto done;
+ }
+
+ if (pstream != NULL) {
+ stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
+ if (stream == NULL) {
+ TALLOC_FREE(sname);
+ TALLOC_FREE(base);
+ return NT_STATUS_NO_MEMORY;
+ }
+ /*
+ * upper-case the type field
+ */
+ strupper_m(strchr_m(stream, ':')+1);
+ }
+
+ done:
+ if (pbase != NULL) {
+ *pbase = base;
+ }
+ if (pstream != NULL) {
+ *pstream = stream;
+ }
+ return NT_STATUS_OK;
+}