-int load_imagefile(struct client_state *csp)
-{
- FILE *fp;
-
- struct block_spec *b, *bl;
- char buf[BUFSIZ], *p, *q;
- int reject;
- struct file_list *fs;
-
- if (!check_file_changed(current_imagefile, imagefile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->ilist = current_imagefile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_imagefile_error;
- }
-
- fs->f = bl = (struct block_spec *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_imagefile_error;
- }
-
- if ((fp = fopen(imagefile, "r")) == NULL)
- {
- goto load_imagefile_error;
- }
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- 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)
- {
- fclose(fp);
- goto load_imagefile_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- b->reject = reject;
-
- /* Save the URL pattern */
- if (create_url_spec(b->url, buf))
- {
- fclose(fp);
- goto load_imagefile_error;
- }
- }
-
- 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_permissions_file
- *
- * Description : Read and parse a permissions file and add to files
- * list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-int load_permissions_file(struct client_state *csp)
-{
- FILE *fp;
-
- struct permissions_spec *b, *bl;
- char buf[BUFSIZ], *p, *q;
- int permissions;
- struct file_list *fs;
- int i;
-
- if (!check_file_changed(current_permissions_file, permissions_file, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->permissions_list = current_permissions_file;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_permissions_error;
- }
-
- fs->f = bl = (struct permissions_spec *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_permissions_error;
- }
-
- if ((fp = fopen(permissions_file, "r")) == NULL)
- {
- goto load_permissions_error;
- }
-
-
- /*
- * default_permissions is set in this file.
- *
- * Reset it to default first.
- */
- default_permissions = PERMIT_RE_FILTER;
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- p = buf;
-
- permissions = PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | PERMIT_POPUPS;
-
- /*
- * FIXME: for() loop is a kludge. Want to loop around until we
- * find a non-control character. Assume there will be at most 4
- * characters.
- */
- for (i = 0; i < 4; i++)
- {
- switch ((int)*p)
- {
- case '>':
- /*
- * Allow cookies to be read by the server, but do
- * not allow them to be set.
- */
- permissions = (permissions & ~PERMIT_COOKIE_SET);
- p++;
- break;
-
- case '<':
- /*
- * Allow server to set cookies but do not let the
- * server read them.
- */
- permissions = (permissions & ~PERMIT_COOKIE_READ);
- p++;
- break;
-
- case '^':
- /*
- * Block popups
- */
- permissions = (permissions & ~PERMIT_POPUPS);
- p++;
- break;
-
- case '%':
- /*
- * Permit filtering using PCRS
- */
- permissions = (permissions | PERMIT_RE_FILTER);
- p++;
- break;
-
- case '~':
- /*
- * All of the above (maximum filtering).
- */
- permissions = PERMIT_RE_FILTER;
- p++;
- break;
-
- default:
- /*
- * FIXME: Should break out of the loop here.
- */
- break;
- }
- }
-
- /*
- * Elide any of the "special" chars from the
- * front of the pattern
- */
- q = buf;
- if (p > q)
- {
- while ((*q++ = *p++) != '\0')
- {
- /* nop */
- }
- }
-
- /* a lines containing only "special" chars sets default */
- if (*buf == '\0')
- {
- default_permissions = permissions;
- continue;
- }
-
- /* allocate a new node */
- if (((b = zalloc(sizeof(*b))) == NULL)
- )
- {
- fclose(fp);
- goto load_permissions_error;
- }
-
- /* add it to the list */
- b->next = bl->next;
- bl->next = b;
-
- /* Save flags */
- b->permissions = permissions;
-
- /* Save the URL pattern */
- if (create_url_spec(b->url, buf))
- {
- fclose(fp);
- goto load_permissions_error;
- }
- }
-
- 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_permissions_file)
- {
- current_permissions_file->unloader = unload_permissions_file;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_permissions_file = fs;
-
- if (csp)
- {
- csp->permissions_list = fs;
- }
-
- return(0);
-
-load_permissions_error:
- log_error(LOG_LEVEL_ERROR, "can't load permissions file '%s': %E", permissions_file);
- 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)