From 68a897b2beb366c777e593eaf022447228ac3808 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 3 Dec 2009 23:28:34 +0100 Subject: [PATCH] [MINOR] config: support passing multiple "domain" statements to cookies In some environments it is not possible to rely on any wildcard for a domain name (eg: .com, .net, .fr...) so it is required to send multiple domain extensions. (Un)fortunately the syntax check on the domain name prevented that from being done the dirty way. So let's just build a domain list when multiple domains are passed on the same line. (cherry picked from commit 950245ca2b772fd6b99b8152c48c694ed0212857) --- doc/configuration.txt | 9 +++++++-- src/cfgparse.c | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 47842d6c7..3c6dd642e 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -1503,7 +1503,7 @@ contimeout cookie [ rewrite | insert | prefix ] [ indirect ] [ nocache ] - [ postonly ] [ domain ] + [ postonly ] [ domain ]* Enable cookie-based persistence in a backend. May be used in sections : defaults | frontend | listen | backend yes | no | yes | yes @@ -1585,7 +1585,12 @@ cookie [ rewrite | insert | prefix ] [ indirect ] [ nocache ] domain This option allows to specify the domain at which a cookie is inserted. It requires exactly one paramater: a valid domain - name. + name. If the domain begins with a dot, the browser is allowed to + use it for any host ending with that name. It is also possible to + specify several domain names by invoking this option multiple + times. Some browsers might have small limits on the number of + domains, so be careful when doing that. For the record, sending + 10 domains to MSIE 6 or Firefox 2 works as expected. There can be only one persistence cookie per HTTP backend, and it can be declared in a defaults section. The value of the cookie will be the value diff --git a/src/cfgparse.c b/src/cfgparse.c index d433ea314..e74b7687a 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1475,7 +1475,21 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } - curproxy->cookie_domain = strdup(args[cur_arg + 1]); + if (!curproxy->cookie_domain) { + curproxy->cookie_domain = strdup(args[cur_arg + 1]); + } else { + /* one domain was already specified, add another one by + * building the string which will be returned along with + * the cookie. + */ + char *new_ptr; + int new_len = strlen(curproxy->cookie_domain) + + strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; + new_ptr = malloc(new_len); + snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); + free(curproxy->cookie_domain); + curproxy->cookie_domain = new_ptr; + } cur_arg++; } else {