httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sherer <mdshe...@tasc.com>
Subject environment patch
Date Wed, 07 Jul 1999 13:17:28 GMT
I originally submitted this as a change request for the mod_access
module, but when I
coded it, it looks like it could be useful elsewhere.  Basically, this
will allow environment
variables to be passed as a command to any of the commands at startup.
Here's what I
had in mind when I started:   We have a lot of groups of ip addresses,
each of which applies
to protected directories and such, but to move these around when we
change permissions
would get tedious.  For example, we may have 20 ip groups that  have
permission on one
directory, but if we want to grant them all access to another directory,
we would have to
define that directory, then add all the ip addresses again.  The same
thing happens when we
want to rearrange the groups - we have to find all the directories that
apply and remove an
ip group from that directory.  So I modified http_config.c so that when
it sees a word starting
with "$" it will get it as an environment variable, and pass the
contents piece by piece on to the
correct handler.  It works for ip groupings, but I figure people might
find it useful for other
parts of the httpd.conf file also.  If this is the wrong list, let me
know.  Here's a small example of
what we're using it for:

GROUP1=205.124.34.*:192.112.102.*:206.34.2.1
GROUP2=143.54.32.*:45.213.78.2:209.54.12.*:231.23.43.7

<Directory ......>
.....
   Allow from $GROUP1 $GROUP2
</Directory>

(Also, I'm no master of diff...I just used diff -u from my version
agains http_config.c in 1.3.6)
--- http_config.c Wed Mar 10 05:34:06 1999
+++ /home/msherer/http_config.c Tue Jun 29 09:59:52 1999
@@ -775,6 +775,9 @@
 {
     char *w, *w2, *w3;
     const char *errmsg;
+    char *envval, *val, *temp, *envcpy;
+    char itemp;
+

     if ((parms->override & cmd->req_override) == 0)
  return ap_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
@@ -909,10 +912,37 @@


  while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
+ {
+         if (!strncmp(w2,"$",1))
+            {
+                w2++;
+                envval = getenv(w2);
+                if (envval == NULL)
+                    return ap_pstrcat(parms->pool, cmd->name,
+                           " expecting environment variable, not
defined",
+                           NULL, NULL);
+                envcpy = malloc(strlen(envval));
+                strcpy(envcpy,envval);
+                while ((val = strchr(envcpy,':')) != NULL)
+                {
+                    *val = '\0'; val++;
+                    temp = malloc(strlen(envcpy));
+                    strcpy(temp,envcpy);
+                    if ((errmsg = ((const char *(*)(cmd_parms *, void
*,
+                        const char *, const char *)) (cmd->func))
(parms,
+                            mconfig, w, temp)))
+                        return errmsg;
+                    envcpy = val;
+                }
+                temp = malloc(strlen(envcpy));
+                strcpy(temp,envcpy);
+                w2 = temp;
+            }
      if   ((errmsg = ((const char *(*)(cmd_parms *, void *,
        const char *, const char *)) (cmd->func)) (parms,
            mconfig, w, w2)))
    return errmsg;
+        }

  return NULL;




Mime
View raw message