aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-05-19 02:57:19 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-05-19 02:57:19 -0800
commit8bff70c4b90a552a5179ed00d053b34d97998b1d (patch)
treec16242d46bd1dd0011def796b158378f767c6c39
parentb7e020e4f9071239f459930a4796d72d9952d833 (diff)
downloadtinytac-8bff70c4b90a552a5179ed00d053b34d97998b1d.tar.gz
tinytac-8bff70c4b90a552a5179ed00d053b34d97998b1d.tar.bz2
tinytac-8bff70c4b90a552a5179ed00d053b34d97998b1d.tar.xz
tinytac-8bff70c4b90a552a5179ed00d053b34d97998b1d.zip
libtinytac: adding tinytac_set_option_keys()
-rw-r--r--include/tinytac.h3
-rw-r--r--lib/libtinytac/libtinytac.h2
-rw-r--r--lib/libtinytac/lmemory.c62
-rw-r--r--lib/libtinytac/lmemory.h1
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 @@
135#define TTAC_OPT_DEBUG_IDENT 2 135#define TTAC_OPT_DEBUG_IDENT 2
136#define TTAC_OPT_DEBUG_SYSLOG 3 136#define TTAC_OPT_DEBUG_SYSLOG 3
137#define TTAC_OPT_HOSTS 10 137#define TTAC_OPT_HOSTS 10
138#define TTAC_OPT_SECRETS 11 138#define TTAC_OPT_KEY 11
139#define TTAC_OPT_KEYS 12
139#define TTAC_OPT_AUTHEN_ASCII 20 140#define TTAC_OPT_AUTHEN_ASCII 20
140#define TTAC_OPT_AUTHEN_PAP 21 141#define TTAC_OPT_AUTHEN_PAP 21
141#define TTAC_OPT_AUTHEN_CHAP 22 142#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
111{ 111{
112 TinyTacObj obj; 112 TinyTacObj obj;
113 char * hosts; 113 char * hosts;
114 char * key; 114 char ** keys;
115 unsigned opts; 115 unsigned opts;
116 unsigned opts_neg; 116 unsigned opts_neg;
117}; 117};
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(
94 const char * invalue ); 94 const char * invalue );
95 95
96 96
97static int
98tinytac_set_option_keys(
99 TinyTac * tt,
100 const char * invalue,
101 char * const * invalues );
102
103
97//-------------------// 104//-------------------//
98// object prototypes // 105// object prototypes //
99//-------------------// 106//-------------------//
@@ -115,6 +122,7 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS;
115char tinytac_dflt_hosts_buff[128]; 122char tinytac_dflt_hosts_buff[128];
116unsigned tinytac_dflt_opts = TTAC_DFLT_OPTS; 123unsigned tinytac_dflt_opts = TTAC_DFLT_OPTS;
117unsigned tinytac_dflt_opts_neg = TTAC_DFLT_OPTS_NEG; 124unsigned tinytac_dflt_opts_neg = TTAC_DFLT_OPTS_NEG;
125char ** tinytac_dflt_keys = NULL;
118 126
119 127
120///////////////// 128/////////////////
@@ -139,8 +147,8 @@ tinytac_tiytac_free(
139 147
140 if ((tt->hosts)) 148 if ((tt->hosts))
141 free(tt->hosts); 149 free(tt->hosts);
142 if ((tt->key)) 150 if ((tt->keys))
143 free(tt->key); 151 tinytacb_strsfree(tt->keys);
144 152
145 memset(tt, 0, sizeof(TinyTac)); 153 memset(tt, 0, sizeof(TinyTac));
146 free(tt); 154 free(tt);
@@ -264,10 +272,10 @@ tinytac_initialize(
264 tinytac_tiytac_free(tt); 272 tinytac_tiytac_free(tt);
265 return(rc); 273 return(rc);
266 }; 274 };
267 if ((tt->key = strdup(key)) == NULL) 275 if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, key)) != TTAC_SUCCESS)
268 { 276 {
269 tinytac_tiytac_free(tt); 277 tinytac_tiytac_free(tt);
270 return(TTAC_ENOMEM); 278 return(rc);
271 }; 279 };
272 280
273 *ttp = tinytac_obj_retain(&tt->obj); 281 *ttp = tinytac_obj_retain(&tt->obj);
@@ -334,6 +342,14 @@ tinytac_set_option(
334 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); 342 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
335 return(tinytac_set_option_host(tt, invalue)); 343 return(tinytac_set_option_host(tt, invalue));
336 344
345 case TTAC_OPT_KEY:
346 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEY, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
347 return(tinytac_set_option_keys(tt, invalue, NULL));
348
349 case TTAC_OPT_KEYS:
350 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEYS, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
351 return(tinytac_set_option_keys(tt, NULL, invalue));
352
337 default: 353 default:
338 break; 354 break;
339 }; 355 };
@@ -403,6 +419,44 @@ tinytac_set_option_host(
403} 419}
404 420
405 421
422int
423tinytac_set_option_keys(
424 TinyTac * tt,
425 const char * invalue,
426 char * const * invalues )
427{
428 char *** strsp;
429 char ** strs;
430
431 TinyTacDebugTrace();
432
433 strs = NULL;
434 strsp = ((tt)) ? &tt->keys : &tinytac_dflt_keys;
435
436 if ((invalue))
437 {
438 if (tinytacb_strsadd(&strs, invalue) != 0)
439 return(TTAC_ENOMEM);
440 }
441 else if ((invalues))
442 {
443 if (tinytacb_strsdup(&strs, invalues) != 0)
444 return(TTAC_ENOMEM);
445 }
446 else if ((tt))
447 {
448 if ((tinytac_dflt_keys))
449 if (tinytacb_strsdup(&strs, tinytac_dflt_keys) != 0)
450 return(TTAC_ENOMEM);
451 };
452
453 tinytacb_strsfree(*strsp);
454 *strsp = strs;
455
456 return(TTAC_SUCCESS);
457}
458
459
406//------------------// 460//------------------//
407// object functions // 461// object functions //
408//------------------// 462//------------------//
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;
66extern char tinytac_dflt_hosts_buff[128]; 66extern char tinytac_dflt_hosts_buff[128];
67extern unsigned tinytac_dflt_opts; 67extern unsigned tinytac_dflt_opts;
68extern unsigned tinytac_dflt_opts_neg; 68extern unsigned tinytac_dflt_opts_neg;
69extern char ** tinytac_dflt_keys;
69 70
70 71
71////////////////// 72//////////////////