aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-03-23 22:25:31 -0800
committerDavid M. Syzdek <david@syzdek.net>2022-03-23 22:25:31 -0800
commitdd971552b9c26d3221e3b650938de0bdc26f5a2a (patch)
tree3fa08db2bd0deb9c531060e9dcaed60278863c19
parent0ee24b7cf0bcf50bf720911d27e29e31f00c3214 (diff)
downloadtinyrad-dd971552b9c26d3221e3b650938de0bdc26f5a2a.tar.gz
tinyrad-dd971552b9c26d3221e3b650938de0bdc26f5a2a.tar.bz2
tinyrad-dd971552b9c26d3221e3b650938de0bdc26f5a2a.tar.xz
tinyrad-dd971552b9c26d3221e3b650938de0bdc26f5a2a.zip
libtinyrad: adding tinyrad_conf_print()
-rw-r--r--include/tinyrad.h13
-rw-r--r--lib/libtinyrad/lconf.c171
-rw-r--r--lib/libtinyrad/libtinyrad.sym3
3 files changed, 186 insertions, 1 deletions
diff --git a/include/tinyrad.h b/include/tinyrad.h
index e55bef5..8452a90 100644
--- a/include/tinyrad.h
+++ b/include/tinyrad.h
@@ -191,7 +191,7 @@
191#define TRAD_CATHOLIC 0x00000010U 191#define TRAD_CATHOLIC 0x00000010U
192#define TRAD_SERVER 0x00000020U 192#define TRAD_SERVER 0x00000020U
193#define TRAD_RAND 0x00000040U 193#define TRAD_RAND 0x00000040U
194#define TRAD_URANDOM 0x00000100U 194#define TRAD_URANDOM 0x00000080U
195#define TRAD_RANDOM (TRAD_RAND | TRAD_URANDOM) 195#define TRAD_RANDOM (TRAD_RAND | TRAD_URANDOM)
196#define TRAD_RANDOM_MASK (TRAD_RAND | TRAD_URANDOM) 196#define TRAD_RANDOM_MASK (TRAD_RAND | TRAD_URANDOM)
197 197
@@ -513,6 +513,17 @@ typedef struct tinyrad_url_desc
513////////////////// 513//////////////////
514#pragma mark - Prototypes 514#pragma mark - Prototypes
515 515
516//-----------------//
517// conf prototypes //
518//-----------------//
519#pragma mark conf prototypes
520
521void
522tinyrad_conf_print(
523 TinyRad * tr,
524 TinyRadDict * dict );
525
526
516//------------------// 527//------------------//
517// debug prototypes // 528// debug prototypes //
518//------------------// 529//------------------//
diff --git a/lib/libtinyrad/lconf.c b/lib/libtinyrad/lconf.c
index b78ce7f..4c76885 100644
--- a/lib/libtinyrad/lconf.c
+++ b/lib/libtinyrad/lconf.c
@@ -150,6 +150,41 @@ tinyrad_conf_opt_bool(
150 const char * value ); 150 const char * value );
151 151
152 152
153void
154tinyrad_conf_print_bool(
155 int comment,
156 const char * name,
157 int value );
158
159
160void
161tinyrad_conf_print_hex(
162 int comment,
163 const char * name,
164 unsigned value );
165
166
167void
168tinyrad_conf_print_int(
169 int comment,
170 const char * name,
171 int value);
172
173
174void
175tinyrad_conf_print_line(
176 int comment,
177 const char * name,
178 const char * value );
179
180
181void
182tinyrad_conf_print_str(
183 int comment,
184 const char * name,
185 const char * str );
186
187
153///////////////// 188/////////////////
154// // 189// //
155// Functions // 190// Functions //
@@ -510,4 +545,140 @@ tinyrad_conf_opt_bool(
510 return(TRAD_SUCCESS); 545 return(TRAD_SUCCESS);
511} 546}
512 547
548
549void
550tinyrad_conf_print(
551 TinyRad * tr,
552 TinyRadDict * dict )
553{
554 size_t pos;
555 char * str;
556 char buff[TRAD_LINE_MAX_LEN];
557
558 if ((tr))
559 {
560 printf("# TinyRad Library Configuration:\n");
561 if ((tinyrad_get_option(tr, TRAD_OPT_URI, &str)) == TRAD_SUCCESS)
562 {
563 printf("%-20s '%s'\n", "URI", str);
564 tinyrad_free(str);
565 };
566 if ((tinyrad_get_option(tr, TRAD_OPT_SOCKET_BIND_ADDRESSES, &str)) == TRAD_SUCCESS)
567 {
568 printf("%-20s '%s'\n", "BIND_ADDRESS:", str);
569 tinyrad_free(str);
570 };
571 if ( (!(tr->opts & TRAD_IPV4)) && (!(tr->opts & TRAD_IPV6)) )
572 {
573 tinyrad_conf_print_bool( 1, "IPV4", TRAD_YES );
574 tinyrad_conf_print_bool( 1, "IPV6", TRAD_YES );
575 } else {
576 tinyrad_conf_print_bool( 0, "IPV4", ((tr->opts & TRAD_IPV4)) );
577 tinyrad_conf_print_bool( 0, "IPV6", ((tr->opts & TRAD_IPV6)) );
578 };
579 tinyrad_conf_print_str( 0, "SECRET_FILE", tr->secret_file);
580 tinyrad_conf_print_str( (tr->secret_file != NULL), "SECRET", tr->secret);
581 tinyrad_conf_print_int( 0, "NETWORK_TIMEOUT", (int)(((tr->net_timeout)) ? tr->net_timeout->tv_sec : 0));
582 tinyrad_conf_print_int( 0, "TIMEOUT", (int)tr->timeout);
583 tinyrad_conf_print_hex( 1, "authenticator", tr->authenticator);
584 switch(tr->opts & TRAD_RANDOM_MASK)
585 { case TRAD_RAND: tinyrad_conf_print_line( 0, "RANDOM", "rand"); break;
586 case TRAD_RANDOM: tinyrad_conf_print_line( 0, "RANDOM", "random"); break;
587 case TRAD_URANDOM: tinyrad_conf_print_line( 0, "RANDOM", "urandom"); break;
588 default: tinyrad_conf_print_int( 0, "RANDOM", (tr->opts | TRAD_RANDOM_MASK)); break;
589 };
590 printf("\n");
591 };
592
593 if ((dict))
594 {
595 printf("# TinyRad Dictionary Configuration:\n");
596 tinyrad_conf_print_bool( 0, "BUILTIN_DICTIONARY", ((dict->opts & TRAD_BUILTIN_DICT)) );
597 tinyrad_conf_print_str( (dict->default_dictfile == NULL), "DICTIONARY", dict->default_dictfile );
598 tinyrad_conf_print_bool( 1, "IPV4", TRAD_YES );
599 if ( ((dict->paths)) && ((dict->paths[0])) )
600 {
601 buff[0] = '\0';
602 for(pos = 0; ((dict->paths[pos])); pos++)
603 {
604 if (!(dict->paths[pos][0]))
605 continue;
606 if ((buff[0]))
607 tinyrad_strlcat(buff, ":", sizeof(buff));
608 tinyrad_strlcat(buff, dict->paths[pos], sizeof(buff));
609 };
610 tinyrad_conf_print_str( 0, "PATHS", buff );
611 };
612 printf("\n");
613 };
614
615 printf("STOPINIT\n\n");
616
617 return;
618}
619
620
621void
622tinyrad_conf_print_bool(
623 int comment,
624 const char * name,
625 int value)
626{
627 tinyrad_conf_print_line(comment, name, (((value)) ? "yes" : "no"));
628 return;
629}
630
631
632void
633tinyrad_conf_print_hex(
634 int comment,
635 const char * name,
636 unsigned value )
637{
638 char buff[9];
639 snprintf(buff, sizeof(buff), "%08x", value);;
640 tinyrad_conf_print_line(comment, name, buff);
641 return;
642}
643
644
645void
646tinyrad_conf_print_int(
647 int comment,
648 const char * name,
649 int value )
650{
651 char buff[32];
652 snprintf(buff, sizeof(buff), "%i", value);;
653 tinyrad_conf_print_line(comment, name, buff);
654 return;
655}
656
657
658void
659tinyrad_conf_print_line(
660 int comment,
661 const char * name,
662 const char * value )
663{
664 printf("%s%-20s %s\n", (((comment)) ? "#" : ""), name, value);
665 return;
666}
667
668
669void
670tinyrad_conf_print_str(
671 int comment,
672 const char * name,
673 const char * value )
674{
675 char buff[TRAD_LINE_MAX_LEN];
676 if (!(value))
677 return;
678 snprintf(buff, sizeof(buff), "'%s'", value);
679 tinyrad_conf_print_line(comment, name, buff);
680 return;
681}
682
683
513/* end of source */ 684/* end of source */
diff --git a/lib/libtinyrad/libtinyrad.sym b/lib/libtinyrad/libtinyrad.sym
index 9fe6e9e..e445804 100644
--- a/lib/libtinyrad/libtinyrad.sym
+++ b/lib/libtinyrad/libtinyrad.sym
@@ -41,6 +41,9 @@ tinyrad_array_push
41tinyrad_array_remove 41tinyrad_array_remove
42tinyrad_array_search 42tinyrad_array_search
43# 43#
44# conf functions
45tinyrad_conf_print
46#
44# data variables 47# data variables
45tinyrad_dict_default_vendors 48tinyrad_dict_default_vendors
46tinyrad_dict_default_attrs 49tinyrad_dict_default_attrs