Ejemplo n.º 1
0
/**
 * Performs per-child (new process) initialisation.
 */
void modsecurity_child_init(msc_engine *msce) 
{
    /* Need to call this once per process before any other XML calls. */
    xmlInitParser();

    if (msce->auditlog_lock != NULL) {
        apr_status_t rc = apr_global_mutex_child_init(&msce->auditlog_lock, NULL, msce->mp);
        if (rc != APR_SUCCESS) {
            /* 原本就无内容 */
        }
    }

    if (msce->geo_lock != NULL) {
        apr_status_t rc = apr_global_mutex_child_init(&msce->geo_lock, NULL, msce->mp);
        if (rc != APR_SUCCESS) {
            /* 原本就无内容 */
        }
    }

#ifdef DEBUG_DBLOG
    if (ap_logdb_mutex != NULL) {
        apr_status_t rc = apr_global_mutex_child_init(&ap_logdb_mutex, NULL, msce->mp);
        if (rc != APR_SUCCESS) {
            /* 原本就无内容 */
        }
    }
#endif
}
Ejemplo n.º 2
0
apr_status_t
server_init_child_stat(dav_rawx_server_conf *conf, apr_pool_t *pool, apr_pool_t *plog)
{
	char buff[256];
	apr_status_t rc;

	DAV_XDEBUG_POOL(plog, 0, "%s()", __FUNCTION__);

	/* Attaches the mutex */
	DAV_DEBUG_POOL(plog, 0, "%s : Attaching the SHM global_mutex at [%s]", __FUNCTION__, conf->shm.path);
	rc = apr_global_mutex_child_init(&(conf->lock.handle), conf->shm.path, pool);
	if (APR_SUCCESS != rc) {
		DAV_ERROR_POOL(plog, 0, "%s : Failed to attach the SHM global_mutex at [%s] rc=%d : %s",
			__FUNCTION__, conf->shm.path, rc, apr_strerror(rc, buff, sizeof(buff)));
		return rc;
	}
	DAV_DEBUG_POOL(plog, 0, "%s : globalmutex attached at [%s]", __FUNCTION__, conf->shm.path);

	/* Atatches the SHM */
	if (!conf->shm.handle) {
		DAV_DEBUG_POOL(plog, 0, "%s : Attaching the SHM segment at [%s]", __FUNCTION__, conf->shm.path);
		rc = apr_shm_attach(&(conf->shm.handle), conf->shm.path, pool);
		if (APR_SUCCESS != rc) {
			DAV_ERROR_POOL(plog, 0, "%s : Failed to attach the SHM segment at [%s] rc=%d : %s",
				__FUNCTION__, conf->shm.path, rc, apr_strerror(rc, buff, sizeof(buff)));
			conf->shm.handle = NULL;
			return rc;
		}
	}
	DAV_DEBUG_POOL(plog, 0, "%s : SHM segment attached at [%s]", __FUNCTION__, conf->shm.path);

	return APR_SUCCESS;
}
Ejemplo n.º 3
0
static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s) {
   while(s) {
      mapcache_server_cfg* cfg = ap_get_module_config(s->module_config, &mapcache_module);
      apr_global_mutex_child_init(&(cfg->mutex),cfg->mutex_name, pool);
      s = s->next;
   }
}
Ejemplo n.º 4
0
/*
 * This routine gets called when a child inits. We use it to attach
 * to the shared memory segments, and reinitialize the corresponding mutex.
 */
static void dosblock_child_init(apr_pool_t *p, server_rec *s)
{
    apr_status_t rs ;
    const apr_table_entry_t *dosrule_mutex_map_elts = NULL;
    const apr_array_header_t *dosrule_mutex_map_arr = NULL;
    /*
     * Re-open the mutexes for the child. Note we're reusing
     * the mutex pointer global here.
     */
     dosblock_cfg *cfg = (dosblock_cfg *)ap_get_module_config(s->module_config, &mod_dosblock_module);
     dosrule_mutex_map_arr = apr_table_elts(cfg->dosrule_mutex_map);

     if (dosrule_mutex_map_arr) {
         dosrule_mutex_map_elts = (const apr_table_entry_t *)dosrule_mutex_map_arr->elts;
         int i = 0;
         for (i=0; i<dosrule_mutex_map_arr->nelts; ++i)
           {
            rs = apr_global_mutex_child_init(&dosblockipc_mutex[i], dosrule_mutex_map_elts[i].val, p);
            if (APR_SUCCESS != rs) {
                ap_log_error(APLOG_MARK, APLOG_CRIT, rs, s,
                         "Failed to reopen mutex %s in child",
                         dosblockipc_mutex[i]);
                /* There's really nothing else we can do here, since This
                 * routine doesn't return a status. If this ever goes wrong,
                 * it will turn Apache into a fork bomb. Let's hope it never
                 * will.
                */
               exit(1); /* Ugly, but what else? */
             }
          }
     }
}
Ejemplo n.º 5
0
/**
 * Performs per-child (new process) initialisation.
 */
void modsecurity_child_init(msc_engine *msce) {
    /* Need to call this once per process before any other XML calls. */
    xmlInitParser();

    if (msce->auditlog_lock != NULL) {
        apr_status_t rc = apr_global_mutex_child_init(&msce->auditlog_lock, NULL, msce->mp);
        if (rc != APR_SUCCESS) {
            // ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, "Failed to child-init auditlog mutex");
        }
    }

    if (msce->geo_lock != NULL) {
        apr_status_t rc = apr_global_mutex_child_init(&msce->geo_lock, NULL, msce->mp);
        if (rc != APR_SUCCESS) {
            // ap_log_error(APLOG_MARK, APLOG_ERR, rs, s, "Failed to child-init geo mutex");
        }
    }

}
Ejemplo n.º 6
0
/*
 * This callback is called when a child process initializes.
 * We use it to set up the mutex.
 */
static void
but_child_init(apr_pool_t *p, server_rec *s)
{
	apr_status_t status;

	/* Re-open the mutex in the child process. */
	status = apr_global_mutex_child_init(&but_mutex, (const char*) mutex_filename, p);
	if (status != APR_SUCCESS) {
		ERRLOG_SRV_CRIT("Failed to reopen mutex on file %s", mutex_filename);
		exit(1);
	}
}
Ejemplo n.º 7
0
apr_status_t
procmgr_child_init(server_rec * main_server, apr_pool_t * configpool)
{
    apr_status_t rv;

    if ((rv = apr_global_mutex_child_init(&g_pipelock,
                                          g_pipelock_name,
                                          main_server->process->pconf)) !=
        APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
                     "mod_fcgid: apr_global_mutex_child_init error for pipe mutex");
        exit(1);
    }

    return APR_SUCCESS;
}
Ejemplo n.º 8
0
/*
 * initialize the shared memory segment in a child process
 */
int oidc_cache_shm_child_init(apr_pool_t *p, server_rec *s) {
	oidc_cfg *cfg = ap_get_module_config(s->module_config, &auth_openidc_module);
	oidc_cache_cfg_shm_t *context = (oidc_cache_cfg_shm_t *)cfg->cache_cfg;

	/* initialize the lock for the child process */
	apr_status_t rv = apr_global_mutex_child_init(&context->mutex,
			(const char *) context->mutex_filename, p);

	if (rv != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
				"oic_cache_shm_child_init: apr_global_mutex_child_init failed to reopen mutex on file %s",
				context->mutex_filename);
	}

	return rv;
}
static void initialize_child(apr_pool_t *p, server_rec *s)
{
	//DEBUGLOG("initialize_child is called");
    apr_status_t status;

    if (!shm) {
		DEBUGLOG("dosdetector: shm is null in initialize_child");
        return;
    }

    status = apr_global_mutex_child_init(&lock, lock_name, p);
    if (status != APR_SUCCESS) {
        log_and_cleanup("dosdetector: failed to create lock (lock)", status, s);
        return;
    }
}
static void upload_progress_child_init(apr_pool_t *p, server_rec *s)
{
    apr_status_t sts;
    ServerConfig *st = (ServerConfig *)ap_get_module_config(s->module_config,
                                                 &upload_progress_module);

    if (!st->cache_lock) return;

    sts = apr_global_mutex_child_init(&st->cache_lock,
                                      st->lock_file, p);
    if (sts != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, sts, s,
                     "Failed to initialise global mutex %s in child process %"
                     APR_PID_T_FMT ".",
                     st->lock_file, getpid());
    }
}
Ejemplo n.º 11
0
int zcache_mutex_reinit(MCConfigRecord *mc,apr_pool_t *p)
{
    apr_status_t rv;

    if (mc->nMutexMode == ZCACHE_MUTEXMODE_NONE)
        return TRUE;

    if ((rv = apr_global_mutex_child_init(&mc->pMutex,
                                    mc->szMutexFile, p)) != APR_SUCCESS) {
     /*   if (mc->szMutexFile)
            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                         "Cannot reinit STORAGEMutex with file `%s'",
                         mc->szMutexFile);
        else
            ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
                         "Cannot reinit STORAGEMutex");*/
        return FALSE;
    }
    return TRUE;
}
Ejemplo n.º 12
0
int ssl_mutex_reinit(server_rec *s, apr_pool_t *p)
{
    SSLModConfigRec *mc = myModConfig(s);
    apr_status_t rv;

    if (mc->nMutexMode == SSL_MUTEXMODE_NONE)
        return TRUE;

    if ((rv = apr_global_mutex_child_init(&mc->pMutex,
                                    mc->szMutexFile, p)) != APR_SUCCESS) {
        if (mc->szMutexFile)
            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                         "Cannot reinit SSLMutex with file `%s'",
                         mc->szMutexFile);
        else
            ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s,
                         "Cannot reinit SSLMutex");
        return FALSE;
    }
    return TRUE;
}
Ejemplo n.º 13
0
bool InitAPRGlobalStorageForChild (APRGlobalStorage *storage_p, apr_pool_t *pool_p)
{
	bool success_flag = false;

	/* Now that we are in a child process, we have to reconnect
	 * to the global mutex and the shared segment. We also
	 * have to find out the base address of the segment, in case
	 * it moved to a new address. */
	apr_status_t res = apr_global_mutex_child_init (& (storage_p -> ags_mutex_p), storage_p -> ags_mutex_lock_filename_s, pool_p);

	if (res != APR_SUCCESS)
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to attach grassroots child to global mutex file '%s', res %d", storage_p -> ags_mutex_lock_filename_s, res);
		}
	else
		{
			success_flag = true;
		}

	return success_flag;
}
Ejemplo n.º 14
0
static void initialize_child(apr_pool_t *p, server_rec *s)
{
    //DEBUGLOG("initialize_child is called");
    apr_status_t status;

    if (!shm) {
        DEBUGLOG("shm is null in initialize_child");
        return;
    }

    if(!lock) {
        DEBUGLOG("global mutex is null in initialize_child");
        return;
    }

    const char *lock_filename = apr_global_mutex_lockfile(lock);
    status = apr_global_mutex_child_init(&lock, lock_filename, p);
    if (status != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, status, s, "apr_global_mutex_child_init failed");
        return;
    }
}
Ejemplo n.º 15
0
static void exipc_child_init(apr_pool_t *p, server_rec *s)
{
    apr_status_t rs;
         
    /* 
     * Re-open the mutex for the child. Note we're reusing
     * the mutex pointer global here. 
     */
    rs = apr_global_mutex_child_init(&exipc_mutex, 
                                     (const char *) mutexfilename, 
                                     p);
    if (APR_SUCCESS != rs) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, rs, s, 
                     "Failed to reopen mutex on file %s", 
                     shmfilename);
        /* There's really nothing else we can do here, since This
         * routine doesn't return a status. If this ever goes wrong,
         * it will turn Apache into a fork bomb. Let's hope it never
         * will.
         */
        exit(1); /* Ugly, but what else? */
    } 
}
Ejemplo n.º 16
0
static void
 akismet_child_init(apr_pool_t *p, server_rec *s)
{
    apr_status_t ret;
    if (!api_cache_shm) {
        return;
    }
    ret = apr_global_mutex_child_init(&global_lock, global_lock_file, p);
    if (ret != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s,
                                   "failed to create lock (global_lock)");
        cleanup_shm_resources(NULL);
        return;
    }
    if(!api_cache_shm) {
        ret = apr_shm_attach( &api_cache_shm, api_cache_shm_file, p);
        if (ret != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_CRIT, ret, s,
                 "Failed to attach to shared memory file '%s'", api_cache_shm_file);
            return;
        }
    }
    key_verified_infos = apr_shm_baseaddr_get(api_cache_shm);
}
Ejemplo n.º 17
0
/* Set up startup-time initialization */
static int vlimit_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
    VLIMIT_DEBUG_SYSLOG("vlimit_init: ", MODULE_NAME " " MODULE_VERSION " started.", p);

    if(apr_file_open(&vlimit_log_fp, VLIMIT_LOG_FILE, APR_WRITE|APR_APPEND|APR_CREATE,
           APR_OS_DEFAULT, p) != APR_SUCCESS){
        return OK;
    }

    apr_status_t status;
    apr_size_t retsize;
    apr_size_t shm_size;
    int t;

    SHM_DATA *shm_data = NULL;

    shm_size = (apr_size_t) (sizeof(shm_data) + sizeof(shm_data->file_stat_shm) + sizeof(shm_data->ip_stat_shm)) * (conf_counter + 1);

    //Create global mutex
    status = apr_global_mutex_create(&vlimit_mutex, NULL, APR_LOCK_DEFAULT, p);
    if(status != APR_SUCCESS){
        VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Error creating global mutex.", p);
        return status;
    }
#ifdef AP_NEED_SET_MUTEX_PERMS
    status = unixd_set_global_mutex_perms(vlimit_mutex);
    if(status != APR_SUCCESS){
        VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Error xrent could not set permissions on global mutex.", p);
        return status;
    }
#endif

    if(apr_global_mutex_child_init(&vlimit_mutex, NULL, p))
        VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "global mutex attached.", p);

    /* If there was a memory block already assigned.. destroy it */
    if (shm) {
        status = apr_shm_destroy(shm);
        if (status != APR_SUCCESS) {
            VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Couldn't destroy old memory block", p);
            return status;
        } else {
            VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Old Shared memory block, destroyed.", p);
        }
    }

    /* Create shared memory block */
    status = apr_shm_create(&shm, shm_size, NULL, p);
    if (status != APR_SUCCESS) {
        VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Error creating shm block", p);
        return status;
    }


    /* Check size of shared memory block */
    retsize = apr_shm_size_get(shm);
    if (retsize != shm_size) {
        VLIMIT_DEBUG_SYSLOG("vlimit_init: ", "Error allocating shared memory block", p);
        return status;
    }
    /* Init shm block */
    shm_base = apr_shm_baseaddr_get(shm);
    if (shm_base == NULL) {
        VLIMIT_DEBUG_SYSLOG("vlimit_init", "Error creating status block.", p);
        return status;
    }
    memset(shm_base, 0, retsize);

    vlimit_debug_log_buf = apr_psprintf(p
        , "Memory Allocated %d bytes (each conf takes %d bytes) MaxClient:%d"
        , (int) retsize
        , (int) (sizeof(shm_data) + sizeof(shm_data->file_stat_shm) + sizeof(shm_data->ip_stat_shm))
        , MAX_CLIENTS
    );
    VLIMIT_DEBUG_SYSLOG("vlimit_init: ", vlimit_debug_log_buf, p);

    if (retsize < (sizeof(shm_data) * conf_counter)) {
        VLIMIT_DEBUG_SYSLOG("vlimit_init ", "Not enough memory allocated!! Giving up" , p);
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    int i;

    for (t = 0; t <= conf_counter; t++) {
        shm_data = shm_base + t;
        for (i = 0; i < MAX_CLIENTS; i++) {
            shm_data->file_stat_shm[i].filename[0] = '\0';
            shm_data->ip_stat_shm[i].address[0]    = '\0';
            shm_data->file_stat_shm[i].counter     = 0;
            shm_data->ip_stat_shm[i].counter       = 0;
        }
    }

    vlimit_debug_log_buf = apr_psprintf(p
        , "%s Version %s - Initialized [%d Conf]"
        , MODULE_NAME
        , MODULE_VERSION
        , conf_counter
    );
    VLIMIT_DEBUG_SYSLOG("vlimit_init: ", vlimit_debug_log_buf, p);

    return OK;
}
Ejemplo n.º 18
0
static void psgi_child_init(apr_pool_t *p, server_rec *s)
{
    apr_global_mutex_child_init(&psgi_mutex, (const char *) mutex_name, p);
    apr_pool_cleanup_register(p, NULL, psgi_child_exit, psgi_child_exit);
}