From 8bff70c4b90a552a5179ed00d053b34d97998b1d Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Thu, 19 May 2022 02:57:19 -0800 Subject: libtinytac: adding tinytac_set_option_keys() --- include/tinytac.h | 3 ++- lib/libtinytac/libtinytac.h | 2 +- lib/libtinytac/lmemory.c | 62 ++++++++++++++++++++++++++++++++++++++++++--- lib/libtinytac/lmemory.h | 1 + 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/include/tinytac.h b/include/tinytac.h index 05987c5..3cd9848 100644 --- a/include/tinytac.h +++ b/include/tinytac.h @@ -135,7 +135,8 @@ #define TTAC_OPT_DEBUG_IDENT 2 #define TTAC_OPT_DEBUG_SYSLOG 3 #define TTAC_OPT_HOSTS 10 -#define TTAC_OPT_SECRETS 11 +#define TTAC_OPT_KEY 11 +#define TTAC_OPT_KEYS 12 #define TTAC_OPT_AUTHEN_ASCII 20 #define TTAC_OPT_AUTHEN_PAP 21 #define TTAC_OPT_AUTHEN_CHAP 22 diff --git a/lib/libtinytac/libtinytac.h b/lib/libtinytac/libtinytac.h index 3fb78ef..fef6a01 100644 --- a/lib/libtinytac/libtinytac.h +++ b/lib/libtinytac/libtinytac.h @@ -111,7 +111,7 @@ struct _tinytac { TinyTacObj obj; char * hosts; - char * key; + char ** keys; unsigned opts; unsigned opts_neg; }; diff --git a/lib/libtinytac/lmemory.c b/lib/libtinytac/lmemory.c index c9a005f..0664d12 100644 --- a/lib/libtinytac/lmemory.c +++ b/lib/libtinytac/lmemory.c @@ -94,6 +94,13 @@ tinytac_set_option_host( const char * invalue ); +static int +tinytac_set_option_keys( + TinyTac * tt, + const char * invalue, + char * const * invalues ); + + //-------------------// // object prototypes // //-------------------// @@ -115,6 +122,7 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS; char tinytac_dflt_hosts_buff[128]; unsigned tinytac_dflt_opts = TTAC_DFLT_OPTS; unsigned tinytac_dflt_opts_neg = TTAC_DFLT_OPTS_NEG; +char ** tinytac_dflt_keys = NULL; ///////////////// @@ -139,8 +147,8 @@ tinytac_tiytac_free( if ((tt->hosts)) free(tt->hosts); - if ((tt->key)) - free(tt->key); + if ((tt->keys)) + tinytacb_strsfree(tt->keys); memset(tt, 0, sizeof(TinyTac)); free(tt); @@ -264,10 +272,10 @@ tinytac_initialize( tinytac_tiytac_free(tt); return(rc); }; - if ((tt->key = strdup(key)) == NULL) + if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, key)) != TTAC_SUCCESS) { tinytac_tiytac_free(tt); - return(TTAC_ENOMEM); + return(rc); }; *ttp = tinytac_obj_retain(&tt->obj); @@ -334,6 +342,14 @@ tinytac_set_option( TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); return(tinytac_set_option_host(tt, invalue)); + case TTAC_OPT_KEY: + TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEY, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); + return(tinytac_set_option_keys(tt, invalue, NULL)); + + case TTAC_OPT_KEYS: + TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEYS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); + return(tinytac_set_option_keys(tt, NULL, invalue)); + default: break; }; @@ -403,6 +419,44 @@ tinytac_set_option_host( } +int +tinytac_set_option_keys( + TinyTac * tt, + const char * invalue, + char * const * invalues ) +{ + char *** strsp; + char ** strs; + + TinyTacDebugTrace(); + + strs = NULL; + strsp = ((tt)) ? &tt->keys : &tinytac_dflt_keys; + + if ((invalue)) + { + if (tinytacb_strsadd(&strs, invalue) != 0) + return(TTAC_ENOMEM); + } + else if ((invalues)) + { + if (tinytacb_strsdup(&strs, invalues) != 0) + return(TTAC_ENOMEM); + } + else if ((tt)) + { + if ((tinytac_dflt_keys)) + if (tinytacb_strsdup(&strs, tinytac_dflt_keys) != 0) + return(TTAC_ENOMEM); + }; + + tinytacb_strsfree(*strsp); + *strsp = strs; + + return(TTAC_SUCCESS); +} + + //------------------// // object functions // //------------------// diff --git a/lib/libtinytac/lmemory.h b/lib/libtinytac/lmemory.h index a3be724..150c69f 100644 --- a/lib/libtinytac/lmemory.h +++ b/lib/libtinytac/lmemory.h @@ -66,6 +66,7 @@ extern const char * tinytac_dflt_hosts; extern char tinytac_dflt_hosts_buff[128]; extern unsigned tinytac_dflt_opts; extern unsigned tinytac_dflt_opts_neg; +extern char ** tinytac_dflt_keys; ////////////////// -- cgit v1.2.3