diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-03-28 15:12:51 -0800 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-03-28 15:12:51 -0800 |
| commit | 60fb5e48847fabd9969c127a481a8fb733e9098e (patch) | |
| tree | 5e29c2926706304b52447c97ac1a90f068bf597c /src | |
| parent | 2f52bb953f654393aaad2dd65c7fa338d0b7ec36 (diff) | |
| download | tinyrad-60fb5e48847fabd9969c127a481a8fb733e9098e.tar.gz tinyrad-60fb5e48847fabd9969c127a481a8fb733e9098e.tar.bz2 tinyrad-60fb5e48847fabd9969c127a481a8fb733e9098e.tar.xz tinyrad-60fb5e48847fabd9969c127a481a8fb733e9098e.zip | |
tinyrad-url: removing utility
Diffstat (limited to 'src')
| -rw-r--r-- | src/tinyrad-url.c | 316 |
1 files changed, 0 insertions, 316 deletions
diff --git a/src/tinyrad-url.c b/src/tinyrad-url.c deleted file mode 100644 index 00d432a..0000000 --- a/src/tinyrad-url.c +++ /dev/null | |||
| @@ -1,316 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Tiny RADIUS Client Library | ||
| 3 | * Copyright (C) 2021 David M. Syzdek <david@syzdek.net>. | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * * Neither the name of David M. Syzdek nor the | ||
| 16 | * names of its contributors may be used to endorse or promote products | ||
| 17 | * derived from this software without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR | ||
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | #define _SRC_UTILITIES_TINYRAD_URL_C 1 | ||
| 32 | |||
| 33 | |||
| 34 | /////////////// | ||
| 35 | // // | ||
| 36 | // Headers // | ||
| 37 | // // | ||
| 38 | /////////////// | ||
| 39 | #pragma mark - Headers | ||
| 40 | |||
| 41 | #include <tinyrad_utils.h> | ||
| 42 | |||
| 43 | #include <stdio.h> | ||
| 44 | #include <stdarg.h> | ||
| 45 | #include <stdlib.h> | ||
| 46 | #include <string.h> | ||
| 47 | #include <strings.h> | ||
| 48 | #include <unistd.h> | ||
| 49 | #include <getopt.h> | ||
| 50 | #include <arpa/inet.h> | ||
| 51 | |||
| 52 | |||
| 53 | /////////////////// | ||
| 54 | // // | ||
| 55 | // Definitions // | ||
| 56 | // // | ||
| 57 | /////////////////// | ||
| 58 | #pragma mark - Definitions | ||
| 59 | |||
| 60 | #undef PROGRAM_NAME | ||
| 61 | #define PROGRAM_NAME "tinyrad-url" | ||
| 62 | |||
| 63 | |||
| 64 | ////////////////// | ||
| 65 | // // | ||
| 66 | // Prototypes // | ||
| 67 | // // | ||
| 68 | ////////////////// | ||
| 69 | #pragma mark - Prototypes | ||
| 70 | |||
| 71 | int main( int argc, char * argv[] ); | ||
| 72 | |||
| 73 | int my_print_urldesc( TinyRadURLDesc * trudp); | ||
| 74 | void my_usage( void ); | ||
| 75 | |||
| 76 | |||
| 77 | ///////////////// | ||
| 78 | // // | ||
| 79 | // Functions // | ||
| 80 | // // | ||
| 81 | ///////////////// | ||
| 82 | #pragma mark - Functions | ||
| 83 | |||
| 84 | int main(int argc, char * argv[]) | ||
| 85 | { | ||
| 86 | int opt; | ||
| 87 | int c; | ||
| 88 | int rc; | ||
| 89 | int pos; | ||
| 90 | int opt_index; | ||
| 91 | int resolve; | ||
| 92 | unsigned opts; | ||
| 93 | uint32_t tr_opts; | ||
| 94 | TinyRadURLDesc * trudp; | ||
| 95 | TinyRadURLDesc ** trudpp; | ||
| 96 | TinyRadURLDesc * trudp_next; | ||
| 97 | |||
| 98 | // getopt options | ||
| 99 | static char short_opt[] = "d:46hqrVv"; | ||
| 100 | static struct option long_opt[] = | ||
| 101 | { | ||
| 102 | {"debug", optional_argument, NULL, 'd' }, | ||
| 103 | {"help", no_argument, NULL, 'h' }, | ||
| 104 | {"quiet", no_argument, NULL, 'q' }, | ||
| 105 | {"silent", no_argument, NULL, 'q' }, | ||
| 106 | {"version", no_argument, NULL, 'V' }, | ||
| 107 | {"verbose", no_argument, NULL, 'v' }, | ||
| 108 | {"resolve", no_argument, NULL, 'r' }, | ||
| 109 | { NULL, 0, NULL, 0 } | ||
| 110 | }; | ||
| 111 | |||
| 112 | trutils_initialize(PROGRAM_NAME); | ||
| 113 | |||
| 114 | opts = 0; | ||
| 115 | tr_opts = 0; | ||
| 116 | resolve = 0; | ||
| 117 | trudp = NULL; | ||
| 118 | trudp_next = NULL; | ||
| 119 | |||
| 120 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | ||
| 121 | { | ||
| 122 | switch(c) | ||
| 123 | { | ||
| 124 | case -1: /* no more arguments */ | ||
| 125 | case 0: /* long options toggles */ | ||
| 126 | break; | ||
| 127 | |||
| 128 | case '4': | ||
| 129 | tr_opts |= TRAD_IPV4; | ||
| 130 | break; | ||
| 131 | |||
| 132 | case '6': | ||
| 133 | tr_opts |= TRAD_IPV6; | ||
| 134 | break; | ||
| 135 | |||
| 136 | case 'd': | ||
| 137 | opt = ((optarg)) ? (int)strtol(optarg, NULL, 0) : TRAD_DEBUG_ANY; | ||
| 138 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt); | ||
| 139 | break; | ||
| 140 | |||
| 141 | case 'h': | ||
| 142 | my_usage(); | ||
| 143 | return(0); | ||
| 144 | |||
| 145 | case 'q': | ||
| 146 | opts |= TRUTILS_OPT_QUIET; | ||
| 147 | opts &= ~TRUTILS_OPT_VERBOSE; | ||
| 148 | break; | ||
| 149 | |||
| 150 | case 'r': | ||
| 151 | resolve = 1; | ||
| 152 | break; | ||
| 153 | |||
| 154 | case 'V': | ||
| 155 | trutils_version(); | ||
| 156 | return(0); | ||
| 157 | |||
| 158 | case 'v': | ||
| 159 | opts |= TRUTILS_OPT_VERBOSE; | ||
| 160 | opts &= ~TRUTILS_OPT_QUIET; | ||
| 161 | break; | ||
| 162 | |||
| 163 | case '?': | ||
| 164 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 165 | return(1); | ||
| 166 | |||
| 167 | default: | ||
| 168 | fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c); | ||
| 169 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 170 | return(1); | ||
| 171 | }; | ||
| 172 | }; | ||
| 173 | |||
| 174 | // argument checks | ||
| 175 | if (optind >= argc) | ||
| 176 | { | ||
| 177 | fprintf(stderr, "%s: missing required argument\n", PROGRAM_NAME); | ||
| 178 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 179 | return(1); | ||
| 180 | }; | ||
| 181 | |||
| 182 | // parse and resolve URLs | ||
| 183 | trudpp = &trudp; | ||
| 184 | for(pos = optind; (pos < argc); pos++) | ||
| 185 | { | ||
| 186 | if ((rc = tinyrad_urldesc_parse(argv[pos], trudpp)) != TRAD_SUCCESS) | ||
| 187 | { | ||
| 188 | if (!(opts & TRUTILS_OPT_QUIET)) | ||
| 189 | { | ||
| 190 | fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, argv[pos], tinyrad_strerror(rc)); | ||
| 191 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 192 | }; | ||
| 193 | return(1); | ||
| 194 | }; | ||
| 195 | if ((resolve)) | ||
| 196 | { | ||
| 197 | if ((rc = tinyrad_urldesc_resolve(*trudpp, tr_opts)) != TRAD_SUCCESS) | ||
| 198 | { | ||
| 199 | if (!(opts & TRUTILS_OPT_QUIET)) | ||
| 200 | { | ||
| 201 | fprintf(stderr, "%s: %s: %s\n", PROGRAM_NAME, argv[pos], tinyrad_strerror(rc)); | ||
| 202 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 203 | }; | ||
| 204 | return(1); | ||
| 205 | }; | ||
| 206 | }; | ||
| 207 | trudpp = &(*trudpp)->trud_next; | ||
| 208 | }; | ||
| 209 | |||
| 210 | // exit if not displaying output | ||
| 211 | if (!(opts & TRUTILS_OPT_VERBOSE)) | ||
| 212 | { | ||
| 213 | tinyrad_urldesc_free(trudp); | ||
| 214 | return(0); | ||
| 215 | }; | ||
| 216 | |||
| 217 | // display URLs | ||
| 218 | trudp_next = trudp; | ||
| 219 | while ((trudp_next)) | ||
| 220 | { | ||
| 221 | if ((my_print_urldesc(trudp_next))) | ||
| 222 | { | ||
| 223 | tinyrad_urldesc_free(trudp); | ||
| 224 | return(1); | ||
| 225 | }; | ||
| 226 | trudp_next = trudp_next->trud_next; | ||
| 227 | }; | ||
| 228 | |||
| 229 | tinyrad_urldesc_free(trudp); | ||
| 230 | |||
| 231 | return(0); | ||
| 232 | } | ||
| 233 | |||
| 234 | |||
| 235 | int my_print_urldesc( TinyRadURLDesc * trudp) | ||
| 236 | { | ||
| 237 | int pos; | ||
| 238 | char * str; | ||
| 239 | const char * scheme; | ||
| 240 | struct sockaddr_storage * sas; | ||
| 241 | char addr[INET6_ADDRSTRLEN]; | ||
| 242 | |||
| 243 | if ((str = tinyrad_urldesc2str(trudp)) == NULL) | ||
| 244 | { | ||
| 245 | fprintf(stderr, "%s: out of virtual memory\n", PROGRAM_NAME); | ||
| 246 | tinyrad_urldesc_free(trudp); | ||
| 247 | return(1); | ||
| 248 | }; | ||
| 249 | switch(trudp->trud_opts & TRAD_SCHEME) | ||
| 250 | { | ||
| 251 | case TRAD_RADIUS: scheme = "radius (RFC2865 RADIUS)"; break;; | ||
| 252 | case TRAD_RADIUS_ACCT: scheme = "radius-acct (RFC2866 RADIUS Accounting)"; break;; | ||
| 253 | case TRAD_RADIUS_DYNAUTH: scheme = "radius-dynauth (RFC2866 RADIUS Dynamic Authorization)"; break;; | ||
| 254 | case TRAD_RADSEC: scheme = "radsec (RFC6614/RFC7360 RADIUS TLS/DTLS)"; break;; | ||
| 255 | default: scheme = "Unknown or unsupported URL scheme"; break; | ||
| 256 | }; | ||
| 257 | |||
| 258 | printf("%s\n", str); | ||
| 259 | printf(" scheme: %s\n", scheme); | ||
| 260 | printf(" host: %s\n", trudp->trud_host); | ||
| 261 | printf(" port: %i\n", trudp->trud_port); | ||
| 262 | printf(" secret: %s\n", (((trudp->trud_secret)) ? trudp->trud_secret : "n/a")); | ||
| 263 | printf(" protocol: %s\n", ((trudp->trud_opts & TRAD_TCP)) ? "tcp" : "udp"); | ||
| 264 | if ( ((trudp->trud_sockaddrs)) && ((trudp->trud_sockaddrs[0])) ) | ||
| 265 | { | ||
| 266 | for(pos = 0; ((trudp->trud_sockaddrs[pos])); pos++) | ||
| 267 | { | ||
| 268 | sas = trudp->trud_sockaddrs[pos]; | ||
| 269 | switch(sas->ss_family) | ||
| 270 | { | ||
| 271 | case AF_INET: inet_ntop(sas->ss_family, &((struct sockaddr_in *)sas)->sin_addr, addr, sizeof(addr)); break; | ||
| 272 | case AF_INET6: inet_ntop(sas->ss_family, &((struct sockaddr_in6 *)sas)->sin6_addr, addr, sizeof(addr)); break; | ||
| 273 | default: | ||
| 274 | addr[0] = '\0'; | ||
| 275 | break; | ||
| 276 | }; | ||
| 277 | printf(" %s%s\n", ((!(pos)) ? "addresses: " : " "), addr); | ||
| 278 | }; | ||
| 279 | }; | ||
| 280 | printf("\n"); | ||
| 281 | |||
| 282 | tinyrad_free(str); | ||
| 283 | |||
| 284 | return(0); | ||
| 285 | } | ||
| 286 | |||
| 287 | |||
| 288 | void my_usage(void) | ||
| 289 | { | ||
| 290 | printf("Usage: %s [OPTIONS] url url ... url\n", PROGRAM_NAME); | ||
| 291 | printf("Options:\n"); | ||
| 292 | printf(" -4 use IPv4 addresses\n"); | ||
| 293 | printf(" -6 use IPv6 addresses\n"); | ||
| 294 | printf(" -d level, --debug=level print debug messages\n"); | ||
| 295 | printf(" -h, --help print this help and exit\n"); | ||
| 296 | printf(" -q, --quiet, --silent do not print messages\n"); | ||
| 297 | printf(" -V, --version print version number and exit\n"); | ||
| 298 | printf(" -v, --verbose print verbose messages\n"); | ||
| 299 | printf(" -r, --resolve resolve URLs\n"); | ||
| 300 | printf("\n"); | ||
| 301 | printf("URL Syntax:\n"); | ||
| 302 | printf(" radius://hostport/[secret][?proto] use RFC2865 (udp/port 1812)\n"); | ||
| 303 | printf(" radius-acct://hostport/[secret][?proto] use RFC2866 (udp/port 1813)\n"); | ||
| 304 | printf(" radsec://hostport/[?proto] use RFC6614/RFC7360 (tcp/port 2083)\n"); | ||
| 305 | printf(" radius-dynauth://hostport/[secret][?proto] use RFC5176 (udp/port 3799)\n"); | ||
| 306 | printf("\n"); | ||
| 307 | printf(" where:\n"); | ||
| 308 | printf(" 'hostport' is a host name with an optional ':portnumber'\n"); | ||
| 309 | printf(" 'secret' is the RADIUS secret encoded using character encoding in RFC3986\n"); | ||
| 310 | printf(" 'proto' is communication protocol used by the connection (UDP or TCP)\n"); | ||
| 311 | printf("\n"); | ||
| 312 | return; | ||
| 313 | } | ||
| 314 | |||
| 315 | |||
| 316 | /* end of source */ | ||
