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.

160 lines
5.1 KiB

  1. /* udns_bl.c
  2. DNSBL stuff
  3. Copyright (C) 2005 Michael Tokarev <mjt@corpit.ru>
  4. This file is part of UDNS library, an async DNS stub resolver.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library, in file named COPYING.LGPL; if not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place,
  16. Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include "udns.h"
  19. #ifndef NULL
  20. # define NULL 0
  21. #endif
  22. struct dns_query *
  23. dns_submit_a4dnsbl(struct dns_ctx *ctx,
  24. const struct in_addr *addr, const char *dnsbl,
  25. dns_query_a4_fn *cbck, void *data) {
  26. dnsc_t dn[DNS_MAXDN];
  27. if (dns_a4ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
  28. dns_setstatus(ctx, DNS_E_BADQUERY);
  29. return NULL;
  30. }
  31. return
  32. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
  33. dns_parse_a4, (dns_query_fn*)cbck, data);
  34. }
  35. struct dns_query *
  36. dns_submit_a4dnsbl_txt(struct dns_ctx *ctx,
  37. const struct in_addr *addr, const char *dnsbl,
  38. dns_query_txt_fn *cbck, void *data) {
  39. dnsc_t dn[DNS_MAXDN];
  40. if (dns_a4ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
  41. dns_setstatus(ctx, DNS_E_BADQUERY);
  42. return NULL;
  43. }
  44. return
  45. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
  46. dns_parse_txt, (dns_query_fn*)cbck, data);
  47. }
  48. struct dns_rr_a4 *
  49. dns_resolve_a4dnsbl(struct dns_ctx *ctx,
  50. const struct in_addr *addr, const char *dnsbl) {
  51. return (struct dns_rr_a4 *)
  52. dns_resolve(ctx, dns_submit_a4dnsbl(ctx, addr, dnsbl, 0, 0));
  53. }
  54. struct dns_rr_txt *
  55. dns_resolve_a4dnsbl_txt(struct dns_ctx *ctx,
  56. const struct in_addr *addr, const char *dnsbl) {
  57. return (struct dns_rr_txt *)
  58. dns_resolve(ctx, dns_submit_a4dnsbl_txt(ctx, addr, dnsbl, 0, 0));
  59. }
  60. struct dns_query *
  61. dns_submit_a6dnsbl(struct dns_ctx *ctx,
  62. const struct in6_addr *addr, const char *dnsbl,
  63. dns_query_a4_fn *cbck, void *data) {
  64. dnsc_t dn[DNS_MAXDN];
  65. if (dns_a6ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
  66. dns_setstatus(ctx, DNS_E_BADQUERY);
  67. return NULL;
  68. }
  69. return
  70. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
  71. dns_parse_a4, (dns_query_fn*)cbck, data);
  72. }
  73. struct dns_query *
  74. dns_submit_a6dnsbl_txt(struct dns_ctx *ctx,
  75. const struct in6_addr *addr, const char *dnsbl,
  76. dns_query_txt_fn *cbck, void *data) {
  77. dnsc_t dn[DNS_MAXDN];
  78. if (dns_a6ptodn(addr, dnsbl, dn, sizeof(dn)) <= 0) {
  79. dns_setstatus(ctx, DNS_E_BADQUERY);
  80. return NULL;
  81. }
  82. return
  83. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
  84. dns_parse_txt, (dns_query_fn*)cbck, data);
  85. }
  86. struct dns_rr_a4 *
  87. dns_resolve_a6dnsbl(struct dns_ctx *ctx,
  88. const struct in6_addr *addr, const char *dnsbl) {
  89. return (struct dns_rr_a4 *)
  90. dns_resolve(ctx, dns_submit_a6dnsbl(ctx, addr, dnsbl, 0, 0));
  91. }
  92. struct dns_rr_txt *
  93. dns_resolve_a6dnsbl_txt(struct dns_ctx *ctx,
  94. const struct in6_addr *addr, const char *dnsbl) {
  95. return (struct dns_rr_txt *)
  96. dns_resolve(ctx, dns_submit_a6dnsbl_txt(ctx, addr, dnsbl, 0, 0));
  97. }
  98. static int
  99. dns_rhsbltodn(const char *name, const char *rhsbl, dnsc_t dn[DNS_MAXDN])
  100. {
  101. int l = dns_sptodn(name, dn, DNS_MAXDN);
  102. if (l <= 0) return 0;
  103. l = dns_sptodn(rhsbl, dn+l-1, DNS_MAXDN-l+1);
  104. if (l <= 0) return 0;
  105. return 1;
  106. }
  107. struct dns_query *
  108. dns_submit_rhsbl(struct dns_ctx *ctx, const char *name, const char *rhsbl,
  109. dns_query_a4_fn *cbck, void *data) {
  110. dnsc_t dn[DNS_MAXDN];
  111. if (!dns_rhsbltodn(name, rhsbl, dn)) {
  112. dns_setstatus(ctx, DNS_E_BADQUERY);
  113. return NULL;
  114. }
  115. return
  116. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_A, DNS_NOSRCH,
  117. dns_parse_a4, (dns_query_fn*)cbck, data);
  118. }
  119. struct dns_query *
  120. dns_submit_rhsbl_txt(struct dns_ctx *ctx, const char *name, const char *rhsbl,
  121. dns_query_txt_fn *cbck, void *data) {
  122. dnsc_t dn[DNS_MAXDN];
  123. if (!dns_rhsbltodn(name, rhsbl, dn)) {
  124. dns_setstatus(ctx, DNS_E_BADQUERY);
  125. return NULL;
  126. }
  127. return
  128. dns_submit_dn(ctx, dn, DNS_C_IN, DNS_T_TXT, DNS_NOSRCH,
  129. dns_parse_txt, (dns_query_fn*)cbck, data);
  130. }
  131. struct dns_rr_a4 *
  132. dns_resolve_rhsbl(struct dns_ctx *ctx, const char *name, const char *rhsbl) {
  133. return (struct dns_rr_a4*)
  134. dns_resolve(ctx, dns_submit_rhsbl(ctx, name, rhsbl, 0, 0));
  135. }
  136. struct dns_rr_txt *
  137. dns_resolve_rhsbl_txt(struct dns_ctx *ctx, const char *name, const char *rhsbl)
  138. {
  139. return (struct dns_rr_txt*)
  140. dns_resolve(ctx, dns_submit_rhsbl_txt(ctx, name, rhsbl, 0, 0));
  141. }