} stringlist_t;
int matchpattern(const char *in, const char *pattern, int caseinsensitive);
+int matchpattern_with_separator(const char *in, const char *pattern, int caseinsensitive, const char *separators, qboolean wildcard_least_one);
void stringlistinit(stringlist_t *list);
void stringlistfreecontents(stringlist_t *list);
void stringlistappend(stringlist_t *list, const char *text);
// LordHavoc: some portable directory listing code I wrote for lmp2pcx, now used in darkplaces to load id1/*.pak and such...
int matchpattern(const char *in, const char *pattern, int caseinsensitive)
+{
+ return matchpattern_with_separator(in, pattern, caseinsensitive, "/\\:", false);
+}
+
+int matchpattern_with_separator(const char *in, const char *pattern, int caseinsensitive, const char *separators, qboolean wildcard_least_one)
{
int c1, c2;
while (*pattern)
case 0:
return 1; // end of pattern
case '?': // match any single character
- if (*in == 0 || *in == '/' || *in == '\\' || *in == ':')
+ if (*in == 0 || strchr(separators, *in))
return 0; // no match
in++;
pattern++;
break;
case '*': // match anything until following string
+ if(wildcard_least_one)
+ if (*in == 0 || strchr(separators, *in))
+ return 0; // no match
if (!*in)
return 1; // match
pattern++;
while (*in)
{
- if (*in == '/' || *in == '\\' || *in == ':')
+ if (strchr(separators, *in))
break;
// see if pattern matches at this offset
if (matchpattern(in, pattern, caseinsensitive))
const char *RCon_Authenticate(const char *password, const char *s, const char *endpos)
{
const char *text;
+ qboolean hasquotes;
if(!strcmp(rcon_password.string, password))
return "rcon";
size_t l = strlen(s);
if(l)
{
- text = s;
-
- if (!COM_ParseToken_Console(&text))
- return NULL;
-
- // com_token now contains the command
- if(!strstr(va(" %s ", rcon_restricted_commands.string), va(" %s ", com_token)))
- return NULL;
+ hasquotes = (strchr(s, '"') != NULL);
+ // sorry, we can't allow these substrings in wildcard expressions,
+ // as they can mess with the argument counts
+ text = rcon_restricted_commands.string;
+ while(COM_ParseToken_Console(&text))
+ {
+ // com_token now contains a pattern to check for...
+ if(strchr(com_token, '*') || strchr(com_token, '?')) // wildcard expression, * can only match a SINGLE argument
+ {
+ if(!hasquotes)
+ if(matchpattern_with_separator(s, com_token, true, " ", true)) // note how we excluded tab, newline etc. above
+ goto match;
+ }
+ else if(strchr(com_token, ' ')) // multi-arg expression? must match in whole
+ {
+ if(!strcmp(com_token, s))
+ goto match;
+ }
+ else // single-arg expression? must match the beginning of the command
+ {
+ if(!strcmp(com_token, s))
+ goto match;
+ if(!memcmp(va("%s ", com_token), s, strlen(com_token) + 1))
+ goto match;
+ }
+ }
+ // if we got here, nothing matched!
+ return NULL;
}
+match:
s += l + 1;
}