portmap-4.0-cleanup.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Some cleanup for my last patch.
  2. --
  3. H.J. Lu (hjl@gnu.org)
  4. --
  5. --- portmap_4/pmap_check.c.hostname Wed May 10 10:23:35 2000
  6. +++ portmap_4/pmap_check.c Wed May 10 11:03:22 2000
  7. @@ -35,6 +35,7 @@
  8. static char sccsid[] = "@(#) pmap_check.c 1.6 93/11/21 20:58:59";
  9. #endif
  10. #include <unistd.h>
  11. +#include <string.h>
  12. #include <rpc/rpc.h>
  13. #include <rpc/pmap_prot.h>
  14. #include <syslog.h>
  15. @@ -69,8 +70,6 @@ int deny_severity = LOG_WARNING;
  16. /* coming from libwrap.a (tcp_wrappers) */
  17. extern int hosts_ctl(char *daemon, char *name, char *addr, char *user);
  18. -#define good_client(a) hosts_ctl("portmap", "", inet_ntoa(a->sin_addr), "")
  19. -
  20. #define reserved_port(p) (IPPORT_RESERVED/2 < (p) && (p) < IPPORT_RESERVED)
  21. #define unreserved_port(p) (IPPORT_RESERVED <= (p) && (p) != NFS_PORT)
  22. @@ -88,6 +87,59 @@ extern int hosts_ctl(char *daemon, char
  23. #define log_client(addr, proc, prog) \
  24. logit(allow_severity, addr, proc, prog, "")
  25. +
  26. +#ifdef HOSTS_ACCESS
  27. +static int
  28. +good_client(addr)
  29. +struct sockaddr_in *addr;
  30. +{
  31. + struct hostent *hp;
  32. + char **sp;
  33. + char *tmpname;
  34. +
  35. + /* Check the IP address first. */
  36. + if (hosts_ctl("portmap", "", inet_ntoa(addr->sin_addr), ""))
  37. + return 1;
  38. +
  39. + /* Check the hostname. */
  40. + hp = gethostbyaddr ((const char *) &(addr->sin_addr),
  41. + sizeof (addr->sin_addr), AF_INET);
  42. +
  43. + if (!hp)
  44. + return 0;
  45. +
  46. + /* must make sure the hostent is authorative. */
  47. + tmpname = alloca (strlen (hp->h_name) + 1);
  48. + strcpy (tmpname, hp->h_name);
  49. + hp = gethostbyname(tmpname);
  50. + if (hp) {
  51. + /* now make sure the "addr->sin_addr" is on the list */
  52. + for (sp = hp->h_addr_list ; *sp ; sp++) {
  53. + if (memcmp(*sp, &(addr->sin_addr), hp->h_length)==0)
  54. + break;
  55. + }
  56. + if (!*sp)
  57. + /* it was a FAKE. */
  58. + return 0;
  59. + }
  60. + else
  61. + /* never heard of it. misconfigured DNS? */
  62. + return 0;
  63. +
  64. + /* Check the official name first. */
  65. + if (hosts_ctl("portmap", "", hp->h_name, ""))
  66. + return 1;
  67. +
  68. + /* Check aliases. */
  69. + for (sp = hp->h_aliases; *sp ; sp++) {
  70. + if (hosts_ctl("portmap", "", *sp, ""))
  71. + return 1;
  72. + }
  73. +
  74. + /* No match */
  75. + return 0;
  76. +}
  77. +#endif
  78. /* check_startup - additional startup code */