httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgau...@hyperreal.org
Subject cvs commit: apachen/src/main http_config.c util.c
Date Wed, 21 Jan 1998 22:11:04 GMT
dgaudet     98/01/21 14:11:04

  Modified:    src      CHANGES
               src/main http_config.c util.c
  Log:
  Clean up the -C/-c implementation.
  
  Submitted by:	Martin Kraemer
  Reviewed by:	Dean Gaudet, Doug MacEachern, Jim Jagielski
  
  Revision  Changes    Path
  1.577     +1 -1      apachen/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/CHANGES,v
  retrieving revision 1.576
  retrieving revision 1.577
  diff -u -r1.576 -r1.577
  --- CHANGES	1998/01/21 22:05:43	1.576
  +++ CHANGES	1998/01/21 22:10:59	1.577
  @@ -78,7 +78,7 @@
        -c "directive" : process directive after reading config files
        example:
        httpd -C "PerlModule Apache::httpd_conf"
  -     [Doug MacEachern]
  +     [Doug MacEachern, Martin Kraemer]
   
     *) WIN32: Fix the execution of CGIs that are scripts and called 
        with path info that does not have an '=' in.
  
  
  
  1.94      +54 -21    apachen/src/main/http_config.c
  
  Index: http_config.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/http_config.c,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- http_config.c	1998/01/13 23:11:09	1.93
  +++ http_config.c	1998/01/21 22:11:01	1.94
  @@ -908,40 +908,73 @@
       return make_full_path(p, server_root, file);
   }
   
  +
  +/* This structure and the following functions are needed for the
  + * table-based config file reading. They are passed to the
  + * cfg_open_custom() routine.
  + */
  +
  +/* Structure to be passed to cfg_open_custom(): it contains an
  + * index which is incremented from 0 to nelts on each call to
  + * cfg_getline() (which in turn calls arr_elts_getstr())
  + * and an array_header pointer for the string array.
  + */
  +typedef struct {
  +    array_header *array;
  +    int curr_idx;
  +} arr_elts_param_t;
  +
  +
  +/* arr_elts_getstr() returns the next line from the string array. */
  +static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
  +{
  +    arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
  +
  +    /* End of array reached? */
  +    if (++arr_param->curr_idx > arr_param->array->nelts)
  +        return NULL;
  +
  +    /* return the line */
  +    ap_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1],
bufsiz);
  +
  +    return buf;
  +}
  +
  +
  +/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
  +static int arr_elts_close(void *param)
  +{
  +    arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
  +    arr_param->curr_idx = arr_param->array->nelts;
  +    return 0;
  +}
  +
   void process_command_config(server_rec *s, array_header *arr, pool *p, pool *ptemp)
   {
       const char *errmsg;
       cmd_parms parms;
  -    int i;
  -    char **lines = (char **)arr->elts;
  +    arr_elts_param_t arr_parms;
  +
  +    arr_parms.curr_idx = 0;
  +    arr_parms.array = arr;
   
       parms = default_parms;
       parms.pool = p;
       parms.temp_pool = ptemp;
       parms.server = s;
       parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
  -    parms.config_file = pcfg_openfile(p, NULL);
  +    parms.config_file = pcfg_open_custom(p, "-c/-C directives",
  +                                         &arr_parms, NULL,
  +                                         arr_elts_getstr, arr_elts_close);
   
  -    for (i = 0; i < arr->nelts; ++i) {
  -	char *line = lines[i];
  +    errmsg = srm_command_loop(&parms, s->lookup_defaults);
   
  -#ifdef MOD_PERL
  -	if(!(strncmp(line, "PerlModule ", 11))) {
  -	    const char *perl_cmd_module(cmd_parms *parms, void *dummy, char *arg);
  -	    line += 11;
  -	    (void)perl_cmd_module(&parms, s->lookup_defaults, line);
  -	    continue;
  -	}
  -#endif
  -	    
  -	errmsg = handle_command(&parms, s->lookup_defaults, line);
  -
  -	if (errmsg) {
  -	    fprintf(stderr, "Syntax error in command: `%s'\n", lines[i]);
  -	    fprintf(stderr, "%s\n", errmsg);
  -	    exit(1);
  -	}
  +    if (errmsg) {
  +        fprintf(stderr, "Syntax error in -C/-c directive:\n%s\n", errmsg);
  +        exit(1);
       }
  +
  +    cfg_closefile(parms.config_file);
   }
   
   void process_resource_config(server_rec *s, char *fname, pool *p, pool *ptemp)
  
  
  
  1.89      +33 -16    apachen/src/main/util.c
  
  Index: util.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/main/util.c,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- util.c	1998/01/20 01:48:47	1.88
  +++ util.c	1998/01/21 22:11:02	1.89
  @@ -674,26 +674,43 @@
   {
       configfile_t *new_cfg;
       FILE *file;
  +#ifdef unvoted_DISALLOW_DEVICE_ACCESS
  +    struct stat stbuf;
  +#endif
  +
  +    if (name == NULL) {
  +        aplog_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
  +               "Internal error: pcfg_openfile() called with NULL filename");
  +        return NULL;
  +    }
   
  +    file = fopen(name, "r");
   #ifdef DEBUG
  -    aplog_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, 
  -		"Opening config file %s (%s)", 
  -		name ? name : "NULL", 
  -		(name && (file == NULL)) ? strerror(errno) : "successful");
  +    aplog_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL,
  +                "Opening config file %s (%s)",
  +                name, (file == NULL) ? strerror(errno) : "successful");
   #endif
  +    if (file == NULL)
  +        return NULL;
   
  -    if (name != NULL) {
  -	file = fopen(name, "r");
  -	if (file == NULL)
  -	    return NULL;
  +#ifdef unvoted_DISALLOW_DEVICE_ACCESS
  +    if (strcmp(name, "/dev/null") != 0 &&
  +        fstat(fileno(file), &stbuf) == 0 &&
  +        !S_ISREG(stbuf.st_mode)) {
  +        aplog_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL,
  +                    "Access to file %s denied by server: not a regular file",
  +                    name);
  +        fclose(file);
  +        return NULL;
       }
  +#endif
   
  -    new_cfg = palloc(p, sizeof (*new_cfg));
  +    new_cfg = palloc(p, sizeof(*new_cfg));
       new_cfg->param = file;
       new_cfg->name = pstrdup(p, name);
  -    new_cfg->getch = (int(*)(void*))fgetc;
  -    new_cfg->getstr = (void *(*)(void *,size_t,void *))fgets;
  -    new_cfg->close = (int(*)(void*))fclose;
  +    new_cfg->getch = (int (*)(void *)) fgetc;
  +    new_cfg->getstr = (void *(*)(void *, size_t, void *)) fgets;
  +    new_cfg->close = (int (*)(void *)) fclose;
       new_cfg->line_number = 0;
       return new_cfg;
   }
  @@ -702,13 +719,13 @@
   /* Allocate a configfile_t handle with user defined functions and params */
   API_EXPORT(configfile_t *) pcfg_open_custom(pool *p, const char *descr,
       void *param,
  -    int(*getch)(void*),
  +    int(*getch)(void *),
       void *(*getstr) (void *buf, size_t bufsiz, void *param),
  -    int(*close_func)(void*))
  +    int(*close_func)(void *))
   {
  -    configfile_t *new_cfg = palloc(p, sizeof (*new_cfg));
  +    configfile_t *new_cfg = palloc(p, sizeof(*new_cfg));
   #ifdef DEBUG
  -    aplog_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Opening config handler %s",
descr);
  +    aplog_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL, "Opening config handler
%s", descr);
   #endif
       new_cfg->param = param;
       new_cfg->name = descr;
  
  
  

Mime
View raw message