aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-05-19 00:03:40 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-05-19 00:24:05 -0800
commitb7e020e4f9071239f459930a4796d72d9952d833 (patch)
treeb63177496a4cd6077a1525cb2435fd061fe72ccc /lib
parent32c86dfa0dc5e5f48248f5172390766ff25df5f5 (diff)
downloadtinytac-b7e020e4f9071239f459930a4796d72d9952d833.tar.gz
tinytac-b7e020e4f9071239f459930a4796d72d9952d833.tar.bz2
tinytac-b7e020e4f9071239f459930a4796d72d9952d833.tar.xz
tinytac-b7e020e4f9071239f459930a4796d72d9952d833.zip
libtinytac: adding tinytac_set_option()
Diffstat (limited to 'lib')
-rw-r--r--lib/libtinytac/libtinytac.sym1
-rw-r--r--lib/libtinytac/lmemory.c145
2 files changed, 144 insertions, 2 deletions
diff --git a/lib/libtinytac/libtinytac.sym b/lib/libtinytac/libtinytac.sym
index f396134..262371f 100644
--- a/lib/libtinytac/libtinytac.sym
+++ b/lib/libtinytac/libtinytac.sym
@@ -38,6 +38,7 @@ tinytac_strerror_r
38tinytac_free 38tinytac_free
39tinytac_get_option 39tinytac_get_option
40tinytac_initialize 40tinytac_initialize
41tinytac_set_option
41# 42#
42# network functions 43# network functions
43tinytac_recv 44tinytac_recv
diff --git a/lib/libtinytac/lmemory.c b/lib/libtinytac/lmemory.c
index e8256c3..c9a005f 100644
--- a/lib/libtinytac/lmemory.c
+++ b/lib/libtinytac/lmemory.c
@@ -81,6 +81,19 @@ tinytac_tiytac_free(
81 TinyTac * tt ); 81 TinyTac * tt );
82 82
83 83
84static int
85tinytac_set_option_flag(
86 TinyTac * tt,
87 unsigned flag,
88 const int * invalue );
89
90
91static int
92tinytac_set_option_host(
93 TinyTac * tt,
94 const char * invalue );
95
96
84//-------------------// 97//-------------------//
85// object prototypes // 98// object prototypes //
86//-------------------// 99//-------------------//
@@ -230,6 +243,7 @@ tinytac_initialize(
230 unsigned opts ) 243 unsigned opts )
231{ 244{
232 TinyTac * tt; 245 TinyTac * tt;
246 int rc;
233 247
234 TinyTacDebugTrace(); 248 TinyTacDebugTrace();
235 249
@@ -245,10 +259,10 @@ tinytac_initialize(
245 if (!(tt->opts & TTAC_AUTHEN_TYPES)) 259 if (!(tt->opts & TTAC_AUTHEN_TYPES))
246 tt->opts |= TTAC_AUTHEN_TYPES; 260 tt->opts |= TTAC_AUTHEN_TYPES;
247 261
248 if ((tt->hosts = strdup(hosts)) == NULL) 262 if ((rc = tinytac_set_option(tt, TTAC_OPT_HOSTS, hosts)) != TTAC_SUCCESS)
249 { 263 {
250 tinytac_tiytac_free(tt); 264 tinytac_tiytac_free(tt);
251 return(TTAC_ENOMEM); 265 return(rc);
252 }; 266 };
253 if ((tt->key = strdup(key)) == NULL) 267 if ((tt->key = strdup(key)) == NULL)
254 { 268 {
@@ -262,6 +276,133 @@ tinytac_initialize(
262} 276}
263 277
264 278
279int
280tinytac_set_option(
281 TinyTac * tt,
282 int option,
283 const void * invalue )
284{
285 int ival;
286 const char * istr;
287
288 TinyTacDebugTrace();
289
290 assert(invalue != NULL);
291
292 switch(option)
293 {
294 case TTAC_OPT_AUTHEN_ASCII:
295 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_AUTHEN_ASCII, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
296 return(tinytac_set_option_flag(tt, TTAC_ASCII, invalue));
297
298 case TTAC_OPT_AUTHEN_CHAP:
299 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_AUTHEN_CHAP, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
300 return(tinytac_set_option_flag(tt, TTAC_CHAP, invalue));
301
302 case TTAC_OPT_AUTHEN_MSCHAP:
303 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_AUTHEN_MSCHAP, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
304 return(tinytac_set_option_flag(tt, TTAC_MSCHAP, invalue));
305
306 case TTAC_OPT_AUTHEN_MSCHAPV2:
307 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_AUTHEN_MSCHAPV2, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
308 return(tinytac_set_option_flag(tt, TTAC_MSCHAPV2, invalue));
309
310 case TTAC_OPT_AUTHEN_PAP:
311 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_AUTHEN_PAP, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
312 return(tinytac_set_option_flag(tt, TTAC_PAP, invalue));
313
314 case TTAC_OPT_DEBUG_IDENT:
315 TinyTacDebug( TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_DEBUG_IDENT, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
316 istr = (((const char *)invalue)) ? ((const char *)invalue) : TTAC_DFLT_DEBUG_IDENT;
317 tinytacb_strlcpy(tinytac_debug_ident_buff, istr, sizeof(tinytac_debug_ident_buff));
318 tinytac_debug_ident = tinytac_debug_ident_buff;
319 return(TTAC_SUCCESS);
320
321 case TTAC_OPT_DEBUG_LEVEL:
322 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_DEBUG_LEVEL, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
323 ival = (((const int *)invalue)) ? *((const int *)invalue) : TTAC_DFLT_DEBUG_LEVEL;
324 tinytac_debug_level = ival;
325 return(TTAC_SUCCESS);
326
327 case TTAC_OPT_DEBUG_SYSLOG:
328 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_DEBUG_SYSLOG, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
329 ival = (((const int *)invalue)) ? *((const int *)invalue) : TTAC_DFLT_DEBUG_SYSLOG;
330 tinytac_debug_syslog = ((ival)) ? TTAC_YES : TTAC_NO;
331 return(TTAC_SUCCESS);
332
333 case TTAC_OPT_HOSTS:
334 TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") );
335 return(tinytac_set_option_host(tt, invalue));
336
337 default:
338 break;
339 };
340
341 return(TTAC_EOPTION);
342}
343
344
345int
346tinytac_set_option_flag(
347 TinyTac * tt,
348 unsigned flag,
349 const int * invalue )
350{
351 int ival;
352 int dflt;
353 unsigned * optsp;
354 unsigned * opts_negp;
355
356 TinyTacDebugTrace();
357
358 if (!(flag))
359 return(TTAC_SUCCESS);
360
361 dflt = ((tt)) ? (tinytac_dflt_opts & flag) : (flag & TTAC_DFLT_OPTS);
362 ival = ((invalue)) ? *invalue : dflt;
363 optsp = ((tt)) ? &tt->opts : &tinytac_dflt_opts;
364 opts_negp = ((tt)) ? &tt->opts_neg : &tinytac_dflt_opts_neg;
365
366 if ((ival))
367 {
368 *optsp |= flag;
369 *opts_negp ^= flag;
370 } else {
371 *optsp ^= flag;
372 *opts_negp |= flag;
373 };
374
375 return(TTAC_SUCCESS);
376}
377
378
379int
380tinytac_set_option_host(
381 TinyTac * tt,
382 const char * invalue )
383{
384 char * ostr;
385
386 TinyTacDebugTrace();
387
388 if ((tt))
389 {
390 invalue = ((invalue)) ? invalue : TTAC_DFLT_HOSTS;
391 tinytacb_strlcpy(tinytac_dflt_hosts_buff, invalue, sizeof(tinytac_dflt_hosts_buff));
392 tinytac_dflt_hosts = tinytac_dflt_hosts_buff;
393 return(TTAC_SUCCESS);
394 };
395
396 invalue = ((invalue)) ? invalue : tinytac_dflt_hosts;
397 if ((ostr = tinytacb_strdup(invalue)) == NULL)
398 return(TTAC_ENOMEM);
399 free(tt->hosts);
400 tt->hosts = ostr;
401
402 return(TTAC_SUCCESS);
403}
404
405
265//------------------// 406//------------------//
266// object functions // 407// object functions //
267//------------------// 408//------------------//