summaryrefslogtreecommitdiffstats
path: root/source3/client/clitar.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-02-17 11:24:33 +0100
committerAndreas Schneider <asn@samba.org>2014-02-19 18:22:30 +0100
commit995118484f7c1ef92b5539567cf878acc1c48b0a (patch)
tree86c51e4a9b7cc049aceffb158b645504428d0cd8 /source3/client/clitar.c
parent3b207dc0f3ef642ec5f16bc1dbce7c018c89cf55 (diff)
downloadsamba-995118484f7c1ef92b5539567cf878acc1c48b0a.tar.gz
samba-995118484f7c1ef92b5539567cf878acc1c48b0a.tar.xz
samba-995118484f7c1ef92b5539567cf878acc1c48b0a.zip
s3-clitar: Simplify is_subpath().
Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: David Disseldorp <ddiss@samba.org>
Diffstat (limited to 'source3/client/clitar.c')
-rw-r--r--source3/client/clitar.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index bad7eac4ad8..0f6b6a80522 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -1433,29 +1433,42 @@ static const char* skip_useless_char_in_path(const char *p)
*/
static bool is_subpath(const char *sub, const char *full)
{
- const char *full_copy = full;
-
- while (*full && *sub &&
- (*full == *sub || tolower_m(*full) == tolower_m(*sub) ||
- (*full == '\\' && *sub=='/') || (*full == '/' && *sub=='\\'))) {
- full++; sub++;
- }
-
- /* if full has a trailing slash, it compared equal, so full is an "initial"
- string of sub.
- */
- if (!*full && full != full_copy && (*(full-1) == '/' || *(full-1) == '\\'))
- return true;
-
- /* ignore trailing slash on full */
- if (!*sub && (*full == '/' || *full == '\\') && !*(full+1))
- return true;
-
- /* check for full is an "initial" string of sub */
- if ((*sub == '/' || *sub == '\\') && !*full)
- return true;
-
- return *full == *sub;
+ TALLOC_CTX *tmp_ctx = PANIC_IF_NULL(talloc_new(NULL));
+ int len = 0;
+ char *f, *s;
+
+ f = PANIC_IF_NULL(strlower_talloc(tmp_ctx, full));
+ string_replace(f, '\\', '/');
+ s = PANIC_IF_NULL(strlower_talloc(tmp_ctx, sub));
+ string_replace(s, '\\', '/');
+
+ /* find the point where sub and full diverge */
+ while ((*f != '\0') && (*s != '\0') && (*f == *s)) {
+ f++;
+ s++;
+ len++;
+ }
+
+ if ((*f == '\0') && (*s == '\0')) {
+ return true; /* sub and full match */
+ }
+
+ if ((*f == '\0') && (len > 0) && (*(f - 1) == '/')) {
+ /* sub diverges from full at path separator */
+ return true;
+ }
+
+ if ((*s == '\0') && (strcmp(f, "/") == 0)) {
+ /* full diverges from sub with trailing slash only */
+ return true;
+ }
+
+ if ((*s == '/') && (*f == '\0')) {
+ /* sub diverges from full with extra path component */
+ return true;
+ }
+
+ return false;
}
/**