summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-10-16 11:33:37 -0700
committerJeremy Allison <jra@samba.org>2007-10-16 11:33:37 -0700
commitce77126e68df65abc063de0ccdaec22cc746203d (patch)
tree97e027102f5a51f2dc89d96a818efa569a551d26 /source3/lib/util.c
parentb111d543a580694f2909c75a280a42a27bbe6dd0 (diff)
downloadsamba-ce77126e68df65abc063de0ccdaec22cc746203d.tar.gz
samba-ce77126e68df65abc063de0ccdaec22cc746203d.tar.bz2
samba-ce77126e68df65abc063de0ccdaec22cc746203d.zip
Fix access control code to be IPv6/v4 protocol independent.
Make unix_wild_match() talloc, not pstring based. Next will be name resolution code, and client code. Jeremy. (This used to be commit f6a01b82c5a47957659df08ea84e335dfbba1826)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c
index b25190b2f7..a6731347a3 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2586,7 +2586,7 @@ BOOL mask_match_list(const char *string, char **list, int listLen, BOOL is_case_
Recursive routine that is called by unix_wild_match.
*********************************************************/
-static BOOL unix_do_match(const char *regexp, const char *str)
+static bool unix_do_match(const char *regexp, const char *str)
{
const char *p;
@@ -2606,7 +2606,7 @@ static BOOL unix_do_match(const char *regexp, const char *str)
*/
p++;
if(!*p)
- return True; /* Automatic match */
+ return true; /* Automatic match */
while(*str) {
while(*str && (*p != *str))
@@ -2641,24 +2641,24 @@ static BOOL unix_do_match(const char *regexp, const char *str)
}
if ( matchcount <= 0 )
- return False;
+ return false;
}
str--; /* We've eaten the match char after the '*' */
if(unix_do_match(p, str))
- return True;
+ return true;
if(!*str)
- return False;
+ return false;
else
str++;
}
- return False;
+ return false;
default:
if(*str != *p)
- return False;
+ return false;
str++;
p++;
break;
@@ -2666,11 +2666,11 @@ static BOOL unix_do_match(const char *regexp, const char *str)
}
if(!*p && !*str)
- return True;
+ return true;
if (!*p && str[0] == '.' && str[1] == 0)
- return(True);
-
+ return true;
+
if (!*str && *p == '?') {
while (*p == '?')
p++;
@@ -2678,9 +2678,9 @@ static BOOL unix_do_match(const char *regexp, const char *str)
}
if(!*str && (*p == '*' && p[1] == '\0'))
- return True;
+ return true;
- return False;
+ return false;
}
/*******************************************************************
@@ -2688,25 +2688,38 @@ static BOOL unix_do_match(const char *regexp, const char *str)
Returns True if match, False if not.
*******************************************************************/
-BOOL unix_wild_match(const char *pattern, const char *string)
+bool unix_wild_match(const char *pattern, const char *string)
{
- pstring p2, s2;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ char *p2;
+ char *s2;
char *p;
+ bool ret = false;
- pstrcpy(p2, pattern);
- pstrcpy(s2, string);
+ p2 = talloc_strdup(ctx,pattern);
+ s2 = talloc_strdup(ctx,string);
+ if (!p2 || !s2) {
+ TALLOC_FREE(ctx);
+ return false;
+ }
strlower_m(p2);
strlower_m(s2);
/* Remove any *? and ** from the pattern as they are meaningless */
- for(p = p2; *p; p++)
- while( *p == '*' && (p[1] == '?' ||p[1] == '*'))
- pstrcpy( &p[1], &p[2]);
-
- if (strequal(p2,"*"))
- return True;
+ for(p = p2; *p; p++) {
+ while( *p == '*' && (p[1] == '?' ||p[1] == '*')) {
+ memmove(&p[1], &p[2], strlen(&p[2])+1);
+ }
+ }
+
+ if (strequal(p2,"*")) {
+ TALLOC_FREE(ctx);
+ return true;
+ }
- return unix_do_match(p2, s2);
+ ret = unix_do_match(p2, s2);
+ TALLOC_FREE(ctx);
+ return ret;
}
/**********************************************************************