END_TEST

START_TEST(isSSL_test) {
  /* stuff state into an arbitrary place in the pool */
  apr_pool_userdata_set("https", "scheme", NULL, request->pool);
  fail_unless(isSSL(request) == TRUE);
  apr_pool_userdata_set("http", "scheme", NULL, request->pool);
  fail_unless(isSSL(request) == FALSE);
}
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);
}
/* Set up startup-time initialization */
static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    void *data;
    const char *userdata_key = "llzr_init";
    llzr_config *conf = ap_get_module_config(parms->server->module_config, &llzr_module);

    conf->redisconn = redisConnect(conf->redis_host, conf->redis_port);
    if (conf->redisconn == NULL || conf->redisconn->err) {
        if (conf->redisconn) {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Redis error encountered %s", conf->redisconn->errstr);
            redisFree(c);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Unable to connect to redis server");
        }

        /* We don't want to kill our site if Redis goes down, but we would be susceptible to attack */
    }

    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
	   apr_pool_userdata_set((const void *)1, userdata_key,apr_pool_cleanup_null, s->process->pool);
	       return OK;
    }

    /* Lets get details from the MPM */
    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " " MODULE_VERSION " started");
    ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
    ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);

    return OK;
}
示例#4
0
文件: stats.c 项目: despegar/mod_tee
int tee_create_stats(apr_pool_t *p, ap_scoreboard_e sb_type)
{
	// Doing mmap()s so each child process has its reference to the shared area after fork()
	global_stats = mmap(NULL, sizeof(global_stats_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	global_stats->count = ap_get_scoreboard_global()->server_limit;
	ap_log_perror(APLOG_MARK, APLOG_NOTICE, 0, p, "tee: Creating stats for %d processes", global_stats->count);
	size_t array_size = sizeof(process_stats_t) * global_stats->count;
	global_stats->stats = mmap(NULL, array_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);

	apr_pool_t *global_pool;
	apr_pool_create(&global_pool, NULL);
	int i;
	for (i = 0; i < global_stats->count; i++) {
		/*
		 * Pthread lock implies that:
		 * - Child init function no needed
		 * - Proc mutex (simpler) also works among threads, no need for global mutex
		 */
		apr_proc_mutex_create(&global_stats->stats[i].mutex, NULL, APR_LOCK_PROC_PTHREAD, global_pool);
	}
	/*
	 * Saving pointer to global stats in pool userdata. This is necessary because the module
	 * is unloaded during graceful restart, and globals are all zeroed.
	 */
	apr_pool_userdata_set(global_stats, STATUS_USERDATA_KEY, NULL, p);
	return OK;
}
示例#5
0
static int
php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
	void *data = NULL;
	const char *userdata_key = "apache2hook_post_config";

	/* Apache will load, unload and then reload a DSO module. This
	 * prevents us from starting PHP until the second load. */
	apr_pool_userdata_get(&data, userdata_key, s->process->pool);
	if (data == NULL) {
		/* We must use set() here and *not* setn(), otherwise the
		 * static string pointed to by userdata_key will be mapped
		 * to a different location when the DSO is reloaded and the
		 * pointers won't match, causing get() to return NULL when
		 * we expected it to return non-NULL. */
		apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
		return OK;
	}

	/* Set up our overridden path. */
	if (apache2_php_ini_path_override) {
		apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
	}
#ifdef ZTS
	tsrm_startup(1, 1, 0, NULL);
	(void)ts_resource(0);
	ZEND_TSRMLS_CACHE_UPDATE;
#endif
	sapi_startup(&apache2_sapi_module);
	apache2_sapi_module.startup(&apache2_sapi_module);
	apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
	php_apache_add_version(pconf);

	return OK;
}
示例#6
0
void ssl_scache_init(server_rec *s, apr_pool_t *p)
{
    SSLModConfigRec *mc = myModConfig(s);

    /*
     * Warn the user that he should use the session cache.
     * But we can operate without it, of course.
     */
    if (mc->nSessionCacheMode == SSL_SCMODE_UNSET) {
        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
                     "Init: Session Cache is not configured "
                     "[hint: SSLSessionCache]");
        mc->nSessionCacheMode = SSL_SCMODE_NONE;
        return;
    }

    if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
        ssl_scache_dbm_init(s, p);
    else if ((mc->nSessionCacheMode == SSL_SCMODE_SHMHT) ||
             (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)) {
        void *data;
        const char *userdata_key = "ssl_scache_init";

        apr_pool_userdata_get(&data, userdata_key, s->process->pool);
        if (!data) {
            apr_pool_userdata_set((const void *)1, userdata_key,
                                  apr_pool_cleanup_null, s->process->pool);
            return;
        }
        if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
            ssl_scache_shmht_init(s, p);
        else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
            ssl_scache_shmcb_init(s, p);
    }
}
示例#7
0
/* run in post config hook ( we are parent process and we are uid 0) */
static int ruid_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
	UNUSED(p);
	UNUSED(plog);
	UNUSED(ptemp);

	void *data;
	const char *userdata_key = "ruid2_init";

	/* keep capabilities after setuid */
	prctl(PR_SET_KEEPCAPS,1);

	/* initialize_module() will be called twice, and if it's a DSO
	 * then all static data from the first call will be lost. Only
	 * set up our static data on the second call. */
	apr_pool_userdata_get(&data, userdata_key, s->process->pool);
	if (!data) {
		apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
	} else {
		ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME "/" MODULE_VERSION " enabled");

		/* MaxRequestsPerChild MUST be 1 to enable drop capability mode */
		if (ap_max_requests_per_child == 1) {
			ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " is in drop capability mode");
			cap_mode = RUID_CAP_MODE_DROP;
		}
	}

	return OK;
}
示例#8
0
文件: testud.c 项目: Bernd8/quantlib
static void set_userdata(abts_case *tc, void *data)
{
    apr_status_t rv;

    rv = apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool);
    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
}
示例#9
0
static int
svc_simulator_256b_post_config(
    apr_pool_t *pconf,
    apr_pool_t *plog,
    apr_pool_t *ptemp,
    server_rec *svr_rec)
{
    apr_status_t status = APR_SUCCESS;
    void *data = NULL;
    const char *userdata_key = "svc_simulator_256b_init";
    svc_simulator_256b_config_rec_t *conf = (svc_simulator_256b_config_rec_t *)ap_get_module_config(
            svr_rec->module_config, &svc_simulator_256b_module);

    /* svc_simulator_256b_post_config() will be called twice. Don't bother
     * going through all of the initialization on the first call
     * because it will just be thrown away.*/

    ap_add_version_component(pconf, SVC_SIMULATOR_HTTP_HEADER_SERVER_SVC_SIMULATOR);

    apr_pool_userdata_get(&data, userdata_key, svr_rec->process->pool);
    if(!data)
    {
        apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null,
            svr_rec->process->pool);
        return OK;
    }

    return OK;
}
示例#10
0
/*
 * connect to Redis server
 */
static redisContext * oidc_cache_redis_connect(request_rec *r,
		oidc_cache_cfg_redis_t *context) {

	/* see if we already have a connection by looking it up in the process context */
	redisContext *ctx = NULL;
	apr_pool_userdata_get((void **) &ctx, OIDC_CACHE_REDIS_CONTEXT,
			r->server->process->pool);

	if (ctx == NULL) {

		/* no connection, connect to the configured Redis server */
		ctx = redisConnect(context->host_str, context->port);

		/* check for errors */
		if ((ctx == NULL) || (ctx->err != 0)) {
			oidc_error(r, "failed to connect to Redis server (%s:%d): '%s'",
					context->host_str, context->port, ctx->errstr);
			return NULL;
		}

		/* store the connection in the process context */
		apr_pool_userdata_set(ctx, OIDC_CACHE_REDIS_CONTEXT,
				(apr_status_t (*)(void *)) redisFree, r->server->process->pool);

		/* log the connection */
		oidc_debug(r, "successfully connected to Redis server (%s:%d)",
				context->host_str, context->port);
	}

	return ctx;
}
示例#11
0
static int dosdetector_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    void *user_data;
    apr_pool_userdata_get(&user_data, USER_DATA_KEY, s->process->pool);
    if (user_data == NULL) {
        apr_pool_userdata_set((const void *)(1), USER_DATA_KEY, apr_pool_cleanup_null, s->process->pool);
        return OK;
    }

    apr_status_t rv = create_shm(s, p);
    if(rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "failed to create shared memory");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    apr_pool_cleanup_register(p, NULL, cleanup_shm, apr_pool_cleanup_null);

    rv = ap_global_mutex_create(&lock, NULL, mutex_id, NULL, s, p, 0);
    if(rv != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "failed to create global mutex");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
#ifdef _DEBUG
    const char *mutex_name = apr_global_mutex_name(lock);
    DEBUGLOG("mutex name is %s", mutex_name);
    const char *mutex_filename = apr_global_mutex_lockfile(lock);
    DEBUGLOG("mutex filename is %s", mutex_filename);
#endif
    apr_pool_cleanup_register(p, NULL, cleanup_mutex, apr_pool_cleanup_null);

    return OK;
}
示例#12
0
static int amagent_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
        server_rec *s) {
    /* main process init */
    int status;
    apr_status_t rv = APR_SUCCESS;
    void *data;

#define AMAGENT_INIT_ONCE "AMAGENT_INIT_ONCE"
    apr_pool_userdata_get(&data, AMAGENT_INIT_ONCE, s->process->pool);
    if (!data) {
        /* module has already been initialized */
        apr_pool_userdata_set((const void *) 1, AMAGENT_INIT_ONCE,
                apr_pool_cleanup_null, s->process->pool);
        return rv;
    }
    apr_pool_cleanup_register(pconf, s, amagent_cleanup, apr_pool_cleanup_null);
    ap_add_version_component(pconf, MODINFO);
    LOG_S(APLOG_DEBUG, s, "amagent_init() %d", getpid());

#ifndef _WIN32
    status = am_init();
    if (status != AM_SUCCESS) {
        rv = APR_EINIT;
        LOG_S(APLOG_ERR, s, "amagent_init() status: %s", am_strerror(status));
    }
#endif
    return rv;
}
示例#13
0
/*
* shm init. it should be called in ap_hook_post_config phase
* code partially from mod_auth_digest.c
*/
static int
 shm_init(apr_pool_t *p, server_rec *s)
{
    apr_status_t ret;
    void *data;
    const char *userdata_key = "akismet_dummy_key";

    /* initialize_module() will be called twice, and if it's a DSO
     * then all static data from the first call will be lost. Only
     * set up our static data on the second call. */
    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
        apr_pool_userdata_set((const void *)1, userdata_key,
                               apr_pool_cleanup_null, s->process->pool);
        return OK; /* This would be the first time through */
    }

    if ( ret = apr_shm_create(&api_cache_shm,
                            API_CACHE_SHM_SIZE,
                            api_cache_shm_file, p) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s,
                "Failed to create shared segment file '%s'", api_cache_shm_file );
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    if (ret = apr_global_mutex_create(&global_lock,
                         global_lock_file, APR_LOCK_DEFAULT, p) != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s,
                "Failed to create global mutex file '%s'", global_lock_file);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

#ifdef AP_NEED_SET_MUTEX_PERMS
    if( ret = unixd_set_global_mutex_perms(global_lock) != APR_SUCCESS ) {
        ap_log_perror(APLOG_MARK, APLOG_CRIT, ret, p,
            "%s:Failed to set mutex permission. "
            "please check out parent process's privileges!");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
#endif

    key_verified_infos = apr_shm_baseaddr_get(api_cache_shm);
    if (!key_verified_infos) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, -1, s,
                        "failed to allocate shared memory" );
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    /* Clear all key_verified_info */
    int i;
    for (i = 0; i < NUM_BUCKETS; i++) {
        key_verified_infos[i].status = -1;
        memset(key_verified_infos[i].key, 0, 1024);
    }
    /* Register a cleanup function */
    apr_pool_cleanup_register(p, NULL, cleanup_shm_resources, apr_pool_cleanup_null);
    return OK;
}
示例#14
0
/*
 * This callback is called when the parent initialized.
 * Note that this can happen multiple times.
 */
static int but_post_config(apr_pool_t *pconf, apr_pool_t *plog,
                             apr_pool_t *ptemp, server_rec *s)
{
	void *data;
	const char *userdata_key = "but_init_module";
	apr_status_t status;

	/* 
	 * The following checks if this routine has been called before.
	 * This is necessary because the parent process gets initialized
	 * a couple of times as the server starts up, and we don't want
	 * to create any more mutexes and shared memory segments than
	 * we're actually going to use.
	 */ 
	apr_pool_userdata_get(&data, userdata_key, s->process->pool);
	if (!data) {
		apr_pool_userdata_set((const void *) 1, userdata_key,
			apr_pool_cleanup_null, s->process->pool);
		return OK;
	}

	/* Create the shared memory segments. */
	status = but_shm_initialize(pconf, plog, ptemp, s);
	if (status != APR_SUCCESS) {
		ERRLOG_SRV_CRIT("Failed to initialize session SHM.");
		return HTTP_INTERNAL_SERVER_ERROR;
	}
	status = but_shm_initialize_cookiestore(pconf, plog, ptemp, s);
	if (status != APR_SUCCESS) {
		ERRLOG_SRV_CRIT("Failed to initialize cookiestore SHM.");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

	/* Create the module mutex. */

	/*
	 * Create another unique filename to lock upon. Note that
	 * depending on OS and locking mechanism of choice, the file
	 * may or may not be actually created. 
	 */
	status = apr_global_mutex_create(&but_mutex, tmpnam(NULL), APR_LOCK_DEFAULT, pconf);
	if (status != APR_SUCCESS) {
		ERRLOG_SRV_CRIT("Failed to create mutex.");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

#ifdef MOD_BUT_SET_MUTEX_PERMS
	status = unixd_set_global_mutex_perms(but_mutex);
	if (status != APR_SUCCESS) {
		ERRLOG_SRV_CRIT("Failed to set mutex permissions.");
		return HTTP_INTERNAL_SERVER_ERROR;
	}
#endif /* MOD_BUT_SET_MUTEX_PERMS */

	return OK;
}
示例#15
0
/* FIXME: zhaozg */
static int req_add_output_filter(lua_State *L)
{
  request_rec *r = CHECK_REQUEST_OBJECT(1);
  const char* filter = luaL_checkstring(L, 2);

  ap_filter_t * f = ap_add_output_filter(filter, NULL, r, r->connection);
  apr_pool_userdata_set(L, ML_OUTPUT_FILTER_KEY4LUA, apr_pool_cleanup_null, r->pool);
  lua_pushboolean(L, f != NULL);
  return 1;
}
示例#16
0
int ml_socache_lookup(lua_State*L)
{
  const request_rec* r = CHECK_REQUEST_OBJECT(1);
  server_rec *s = r->server;
  apr_pool_t *pool = s->process->pool; //store provider in pool
  const char *provider_id = luaL_checkstring(L, 2);
  apr_time_t timeout  = luaL_optint(L, 3, 30 * 60);
  const char *provider_name = luaL_optstring(L, 4, AP_SOCACHE_DEFAULT_PROVIDER);
  const char *provider_arg  = luaL_optstring(L, 5, NULL);
  ml_socache *c = NULL;
  apr_status_t status = APR_SUCCESS;
  char socache_key[128];
  struct ap_socache_hints hints = {0};
  hints.avg_id_len = 64;
  hints.avg_obj_size = 1024;
  hints.expiry_interval = timeout;

  apr_snprintf(socache_key, 128, "%s_%s_%s", provider_id, provider_name, AP_SOCACHE_PROVIDER_GROUP);

  status = apr_pool_userdata_get((void**)&c, socache_key, pool);
  if ( status == APR_SUCCESS )
  {
    if (c == NULL)
    {
      const char* err;
      c = lua_newuserdata(L, sizeof(ml_socache));
      c->_provider = ap_lookup_provider(AP_SOCACHE_PROVIDER_GROUP, provider_name, AP_SOCACHE_PROVIDER_VERSION);
      err = c->_provider->create(&c->_instance, provider_arg, pool, pool);
      if (err)
      {
        luaL_error(L, err);
      }
      c->_provider->init(c->_instance, provider_id, &hints, s, pool);
      c->_server = s;
      c->_timeout = timeout * APR_USEC_PER_SEC;
      c->_maxdatalen = 1024;
      apr_pool_userdata_set(c, socache_key, apr_pool_cleanup_null, pool);
    }
    c->_pool = r->pool;
    lua_boxpointer(L, c);
    luaL_getmetatable(L, "mod_luaex.socache");
    lua_setmetatable(L, -2);
  }
  else
  {
    char err[APR_PATH_MAX];
    apr_strerror(status, err, APR_PATH_MAX);
    luaL_error(L, err);
  }

  return 1;
}
示例#17
0
static void ap_mrb_set_mrb_state(apr_pool_t *pool, mrb_state *mrb)
{
    TRACER;
    apr_pool_userdata_set(mrb, "mod_mruby_state", cleanup_mrb_state, pool);
    ap_log_error(APLOG_MARK
        , APLOG_DEBUG
        , 0
        , ap_server_conf
        , "%s DEBUG %s: set mrb_state to mod_mruby_state key: %x"
        , MODULE_NAME
        , __func__
        , mrb
    );
}
示例#18
0
END_TEST

START_TEST(getCASService_http_test) {
  cas_cfg *c = ap_get_module_config(request->server->module_config,
                                    &auth_cas_module);
  char *service;
  const char *expected_service =
      "http%3a%2f%2ffoo.example.com%2ffoo%3fbar%3dbaz%26zot%3dqux";

  apr_pool_userdata_set("http", "scheme", NULL, request->pool);

  service = getCASService(request, c);
  fail_unless(strcmp(service, expected_service) == 0);
}
示例#19
0
/* Dynamically shared modules are loaded twice by apache! 
 * Then we set a dummy information in the server's pool's
 * userdata*/
static int
__rainx_is_first_call(server_rec *server)
{
	const char *userdata_key = "rainx_hook_post_config";
	void *data;

	apr_pool_userdata_get(&data, userdata_key, server->process->pool);
	if (!data) {
		apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, server->process->pool);
		return 1;
	}

	return 0;
}
示例#20
0
static apr_bucket_brigade* get_bb(request_rec* r)
{
  apr_bucket_brigade *bb = NULL;
  int s = apr_pool_userdata_get((void**)&bb, "bb", r->pool);
  if (s == 0)
  {
    if (bb == NULL)
    {
      bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
      apr_pool_userdata_set(bb, "bb", NULL, r->pool);
    }
  }
  return bb;
}
示例#21
0
END_TEST

START_TEST(redirectRequest_test) {
  cas_cfg *c = ap_get_module_config(request->server->module_config,
                                    &auth_cas_module);
  const char *expected = "https://login.example.com/cas/login?service=http%3a"
      "%2f%2ffoo.example.com%2ffoo%3fbar%3dbaz%26zot%3dqux", *rv;
  fail_unless(apr_table_get(request->headers_out, "Location") == NULL);
  apr_pool_userdata_set("http", "scheme", NULL, request->pool);
  redirectRequest(request, c);

  rv = apr_table_get(request->headers_out, "Location");
  fail_if(rv == NULL);
  fail_unless(strcmp(rv, expected) == 0);
}
static int process_security_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    void *data;
    const char *userdata_key = "process_security_init";

    prctl(PR_SET_KEEPCAPS,1);
    apr_pool_userdata_get(&data, userdata_key, s->process->pool);

    if (!data)
        apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);
    else                                              
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME "/" MODULE_VERSION " mechanism enabled");
    
    return OK;
}
示例#23
0
/* make sure the shared memory is cleaned */
static int initialize_cleanup(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    void *data;
    const char *userdata_key = "mod_sharedmem_init";

    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
        apr_pool_userdata_set((const void *)1, userdata_key,
                               apr_pool_cleanup_null, s->process->pool);
        return OK;
    }

    sharedmem_initialize_cleanup(p);
    return OK;
}
示例#24
0
SSLModConfigRec *ssl_config_global_create(server_rec *s)
{
    apr_pool_t *pool = s->process->pool;
    SSLModConfigRec *mc;
    void *vmc;

    apr_pool_userdata_get(&vmc, SSL_MOD_CONFIG_KEY, pool);
    if (vmc) {
        return vmc; /* reused for lifetime of the server */
    }

    /*
     * allocate an own subpool which survives server restarts
     */
    mc = (SSLModConfigRec *)apr_palloc(pool, sizeof(*mc));
    mc->pPool = pool;
    mc->bFixed = FALSE;

    /*
     * initialize per-module configuration
     */
    mc->nSessionCacheMode      = SSL_SCMODE_UNSET;
    mc->szSessionCacheDataFile = NULL;
    mc->nSessionCacheDataSize  = 0;
    mc->pSessionCacheDataMM    = NULL;
    mc->pSessionCacheDataRMM   = NULL;
    mc->tSessionCacheDataTable = NULL;
    mc->nMutexMode             = SSL_MUTEXMODE_UNSET;
    mc->nMutexMech             = APR_LOCK_DEFAULT;
    mc->szMutexFile            = NULL;
    mc->pMutex                 = NULL;
    mc->aRandSeed              = apr_array_make(pool, 4,
                                                sizeof(ssl_randseed_t));
    mc->tVHostKeys             = apr_hash_make(pool);
    mc->tPrivateKey            = apr_hash_make(pool);
    mc->tPublicCert            = apr_hash_make(pool);
#if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ENGINE_INIT)
    mc->szCryptoDevice         = NULL;
#endif

    memset(mc->pTmpKeys, 0, sizeof(mc->pTmpKeys));

    apr_pool_userdata_set(mc, SSL_MOD_CONFIG_KEY,
                          apr_pool_cleanup_null,
                          pool);

    return mc;
}
示例#25
0
文件: mod_psgi.c 项目: mattn/mod_psgi
static int
psgi_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    dTHX;
    const void *key;
    char *file;
    SV *app;
    apr_hash_index_t *hi;
    void *data;
    const char *userdata_key = "psgi_post_config";
    psgi_apps_t *psgi_apps = NULL;
    apr_status_t rc;

    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (data == NULL) {
        apr_pool_userdata_set((const void *)1, userdata_key,
                apr_pool_cleanup_null, s->process->pool);
        return OK;
    }

    ap_add_version_component(pconf, apr_psprintf(pconf, "mod_psgi/%s", MOD_PSGI_VERSION));

    mutex_name = apr_psprintf(pconf, "/tmp/psgi_mutex.%ld", (long int) getpid());
    rc = apr_global_mutex_create(&psgi_mutex,
                        (const char *) mutex_name, APR_LOCK_DEFAULT, pconf);
    if (rc != APR_SUCCESS) {
        return DECLINED;
    }
    rc = apr_global_mutex_lock(psgi_mutex);
    if (rc != APR_SUCCESS) {
        return DECLINED;
    }

    /* shared name to store apps */
    shm_name = apr_pstrdup(pconf, "/tmp/psgi_shm");
    rc = apr_shm_attach(&psgi_shm, (const char *) shm_name, pconf);
    if (rc != APR_SUCCESS) {
        rc = apr_shm_create(&psgi_shm, sizeof(psgi_apps_t),
                        (const char *) shm_name, pconf);
    }
    if (rc == APR_SUCCESS) {
        psgi_apps = (psgi_apps_t *)apr_shm_baseaddr_get(psgi_shm);
        psgi_apps->apps = apr_hash_make(pconf);
    }
    apr_global_mutex_unlock(psgi_mutex);

    return OK;
}
示例#26
0
static int mod_mruby_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    apr_status_t status = apr_thread_mutex_create(&mod_mruby_mutex, APR_THREAD_MUTEX_DEFAULT, p);
    TRACER;
    if(status != APR_SUCCESS){
        ap_log_error(APLOG_MARK
            , APLOG_ERR        
            , 0                
            , ap_server_conf             
            , APLOGNO(05001) "%s ERROR %s: Error creating thread mutex."
            , MODULE_NAME
            , __func__
        );
        return DECLINED;
    }   

    void *data = NULL;
    const char *userdata_key = "mruby_init";

    ap_log_error(APLOG_MARK
        , APLOG_INFO
        , 0                
        , ap_server_conf
        , APLOGNO(05002) "%s %s: main process / thread (pid=%d) initialized."
        , MODULE_NAME
        , __func__
        , getpid()
    );  

    apr_pool_userdata_get(&data, userdata_key, p);

    if (!data)
        apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, p);

    ap_log_error(APLOG_MARK
        , APLOG_NOTICE
        , 0                
        , ap_server_conf
        , APLOGNO(05003) "%s %s: %s / %s mechanism enabled."
        , MODULE_NAME
        , __func__
        , MODULE_NAME
        , MODULE_VERSION
    );  
    
    return DECLINED;
}
示例#27
0
static int suexec_post_config(apr_pool_t *p, apr_pool_t *plog,
                              apr_pool_t *ptemp, server_rec *s)
{
    void *reported;

    apr_pool_userdata_get(&reported, SUEXEC_POST_CONFIG_USERDATA,
                          s->process->pool);

    if ((reported == NULL) && unixd_config.suexec_enabled) {
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
                     "suEXEC mechanism enabled (wrapper: %s)", SUEXEC_BIN);

        apr_pool_userdata_set((void *)1, SUEXEC_POST_CONFIG_USERDATA,
                              apr_pool_cleanup_null, s->process->pool);
    }

    return OK;
}
示例#28
0
/* passing the main server object here, just because we don't have the
 * modperl_server_pool available yet, later on we can access it
 * through the modperl_server_pool() call.
 */
void modperl_restart_count_inc(server_rec *base_server)
{
    void *data;
    int *counter;
    apr_pool_t *p = base_server->process->pool;

    apr_pool_userdata_get(&data, MP_RESTART_COUNT_KEY, p);
    if (data) {
        counter = data;
        (*counter)++;
    }
    else {
        counter = apr_palloc(p, sizeof *counter);
        *counter = 1;
        apr_pool_userdata_set(counter, MP_RESTART_COUNT_KEY,
                              apr_pool_cleanup_null, p);
    }
}
示例#29
0
文件: mod_ghc.c 项目: r0ml/mod_ghc
static void doChildInit(apr_pool_t *pool, server_rec *pServer) {
  void *data = NULL;
  
  fprintf(stderr, "mod_ghc initialized; pid=%d\n", getpid());

  apr_pool_userdata_get(&data, hs_init_key, pServer->process->pool);
  if (data == NULL) {
    // only hs_init once?
    fprintf(stderr, "mod_ghc hs_init; pid=%d\n", getpid());
    apr_pool_userdata_set((const void *)1, hs_init_key, apr_pool_cleanup_null, pServer->process->pool );
    fprintf(stderr, "mod_ghc registering cleanup; pid=%d\n", getpid());
    apr_pool_cleanup_register(pool, NULL, doChildExit, apr_pool_cleanup_null);
    do_hs_init();
    hs_add_root(__stginit_modzmghczm0zi1_ApacheziBindings); // __stginit_modzmghczm0zi1_ApacheziGlue
  } else {
    fprintf(stderr, "skipped the mod_ghc hs_init; pid=%d\n", getpid());
  }
}
示例#30
0
END_TEST

START_TEST(getCASService_root_proxied_test) {
  cas_cfg *c = ap_get_module_config(request->server->module_config,
                                    &auth_cas_module);
  char *service;
  const char *expected_service = 
      "http%3a%2f%2frev-proxy.example.com%2fapp%2ffoo%3fbar%3dbaz%26zot%3dqux";
  const char *root = "http://rev-proxy.example.com/app";
  apr_uri_t parsed_url;
  apr_uri_parse(request->pool, root, &parsed_url);
  apr_pool_userdata_set("https", "scheme", NULL, request->pool);
  request->connection->local_addr->port = 9999;
  memcpy(&c->CASRootProxiedAs, &parsed_url, sizeof(apr_uri_t));

  service = getCASService(request, c);
  fail_unless(strcmp(service, expected_service) == 0);
}