fred-mod-whoisd-3.12.1
Data Structures | Macros | Functions | Variables
mod_whoisd.c File Reference

Module implementing whois service. More...

#include "httpd.h"
#include "http_log.h"
#include "http_config.h"
#include "http_connection.h"
#include "apr.h"
#include "apr_buckets.h"
#include "apr_file_io.h"
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_pools.h"
#include "apr_strings.h"
#include "apr_time.h"
#include "apr_hash.h"
#include "apr_getopt.h"
#include "apr_want.h"
#include "scoreboard.h"
#include "util_filter.h"
#include "whois-client.h"
Include dependency graph for mod_whoisd.c:

Data Structures

struct  whoisd_server_conf
 Configuration structure of whoisd module. More...
 

Macros

#define CORE_PRIVATE
 
#define APR_FOPEN_READ   APR_READ
 
#define APR_WANT_STRFUNC
 
#define client_ip(r)   ((r)->remote_ip)
 
#define ap_unixd_set_global_mutex_perms   unixd_set_global_mutex_perms
 
#define DEFAULT_DISCLAIMER   "Domain Information over Whois protocol\n"
 This default disclaimer should never be used in production release. More...
 
#define INT_ERROR_MSG   "Internal error occured when processing your \request.\nPlease try again later.\n"
 Message displayed bellow disclaimer when query cannot be answered becauseof an error.
 
#define MAXARGS   20
 Maximal number of whois arguments. More...
 
#define MAXTYPELEN   15
 Maximal length of object type identifier. More...
 
#define MAXAXELEN   15
 Maximal length of search axe identifier. More...
 
#define MAXQPARLEN   15
 Maximal length of -q parameter. More...
 
#define MIN_WHOIS_REQUEST_LENGTH   1
 Minimal length of input line. More...
 
#define MAX_WHOIS_REQUEST_LENGTH   1000
 Maximal length of input line. More...
 
#define ap_log_cerror(mark, level, status, c,...)   ap_log_error(mark, level, status, (c)->base_server, __VA_ARGS__)
 This is wrapper function for compatibility reason. More...
 
#define IS_SEARCH_SET(wr)   ((wr)->axe || (wr)->norecursion || (wr)->type)
 checks if there is any kind of search set in the query
 
#define SAFE_PRINTF(fmt, str)   if (str != NULL) apr_brigade_printf(bb, NULL, NULL, fmt, str);
 
#define SAFE_PRINTF(fmt, str)   if (str != NULL) apr_brigade_printf(bb, NULL, NULL, fmt, str);
 
#define SAFE_PRINTF(fmt, str)   if (str != NULL) apr_brigade_printf(bb, NULL, NULL, fmt, str);
 
#define SAFE_PRINTF(fmt, str)   if (str != NULL) apr_brigade_printf(bb, NULL, NULL, fmt, str);
 
#define SAFE_PRINTF(fmt, str)   if (str != NULL) apr_brigade_printf(bb, NULL, NULL, fmt, str);
 

Functions

void whois_log_status (conn_rec *c, service_Logger service, const char *content, ccReg_RequestProperties *properties, ccReg_TID log_entry_id, CORBA_long result_code)
 
static void print_intro (apr_bucket_brigade *bb, conn_rec *c, const char *disclaimer, const char *timestamp)
 Print whois disclaimer into the bucket brigade.
 
static void send_error (conn_rec *c, const char *disclaimer, int nerr)
 Routine trigerred upon error. More...
 
static void print_domain_object (apr_bucket_brigade *bb, obj_domain *d)
 Function prints domain information to bucket brigade. More...
 
static void print_nsset_object (apr_bucket_brigade *bb, obj_nsset *n)
 Function prints nsset information to bucket brigade. More...
 
static void print_keyset_object (apr_bucket_brigade *bb, obj_keyset *k)
 Function prints keyset information to bucket brigade. More...
 
static void print_contact_object (apr_bucket_brigade *bb, obj_contact *c)
 Function prints contact information to bucket brigade. More...
 
static void print_registrar_object (apr_bucket_brigade *bb, obj_registrar *r)
 Function prints registrar information to bucket brigade. More...
 
static void * get_corba_service (conn_rec *c, char *name)
 
static apr_status_t process_whois_query (conn_rec *c, whoisd_server_conf *sc, whois_request *wr, ccReg_TID log_entry_id)
 Whois request processor. More...
 
static char * read_request (conn_rec *c, int *http_status)
 This will read whois request (one line of text). More...
 
static int getobjtype (int *bittype, const char *strtype)
 Function converts object type from string form to bit form. More...
 
static char * wrap_str (const char *str)
 Function wraps strings passed from XML parser into strings accepted by CORBA. More...
 
static apr_status_t log_whois_request (whois_request *wr, conn_rec *c, char *content, whoisd_server_conf *sc, ccReg_TID *log_entry_id)
 Call fred-logd now it mostly returns APR_SUCCESS because logger failure isn't fatal to whois itself only if memory allocation fails, it returns HTTP_INTERNAL_SERVER_ERROR. More...
 
static int process_whois_connection (conn_rec *c)
 Connection handler of mod_whoisd module. More...
 
static apr_status_t whois_output_filter (ap_filter_t *f, apr_bucket_brigade *bb)
 Whois output filter inserts in front of every <LF>, which is not preceeded by <CR>, <CR>. More...
 
static int whois_postconfig_hook (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 Postconfig hook is a good occasion to check consistency of mod_whoisd configuration and to initialize CORBA component. More...
 
static const char * set_whois_protocol (cmd_parms *cmd, void *dummy, int flag)
 Routine disables or enables the operation of mod_whois. More...
 
static const char * set_disclaimer_file (cmd_parms *cmd, void *dummy, const char *a1)
 Routine accepts name of file with disclaimer, it also reads the file and stores disclaimer in server configuration struct. More...
 
static const char * set_logger_object (cmd_parms *cmd, void *dummy, const char *name)
 Routine sets name under which logger object is registered by nameservice. More...
 
static const char * set_whois_object (cmd_parms *cmd, void *dummy, const char *name)
 Routine sets name under which is registered whois object by nameservice. More...
 
static void * create_whoisd_config (apr_pool_t *p, server_rec *s)
 Create server configuration for whoisd module. More...
 
static void register_hooks (apr_pool_t *p)
 Function registering hooks of whoisd module. More...
 

Variables

module AP_MODULE_DECLARE_DATA whoisd_module
 Whois module declaration. More...
 
static const char * usagestr
 Error message in case of incorrect usage.
 
static const char * indexlist
 List of attributes which can be used in search, this is displayed with -q indexes. More...
 
static const char * templatelist
 List of templates for all five object types.
 
static const command_rec whoisd_cmds []
 Structure defining configuration options for whoisd module. More...
 

Detailed Description

Module implementing whois service.

Whois daemon accepts requests containing object name and returns information about that object. The only object, which this server serves information about, is currently a domain.

The module serves only as a proxy, translating whois requests to CORBA requests and back. CORBA functionality is implemented in whois-client.c.

Macro Definition Documentation

#define ap_log_cerror (   mark,
  level,
  status,
  c,
  ... 
)    ap_log_error(mark, level, status, (c)->base_server, __VA_ARGS__)

This is wrapper function for compatibility reason.

Apache 2.0 does not have ap_log_cerror, instead we will use ap_log_error.

Referenced by get_corba_service(), log_whois_request(), process_whois_connection(), process_whois_query(), read_request(), and send_error().

#define DEFAULT_DISCLAIMER   "Domain Information over Whois protocol\n"

This default disclaimer should never be used in production release.

Referenced by whois_postconfig_hook().

#define MAX_WHOIS_REQUEST_LENGTH   1000

Maximal length of input line.

Referenced by process_whois_connection(), and read_request().

#define MAXARGS   20

Maximal number of whois arguments.

Referenced by process_whois_connection().

#define MAXAXELEN   15

Maximal length of search axe identifier.

Referenced by process_whois_connection().

#define MAXQPARLEN   15

Maximal length of -q parameter.

Referenced by process_whois_connection().

#define MAXTYPELEN   15

Maximal length of object type identifier.

#define MIN_WHOIS_REQUEST_LENGTH   1

Minimal length of input line.

Referenced by read_request().

Function Documentation

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

Create server configuration for whoisd module.

Parameters
pPool used for allocations.
sServer structure.
static void* get_corba_service ( conn_rec *  c,
char *  name 
)
static
  • Get a reference to the CORBA service with the given name
      • Parameters
        cConnection.
        nameName of the service.

References ap_log_cerror.

Referenced by log_whois_request(), and process_whois_query().

static int getobjtype ( int *  bittype,
const char *  strtype 
)
static

Function converts object type from string form to bit form.

If the object type is not recognized the bit array is unchanged.

Parameters
bittypeNumber where each object type has its own bit.
strtypeObject type token.
Returns
0 if successfull, 1 if object type was not recognized.

Referenced by process_whois_connection().

static apr_status_t log_whois_request ( whois_request wr,
conn_rec *  c,
char *  content,
whoisd_server_conf sc,
ccReg_TID *  log_entry_id 
)
static

Call fred-logd now it mostly returns APR_SUCCESS because logger failure isn't fatal to whois itself only if memory allocation fails, it returns HTTP_INTERNAL_SERVER_ERROR.

Parameters
wrRequest data.
cIncomnig connection.
contentRequest string.
scServer config.
log_entry_idOutput of entry ID from event logger.

References ap_log_cerror, whois_request::axe, CORBA_OK, CORBA_OK_LIMIT, get_corba_service(), whoisd_server_conf::logger_object, MAX_ERROR_MSG_LEN, whois_request::norecursion, whois_request::type, whois_request::value, whois_log_new_message(), and wrap_str().

Referenced by process_whois_connection().

static void print_contact_object ( apr_bucket_brigade *  bb,
obj_contact c 
)
static
static void print_domain_object ( apr_bucket_brigade *  bb,
obj_domain d 
)
static
static void print_keyset_object ( apr_bucket_brigade *  bb,
obj_keyset k 
)
static
static void print_nsset_object ( apr_bucket_brigade *  bb,
obj_nsset n 
)
static

Function prints nsset information to bucket brigade.

Parameters
bbBucket brigade.
nNsset object.

References obj_nsset::changed, obj_nsset::created, obj_nsset::nserver, obj_nsset::nserver_addrs, obj_nsset::nsset, obj_nsset::registrar, and obj_nsset::tech_c.

Referenced by process_whois_query().

static void print_registrar_object ( apr_bucket_brigade *  bb,
obj_registrar r 
)
static

Function prints registrar information to bucket brigade.

Parameters
bbBucket brigade.
rRegistrar object.

References obj_registrar::address, obj_registrar::org, obj_registrar::phone, obj_registrar::registrar, and obj_registrar::url.

Referenced by process_whois_query().

static int process_whois_connection ( conn_rec *  c)
static

Connection handler of mod_whoisd module.

If mod_whoisd is for server enabled, the request is read (assuming it is whois request) and processed in request handler, which is called from inside of this function.

Parameters
cIncomming connection.
Returns
Status.

References ap_log_cerror, whois_request::axe, whoisd_server_conf::disclaimer, getobjtype(), indexlist, IS_SEARCH_SET, log_whois_request(), MAX_WHOIS_REQUEST_LENGTH, MAXARGS, MAXAXELEN, MAXQPARLEN, whois_request::norecursion, print_intro(), process_whois_query(), read_request(), send_error(), templatelist, whois_request::type, whois_request::value, whoisd_server_conf::whoisd_enabled, and whoisd_module.

Referenced by register_hooks().

static apr_status_t process_whois_query ( conn_rec *  c,
whoisd_server_conf sc,
whois_request wr,
ccReg_TID  log_entry_id 
)
static

Whois request processor.

This function is called from connection handler. It performs a CORBA call through CORBA backend and then processes data and sends a whois answer.

Parameters
cConnection.
scServer configuration.
wrWhois request data
log_entry_idEntry ID from event logger
Returns
Result of processing.

References ap_log_cerror, CORBA_INTERNAL_ERROR, CORBA_OK, CORBA_OK_LIMIT, CORBA_SERVICE_FAILED, whoisd_server_conf::disclaimer, get_corba_service(), whoisd_server_conf::logger_object, MAX_ERROR_MSG_LEN, MAX_OBJECT_COUNT, whoisd_server_conf::object, print_contact_object(), print_domain_object(), print_intro(), print_keyset_object(), print_nsset_object(), print_registrar_object(), send_error(), TIME_BUFFER_LENGTH, whois_request::value, whois_corba_call(), and whois_release_data().

Referenced by process_whois_connection().

static char* read_request ( conn_rec *  c,
int *  http_status 
)
static

This will read whois request (one line of text).

Parameters
cConnection structure.
http_statusHTTP error code.
Returns
The string which was read, NULL in case of error.

References ap_log_cerror, MAX_WHOIS_REQUEST_LENGTH, and MIN_WHOIS_REQUEST_LENGTH.

Referenced by process_whois_connection().

static void register_hooks ( apr_pool_t *  p)
static

Function registering hooks of whoisd module.

Parameters
pPool used for allocations.

References process_whois_connection(), whois_output_filter(), and whois_postconfig_hook().

static void send_error ( conn_rec *  c,
const char *  disclaimer,
int  nerr 
)
static

Routine trigerred upon error.

Parameters
cConnection.
disclaimerDisclaimer.
nerrNumber of error.

References ap_log_cerror, print_intro(), and usagestr.

Referenced by process_whois_connection(), and process_whois_query().

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

Routine accepts name of file with disclaimer, it also reads the file and stores disclaimer in server configuration struct.

Parameters
cmdCommand.
dummyNot used arg.
a1The value.
Returns
NULL if OK, otherwise a string.

References whoisd_server_conf::disclaimer, whoisd_server_conf::disclaimer_filename, and whoisd_module.

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

Routine sets name under which logger object is registered by nameservice.

Parameters
cmdCommand.
dummyNot used arg.
nameThe value.
Returns
NULL if OK, otherwise a string.

References whoisd_server_conf::logger_object, and whoisd_module.

static const char* set_whois_object ( cmd_parms *  cmd,
void *  dummy,
const char *  name 
)
static

Routine sets name under which is registered whois object by nameservice.

Parameters
cmdCommand.
dummyNot used arg.
nameThe value.
Returns
NULL if OK, otherwise a string.

References whoisd_server_conf::object, and whoisd_module.

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

Routine disables or enables the operation of mod_whois.

Parameters
cmdCommand.
dummyNot used arg.
flagThe value.
Returns
NULL if OK, otherwise a string.

References whoisd_server_conf::whoisd_enabled, and whoisd_module.

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

Whois output filter inserts in front of every <LF>, which is not preceeded by <CR>, <CR>.

Parameters
fChain of filters.
bbBucket brigade to be filtered.
Returns
Status.

Referenced by register_hooks().

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

Postconfig hook is a good occasion to check consistency of mod_whoisd configuration and to initialize CORBA component.

Parameters
pPool to allocate from.
plogPool used for logging.
ptempTemporary pool.
sServer struct.
Returns
Status.

References DEFAULT_DISCLAIMER, whoisd_server_conf::disclaimer, whoisd_server_conf::disclaimer_filename, whoisd_server_conf::object, whoisd_server_conf::whoisd_enabled, and whoisd_module.

Referenced by register_hooks().

static char* wrap_str ( const char *  str)
static

Function wraps strings passed from XML parser into strings accepted by CORBA.

Null strings are transformed to empty strings. The resulting string must be freed with CORBA_free().

Parameters
strInput string.
Returns
Output string.

Referenced by log_whois_request().

Variable Documentation

const char* indexlist
static
Initial value:
=
"% The following object types can be looked up in whois database:\n\
% domain, nsset, keyset, contact, registrar.\n\
% \n\
% If you don't specify -i option the object is looked up by its primary key.\n\
% Specify object type by -T option, if you want to narrow the search.\n\
% \n\
% List of attribute names which can be used with -i option. Use only the part\n\
% following the colon. The part preceding the colon is object type, which is\n\
% associated with the attribute.\n\
% \n\
% domain:registrant\n\
% domain:admin-c\n\
% domain:temp-c\n\
% domain:nsset\n\
% domain:keyset\n\
% nsset:nserver\n\
% nsset:tech-c\n\
% keyset:tech-c\n\
"

List of attributes which can be used in search, this is displayed with -q indexes.

Referenced by process_whois_connection().

const command_rec whoisd_cmds[]
static
Initial value:
= {
AP_INIT_FLAG("WhoisProtocol", set_whois_protocol, NULL, RSRC_CONF,
"Whether this server is serving the whois protocol"),
AP_INIT_TAKE1("WhoisDisclaimer", set_disclaimer_file, NULL, RSRC_CONF,
"File name with disclaimer which is standard part"
"of every whois response"),
AP_INIT_TAKE1("WhoisObject", set_whois_object, NULL, RSRC_CONF,
"Name under which the whois object is known to "
"nameserver. Default is \"Whois\"."),
AP_INIT_TAKE1("WhoisLogdObject", set_logger_object, NULL, RSRC_CONF,
"Name under which the fred-logd object is known to "
"nameserver. Default is \"Logger\"."),
{ NULL }
}
static const char * set_logger_object(cmd_parms *cmd, void *dummy, const char *name)
Routine sets name under which logger object is registered by nameservice.
Definition: mod_whoisd.c:1592
static const char * set_whois_object(cmd_parms *cmd, void *dummy, const char *name)
Routine sets name under which is registered whois object by nameservice.
Definition: mod_whoisd.c:1628
static const char * set_whois_protocol(cmd_parms *cmd, void *dummy, int flag)
Routine disables or enables the operation of mod_whois.
Definition: mod_whoisd.c:1490
static const char * set_disclaimer_file(cmd_parms *cmd, void *dummy, const char *a1)
Routine accepts name of file with disclaimer, it also reads the file and stores disclaimer in server ...
Definition: mod_whoisd.c:1513

Structure defining configuration options for whoisd module.

module AP_MODULE_DECLARE_DATA whoisd_module
Initial value:
= {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
}
static const command_rec whoisd_cmds[]
Structure defining configuration options for whoisd module.
Definition: mod_whoisd.c:1656
static void register_hooks(apr_pool_t *p)
Function registering hooks of whoisd module.
Definition: mod_whoisd.c:1690
static void * create_whoisd_config(apr_pool_t *p, server_rec *s)
Create server configuration for whoisd module.
Definition: mod_whoisd.c:1677

Whois module declaration.

Definition of whoisd module.

Referenced by process_whois_connection(), set_disclaimer_file(), set_logger_object(), set_whois_object(), set_whois_protocol(), and whois_postconfig_hook().