/** * match_pattern() - compare a string with a pattern which might include * wildcard '*' and '?' * TODO : implement consideration about DOS_DOT, DOS_QM and DOS_STAR * * @str: string to compare with a pattern * @len: string length * @pattern: pattern string which might include wildcard '*' and '?' * * Return: 0 if pattern matched with the string, otherwise non zero value
*/ int match_pattern(constchar *str, size_t len, constchar *pattern)
{ constchar *s = str; constchar *p = pattern; bool star = false;
while (*s && len) { switch (*p) { case'?':
s++;
len--;
p++; break; case'*':
star = true;
str = s; if (!*++p) returntrue;
pattern = p; break; default: if (tolower(*s) == tolower(*p)) {
s++;
len--;
p++;
} else { if (!star) returnfalse;
str++;
s = str;
p = pattern;
} break;
}
}
if (*p == '*')
++p; return !*p;
}
/* * is_char_allowed() - check for valid character * @ch: input character to be checked * * Return: 1 if char is allowed, otherwise 0
*/ staticinlineint is_char_allowed(char ch)
{ /* check for control chars, wildcards etc. */ if (!(ch & 0x80) &&
(ch <= 0x1f ||
ch == '?' || ch == '"' || ch == '<' ||
ch == '>' || ch == '|' || ch == '*')) return 0;
return 1;
}
int ksmbd_validate_filename(char *filename)
{ while (*filename) { char c = *filename;
filename++; if (!is_char_allowed(c)) {
ksmbd_debug(VFS, "File name validation failed: 0x%x\n", c); return -ENOENT;
}
}
return 0;
}
staticint ksmbd_validate_stream_name(char *stream_name)
{ while (*stream_name) { char c = *stream_name;
stream_name++; if (c == '/' || c == ':' || c == '\\') {
pr_err("Stream name validation failed: %c\n", c); return -ENOENT;
}
}
return 0;
}
int parse_stream_name(char *filename, char **stream_name, int *s_type)
{ char *stream_type; char *s_name; int rc = 0;
/** * ksmbd_extract_sharename() - get share name from tree connect request * @um: pointer to a unicode_map structure for character encoding handling * @treename: buffer containing tree name and share name * * Return: share name on success, otherwise error
*/ char *ksmbd_extract_sharename(struct unicode_map *um, constchar *treename)
{ constchar *name = treename, *pos = strrchr(name, '\\');
if (pos)
name = (pos + 1);
/* caller has to free the memory */ return ksmbd_casefold_sharename(um, name);
}
/** * convert_to_unix_name() - convert windows name to unix format * @share: ksmbd_share_config pointer * @name: file name that is relative to share * * Return: converted name on success, otherwise NULL
*/ char *convert_to_unix_name(struct ksmbd_share_config *share, constchar *name)
{ int no_slash = 0, name_len, path_len; char *new_name;
/* We allocate buffer twice bigger than needed. */
conv[*conv_len] = 0x00;
conv[*conv_len + 1] = 0x00; return conv;
}
/* * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units) * into Unix UTC (based 1970-01-01, in seconds).
*/ struct timespec64 ksmbd_NTtimeToUnix(__le64 ntutc)
{ struct timespec64 ts;
/* Subtract the NTFS time offset, then convert to 1s intervals. */
s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
u64 abs_t;
/* * Unfortunately can not use normal 64 bit division on 32 bit arch, but * the alternative, do_div, does not work with negative numbers so have * to special case them
*/ if (t < 0) {
abs_t = -t;
ts.tv_nsec = do_div(abs_t, 10000000) * 100;
ts.tv_nsec = -ts.tv_nsec;
ts.tv_sec = -abs_t;
} else {
abs_t = t;
ts.tv_nsec = do_div(abs_t, 10000000) * 100;
ts.tv_sec = abs_t;
}
return ts;
}
/* Convert the Unix UTC into NT UTC. */ inline u64 ksmbd_UnixTimeToNT(struct timespec64 t)
{ /* Convert to 100ns intervals and then add the NTFS time offset. */ return (u64)t.tv_sec * 10000000 + t.tv_nsec / 100 + NTFS_TIME_OFFSET;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.