fred-mod-eppd-2.14.2
|
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"
Defines | |
#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. | |
#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. | |
#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. | |
#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 | |
static | APR_OPTIONAL_FN_TYPE (ssl_var_lookup) |
SSL variable lookup function pointer used for client's PEM encoded certificate retrieval. | |
void * | epp_malloc (void *pool, unsigned size) |
Wrapper around apache's apr_palloc() which allocates memory from a pool. | |
void * | epp_calloc (void *pool, unsigned size) |
Wrapper around apache's apr_pcalloc() which allocates memory from a pool. | |
char * | epp_strdup (void *pool, const char *str) |
Wrapper around apache's apr_strdup() which allocates memory from a pool. | |
char * | epp_strcat (void *pool, const char *str1, const char *str2) |
Wrapper around apache's apr_pstrcat() which concatenates strings. | |
char * | epp_sprintf (void *pool, const char *fmt,...) |
Wrapper around apache's apr_pvsprintf() which prints formated string. | |
static void | current_logtime (char *buf, int nbytes) |
Get well formatted time used in log file as a timestamp. | |
void | epplog (epp_context *epp_ctx, epp_loglevel level, const char *fmt,...) |
Write a log message to eppd log file. | |
static apr_status_t | epp_cleanup_request (void *cdata) |
Cleanup routine, is merely wrapper around epp_parser_request_cleanup(). | |
static int | epp_read_request (epp_context *epp_ctx, char **content, unsigned *bytes) |
Read epp request. | |
static int | get_md5 (char *cert_md5, char *pem) |
Get md5 signature of given PEM encoded certificate. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
static apr_status_t | epp_cleanup_xml (void *data) |
Cleanup routine, is merely wrapper around epp_parser_init_cleanup(). | |
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 ... | |
static const char * | set_epp_protocol (cmd_parms *cmd, void *dummy, int flag) |
Handler for apache's configuration directive "EPPprotocol". | |
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". | |
static const char * | set_logger_object (cmd_parms *cmd, void *dummy, const char *obj_name) |
Handler for apache's configuration directive "EPPlogdObject". | |
static const char * | set_schema (cmd_parms *cmd, void *dummy, const char *schemaurl) |
Handler for apache's configuration directive "EPPschema". | |
static const char * | set_epplog (cmd_parms *cmd, void *dummy, const char *a1) |
Handler for apache's configuration directive "EPPlog". | |
static const char * | set_loglevel (cmd_parms *cmd, void *dummy, const char *a1) |
Handler for apache's configuration directive "EPPloglevel". | |
static const char * | set_servername (cmd_parms *cmd, void *dummy, const char *a1) |
Handler for apache's configuration directive "EPPservername". | |
static const char * | set_valid_resp (cmd_parms *cmd, void *dummy, int flag) |
Handler for apache's configuration directive "EPPvalidResponse". | |
static const char * | set_defer_errors (cmd_parms *cmd, void *dummy, const char *a1) |
Handler for apache's configuration directive "EPPdeferErrors". | |
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. | |
eppd_server_conf | |
static apr_global_mutex_t * | epp_log_lock |
Used for access serialization to epp log file. | |
static const command_rec | eppd_cmds [] |
Structure containing mod_eppd's configuration directives and their handler references. |
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.
#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().
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.
epp_ctx | EPP context. |
service | CORBA object reference - rifd. |
service_log | CORBA object reference - logd |
cdata | EPP data. |
pstat | Parser return status. |
loginid | Login id assigned by fred_rifd. |
session_id | output - fred-logd session ID |
request_id | fred-logd request ID |
lang | Language selected by client. |
logd_mandatory | nonzero if all logd related errors are fatal |
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.
epp_ctx | EPP context. |
service | CORBA object reference. |
cdata | EPP data. |
loginid | Login id assigned by fred_rifd. |
request_id | fred-logd request ID |
lang | Language selected by client. |
cstat | Corba status. |
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.
buf | Buffer to print time into. |
nbytes | Size 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().
cdata | Structure containing data to be freed. |
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().
data | XML schema. |
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.
p | Memory pool. |
s | Server 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.
f | Apache filter structure. |
bb | Bucket brigade containing a response. |
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 ...
p | Memory pool. |
plog | Memory pool used for logging. |
ptemp | Memory pool destroyed right after postconfig phase. |
s | Server record. |
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.
c | Incoming connection. |
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.
epp_ctx | EPP context struct. |
content | The read request without header. |
bytes | Length of request (excluding header length). |
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, | ||
... | |||
) |
Write a log message to eppd log file.
epp_ctx | EPP context structure (connection, pool and session id). |
level | Log level. |
fmt | Printf-style format string. |
References ap_log_cerror, epp_context::conn, current_logtime(), EPP_DEBUG, EPP_ERROR, EPP_FATAL, EPP_INFO, epp_log_lock, EPP_WARNING, eppd_module, and epp_context::pool.
Referenced by APR_OPTIONAL_FN_TYPE(), call_corba(), call_login(), epp_call_check(), epp_call_CloseSession(), epp_call_cmd(), epp_call_dummy(), epp_call_hello(), epp_call_login(), epp_call_logout(), epp_call_poll_req(), epp_parse_command(), epp_process_connection(), epp_read_request(), epp_request_loop(), gen_response(), get_corba_service(), handle_exception(), and unwrap_str_req().
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.
epp_ctx | EPP context. |
service | EPP CORBA object reference. |
cdata | Command data. |
validate | Validate responses. |
schema | Parsed XML schema. |
lang | Language of session. |
response | On return holds response if ret code is 1. |
gstat | generator's return code |
valerr | encountered errors when validating response |
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.
epp_ctx | EPP context. |
name | Name 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.
cert_md5 | Allocated buffer for storing the resulting fingerprint (should be at least 50 bytes long). |
pem | PEM encoded certificate in its string representation. |
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".
cmd | Command structure. |
dummy | Not used parameter. |
a1 | Integer value representing time for deferring error responses from CR |
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.
cmd | Command structure. |
dummy | Not used parameter. |
obj_name | A name of object. |
References eppd_module.
static const char* set_epp_protocol | ( | cmd_parms * | cmd, |
void * | dummy, | ||
int | flag | ||
) | [static] |
Handler for apache's configuration directive "EPPprotocol".
cmd | Command structure. |
dummy | Not used parameter. |
flag | 1 means EPPprotocol is turned on, 0 means turned off. |
References eppd_module.
static const char* set_epplog | ( | cmd_parms * | cmd, |
void * | dummy, | ||
const char * | a1 | ||
) | [static] |
Handler for apache's configuration directive "EPPlog".
cmd | Command structure. |
dummy | Not used parameter. |
a1 | The file where log messages from mod_eppd should be logged. |
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.
cmd | Command structure. |
dummy | Not used parameter. |
obj_name | A name of object. |
References eppd_module.
static const char* set_loglevel | ( | cmd_parms * | cmd, |
void * | dummy, | ||
const char * | a1 | ||
) | [static] |
Handler for apache's configuration directive "EPPloglevel".
cmd | Command structure. |
dummy | Not used parameter. |
a1 | Loglevel is one of fatal, error, warning, info, debug. |
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.
cmd | Command structure. |
dummy | Not used parameter. |
schemaurl | The file with xml schema of EPP protocol. |
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".
cmd | Command structure. |
dummy | Not used parameter. |
a1 | Server name of length less than 30 characters. |
References eppd_module.
static const char* set_valid_resp | ( | cmd_parms * | cmd, |
void * | dummy, | ||
int | flag | ||
) | [static] |
Handler for apache's configuration directive "EPPvalidResponse".
cmd | Command structure. |
dummy | Not used parameter. |
flag | 1 if mod_eppd's responses should be validated, otherwise 0. |
References eppd_module.
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 |
{ STANDARD20_MODULE_STUFF, NULL, NULL, create_eppd_config, NULL, eppd_cmds, register_hooks }
eppd_module declaration.
eppd_module definition.
Referenced by epp_postconfig_hook(), epp_process_connection(), epplog(), set_defer_errors(), set_epp_object(), set_epp_protocol(), set_epplog(), set_logger_object(), set_loglevel(), set_schema(), set_servername(), and set_valid_resp().