// --- BEGIN COPYRIGHT BLOCK ---
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301 USA
//
// Copyright (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef XP_WIN32
#define TOKENDB_PUBLIC __declspec(dllexport)
#else /* !XP_WIN32 */
#define TOKENDB_PUBLIC
#endif /* !XP_WIN32 */
/* _________________________________________________________________
**
** Tokendb Module Headers
** _________________________________________________________________
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef XP_WIN32
#include <unistd.h> /* sleep */
#else /* XP_WIN32 */
#include <windows.h>
#endif /* XP_WIN32 */
#include "nspr.h"
#include "prio.h"
#include "plstr.h"
#include "prmem.h"
#include "prtime.h"
#include "prthread.h"
#include "cert.h"
#include "regex.h"
#include "nss3/base64.h"
#include "httpd/httpd.h"
#include "httpd/http_config.h"
#include "httpd/http_log.h"
#include "httpd/http_protocol.h"
#include "httpd/http_main.h"
#include "httpd/http_request.h"
#include "apr_strings.h"
#include "cms/CertEnroll.h"
#include "engine/RA.h"
#include "tus/tus_db.h"
#include "processor/RA_Processor.h"
#include "selftests/SelfTest.h"
extern TOKENDB_PUBLIC char *nss_var_lookup( apr_pool_t *p, server_rec *s,
conn_rec *c, request_rec *r,
char *var );
/* _________________________________________________________________
**
** Tokendb Module Definitions
** _________________________________________________________________
*/
#define JS_START "<SCRIPT LANGUAGE=\"JavaScript\">\n<!--\n"
#define JS_STOP "//-->\n</SCRIPT>\n"
#define CMS_TEMPLATE_TAG "<CMS_TEMPLATE>"
#define MAX_INJECTION_SIZE 5120
#define MAX_OVERLOAD 20
#define LOW_INJECTION_SIZE 2048
#define SHORT_LEN 256
#define BASE64_HEADER "-----BEGIN CERTIFICATE-----\n"
#define BASE64_FOOTER "-----END CERTIFICATE-----\n"
#define TOKENDB_OPERATORS_IDENTIFIER "TUS Operators"
#define TOKENDB_AGENTS_IDENTIFIER "TUS Agents"
#define TOKENDB_ADMINISTRATORS_IDENTIFIER "TUS Administrators"
#define OP_PREFIX "op.format"
#define NUM_PROFILES_TO_DISPLAY 15
#define NUM_ENTRIES_PER_PAGE 25
#define MAX_LEN_PROFILES_TO_DISPLAY 1000
#define error_out(msg1,msg2) \
PR_snprintf(injection, MAX_INJECTION_SIZE, \
"%s%s%s%s%s", JS_START, "var error = \"Error: ", \
msg1,"\";\n", JS_STOP ); \
buf = getData( errorTemplate, injection ); \
ap_log_error( ( const char * ) "tus", __LINE__, \
APLOG_ERR, 0, rq->server, \
( const char * ) msg2 ); \
( void ) ap_rwrite( ( const void * ) buf, PL_strlen( buf ), rq );
#define ldap_error_out(msg1,msg2) \
PR_snprintf( injection, MAX_INJECTION_SIZE, \
"%s%s%s%s%s%s", JS_START, \
"var error = \"", msg1, \
ldap_err2string( status ), \
"\";\n", JS_STOP ); \
buf = getData( errorTemplate, injection ); \
ap_log_error( ( const char * ) "tus", __LINE__, \
APLOG_ERR, 0, rq->server, \
( const char * ) msg2, \
ldap_err2string( status ) ); \
( void ) ap_rwrite( ( const void * ) buf, PL_strlen( buf ), rq );
#define post_ldap_error(msg) \
ap_log_error( ( const char * ) "tus", __LINE__, \
APLOG_ERR, 0, rq->server, \
(const char *) msg, ldap_err2string( status ) );
#define get_cfg_string(cname, vname) \
if( ( s = PL_strstr( buf, cname ) ) != NULL ) { \
s += PL_strlen( cname ); \
v = s; \
while( *s != '\x0D' && *s != '\x0A' && *s != '\0' && \
( PRUint32 ) ( s - buf ) < size ) { \
s++; \
} \
n = s - v; \
s = PL_strndup( v, n ); \
if( s != NULL ) { \
if( vname != NULL ) { \
PL_strfree( vname ); \
vname = NULL; \
} \
vname = s; \
} else { \
do_free(buf); \
return 0; \
} \
}
#define get_cfg_int(cname, vname) \
if( ( s = PL_strstr( buf, cname ) ) != NULL ) { \
s += PL_strlen( cname ); \
v = s; \
while( *s != '\x0D' && *s != '\x0A' && *s != '\0' && \
( PRUint32 ) ( s - buf ) < size ) { \
s++; \
} \
n = s - v; \
s = PL_strndup( v, n ); \
if( s != NULL ) { \
char *endptr = NULL; \
errno = 0; \
vname = strtol(s, &endptr, 10);\
if ((errno == ERANGE && (vname == LONG_MAX || vname == LONG_MIN)) \
|| (endptr == s)) { \
vname=0; \
} \
do_free(s); \
} else { \
do_free(buf); \
do_free(s); \
return 0; \
} \
}
/**
* Provide reasonable defaults for some defines.
*/
enum MOD_TOKENDB_BOOL {
MOD_TOKENDB_FALSE = 0,
MOD_TOKENDB_TRUE = 1
};
#define MAX_TOKEN_UI_STATE 6
enum token_ui_states {
TOKEN_UNINITIALIZED = 0,
TOKEN_DAMAGED =1,
TOKEN_PERM_LOST=2,
TOKEN_TEMP_LOST=3,
TOKEN_FOUND =4,
TOKEN_TEMP_LOST_PERM_LOST =5,
TOKEN_TERMINATED = 6
};
/* _________________________________________________________________
**
** Tokendb Module Request Data
** _________________________________________________________________
*/
#ifdef DEBUG_Tokendb
static PRFileDesc *debug_fd = NULL;
#endif
static char *templateDir = NULL;
static char *errorTemplate = NULL;
static char *indexTemplate = NULL;
static char *indexAdminTemplate = NULL;
static char *indexOperatorTemplate = NULL;
static char *newTemplate = NULL;
static char *searchTemplate = NULL;
static char *searchResultTemplate = NULL;
static char *searchAdminTemplate = NULL;
static char *searchAdminResultTemplate = NULL;
static char *searchActivityTemplate = NULL;
static char *searchCertificateTemplate = NULL;
static char *searchCertificateResultTemplate = NULL;
static char *searchActivityResultTemplate = NULL;
static char *searchActivityAdminTemplate = NULL;
static char *searchActivityAdminResultTemplate = NULL;
static char *editTemplate = NULL;
static char *editResultTemplate = NULL;
static char *showTemplate = NULL;
static char *showCertTemplate = NULL;
static char *showAdminTemplate = NULL;
static char *deleteTemplate = NULL;
static char *doTokenTemplate = NULL;
static char *doTokenConfirmTemplate = NULL;
static char *revokeTemplate = NULL;
static char *addResultTemplate = NULL;
static char *deleteResultTemplate = NULL;
static char *editUserTemplate = NULL;
static char *searchUserResultTemplate = NULL;
static char *searchUserTemplate = NULL;
static char *newUserTemplate = NULL;
static char *userDeleteTemplate = NULL;
static char *auditAdminTemplate = NULL;
static char *selfTestTemplate = NULL;
static char *selfTestResultsTemplate = NULL;
static char *agentSelectConfigTemplate = NULL;
static char *selectConfigTemplate = NULL;
static char *agentViewConfigTemplate = NULL;
static char *editConfigTemplate = NULL;
static char *confirmConfigChangesTemplate = NULL;
static char *addConfigTemplate = NULL;
static char *confirmDeleteConfigTemplate = NULL;
|