fred-mod-eppd-2.14.1
Macros | Functions | Variables
mod_eppd.c File Reference

mod_eppd.c is a true heart of the epp module which is called mod_eppd. More...

#include <unistd.h>
#include "httpd.h"
#include "http_core.h"
#include "http_log.h"
#include "http_config.h"
#include "http_connection.h"
#include "apr_want.h"
#include "apr_buckets.h"
#include "apr_file_io.h"
#include "apr_general.h"
#include "apr_global_mutex.h"
#include "apr_lib.h"
#include "apr_pools.h"
#include "apr_strings.h"
#include "apr_time.h"
#include "apr_hash.h"
#include "scoreboard.h"
#include "util_filter.h"
#include "unixd.h"
#include "mod_ssl.h"
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include "epp_common.h"
#include "epp_parser.h"
#include "epp_gen.h"
#include "epp-client.h"
#include "logd-client.h"

Macros

#define CORE_PRIVATE
 
#define APR_WANT_BYTEFUNC
 
#define APR_WANT_STRFUNC
 
#define APR_FOPEN_READ   APR_READ
 define which overcomes subtle difference between apache 2.0 and 2.2. More...
 
#define client_ip(r)   ((r)->remote_ip)
 
#define ap_unixd_set_global_mutex_perms   unixd_set_global_mutex_perms
 
#define DEFER_MIN   0
 Min and max time values (in msec) for deferring error responses.
 
#define DEFER_MAX   10000
 
#define EPP_HEADER_LENGTH   4
 Length of EPP header containing message size. More...
 
#define MAX_FRAME_LENGTH   16000
 If client claims in EPP header that he is sending message which is longer than this number of bytes, the message is omitted. More...
 
#define EPP_LOGD_ERRLVL   EPP_ERROR
 Many errors in logging will be logged to epplog with this severity, If logging is mandatory, it should be rised much higher than EPP_DEBUG.
 
#define ap_log_cerror(mark, level, status, c, ...)   ap_log_error(mark, level, status, (c)->base_server, __VA_ARGS__)
 ap_log_cerror is defined only if apache version is 2.0 because 2.0 contrary to 2.2 does not have this function.
 

Functions

static void * get_corba_service (epp_context *epp_ctx, char *name)
 function for obtaining a reference to a CORBA object More...
 
static APR_OPTIONAL_FN_TYPE (ssl_var_lookup)
 SSL variable lookup function pointer used for client's PEM encoded certificate retrieval. More...
 
void * epp_malloc (void *pool, unsigned size)
 Wrapper around apache's apr_palloc() which allocates memory from a pool. More...
 
void * epp_calloc (void *pool, unsigned size)
 Wrapper around apache's apr_pcalloc() which allocates memory from a pool. More...
 
char * epp_strdup (void *pool, const char *str)
 Wrapper around apache's apr_strdup() which allocates memory from a pool. More...
 
char * epp_strcat (void *pool, const char *str1, const char *str2)
 Wrapper around apache's apr_pstrcat() which concatenates strings. More...
 
char * epp_sprintf (void *pool, const char *fmt,...)
 Wrapper around apache's apr_pvsprintf() which prints formated string. More...
 
static void current_logtime (char *buf, int nbytes)
 Get well formatted time used in log file as a timestamp. More...
 
void epplog (epp_context *epp_ctx, epp_loglevel level, const char *fmt,...)
 Write a log message to eppd log file. More...
 
static apr_status_t epp_cleanup_request (void *cdata)
 Cleanup routine, is merely wrapper around epp_parser_request_cleanup(). More...
 
static int epp_read_request (epp_context *epp_ctx, char **content, unsigned *bytes)
 Read epp request. More...
 
static int get_md5 (char *cert_md5, char *pem)
 Get md5 signature of given PEM encoded certificate. More...
 
static int call_login (epp_context *epp_ctx, service_EPP *service, epp_command_data *cdata, unsigned long long *loginid, const ccReg_TID request_id, epp_lang *lang, corba_status *cstat)
 Function calls login over corba and before it computes fingerprint of client's SSL certificate. More...
 
static int call_corba (epp_context *epp_ctx, service_EPP *service, service_Logger *service_log, epp_command_data *cdata, parser_status pstat, unsigned long long *loginid, ccReg_TID *const session_id, const ccReg_TID request_id, epp_lang *lang, unsigned int logd_mandatory)
 Function calls command from corba backend. More...
 
static int gen_response (epp_context *epp_ctx, service_EPP *service, epp_command_data *cdata, int validate, void *schema, epp_lang lang, char **response, gen_status *gstat, qhead *valerr)
 Function generates XML response. More...
 
static int epp_request_loop (epp_context *epp_ctx, apr_bucket_brigade *bb, service_EPP *EPPservice, service_Logger *logger_service, eppd_server_conf *sc, unsigned long long *login_id_save, ccReg_TID *session_id_save)
 Read and process EPP requests waiting in the queue.
 
static int epp_process_connection (conn_rec *c)
 EPP Connection handler. More...
 
static apr_status_t epp_output_filter (ap_filter_t *f, apr_bucket_brigade *bb)
 EPP output filter, which prefixes each response with length of the response. More...
 
static void epp_init_child_hook (apr_pool_t *p, server_rec *s)
 Init child hook is run everytime a new thread (or process) is started. More...
 
static apr_status_t epp_cleanup_xml (void *data)
 Cleanup routine, is merely wrapper around epp_parser_init_cleanup(). More...
 
static int epp_postconfig_hook (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 In post config hook is check consistency of configuration (required parameters, default values of parameters), components are initialized, log file is setted up ... More...
 
static const char * set_epp_protocol (cmd_parms *cmd, void *dummy, int flag)
 Handler for apache's configuration directive "EPPprotocol". More...
 
static const char * set_epp_logd_mandatory (cmd_parms *cmd, void *dummy, int flag)
 
static const char * set_epp_object (cmd_parms *cmd, void *dummy, const char *obj_name)
 Handler for apache's configuration directive "EPPObject". More...
 
static const char * set_logger_object (cmd_parms *cmd, void *dummy, const char *obj_name)
 Handler for apache's configuration directive "EPPlogdObject". More...
 
static const char * set_schema (cmd_parms *cmd, void *dummy, const char *schemaurl)
 Handler for apache's configuration directive "EPPschema". More...
 
static const char * set_epplog (cmd_parms *cmd, void *dummy, const char *a1)
 Handler for apache's configuration directive "EPPlog". More...
 
static const char * set_loglevel (cmd_parms *cmd, void *dummy, const char *a1)
 Handler for apache's configuration directive "EPPloglevel". More...
 
static const char * set_servername (cmd_parms *cmd, void *dummy, const char *a1)
 Handler for apache's configuration directive "EPPservername". More...
 
static const char * set_valid_resp (cmd_parms *cmd, void *dummy, int flag)
 Handler for apache's configuration directive "EPPvalidResponse". More...
 
static const char * set_defer_errors (cmd_parms *cmd, void *dummy, const char *a1)
 Handler for apache's configuration directive "EPPdeferErrors". More...
 
static void * create_eppd_config (apr_pool_t *p, server_rec *s)
 Initialization of of mod_eppd's configuration structure.
 
static void register_hooks (apr_pool_t *p)
 Registration of various hooks which the mod_eppd is interested in.
 

Variables

module AP_MODULE_DECLARE_DATA eppd_module
 eppd_module declaration. More...
 
 eppd_server_conf
 
static apr_global_mutex_t * epp_log_lock
 Used for access serialization to epp log file. More...
 
static const command_rec eppd_cmds []
 Structure containing mod_eppd's configuration directives and their handler references.
 

Detailed Description

mod_eppd.c is a true heart of the epp module which is called mod_eppd.

The file contains typical apache-module-stuff (hooks, command table, configuration table, filters, ...) and manages other components which are used to parse/generate xml and call corba functions. There are good reasons for parting the module in several components:

This file uses three interfaces in order to get work done.

In addition the module uses openssl library to compute x509 certificate fingerprint which is used when authenticating client.

The task of this module is to handle any incomming request if epp engine is turned on. It is a translator from xml to corba function calls. Request processing consists of three stages:

General information concerning configuration and installation of mod_eppd module can be found in README file.

Macro Definition Documentation

#define APR_FOPEN_READ   APR_READ

define which overcomes subtle difference between apache 2.0 and 2.2.

#define EPP_HEADER_LENGTH   4

Length of EPP header containing message size.

Referenced by epp_output_filter(), and epp_read_request().

#define MAX_FRAME_LENGTH   16000

If client claims in EPP header that he is sending message which is longer than this number of bytes, the message is omitted.

It is also a limit for maximal xml document length sent to CR to be saved.

Referenced by epp_read_request().

Function Documentation

static APR_OPTIONAL_FN_TYPE ( ssl_var_lookup  )
static

SSL variable lookup function pointer used for client's PEM encoded certificate retrieval.

Configuration structure of eppd module.

< Decides whether mod_eppd is enabled for host.

< Epp server name used in <greeting> frame.

< Location of CORBA nameservice.

< Name under which the object is known.

< Name of fred-logd object

< Whether fred-logd failure is fatal to EPP

< URL of EPP schema (use just path).

< Validate response before sending it to client.

< Epp log filename.

< File descriptor of epp log file.

< Epp log level.

< Time value for deferring error response.

References epplog().

static int call_corba ( epp_context epp_ctx,
service_EPP service,
service_Logger service_log,
epp_command_data cdata,
parser_status  pstat,
unsigned long long *  loginid,
ccReg_TID *const  session_id,
const ccReg_TID  request_id,
epp_lang lang,
unsigned int  logd_mandatory 
)
static

Function calls command from corba backend.

Return 0 only in case of a serious error.

Parameters
epp_ctxEPP context.
serviceCORBA object reference - rifd.
service_logCORBA object reference - logd
cdataEPP data.
pstatParser return status.
loginidLogin id assigned by fred_rifd.
session_idoutput - fred-logd session ID
request_idfred-logd request ID
langLanguage selected by client.
logd_mandatorynonzero if all logd related errors are fatal
Returns
0 in case of internal error, 1 if ok.

References call_login(), CORBA_ERROR, CORBA_INT_ERROR, CORBA_OK, CORBA_REMOTE_ERROR, epp_command_data::data, epp_call_CloseSession(), epp_call_cmd(), epp_call_logout(), EPP_DEBUG, EPP_ERROR, EPP_FATAL, EPP_LOGD_ERRLVL, epplog(), PARSER_CMD_LOGIN, and PARSER_CMD_LOGOUT.

Referenced by epp_request_loop().

static int call_login ( epp_context epp_ctx,
service_EPP service,
epp_command_data cdata,
unsigned long long *  loginid,
const ccReg_TID  request_id,
epp_lang lang,
corba_status cstat 
)
static

Function calls login over corba and before it computes fingerprint of client's SSL certificate.

Parameters
epp_ctxEPP context.
serviceCORBA object reference.
cdataEPP data.
loginidLogin id assigned by fred_rifd.
request_idfred-logd request ID
langLanguage selected by client.
cstatCorba status.
Returns
0 in case of internal error, 1 if ok.

References epp_context::conn, epp_call_login(), EPP_DEBUG, EPP_ERROR, epplog(), get_md5(), and epp_context::pool.

Referenced by call_corba().

static void current_logtime ( char *  buf,
int  nbytes 
)
static

Get well formatted time used in log file as a timestamp.

Parameters
bufBuffer to print time into.
nbytesSize of the buffer.

Referenced by epplog().

static apr_status_t epp_cleanup_request ( void *  cdata)
static

Cleanup routine, is merely wrapper around epp_parser_request_cleanup().

Parameters
cdataStructure containing data to be freed.
Returns
Always success.

References epp_parser_request_cleanup().

Referenced by epp_request_loop().

static apr_status_t epp_cleanup_xml ( void *  data)
static

Cleanup routine, is merely wrapper around epp_parser_init_cleanup().

Parameters
dataXML schema.
Returns
Always success.

References epp_parser_init_cleanup().

Referenced by set_schema().

static void epp_init_child_hook ( apr_pool_t *  p,
server_rec *  s 
)
static

Init child hook is run everytime a new thread (or process) is started.

Task of the hook is to initialize a lock which protects epp log file.

Parameters
pMemory pool.
sServer record.

References epp_log_lock.

Referenced by register_hooks().

static apr_status_t epp_output_filter ( ap_filter_t *  f,
apr_bucket_brigade *  bb 
)
static

EPP output filter, which prefixes each response with length of the response.

Parameters
fApache filter structure.
bbBucket brigade containing a response.
Returns
Return code of next filter in chain.

References ap_log_cerror, and EPP_HEADER_LENGTH.

Referenced by register_hooks().

static int epp_postconfig_hook ( apr_pool_t *  p,
apr_pool_t *  plog,
apr_pool_t *  ptemp,
server_rec *  s 
)
static

In post config hook is check consistency of configuration (required parameters, default values of parameters), components are initialized, log file is setted up ...

Parameters
pMemory pool.
plogMemory pool used for logging.
ptempMemory pool destroyed right after postconfig phase.
sServer record.
Returns
Status.

References DEFER_MIN, EPP_INFO, epp_log_lock, and eppd_module.

Referenced by register_hooks().

static int epp_process_connection ( conn_rec *  c)
static

EPP Connection handler.

When EPP engine is turn on for connection, this handler takes care of it for whole connection's lifetime duration. The connection is taken out of reach of other handlers, this is important, since EPP protocol and HTTP protocol are quite different and even if you make EPP request as much as possible similar to HTTP request, unexpectable influences from other modules occur.

Parameters
cIncoming connection.
Returns
Return code

References epp_context::conn, CORBA_ERROR, CORBA_OK, CORBA_REMOTE_ERROR, epp_call_CloseSession(), epp_call_hello(), EPP_DEBUG, EPP_ERROR, EPP_FATAL, epp_gen_greeting(), EPP_INFO, EPP_LOGD_ERRLVL, epp_request_loop(), eppd_module, epplog(), GEN_OK, get_corba_service(), and epp_context::pool.

Referenced by register_hooks().

static int epp_read_request ( epp_context epp_ctx,
char **  content,
unsigned *  bytes 
)
static

Read epp request.

Epp request consists of header, which contains frame length including the header itself (4 bytes) and the actual request which is xml document.

Parameters
epp_ctxEPP context struct.
contentThe read request without header.
bytesLength of request (excluding header length).
Returns
0 if successful, 1 if EOF was red and 2 when error occured.

References epp_context::conn, EPP_DEBUG, EPP_ERROR, EPP_FATAL, EPP_HEADER_LENGTH, EPP_INFO, epplog(), MAX_FRAME_LENGTH, and epp_context::pool.

Referenced by epp_request_loop().

void epplog ( epp_context epp_ctx,
epp_loglevel  level,
const char *  fmt,
  ... 
)
static int gen_response ( epp_context epp_ctx,
service_EPP service,
epp_command_data cdata,
int  validate,
void *  schema,
epp_lang  lang,
char **  response,
gen_status gstat,
qhead valerr 
)
static

Function generates XML response.

Parameters
epp_ctxEPP context.
serviceEPP CORBA object reference.
cdataCommand data.
validateValidate responses.
schemaParsed XML schema.
langLanguage of session.
responseOn return holds response if ret code is 1.
gstatgenerator's return code
valerrencountered errors when validating response
Returns
0 in case of internal error, 1 if ok.

References qhead::body, qhead::count, EPP_ERROR, EPP_FATAL, epp_gen_response(), epplog(), GEN_EBUFFER, GEN_EBUILD, GEN_EINTERNAL, GEN_ESCHEMA, GEN_EWRITER, GEN_NOT_VALID, GEN_NOT_XML, GEN_OK, q_content, q_foreach, epp_error::reason, and epp_error::value.

Referenced by epp_request_loop().

static void * get_corba_service ( epp_context epp_ctx,
char *  name 
)
static

function for obtaining a reference to a CORBA object

Get a reference to the CORBA service with the given name.

Parameters
epp_ctxEPP context.
nameName of the service.

References epp_context::conn, EPP_ERROR, EPP_FATAL, and epplog().

Referenced by epp_process_connection().

static int get_md5 ( char *  cert_md5,
char *  pem 
)
static

Get md5 signature of given PEM encoded certificate.

The only function in module which uses openssl library.

Parameters
cert_md5Allocated buffer for storing the resulting fingerprint (should be at least 50 bytes long).
pemPEM encoded certificate in its string representation.
Returns
1 if successful and 0 when error occured.

Referenced by call_login().

static const char* set_defer_errors ( cmd_parms *  cmd,
void *  dummy,
const char *  a1 
)
static

Handler for apache's configuration directive "EPPdeferErrors".

Parameters
cmdCommand structure.
dummyNot used parameter.
a1Integer value representing time for deferring error responses from CR
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_epp_object ( cmd_parms *  cmd,
void *  dummy,
const char *  obj_name 
)
static

Handler for apache's configuration directive "EPPObject".

Sets the name under which is EPP object known to nameservice.

Parameters
cmdCommand structure.
dummyNot used parameter.
obj_nameA name of object.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_epp_protocol ( cmd_parms *  cmd,
void *  dummy,
int  flag 
)
static

Handler for apache's configuration directive "EPPprotocol".

Parameters
cmdCommand structure.
dummyNot used parameter.
flag1 means EPPprotocol is turned on, 0 means turned off.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_epplog ( cmd_parms *  cmd,
void *  dummy,
const char *  a1 
)
static

Handler for apache's configuration directive "EPPlog".

Parameters
cmdCommand structure.
dummyNot used parameter.
a1The file where log messages from mod_eppd should be logged.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_logger_object ( cmd_parms *  cmd,
void *  dummy,
const char *  obj_name 
)
static

Handler for apache's configuration directive "EPPlogdObject".

Sets the name under which is Logger object known to nameservice.

Parameters
cmdCommand structure.
dummyNot used parameter.
obj_nameA name of object.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_loglevel ( cmd_parms *  cmd,
void *  dummy,
const char *  a1 
)
static

Handler for apache's configuration directive "EPPloglevel".

Parameters
cmdCommand structure.
dummyNot used parameter.
a1Loglevel is one of fatal, error, warning, info, debug.
Returns
Error string in case of failure otherwise NULL.

References EPP_DEBUG, EPP_ERROR, EPP_FATAL, EPP_INFO, EPP_WARNING, and eppd_module.

static const char* set_schema ( cmd_parms *  cmd,
void *  dummy,
const char *  schemaurl 
)
static

Handler for apache's configuration directive "EPPschema".

The xml schema file is herewith read and parsed and stays in use for life-time of apache. So you have to restart the apache if you want to change schema.

Parameters
cmdCommand structure.
dummyNot used parameter.
schemaurlThe file with xml schema of EPP protocol.
Returns
Error string in case of failure otherwise NULL.

References epp_cleanup_xml(), epp_parser_init(), and eppd_module.

static const char* set_servername ( cmd_parms *  cmd,
void *  dummy,
const char *  a1 
)
static

Handler for apache's configuration directive "EPPservername".

Parameters
cmdCommand structure.
dummyNot used parameter.
a1Server name of length less than 30 characters.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

static const char* set_valid_resp ( cmd_parms *  cmd,
void *  dummy,
int  flag 
)
static

Handler for apache's configuration directive "EPPvalidResponse".

Parameters
cmdCommand structure.
dummyNot used parameter.
flag1 if mod_eppd's responses should be validated, otherwise 0.
Returns
Error string in case of failure otherwise NULL.

References eppd_module.

Variable Documentation

apr_global_mutex_t* epp_log_lock
static

Used for access serialization to epp log file.

Referenced by epp_init_child_hook(), epp_postconfig_hook(), and epplog().

module AP_MODULE_DECLARE_DATA eppd_module
Initial value:
= {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
}
static const command_rec eppd_cmds[]
Structure containing mod_eppd&#39;s configuration directives and their handler references.
Definition: mod_eppd.c:1951
static void register_hooks(apr_pool_t *p)
Registration of various hooks which the mod_eppd is interested in.
Definition: mod_eppd.c:1995
static void * create_eppd_config(apr_pool_t *p, server_rec *s)
Initialization of of mod_eppd&#39;s configuration structure.
Definition: mod_eppd.c:1986

eppd_module declaration.

eppd_module definition.

Referenced by epp_postconfig_hook(), epp_process_connection(), epplog(), register_hooks(), set_defer_errors(), set_epp_object(), set_epp_protocol(), set_epplog(), set_logger_object(), set_loglevel(), set_schema(), set_servername(), and set_valid_resp().