- *********************************************************************/
-int load_aclfile(struct client_state *csp)
-{
- FILE *fp;
- char buf[BUFSIZ], *v[3], *p;
- int i;
- struct access_control_list *a, *bl;
- struct file_list *fs;
-
- if (!check_file_changed(current_aclfile, aclfile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->alist = current_aclfile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_aclfile_error;
- }
-
- fs->f = bl = (struct access_control_list *)zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- freez(fs->filename);
- freez(fs);
- goto load_aclfile_error;
- }
-
- fp = fopen(aclfile, "r");
-
- if (fp == NULL)
- {
- goto load_aclfile_error;
- }
-
- while (read_config_line(buf, sizeof(buf), fp, fs) != NULL)
- {
- i = ssplit(buf, " \t", v, SZ(v), 1, 1);
-
- /* allocate a new node */
- a = (struct access_control_list *) zalloc(sizeof(*a));
-
- if (a == NULL)
- {
- fclose(fp);
- freez(fs->f);
- freez(fs->filename);
- freez(fs);
- goto load_aclfile_error;
- }
-
- /* add it to the list */
- a->next = bl->next;
- bl->next = a;
-
- switch (i)
- {
- case 3:
- if (acl_addr(v[2], a->dst) < 0)
- {
- goto load_aclfile_error;
- }
- /* no break */
-
- case 2:
- if (acl_addr(v[1], a->src) < 0)
- {
- goto load_aclfile_error;
- }
-
- p = v[0];
- if (strcmpic(p, "permit") == 0)
- {
- a->action = ACL_PERMIT;
- break;
- }
-
- if (strcmpic(p, "deny") == 0)
- {
- a->action = ACL_DENY;
- break;
- }
- /* no break */
-
- default:
- goto load_aclfile_error;
- }
- }
-
- fclose(fp);
-
-#ifndef SPLIT_PROXY_ARGS
- if (!suppress_blocklists)
- {
- fs->proxy_args = strsav(fs->proxy_args, "</pre>");
- }
-#endif /* ndef SPLIT_PROXY_ARGS */
-
- if (current_aclfile)
- {
- current_aclfile->unloader = unload_aclfile;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_aclfile = fs;
-
- if (csp)
- {
- csp->alist = fs;
- }
-
- return(0);
-
-load_aclfile_error:
- log_error(LOG_LEVEL_ERROR, "can't load access control list %s: %E", aclfile);
- return(-1);
-
-}
-#endif /* def ACL_FILES */
-
-
-/*********************************************************************
- *
- * Function : load_blockfile
- *
- * Description : Read and parse a blockfile and add to files list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-int load_blockfile(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_blockfile, blockfile, &fs))
- {
- /* No need to load */
- if (csp)
- {
- csp->blist = current_blockfile;
- }
- return(0);
- }
- if (!fs)
- {
- goto load_blockfile_error;
- }
-
- fs->f = bl = (struct block_spec *) zalloc(sizeof(*bl));
- if (bl == NULL)
- {
- goto load_blockfile_error;
- }
-
- if ((fp = fopen(blockfile, "r")) == NULL)
- {
- goto load_blockfile_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_blockfile_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_blockfile_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_blockfile)
- {
- current_blockfile->unloader = unload_blockfile;
- }
-
- fs->next = files->next;
- files->next = fs;
- current_blockfile = fs;
-
- if (csp)
- {
- csp->blist = fs;
- }
-
- return(0);
-
-load_blockfile_error:
- log_error(LOG_LEVEL_ERROR, "can't load blockfile '%s': %E", blockfile);
- return(-1);
-
-}
-
-
-#ifdef USE_IMAGE_LIST
-/*********************************************************************
- *
- * Function : load_imagefile
- *
- * Description : Read and parse an imagefile and add to files list.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- *
- * Returns : 0 => Ok, everything else is an error.
- *
- *********************************************************************/
-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;