mirror of
https://github.com/kakwa/uts-server
synced 2025-01-10 05:34:29 +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
a2007f36dd
commit
ec467ba646
@ -38,7 +38,7 @@ EOF
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
simple_logger(){
|
simple_uts_logger(){
|
||||||
[ $SYSLOG -eq 0 ] && logger -t `basename $0` -p user.$1 $2
|
[ $SYSLOG -eq 0 ] && logger -t `basename $0` -p user.$1 $2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "rfc3161.h"
|
|
||||||
|
|
||||||
int http_server_start(char *conffile, bool stdout_dbg);
|
int http_server_start(char *conffile, bool stdout_dbg);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
#include <openssl/ts.h>
|
#include <openssl/ts.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
|
#include "context.h"
|
||||||
|
|
||||||
/* Name of config entry that defines the OID file. */
|
/* Name of config entry that defines the OID file. */
|
||||||
#define ENV_OID_FILE "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 *serial_cb(TS_RESP_CTX *ctx, void *data);
|
||||||
static ASN1_INTEGER *next_serial(const char *serialfile);
|
static ASN1_INTEGER *next_serial(const char *serialfile);
|
||||||
static int save_ts_serial(const char *serialfile, ASN1_INTEGER *serial);
|
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"
|
#include "rfc3161.h"
|
||||||
|
|
||||||
void skeleton_daemon();
|
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);
|
int set_params(rfc3161_context *ct, char *conf_file);
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
#include "rfc3161.h"
|
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
|
||||||
const char *argp_program_version = UTS_VERSION;
|
const char *argp_program_version = UTS_VERSION;
|
||||||
|
@ -17,27 +17,27 @@
|
|||||||
void log_request_debug(const struct mg_request_info *request_info,
|
void log_request_debug(const struct mg_request_info *request_info,
|
||||||
int request_id, void *context) {
|
int request_id, void *context) {
|
||||||
for (int i = 0; i < request_info->num_headers; i++) {
|
for (int i = 0; i < request_info->num_headers; i++) {
|
||||||
logger(context, LOG_DEBUG, "Request[%d], Header[%s]: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], Header[%s]: %s\n",
|
||||||
request_info->http_headers[i].name,
|
request_id, request_info->http_headers[i].name,
|
||||||
request_info->http_headers[i].value);
|
request_info->http_headers[i].value);
|
||||||
}
|
}
|
||||||
logger(context, LOG_DEBUG, "Request[%d], request_method: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], request_method: %s\n",
|
||||||
request_info->request_method);
|
request_id, request_info->request_method);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], request_uri: %s\n", request_id,
|
||||||
request_info->request_uri);
|
request_info->request_uri);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], local_uri: %s\n", request_id,
|
||||||
request_info->local_uri);
|
request_info->local_uri);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], http_version: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], http_version: %s\n",
|
||||||
request_info->http_version);
|
request_id, request_info->http_version);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], query_string: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], query_string: %s\n",
|
||||||
request_info->query_string);
|
request_id, request_info->query_string);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], remote_addr: %s\n", request_id,
|
||||||
request_info->remote_addr);
|
request_info->remote_addr);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], is_ssl: %d\n", request_id,
|
||||||
request_info->is_ssl);
|
request_info->is_ssl);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], content_length: %d\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], content_length: %d\n",
|
||||||
request_info->content_length);
|
request_id, request_info->content_length);
|
||||||
logger(context, LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
uts_logger(context, LOG_DEBUG, "Request[%d], remote_port: %d\n", request_id,
|
||||||
request_info->remote_port);
|
request_info->remote_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,12 @@
|
|||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
#include <openssl/ts.h>
|
#include <openssl/ts.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include "rfc3161.h"
|
#include <syslog.h>
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/* Name of config entry that defines the OID file. */
|
/* Name of config entry that defines the OID file. */
|
||||||
#define ENV_OID_FILE "oid_file"
|
#define ENV_OID_FILE "oid_file"
|
||||||
|
|
||||||
static ASN1_OBJECT *txt2obj(const char *oid);
|
|
||||||
|
|
||||||
/* Reply related functions. */
|
/* Reply related functions. */
|
||||||
static int reply_command(CONF *conf, char *section, char *engine, char *query,
|
static int reply_command(CONF *conf, char *section, char *engine, char *query,
|
||||||
char *passin, char *inkey, const EVP_MD *md,
|
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.
|
* Reply-related method definitions.
|
||||||
*/
|
*/
|
||||||
@ -198,11 +184,14 @@ end:
|
|||||||
return resp;
|
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;
|
int ret = 0;
|
||||||
TS_RESP_CTX *resp_ctx = NULL;
|
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;
|
goto end;
|
||||||
|
}
|
||||||
if ((resp_ctx = TS_RESP_CTX_new()) == NULL)
|
if ((resp_ctx = TS_RESP_CTX_new()) == NULL)
|
||||||
goto end;
|
goto end;
|
||||||
if (!TS_CONF_set_serial(conf, section, NULL, resp_ctx))
|
if (!TS_CONF_set_serial(conf, section, NULL, resp_ctx))
|
||||||
|
@ -81,7 +81,7 @@ void skeleton_daemon() {
|
|||||||
openlog("uts-server", LOG_PID, LOG_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
|
// ignore all messages less critical than the loglevel
|
||||||
// except if the debug flag is set
|
// except if the debug flag is set
|
||||||
if (priority > ct->loglevel && !ct->stdout_dbg)
|
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);
|
free(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +142,14 @@ static BIO *bio_open_default(rfc3161_context *ct, const char *filename,
|
|||||||
format = FORMAT_TEXT;
|
format = FORMAT_TEXT;
|
||||||
|
|
||||||
if (filename == NULL || strcmp(filename, "-") == 0) {
|
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;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
ret = BIO_new_file(filename, "rb");
|
ret = BIO_new_file(filename, "rb");
|
||||||
if (ret != NULL)
|
if (ret != NULL)
|
||||||
return ret;
|
return ret;
|
||||||
logger(ct, LOG_CRIT, "Can't open %s for %s, %s", filename, "rb",
|
uts_logger(ct, LOG_CRIT, "Can't open %s for %s, %s", filename, "rb",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
// ERR_print_errors(bio_err);
|
// ERR_print_errors(bio_err);
|
||||||
@ -162,12 +163,12 @@ static CONF *load_config_file(rfc3161_context *ct, const char *filename) {
|
|||||||
int i;
|
int i;
|
||||||
ct->loglevel = LOG_INFO;
|
ct->loglevel = LOG_INFO;
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
logger(ct, LOG_WARNING, "no configuration file passed");
|
uts_logger(ct, LOG_WARNING, "no configuration file passed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
in = bio_open_default(ct, filename, 'r');
|
in = bio_open_default(ct, filename, 'r');
|
||||||
if (in == NULL) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +179,9 @@ static CONF *load_config_file(rfc3161_context *ct, const char *filename) {
|
|||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
if (errorline <= 0)
|
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
|
else
|
||||||
logger(ct, LOG_CRIT, "Error on line %ld of config file \"%s\"",
|
uts_logger(ct, LOG_CRIT, "Error on line %ld of config file \"%s\"",
|
||||||
errorline, filename);
|
errorline, filename);
|
||||||
NCONF_free(conf);
|
NCONF_free(conf);
|
||||||
return NULL;
|
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 *default_value = rfc3161_options[i].default_value;
|
||||||
const char *value = NCONF_get_string(conf, MAIN_CONF_SECTION, name);
|
const char *value = NCONF_get_string(conf, MAIN_CONF_SECTION, name);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
logger(ct, LOG_NOTICE,
|
uts_logger(ct, LOG_NOTICE,
|
||||||
"configuration param['%s'] not set, using default: '%s'",
|
"configuration param['%s'] not set, using default: '%s'",
|
||||||
name, default_value);
|
name, default_value);
|
||||||
value = 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) {
|
switch (type) {
|
||||||
case HTTP_OPTIONS:
|
case HTTP_OPTIONS:
|
||||||
if (value != NULL) {
|
if (value != NULL) {
|
||||||
@ -238,7 +240,7 @@ int set_params(rfc3161_context *ct, char *conf_file) {
|
|||||||
ct->http_options[http_counter] = NULL;
|
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)
|
if (ct->ts_ctx == NULL)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user