03_all_wildcard.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --- /tmp/hosts_access.c 2003-08-03 22:18:00.000000000 +0000
  2. +++ hosts_access.c 2003-08-03 22:39:44.000000000 +0000
  3. @@ -289,6 +289,17 @@
  4. {
  5. int n;
  6. +#ifndef DISABLE_WILDCARD_MATCHING
  7. + if (strchr(tok, '*') || strchr(tok,'?')) { /* contains '*' or '?' */
  8. + /* we must convert the both to lowercase as match_pattern_ylo is case-sensitive */
  9. + for (n = 0; n < strlen(tok); n++)
  10. + tok[n] = isupper(tok[n]) ? tolower(tok[n]) : tok[n];
  11. + for (n = 0; n < strlen(string); n++)
  12. + string[n] = isupper(string[n]) ? tolower(string[n]) : string[n];
  13. + return (match_pattern_ylo(string,tok));
  14. + } else
  15. +#endif
  16. +
  17. if (tok[0] == '.') { /* suffix */
  18. n = strlen(string) - strlen(tok);
  19. return (n > 0 && STR_EQ(tok, string + n));
  20. @@ -329,3 +340,72 @@
  21. }
  22. return ((addr & mask) == net);
  23. }
  24. +
  25. +#ifndef DISABLE_WILDCARD_MATCHING
  26. +/* Note: this feature has been adapted in a pretty straightforward way
  27. + from Tatu Ylonen's last SSH version under free license by
  28. + Pekka Savola <pekkas@netcore.fi>.
  29. +
  30. + Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  31. +*/
  32. +
  33. +/* Returns true if the given string matches the pattern (which may contain
  34. + ? and * as wildcards), and zero if it does not match. */
  35. +
  36. +int match_pattern_ylo(const char *s, const char *pattern)
  37. +{
  38. + while (1)
  39. + {
  40. + /* If at end of pattern, accept if also at end of string. */
  41. + if (!*pattern)
  42. + return !*s;
  43. +
  44. + /* Process '*'. */
  45. + if (*pattern == '*')
  46. + {
  47. + /* Skip the asterisk. */
  48. + pattern++;
  49. +
  50. + /* If at end of pattern, accept immediately. */
  51. + if (!*pattern)
  52. + return 1;
  53. +
  54. + /* If next character in pattern is known, optimize. */
  55. + if (*pattern != '?' && *pattern != '*')
  56. + {
  57. + /* Look instances of the next character in pattern, and try
  58. + to match starting from those. */
  59. + for (; *s; s++)
  60. + if (*s == *pattern &&
  61. + match_pattern_ylo(s + 1, pattern + 1))
  62. + return 1;
  63. + /* Failed. */
  64. + return 0;
  65. + }
  66. +
  67. + /* Move ahead one character at a time and try to match at each
  68. + position. */
  69. + for (; *s; s++)
  70. + if (match_pattern_ylo(s, pattern))
  71. + return 1;
  72. + /* Failed. */
  73. + return 0;
  74. + }
  75. +
  76. + /* There must be at least one more character in the string. If we are
  77. + at the end, fail. */
  78. + if (!*s)
  79. + return 0;
  80. +
  81. + /* Check if the next character of the string is acceptable. */
  82. + if (*pattern != '?' && *pattern != *s)
  83. + return 0;
  84. +
  85. + /* Move to the next character, both in string and in pattern. */
  86. + s++;
  87. + pattern++;
  88. + }
  89. + /*NOTREACHED*/
  90. +}
  91. +#endif /* DISABLE_WILDCARD_MATCHING */
  92. +