diff options
Diffstat (limited to 'lib/libtinyrad/lconf.c')
| -rw-r--r-- | lib/libtinyrad/lconf.c | 171 |
1 files changed, 171 insertions, 0 deletions
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 | ||
| 153 | void | ||
| 154 | tinyrad_conf_print_bool( | ||
| 155 | int comment, | ||
| 156 | const char * name, | ||
| 157 | int value ); | ||
| 158 | |||
| 159 | |||
| 160 | void | ||
| 161 | tinyrad_conf_print_hex( | ||
| 162 | int comment, | ||
| 163 | const char * name, | ||
| 164 | unsigned value ); | ||
| 165 | |||
| 166 | |||
| 167 | void | ||
| 168 | tinyrad_conf_print_int( | ||
| 169 | int comment, | ||
| 170 | const char * name, | ||
| 171 | int value); | ||
| 172 | |||
| 173 | |||
| 174 | void | ||
| 175 | tinyrad_conf_print_line( | ||
| 176 | int comment, | ||
| 177 | const char * name, | ||
| 178 | const char * value ); | ||
| 179 | |||
| 180 | |||
| 181 | void | ||
| 182 | tinyrad_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 | |||
| 549 | void | ||
| 550 | tinyrad_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 | |||
| 621 | void | ||
| 622 | tinyrad_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 | |||
| 632 | void | ||
| 633 | tinyrad_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 | |||
| 645 | void | ||
| 646 | tinyrad_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 | |||
| 658 | void | ||
| 659 | tinyrad_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 | |||
| 669 | void | ||
| 670 | tinyrad_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 */ |
