From 376d100e9f97e6c1a48d968b3b21515701015dfa Mon Sep 17 00:00:00 2001 From: kakwa Date: Fri, 26 Aug 2016 20:39:45 +0200 Subject: [PATCH] general reorganization * rename the logger function to uts_logger * add logging to the create_tsctx fucntion * fix some warning * --- goodies/timestamp-file.sh | 2 +- inc/http.h | 1 - inc/rfc3161.h | 4 +++- inc/utils.h | 3 +-- src/cmd/uts-server.c | 1 - src/lib/http.c | 42 +++++++++++++++++++-------------------- src/lib/rfc3161.c | 25 +++++++---------------- src/lib/utils.c | 32 +++++++++++++++-------------- 8 files changed, 50 insertions(+), 60 deletions(-) diff --git a/goodies/timestamp-file.sh b/goodies/timestamp-file.sh index c95c48b..4e9c6a5 100755 --- a/goodies/timestamp-file.sh +++ b/goodies/timestamp-file.sh @@ -38,7 +38,7 @@ EOF exit 1 } -simple_logger(){ +simple_uts_logger(){ [ $SYSLOG -eq 0 ] && logger -t `basename $0` -p user.$1 $2 } diff --git a/inc/http.h b/inc/http.h index 24aa7f0..d29de81 100644 --- a/inc/http.h +++ b/inc/http.h @@ -1,5 +1,4 @@ #include #include "utils.h" -#include "rfc3161.h" int http_server_start(char *conffile, bool stdout_dbg); diff --git a/inc/rfc3161.h b/inc/rfc3161.h index d66e7ed..bf64565 100644 --- a/inc/rfc3161.h +++ b/inc/rfc3161.h @@ -10,6 +10,7 @@ #include #include #include +#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); diff --git a/inc/utils.h b/inc/utils.h index cda05d9..b66180b 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -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); diff --git a/src/cmd/uts-server.c b/src/cmd/uts-server.c index 419c041..460e34b 100644 --- a/src/cmd/uts-server.c +++ b/src/cmd/uts-server.c @@ -6,7 +6,6 @@ #include #include #include -#include "rfc3161.h" #include "http.h" const char *argp_program_version = UTS_VERSION; diff --git a/src/lib/http.c b/src/lib/http.c index 8123b49..fc00d22 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -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. diff --git a/src/lib/rfc3161.c b/src/lib/rfc3161.c index 4304544..da06dfc 100644 --- a/src/lib/rfc3161.c +++ b/src/lib/rfc3161.c @@ -19,13 +19,12 @@ #include #include #include -#include "rfc3161.h" +#include +#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)) diff --git a/src/lib/utils.c b/src/lib/utils.c index d52a8aa..08463cd 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -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;