OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.2 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../tcp_wrappers/0005-tcp_wrappers-7.6-wildcard-matching.patch
  5. # Copyright (C) 2011 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. See https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=17847
  17. (Though the original code needs to be patched to be case-insensitive.)
  18. --- a/hosts_access.5
  19. +++ b/hosts_access.5
  20. @@ -89,6 +89,10 @@ An expression of the form `n.n.n.n/m.m.m
  21. bitwise AND of the address and the `mask\'. For example, the net/mask
  22. pattern `131.155.72.0/255.255.254.0\' matches every address in the
  23. range `131.155.72.0\' through `131.155.73.255\'.
  24. +.IP \(bu
  25. +Wildcards `*\' and `?\' can be used to match hostnames or IP addresses. This
  26. +method of matching cannot be used in conjunction with `net/mask\' matching,
  27. +hostname matching beginning with `.\' or IP address matching ending with `.\'.
  28. .SH WILDCARDS
  29. The access control language supports explicit wildcards:
  30. .IP ALL
  31. --- a/hosts_access.c
  32. +++ b/hosts_access.c
  33. @@ -82,6 +82,7 @@ static int client_match();
  34. static int host_match();
  35. static int string_match();
  36. static int masked_match();
  37. +static int match_pattern_ylo();
  38. /* Size of logical line buffer. */
  39. @@ -289,6 +290,11 @@ char *string;
  40. {
  41. int n;
  42. +#ifndef DISABLE_WILDCARD_MATCHING
  43. + if (strchr(tok, '*') || strchr(tok,'?')) { /* contains '*' or '?' */
  44. + return (match_pattern_ylo(string,tok));
  45. + } else
  46. +#endif
  47. if (tok[0] == '.') { /* suffix */
  48. n = strlen(string) - strlen(tok);
  49. return (n > 0 && STR_EQ(tok, string + n));
  50. @@ -329,3 +335,78 @@ char *string;
  51. }
  52. return ((addr & mask) == net);
  53. }
  54. +
  55. +#ifndef DISABLE_WILDCARD_MATCHING
  56. +/* Note: this feature has been adapted in a pretty straightforward way
  57. + from Tatu Ylonen's last SSH version under free license by
  58. + Pekka Savola <pekkas@netcore.fi>.
  59. +
  60. + Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  61. +*/
  62. +
  63. +/* Returns true if the given string matches the pattern (which may contain
  64. + ? and * as wildcards), and zero if it does not match. */
  65. +
  66. +static int match_pattern_ylo(const char *s, const char *pattern)
  67. +{
  68. + char src;
  69. + char pat;
  70. + while (1)
  71. + {
  72. + /* If at end of pattern, accept if also at end of string. */
  73. + if (!*pattern)
  74. + return !*s;
  75. +
  76. + /* Process '*'. */
  77. + if (*pattern == '*')
  78. + {
  79. + /* Skip the asterisk. */
  80. + pattern++;
  81. +
  82. + /* If at end of pattern, accept immediately. */
  83. + if (!*pattern)
  84. + return 1;
  85. +
  86. + /* If next character in pattern is known, optimize. */
  87. + if (*pattern != '?' && *pattern != '*')
  88. + {
  89. + /* Look instances of the next character in pattern, and try
  90. + to match starting from those. */
  91. + pat = *pattern;
  92. + for (; *s; s++) {
  93. + src = *s;
  94. + if (toupper(src) == toupper(pat) &&
  95. + match_pattern_ylo(s + 1, pattern + 1))
  96. + return 1;
  97. + }
  98. + /* Failed. */
  99. + return 0;
  100. + }
  101. +
  102. + /* Move ahead one character at a time and try to match at each
  103. + position. */
  104. + for (; *s; s++)
  105. + if (match_pattern_ylo(s, pattern))
  106. + return 1;
  107. + /* Failed. */
  108. + return 0;
  109. + }
  110. +
  111. + /* There must be at least one more character in the string. If we are
  112. + at the end, fail. */
  113. + if (!*s)
  114. + return 0;
  115. +
  116. + /* Check if the next character of the string is acceptable. */
  117. + pat = *pattern;
  118. + src = *s;
  119. + if (*pattern != '?' && toupper(pat) != toupper(src))
  120. + return 0;
  121. +
  122. + /* Move to the next character, both in string and in pattern. */
  123. + s++;
  124. + pattern++;
  125. + }
  126. + /*NOTREACHED*/
  127. +}
  128. +#endif /* DISABLE_WILDCARD_MATCHING */