home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / patches / 1.2 / cidr.patch < prev    next >
Encoding:
Text File  |  1998-06-11  |  2.8 KB  |  115 lines

  1.  
  2. From brian@hyperreal.com Sat May  3 13:28:02 1997
  3. Date: Mon, 14 Apr 1997 12:01:11 -0700 (PDT)
  4. From: Brian Behlendorf <brian@hyperreal.com>
  5. Reply-To: new-httpd@apache.org
  6. To: new-httpd@apache.org
  7. Subject: mod_access.c patch for apache 1.2b8 (fwd)
  8.  
  9.  
  10. Could someone follow up, and help his patch make it to /contrib?  Thanks.
  11.  
  12.     Brian
  13.  
  14. --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--
  15. brian@hyperreal.com     http://www.apache.org     http://www.organic.com/jobs
  16.  
  17. ---------- Forwarded message ----------
  18. Date: Wed, 9 Apr 1997 17:10:19 +0900 (JST)
  19. From: Hideo Matsumoto <hideo-m@nerv.org>
  20. To: apache@apache.org
  21. Subject: mod_access.c patch for apache 1.2b8
  22.  
  23. Hello,
  24.  
  25. I made following patch for mod_access.c.  This patch extends access
  26. control syntax specifying IP address block for access control as
  27. follows:
  28.  
  29. [access.conf sample] ------
  30. order deny,allow
  31. allow from 10.0.0.0/8
  32. allow from 172.16.0.0/12
  33. allow from 192.168.0.0/16
  34. deny from all
  35. ---------------------------
  36.  
  37. If you feel this patch useful, please include next release.
  38. I'm Japanese. Sorry for my poor English.
  39.  
  40. Thanx,
  41.  
  42. --
  43. Hideo Matsumoto <hideo-m@nerv.org>        NERV, Tokyo-3, Japan.
  44.  
  45.  
  46.   [ Part 2: "" ]
  47.  
  48. --- mod_access.c.orig    Fri Mar  7 23:15:36 1997
  49. +++ mod_access.c    Wed Apr  9 16:21:48 1997
  50. @@ -66,6 +66,7 @@
  51.  typedef struct {
  52.      char *from;
  53.      int limited;
  54. +    unsigned long net, mask;
  55.  } allowdeny;
  56.  
  57.  /* things in the 'order' array */
  58. @@ -81,6 +82,35 @@
  59.  
  60.  module access_module;
  61.  
  62. +int readmask(const char *param, unsigned long *Network, unsigned long *Netmask)
  63. +{
  64. +    char buf[sizeof("255.255.255.255/255")];
  65. +    char *s, *t;
  66. +    int i;
  67. +    unsigned long netmask;
  68. +
  69. +    if (!strchr(param, '/'))  return -1;
  70. +
  71. +    strncpy(buf, param, sizeof(buf));
  72. +    buf[sizeof(buf)-1] = '\0';
  73. +
  74. +    if ((s = strtok(buf, "/")) == NULL)  return -1;    /* ex:192.168.0.1 */
  75. +    if ((t = strtok(NULL, "/")) == NULL) return -1;    /* ex:24 */
  76. +
  77. +    if ((*Network = inet_addr(s)) == INADDR_NONE)  return -1;
  78. +
  79. +#define ADDR_SIZE    (sizeof(unsigned long) * 8)
  80. +    if ((i = atoi(t)) <= 0)
  81. +    netmask = 0x00000000UL;
  82. +    else {
  83. +    if (i > ADDR_SIZE)  i = ADDR_SIZE;
  84. +    netmask = 0xffffffffUL << (ADDR_SIZE - i);
  85. +    }
  86. +
  87. +    *Netmask = htonl(netmask);
  88. +    return 0;
  89. +}
  90. +
  91.  void *create_access_dir_config (pool *p, char *dummy)
  92.  {
  93.      access_dir_conf *conf =
  94. @@ -122,6 +152,8 @@
  95.      a = (allowdeny *)push_array (cmd->info ? d->allows : d->denys);
  96.      a->from = pstrdup (cmd->pool, where);
  97.      a->limited = cmd->limited;
  98. +    if (strchr(a->from, '/') == NULL||readmask(a->from, &a->net, &a->mask) < 0)
  99. +    a->net = INADDR_NONE;
  100.      return NULL;
  101.  }
  102.  
  103. @@ -213,6 +245,11 @@
  104.          else
  105.              gothost = 2;
  106.      }
  107. +
  108. +
  109. +    if (ap[i].net != INADDR_NONE
  110. +        && (r->connection->remote_addr.sin_addr.s_addr & ap[i].mask) == ap[i].net)
  111. +      return 1;
  112.  
  113.          if ((gothost == 2) && in_domain(ap[i].from, remotehost))
  114.              return 1;
  115.