From 40ee5f3f4065bc4fdb16fc48c74a1ffdea64f982 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 15 Jan 2019 20:44:37 -0200 Subject: [PATCH] Adding host & crl default settings. --- configure.ac | 4 ++++ src/include/config.h.in | 6 ++++++ src/lib3270/host.c | 34 +++++++++++++++++++++++++++------- src/lib3270/session.c | 8 -------- src/lib3270/ssl/linux/getcrl.c | 19 +++++++++++++++++++ src/lib3270/testprogram/testprogram.c | 8 +++++--- 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 28db2c3..5832eda 100644 --- a/configure.ac +++ b/configure.ac @@ -344,6 +344,8 @@ if test "$app_cv_self_signed_certs" == "yes"; then AC_DEFINE(SSL_ENABLE_CRL_CHECK) fi +AC_ARG_WITH([default-crl], [AS_HELP_STRING([--with-default-crl], [Set lib3270 default crl url])], [ AC_DEFINE_UNQUOTED(LIB3270_DEFAULT_CRL,"$withval") ],[ AC_MSG_NOTICE(No default crl)]) + dnl --------------------------------------------------------------------------- dnl Check for pic dnl --------------------------------------------------------------------------- @@ -387,6 +389,8 @@ AC_ARG_WITH([sdk-version], [AS_HELP_STRING([--with-sdk-version], [Setup library AC_DEFINE(LIB3270_SDK_VERSION,$app_cv_sdkversion) AC_SUBST(LIB3270_SDK_VERSION,$app_cv_sdkversion) +AC_ARG_WITH([default-host], [AS_HELP_STRING([--with-default-host], [Set lib3270 default host url])], [ AC_DEFINE_UNQUOTED(LIB3270_DEFAULT_HOST,"$withval") ],[ AC_MSG_NOTICE(No default host)]) + dnl --------------------------------------------------------------------------- dnl Check for headers dnl --------------------------------------------------------------------------- diff --git a/src/include/config.h.in b/src/include/config.h.in index 01b8578..caa2dbe 100644 --- a/src/include/config.h.in +++ b/src/include/config.h.in @@ -31,10 +31,15 @@ #define LIB3270_CONFIG_INCLUDED 1 + /* Version info */ #undef PACKAGE_NAME #undef PACKAGE_VERSION #undef PACKAGE_RELEASE + /* Defaults */ + #undef LIB3270_DEFAULT_HOST + + /* Libraries */ #undef HAVE_GNUC_VISIBILITY #undef HAVE_LIBINTL #undef HAVE_GETADDRINFO @@ -50,6 +55,7 @@ #undef HAVE_LIBSSL #undef SSL_ALLOW_SELF_SIGNED_CERT #undef SSL_ENABLE_CRL_CHECK + #undef LIB3270_DEFAULT_CRL /* Windows Options */ #ifdef WIN32 diff --git a/src/lib3270/host.c b/src/lib3270/host.c index 20faf9c..eec0bc9 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -232,12 +232,6 @@ static void update_host(H3270 *h) } -LIB3270_EXPORT const char * lib3270_get_url(H3270 *hSession) -{ - CHECK_SESSION_HANDLE(hSession); - return hSession->host.full; -} - LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname) { FAIL_IF_ONLINE(hSession); @@ -245,11 +239,37 @@ LIB3270_EXPORT int lib3270_set_luname(H3270 *hSession, const char *luname) return 0; } +LIB3270_EXPORT const char * lib3270_get_url(H3270 *hSession) +{ + CHECK_SESSION_HANDLE(hSession); + + if(hSession->host.full) + return hSession->host.full; + +#ifdef LIB3270_DEFAULT_HOST + return LIB3270_DEFAULT_HOST; +#else + return getenv("LIB3270_DEFAULT_HOST"); +#endif // LIB3270_DEFAULT_HOST + +} + LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) { FAIL_IF_ONLINE(h); - if(n && n != h->host.full) + if(!n) + { +#ifdef LIB3270_DEFAULT_HOST + n = LIB3270_DEFAULT_HOST; +#else + n = getenv("LIB3270_DEFAULT_HOST"); + if(!n) + return errno = EINVAL; +#endif // LIB3270_DEFAULT_HOST + } + + if(!h->host.full || strcmp(n,h->host.full)) { static const struct _sch { diff --git a/src/lib3270/session.c b/src/lib3270/session.c index b691441..b748836 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -320,14 +320,6 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char hSession->unlock_delay_ms = 350; // 0.35s after last unlock hSession->pointer = (unsigned short) LIB3270_POINTER_LOCKED; -#ifdef SSL_ENABLE_CRL_CHECK - char *env = getenv("LIB3270_DEFAULT_CRL"); - if(env) - { - hSession->ssl.crl = strdup(env); - } -#endif // SSL_ENABLE_CRL_CHECK - // CSD for(f=0;f<4;f++) hSession->csd[f] = hSession->saved_csd[f] = LIB3270_ANSI_CSD_US; diff --git a/src/lib3270/ssl/linux/getcrl.c b/src/lib3270/ssl/linux/getcrl.c index 810b787..e9d4e16 100644 --- a/src/lib3270/ssl/linux/getcrl.c +++ b/src/lib3270/ssl/linux/getcrl.c @@ -47,6 +47,7 @@ #endif // HAVE_LDAP #include "../../private.h" +#include #include #include @@ -97,6 +98,24 @@ X509_CRL * lib3270_get_X509_CRL(H3270 *hSession, SSL_ERROR_MESSAGE * message) { X509_CRL * crl = NULL; + if(!hSession->ssl.crl) + { +#ifdef LIB3270_DEFAULT_CRL + hSession->ssl.crl = strdup(LIB3270_DEFAULT_CRL); +#else + char *env = getenv("LIB3270_DEFAULT_CRL"); + if(env) + hSession->ssl.crl = strdup(env); +#endif // LIB3270_DEFAULT_CRL + } + + if(!hSession->ssl.crl) + { + return NULL; + } + + trace_ssl(hSession, "crl=%s",hSession->ssl.crl); + if(strncasecmp(hSession->ssl.crl,"file://",7) == 0) { lib3270_autoptr(FILE) hCRL = fopen(hSession->ssl.crl+7,"r"); diff --git a/src/lib3270/testprogram/testprogram.c b/src/lib3270/testprogram/testprogram.c index 8d5069c..ee9970a 100644 --- a/src/lib3270/testprogram/testprogram.c +++ b/src/lib3270/testprogram/testprogram.c @@ -11,16 +11,18 @@ int main(int numpar, char *param[]) { H3270 * h; int rc = 0; - const char * url = getenv("LIB3270_DEFAULT_HOST"); - h = lib3270_session_new(""); printf("3270 session %p created\n]",h); + // lib3270_set_url(h,url ? url : "tn3270://fandezhi.efglobe.com"); + + if(lib3270_set_url(h,NULL)) + lib3270_set_url(h,"tn3270://fandezhi.efglobe.com"); + // lib3270_set_toggle(h,LIB3270_TOGGLE_DS_TRACE,1); lib3270_set_toggle(h,LIB3270_TOGGLE_SSL_TRACE,1); - lib3270_set_url(h,url ? url : "tn3270://fandezhi.efglobe.com"); rc = lib3270_connect(h,120); printf("\nConnect %s exits with rc=%d\n",lib3270_get_url(h),rc); -- libgit2 0.21.2