Beispiel #1
0
static int setup_db_pool(apr_pool_t* p, apr_pool_t* plog,
	apr_pool_t* ptemp, server_rec* s) {

  void *data = NULL;
  char *key;
  const char *userdata_key = "pgasp_post_config";
  apr_hash_index_t *idx;
  apr_ssize_t len;
  pgasp_config *pgasp;

  // This code is used to prevent double initialization of the module during Apache startup
  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;
  }

  for (idx = apr_hash_first(p, pgasp_pool_config); idx; idx = apr_hash_next(idx)) {

    apr_hash_this(idx, (void *) &key, &len, (void *) &pgasp);

    if ( apr_reslist_create(&pgasp->dbpool,
			    pgasp->nmin,
			    pgasp->nkeep,
			    pgasp->nmax,
			    pgasp->exptime,
			    pgasp_pool_construct,
			    pgasp_pool_destruct,
			    (void*)pgasp, p) != APR_SUCCESS ) {
      ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "mod_pgasp: failed to initialise") ;
      return 500 ;
    }
    apr_pool_cleanup_register(p, pgasp->dbpool,
			      (void*)apr_reslist_destroy,
			      apr_pool_cleanup_null) ;
    apr_hash_set(pgasp_pool_config, key, APR_HASH_KEY_STRING, pgasp);

  }
  return OK ;
}
static void store_slotmem(ap_slotmem_instance_t *slotmem)
{
    apr_file_t *fp;
    apr_status_t rv;
    apr_size_t nbytes;
    const char *storename;
    unsigned char digest[APR_MD5_DIGESTSIZE];

    storename = slotmem_filename(slotmem->gpool, slotmem->name, 1);

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02334)
                 "storing %s", storename);

    if (storename) {
        rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE,
                           APR_OS_DEFAULT, slotmem->gpool);
        if (APR_STATUS_IS_EEXIST(rv)) {
            apr_file_remove(storename, slotmem->gpool);
            rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE,
                               APR_OS_DEFAULT, slotmem->gpool);
        }
        if (rv != APR_SUCCESS) {
            return;
        }
        if (AP_SLOTMEM_IS_CLEARINUSE(slotmem)) {
            slotmem_clearinuse(slotmem);
        }
        nbytes = (slotmem->desc.size * slotmem->desc.num) +
                 (slotmem->desc.num * sizeof(char)) + AP_UNSIGNEDINT_OFFSET;
        apr_md5(digest, slotmem->persist, nbytes);
        rv = apr_file_write_full(fp, slotmem->persist, nbytes, NULL);
        if (rv == APR_SUCCESS) {
            rv = apr_file_write_full(fp, digest, APR_MD5_DIGESTSIZE, NULL);
        }
        apr_file_close(fp);
        if (rv != APR_SUCCESS) {
            apr_file_remove(storename, slotmem->gpool);
        }
    }
}
Beispiel #3
0
/**
 * Sends bucket data to ironbee for processing.
 */
static void process_bucket(ap_filter_t *f, apr_bucket *b)
{
    conn_rec *c = f->c;
    ironbee_conn_context *ctx = f->ctx;
    ib_conndata_t icdata;
    const char *bdata;
    apr_size_t nbytes;
    apr_status_t rc;

    if (APR_BUCKET_IS_METADATA(b)) {
        return;
    }

    /* Translate a bucket to a ib_conndata_t structure to be passed
     * to IronBee. */
    rc = apr_bucket_read(b, &bdata, &nbytes, APR_BLOCK_READ);
    if (rc != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, c->base_server,
                     IB_PRODUCT_NAME ": %s (%s): error reading %s data",
                     f->frec->name, b->type->name,
                     ((ctx->direction == IRONBEE_REQUEST) ? "request" : "response"));
            return;
    }
    icdata.conn = ctx->iconn;
    icdata.dlen = nbytes;
    icdata.data = (uint8_t *)bdata;


    if (ctx->direction == IRONBEE_REQUEST) {
        ctx->status = ib_state_notify_conn_data_in(ironbee, &icdata);
    }
    else {
        ctx->status = ib_state_notify_conn_data_out(ironbee, &icdata);
    }
    if (ctx->status != IB_OK) {
        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c,
                     IB_PRODUCT_NAME ": signaled error in %s",
                     ((ctx->direction == IRONBEE_REQUEST) ? "request" : "response"));
    }
}
Beispiel #4
0
void proc_print_exit_info(fcgid_procnode * procnode, int exitcode,
                          apr_exit_why_e exitwhy, server_rec * main_server)
{
    char *diewhy = NULL;

    /* Reasons to exit */
    switch (procnode->diewhy) {
    case FCGID_DIE_KILLSELF:
        if (exitwhy == APR_PROC_EXIT)
            diewhy = "normal exit";
        else
            diewhy = "access violation";
        break;
    case FCGID_DIE_IDLE_TIMEOUT:
        diewhy = "idle timeout";
        break;
    case FCGID_DIE_LIFETIME_EXPIRED:
        diewhy = "lifetime expired";
        break;
    case FCGID_DIE_BUSY_TIMEOUT:
        diewhy = "busy timeout";
        break;
    case FCGID_DIE_CONNECT_ERROR:
        diewhy = "connect error, server may has exited";
        break;
    case FCGID_DIE_COMM_ERROR:
        diewhy = "communication error";
        break;
    case FCGID_DIE_SHUTDOWN:
        diewhy = "shutting down";
        break;
    default:
        diewhy = "unknown";
    }

    /* Print log now */
    ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
                     "mod_fcgid: process %s(%" APR_PID_T_FMT ") exit(%s), return code %d",
                     procnode->executable_path, procnode->proc_id.pid, diewhy, exitcode);
}
/* This function sets a string into the specified storage on the entry.
 *
 * NOTE: The string pointer may be NULL, in that case storage is freed
 * and set to NULL.
 *
 * Parametrs:
 *  am_cache_entry_t *entry         Pointer to an entry
 *  am_cache_storage_t *slot        Pointer to storage
 *  const char *string              Pointer to a replacement string
 *
 * Returns:
 *  0 on success, HTTP_INTERNAL_SERVER_ERROR on error.
 */
static int am_cache_entry_store_string(am_cache_entry_t *entry,
                                       am_cache_storage_t *slot,
                                       const char *string)
{
    char *datastr = NULL;
    apr_size_t datalen = 0;
    apr_size_t str_len = 0;

    if (string == NULL) return 0;

    if (slot->ptr != 0) {
        datastr = &entry->pool[slot->ptr];
        datalen = strlen(datastr) + 1;
    }
    str_len = strlen(string) + 1;
    if (str_len - datalen <= 0) {
        memcpy(datastr, string, str_len);
        return 0;
    }

    /* recover space if slot happens to point to the last allocated space */
    if (slot->ptr + datalen == entry->pool_used) {
        entry->pool_used -= datalen;
        slot->ptr = 0;
    }

    if (am_cache_entry_pool_left(entry) < str_len) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                     "apr_cache_entry_store_string() asked %zd available: %zd. "
                     "It may be a good idea to increase MellonCacheEntrySize.",
                     str_len, am_cache_entry_pool_left(entry));
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    slot->ptr = entry->pool_used;
    datastr = &entry->pool[slot->ptr];
    memcpy(datastr, string, str_len);
    entry->pool_used += str_len;
    return 0;
}
Beispiel #6
0
static void dump_iphash_statistics(server_rec *main_s)
{
    unsigned count[IPHASH_TABLE_SIZE];
    int i;
    ipaddr_chain *src;
    unsigned total;
    char buf[HUGE_STRING_LEN];
    char *p;

    total = 0;
    for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
        count[i] = 0;
        for (src = iphash_table[i]; src; src = src->next) {
            ++count[i];
            if (i < IPHASH_TABLE_SIZE) {
                /* don't count the slop buckets in the total */
                ++total;
            }
        }
    }
    qsort(count, IPHASH_TABLE_SIZE, sizeof(count[0]), iphash_compare);
    p = buf + apr_snprintf(buf, sizeof(buf),
                           "iphash: total hashed = %u, avg chain = %u, "
                           "chain lengths (count x len):",
                           total, total / IPHASH_TABLE_SIZE);
    total = 1;
    for (i = 1; i < IPHASH_TABLE_SIZE; ++i) {
        if (count[i - 1] != count[i]) {
            p += apr_snprintf(p, sizeof(buf) - (p - buf), " %ux%u",
                              total, count[i - 1]);
            total = 1;
        }
        else {
            ++total;
        }
    }
    p += apr_snprintf(p, sizeof(buf) - (p - buf), " %ux%u",
                      total, count[IPHASH_TABLE_SIZE - 1]);
    ap_log_error(APLOG_MARK, APLOG_DEBUG, main_s, buf);
}
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;
    }
}
Beispiel #8
0
int suphp_source_child(void *rp, child_info *cinfo) {
    request_rec *r = (request_rec *) rp;
    suphp_conf *conf;
    pool *p = r->main ? r->main->pool : r->pool;
    char **argv, **env;
    table *empty_table = ap_make_table(p, 0);

    conf = ap_get_module_config(r->server->module_config, &suphp_module);

    /* We want to log output written to stderr */
    ap_error_log2stderr(r->server);

    /* prepare argv for new process */

    argv = ap_palloc(p, 4 * sizeof(char *));
    argv[0] = ap_pstrdup(p, conf->php_path);
    argv[1] = "-s";
    argv[2] = ap_pstrdup(p, r->filename);
    argv[3] = NULL;

    /* prepare environment */

    env = ap_create_environment(p, empty_table);

    /* We cannot use ap_call_exec because of the interference with suExec */
    /* So we do everything ourselves */

    /* mandatory cleanup before execution */
    ap_cleanup_for_exec();

    execve(ap_pstrdup(p, conf->php_path), argv, env);

    /* We are still here? Okay - exec failed */
    ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "exec of %s failed",
                 conf->php_path);
    exit(0);
    /* NOT REACHED */
    return (0);
}
Beispiel #9
0
apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s)
{
    apr_status_t status = APR_SUCCESS;
    int minw, maxw;
    int max_threads_per_child = 0;
    int idle_secs = 0;

    check_modules(1);
    ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child);
    
    status = ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm);
    if (status != APR_SUCCESS) {
        /* some MPMs do not implemnent this */
        async_mpm = 0;
        status = APR_SUCCESS;
    }

    h2_config_init(pool);
    
    h2_get_num_workers(s, &minw, &maxw);
    
    idle_secs = h2_config_sgeti(s, H2_CONF_MAX_WORKER_IDLE_SECS);
    ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s,
                 "h2_workers: min=%d max=%d, mthrpchild=%d, idle_secs=%d", 
                 minw, maxw, max_threads_per_child, idle_secs);
    workers = h2_workers_create(s, pool, minw, maxw, idle_secs);
 
    ap_register_input_filter("H2_IN", h2_filter_core_input,
                             NULL, AP_FTYPE_CONNECTION);
   
    status = h2_mplx_child_init(pool, s);

    if (status == APR_SUCCESS) {
        status = apr_socket_create(&dummy_socket, APR_INET, SOCK_STREAM,
                                   APR_PROTO_TCP, pool);
    }

    return status;
}
static void init_child(apr_pool_t *p, server_rec *s)
{
    int mpm_threads;

    ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads);

    /* Now register the last buffer flush with the cleanup engine */
    if (buffered_logs) {
        int i;
        buffered_log **array = (buffered_log **)all_buffered_logs->elts;

        apr_pool_cleanup_register(p, s, flush_all_logs, flush_all_logs);

        for (i = 0; i < all_buffered_logs->nelts; i++) {
            buffered_log *this = array[i];

#if APR_HAS_THREADS
            if (mpm_threads > 1) {
                apr_status_t rv;

                this->mutex.type = apr_anylock_threadmutex;
                rv = apr_thread_mutex_create(&this->mutex.lock.tm,
                                             APR_THREAD_MUTEX_DEFAULT,
                                             p);
                if (rv != APR_SUCCESS) {
                    ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
                                 "could not initialize buffered log mutex, "
                                 "transfer log may become corrupted");
                    this->mutex.type = apr_anylock_none;
                }
            }
            else
#endif
            {
                this->mutex.type = apr_anylock_none;
            }
        }
    }
}
Beispiel #11
0
static int setup_listeners(server_rec *s)
{
    ap_listen_rec *lr;
    int sockdes;

    if (ap_setup_listeners(s) < 1 ) {
        ap_log_error(APLOG_MARK, APLOG_ALERT, 0, s, APLOGNO(00222)
            "no listening sockets available, shutting down");
        return -1;
    }

    listenmaxfd = -1;
    FD_ZERO(&listenfds);
    for (lr = ap_listeners; lr; lr = lr->next) {
        apr_os_sock_get(&sockdes, lr->sd);
        FD_SET(sockdes, &listenfds);
        if (sockdes > listenmaxfd) {
            listenmaxfd = sockdes;
        }
    }
    return 0;
}
Beispiel #12
0
static const char *mod_tora_config( cmd_parms *cmd, MCONFIG mconfig, const char *fargs ) {
	char *code = strdup(fargs);
	char *args = code;
	int value;
	while( true ) {
		char c = *args;
		if( c == 0 || c == ' ' || c == '\t' ) break;
		args++;
	}
	while( *args == ' ' || *args == '\t' )
		*args++ = 0;
	value = atoi(args);
	mod_tora_do_init();
	if( strcmp(code,"HOST") == 0 ) config.host = strdup(args);
	else if( strcmp(code,"PORT") == 0 ) { config.port_min = value; config.port_max = value; }
	else if( strcmp(code,"PORT_MAX") == 0 ) config.port_max = value;
	else if( strcmp(code,"POST_SIZE") == 0 ) config.max_post_size = value;
	else if( strcmp(code,"PROXY_MODE") == 0 ) config.proxy_mode = value;
	else ap_log_error(__FILE__,__LINE__,APLOG_WARNING,LOG_SUCCESS cmd->server,"Unknown ModTora configuration command '%s'",code);
	free(code);
	return NULL;
}
Beispiel #13
0
static const char *add_env_module_vars_set(cmd_parms *cmd, void *sconf_,
                                           const char *name, const char *value)
{
    env_dir_config_rec *sconf = sconf_;

    if (ap_strchr_c(name, '=')) {
        char *env, *plast;

        env = apr_strtok(apr_pstrdup(cmd->temp_pool, name), "=", &plast);

        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(10032)
                     "Spurious usage of '=' in an environment variable name. "
                     "'%s %s %s' expected instead?", cmd->cmd->name, env, plast);
    }

    /* name is mandatory, value is optional.  no value means
     * set the variable to an empty string
     */
    apr_table_setn(sconf->vars, name, value ? value : "");

    return NULL;
}
Beispiel #14
0
void apache_context_server_log(mapcache_context *c, mapcache_log_level level, char *message, ...)
{
  mapcache_context_apache_server *ctx = (mapcache_context_apache_server*)c;
  va_list args;
  char *msg;
  int ap_log_level;
  va_start(args,message);
  msg = apr_pvsprintf(c->pool,message,args);
  va_end(args);
  switch(level) {
    case MAPCACHE_DEBUG:
      ap_log_level = APLOG_DEBUG;
      break;
    case MAPCACHE_INFO:
      ap_log_level = APLOG_INFO;
      break;
    case MAPCACHE_NOTICE:
      ap_log_level = APLOG_NOTICE;
      break;
    case MAPCACHE_WARN:
      ap_log_level = APLOG_WARNING;
      break;
    case MAPCACHE_ERROR:
      ap_log_level = APLOG_ERR;
      break;
    case MAPCACHE_CRIT:
      ap_log_level = APLOG_CRIT;
      break;
    case MAPCACHE_ALERT:
      ap_log_level = APLOG_ALERT;
      break;
    case MAPCACHE_EMERG:
      ap_log_level = APLOG_EMERG;
      break;
    default:
      ap_log_level = APLOG_WARNING;
  }
  ap_log_error(APLOG_MARK, ap_log_level, 0, ctx->server,"%s",msg);
}
Beispiel #15
0
int mgs_rehandshake(mgs_handle_t * ctxt) {
    int rv;

    if (ctxt->session == NULL)
        return -1;

    rv = gnutls_rehandshake(ctxt->session);

    if (rv != 0) {
        /* the client did not want to rehandshake. goodbye */
        ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
                ctxt->c->base_server,
                "GnuTLS: Client Refused Rehandshake request.");
        return -1;
    }

    ctxt->status = 0;

    rv = gnutls_do_handshake(ctxt);

    return rv;
}
int add_upload_to_track(request_rec* r, const char* key) {
  ServerConfig *config = get_server_config(r);
  upload_progress_node_t* node;
  
  clean_old_connections(r);

  CACHE_LOCK();
  node = find_node(r, key);
  if(node == NULL) {
    node = insert_node(r, key);
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                         "Upload Progress: Added upload with id=%s to list.", key);
    upload_progress_context_t *ctx = (upload_progress_context_t*)apr_pcalloc(r->pool, sizeof(upload_progress_context_t));
    ctx->node = node;
    ctx->r = r;
    CACHE_UNLOCK();
    apr_pool_cleanup_register(r->pool, ctx, upload_progress_cleanup, apr_pool_cleanup_null);
    return OK;
  }
  CACHE_UNLOCK();
  return OK;
}
Beispiel #17
0
API_EXPORT(char *)ap_os_case_canonical_filename(pool *pPool, const char *szFile)
{
    char *buf;
    char buf2[CCHMAXPATH];
    int rc, len; 
    char *pos;
    
/* Remove trailing slash unless it's a root directory */
    len = strlen(szFile);
    buf = ap_pstrndup(pPool, szFile, len);
    
    if (len > 3 && buf[len-1] == '/')
        buf[--len] = 0;

    if (buf[0] == '/' && buf[1] == '/') {
        /* A UNC path */
        if (strchr(buf+2, '/') == NULL) {  /* Allow // or //server */
            return ap_pstrdup(pPool, buf);
        }
    }

    rc = DosQueryPathInfo(buf, FIL_QUERYFULLNAME, buf2, sizeof(buf2));

    if (rc) {
        if ( rc != ERROR_INVALID_NAME ) {
            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, NULL, "OS/2 error %d for file %s", rc, szFile);
        }

        return ap_pstrdup(pPool, szFile);
    }

/* Switch backslashes to forward */
    for (pos=buf2; *pos; pos++)
        if (*pos == '\\')
            *pos = '/';
    
    return ap_pstrdup(pPool, buf2);
}
Beispiel #18
0
/* Implements the #merge_dir_config method of Apache's #module vtable. */
static void *
merge_dir_config(apr_pool_t *p, void *base, void *overrides)
{
  dir_conf_t *parent = base;
  dir_conf_t *child = overrides;
  dir_conf_t *newconf;

  newconf = apr_pcalloc(p, sizeof(*newconf));

  newconf->fs_path = INHERIT_VALUE(parent, child, fs_path);
  newconf->master_uri = INHERIT_VALUE(parent, child, master_uri);
  newconf->master_version = INHERIT_VALUE(parent, child, master_version);
  newconf->activities_db = INHERIT_VALUE(parent, child, activities_db);
  newconf->repo_name = INHERIT_VALUE(parent, child, repo_name);
  newconf->xslt_uri = INHERIT_VALUE(parent, child, xslt_uri);
  newconf->fs_parent_path = INHERIT_VALUE(parent, child, fs_parent_path);
  newconf->autoversioning = INHERIT_VALUE(parent, child, autoversioning);
  newconf->bulk_updates = INHERIT_VALUE(parent, child, bulk_updates);
  newconf->v2_protocol = INHERIT_VALUE(parent, child, v2_protocol);
  newconf->path_authz_method = INHERIT_VALUE(parent, child, path_authz_method);
  newconf->list_parentpath = INHERIT_VALUE(parent, child, list_parentpath);
  newconf->txdelta_cache = INHERIT_VALUE(parent, child, txdelta_cache);
  newconf->fulltext_cache = INHERIT_VALUE(parent, child, fulltext_cache);
  newconf->revprop_cache = INHERIT_VALUE(parent, child, revprop_cache);
  newconf->block_read = INHERIT_VALUE(parent, child, block_read);
  newconf->root_dir = INHERIT_VALUE(parent, child, root_dir);
  newconf->hooks_env = INHERIT_VALUE(parent, child, hooks_env);

  if (parent->fs_path)
    ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
                 "mod_dav_svn: nested Location '%s' hinders access to '%s' "
                 "in SVNPath Location '%s'",
                 child->root_dir,
                 svn_urlpath__skip_ancestor(parent->root_dir, child->root_dir),
                 parent->root_dir);

  return newconf;
}
Beispiel #19
0
static saxctxt *check_html_filter_init(ap_filter_t * f)
{
  saxctxt *fctx;
  if (!f->ctx) {
    cdn_conf *cfg = ap_get_module_config(f->r->per_dir_config, &cdn_module);

    const char *errmsg = NULL;
    if(!f->r->content_type)
      errmsg = "check_html_filter_init: no content-type; bailing out of cdn filter";
    else if(cfg->content_types) {
      int i, found = 0;
      tattr *content_types = (tattr *)cfg->content_types->elts;
      for(i = 0; i < cfg->content_types->nelts; ++i) {
        if(!strncasecmp(content_types[i].val, f->r->content_type, strlen(content_types[i].val))) {
          found = 1;
          break;
        }
      }
      if(!found)
        errmsg = "check_html_filter_init: Content-type doesn't match any defined types; "
          "not inserting cdn filter";
    }

    if(errmsg) {
      ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, f->r->server, "%s", errmsg);
      ap_remove_output_filter(f);
      return NULL;
    }

    fctx = f->ctx = apr_pcalloc(f->r->pool, sizeof(saxctxt));
    fctx->f = f;
    fctx->bb =
      apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc);
    fctx->cfg = cfg;
    apr_table_unset(f->r->headers_out, "Content-Length");
  }
  return f->ctx;
}
Beispiel #20
0
int service_main(int (*main_fn)(int, char **), int argc, char **argv )
{
    SERVICE_TABLE_ENTRY dispatchTable[] =
    {
        { "", service_main_fn },
        { NULL, NULL }
    };

    /* Prevent holding open the (nonexistant) console and allow us past
     * the first NT service to parse the service's args in apache_main() 
     */
    ap_server_argv0 = argv[0];
    real_exit_code = 0;

    /* keep the server from going to any real effort, since we know */
    is_service = 1;

    globdat.main_fn = main_fn;
    globdat.connected = 1;

    if(!StartServiceCtrlDispatcher(dispatchTable))
    {
        /* This is a genuine failure of the SCM. */
        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_WIN32ERROR, NULL,
                     "Error starting service control dispatcher");
    }

    globdat.connected = 0;

    if (eventlog_pipewrite)
    {
        CloseHandle(eventlog_pipewrite);
        WaitForSingleObject(eventlog_thread, 10000);
        eventlog_pipewrite = NULL;
    }

    return(globdat.exit_status);
}
Beispiel #21
0
/*
 * Reads headers from a buffer and returns an array of headers.
 * Returns NULL on file error
 * This routine tries to deal with too long lines and continuation lines.
 * @@@: XXX: FIXME: currently the headers are passed thru un-merged.
 * Is that okay, or should they be collapsed where possible?
 */
static apr_status_t recall_headers(cache_handle_t *h, request_rec *r)
{
    disk_cache_object_t *dobj = (disk_cache_object_t *) h->cache_obj->vobj;

    /* This case should not happen... */
    if (!dobj->hfd) {
        /* XXX log message */
        return APR_NOTFOUND;
    }

    h->req_hdrs = apr_table_make(r->pool, 20);
    h->resp_hdrs = apr_table_make(r->pool, 20);

    /* Call routine to read the header lines/status line */
    read_table(h, r, h->resp_hdrs, dobj->hfd);
    read_table(h, r, h->req_hdrs, dobj->hfd);

    apr_file_close(dobj->hfd);

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                 "disk_cache: Recalled headers for URL %s",  dobj->name);
    return APR_SUCCESS;
}
Beispiel #22
0
static int hook_pre_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_temp) {
    
    void (*fn)(const char *name,
               void *fn_init, void *fn_process, void *fn_complete);

    /* Look for the registration function exported by ModSecurity. */
    fn = APR_RETRIEVE_OPTIONAL_FN(modsec_register_reqbody_processor);
    if (fn) {
        /* Use it to register our new request body parser functions under
         * the name "EXAMPLE".
         */
        fn("EXAMPLE",
           (void *)example_init,
           (void *)example_process,
           (void *)example_complete);
    }
    else {
        ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
            "mod_reqbody_example: Unable to find modsec_register_reqbody_processor.");
    }

    return OK;
}
Beispiel #23
0
static const char* mapcache_add_alias(cmd_parms *cmd, void *cfg, const char *alias, const char* configfile)
{
  mapcache_server_cfg *sconfig = ap_get_module_config(cmd->server->module_config, &mapcache_module);
  mapcache_cfg *config = mapcache_configuration_create(cmd->pool);
  mapcache_context *ctx = (mapcache_context*)apache_server_context_create(cmd->server,cmd->pool);
  char *msg = NULL;
  config->configFile = apr_pstrdup(cmd->pool,configfile);
  config->endpoint = alias;
  mapcache_configuration_parse(ctx,configfile,config,0);
  if(GC_HAS_ERROR(ctx)) {
    return ctx->get_error_message(ctx);
  }
  mapcache_configuration_post_config(ctx, config);
  if(GC_HAS_ERROR(ctx)) {
    return ctx->get_error_message(ctx);
  }
  ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, "loaded mapcache configuration file from %s on alias %s", config->configFile, alias);
  if(!sconfig->aliases) {
    sconfig->aliases = apr_hash_make(cmd->pool);
  }
  apr_hash_set(sconfig->aliases,configfile,APR_HASH_KEY_STRING,config);
  return msg;
}
Beispiel #24
0
AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
                                             const char *program,
                                             apr_cmdtype_e cmdtype)
{
    piped_log *pl;
    apr_file_t *dummy = NULL;
    int rc;

    rc = log_child(p, program, &dummy, cmdtype, 0);
    if (rc != APR_SUCCESS) {
        ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
                     "Couldn't start piped log process");
        return NULL;
    }

    pl = apr_palloc(p, sizeof (*pl));
    pl->p = p;
    ap_piped_log_read_fd(pl) = NULL;
    ap_piped_log_write_fd(pl) = dummy;
    apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);

    return pl;
}
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? */
    } 
}
Beispiel #26
0
static PyObject * conn_log_error(connobject *self, PyObject *args)
{
    int level = 0;
    char *message = NULL;

    if (! PyArg_ParseTuple(args, "z|i", &message, &level))
        return NULL; /* error */

    if (message) {

        if (! level)
            level = APLOG_ERR;

#if AP_MODULE_MAGIC_AT_LEAST(20020903,10)
        ap_log_cerror(APLOG_MARK, level, 0, self->conn, "%s", message);
#else
        ap_log_error(APLOG_MARK, level, 0, self->conn->base_server, "%s", message);
#endif
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Beispiel #27
0
static void server_maintenance(void *vpArg)
{
    int num_idle, num_needed;
    ULONG num_pending = 0;
    int threadnum;
    HQUEUE workq;
    ULONG rc;
    PID owner;

    rc = DosOpenQueue(&owner, &workq,
                      apr_psprintf(pchild, "/queues/httpd/work.%d", getpid()));

    if (rc) {
        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf,
                     "unable to open work queue in maintenance thread");
        return;
    }

    do {
        for (num_idle=0, threadnum=0; threadnum < HARD_THREAD_LIMIT; threadnum++) {
            num_idle += ap_scoreboard_image->servers[child_slot][threadnum].status == SERVER_READY;
        }

        DosQueryQueue(workq, &num_pending);
        num_needed = ap_min_spare_threads - num_idle + num_pending;

        if (num_needed > 0) {
            for (threadnum=0; threadnum < num_needed; threadnum++) {
                add_worker();
            }
        }

        if (num_idle - num_pending > ap_max_spare_threads) {
            DosWriteQueue(workq, WORKTYPE_EXIT, 0, NULL, 0);
        }
    } while (DosWaitEventSem(shutdown_event, 500) == ERROR_TIMEOUT);
}
Beispiel #28
0
/* rfc1413 - return remote user name, given socket structures */
API_EXPORT(char *) ap_rfc1413(conn_rec *conn, server_rec *srv)
{
    RFC_USER_STATIC char user[RFC1413_USERLEN + 1];	/* XXX */
    RFC_USER_STATIC char *result;
    RFC_USER_STATIC int sock;

    result = FROM_UNKNOWN;

    sock = ap_psocket_ex(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP, 1);
    if (sock < 0) {
    	ap_log_error(APLOG_MARK, APLOG_CRIT, srv,
    		    "socket: rfc1413: error creating socket");
    	conn->remote_logname = result;
    }

    /*
     * Set up a timer so we won't get stuck while waiting for the server.
     */
#ifdef MULTITHREAD
    if (setsocktimeout(sock, ap_rfc1413_timeout) == 0) {
        if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0)
            result = ap_pstrdup (conn->pool, user);
    }
#else
    if (ap_setjmp(timebuf) == 0) {
	ap_set_callback_and_alarm(ident_timeout, ap_rfc1413_timeout);

	if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0)
	    result = user;
    }
    ap_set_callback_and_alarm(NULL, 0);
#endif
    ap_pclosesocket(conn->pool, sock);
    conn->remote_logname = result;

    return conn->remote_logname;
}
Beispiel #29
0
// ML: string * int * int -> cache ptr_option
const cache *
apsml_cacheCreate (char *key, int maxsize, int timeout, request_data * rd)	/*{{{ */
{
//  keyNhash kn1;
//  kn1.key = &(cacheName1->data);
//  kn1.hash = charhashfunction (kn1.key);
//  char *key = &(cacheName1->data);
  apr_thread_rwlock_wrlock (rd->cachetable->rwlock);
  const cache *c;
//  void **c1 = (void **) &c;
//  ap_log_error (APLOG_MARK, LOG_DEBUG, 0, rd->server,
//    "apsml_cacheCreate: cacheName == %s, maxsize == %i, timeout == %i",
//    &(cacheName1->data), maxsize, timeout);
  if (cachetable_find (rd->cachetable->ht, key, &c) == hash_DNE)
    {
      int size = strlen(key);
      char *kn = malloc (size+1);
//      ap_log_error (APLOG_MARK, LOG_DEBUG, 0, rd->server,
//		    "apsml_cacheCreate: malloc 0x%x, length:%d", (unsigned long) kn, size);
      
      if (kn == NULL) return NULL;
//      kn->key = (char *) (kn + 1);
//      kn->hash = kn1.hash;
      strncpy (kn, key, size);
      kn[size] = 0;
      c = cacheCreate (maxsize, timeout, charhashfunction(kn), rd);
      cachetable_insert (rd->cachetable->ht, kn, c);
    }
  else
    {
      ap_log_error (APLOG_MARK, LOG_DEBUG, 0, rd->server,
		    "apsml_cacheCreate: cacheName == %s already exists", key);
    }
//  ppGlobalCache(rd);
  apr_thread_rwlock_unlock (rd->cachetable->rwlock);
  return c;
}				/*}}} */
Beispiel #30
0
/* BS2000 requires a "special" version of fork() before a setuid()/_rini() call */
pid_t os_fork(const char *user)
{
    pid_t pid;
    char  username[USER_LEN+1];

    switch (os_forktype()) {
      case bs2_FORK:
      case bs2_FORK_RINI:
	pid = fork();
	break;

      case bs2_RFORK_RINI:
	pid = _rfork();
	break;

      case bs2_UFORK:
	ap_cpystrn(username, user, sizeof username);

	/* Make user name all upper case - for some versions of ufork() */
	ap_str_toupper(username);

	pid = ufork(username);
	if (pid == -1 && errno == EPERM) {
	    ap_log_error(APLOG_MARK, APLOG_EMERG,
			 NULL, "ufork: Possible mis-configuration "
			 "for user %s - Aborting.", user);
	    exit(1);
	}
	break;

      default:
	pid = 0;
	break;
    }

    return pid;
}