Hi,
To use squid as a gate (in http accel. mode) for a portal project, some
authentication is needed. Since in http accel. mode, we can't do
proxy_auth, the best place to do it is in the redirect_program but it
needs to receive the cookies. The following patch adds, at the end of
the line sent to the redirect_program, the 'Cookie: ...' line from the
HTTP header.
Note that this patch was done very quickly since it's only a small
portion of the project and I don't have time to do squid development.
It'd be great to have this feature so that more flexible redirectors
could be written. Someone more familiar with squid's source code could
probably redo/clean and integrate this patch in squid very quickly.
BTW, I changed the #define for malloc,free,calloc,sprintf,strdup. The
error given by gcc when one tried to use one of these was far from
obvious and made me waste a lot of time trying to figure out what was wrong.
Thanks.
----------------------------------------------------------------------
diff -u --recursive squid-2.4.STABLE2/src/Makefile.in squid-2.4.STABLE2-js1/src/Makefile.in
--- squid-2.4.STABLE2/src/Makefile.in Wed Apr 4 07:01:12 2001
+++ squid-2.4.STABLE2-js1/src/Makefile.in Wed Dec 5 22:42:57 2001
@@ -76,6 +76,7 @@
SHELL = /bin/sh
INCLUDE = -I. -I../include -I$(top_srcdir)/include
+DEFINES = -DREDIR_COOKIES
CFLAGS = $(AC_CFLAGS) $(INCLUDE) $(DEFINES)
SQUID_LIBS = -L../lib $(CRYPTLIB) $(REGEXLIB) @SQUID_PTHREAD_LIB@ \
$(SNMPLIB) $(MALLOCLIB) -lmiscutil $(XTRA_LIBS)
diff -u --recursive squid-2.4.STABLE2/src/client_side.c squid-2.4.STABLE2-js1/src/client_side.c
--- squid-2.4.STABLE2/src/client_side.c Fri Apr 20 23:21:41 2001
+++ squid-2.4.STABLE2-js1/src/client_side.c Thu Dec 6 01:18:24 2001
@@ -2263,6 +2263,9 @@
char *token = NULL;
char *t = NULL;
char *end;
+#ifdef REDIR_COOKIES
+ char *cookies, *cookies_sz;
+#endif
int free_request = 0;
size_t header_sz; /* size of headers, not including first line */
size_t prefix_sz; /* size of whole request (req-line + headers) */
@@ -2375,6 +2378,18 @@
/* Ok, all headers are received */
http = memAllocate(MEM_CLIENTHTTPREQUEST);
cbdataAdd(http, memFree, MEM_CLIENTHTTPREQUEST);
+#ifdef REDIR_COOKIES
+ /* take the Cookie: line and put it in http->cookies */
+ cookies=strstr(req_hdr,"Cookie:");
+ if (cookies == NULL) {
+ http->cookies=xstrdup("-");
+ } else {
+ cookies_sz=strchr(cookies,'\n');
+ *cookies_sz='\0';
+ http->cookies=xstrdup(cookies);
+ *cookies_sz='\n';
+ }
+#endif
http->http_ver = http_ver;
http->conn = conn;
http->start = current_time;
diff -u --recursive squid-2.4.STABLE2/src/redirect.c squid-2.4.STABLE2-js1/src/redirect.c
--- squid-2.4.STABLE2/src/redirect.c Fri Jan 12 00:51:51 2001
+++ squid-2.4.STABLE2-js1/src/redirect.c Thu Dec 6 01:17:35 2001
@@ -96,6 +96,7 @@
redirectStateData *r = NULL;
const char *fqdn;
char buf[8192];
+ int buf_sz;
assert(http);
assert(handler);
debug(29, 5) ("redirectStart: '%s'\n", http->uri);
@@ -139,12 +140,24 @@
cbdataLock(r->data);
if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL)
fqdn = dash_str;
- snprintf(buf, 8192, "%s %s/%s %s %s\n",
+ buf_sz=snprintf(buf, 8192, "%s %s/%s %s %s\n",
r->orig_url,
inet_ntoa(r->client_addr),
fqdn,
r->client_ident,
r->method_s);
+#ifdef REDIR_COOKIES
+ /* erase the last \n from the snprintf */
+ buf[buf_sz-1]=' ';
+ /* append http->cookies + "\n\0" to buf */
+ assert((8180-buf_sz) > 0);
+ strncpy(&buf[buf_sz],http->cookies,8180-buf_sz);
+ buf_sz=strlen(buf);
+ buf[buf_sz++]='\n';
+ buf[buf_sz++]='\0';
+ xfree(http->cookies);
+ http->cookies=NULL;
+#endif
helperSubmit(redirectors, buf, redirectHandleReply, r);
}
diff -u --recursive squid-2.4.STABLE2/src/squid.h squid-2.4.STABLE2-js1/src/squid.h
--- squid-2.4.STABLE2/src/squid.h Thu Feb 22 21:39:14 2001
+++ squid-2.4.STABLE2-js1/src/squid.h Thu Dec 6 00:07:26 2001
@@ -401,19 +401,19 @@
* Also use xmemcpy, xisspace, ...
*/
#ifndef malloc
-#define malloc +
+#define malloc Use_xmalloc_instead+-
#endif
#ifndef free
-#define free +
+#define free Use_xfree_instead+-
#endif
#ifndef calloc
-#define calloc +
+#define calloc Use_xcalloc_instead+-
#endif
#ifndef sprintf
-#define sprintf +
+#define sprintf Use_snprintf_instead+-
#endif
#ifndef strdup
-#define strdup +
+#define strdup Use_xstrdup_instead+-
#endif
/*
diff -u --recursive squid-2.4.STABLE2/src/structs.h squid-2.4.STABLE2-js1/src/structs.h
--- squid-2.4.STABLE2/src/structs.h Wed Apr 4 07:01:12 2001
+++ squid-2.4.STABLE2-js1/src/structs.h Wed Dec 5 23:13:59 2001
@@ -870,6 +870,9 @@
};
struct _clientHttpRequest {
+#ifdef REDIR_COOKIES
+ char *cookies;
+#endif
ConnStateData *conn;
request_t *request; /* Parsed URL ... */
store_client *sc; /* The store_client we're using */
----------------------------------------------------------------------
-- _ ASCII ribbon campaign ( ) - against HTML email X & vcards / \ /********************************************************************** * Jonathan St-Andre Matrox Electronic Systems Ltd. * UNIX Systems Administrator IT Department * Administrateur de systemes UNIX 1055 Blv. St-Regis * Tel: 514-822-6000 x.2000 Dorval (Quebec) * Fax: 514-822-6262 H9P 2T4 * jstandre@matrox.com http://www.matrox.com **********************************************************************/Received on Wed Dec 05 2001 - 19:09:42 MST
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:40 MST