*/
static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
struct max_n *max_n, const smb_ucs2_t *ldot,
- BOOL is_case_sensitive)
+ bool is_case_sensitive)
{
smb_ucs2_t c;
int i;
if (is_case_sensitive) {
return -1;
}
- if (toupper_w(c) != toupper_w(*n)) {
+ if (toupper_m(c) != toupper_m(*n)) {
return -1;
}
}
return -1;
}
-int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
- BOOL is_case_sensitive)
+int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
+ bool is_case_sensitive)
{
smb_ucs2_t *p = NULL;
smb_ucs2_t *s = NULL;
int ret, count, i;
struct max_n *max_n = NULL;
+ struct max_n *max_n_free = NULL;
+ struct max_n one_max_n;
+ size_t converted_size;
if (ISDOTDOT(string)) {
string = ".";
}
}
- if (push_ucs2_allocate(&p, pattern) == (size_t)-1) {
+ if (!push_ucs2_talloc(talloc_tos(), &p, pattern, &converted_size)) {
return -1;
}
- if (push_ucs2_allocate(&s, string) == (size_t)-1) {
- SAFE_FREE(p);
+ if (!push_ucs2_talloc(talloc_tos(), &s, string, &converted_size)) {
+ TALLOC_FREE(p);
return -1;
}
}
if (count != 0) {
- max_n = SMB_CALLOC_ARRAY(struct max_n, count);
- if (!max_n) {
- SAFE_FREE(p);
- SAFE_FREE(s);
- return -1;
+ if (count == 1) {
+ /*
+ * We're doing this a LOT, so save the effort to allocate
+ */
+ ZERO_STRUCT(one_max_n);
+ max_n = &one_max_n;
+ }
+ else {
+ max_n = SMB_CALLOC_ARRAY(struct max_n, count);
+ if (!max_n) {
+ TALLOC_FREE(p);
+ TALLOC_FREE(s);
+ return -1;
+ }
+ max_n_free = max_n;
}
}
ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive);
- SAFE_FREE(max_n);
- SAFE_FREE(p);
- SAFE_FREE(s);
+ SAFE_FREE(max_n_free);
+ TALLOC_FREE(p);
+ TALLOC_FREE(s);
return ret;
}
-
-
-/* a generic fnmatch function - uses for non-CIFS pattern matching */
-int gen_fnmatch(const char *pattern, const char *string)
-{
- return ms_fnmatch(pattern, string, PROTOCOL_NT1, False);
-}