diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-05-31 16:27:59 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-05-31 16:27:59 -0800 |
| commit | 3995bcbc64353538fa056c7d552efd771fe0c7f1 (patch) | |
| tree | 50f9930ded8e2f1a796062538f42d2f68a2044ed | |
| parent | 502082565ba0f5bef320ee243b8a1e82093f2ea1 (diff) | |
| download | tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.gz tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.bz2 tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.tar.xz tinytac-3995bcbc64353538fa056c7d552efd771fe0c7f1.zip | |
libtinytac: adding tinytac_defaults()
| -rw-r--r-- | include/tinytac.h | 2 | ||||
| -rw-r--r-- | lib/libtinytac/lconf.c | 5 | ||||
| -rw-r--r-- | lib/libtinytac/lmemory.c | 57 | ||||
| -rw-r--r-- | 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 @@ | |||
| 172 | #define TTAC_DFLT_DEBUG_SYSLOG TTAC_NO | 172 | #define TTAC_DFLT_DEBUG_SYSLOG TTAC_NO |
| 173 | #define TTAC_DFLT_HOSTS "localhost" | 173 | #define TTAC_DFLT_HOSTS "localhost" |
| 174 | #define TTAC_DFLT_SECRETS NULL | 174 | #define TTAC_DFLT_SECRETS NULL |
| 175 | #define TTAC_DFLT_OPTS ( TTAC_RND_URANDOM ) | 175 | #define TTAC_DFLT_OPTS ( TTAC_RND_URANDOM | TTAC_IP_UNSPEC | TTAC_AUTHEN_TYPES ) |
| 176 | #define TTAC_DFLT_OPTS_NEG 0 | 176 | #define TTAC_DFLT_OPTS_NEG 0 |
| 177 | #define TTAC_DFLT_PORT 49 | 177 | #define TTAC_DFLT_PORT 49 |
| 178 | #define TTAC_DFLT_TIMEOUT 10 | 178 | #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 | |||
| 150 | tinytac_conf( | 150 | tinytac_conf( |
| 151 | unsigned opts ) | 151 | unsigned opts ) |
| 152 | { | 152 | { |
| 153 | int rc; | ||
| 153 | const char * tintacrc; | 154 | const char * tintacrc; |
| 154 | const char * tinytacconf; | 155 | const char * tinytacconf; |
| 155 | char buff[4096]; | 156 | char buff[4096]; |
| @@ -174,6 +175,10 @@ tinytac_conf( | |||
| 174 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); | 175 | getpwuid_r(getuid(), &pwd, buff, sizeof(buff), &pwres); |
| 175 | home = (((pwres)) ? pwres->pw_dir : "/"); | 176 | home = (((pwres)) ? pwres->pw_dir : "/"); |
| 176 | 177 | ||
| 178 | // load defaults | ||
| 179 | if ((rc = tinytac_defaults(NULL)) != TTAC_SUCCESS) | ||
| 180 | return(rc); | ||
| 181 | |||
| 177 | // process "/usr/local/etc/tinytac.conf" | 182 | // process "/usr/local/etc/tinytac.conf" |
| 178 | tinytac_conf_file(SYSCONFDIR "/tinytac.conf"); | 183 | tinytac_conf_file(SYSCONFDIR "/tinytac.conf"); |
| 179 | 184 | ||
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 | |||
| @@ -155,6 +155,29 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS; | |||
| 155 | #pragma mark TinyTac functions | 155 | #pragma mark TinyTac functions |
| 156 | 156 | ||
| 157 | int | 157 | int |
| 158 | tinytac_defaults( | ||
| 159 | TinyTac * tt ) | ||
| 160 | { | ||
| 161 | int rc; | ||
| 162 | |||
| 163 | if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_ASCII, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 164 | if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_PAP, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 165 | if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_CHAP, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 166 | if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAP, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 167 | if ((rc = tinytac_set_option(tt, TTAC_OPT_AUTHEN_MSCHAPV2, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 168 | if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 169 | if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV4, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 170 | if ((rc = tinytac_set_option(tt, TTAC_OPT_IPV6, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 171 | if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 172 | if ((rc = tinytac_set_option(tt, TTAC_OPT_NETWORK_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 173 | if ((rc = tinytac_set_option(tt, TTAC_OPT_RANDOM, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 174 | if ((rc = tinytac_set_option(tt, TTAC_OPT_TIMEOUT, NULL)) != TTAC_SUCCESS) return(rc); | ||
| 175 | |||
| 176 | return(TTAC_SUCCESS); | ||
| 177 | } | ||
| 178 | |||
| 179 | |||
| 180 | int | ||
| 158 | tinytac_get_option( | 181 | tinytac_get_option( |
| 159 | TinyTac * tt, | 182 | TinyTac * tt, |
| 160 | int option, | 183 | int option, |
| @@ -168,8 +191,9 @@ tinytac_get_option( | |||
| 168 | 191 | ||
| 169 | assert(outvalue != NULL); | 192 | assert(outvalue != NULL); |
| 170 | 193 | ||
| 171 | if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) | 194 | if (option != TTAC_OPT_NOINIT) |
| 172 | return(rc); | 195 | if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS) |
| 196 | return(rc); | ||
| 173 | 197 | ||
| 174 | // get global options | 198 | // get global options |
| 175 | switch(option) | 199 | switch(option) |
| @@ -271,19 +295,29 @@ tinytac_initialize( | |||
| 271 | 295 | ||
| 272 | assert(ttp != NULL); | 296 | assert(ttp != NULL); |
| 273 | 297 | ||
| 274 | if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) | 298 | if ((rc = tinytac_conf(opts)) != TTAC_SUCCESS) |
| 275 | return(rc); | 299 | return(rc); |
| 276 | 300 | ||
| 277 | if ((tt = tinytac_obj_alloc(sizeof(TinyTac), (void(*)(void*))&tinytac_tinytac_free)) == NULL) | 301 | if ((tt = tinytac_obj_alloc(sizeof(TinyTac), (void(*)(void*))&tinytac_tinytac_free)) == NULL) |
| 278 | return(TTAC_ENOMEM); | 302 | return(TTAC_ENOMEM); |
| 279 | 303 | ||
| 280 | // adjust options | 304 | // apply default options |
| 281 | tt->opts = opts; | 305 | if ((rc = tinytac_defaults(tt)) != TTAC_SUCCESS) |
| 282 | if (!(tt->opts & TTAC_IP_UNSPEC)) | 306 | { |
| 283 | tt->opts |= TTAC_IP_UNSPEC; | 307 | tinytac_tinytac_free(tt); |
| 284 | if (!(tt->opts & TTAC_AUTHEN_TYPES)) | 308 | return(rc); |
| 285 | tt->opts |= TTAC_AUTHEN_TYPES; | 309 | }; |
| 310 | |||
| 311 | // clear default options if overriden by user | ||
| 312 | if ((opts & TTAC_IP_UNSPEC)) | ||
| 313 | tt->opts &= ~TTAC_IP_UNSPEC; | ||
| 314 | if ((opts & TTAC_AUTHEN_TYPES)) | ||
| 315 | tt->opts &= ~TTAC_AUTHEN_TYPES; | ||
| 316 | if ((opts & TTAC_RND_METHODS)) | ||
| 317 | tt->opts &= ~TTAC_RND_METHODS; | ||
| 286 | 318 | ||
| 319 | // apply user options | ||
| 320 | tt->opts |= opts; | ||
| 287 | if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS) | 321 | if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS) |
| 288 | { | 322 | { |
| 289 | tinytac_tinytac_free(tt); | 323 | tinytac_tinytac_free(tt); |
| @@ -317,8 +351,9 @@ tinytac_set_option( | |||
| 317 | 351 | ||
| 318 | assert(invalue != NULL); | 352 | assert(invalue != NULL); |
| 319 | 353 | ||
| 320 | if ((rc = tinytac_conf(0)) != TTAC_SUCCESS) | 354 | if (option != TTAC_OPT_NOINIT) |
| 321 | return(rc); | 355 | if ((rc = tinytac_conf(((tt)) ? tt->opts : 0)) != TTAC_SUCCESS) |
| 356 | return(rc); | ||
| 322 | 357 | ||
| 323 | switch(option) | 358 | switch(option) |
| 324 | { | 359 | { |
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; | |||
| 73 | ////////////////// | 73 | ////////////////// |
| 74 | #pragma mark - Prototypes | 74 | #pragma mark - Prototypes |
| 75 | 75 | ||
| 76 | //--------------------// | ||
| 77 | // TinyTac prototypes // | ||
| 78 | //--------------------// | ||
| 79 | #pragma mark TinyTac prototypes | ||
| 80 | |||
| 81 | int | ||
| 82 | tinytac_defaults( | ||
| 83 | TinyTac * tt ); | ||
| 84 | |||
| 85 | |||
| 76 | //-------------------// | 86 | //-------------------// |
| 77 | // object prototypes // | 87 | // object prototypes // |
| 78 | //-------------------// | 88 | //-------------------// |
