From 740d6f5dd60bef72037ed5fcd7b2192af22c2e41 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Nov 2001 18:26:53 +0000 Subject: a big one: - old mangle code has gone, the new one based on tdb seem resonably ok probably the valid.dat table need to be updated to treat wild chars as invalid ones (work ok without it) - a LOT of new string manipulation function for unicode, they are somewhat tested but a review would not be bad - some new function I will need for the new unix_convert function I'm writing, this will be renamed filename_convert and use only unicode strings. - charconv, I attached a comment, if someone wnat to look if I'm right or just was hacking to late in the night to make a sane one :) of course any bug is my responsibility an will be pleased to see patches if you find any. :-) Simo. (This used to be commit ee19f7efb6ea9216fc91cf112ac1afa691983e9d) --- source3/lib/util.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'source3/lib/util.c') diff --git a/source3/lib/util.c b/source3/lib/util.c index c833707d62..e2a5fe10d0 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -418,6 +418,58 @@ void unix_clean_name(char *s) trim_string(s,NULL,"/.."); } +/******************************************************************* +convert '\' to '/' +reduce a file name, removing or reducing /../ , /./ , // elements. +remove also any trailing . and / +return a new allocated string. +********************************************************************/ +smb_ucs2_t *unix_clean_path(const smb_ucs2_t *s) +{ + smb_ucs2_t *ns; + smb_ucs2_t *p, *r, *t; + + DEBUG(3, ("unix_clean_name_w\n")); /* [%unicode]\n")); */ + + /* convert '\' to '/' */ + ns = strdup_w(s); + if (!ns) return NULL; + unix_format_w(ns); + + /* remove all double slashes */ + p = ns; + ns = all_string_sub_wa(p, "//", "/"); + SAFE_FREE(p); + if (!ns) return NULL; + + /* remove any /./ */ + p = ns; + ns = all_string_sub_wa(p, "/./", "/"); + SAFE_FREE(p); + if (!ns) return NULL; + + /* reduce any /../ */ + t = ns; + while ((r = strstr_wa(t, "/..")) != NULL) { + t = &(r[3]); + if (*t == UCS2_CHAR('/') || *t == 0) { + *r = 0; + p = strrchr_w(ns, UCS2_CHAR('/')); + if (!p) p = ns; + memmove(p, t, (strlen_w(t) + 1) * sizeof(smb_ucs2_t)); + t = p; + } + } + + /* remove any trailing /. */ + trim_string_wa(ns, NULL, "/."); + + /* remove any leading and trailing / */ + trim_string_wa(ns, "/", "/"); + + return ns; +} + /**************************************************************************** make a dir struct ****************************************************************************/ @@ -1783,6 +1835,22 @@ BOOL ms_has_wild(char *s) return False; } +BOOL ms_has_wild_w(const smb_ucs2_t *s) +{ + smb_ucs2_t c; + while ((c = *s++)) { + switch (c) { + case UCS2_CHAR('*'): + case UCS2_CHAR('?'): + case UCS2_CHAR('<'): + case UCS2_CHAR('>'): + case UCS2_CHAR('"'): + return True; + } + } + return False; +} + /******************************************************************* a wrapper that handles case sensitivity and the special handling of the ".." name -- cgit