httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George V Thomas <George.Tho...@trianz.com>
Subject RE: Issue with ap_get_module_config in Apache 2.4 module on 32 bit
Date Fri, 23 Jan 2015 10:36:28 GMT
Please ignore my previous mail. It seem to be that I had been compiling with wrong version
of apache header files.

From: George V Thomas
Sent: Thursday, January 22, 2015 4:02 PM
To: 'modules-dev@httpd.apache.org'
Subject: Issue with ap_get_module_config in Apache 2.4 module on 32 bit

Hi,

My colleague has posted somewhat identical issue on RHEL earlier (https://issues.apache.org/bugzilla/show_bug.cgi?id=56571)

I am also facing somewhat identical issue in Solaris 10 sparc system. The 64 bit module is
working fine. The 32 bit only has the problem.

Code snippet to reproduce the issue is attached as well as pasted below. The problem is that
in cmd_gavsid(),ap_get_module_config() call returns NULL with 32 bit module file(shared library).
If I assign a value for
ga_vs_config->vsid in ga_create_server_config() with couple of modifications, I can get
this value in ga_check_access() in 32 bit. But the problem is that I have to assign the vsid
in cmd_gavsid() based on the argument it gets from httpd.conf file. This is to uniquely identify
the virtual server.

The httpd.conf has GAVirtualServerID defined something as below
GAVirtualServerID main_sunblade4.domain.com527224900

Is this a bug? Is there any solutions or workarounds? I am using Apache 2.4.10

Regards,
George
//cpp file contents

#include <stdlib.h>
#include <stdio.h>

#ifdef WIN32
#include <windows.h>
#include <process.h>

#else
#include <unistd.h>
#include <pthread.h>
#endif

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "util_script.h"
#include "http_connection.h"

#include "apr_strings.h"

#ifdef __cplusplus
extern "C" {
#endif
   static void *ga_create_server_config (apr_pool_t *p, server_rec *s);
   static const char* cmd_gavsid (cmd_parms *cmd, void *mconfig, char *vsid);
   static int  ga_check_access(request_rec *r);
   static void ga_register_hooks(apr_pool_t *p);
   static int debugprintf(char *format, ...);
#ifdef __cplusplus
};
#endif

extern "C" module AP_MODULE_DECLARE_DATA ga_module;

// This variable tells us whether the module has been initialized or not.
int ga_module_initialized = 0;

/* debugprintf: Logs the given message to std err. Note that Apache redirects
*              the std err into it's error log once it's fully initialized,
*              so these messages will appear in the Apache error log.
*/
int debugprintf(char *format, ...)
{
   va_list v;

   if( format )
   {
      va_start(v, format);
#ifdef WIN32
      fprintf(stderr, "%d - %d - ", _getpid(), GetCurrentThreadId());
#else
      fprintf(stderr, "%d - %d - ", getpid(), pthread_self());
#endif
      vfprintf(stderr, format, v);
   }
   else
   {
      fprintf(stderr, "debugprintf: Didn't get any valid input.\n");
   }

   return 1;
}


/*
* ga_vs_config: This is where we store our per-virtualserver configuration info.
*               Currently, just has virtual server ID. We can add more later if needed.
*/
typedef struct ga_vs_config
{
   char *vsid;
   char *vsname;          // Don't know if applicable yet
} ga_vs_config;


/*
* ga_create_server_config: This is where we allocate storage for our per-virtualserver
 *               configuration info.
*/
static void *ga_create_server_config (apr_pool_t *p, server_rec *s)
{
   ga_vs_config *vs_config = NULL;

   vs_config = (ga_vs_config *) apr_palloc (p, sizeof(ga_vs_config));

   return (void *) vs_config;
}


static const char* cmd_gavsid(cmd_parms *cmd, void *config, char *vsid)
{
                server_rec *s  = NULL;
   if(cmd)
   {
                                s = cmd->server;
                                if(s)
                                {
                                                ga_vs_config *vs_config = (ga_vs_config *)ap_get_module_config(s->module_config,
&ga_module);

                                                if(vs_config)
                                                {
                                                                vs_config->vsid = vsid;
                                                                debugprintf("GT_AA vs-config
is NOT null!\n"); //64 bit enters here
                                                }
                                                else
                                                {
                                                                debugprintf("GT_AA vs-config
is null!"); //32 bit enters here!!!
                                                }



                                debugprintf("cmd_gavsid: vs_config->vsid=%s\n", (vs_config)
? vs_config->vsid : "");
                                }
                }
   return NULL;
}

/*
* ga_cmds: This data structure tells Apache which configuration parameters we want
*          to read.
*/
static const command_rec ga_cmds[] =
{
   {
      "GAVirtualServerID",
      (const char * (*)())cmd_gavsid,
      NULL,
      RSRC_CONF,
      TAKE1,
      "GetAccess defined ID to uniquely identify the virtual servers."
   },
   {NULL}
};

static int ga_check_access(request_rec *r)
{

                if(!r)
                                return HTTP_BAD_REQUEST;

                server_rec *s = r->server;

      // Get the virtual server ID
                  ga_vs_config *vs_config = (ga_vs_config *)ap_get_module_config( (s)?s->module_config:NULL,
&ga_module);

      const char *vsid = (vs_config)?vs_config->vsid:NULL;
      debugprintf("\nVirtual server id is : %s", vsid);  //Doesn't seem to get logged!

      return DONE;

}

static void ga_register_hooks(apr_pool_t *p)
{
   ap_hook_check_access(ga_check_access, NULL, NULL, APR_HOOK_FIRST, AP_AUTH_INTERNAL_PER_URI
);

}

module AP_MODULE_DECLARE_DATA ga_module =
{
   STANDARD20_MODULE_STUFF,
      NULL,                    /* per-directory config creator */
      NULL,                    /* dir config merger */
      ga_create_server_config, /* server config creator */
      NULL,                    /* server config merger */
      ga_cmds,                 /* command table */
      ga_register_hooks,       /* set up other request processing hooks */
};


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message