--------------------- PatchSet 11924 Date: 2008/01/23 10:39:01 Author: hno Branch: SQUID_2_7 Tag: (none) Log: Author: adrian squid.conf include support squid.conf include directive enabling squid.conf to be split in multiple files Members: src/cache_cf.c:1.480.2.1->1.480.2.2 src/cf.data.pre:1.450.2.5->1.450.2.6 Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid/squid/src/cache_cf.c,v retrieving revision 1.480.2.1 retrieving revision 1.480.2.2 diff -u -r1.480.2.1 -r1.480.2.2 --- squid/src/cache_cf.c 22 Jan 2008 14:36:46 -0000 1.480.2.1 +++ squid/src/cache_cf.c 23 Jan 2008 10:39:01 -0000 1.480.2.2 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.480.2.1 2008/01/22 14:36:46 hno Exp $ + * $Id: cache_cf.c,v 1.480.2.2 2008/01/23 10:39:01 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -132,6 +132,8 @@ static void free_programline(wordlist **); static void dump_programline(StoreEntry *, const char *, const wordlist *); +static int parseOneConfigFile(const char *file_name, int depth); + void self_destruct(void) { @@ -324,24 +326,45 @@ store_maxobjsize = ms; } -int -parseConfigFile(const char *file_name) +static int +parseManyConfigFiles(char *files, int depth) +{ + int error_count = 0; + char *saveptr = NULL; + char *file = strwordtok(files, &saveptr); + while (file != NULL) { + error_count += parseOneConfigFile(file, depth); + file = strwordtok(NULL, &saveptr); + } + return error_count; +} + +static int +parseOneConfigFile(const char *file_name, int depth) { FILE *fp = NULL; + const char *orig_cfg_filename = cfg_filename; + int orig_config_lineno = config_lineno; char *token = NULL; char *tmp_line = NULL; int tmp_line_len = 0; size_t config_input_line_len; int err_count = 0; - configFreeMemory(); - default_all(); + + debug(3, 1) ("Including Configuration File: %s (depth %d)\n", file_name, depth); + if (depth > 16) { + debug(0, 0) ("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name); + return 1; + } if ((fp = fopen(file_name, "r")) == NULL) fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); #ifdef _SQUID_WIN32_ setmode(fileno(fp), O_TEXT); #endif + cfg_filename = file_name; + if ((token = strrchr(cfg_filename, '/'))) cfg_filename = token + 1; memset(config_input_line, '\0', BUFSIZ); @@ -368,25 +391,46 @@ continue; } debug(3, 5) ("Processing: '%s'\n", tmp_line); - if (!parse_line(tmp_line)) { - debug(3, 0) ("parseConfigFile: line %d unrecognized: '%s'\n", + + /* Handle includes here */ + if (tmp_line_len >= 9 && + strncmp(tmp_line, "include", 7) == 0 && + xisspace(tmp_line[7])) { + err_count += parseManyConfigFiles(tmp_line + 8, depth + 1); + } else if (!parse_line(tmp_line)) { + debug(3, 0) ("parseConfigFile: %s:%d unrecognized: '%s'\n", + cfg_filename, config_lineno, - config_input_line); + tmp_line); err_count++; } safe_free(tmp_line); tmp_line_len = 0; } fclose(fp); + cfg_filename = orig_cfg_filename; + config_lineno = orig_config_lineno; + return err_count; +} + +int +parseConfigFile(const char *file_name) +{ + int ret; + + configFreeMemory(); + default_all(); + ret = parseOneConfigFile(file_name, 0); defaults_if_none(); configDoConfigure(); + if (opt_send_signal == -1) { cachemgrRegister("config", "Current Squid Configuration", dump_config, 1, 1); } - return err_count; + return ret; } static void Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid/squid/src/cf.data.pre,v retrieving revision 1.450.2.5 retrieving revision 1.450.2.6 diff -u -r1.450.2.5 -r1.450.2.6 --- squid/src/cf.data.pre 23 Jan 2008 10:36:46 -0000 1.450.2.5 +++ squid/src/cf.data.pre 23 Jan 2008 10:39:01 -0000 1.450.2.6 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.450.2.5 2008/01/23 10:36:46 hno Exp $ +# $Id: cf.data.pre,v 1.450.2.6 2008/01/23 10:39:01 hno Exp $ # # SQUID Web Proxy Cache http://www.squid-cache.org/ # ---------------------------------------------------------- @@ -48,6 +48,20 @@ COMMENT_END COMMENT_START + Configuration options can be included using the "include" directive. + Include takes a list of files to include. Quoting is supported. + + For example, + + include /path/to/included/file/squid.acl.config + + Includes can be nested up to a hard-coded depth of 16 levels. + This arbitrary restriction is to prevent recursive include references + from causing Squid entering an infinite loop whilst trying to load + configuration files. +COMMENT_END + +COMMENT_START OPTIONS FOR AUTHENTICATION ----------------------------------------------------------------------------- COMMENT_END @@ -5561,4 +5575,5 @@ time. DOC_END + EOF