- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
-#ifdef REGEX
- || ((b->url->preg = zalloc(sizeof(*b->url->preg))) == NULL)
-#endif
- )
- {
- fclose(fp);
- goto load_imagefile_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* save a copy of the orignal specification */
- if ((b->url->spec = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_imagefile_error;
- }
-
- b->reject = reject;
-
- if ((p = strchr(buf, '/')))
- {
- b->url->path = strdup(p);
- b->url->pathlen = strlen(b->url->path);
- *p = '\0';
- }
- else
- {
- b->url->path = NULL;
- b->url->pathlen = 0;
- }
-#ifdef REGEX
- if (b->url->path)
- {
- int errcode;
- char rebuf[BUFSIZ];
-
- sprintf(rebuf, "^(%s)", b->url->path);
-
- errcode = regcomp(b->url->preg, rebuf,
- (REG_EXTENDED|REG_NOSUB|REG_ICASE));
-
- if (errcode)
- {
- size_t errlen =
- regerror(errcode,
- b->url->preg, buf, sizeof(buf));
-
- buf[errlen] = '\0';
-
- log_error(LOG_LEVEL_ERROR, "error compiling %s: %s",
- b->url->spec, buf);
- fclose(fp);
- goto load_imagefile_error;
- }
- }
- else
- {
- freez(b->url->preg);
- }
-#endif
- if ((p = strchr(buf, ':')) == NULL)
- {
- port = 0;
- }
- else
- {
- *p++ = '\0';
- port = atoi(p);
- }
-
- b->url->port = port;
-
- if ((b->url->domain = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_imagefile_error;
- }
-
- /* split domain into components */
- *url = dsplit(b->url->domain);
- b->url->dbuf = url->dbuf;
- b->url->dcnt = url->dcnt;
- b->url->dvec = url->dvec;
- }
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- fclose(fp);
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- /* the old one is now obsolete */
- if (current_imagefile)
- {
- current_imagefile->unloader = unload_imagefile;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_imagefile = fs;
-
- if (csp)
- {
- csp->ilist = fs;
- }
-
- return(0);
-
-load_imagefile_error:
- log_error(LOG_LEVEL_ERROR, "can't load imagefile '%s': %E", imagefile);
- return(-1);
-
-}
-#endif /* def USE_IMAGE_LIST */
-
-
-/*********************************************************************
- *
- * Function : load_cookiefile
- *
- * Description : Read and parse a cookiefile and add to files list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-int load_cookiefile(struct client_state *csp)
-{
- FILE *fp;
-
- struct cookie_spec *b, *bl;
- char buf[BUFSIZ], *p, *q;
- int port, user_cookie, server_cookie;
- struct file_list *fs;
- struct url_spec url[1];
-
- if (!check_file_changed(current_cookiefile, cookiefile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->clist = current_cookiefile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_cookie_error;
- }
-
- fs->f = bl = (struct cookie_spec *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_cookie_error;
- }
-
- if ((fp = fopen(cookiefile, "r")) == NULL)
- {
- goto load_cookie_error;
- }
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- p = buf;
-
- switch ((int)*p)
- {
- case '>':
- server_cookie = 0;
- user_cookie = 1;
- p++;
- break;
-
- case '<':
- server_cookie = 1;
- user_cookie = 0;
- p++;
- break;
-
- case '~':
- server_cookie = 0;
- user_cookie = 0;
- p++;
- break;
-
- default:
- server_cookie = 1;
- user_cookie = 1;
- break;
- }
-
- /*
- * Elide any of the "special" chars from the
- * front of the pattern
- */
- q = buf;
- if (p > q) while ((*q++ = *p++))
- {
- /* nop */
- }
-
- /* skip lines containing only "special" chars */
- if (*buf == '\0')
- {
- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
-#ifdef REGEX
- || ((b->url->preg = zalloc(sizeof(*b->url->preg))) == NULL)
-#endif
- )
- {
- fclose(fp);
- goto load_cookie_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* save a copy of the orignal specification */
- if ((b->url->spec = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_cookie_error;
- }
-
- b->send_user_cookie = user_cookie;
- b->accept_server_cookie = server_cookie;
-
- if ((p = strchr(buf, '/')))
- {
- b->url->path = strdup(p);
- b->url->pathlen = strlen(b->url->path);
- *p = '\0';
- }
- else
- {
- b->url->path = NULL;
- b->url->pathlen = 0;
- }
-#ifdef REGEX
- if (b->url->path)
- {
- int errcode;
- char rebuf[BUFSIZ];
-
- sprintf(rebuf, "^(%s)", b->url->path);
-
- errcode = regcomp(b->url->preg, rebuf,
- (REG_EXTENDED|REG_NOSUB|REG_ICASE));
- if (errcode)
- {
- size_t errlen =
- regerror(errcode,
- b->url->preg, buf, sizeof(buf));
-
- buf[errlen] = '\0';
-
- log_error(LOG_LEVEL_ERROR, "error compiling %s: %s",
- b->url->spec, buf);
- fclose(fp);
- goto load_cookie_error;
- }
- }
- else
- {
- freez(b->url->preg);
- }
-#endif
- if ((p = strchr(buf, ':')) == NULL)
- {
- port = 0;
- }
- else
- {
- *p++ = '\0';
- port = atoi(p);
- }
-
- b->url->port = port;
-
- if ((b->url->domain = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_cookie_error;
- }
-
- /* split domain into components */
-
- *url = dsplit(b->url->domain);
- b->url->dbuf = url->dbuf;
- b->url->dcnt = url->dcnt;
- b->url->dvec = url->dvec;
- }
-
- fclose(fp);
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- /* the old one is now obsolete */
- if (current_cookiefile)
- {
- current_cookiefile->unloader = unload_cookiefile;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_cookiefile = fs;
-
- if (csp)
- {
- csp->clist = fs;
- }
-
- return(0);
-
-load_cookie_error:
- log_error(LOG_LEVEL_ERROR, "can't load cookiefile '%s': %E", cookiefile);
- return(-1);
-
-}
-
-
-#ifdef TRUST_FILES
-/*********************************************************************
- *
- * Function : load_trustfile
- *
- * Description : Read and parse a trustfile and add to files list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-int load_trustfile(struct client_state *csp)
-{
- FILE *fp;
-
- struct block_spec *b, *bl;
- struct url_spec **tl;
-
- char buf[BUFSIZ], *p, *q;
- int port, reject, trusted;
- struct file_list *fs;
- struct url_spec url[1];
-
- if (!check_file_changed(current_trustfile, trustfile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->tlist = current_trustfile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_trustfile_error;
- }
-
- fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_trustfile_error;
- }
-
- if ((fp = fopen(trustfile, "r")) == NULL)
- {
- goto load_trustfile_error;
- }
-
- tl = trust_list;
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- trusted = 0;
- reject = 1;
-
- if (*buf == '+')
- {
- trusted = 1;
- *buf = '~';
- }
-
- if (*buf == '~')
- {
- reject = 0;
- p = buf;
- q = p+1;
- while ((*p++ = *q++))
- {
- /* nop */
- }
- }
-
- /* skip blank lines */
- if (*buf == '\0')
- {
- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
-#ifdef REGEX
- || ((b->url->preg = zalloc(sizeof(*b->url->preg))) == NULL)
-#endif
- )
- {
- fclose(fp);
- goto load_trustfile_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* save a copy of the orignal specification */
- if ((b->url->spec = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_trustfile_error;
- }
-
- b->reject = reject;
-
- if ((p = strchr(buf, '/')))
- {
- b->url->path = strdup(p);
- b->url->pathlen = strlen(b->url->path);
- *p = '\0';
- }
- else
- {
- b->url->path = NULL;
- b->url->pathlen = 0;
- }
-#ifdef REGEX
- if (b->url->path)
- {
- int errcode;
- char rebuf[BUFSIZ];
-
- sprintf(rebuf, "^(%s)", b->url->path);
-
- errcode = regcomp(b->url->preg, rebuf,
- (REG_EXTENDED|REG_NOSUB|REG_ICASE));
-
- if (errcode)
- {
- size_t errlen =
- regerror(errcode,
- b->url->preg, buf, sizeof(buf));
-
- buf[errlen] = '\0';
-
- log_error(LOG_LEVEL_ERROR, "error compiling %s: %s",
- b->url->spec, buf);
- fclose(fp);
- goto load_trustfile_error;
- }
- }
- else
- {
- freez(b->url->preg);
- }
-#endif
- if ((p = strchr(buf, ':')) == NULL)
- {
- port = 0;
- }
- else
- {
- *p++ = '\0';
- port = atoi(p);
- }
-
- b->url->port = port;
-
- if ((b->url->domain = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_trustfile_error;
- }
-
- /* split domain into components */
- *url = dsplit(b->url->domain);
- b->url->dbuf = url->dbuf;
- b->url->dcnt = url->dcnt;
- b->url->dvec = url->dvec;
-
- /*
- * save a pointer to URL's spec in the list of trusted URL's, too
- */
- if (trusted)
- {
- *tl++ = b->url;
- }
- }
-
- *tl = NULL;
-
- fclose(fp);
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- /* the old one is now obsolete */
- if (current_trustfile)
- {
- current_trustfile->unloader = unload_trustfile;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_trustfile = fs;
-
- if (csp)
- {
- csp->tlist = fs;
- }
-
- return(0);
-
-load_trustfile_error:
- log_error(LOG_LEVEL_ERROR, "can't load trustfile '%s': %E", trustfile);
- return(-1);
-
-}
-#endif /* def TRUST_FILES */
-
-
-/*********************************************************************
- *
- * Function : load_forwardfile
- *
- * Description : Read and parse a forwardfile and add to files list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-int load_forwardfile(struct client_state *csp)
-{
- FILE *fp;
-
- struct forward_spec *b, *bl;
- char buf[BUFSIZ], *p, *q, *tmp;
- char *vec[4];
- int port, n, reject;
- struct file_list *fs;
- const struct gateway *gw;
- struct url_spec url[1];
-
- if (!check_file_changed(current_forwardfile, forwardfile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->flist = current_forwardfile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_forwardfile_error;
- }
-
- fs->f = bl = (struct forward_spec *)zalloc(sizeof(*bl));
-
- if ((fs == NULL) || (bl == NULL))
- {
- goto load_forwardfile_error;
- }
-
- if ((fp = fopen(forwardfile, "r")) == NULL)
- {
- goto load_forwardfile_error;
- }
-
- tmp = NULL;
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- freez(tmp);
-
- tmp = strdup(buf);
-
- n = ssplit(tmp, " \t", vec, SZ(vec), 1, 1);
-
- if (n != 4)
- {
- log_error(LOG_LEVEL_ERROR, "error in forwardfile: %s", buf);
- continue;
- }
-
- strcpy(buf, vec[0]);
-
- reject = 1;
-
- if (*buf == '~')
- {
- reject = 0;
- p = buf;
- q = p+1;
- while ((*p++ = *q++))
- {
- /* nop */
- }
- }
-
- /* skip lines containing only ~ */
- if (*buf == '\0')
- {
- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
-#ifdef REGEX
- || ((b->url->preg = zalloc(sizeof(*b->url->preg))) == NULL)
-#endif
- )
- {
- fclose(fp);
- goto load_forwardfile_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* save a copy of the orignal specification */
- if ((b->url->spec = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_forwardfile_error;
- }
-
- b->reject = reject;
-
- if ((p = strchr(buf, '/')))
- {
- b->url->path = strdup(p);
- b->url->pathlen = strlen(b->url->path);
- *p = '\0';
- }
- else
- {
- b->url->path = NULL;
- b->url->pathlen = 0;
- }
-#ifdef REGEX
- if (b->url->path)
- {
- int errcode;
- char rebuf[BUFSIZ];
-
- sprintf(rebuf, "^(%s)", b->url->path);
-
- errcode = regcomp(b->url->preg, rebuf,
- (REG_EXTENDED|REG_NOSUB|REG_ICASE));
-
- if (errcode)
- {
- size_t errlen = regerror(errcode, b->url->preg, buf, sizeof(buf));
-
- buf[errlen] = '\0';
-
- log_error(LOG_LEVEL_ERROR, "error compiling %s: %s",
- b->url->spec, buf);
- fclose(fp);
- goto load_forwardfile_error;
- }
- }
- else
- {
- freez(b->url->preg);
- }
-#endif
- if ((p = strchr(buf, ':')) == NULL)
- {
- port = 0;
- }
- else
- {
- *p++ = '\0';
- port = atoi(p);
- }
-
- b->url->port = port;
-
- if ((b->url->domain = strdup(buf)) == NULL)
- {
- fclose(fp);
- goto load_forwardfile_error;
- }
-
- /* split domain into components */
- *url = dsplit(b->url->domain);
- b->url->dbuf = url->dbuf;
- b->url->dcnt = url->dcnt;
- b->url->dvec = url->dvec;
-
- /* now parse the gateway specs */
-
- p = vec[2];
-
- for (gw = gateways; gw->name; gw++)
- {
- if (strcmp(gw->name, p) == 0)
- {
- break;
- }