Пример #1
0
static void *create_modauthopenid_config(apr_pool_t *p, char *s) {
    modauthopenid_config *newcfg;
    newcfg = (modauthopenid_config *) apr_pcalloc(p, sizeof(modauthopenid_config));
    newcfg->db_location = "/tmp/mod_auth_openid.db";
    newcfg->use_cookie = true;
    newcfg->cookie_name = "open_id_session_id";
    newcfg->cookie_path = NULL;
    newcfg->trusted = apr_array_make(p, 5, sizeof(char *));
    newcfg->distrusted = apr_array_make(p, 5, sizeof(char *));
    newcfg->trust_root = NULL;
    newcfg->cookie_lifespan = 0;
    newcfg->secure_cookie = false;
    newcfg->server_name = NULL;
    newcfg->auth_program = NULL;
    newcfg->use_auth_program = false;
    newcfg->use_ax = false;
    newcfg->ax_attrs = apr_array_make(p, 5, sizeof(char *));
    newcfg->ax_attr_uris = apr_table_make(p, 5);
    newcfg->ax_attr_patterns = apr_table_make(p, 5);
    newcfg->use_ax_username = false;
    newcfg->ax_username_attr = NULL;
    newcfg->use_single_idp = false;
    newcfg->single_idp_url = NULL;
    return (void *) newcfg;
}
Пример #2
0
END_TEST

void core_setup(void) {
  const unsigned int kIdx = 0;
  const unsigned int kEls = kIdx + 1;
  cas_cfg *cfg = NULL;
  cas_dir_cfg *d_cfg = NULL;
  apr_uri_t login;
  request = (request_rec *) malloc(sizeof(request_rec));

  apr_pool_create(&pool, NULL);
  request->pool = pool;
  /* set up the request */
  request->headers_in = apr_table_make(request->pool, 0);
  request->headers_out = apr_table_make(request->pool, 0);
  request->err_headers_out = apr_table_make(request->pool, 0);

  apr_table_set(request->headers_in, "Host", "foo.example.com");
  apr_table_set(request->headers_in, "CAS_foo", "foo-value");
  apr_table_set(request->headers_in, "Cookie", "foo=bar; "
                CAS_DEFAULT_COOKIE "=0123456789abcdef; baz=zot");

  request->server = apr_pcalloc(request->pool,
                                sizeof(struct server_rec));
  request->connection = apr_pcalloc(request->pool, sizeof(struct conn_rec));
  request->connection->local_addr = apr_pcalloc(request->pool,
                                                sizeof(apr_sockaddr_t));


  apr_pool_userdata_set("https", "scheme", NULL, request->pool);
  request->server->server_hostname = "foo.example.com";
  request->connection->local_addr->port = 80;
  request->unparsed_uri = "/foo?bar=baz&zot=qux";
  request->uri = "/foo";
  request->args = "bar=baz&zot=qux";
  apr_uri_parse(request->pool, "http://foo.example.com/foo?bar=baz&zot=qux",
                &request->parsed_uri);

  /* set up the per server, and per directory configs */
  auth_cas_module.module_index = kIdx;
  cfg = cas_create_server_config(request->pool, request->server);
  cfg->CASDebug = TRUE;
  memset(&login, 0, sizeof(login));
  login.scheme = "https";
  login.hostname = "login.example.com";
  login.path = "/cas/login";
  login.port = 0;
  memcpy(&cfg->CASLoginURL, &login, sizeof(apr_uri_t));

  d_cfg = cas_create_dir_config(request->pool, NULL);

  request->request_config = apr_pcalloc(request->pool,
                                      sizeof(ap_conf_vector_t *)*kEls);  
  request->server->module_config = apr_pcalloc(request->pool,
                                               sizeof(ap_conf_vector_t *)*kEls);
  request->per_dir_config = apr_pcalloc(request->pool,
                                        sizeof(ap_conf_vector_t *)*kEls);
  ap_set_module_config(request->server->module_config, &auth_cas_module, cfg);
  ap_set_module_config(request->per_dir_config, &auth_cas_module, d_cfg);
}
Пример #3
0
static void
s_send_request_to_google_analytics(request_rec *r, const char *utm_url)
{
  apr_pool_t *ppool;
  apr_size_t response_len;
  char *data;
  int ii;
  request_rec *get_r;
  mod_chxj_config *conf;

  DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__);
  apr_pool_create(&ppool, r->pool);
  get_r = apr_palloc(ppool, sizeof(request_rec));
  memset(get_r, 0, sizeof(request_rec));
  get_r->pool = ppool;
  get_r->headers_in = apr_table_make(ppool, 4);
  get_r->headers_out = apr_table_make(ppool, 4);
  
  apr_table_setn(get_r->headers_in, "User-Agent",apr_table_get(r->headers_in, "User-Agent"));
  apr_table_setn(get_r->headers_in, "Host", DL_GOOGLE_HOST);

  // ichiou data ni totte oku. tsukawanai kedo.
  data = chxj_serf_get(get_r, ppool, utm_url, 0, &response_len);
  DBG(r, "REQ[%X] response from google:[%s]", TO_ADDR(r), data);
  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
  if (conf->google_analytics_debug && *conf->google_analytics_debug) {
    FILE *fp;
    if ((fp = fopen(conf->google_analytics_debug, "w")) != NULL) {
      fwrite(data, response_len, 1, fp);
      fclose(fp);
    }
  }
  
  DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__);
}
Пример #4
0
static void table_overlap(abts_case *tc, void *data)
{
    const char *val;
    apr_table_t *t1 = apr_table_make(p, 1);
    apr_table_t *t2 = apr_table_make(p, 1);

    apr_table_addn(t1, "a", "0");
    apr_table_addn(t1, "g", "7");
    apr_table_addn(t2, "a", "1");
    apr_table_addn(t2, "b", "2");
    apr_table_addn(t2, "c", "3");
    apr_table_addn(t2, "b", "2.0");
    apr_table_addn(t2, "d", "4");
    apr_table_addn(t2, "e", "5");
    apr_table_addn(t2, "b", "2.");
    apr_table_addn(t2, "f", "6");
    apr_table_overlap(t1, t2, APR_OVERLAP_TABLES_SET);

    ABTS_INT_EQUAL(tc, 7, apr_table_elts(t1)->nelts);
    val = apr_table_get(t1, "a");
    ABTS_STR_EQUAL(tc, "1", val);
    val = apr_table_get(t1, "b");
    ABTS_STR_EQUAL(tc, "2.", val);
    val = apr_table_get(t1, "c");
    ABTS_STR_EQUAL(tc, "3", val);
    val = apr_table_get(t1, "d");
    ABTS_STR_EQUAL(tc, "4", val);
    val = apr_table_get(t1, "e");
    ABTS_STR_EQUAL(tc, "5", val);
    val = apr_table_get(t1, "f");
    ABTS_STR_EQUAL(tc, "6", val);
    val = apr_table_get(t1, "g");
    ABTS_STR_EQUAL(tc, "7", val);
}
Пример #5
0
static apr_table_t *parse_headers(apr_array_header_t *hlines, apr_pool_t *pool)
{
    if (hlines) {
        apr_table_t *headers = apr_table_make(pool, hlines->nelts);        
        int i;
        
        for (i = 0; i < hlines->nelts; ++i) {
            char *hline = ((char **)hlines->elts)[i];
            char *sep = ap_strchr(hline, ':');
            if (!sep) {
                ap_log_perror(APLOG_MARK, APLOG_WARNING, APR_EINVAL, pool,
                              APLOGNO(02955) "h2_response: invalid header[%d] '%s'",
                              i, (char*)hline);
                /* not valid format, abort */
                return NULL;
            }
            (*sep++) = '\0';
            while (*sep == ' ' || *sep == '\t') {
                ++sep;
            }
            
            if (!h2_util_ignore_header(hline)) {
                apr_table_merge(headers, hline, sep);
            }
        }
        return headers;
    }
    else {
        return apr_table_make(pool, 0);        
    }
}
h2_response *h2_response_create(int stream_id,
                                const char *http_status,
                                apr_array_header_t *hlines,
                                apr_pool_t *pool)
{
    apr_table_t *header;
    h2_response *response = apr_pcalloc(pool, sizeof(h2_response));
    int i;
    if (response == NULL) {
        return NULL;
    }
    
    response->stream_id = stream_id;
    response->status = http_status;
    response->content_length = -1;
    
    if (hlines) {
        header = apr_table_make(pool, hlines->nelts);        
        for (i = 0; i < hlines->nelts; ++i) {
            char *hline = ((char **)hlines->elts)[i];
            char *sep = ap_strchr(hline, ':');
            if (!sep) {
                ap_log_perror(APLOG_MARK, APLOG_WARNING, APR_EINVAL, pool,
                              APLOGNO(02955) "h2_response(%d): invalid header[%d] '%s'",
                              response->stream_id, i, (char*)hline);
                /* not valid format, abort */
                return NULL;
            }
            (*sep++) = '\0';
            while (*sep == ' ' || *sep == '\t') {
                ++sep;
            }
            if (ignore_header(hline)) {
                /* never forward, ch. 8.1.2.2 */
            }
            else {
                apr_table_merge(header, hline, sep);
                if (*sep && H2_HD_MATCH_LIT_CS("content-length", hline)) {
                    char *end;
                    response->content_length = apr_strtoi64(sep, &end, 10);
                    if (sep == end) {
                        ap_log_perror(APLOG_MARK, APLOG_WARNING, APR_EINVAL, 
                                      pool, APLOGNO(02956) 
                                      "h2_response(%d): content-length"
                                      " value not parsed: %s", 
                                      response->stream_id, sep);
                        response->content_length = -1;
                    }
                }
            }
        }
    }
    else {
        header = apr_table_make(pool, 0);        
    }

    response->rheader = header;
    return response;
}
Пример #7
0
static void *create_env_dir_config(apr_pool_t *p, char *dummy)
{
    env_dir_config_rec *conf = apr_palloc(p, sizeof(*conf));

    conf->vars = apr_table_make(p, 10);
    conf->unsetenv = apr_table_make(p, 10);

    return conf;
}
Пример #8
0
static void jar_make(dAT)
{
    jar = apr_table_make(p, APREQ_DEFAULT_NELTS);
    AT_not_null(jar);
    AT_int_eq(apreq_parse_cookie_header(p, jar, nscookies), APREQ_ERROR_NOTOKEN);
    jar2 = apr_table_make(p, APREQ_DEFAULT_NELTS);
    AT_not_null(jar2);
    AT_int_eq(apreq_parse_cookie_header(p, jar2, rfccookies), APR_SUCCESS);
}
Пример #9
0
static void *create_userdir_config(apr_pool_t *p, server_rec *s)
{
    userdir_config *newcfg = apr_pcalloc(p, sizeof(*newcfg));

    newcfg->globally_disabled = O_DEFAULT;
    newcfg->userdir = DEFAULT_USER_DIR;
    newcfg->enabled_users = apr_table_make(p, 4);
    newcfg->disabled_users = apr_table_make(p, 4);

    return newcfg;
}
static void *create_authnz_external_svr_config( apr_pool_t *p, server_rec *s)
{
    authnz_external_svr_config_rec *svr= (authnz_external_svr_config_rec *)
	apr_palloc(p, sizeof(authnz_external_svr_config_rec));

    svr->auth_method=  apr_table_make(p, 4);
    svr->auth_path=    apr_table_make(p, 4);
    svr->group_method= apr_table_make(p, 4);
    svr->group_path=   apr_table_make(p, 4);
    /* Note: 4 is only initial hash size - they can grow bigger) */

    return (void *)svr;
}
Пример #11
0
/* Set up all our data structs in the pre config phase */
static void * dosblock_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) {
    dosblock_cfg *cfg = apr_pcalloc(p, sizeof(*cfg));

    if (!cfg)
        return NULL;
    cfg->urlrules = apr_table_make(p, MAXRULE);
    cfg->headerrules = apr_hash_make(p);
    cfg->ruletype = apr_table_make(p, MAXRULE);
    cfg->dosrulemap = apr_table_make(p, MAXRULE);
    cfg->dosrules = apr_hash_make(p);
    cfg->dosrule_shm_map = apr_hash_make(p);
    cfg->dosrule_mutex_map = apr_table_make(p, MAXRULE);

    return cfg;
}
Пример #12
0
/* Parse x-www-url-formencoded args */
apr_table_t *parse_args(request_rec *r, char *args) {

  char* pair;
  char* last = NULL;
  char* eq;
  char *delim = "&";

  apr_table_t *vars = apr_table_make(r->pool, 10);
  for (pair = apr_strtok(r->args, delim, &last); pair; pair = apr_strtok(NULL, delim, &last)) {

    for (eq = pair; *eq; ++eq)
      if (*eq == '+')
        *eq = ' ';

    ap_unescape_url(pair);
    eq = strchr(pair, '=');
    if (eq) {
      *eq++ = 0;
      apr_table_merge(vars, pair, eq);
    } else {
      apr_table_merge(vars, pair, "");
    }

  }

  return vars;

}
Пример #13
0
h2_to_h1 *h2_to_h1_create(int stream_id, apr_pool_t *pool, 
                          apr_bucket_alloc_t *bucket_alloc, 
                          const char *method, const char *path,
                          const char *authority, struct h2_mplx *m)
{
    if (!method) {
        ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, h2_mplx_get_conn(m),
                      "h2_to_h1: header start but :method missing");
        return NULL;
    }
    if (!path) {
        ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, h2_mplx_get_conn(m),
                      "h2_to_h1: header start but :path missing");
        return NULL;
    }
    
    h2_to_h1 *to_h1 = apr_pcalloc(pool, sizeof(h2_to_h1));
    if (to_h1) {
        to_h1->stream_id = stream_id;
        to_h1->pool = pool;
        to_h1->method = method;
        to_h1->path = path;
        to_h1->authority = authority;
        to_h1->m = m;
        to_h1->headers = apr_table_make(to_h1->pool, 10);
        to_h1->bb = apr_brigade_create(pool, bucket_alloc);
        to_h1->chunked = 0; /* until we see a content-type and no length */
        to_h1->content_len = -1;
    }
    return to_h1;
}
Пример #14
0
/**
 * Fixup routine for request header processing.
 *
 * @params r    The request record
 */
static apr_status_t replace_input_fixup(request_rec *r)
{
    replace_server_t *conf = ap_get_module_config(r->server->module_config,
                                                  &replace_module);
    replace_filter_t *filter = (replace_filter_t*)apr_hash_get(conf->h, 
                                    REQUEST_REPLACE_FILTER,
                                    APR_HASH_KEY_STRING);
    header_replace_pattern_t *pattern;
    /* Exit if there is no filter definition. */
    if (filter == NULL) {
        return DECLINED;
    }

    /* Loop the configured patterns */
    for (pattern = filter->header_pattern; pattern != NULL; pattern = pattern->next) {
        apr_table_t *header_table = apr_table_make(r->pool, 2);
        header_replace_cb_t *hrcb = apr_palloc(r->pool,
                                               sizeof(header_replace_cb_t));
        hrcb->header_table = header_table;
        hrcb->pattern = pattern->pattern;
        hrcb->extra = pattern->extra;
        hrcb->replacement = pattern->replacement;
        hrcb->r = r;
        apr_table_do(replace_header_cb, hrcb, r->headers_in,
                     pattern->header, NULL);
        if (!apr_is_empty_table(header_table)) {
            apr_table_unset(r->headers_in, pattern->header);
            r->headers_in = apr_table_overlay(r->pool, r->headers_in,
                                              header_table);
        }
    }
    return OK;
}
static int get_block_and_count_value(request_rec *r, const char *blockkey, const char *countkey,
                char **blockval, char **countval )
{
    int i;
    const char **keys;
    apr_table_t *results;
    const apr_array_header_t *arr;
    const apr_table_entry_t *te;
    if (!blockkey||!countkey) {
        return -1;
    }
    keys = apr_pcalloc(r->pool, (sizeof(char*))* 2);
    *(keys) = blockkey;
    *(keys+1) = countkey;
    results = apr_table_make(r->pool, 2);
    if( memcached_mget_ilimit_func(r, keys, 2, results) < 0 ) {
        return -1;
    }
    arr = apr_table_elts(results);
    te = (const apr_table_entry_t*)arr->elts;
    for (i = 0; i < arr->nelts; i++) {
        if ( !strcmp(blockkey, te[i].key) ) {
            *blockval = te[i].val;
        }
        if ( !strcmp(blockkey, te[i].key) ) {
            *countval = te[i].val;
        }
    }
    return 0;
}
Пример #16
0
/**
 * \brief creates and initializes a mapcache_sqlite_cache
 */
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx)
{
  mapcache_cache_sqlite *cache = apr_pcalloc(ctx->pool, sizeof (mapcache_cache_sqlite));
  if (!cache) {
    ctx->set_error(ctx, 500, "failed to allocate sqlite cache");
    return NULL;
  }
  cache->cache.metadata = apr_table_make(ctx->pool, 3);
  cache->cache.type = MAPCACHE_CACHE_SQLITE;
  cache->cache.tile_delete = _mapcache_cache_sqlite_delete;
  cache->cache.tile_get = _mapcache_cache_sqlite_get;
  cache->cache.tile_exists = _mapcache_cache_sqlite_has_tile;
  cache->cache.tile_set = _mapcache_cache_sqlite_set;
  cache->cache.tile_multi_set = _mapcache_cache_sqlite_multi_set;
  cache->cache.configuration_post_config = _mapcache_cache_sqlite_configuration_post_config;
  cache->cache.configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml;
  cache->create_stmt.sql = apr_pstrdup(ctx->pool,
                                       "create table if not exists tiles(tileset text, grid text, x integer, y integer, z integer, data blob, dim text, ctime datetime, primary key(tileset,grid,x,y,z,dim))");
  cache->exists_stmt.sql = apr_pstrdup(ctx->pool,
                                       "select 1 from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->get_stmt.sql = apr_pstrdup(ctx->pool,
                                    "select data,strftime(\"%s\",ctime) from tiles where tileset=:tileset and grid=:grid and x=:x and y=:y and z=:z and dim=:dim");
  cache->set_stmt.sql = apr_pstrdup(ctx->pool,
                                    "insert or replace into tiles(tileset,grid,x,y,z,data,dim,ctime) values (:tileset,:grid,:x,:y,:z,:data,:dim,datetime('now'))");
  cache->delete_stmt.sql = apr_pstrdup(ctx->pool,
                                       "delete from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->n_prepared_statements = 4;
  cache->bind_stmt = _bind_sqlite_params;
  cache->detect_blank = 1;
  return (mapcache_cache*) cache;
}
Пример #17
0
/*
 * send an OpenID Connect authorization request to the specified provider preserving POST parameters using HTML5 storage
 */
int oidc_proto_authorization_request_post_preserve(request_rec *r,
		const char *authorization_request) {
	/* read the parameters that are POST-ed to us */
	apr_table_t *params = apr_table_make(r->pool, 8);
	if (oidc_util_read_post(r, params) == FALSE) {
		oidc_error(r, "something went wrong when reading the POST parameters");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

	const apr_array_header_t *arr = apr_table_elts(params);
	const apr_table_entry_t *elts = (const apr_table_entry_t*) arr->elts;
	int i;
	char *json = "";
	for (i = 0; i < arr->nelts; i++) {
		json = apr_psprintf(r->pool, "%s'%s': '%s'%s", json,
				oidc_util_html_escape(r->pool, elts[i].key),
				oidc_util_html_escape(r->pool, elts[i].val),
				i < arr->nelts - 1 ? "," : "");
	}
	json = apr_psprintf(r->pool, "{ %s }", json);

	char *java_script =
			apr_psprintf(r->pool,
					"    <script type=\"text/javascript\">\n"
							"      function preserveOnLoad() {\n"
							"        localStorage.setItem('mod_auth_openidc_preserve_post_params', JSON.stringify(%s));\n"
							"        window.location='%s';\n"
							"      }\n"
							"    </script>\n", json, authorization_request);

	return oidc_util_html_send(r, "Preserving...", java_script,
			"preserveOnLoad", "<p>Preserving...</p>", DONE);
}
Пример #18
0
/**
 * Read a cookie called name, placing its value in val.
 *
 * Both the Cookie and Cookie2 headers are scanned for the cookie.
 *
 * If the cookie is duplicated, this function returns APR_EGENERAL. If found,
 * and if remove is non zero, the cookie will be removed from the headers, and
 * thus kept private from the backend.
 */
AP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const char **val,
                                        int remove)
{

    ap_cookie_do v;
    v.r = r;
    v.encoded = NULL;
    v.new_cookies = apr_table_make(r->pool, 10);
    v.duplicated = 0;
    v.name = name;

    apr_table_do((int (*) (void *, const char *, const char *))
                 extract_cookie_line, (void *) &v, r->headers_in,
                 "Cookie", "Cookie2", NULL);
    if (v.duplicated) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00011) LOG_PREFIX
         "client submitted cookie '%s' more than once: %s", v.name, r->uri);
        return APR_EGENERAL;
    }

    /* remove our cookie(s), and replace them */
    if (remove) {
        apr_table_unset(r->headers_in, "Cookie");
        apr_table_unset(r->headers_in, "Cookie2");
        r->headers_in = apr_table_overlay(r->pool, r->headers_in, v.new_cookies);
    }

    *val = v.encoded;

    return APR_SUCCESS;

}
Пример #19
0
/*
 * load the session from the request context, create a new one if no luck
 */
static apr_status_t oidc_session_load_22(request_rec *r, session_rec **zz) {

	oidc_cfg *c = ap_get_module_config(r->server->module_config,
			&auth_openidc_module);

	/* first see if this is a sub-request and it was set already in the main request */
	if (((*zz) = (session_rec *) oidc_request_state_get(r, "session")) != NULL) {
		oidc_debug(r, "loading session from request state");
		return APR_SUCCESS;
	}

	/* allocate space for the session object and fill it */
	session_rec *z = (*zz = apr_pcalloc(r->pool, sizeof(session_rec)));
	z->pool = r->pool;

	/* get a new uuid for this session */
	z->uuid = (apr_uuid_t *) apr_pcalloc(z->pool, sizeof(apr_uuid_t));
	apr_uuid_get(z->uuid);

	z->remote_user = NULL;
	z->encoded = NULL;
	z->entries = apr_table_make(z->pool, 10);

	apr_status_t rc = APR_SUCCESS;
	if (c->session_type == OIDC_SESSION_TYPE_22_SERVER_CACHE) {
		/* load the session from the cache */
		rc = oidc_session_load_cache(r, z);
	} else if (c->session_type == OIDC_SESSION_TYPE_22_CLIENT_COOKIE) {
		/* load the session from a self-contained cookie */
		rc = oidc_session_load_cookie(r, z);
	} else {
		oidc_error(r, "oidc_session_load_22: unknown session type: %d",
				c->session_type);
		rc = APR_EGENERAL;
	}

	/* see if it worked out */
	if (rc != APR_SUCCESS)
		return rc;

	/* yup, now decode the info */
	if (oidc_session_identity_decode(r, z) != APR_SUCCESS)
		return APR_EGENERAL;

	/* check whether it has expired */
	if (apr_time_now() > z->expiry) {

		oidc_warn(r, "session restored from cache has expired");
		apr_table_clear(z->entries);
		z->expiry = 0;
		z->encoded = NULL;

		return APR_EGENERAL;
	}

	/* store this session in the request context, so it is available to sub-requests */
	oidc_request_state_set(r, "session", (const char *) z);

	return APR_SUCCESS;
}
Пример #20
0
Ganglia_metric
Ganglia_metric_create( Ganglia_pool parent_pool )
{
  apr_pool_t *pool = (apr_pool_t*)Ganglia_pool_create(parent_pool);
  Ganglia_metric gmetric;
  if(!pool)
    {
      return NULL;
    }
  gmetric = apr_pcalloc( pool, sizeof(struct Ganglia_metric));
  if(!gmetric)
    {
      Ganglia_pool_destroy((Ganglia_pool)pool);
      return NULL;
    }

  gmetric->pool = (Ganglia_pool)pool;
  gmetric->msg  = apr_pcalloc( pool, sizeof(struct Ganglia_metadata_message));
  if(!gmetric->msg)
    {
      Ganglia_pool_destroy((Ganglia_pool)pool);
      return NULL;
    }
  gmetric->extra = (void*)apr_table_make(pool, 2);

  return gmetric;
}
Пример #21
0
/*
 * allocate and initialize a new tileset
 */
mapcache_grid* mapcache_grid_create(apr_pool_t *pool) {
   mapcache_grid* grid = (mapcache_grid*)apr_pcalloc(pool, sizeof(mapcache_grid));
   grid->metadata = apr_table_make(pool,3);
   grid->srs_aliases = apr_array_make(pool,0,sizeof(char*));
   grid->unit = MAPCACHE_UNIT_METERS;
   return grid;
}
Пример #22
0
void mapcache_source_init(mapcache_context *ctx, mapcache_source *source) {
	source->data_extent[0] =
			source->data_extent[1] =
			source->data_extent[2] =
			source->data_extent[3] = -1;
	source->metadata = apr_table_make(ctx->pool,3);
}
Пример #23
0
/**
 * \brief creates and initializes a mapcache_sqlite_cache
 */
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx) {
   mapcache_cache_sqlite *cache = apr_pcalloc(ctx->pool,sizeof(mapcache_cache_sqlite));
   if(!cache) {
      ctx->set_error(ctx, 500, "failed to allocate sqlite cache");
      return NULL;
   }
   cache->cache.metadata = apr_table_make(ctx->pool,3);
   cache->cache.type = MAPCACHE_CACHE_SQLITE;
   cache->cache.tile_delete = _mapcache_cache_sqlite_delete;
   cache->cache.tile_get = _mapcache_cache_sqlite_get;
   cache->cache.tile_exists = _mapcache_cache_sqlite_has_tile;
   cache->cache.tile_set = _mapcache_cache_sqlite_set;
   cache->cache.configuration_post_config = _mapcache_cache_sqlite_configuration_post_config;
   cache->cache.configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml;
   cache->create_stmt.sql = apr_pstrdup(ctx->pool,
         "create table if not exists tiles(x integer, y integer, z integer, data blob, dim text, ctime datetime, atime datetime, hitcount integer default 0, primary key(x,y,z,dim))");
   cache->exists_stmt.sql = apr_pstrdup(ctx->pool,
         "select 1 from tiles where x=:x and y=:y and z=:z and dim=:dim");
   cache->get_stmt.sql = apr_pstrdup(ctx->pool,
         "select data,strftime(\"%s\",ctime) from tiles where x=:x and y=:y and z=:z and dim=:dim");
   cache->set_stmt.sql = apr_pstrdup(ctx->pool,
         "insert or replace into tiles(x,y,z,data,dim,ctime) values (:x,:y,:z,:data,:dim,datetime('now'))");
   cache->delete_stmt.sql = apr_pstrdup(ctx->pool,
         "delete from tiles where x=:x and y=:y and z=:z and dim=:dim");
   cache->hitstat_stmt.sql = apr_pstrdup(ctx->pool,
         "update tiles set hitcount=hitcount+1, atime=datetime('now') where x=:x and y=:y and z=:z and dim=:dim");
   return (mapcache_cache*)cache;
}
static apr_status_t upload_filter_init(ap_filter_t* f) {
  upload_conf* conf = ap_get_module_config(f->r->per_dir_config,&upload_module);
  upload_ctx* ctx = apr_palloc(f->r->pool, sizeof(upload_ctx)) ;
  // check content-type, get boundary or error
  const char* ctype = apr_table_get(f->r->headers_in, "Content-Type") ;

  if ( ! ctype || ! conf->file_field ||
	strncmp ( ctype , "multipart/form-data", 19 ) ) {
    ap_remove_input_filter(f) ;
    return APR_SUCCESS ;
  }

  ctx->pool = f->r->pool ;
  ctx->form = apr_table_make(ctx->pool, conf->form_size) ;
  ctx->boundary = get_boundary(f->r->pool, ctype) ;
  ctx->parse_state = p_none ;
  ctx->key = ctx->val = 0 ;
  ctx->file_field = conf->file_field ;
  ctx->is_file = 0 ;
  ctx->leftover = 0 ;
//  ctx->bbin = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc) ;

  /* save the table in request_config */
  ap_set_module_config(f->r->request_config, &upload_module, ctx->form) ;

  f->ctx = ctx ;
  return APR_SUCCESS ;
}
Пример #25
0
static int  parse_request_cookie(modsec_rec *msr)
{
    const apr_array_header_t *arr;
    apr_table_entry_t *te;
    apr_table_t *cookies_tb;
    char cookies_key[20];
    char *key;
    int cookies_count;
    int i, j;

    arr = apr_table_elts(msr->request_headers);
    te = (apr_table_entry_t *)arr->elts;
    for (i = 0, j = 0; i < arr->nelts; i++) {
        if (strcasecmp(te[i].key, "Cookie") == 0) {
            cookies_tb = apr_table_make(msr->mp, 8);
            if (cookies_tb == NULL) {
                return -1;
            }
            if (msr->txcfg->cookie_format == COOKIES_V0) {
                cookies_count = parse_cookies_v0(msr, te[i].val, cookies_tb);
            } else {
                cookies_count = parse_cookies_v1(msr, te[i].val, cookies_tb);
            }
            if (cookies_count <= 0) {
                continue;
            }
            snprintf(cookies_key, 20, "cookies%d", ++j);
            key = apr_pstrdup(msr->mp, cookies_key);
            apr_table_setn(msr->request_cookies, key, (void *)cookies_tb);
        }
    }

    return 0;
}
Пример #26
0
/*
 * validate an access token against the validation endpoint of the Authorization server and gets a response back
 */
static int oidc_oauth_validate_access_token(request_rec *r, oidc_cfg *c,
		const char *token, const char **response) {

	/* get a handle to the directory config */
	oidc_dir_cfg *dir_cfg = ap_get_module_config(r->per_dir_config,
			&auth_openidc_module);

	/* assemble parameters to call the token endpoint for validation */
	apr_table_t *params = apr_table_make(r->pool, 4);

	/* add any configured extra static parameters to the introspection endpoint */
	oidc_util_table_add_query_encoded_params(r->pool, params,
			c->oauth.introspection_endpoint_params);

	/* add the access_token itself */
	apr_table_addn(params, "token", token);

	/* see if we want to do basic auth or post-param-based auth */
	const char *basic_auth = NULL;
	if ((c->oauth.introspection_endpoint_auth != NULL)
			&& (apr_strnatcmp(c->oauth.introspection_endpoint_auth,
					"client_secret_post") == 0)) {
		apr_table_addn(params, "client_id", c->oauth.client_id);
		apr_table_addn(params, "client_secret", c->oauth.client_secret);
	} else {
		basic_auth = apr_psprintf(r->pool, "%s:%s", c->oauth.client_id,
				c->oauth.client_secret);
	}

	/* call the endpoint with the constructed parameter set and return the resulting response */
	return oidc_util_http_post_form(r, c->oauth.introspection_endpoint_url,
			params, basic_auth, NULL, c->oauth.ssl_validate_server, response,
			c->http_timeout_long, c->outgoing_proxy, dir_cfg->pass_cookies);
}
Пример #27
0
static void *domaintree_create_srv(apr_pool_t *p, server_rec *s)
{
	MDT_CNF *DT= (MDT_CNF *) apr_palloc(p, sizeof(MDT_CNF));
	
	DT->server = s;
	DT->enabled = -1;
	DT->stripwww = -1;
	DT->statroot = -1;
	DT->maxdepth = -1;
	
	DT->prefix = "/var/www";
	DT->suffix = "public_html";
	
	DT->ignore = apr_array_make(p, 0, sizeof(char *));
	DT->forbid = apr_array_make(p, 0, sizeof(char *));
#ifdef HAVE_UNIX_SUEXEC
	DT->suexec = apr_array_make(p, 0, sizeof(char *));
#endif
	
	DT->aliases.recursion = -1;
	DT->aliases.faketable = apr_table_make(p, 0);
	
	DT->dircache.clim = -1;
	DT->dircache.hmap = apr_hash_make(p);
	apr_pool_create(&DT->dircache.pool, p);
	apr_global_mutex_create(&DT->dircache.lock, __FILE__, APR_LOCK_DEFAULT, p);
#if DBG
	fprintf(stderr, "MDT: cfg create %p\n", DT);
#endif
	return DT;
}
Пример #28
0
apr_status_t h2_request_end_headers(h2_request *req, apr_pool_t *pool, 
                                    int eos, int push)
{
    const char *s;
    
    if (req->eoh) {
        return APR_EINVAL;
    }

    /* Always set the "Host" header from :authority, see rfc7540, ch. 8.1.2.3 */
    if (!req->authority) {
        return APR_BADARG;
    }
    apr_table_setn(req->headers, "Host", req->authority);

    s = apr_table_get(req->headers, "Content-Length");
    if (s) {
        if (inspect_clen(req, s) != APR_SUCCESS) {
            ap_log_perror(APLOG_MARK, APLOG_WARNING, APR_EINVAL, pool,
                          APLOGNO(02959) 
                          "h2_request(%d): content-length value not parsed: %s",
                          req->id, s);
            return APR_EINVAL;
        }
    }
    else {
        /* no content-length given */
        req->content_length = -1;
        if (!eos) {
            /* We have not seen a content-length and have no eos,
             * simulate a chunked encoding for our HTTP/1.1 infrastructure,
             * in case we have "H2SerializeHeaders on" here
             */
            req->chunked = 1;
            apr_table_mergen(req->headers, "Transfer-Encoding", "chunked");
        }
        else if (apr_table_get(req->headers, "Content-Type")) {
            /* If we have a content-type, but already see eos, no more
             * data will come. Signal a zero content length explicitly.
             */
            apr_table_setn(req->headers, "Content-Length", "0");
        }
    }

    req->eoh = 1;
    h2_push_policy_determine(req, pool, push);
    
    /* In the presence of trailers, force behaviour of chunked encoding */
    s = apr_table_get(req->headers, "Trailer");
    if (s && s[0]) {
        req->trailers = apr_table_make(pool, 5);
        if (!req->chunked) {
            req->chunked = 1;
            apr_table_mergen(req->headers, "Transfer-Encoding", "chunked");
        }
    }
    
    return APR_SUCCESS;
}
Пример #29
0
/**
 * Create a new BMX Objectname from the given BMX Bean Domain.
 * @param objectname A pointer to an BMX Objectname pointer where the
 *        new BMX Objectname will be stored.
 * @param domain The domain for the new objectname.
 * @param pool The pool from where this objectname should be allocated.
 */
void bmx_objectname_create(struct bmx_objectname **objectname,
                           const char *domain, apr_pool_t *pool)
{
    struct bmx_objectname *ret = apr_pcalloc(pool, sizeof(*ret));
    ret->domain = apr_pstrdup(pool, domain);
    ret->props = apr_table_make(pool, 0);
    (*objectname) = ret;
}
Пример #30
0
static void *create_reflector_dir_config(apr_pool_t * p, char *d)
{
    reflector_cfg *conf = apr_pcalloc(p, sizeof(reflector_cfg));

    conf->headers = apr_table_make(p, 8);

    return conf;
}