httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject cvs commit: apache-1.3/src/modules/standard mod_usertrack.c
Date Thu, 16 Oct 2003 17:23:26 GMT
jim         2003/10/16 10:23:26

  Modified:    .        STATUS
               src      CHANGES
               src/modules/standard mod_usertrack.c
  Log:
    *) Fixed mod_usertrack to not get false positive matches on the
       user-tracking cookie's name.  PR 16661.
       [Manni Wood <manniwood@planet-save.com>]
  
  PR: 16661 (2.x)
  Reviewed by:	cliff, jeff, jim
  
  Revision  Changes    Path
  1.1048    +1 -5      apache-1.3/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/apache-1.3/STATUS,v
  retrieving revision 1.1047
  retrieving revision 1.1048
  diff -u -r1.1047 -r1.1048
  --- STATUS	16 Oct 2003 17:18:43 -0000	1.1047
  +++ STATUS	16 Oct 2003 17:23:26 -0000	1.1048
  @@ -56,10 +56,6 @@
          Message-Id: <3F8C56E3.8050501@attglobal.net>
           +1: jeff, jim
   
  -   * [PATCH] mod_usertrack cookie matching
  -       Message-Id: <Pine.GSO.4.58.0310151648120.17890@cobra.cs.Virginia.EDU>
  -        +1: cliff, jeff, jim
  -
   
   RELEASE NON-SHOWSTOPPERS BUT WOULD BE REAL NICE TO WRAP THESE UP:
   
  
  
  
  1.1906    +4 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1905
  retrieving revision 1.1906
  diff -u -r1.1905 -r1.1906
  --- CHANGES	18 Sep 2003 18:54:26 -0000	1.1905
  +++ CHANGES	16 Oct 2003 17:23:26 -0000	1.1906
  @@ -1,5 +1,9 @@
   Changes with Apache 1.3.29
   
  +  *) Fixed mod_usertrack to not get false positive matches on the
  +     user-tracking cookie's name.  PR 16661.
  +     [Manni Wood <manniwood@planet-save.com>]
  +
     *) Enabled RFC1413 ident functionality for both Win32 and
        NetWare platforms.  This also included an alternate thread safe
        implementation of the socket timout functionality when querying
  
  
  
  1.57      +53 -19    apache-1.3/src/modules/standard/mod_usertrack.c
  
  Index: mod_usertrack.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_usertrack.c,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- mod_usertrack.c	3 Feb 2003 17:13:30 -0000	1.56
  +++ mod_usertrack.c	16 Oct 2003 17:23:26 -0000	1.57
  @@ -126,6 +126,8 @@
       char *cookie_name;
       char *cookie_domain;
       char *prefix_string;
  +    char *regexp_string;  /* used to compile regexp; save for debugging */
  +    regex_t *regexp;  /* used to find usertrack cookie in cookie header */
   } cookie_dir_rec;
   
   /* Define this to allow post-2000 cookies. Cookies use two-digit dates,
  @@ -284,35 +286,48 @@
       return;
   }
   
  +/* dcfg->regexp is "^cookie_name=([^;]+)|;[ \t]+cookie_name=([^;]+)",
  + * which has three subexpressions, $0..$2 */
  +#define NUM_SUBS 3
  +
   static int spot_cookie(request_rec *r)
   {
       cookie_dir_rec *dcfg = ap_get_module_config(r->per_dir_config,
   						&usertrack_module);
  -    const char *cookie;
  -    char *value;
  +    const char *cookie_header;
  +    regmatch_t regm[NUM_SUBS];
  +    int i;
   
       if (!dcfg->enabled) {
           return DECLINED;
       }
   
  -    if ((cookie = ap_table_get(r->headers_in,
  -                               (dcfg->style == CT_COOKIE2
  -                                ? "Cookie2"
  -                                : "Cookie"))))
  -        if ((value = strstr(cookie, dcfg->cookie_name))) {
  -            char *cookiebuf, *cookieend;
  -
  -            value += strlen(dcfg->cookie_name) + 1;  /* Skip over the '=' */
  -            cookiebuf = ap_pstrdup(r->pool, value);
  -            cookieend = strchr(cookiebuf, ';');
  -            if (cookieend)
  -                *cookieend = '\0';      /* Ignore anything after a ; */
  -
  -            /* Set the cookie in a note, for logging */
  -            ap_table_setn(r->notes, "cookie", cookiebuf);
  +    if ((cookie_header = ap_table_get(r->headers_in,
  +                                      (dcfg->style == CT_COOKIE2
  +                                       ? "Cookie2"
  +                                       : "Cookie")))) {
  +	if (!ap_regexec(dcfg->regexp, cookie_header, NUM_SUBS, regm, 0)) {
  +	    char *cookieval = NULL;
  +	    /* Our regexp,
  +	     * ^cookie_name=([^;]+)|;[ \t]+cookie_name=([^;]+)
  +	     * only allows for $1 or $2 to be available. ($0 is always
  +	     * filled with the entire matched expression, not just
  +	     * the part in parentheses.) So just check for either one
  +	     * and assign to cookieval if present. */
  +	    if (regm[1].rm_so != -1) {
  +		cookieval = ap_pregsub(r->pool, "$1", cookie_header, 
  +                                       NUM_SUBS, regm);
  +	    }
  +	    if (regm[2].rm_so != -1) {
  +		cookieval = ap_pregsub(r->pool, "$2", cookie_header, 
  +                                       NUM_SUBS, regm);
  +	    }
  +	    /* Set the cookie in a note, for logging */
  +	    ap_table_setn(r->notes, "cookie", cookieval);
   
  -            return DECLINED;    /* There's already a cookie, no new one */
  -        }
  +	    return DECLINED;    /* There's already a cookie, no new one */
  +	}
  +    }
       make_cookie(r);
       return OK;                  /* We set our cookie */
   }
  @@ -422,7 +437,26 @@
   {
       cookie_dir_rec *dcfg = (cookie_dir_rec *) mconfig;
   
  +    /* The goal is to end up with this regexp, 
  +     * ^cookie_name=([^;]+)|;[ \t]+cookie_name=([^;]+)
  +     * with cookie_name
  +     * obviously substituted with the real cookie name set by the
  +     * user in httpd.conf. */
  +    dcfg->regexp_string = ap_pstrcat(cmd->pool, "^", name, 
  +                                     "=([^;]+)|;[ \t]+", name, 
  +                                     "=([^;]+)", NULL);
  +
       dcfg->cookie_name = ap_pstrdup(cmd->pool, name);
  +
  +    dcfg->regexp = ap_pregcomp(cmd->pool, dcfg->regexp_string, REG_EXTENDED);
  +    if (dcfg->regexp == NULL) {
  +	return "Regular expression could not be compiled.";
  +    }
  +    if (dcfg->regexp->re_nsub + 1 != NUM_SUBS) {
  +        return ap_pstrcat(cmd->pool, "Invalid cookie name \"",
  +                           name, "\"", NULL);
  +    }
  +
       return NULL;
   }
   
  
  
  

Mime
View raw message