From 3995bcbc64353538fa056c7d552efd771fe0c7f1 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Tue, 31 May 2022 16:27:59 -0800 Subject: libtinytac: adding tinytac_defaults() --- include/tinytac.h | 2 +- lib/libtinytac/lconf.c | 5 +++++ lib/libtinytac/lmemory.c | 57 ++++++++++++++++++++++++++++++++++++++---------- lib/libtinytac/lmemory.h | 10 +++++++++ 4 files changed, 62 insertions(+), 12 deletions(-) diff --git a/include/tinytac.h b/include/tinytac.h index ccb4121..2383554 100644 --- a/include/tinytac.h +++ b/include/tinytac.h @@ -172,7 +172,7 @@ #define TTAC_DFLT_DEBUG_SYSLOG TTAC_NO #define TTAC_DFLT_HOSTS "localhost" #define TTAC_DFLT_SECRETS NULL -#define TTAC_DFLT_OPTS ( TTAC_RND_URANDOM ) +#define TTAC_DFLT_OPTS ( TTAC_RND_URANDOM | TTAC_IP_UNSPEC | TTAC_AUTHEN_TYPES ) #define TTAC_DFLT_OPTS_NEG 0 #define TTAC_DFLT_PORT 49 #define TTAC_DFLT_TIMEOUT 10 diff --git a/lib/libtinytac/lconf.c b/lib/libtinytac/lconf.c index e3aa339..4558b73 100644 --- a/lib/libtinytac/lconf.c +++ b/lib/libtinytac/lconf.c @@ -150,6 +150,7 @@ int tinytac_conf( unsigned opts ) { + int rc; const char * tintacrc; const char * tinytacconf; char buff[4096]; @@ -174,6 +175,10 @@ tinytac_conf( getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); home = (((pwres)) ? pwres->pw_dir : "/"); + // load defaults + if ((rc = tinytac_defaults(NULL)) != TTAC_SUCCESS) + return(rc); + // process "/usr/local/etc/tinytac.conf" tinytac_conf_file(SYSCONFDIR "/tinytac.conf"); diff --git a/lib/libtinytac/lmemory.c b/lib/libtinytac/lmemory.c index 8f35104..4d5a08a 100644 --- a/lib/libtinytac/lmemory.c +++ b/lib/libtinytac/lmemory.c @@ -154,6 +154,29 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS; //-------------------// #pragma mark TinyTac functions +int +tinytac_defaults( + TinyTac * tt ) +{ + int rc; + + if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_ASCII, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_PAP, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_CHAP, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAP, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAPV2, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV4, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV6, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_NETWORK_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_RANDOM, NULL)) != TTAC_SUCCESS) return(rc); + if ((rc = tinytac_set_option(tt, TTAC_OPT_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc); + + return(TTAC_SUCCESS); +} + + int tinytac_get_option( TinyTac * tt, @@ -168,8 +191,9 @@ tinytac_get_option( assert(outvalue != NULL); - if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) - return(rc); + if (option != TTAC_OPT_NOINIT) + if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS) + return(rc); // get global options switch(option) @@ -271,19 +295,29 @@ tinytac_initialize( assert(ttp != NULL); - if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) + if ((rc = tinytac_conf(opts)) != TTAC_SUCCESS) return(rc); if ((tt = tinytac_obj_alloc(sizeof(TinyTac), (void(*)(void*))&tinytac_tinytac_free)) == NULL) return(TTAC_ENOMEM); - // adjust options - tt->opts = opts; - if (!(tt->opts & TTAC_IP_UNSPEC)) - tt->opts |= TTAC_IP_UNSPEC; - if (!(tt->opts & TTAC_AUTHEN_TYPES)) - tt->opts |= TTAC_AUTHEN_TYPES; + // apply default options + if ((rc = tinytac_defaults(tt)) != TTAC_SUCCESS) + { + tinytac_tinytac_free(tt); + return(rc); + }; + + // clear default options if overriden by user + if ((opts & TTAC_IP_UNSPEC)) + tt->opts &= ~TTAC_IP_UNSPEC; + if ((opts & TTAC_AUTHEN_TYPES)) + tt->opts &= ~TTAC_AUTHEN_TYPES; + if ((opts & TTAC_RND_METHODS)) + tt->opts &= ~TTAC_RND_METHODS; + // apply user options + tt->opts |= opts; if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS) { tinytac_tinytac_free(tt); @@ -317,8 +351,9 @@ tinytac_set_option( assert(invalue != NULL); - if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) - return(rc); + if (option != TTAC_OPT_NOINIT) + if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS) + return(rc); switch(option) { diff --git a/lib/libtinytac/lmemory.h b/lib/libtinytac/lmemory.h index a908711..1d4934b 100644 --- a/lib/libtinytac/lmemory.h +++ b/lib/libtinytac/lmemory.h @@ -73,6 +73,16 @@ extern const char * tinytac_dflt_hosts; ////////////////// #pragma mark - Prototypes +//--------------------// +// TinyTac prototypes // +//--------------------// +#pragma mark TinyTac prototypes + +int +tinytac_defaults( + TinyTac * tt ); + + //-------------------// // object prototypes // //-------------------// -- cgit v1.2.3