mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 23:15:54 +01:00
general reorganization
* rename the logger function to uts_logger * add logging to the create_tsctx fucntion * fix some warning *
This commit is contained in:
parent
c2752532f1
commit
376d100e9f
@ -38,7 +38,7 @@ EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
simple_logger(){
|
||||
simple_uts_logger(){
|
||||
[ $SYSLOG -eq 0 ] && logger -t `basename $0` -p user.$1 $2
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <stdbool.h>
|
||||
#include "utils.h"
|
||||
#include "rfc3161.h"
|
||||
|
||||
int http_server_start(char *conffile, bool stdout_dbg);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ts.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "context.h"
|
||||
|
||||
/* Name of config entry that defines the OID file. */
|
||||
#define ENV_OID_FILE "oid_file"
|
||||
@ -35,4 +36,5 @@ static TS_RESP *create_response(CONF *conf, const char *section, char *engine,
|
||||
static ASN1_INTEGER *serial_cb(TS_RESP_CTX *ctx, void *data);
|
||||
static ASN1_INTEGER *next_serial(const char *serialfile);
|
||||
static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial);
|
||||
TS_RESP_CTX *create_tsctx(CONF *conf, const char *section, const char *policy);
|
||||
TS_RESP_CTX *create_tsctx(rfc3161_context *ct, CONF *conf, const char *section,
|
||||
const char *policy);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "context.h"
|
||||
#include "rfc3161.h"
|
||||
|
||||
void skeleton_daemon();
|
||||
void logger(rfc3161_context *ct, int priority, char *fmt, ...);
|
||||
void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...);
|
||||
int set_params(rfc3161_context *ct, char *conf_file);
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <getopt.h>
|
||||
#include <argp.h>
|
||||
#include <sys/syslog.h>
|
||||
#include "rfc3161.h"
|
||||
#include "http.h"
|
||||
|
||||
const char *argp_program_version = UTS_VERSION;
|
||||
|
@ -17,28 +17,28 @@
|
||||
void log_request_debug(const struct mg_request_info *request_info,
|
||||
int request_id, void *context) {
|
||||
for (int i = 0; i < request_info->num_headers; i++) {
|
||||
logger(context, LOG_DEBUG, "Request[%d], Header[%s]: %s\n", request_id,
|
||||
request_info->http_headers[i].name,
|
||||
request_info->http_headers[i].value);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], Header[%s]: %s\n",
|
||||
request_id, request_info->http_headers[i].name,
|
||||
request_info->http_headers[i].value);
|
||||
}
|
||||
logger(context, LOG_DEBUG, "Request[%d], request_method: %s\n", request_id,
|
||||
request_info->request_method);
|
||||
logger(context, LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
||||
request_info->request_uri);
|
||||
logger(context, LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
||||
request_info->local_uri);
|
||||
logger(context, LOG_DEBUG, "Request[%d], http_version: %s\n", request_id,
|
||||
request_info->http_version);
|
||||
logger(context, LOG_DEBUG, "Request[%d], query_string: %s\n", request_id,
|
||||
request_info->query_string);
|
||||
logger(context, LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
||||
request_info->remote_addr);
|
||||
logger(context, LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
||||
request_info->is_ssl);
|
||||
logger(context, LOG_DEBUG, "Request[%d], content_length: %d\n", request_id,
|
||||
request_info->content_length);
|
||||
logger(context, LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
||||
request_info->remote_port);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], request_method: %s\n",
|
||||
request_id, request_info->request_method);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
||||
request_info->request_uri);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
||||
request_info->local_uri);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], http_version: %s\n",
|
||||
request_id, request_info->http_version);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], query_string: %s\n",
|
||||
request_id, request_info->query_string);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
||||
request_info->remote_addr);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
||||
request_info->is_ssl);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], content_length: %d\n",
|
||||
request_id, request_info->content_length);
|
||||
uts_logger(context, LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
||||
request_info->remote_port);
|
||||
}
|
||||
|
||||
// This function will be called by civetweb on every new request.
|
||||
|
@ -19,13 +19,12 @@
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ts.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "rfc3161.h"
|
||||
#include <syslog.h>
|
||||
#include "utils.h"
|
||||
|
||||
/* Name of config entry that defines the OID file. */
|
||||
#define ENV_OID_FILE "oid_file"
|
||||
|
||||
static ASN1_OBJECT *txt2obj(const char *oid);
|
||||
|
||||
/* Reply related functions. */
|
||||
static int reply_command(CONF *conf, char *section, char *engine, char *query,
|
||||
char *passin, char *inkey, const EVP_MD *md,
|
||||
@ -68,19 +67,6 @@ static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configuration file-related function definitions.
|
||||
*/
|
||||
|
||||
static ASN1_OBJECT *txt2obj(const char *oid) {
|
||||
ASN1_OBJECT *oid_obj = NULL;
|
||||
|
||||
if ((oid_obj = OBJ_txt2obj(oid, 0)) == NULL)
|
||||
// BIO_printf(bio_err, "cannot convert %s to OID\n", oid);
|
||||
|
||||
return oid_obj;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reply-related method definitions.
|
||||
*/
|
||||
@ -198,11 +184,14 @@ end:
|
||||
return resp;
|
||||
}
|
||||
|
||||
TS_RESP_CTX *create_tsctx(CONF *conf, const char *section, const char *policy) {
|
||||
TS_RESP_CTX *create_tsctx(rfc3161_context *ct, CONF *conf, const char *section,
|
||||
const char *policy) {
|
||||
int ret = 0;
|
||||
TS_RESP_CTX *resp_ctx = NULL;
|
||||
if ((section = TS_CONF_get_tsa_section(conf, section)) == NULL)
|
||||
if ((section = TS_CONF_get_tsa_section(conf, section)) == NULL) {
|
||||
uts_logger(ct, LOG_ERR, "failed to get the tsa default section");
|
||||
goto end;
|
||||
}
|
||||
if ((resp_ctx = TS_RESP_CTX_new()) == NULL)
|
||||
goto end;
|
||||
if (!TS_CONF_set_serial(conf, section, NULL, resp_ctx))
|
||||
|
@ -81,7 +81,7 @@ void skeleton_daemon() {
|
||||
openlog("uts-server", LOG_PID, LOG_DAEMON);
|
||||
}
|
||||
|
||||
void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
// ignore all messages less critical than the loglevel
|
||||
// except if the debug flag is set
|
||||
if (priority > ct->loglevel && !ct->stdout_dbg)
|
||||
@ -132,7 +132,7 @@ void logger(rfc3161_context *ct, int priority, char *fmt, ...) {
|
||||
;
|
||||
}
|
||||
}
|
||||
syslog(priority, out);
|
||||
syslog(priority, "%s", out);
|
||||
free(out);
|
||||
}
|
||||
|
||||
@ -142,14 +142,15 @@ static BIO *bio_open_default(rfc3161_context *ct, const char *filename,
|
||||
format = FORMAT_TEXT;
|
||||
|
||||
if (filename == NULL || strcmp(filename, "-") == 0) {
|
||||
logger(ct, LOG_CRIT, "Can't open %s, %s", filename, strerror(errno));
|
||||
uts_logger(ct, LOG_CRIT, "Can't open %s, %s", filename,
|
||||
strerror(errno));
|
||||
return NULL;
|
||||
} else {
|
||||
ret = BIO_new_file(filename, "rb");
|
||||
if (ret != NULL)
|
||||
return ret;
|
||||
logger(ct, LOG_CRIT, "Can't open %s for %s, %s", filename, "rb",
|
||||
strerror(errno));
|
||||
uts_logger(ct, LOG_CRIT, "Can't open %s for %s, %s", filename, "rb",
|
||||
strerror(errno));
|
||||
}
|
||||
// ERR_print_errors(bio_err);
|
||||
return NULL;
|
||||
@ -162,12 +163,12 @@ static CONF *load_config_file(rfc3161_context *ct, const char *filename) {
|
||||
int i;
|
||||
ct->loglevel = LOG_INFO;
|
||||
if (filename == NULL) {
|
||||
logger(ct, LOG_WARNING, "no configuration file passed");
|
||||
uts_logger(ct, LOG_WARNING, "no configuration file passed");
|
||||
return NULL;
|
||||
}
|
||||
in = bio_open_default(ct, filename, 'r');
|
||||
if (in == NULL) {
|
||||
logger(ct, LOG_CRIT, "Can't load config file \"%s\"", filename);
|
||||
uts_logger(ct, LOG_CRIT, "Can't load config file \"%s\"", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -178,10 +179,10 @@ static CONF *load_config_file(rfc3161_context *ct, const char *filename) {
|
||||
return conf;
|
||||
}
|
||||
if (errorline <= 0)
|
||||
logger(ct, LOG_CRIT, "Can't load config file \"%s\"", filename);
|
||||
uts_logger(ct, LOG_CRIT, "Can't load config file \"%s\"", filename);
|
||||
else
|
||||
logger(ct, LOG_CRIT, "Error on line %ld of config file \"%s\"",
|
||||
errorline, filename);
|
||||
uts_logger(ct, LOG_CRIT, "Error on line %ld of config file \"%s\"",
|
||||
errorline, filename);
|
||||
NCONF_free(conf);
|
||||
return NULL;
|
||||
}
|
||||
@ -215,12 +216,13 @@ int set_params(rfc3161_context *ct, char *conf_file) {
|
||||
const char *default_value = rfc3161_options[i].default_value;
|
||||
const char *value = NCONF_get_string(conf, MAIN_CONF_SECTION, name);
|
||||
if (value == NULL) {
|
||||
logger(ct, LOG_NOTICE,
|
||||
"configuration param['%s'] not set, using default: '%s'",
|
||||
name, default_value);
|
||||
uts_logger(ct, LOG_NOTICE,
|
||||
"configuration param['%s'] not set, using default: '%s'",
|
||||
name, default_value);
|
||||
value = default_value;
|
||||
}
|
||||
logger(ct, LOG_DEBUG, "configuration param['%s'] = '%s'", name, value);
|
||||
uts_logger(ct, LOG_DEBUG, "configuration param['%s'] = '%s'", name,
|
||||
value);
|
||||
switch (type) {
|
||||
case HTTP_OPTIONS:
|
||||
if (value != NULL) {
|
||||
@ -238,7 +240,7 @@ int set_params(rfc3161_context *ct, char *conf_file) {
|
||||
ct->http_options[http_counter] = NULL;
|
||||
}
|
||||
|
||||
ct->ts_ctx = create_tsctx(conf, "tsa", NULL);
|
||||
ct->ts_ctx = create_tsctx(ct, conf, "tsa", NULL);
|
||||
if (ct->ts_ctx == NULL)
|
||||
ret = 0;
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user