smb_match.c revision 3a6c5f83d4cb79e49561f3fad2b016450f0e6fec
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _KERNEL
#include <stdlib.h>
#include <string.h>
#else
#endif
/*
* Maximum recursion depth for the wildcard match functions.
* These functions may recurse when processing a '*'.
*/
#define SMB_MATCH_DEPTH_MAX 32
#define SMB_CRC_POLYNOMIAL 0xD8B5D8B5
static int smb_match_private(const char *, const char *, int *);
static int smb_match_ci_private(const char *, const char *, int *);
/*
* Returns:
* 1 match
* 0 no-match
*/
int
{
int depth = 0;
int rc;
rc = 0;
return (rc);
}
/*
* The '*' character matches multiple characters.
* The '?' character matches a single character.
*
* If the pattern has trailing '?'s then it matches the specified number
* of characters or less. For example, "x??" matches "xab", "xa" and "x",
* but not "xabc".
*
* Returns:
* 1 match
* 0 no-match
* -1 no-match, too many wildcards in pattern
*/
static int
{
int rc;
for (;;) {
switch (*patn) {
case 0:
return (*str == 0);
case '?':
if (*str != 0) {
str++;
patn++;
continue;
} else {
return (0);
}
/*NOTREACHED*/
case '*':
if (*patn == 0)
return (1);
if ((*depth)++ >= SMB_MATCH_DEPTH_MAX)
return (-1);
while (*str) {
if (rc != 0)
return (rc);
str++;
}
return (0);
default:
return (0);
str++;
patn++;
continue;
}
}
/*NOTREACHED*/
}
int
{
int avail;
char *ptr;
char name83[14];
avail--) {
}
while (avail--)
*(ptr++) = ' ';
*(ptr++) = '.';
if (*patn == '.')
patn++;
else if (*patn != 0)
return (0);
}
if (*patn != 0)
return (0);
while (avail--)
*(ptr++) = ' ';
*ptr = 0;
}
/*
* Returns:
* 1 match
* 0 no-match
*/
int
{
int depth = 0;
int rc;
rc = 0;
return (rc);
}
/*
* The '*' character matches multiple characters.
* The '?' character matches a single character.
*
* If the pattern has trailing '?'s then it matches the specified number
* of characters or less. For example, "x??" matches "xab", "xa" and "x",
* but not "xabc".
*
* Returns:
* 1 match
* 0 no-match
* -1 no-match, too many wildcards in pattern
*/
static int
{
const char *p;
int rc;
/*
* "<" is a special pattern that matches only those names that do
* NOT have an extension. "." and ".." are ok.
*/
return (1);
return (1);
return (0);
}
for (;;) {
switch (*patn) {
case 0:
return (*str == 0);
case '?':
if (*str != 0) {
str++;
patn++;
continue;
} else {
p = patn;
p += strspn(p, "?");
return ((*p == '\0') ? 1 : 0);
}
/*NOTREACHED*/
case '*':
if (*patn == 0)
return (1);
if ((*depth)++ >= SMB_MATCH_DEPTH_MAX)
return (-1);
while (*str) {
if (rc != 0)
return (rc);
str++;
}
return (0);
default:
return (0);
}
str++;
patn++;
continue;
}
}
/*NOTREACHED*/
}
{
uint8_t *p;
int i;
}
return (crc);
}