Adapt ENGINE_TABLE_DEBUG to the new generic trace API

Co-authored-by: Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8198)
This commit is contained in:
Richard Levitte 2018-12-13 01:42:07 +01:00
parent f4db05df0e
commit f272be676b
4 changed files with 32 additions and 47 deletions

View file

@ -11,6 +11,7 @@
#ifndef HEADER_ENGINE_INT_H
# define HEADER_ENGINE_INT_H
# include <openssl/trace.h>
# include "internal/cryptlib.h"
# include "internal/engine.h"
# include "internal/thread_once.h"
@ -58,14 +59,6 @@ void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb);
/* We need stacks of ENGINEs for use in eng_table.c */
DEFINE_STACK_OF(ENGINE)
/*
* If this symbol is defined then engine_table_select(), the function that is
* used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults
* and functional references (etc), will display debugging summaries to
* stderr.
*/
/* #define ENGINE_TABLE_DEBUG */
/*
* This represents an implementation table. Dependent code should instantiate
* it as a (ENGINE_TABLE *) pointer value set initially to NULL.
@ -76,13 +69,10 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
int setdefault);
void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e);
void engine_table_cleanup(ENGINE_TABLE **table);
# ifndef ENGINE_TABLE_DEBUG
ENGINE *engine_table_select(ENGINE_TABLE **table, int nid);
# else
ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
ENGINE *engine_table_select_int(ENGINE_TABLE **table, int nid, const char *f,
int l);
# define engine_table_select(t,n) engine_table_select_tmp(t,n,OPENSSL_FILE,OPENSSL_LINE)
# endif
# define engine_table_select(t,n) \
engine_table_select_int(t,n,OPENSSL_FILE,OPENSSL_LINE)
typedef void (engine_table_doall_cb) (int nid, STACK_OF(ENGINE) *sk,
ENGINE *def, void *arg);
void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,

View file

@ -10,6 +10,7 @@
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <openssl/lhash.h>
#include <openssl/trace.h>
#include "eng_int.h"
/* The type of the items in the table */
@ -189,29 +190,24 @@ void engine_table_cleanup(ENGINE_TABLE **table)
}
/* return a functional reference for a given 'nid' */
#ifndef ENGINE_TABLE_DEBUG
ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
#else
ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
ENGINE *engine_table_select_int(ENGINE_TABLE **table, int nid, const char *f,
int l)
#endif
{
ENGINE *ret = NULL;
ENGINE_PILE tmplate, *fnd = NULL;
int initres, loop = 0;
if (!(*table)) {
#ifdef ENGINE_TABLE_DEBUG
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "
"registered!\n", f, l, nid);
#endif
OSSL_TRACE3(ENGINE_TABLE,
"%s:%d, nid=%d, nothing registered!\n",
f, l, nid);
return NULL;
}
ERR_set_mark();
CRYPTO_THREAD_write_lock(global_engine_lock);
/*
* Check again inside the lock otherwise we could race against cleanup
* operations. But don't worry about a fprintf(stderr).
* operations. But don't worry about a debug printout
*/
if (!int_table_check(table, 0))
goto end;
@ -220,10 +216,9 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
if (!fnd)
goto end;
if (fnd->funct && engine_unlocked_init(fnd->funct)) {
#ifdef ENGINE_TABLE_DEBUG
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
"ENGINE '%s' cached\n", f, l, nid, fnd->funct->id);
#endif
OSSL_TRACE4(ENGINE_TABLE,
"%s:%d, nid=%d, using ENGINE '%s' cached\n",
f, l, nid, fnd->funct->id);
ret = fnd->funct;
goto end;
}
@ -234,10 +229,10 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
trynext:
ret = sk_ENGINE_value(fnd->sk, loop++);
if (!ret) {
#ifdef ENGINE_TABLE_DEBUG
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
"registered implementations would initialise\n", f, l, nid);
#endif
OSSL_TRACE3(ENGINE_TABLE,
"%s:%d, nid=%d, "
"no registered implementations would initialise\n",
f, l, nid);
goto end;
}
/* Try to initialise the ENGINE? */
@ -252,15 +247,13 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
if (fnd->funct)
engine_unlocked_finish(fnd->funct, 0);
fnd->funct = ret;
#ifdef ENGINE_TABLE_DEBUG
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
"setting default to '%s'\n", f, l, nid, ret->id);
#endif
OSSL_TRACE4(ENGINE_TABLE,
"%s:%d, nid=%d, setting default to '%s'\n",
f, l, nid, ret->id);
}
#ifdef ENGINE_TABLE_DEBUG
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "
"newly initialised '%s'\n", f, l, nid, ret->id);
#endif
OSSL_TRACE4(ENGINE_TABLE,
"%s:%d, nid=%d, using newly initialised '%s'\n",
f, l, nid, ret->id);
goto end;
}
goto trynext;
@ -271,14 +264,14 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,
*/
if (fnd)
fnd->uptodate = 1;
#ifdef ENGINE_TABLE_DEBUG
if (ret)
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
"ENGINE '%s'\n", f, l, nid, ret->id);
OSSL_TRACE4(ENGINE_TABLE,
"%s:%d, nid=%d, caching ENGINE '%s'\n",
f, l, nid, ret->id);
else
fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
"'no matching ENGINE'\n", f, l, nid);
#endif
OSSL_TRACE3(ENGINE_TABLE,
"%s:%d, nid=%d, caching 'no matching ENGINE'\n",
f, l, nid);
CRYPTO_THREAD_unlock(global_engine_lock);
/*
* Whatever happened, any failed init()s are not failures in this

View file

@ -124,6 +124,7 @@ static const struct trace_category_st trace_categories[] = {
TRACE_CATEGORY_(TLS),
TRACE_CATEGORY_(TLS_CIPHER),
TRACE_CATEGORY_(ENGINE_CONF),
TRACE_CATEGORY_(ENGINE_TABLE),
};
const char *OSSL_trace_get_category_name(int num)

View file

@ -37,7 +37,8 @@ extern "C" {
# define OSSL_TRACE_CATEGORY_TLS 2
# define OSSL_TRACE_CATEGORY_TLS_CIPHER 3
# define OSSL_TRACE_CATEGORY_ENGINE_CONF 4
# define OSSL_TRACE_CATEGORY_NUM 5
# define OSSL_TRACE_CATEGORY_ENGINE_TABLE 5
# define OSSL_TRACE_CATEGORY_NUM 6
/* Returns the trace category number for the given |name| */
int OSSL_trace_get_category_num(const char *name);