From daac2f633f49a45baa8412c5e4e71e594236e7b8 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 28 Jul 2008 23:44:12 +0000 Subject: This commit was manufactured by cvs2git to create tag 'pre_openssl_0_9_8h'. --- src/lib/libc/crypt/Makefile.inc | 16 - src/lib/libc/crypt/arc4random.3 | 136 -- src/lib/libc/crypt/arc4random.c | 272 --- src/lib/libc/crypt/bcrypt.c | 338 --- src/lib/libc/crypt/blowfish.3 | 106 - src/lib/libc/crypt/blowfish.c | 685 ------ src/lib/libc/crypt/cast.c | 790 ------- src/lib/libc/crypt/crypt.3 | 324 --- src/lib/libc/crypt/crypt.c | 696 ------ src/lib/libc/crypt/crypt2.c | 104 - src/lib/libc/crypt/md5crypt.c | 149 -- src/lib/libc/crypt/skipjack.c | 260 --- src/lib/libc/include/ctype_private.h | 7 - src/lib/libc/include/namespace.h | 18 - src/lib/libc/include/thread_private.h | 160 -- src/lib/libc/net/Makefile.inc | 101 - src/lib/libc/net/base64.c | 308 --- src/lib/libc/net/byteorder.3 | 206 -- src/lib/libc/net/ethers.3 | 122 - src/lib/libc/net/ethers.c | 232 -- src/lib/libc/net/freeaddrinfo.c | 50 - src/lib/libc/net/gai_strerror.3 | 93 - src/lib/libc/net/gai_strerror.c | 76 - src/lib/libc/net/getaddrinfo.3 | 437 ---- src/lib/libc/net/getaddrinfo.c | 1748 -------------- src/lib/libc/net/gethostbyname.3 | 297 --- src/lib/libc/net/gethostnamadr.c | 1129 --------- src/lib/libc/net/getifaddrs.3 | 157 -- src/lib/libc/net/getifaddrs.c | 277 --- src/lib/libc/net/getnameinfo.3 | 266 --- src/lib/libc/net/getnameinfo.c | 351 --- src/lib/libc/net/getnetbyaddr.c | 47 - src/lib/libc/net/getnetbyname.c | 54 - src/lib/libc/net/getnetent.3 | 140 -- src/lib/libc/net/getnetent.c | 121 - src/lib/libc/net/getnetnamadr.c | 384 --- src/lib/libc/net/getproto.c | 59 - src/lib/libc/net/getprotoent.3 | 213 -- src/lib/libc/net/getprotoent.c | 166 -- src/lib/libc/net/getprotoname.c | 67 - src/lib/libc/net/getrrsetbyname.3 | 166 -- src/lib/libc/net/getrrsetbyname.c | 514 ---- src/lib/libc/net/getservbyname.c | 70 - src/lib/libc/net/getservbyport.c | 64 - src/lib/libc/net/getservent.3 | 220 -- src/lib/libc/net/getservent.c | 168 -- src/lib/libc/net/herror.c | 106 - src/lib/libc/net/htonl.c | 21 - src/lib/libc/net/htons.c | 21 - src/lib/libc/net/if_indextoname.3 | 144 -- src/lib/libc/net/if_indextoname.c | 86 - src/lib/libc/net/if_nameindex.c | 140 -- src/lib/libc/net/if_nametoindex.c | 81 - src/lib/libc/net/inet.3 | 345 --- src/lib/libc/net/inet6_opt_init.3 | 338 --- src/lib/libc/net/inet6_option_space.3 | 444 ---- src/lib/libc/net/inet6_rth_space.3 | 219 -- src/lib/libc/net/inet6_rthdr_space.3 | 314 --- src/lib/libc/net/inet_addr.c | 171 -- src/lib/libc/net/inet_lnaof.c | 51 - src/lib/libc/net/inet_makeaddr.c | 54 - src/lib/libc/net/inet_net.3 | 176 -- src/lib/libc/net/inet_net_ntop.c | 135 -- src/lib/libc/net/inet_net_pton.c | 191 -- src/lib/libc/net/inet_neta.c | 80 - src/lib/libc/net/inet_netof.c | 50 - src/lib/libc/net/inet_network.c | 84 - src/lib/libc/net/inet_ntoa.c | 51 - src/lib/libc/net/inet_ntop.c | 195 -- src/lib/libc/net/inet_pton.c | 212 -- src/lib/libc/net/ip6opt.c | 596 ----- src/lib/libc/net/link_addr.3 | 127 - src/lib/libc/net/linkaddr.c | 148 -- src/lib/libc/net/net_addrcmp.3 | 91 - src/lib/libc/net/net_addrcmp.c | 63 - src/lib/libc/net/nsap_addr.c | 94 - src/lib/libc/net/ntohl.c | 21 - src/lib/libc/net/ntohs.c | 21 - src/lib/libc/net/rcmd.3 | 266 --- src/lib/libc/net/rcmd.c | 691 ------ src/lib/libc/net/rcmdsh.3 | 96 - src/lib/libc/net/rcmdsh.c | 186 -- src/lib/libc/net/recv.c | 40 - src/lib/libc/net/res_comp.c | 475 ---- src/lib/libc/net/res_data.c | 105 - src/lib/libc/net/res_debug.c | 1395 ----------- src/lib/libc/net/res_debug_syms.c | 189 -- src/lib/libc/net/res_init.c | 666 ------ src/lib/libc/net/res_mkquery.c | 232 -- src/lib/libc/net/res_query.c | 400 ---- src/lib/libc/net/res_random.c | 264 --- src/lib/libc/net/res_send.c | 853 ------- src/lib/libc/net/resolver.3 | 354 --- src/lib/libc/net/rresvport.c | 107 - src/lib/libc/net/rthdr.c | 378 --- src/lib/libc/net/send.c | 40 - src/lib/libc/net/sethostent.c | 57 - src/lib/libc/net/vars6.c | 42 - src/lib/libc/stdlib/Makefile.inc | 73 - src/lib/libc/stdlib/_Exit.c | 22 - src/lib/libc/stdlib/_rand48.c | 47 - src/lib/libc/stdlib/a64l.3 | 133 -- src/lib/libc/stdlib/a64l.c | 42 - src/lib/libc/stdlib/abort.3 | 63 - src/lib/libc/stdlib/abort.c | 78 - src/lib/libc/stdlib/abs.3 | 66 - src/lib/libc/stdlib/abs.c | 37 - src/lib/libc/stdlib/alloca.3 | 80 - src/lib/libc/stdlib/atexit.3 | 77 - src/lib/libc/stdlib/atexit.c | 209 -- src/lib/libc/stdlib/atexit.h | 51 - src/lib/libc/stdlib/atof.3 | 69 - src/lib/libc/stdlib/atof.c | 37 - src/lib/libc/stdlib/atoi.3 | 86 - src/lib/libc/stdlib/atoi.c | 37 - src/lib/libc/stdlib/atol.3 | 70 - src/lib/libc/stdlib/atol.c | 37 - src/lib/libc/stdlib/atoll.3 | 70 - src/lib/libc/stdlib/atoll.c | 38 - src/lib/libc/stdlib/bsearch.3 | 84 - src/lib/libc/stdlib/bsearch.c | 67 - src/lib/libc/stdlib/calloc.c | 50 - src/lib/libc/stdlib/cfree.c | 40 - src/lib/libc/stdlib/div.3 | 65 - src/lib/libc/stdlib/div.c | 71 - src/lib/libc/stdlib/drand48.c | 23 - src/lib/libc/stdlib/ecvt.3 | 165 -- src/lib/libc/stdlib/ecvt.c | 105 - src/lib/libc/stdlib/erand48.c | 24 - src/lib/libc/stdlib/exit.3 | 114 - src/lib/libc/stdlib/exit.c | 59 - src/lib/libc/stdlib/gcvt.c | 111 - src/lib/libc/stdlib/getenv.3 | 148 -- src/lib/libc/stdlib/getenv.c | 80 - src/lib/libc/stdlib/getopt.3 | 371 --- src/lib/libc/stdlib/getopt_long.3 | 464 ---- src/lib/libc/stdlib/getopt_long.c | 517 ---- src/lib/libc/stdlib/getsubopt.3 | 145 -- src/lib/libc/stdlib/getsubopt.c | 92 - src/lib/libc/stdlib/hcreate.3 | 184 -- src/lib/libc/stdlib/hcreate.c | 191 -- src/lib/libc/stdlib/heapsort.c | 173 -- src/lib/libc/stdlib/imaxabs.3 | 66 - src/lib/libc/stdlib/imaxabs.c | 38 - src/lib/libc/stdlib/imaxdiv.3 | 67 - src/lib/libc/stdlib/imaxdiv.c | 50 - src/lib/libc/stdlib/insque.3 | 106 - src/lib/libc/stdlib/insque.c | 48 - src/lib/libc/stdlib/jrand48.c | 22 - src/lib/libc/stdlib/l64a.c | 42 - src/lib/libc/stdlib/labs.3 | 69 - src/lib/libc/stdlib/labs.c | 37 - src/lib/libc/stdlib/lcong48.c | 31 - src/lib/libc/stdlib/ldiv.3 | 67 - src/lib/libc/stdlib/ldiv.c | 50 - src/lib/libc/stdlib/llabs.c | 38 - src/lib/libc/stdlib/lldiv.3 | 67 - src/lib/libc/stdlib/lldiv.c | 50 - src/lib/libc/stdlib/lrand48.c | 24 - src/lib/libc/stdlib/lsearch.3 | 108 - src/lib/libc/stdlib/lsearch.c | 88 - src/lib/libc/stdlib/malloc.3 | 456 ---- src/lib/libc/stdlib/malloc.c | 1325 ----------- src/lib/libc/stdlib/merge.c | 333 --- src/lib/libc/stdlib/mrand48.c | 24 - src/lib/libc/stdlib/nrand48.c | 22 - src/lib/libc/stdlib/putenv.c | 50 - src/lib/libc/stdlib/qabs.3 | 57 - src/lib/libc/stdlib/qabs.c | 37 - src/lib/libc/stdlib/qdiv.3 | 62 - src/lib/libc/stdlib/qdiv.c | 50 - src/lib/libc/stdlib/qsort.3 | 233 -- src/lib/libc/stdlib/qsort.c | 161 -- src/lib/libc/stdlib/radixsort.3 | 155 -- src/lib/libc/stdlib/radixsort.c | 294 --- src/lib/libc/stdlib/rand.3 | 98 - src/lib/libc/stdlib/rand.c | 52 - src/lib/libc/stdlib/rand48.3 | 165 -- src/lib/libc/stdlib/rand48.h | 32 - src/lib/libc/stdlib/random.3 | 185 -- src/lib/libc/stdlib/random.c | 395 ---- src/lib/libc/stdlib/realpath.3 | 117 - src/lib/libc/stdlib/realpath.c | 190 -- src/lib/libc/stdlib/remque.c | 44 - src/lib/libc/stdlib/seed48.c | 37 - src/lib/libc/stdlib/setenv.c | 103 - src/lib/libc/stdlib/srand48.c | 31 - src/lib/libc/stdlib/strtod.3 | 129 - src/lib/libc/stdlib/strtod.c | 2459 -------------------- src/lib/libc/stdlib/strtof.c | 39 - src/lib/libc/stdlib/strtoimax.c | 140 -- src/lib/libc/stdlib/strtol.3 | 264 --- src/lib/libc/stdlib/strtol.c | 140 -- src/lib/libc/stdlib/strtoll.c | 153 -- src/lib/libc/stdlib/strtonum.3 | 152 -- src/lib/libc/stdlib/strtonum.c | 65 - src/lib/libc/stdlib/strtoul.3 | 248 -- src/lib/libc/stdlib/strtoul.c | 102 - src/lib/libc/stdlib/strtoull.c | 115 - src/lib/libc/stdlib/strtoumax.c | 102 - src/lib/libc/stdlib/system.3 | 104 - src/lib/libc/stdlib/system.c | 74 - src/lib/libc/stdlib/tfind.c | 41 - src/lib/libc/stdlib/tsearch.3 | 127 - src/lib/libc/stdlib/tsearch.c | 121 - src/lib/libc/string/Makefile.inc | 178 -- src/lib/libc/string/bcmp.3 | 66 - src/lib/libc/string/bcmp.c | 55 - src/lib/libc/string/bcopy.3 | 67 - src/lib/libc/string/bcopy.c | 128 - src/lib/libc/string/bm.3 | 112 - src/lib/libc/string/bm.c | 205 -- src/lib/libc/string/bstring.3 | 98 - src/lib/libc/string/bzero.3 | 61 - src/lib/libc/string/bzero.c | 48 - src/lib/libc/string/ffs.3 | 56 - src/lib/libc/string/ffs.c | 44 - src/lib/libc/string/index.c | 47 - src/lib/libc/string/memccpy.3 | 73 - src/lib/libc/string/memccpy.c | 48 - src/lib/libc/string/memchr.3 | 93 - src/lib/libc/string/memchr.c | 48 - src/lib/libc/string/memcmp.3 | 77 - src/lib/libc/string/memcmp.c | 51 - src/lib/libc/string/memcpy.3 | 77 - src/lib/libc/string/memmove.3 | 70 - src/lib/libc/string/memrchr.c | 38 - src/lib/libc/string/memset.3 | 67 - src/lib/libc/string/memset.c | 47 - src/lib/libc/string/rindex.c | 49 - src/lib/libc/string/strcasecmp.3 | 84 - src/lib/libc/string/strcasecmp.c | 105 - src/lib/libc/string/strcasestr.c | 60 - src/lib/libc/string/strcat.3 | 133 -- src/lib/libc/string/strcat.c | 51 - src/lib/libc/string/strchr.3 | 102 - src/lib/libc/string/strcmp.3 | 87 - src/lib/libc/string/strcmp.c | 51 - src/lib/libc/string/strcoll.3 | 68 - src/lib/libc/string/strcoll.c | 44 - src/lib/libc/string/strcpy.3 | 151 -- src/lib/libc/string/strcpy.c | 50 - src/lib/libc/string/strcspn.3 | 100 - src/lib/libc/string/strcspn.c | 58 - src/lib/libc/string/strdup.3 | 84 - src/lib/libc/string/strdup.c | 49 - src/lib/libc/string/strerror.3 | 113 - src/lib/libc/string/strerror.c | 41 - src/lib/libc/string/strerror_r.c | 137 -- src/lib/libc/string/string.3 | 136 -- src/lib/libc/string/strlcat.c | 55 - src/lib/libc/string/strlcpy.3 | 186 -- src/lib/libc/string/strlcpy.c | 51 - src/lib/libc/string/strlen.3 | 61 - src/lib/libc/string/strlen.c | 47 - src/lib/libc/string/strmode.3 | 157 -- src/lib/libc/string/strmode.c | 140 -- src/lib/libc/string/strncat.c | 57 - src/lib/libc/string/strncmp.c | 51 - src/lib/libc/string/strncpy.c | 62 - src/lib/libc/string/strpbrk.3 | 72 - src/lib/libc/string/strpbrk.c | 48 - src/lib/libc/string/strrchr.3 | 104 - src/lib/libc/string/strsep.3 | 112 - src/lib/libc/string/strsep.c | 71 - src/lib/libc/string/strsignal.3 | 56 - src/lib/libc/string/strsignal.c | 41 - src/lib/libc/string/strspn.3 | 84 - src/lib/libc/string/strspn.c | 51 - src/lib/libc/string/strstr.3 | 92 - src/lib/libc/string/strstr.c | 56 - src/lib/libc/string/strtok.3 | 152 -- src/lib/libc/string/strtok.c | 86 - src/lib/libc/string/strxfrm.3 | 74 - src/lib/libc/string/strxfrm.c | 51 - src/lib/libc/string/swab.3 | 61 - src/lib/libc/string/swab.c | 61 - src/lib/libc/string/wcscat.c | 55 - src/lib/libc/string/wcschr.c | 48 - src/lib/libc/string/wcscmp.c | 51 - src/lib/libc/string/wcscpy.c | 52 - src/lib/libc/string/wcscspn.c | 53 - src/lib/libc/string/wcslcat.c | 68 - src/lib/libc/string/wcslcpy.c | 64 - src/lib/libc/string/wcslen.c | 44 - src/lib/libc/string/wcsncat.c | 52 - src/lib/libc/string/wcsncmp.c | 52 - src/lib/libc/string/wcsncpy.c | 50 - src/lib/libc/string/wcspbrk.c | 53 - src/lib/libc/string/wcsrchr.c | 50 - src/lib/libc/string/wcsspn.c | 55 - src/lib/libc/string/wcsstr.c | 70 - src/lib/libc/string/wcstok.3 | 136 -- src/lib/libc/string/wcstok.c | 93 - src/lib/libc/string/wcswcs.c | 5 - src/lib/libc/string/wcswidth.c | 47 - src/lib/libc/string/wmemchr.3 | 141 -- src/lib/libc/string/wmemchr.c | 47 - src/lib/libc/string/wmemcmp.c | 50 - src/lib/libc/string/wmemcpy.c | 40 - src/lib/libc/string/wmemmove.c | 40 - src/lib/libc/string/wmemset.c | 46 - src/lib/libcrypto/aes/README | 3 - src/lib/libcrypto/aes/aes.h | 127 - src/lib/libcrypto/aes/aes_cbc.c | 133 -- src/lib/libcrypto/aes/aes_cfb.c | 225 -- src/lib/libcrypto/aes/aes_core.c | 1261 ---------- src/lib/libcrypto/aes/aes_ctr.c | 139 -- src/lib/libcrypto/aes/aes_ecb.c | 73 - src/lib/libcrypto/aes/aes_locl.h | 85 - src/lib/libcrypto/aes/aes_misc.c | 64 - src/lib/libcrypto/aes/aes_ofb.c | 142 -- src/lib/libcrypto/aes/asm/aes-586.pl | 1541 ------------ src/lib/libcrypto/asn1/a_bitstr.c | 222 -- src/lib/libcrypto/asn1/a_bool.c | 114 - src/lib/libcrypto/asn1/a_bytes.c | 312 --- src/lib/libcrypto/asn1/a_d2i_fp.c | 262 --- src/lib/libcrypto/asn1/a_digest.c | 111 - src/lib/libcrypto/asn1/a_dup.c | 107 - src/lib/libcrypto/asn1/a_enum.c | 180 -- src/lib/libcrypto/asn1/a_i2d_fp.c | 163 -- src/lib/libcrypto/asn1/a_int.c | 453 ---- src/lib/libcrypto/asn1/a_mbstr.c | 400 ---- src/lib/libcrypto/asn1/a_object.c | 320 --- src/lib/libcrypto/asn1/a_octet.c | 71 - src/lib/libcrypto/asn1/a_print.c | 127 - src/lib/libcrypto/asn1/a_set.c | 235 -- src/lib/libcrypto/asn1/a_sign.c | 294 --- src/lib/libcrypto/asn1/a_strex.c | 567 ----- src/lib/libcrypto/asn1/a_strnid.c | 290 --- src/lib/libcrypto/asn1/a_time.c | 164 -- src/lib/libcrypto/asn1/a_type.c | 84 - src/lib/libcrypto/asn1/a_utf8.c | 211 -- src/lib/libcrypto/asn1/a_verify.c | 181 -- src/lib/libcrypto/asn1/asn1.h | 1113 --------- src/lib/libcrypto/asn1/asn1_err.c | 254 -- src/lib/libcrypto/asn1/asn1_lib.c | 433 ---- src/lib/libcrypto/asn1/asn1_mac.h | 560 ----- src/lib/libcrypto/asn1/asn1_par.c | 418 ---- src/lib/libcrypto/asn1/asn1t.h | 846 ------- src/lib/libcrypto/asn1/asn_moid.c | 100 - src/lib/libcrypto/asn1/asn_pack.c | 191 -- src/lib/libcrypto/asn1/charmap.h | 15 - src/lib/libcrypto/asn1/charmap.pl | 80 - src/lib/libcrypto/asn1/d2i_pr.c | 145 -- src/lib/libcrypto/asn1/d2i_pu.c | 122 - src/lib/libcrypto/asn1/evp_asn1.c | 189 -- src/lib/libcrypto/asn1/f_enum.c | 207 -- src/lib/libcrypto/asn1/f_int.c | 219 -- src/lib/libcrypto/asn1/f_string.c | 212 -- src/lib/libcrypto/asn1/i2d_pr.c | 90 - src/lib/libcrypto/asn1/i2d_pu.c | 88 - src/lib/libcrypto/asn1/n_pkey.c | 333 --- src/lib/libcrypto/asn1/nsseq.c | 82 - src/lib/libcrypto/asn1/p5_pbe.c | 130 -- src/lib/libcrypto/asn1/p5_pbev2.c | 205 -- src/lib/libcrypto/asn1/p8_pkey.c | 84 - src/lib/libcrypto/asn1/t_bitst.c | 102 - src/lib/libcrypto/asn1/t_crl.c | 134 -- src/lib/libcrypto/asn1/t_pkey.c | 387 --- src/lib/libcrypto/asn1/t_req.c | 276 --- src/lib/libcrypto/asn1/t_spki.c | 116 - src/lib/libcrypto/asn1/t_x509.c | 505 ---- src/lib/libcrypto/asn1/t_x509a.c | 110 - src/lib/libcrypto/asn1/tasn_dec.c | 1023 -------- src/lib/libcrypto/asn1/tasn_enc.c | 500 ---- src/lib/libcrypto/asn1/tasn_fre.c | 229 -- src/lib/libcrypto/asn1/tasn_new.c | 351 --- src/lib/libcrypto/asn1/tasn_prn.c | 198 -- src/lib/libcrypto/asn1/tasn_typ.c | 133 -- src/lib/libcrypto/asn1/tasn_utl.c | 253 -- src/lib/libcrypto/asn1/x_algor.c | 73 - src/lib/libcrypto/asn1/x_attrib.c | 118 - src/lib/libcrypto/asn1/x_bignum.c | 137 -- src/lib/libcrypto/asn1/x_crl.c | 140 -- src/lib/libcrypto/asn1/x_exten.c | 71 - src/lib/libcrypto/asn1/x_info.c | 114 - src/lib/libcrypto/asn1/x_long.c | 169 -- src/lib/libcrypto/asn1/x_name.c | 275 --- src/lib/libcrypto/asn1/x_pkey.c | 151 -- src/lib/libcrypto/asn1/x_pubkey.c | 360 --- src/lib/libcrypto/asn1/x_req.c | 112 - src/lib/libcrypto/asn1/x_sig.c | 69 - src/lib/libcrypto/asn1/x_spki.c | 81 - src/lib/libcrypto/asn1/x_val.c | 69 - src/lib/libcrypto/asn1/x_x509.c | 189 -- src/lib/libcrypto/asn1/x_x509a.c | 151 -- src/lib/libcrypto/bf/COPYRIGHT | 46 - src/lib/libcrypto/bf/INSTALL | 14 - src/lib/libcrypto/bf/README | 8 - src/lib/libcrypto/bf/VERSION | 6 - src/lib/libcrypto/bf/asm/bf-586.pl | 136 -- src/lib/libcrypto/bf/bf_cbc.c | 143 -- src/lib/libcrypto/bf/bf_cfb64.c | 121 - src/lib/libcrypto/bf/bf_ecb.c | 96 - src/lib/libcrypto/bf/bf_enc.c | 306 --- src/lib/libcrypto/bf/bf_locl.h | 219 -- src/lib/libcrypto/bf/bf_ofb64.c | 110 - src/lib/libcrypto/bf/bf_pi.h | 325 --- src/lib/libcrypto/bf/bf_skey.c | 118 - src/lib/libcrypto/bf/blowfish.h | 130 -- src/lib/libcrypto/bio/b_dump.c | 156 -- src/lib/libcrypto/bio/b_print.c | 841 ------- src/lib/libcrypto/bio/b_sock.c | 752 ------ src/lib/libcrypto/bio/bf_buff.c | 511 ---- src/lib/libcrypto/bio/bf_lbuf.c | 397 ---- src/lib/libcrypto/bio/bf_nbio.c | 255 -- src/lib/libcrypto/bio/bf_null.c | 183 -- src/lib/libcrypto/bio/bio.h | 695 ------ src/lib/libcrypto/bio/bio_cb.c | 139 -- src/lib/libcrypto/bio/bio_err.c | 156 -- src/lib/libcrypto/bio/bio_lib.c | 556 ----- src/lib/libcrypto/bio/bss_acpt.c | 479 ---- src/lib/libcrypto/bio/bss_bio.c | 924 -------- src/lib/libcrypto/bio/bss_conn.c | 652 ------ src/lib/libcrypto/bio/bss_fd.c | 282 --- src/lib/libcrypto/bio/bss_file.c | 343 --- src/lib/libcrypto/bio/bss_log.c | 400 ---- src/lib/libcrypto/bio/bss_mem.c | 321 --- src/lib/libcrypto/bio/bss_null.c | 150 -- src/lib/libcrypto/bio/bss_sock.c | 305 --- src/lib/libcrypto/bn/asm/bn-586.pl | 593 ----- src/lib/libcrypto/bn/asm/co-586.pl | 286 --- src/lib/libcrypto/bn/asm/ia64.S | 1560 ------------- src/lib/libcrypto/bn/asm/pa-risc2.s | 1618 ------------- src/lib/libcrypto/bn/asm/pa-risc2W.s | 1605 ------------- src/lib/libcrypto/bn/asm/ppc.pl | 2078 ----------------- src/lib/libcrypto/bn/asm/sparcv8.S | 1458 ------------ src/lib/libcrypto/bn/asm/sparcv8plus.S | 1547 ------------ src/lib/libcrypto/bn/asm/x86.pl | 28 - src/lib/libcrypto/bn/asm/x86/add.pl | 76 - src/lib/libcrypto/bn/asm/x86/comba.pl | 277 --- src/lib/libcrypto/bn/asm/x86/div.pl | 15 - src/lib/libcrypto/bn/asm/x86/mul.pl | 77 - src/lib/libcrypto/bn/asm/x86/mul_add.pl | 87 - src/lib/libcrypto/bn/asm/x86/sqr.pl | 60 - src/lib/libcrypto/bn/asm/x86/sub.pl | 76 - src/lib/libcrypto/bn/asm/x86_64-gcc.c | 593 ----- src/lib/libcrypto/bn/bn.h | 583 ----- src/lib/libcrypto/bn/bn_add.c | 309 --- src/lib/libcrypto/bn/bn_asm.c | 832 ------- src/lib/libcrypto/bn/bn_blind.c | 144 -- src/lib/libcrypto/bn/bn_ctx.c | 155 -- src/lib/libcrypto/bn/bn_div.c | 387 --- src/lib/libcrypto/bn/bn_err.c | 139 -- src/lib/libcrypto/bn/bn_exp.c | 987 -------- src/lib/libcrypto/bn/bn_exp2.c | 313 --- src/lib/libcrypto/bn/bn_gcd.c | 490 ---- src/lib/libcrypto/bn/bn_kron.c | 182 -- src/lib/libcrypto/bn/bn_lcl.h | 492 ---- src/lib/libcrypto/bn/bn_lib.c | 824 ------- src/lib/libcrypto/bn/bn_mod.c | 296 --- src/lib/libcrypto/bn/bn_mont.c | 421 ---- src/lib/libcrypto/bn/bn_mpi.c | 129 - src/lib/libcrypto/bn/bn_mul.c | 802 ------- src/lib/libcrypto/bn/bn_prime.c | 468 ---- src/lib/libcrypto/bn/bn_prime.h | 325 --- src/lib/libcrypto/bn/bn_prime.pl | 117 - src/lib/libcrypto/bn/bn_print.c | 333 --- src/lib/libcrypto/bn/bn_rand.c | 291 --- src/lib/libcrypto/bn/bn_recp.c | 230 -- src/lib/libcrypto/bn/bn_shift.c | 205 -- src/lib/libcrypto/bn/bn_sqr.c | 288 --- src/lib/libcrypto/bn/bn_sqrt.c | 387 --- src/lib/libcrypto/bn/bn_word.c | 208 -- src/lib/libcrypto/bn/bn_x931p.c | 282 --- src/lib/libcrypto/buffer/buf_err.c | 99 - src/lib/libcrypto/buffer/buffer.c | 202 -- src/lib/libcrypto/buffer/buffer.h | 105 - src/lib/libcrypto/cast/asm/cast-586.pl | 176 -- src/lib/libcrypto/cast/c_cfb64.c | 122 - src/lib/libcrypto/cast/c_ecb.c | 80 - src/lib/libcrypto/cast/c_enc.c | 209 -- src/lib/libcrypto/cast/c_ofb64.c | 111 - src/lib/libcrypto/cast/c_skey.c | 169 -- src/lib/libcrypto/cast/cast.h | 106 - src/lib/libcrypto/cast/cast_lcl.h | 227 -- src/lib/libcrypto/cast/cast_s.h | 585 ----- src/lib/libcrypto/comp/c_rle.c | 62 - src/lib/libcrypto/comp/c_zlib.c | 215 -- src/lib/libcrypto/comp/comp.h | 59 - src/lib/libcrypto/comp/comp_err.c | 92 - src/lib/libcrypto/comp/comp_lib.c | 78 - src/lib/libcrypto/conf/README | 78 - src/lib/libcrypto/conf/conf.h | 250 -- src/lib/libcrypto/conf/conf_api.c | 308 --- src/lib/libcrypto/conf/conf_api.h | 89 - src/lib/libcrypto/conf/conf_def.c | 750 ------ src/lib/libcrypto/conf/conf_def.h | 180 -- src/lib/libcrypto/conf/conf_err.c | 130 -- src/lib/libcrypto/conf/conf_lib.c | 401 ---- src/lib/libcrypto/conf/conf_mall.c | 80 - src/lib/libcrypto/conf/conf_mod.c | 616 ----- src/lib/libcrypto/conf/conf_sap.c | 111 - src/lib/libcrypto/conf/keysets.pl | 185 -- src/lib/libcrypto/conf/ssleay.cnf | 78 - src/lib/libcrypto/cpt_err.c | 106 - src/lib/libcrypto/cryptlib.c | 744 ------ src/lib/libcrypto/cryptlib.h | 104 - src/lib/libcrypto/crypto.h | 518 ----- src/lib/libcrypto/cversion.c | 120 - src/lib/libcrypto/des/COPYRIGHT | 50 - src/lib/libcrypto/des/asm/crypt586.pl | 208 -- src/lib/libcrypto/des/asm/des-586.pl | 255 -- src/lib/libcrypto/des/asm/desboth.pl | 79 - src/lib/libcrypto/des/cbc_cksm.c | 106 - src/lib/libcrypto/des/cbc_enc.c | 61 - src/lib/libcrypto/des/cfb64ede.c | 254 -- src/lib/libcrypto/des/cfb64enc.c | 121 - src/lib/libcrypto/des/cfb_enc.c | 174 -- src/lib/libcrypto/des/des.h | 246 -- src/lib/libcrypto/des/des_enc.c | 417 ---- src/lib/libcrypto/des/des_locl.h | 428 ---- src/lib/libcrypto/des/ecb3_enc.c | 81 - src/lib/libcrypto/des/ecb_enc.c | 123 - src/lib/libcrypto/des/ede_cbcm_enc.c | 197 -- src/lib/libcrypto/des/enc_read.c | 228 -- src/lib/libcrypto/des/enc_writ.c | 171 -- src/lib/libcrypto/des/fcrypt.c | 173 -- src/lib/libcrypto/des/fcrypt_b.c | 145 -- src/lib/libcrypto/des/ncbc_enc.c | 148 -- src/lib/libcrypto/des/ofb64ede.c | 125 - src/lib/libcrypto/des/ofb64enc.c | 110 - src/lib/libcrypto/des/ofb_enc.c | 135 -- src/lib/libcrypto/des/pcbc_enc.c | 123 - src/lib/libcrypto/des/qud_cksm.c | 139 -- src/lib/libcrypto/des/rand_key.c | 68 - src/lib/libcrypto/des/set_key.c | 411 ---- src/lib/libcrypto/des/spr.h | 204 -- src/lib/libcrypto/des/str2key.c | 173 -- src/lib/libcrypto/des/xcbc_enc.c | 195 -- src/lib/libcrypto/dh/dh.h | 223 -- src/lib/libcrypto/dh/dh_asn1.c | 87 - src/lib/libcrypto/dh/dh_check.c | 146 -- src/lib/libcrypto/dh/dh_err.c | 106 - src/lib/libcrypto/dh/dh_gen.c | 175 -- src/lib/libcrypto/dh/dh_key.c | 266 --- src/lib/libcrypto/dh/dh_lib.c | 247 -- src/lib/libcrypto/doc/DH_generate_key.pod | 50 - src/lib/libcrypto/doc/DH_generate_parameters.pod | 73 - src/lib/libcrypto/doc/DH_get_ex_new_index.pod | 36 - src/lib/libcrypto/doc/DH_new.pod | 40 - src/lib/libcrypto/doc/DH_set_method.pod | 129 - src/lib/libcrypto/doc/DH_size.pod | 33 - src/lib/libcrypto/doc/DSA_SIG_new.pod | 40 - src/lib/libcrypto/doc/DSA_do_sign.pod | 47 - src/lib/libcrypto/doc/DSA_dup_DH.pod | 36 - src/lib/libcrypto/doc/DSA_generate_key.pod | 34 - src/lib/libcrypto/doc/DSA_generate_parameters.pod | 105 - src/lib/libcrypto/doc/DSA_get_ex_new_index.pod | 36 - src/lib/libcrypto/doc/DSA_new.pod | 42 - src/lib/libcrypto/doc/DSA_set_method.pod | 143 -- src/lib/libcrypto/doc/DSA_sign.pod | 66 - src/lib/libcrypto/doc/DSA_size.pod | 33 - src/lib/libcrypto/doc/ERR_GET_LIB.pod | 51 - src/lib/libcrypto/doc/ERR_clear_error.pod | 29 - src/lib/libcrypto/doc/ERR_error_string.pod | 73 - src/lib/libcrypto/doc/ERR_get_error.pod | 76 - src/lib/libcrypto/doc/ERR_load_crypto_strings.pod | 46 - src/lib/libcrypto/doc/ERR_load_strings.pod | 54 - src/lib/libcrypto/doc/ERR_print_errors.pod | 51 - src/lib/libcrypto/doc/ERR_put_error.pod | 44 - src/lib/libcrypto/doc/ERR_remove_state.pod | 34 - src/lib/libcrypto/doc/EVP_BytesToKey.pod | 67 - src/lib/libcrypto/doc/EVP_DigestInit.pod | 256 -- src/lib/libcrypto/doc/EVP_EncryptInit.pod | 511 ---- src/lib/libcrypto/doc/EVP_OpenInit.pod | 63 - src/lib/libcrypto/doc/EVP_PKEY_new.pod | 47 - src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod | 80 - src/lib/libcrypto/doc/EVP_SealInit.pod | 85 - src/lib/libcrypto/doc/EVP_SignInit.pod | 95 - src/lib/libcrypto/doc/EVP_VerifyInit.pod | 86 - src/lib/libcrypto/doc/OBJ_nid2obj.pod | 149 -- src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod | 101 - src/lib/libcrypto/doc/OPENSSL_config.pod | 82 - .../libcrypto/doc/OPENSSL_load_builtin_modules.pod | 51 - .../libcrypto/doc/OpenSSL_add_all_algorithms.pod | 66 - src/lib/libcrypto/doc/PKCS12_create.pod | 57 - src/lib/libcrypto/doc/PKCS12_parse.pod | 50 - src/lib/libcrypto/doc/PKCS7_decrypt.pod | 53 - src/lib/libcrypto/doc/PKCS7_encrypt.pod | 65 - src/lib/libcrypto/doc/PKCS7_sign.pod | 85 - src/lib/libcrypto/doc/PKCS7_verify.pod | 116 - src/lib/libcrypto/doc/RAND_add.pod | 77 - src/lib/libcrypto/doc/RAND_bytes.pod | 47 - src/lib/libcrypto/doc/RAND_cleanup.pod | 29 - src/lib/libcrypto/doc/RAND_load_file.pod | 53 - src/lib/libcrypto/doc/RAND_set_rand_method.pod | 83 - src/lib/libcrypto/doc/RSA_blinding_on.pod | 43 - src/lib/libcrypto/doc/RSA_check_key.pod | 67 - src/lib/libcrypto/doc/RSA_generate_key.pod | 69 - src/lib/libcrypto/doc/RSA_get_ex_new_index.pod | 120 - src/lib/libcrypto/doc/RSA_new.pod | 41 - .../libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod | 124 - src/lib/libcrypto/doc/RSA_print.pod | 49 - src/lib/libcrypto/doc/RSA_private_encrypt.pod | 70 - src/lib/libcrypto/doc/RSA_public_encrypt.pod | 84 - src/lib/libcrypto/doc/RSA_set_method.pod | 202 -- src/lib/libcrypto/doc/RSA_sign.pod | 62 - .../libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod | 59 - src/lib/libcrypto/doc/RSA_size.pod | 33 - src/lib/libcrypto/doc/SMIME_read_PKCS7.pod | 71 - src/lib/libcrypto/doc/SMIME_write_PKCS7.pod | 59 - .../libcrypto/doc/X509_NAME_ENTRY_get_object.pod | 72 - .../libcrypto/doc/X509_NAME_add_entry_by_txt.pod | 114 - .../libcrypto/doc/X509_NAME_get_index_by_NID.pod | 106 - src/lib/libcrypto/doc/X509_NAME_print_ex.pod | 105 - src/lib/libcrypto/doc/X509_new.pod | 37 - src/lib/libcrypto/doc/bn.pod | 158 -- src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod | 29 - src/lib/libcrypto/doc/d2i_DHparams.pod | 30 - src/lib/libcrypto/doc/d2i_DSAPublicKey.pod | 83 - src/lib/libcrypto/doc/d2i_RSAPublicKey.pod | 67 - src/lib/libcrypto/doc/d2i_X509.pod | 231 -- src/lib/libcrypto/doc/d2i_X509_ALGOR.pod | 30 - src/lib/libcrypto/doc/d2i_X509_CRL.pod | 37 - src/lib/libcrypto/doc/d2i_X509_NAME.pod | 31 - src/lib/libcrypto/doc/d2i_X509_REQ.pod | 36 - src/lib/libcrypto/doc/d2i_X509_SIG.pod | 30 - src/lib/libcrypto/doc/dh.pod | 78 - src/lib/libcrypto/doc/dsa.pod | 113 - src/lib/libcrypto/doc/engine.pod | 621 ----- src/lib/libcrypto/doc/evp.pod | 45 - src/lib/libcrypto/doc/lh_stats.pod | 60 - src/lib/libcrypto/doc/rsa.pod | 123 - src/lib/libcrypto/dsa/dsa.h | 272 --- src/lib/libcrypto/dsa/dsa_asn1.c | 140 -- src/lib/libcrypto/dsa/dsa_err.c | 114 - src/lib/libcrypto/dsa/dsa_gen.c | 305 --- src/lib/libcrypto/dsa/dsa_key.c | 121 - src/lib/libcrypto/dsa/dsa_lib.c | 308 --- src/lib/libcrypto/dsa/dsa_ossl.c | 393 ---- src/lib/libcrypto/dsa/dsa_sign.c | 106 - src/lib/libcrypto/dsa/dsa_vrf.c | 103 - src/lib/libcrypto/dso/dso.h | 322 --- src/lib/libcrypto/dso/dso_dlfcn.c | 325 --- src/lib/libcrypto/dso/dso_err.c | 139 -- src/lib/libcrypto/dso/dso_lib.c | 439 ---- src/lib/libcrypto/dso/dso_null.c | 86 - src/lib/libcrypto/dso/dso_openssl.c | 81 - src/lib/libcrypto/ec/ec.h | 243 -- src/lib/libcrypto/ec/ec_cvt.c | 80 - src/lib/libcrypto/ec/ec_err.c | 153 -- src/lib/libcrypto/ec/ec_lcl.h | 277 --- src/lib/libcrypto/ec/ec_lib.c | 656 ------ src/lib/libcrypto/ec/ec_mult.c | 485 ---- src/lib/libcrypto/ec/ecp_mont.c | 304 --- src/lib/libcrypto/ec/ecp_nist.c | 134 -- src/lib/libcrypto/ec/ecp_smpl.c | 1717 -------------- src/lib/libcrypto/engine/README | 211 -- src/lib/libcrypto/engine/eng_all.c | 113 - src/lib/libcrypto/engine/eng_cnf.c | 242 -- src/lib/libcrypto/engine/eng_ctrl.c | 391 ---- src/lib/libcrypto/engine/eng_dyn.c | 460 ---- src/lib/libcrypto/engine/eng_err.c | 170 -- src/lib/libcrypto/engine/eng_fat.c | 147 -- src/lib/libcrypto/engine/eng_init.c | 157 -- src/lib/libcrypto/engine/eng_int.h | 185 -- src/lib/libcrypto/engine/eng_lib.c | 321 --- src/lib/libcrypto/engine/eng_list.c | 394 ---- src/lib/libcrypto/engine/eng_openssl.c | 361 --- src/lib/libcrypto/engine/eng_pkey.c | 157 -- src/lib/libcrypto/engine/eng_table.c | 361 --- src/lib/libcrypto/engine/engine.h | 729 ------ src/lib/libcrypto/engine/tb_cipher.c | 145 -- src/lib/libcrypto/engine/tb_dh.c | 120 - src/lib/libcrypto/engine/tb_digest.c | 145 -- src/lib/libcrypto/engine/tb_dsa.c | 120 - src/lib/libcrypto/engine/tb_rand.c | 120 - src/lib/libcrypto/engine/tb_rsa.c | 120 - src/lib/libcrypto/err/err.c | 1079 --------- src/lib/libcrypto/err/err.h | 302 --- src/lib/libcrypto/err/err_all.c | 137 -- src/lib/libcrypto/err/err_prn.c | 106 - src/lib/libcrypto/err/openssl.ec | 82 - src/lib/libcrypto/evp/bio_b64.c | 567 ----- src/lib/libcrypto/evp/bio_enc.c | 426 ---- src/lib/libcrypto/evp/bio_md.c | 264 --- src/lib/libcrypto/evp/c_all.c | 84 - src/lib/libcrypto/evp/digest.c | 379 --- src/lib/libcrypto/evp/e_aes.c | 118 - src/lib/libcrypto/evp/e_bf.c | 88 - src/lib/libcrypto/evp/e_cast.c | 90 - src/lib/libcrypto/evp/e_des.c | 154 -- src/lib/libcrypto/evp/e_des3.c | 232 -- src/lib/libcrypto/evp/e_idea.c | 118 - src/lib/libcrypto/evp/e_null.c | 101 - src/lib/libcrypto/evp/e_old.c | 108 - src/lib/libcrypto/evp/e_rc2.c | 230 -- src/lib/libcrypto/evp/e_rc4.c | 134 -- src/lib/libcrypto/evp/e_xcbc_d.c | 122 - src/lib/libcrypto/evp/encode.c | 446 ---- src/lib/libcrypto/evp/evp.h | 910 -------- src/lib/libcrypto/evp/evp_enc.c | 592 ----- src/lib/libcrypto/evp/evp_err.c | 171 -- src/lib/libcrypto/evp/evp_key.c | 175 -- src/lib/libcrypto/evp/evp_lib.c | 168 -- src/lib/libcrypto/evp/evp_locl.h | 252 -- src/lib/libcrypto/evp/evp_pbe.c | 136 -- src/lib/libcrypto/evp/evp_pkey.c | 468 ---- src/lib/libcrypto/evp/m_dss.c | 95 - src/lib/libcrypto/evp/m_dss1.c | 102 - src/lib/libcrypto/evp/m_md4.c | 97 - src/lib/libcrypto/evp/m_md5.c | 97 - src/lib/libcrypto/evp/m_null.c | 95 - src/lib/libcrypto/evp/m_ripemd.c | 96 - src/lib/libcrypto/evp/m_sha1.c | 214 -- src/lib/libcrypto/evp/names.c | 126 - src/lib/libcrypto/evp/p5_crpt.c | 153 -- src/lib/libcrypto/evp/p5_crpt2.c | 256 -- src/lib/libcrypto/evp/p_dec.c | 87 - src/lib/libcrypto/evp/p_enc.c | 86 - src/lib/libcrypto/evp/p_lib.c | 337 --- src/lib/libcrypto/evp/p_open.c | 123 - src/lib/libcrypto/evp/p_seal.c | 115 - src/lib/libcrypto/evp/p_sign.c | 114 - src/lib/libcrypto/evp/p_verify.c | 101 - src/lib/libcrypto/ex_data.c | 636 ----- src/lib/libcrypto/hmac/hmac.c | 183 -- src/lib/libcrypto/hmac/hmac.h | 111 - src/lib/libcrypto/idea/idea.h | 103 - src/lib/libcrypto/krb5/krb5_asn.c | 167 -- src/lib/libcrypto/krb5/krb5_asn.h | 256 -- src/lib/libcrypto/lhash/lh_stats.c | 248 -- src/lib/libcrypto/lhash/lhash.c | 470 ---- src/lib/libcrypto/lhash/lhash.h | 199 -- src/lib/libcrypto/md32_common.h | 649 ------ src/lib/libcrypto/md4/md4.h | 119 - src/lib/libcrypto/md4/md4_dgst.c | 258 -- src/lib/libcrypto/md4/md4_locl.h | 154 -- src/lib/libcrypto/md4/md4_one.c | 97 - src/lib/libcrypto/md5/asm/md5-586.pl | 306 --- src/lib/libcrypto/md5/md5.h | 119 - src/lib/libcrypto/md5/md5_dgst.c | 292 --- src/lib/libcrypto/md5/md5_locl.h | 172 -- src/lib/libcrypto/md5/md5_one.c | 97 - src/lib/libcrypto/mem_clr.c | 75 - src/lib/libcrypto/mem_dbg.c | 787 ------- src/lib/libcrypto/o_str.c | 96 - src/lib/libcrypto/o_time.c | 217 -- src/lib/libcrypto/o_time.h | 66 - src/lib/libcrypto/objects/o_names.c | 369 --- src/lib/libcrypto/objects/obj_dat.c | 668 ------ src/lib/libcrypto/objects/obj_dat.pl | 307 --- src/lib/libcrypto/objects/obj_err.c | 105 - src/lib/libcrypto/objects/obj_lib.c | 127 - src/lib/libcrypto/objects/obj_mac.num | 675 ------ src/lib/libcrypto/objects/objects.README | 44 - src/lib/libcrypto/objects/objects.h | 1044 --------- src/lib/libcrypto/objects/objects.pl | 230 -- src/lib/libcrypto/objects/objects.txt | 952 -------- src/lib/libcrypto/ocsp/ocsp.h | 619 ----- src/lib/libcrypto/ocsp/ocsp_asn.c | 182 -- src/lib/libcrypto/ocsp/ocsp_cl.c | 370 --- src/lib/libcrypto/ocsp/ocsp_err.c | 143 -- src/lib/libcrypto/ocsp/ocsp_ext.c | 538 ----- src/lib/libcrypto/ocsp/ocsp_ht.c | 173 -- src/lib/libcrypto/ocsp/ocsp_lib.c | 262 --- src/lib/libcrypto/ocsp/ocsp_prn.c | 291 --- src/lib/libcrypto/ocsp/ocsp_srv.c | 264 --- src/lib/libcrypto/ocsp/ocsp_vfy.c | 444 ---- src/lib/libcrypto/opensslv.h | 89 - src/lib/libcrypto/ossl_typ.h | 122 - src/lib/libcrypto/pem/message | 16 - src/lib/libcrypto/pem/pem.h | 672 ------ src/lib/libcrypto/pem/pem2.h | 70 - src/lib/libcrypto/pem/pem_all.c | 315 --- src/lib/libcrypto/pem/pem_err.c | 135 -- src/lib/libcrypto/pem/pem_info.c | 365 --- src/lib/libcrypto/pem/pem_lib.c | 776 ------ src/lib/libcrypto/pem/pem_oth.c | 85 - src/lib/libcrypto/pem/pem_pk8.c | 243 -- src/lib/libcrypto/pem/pem_pkey.c | 145 -- src/lib/libcrypto/pem/pem_seal.c | 187 -- src/lib/libcrypto/pem/pem_sign.c | 102 - src/lib/libcrypto/pem/pem_x509.c | 69 - src/lib/libcrypto/pem/pem_xaux.c | 68 - src/lib/libcrypto/pem/pkcs7.lis | 22 - src/lib/libcrypto/perlasm/cbc.pl | 349 --- src/lib/libcrypto/perlasm/readme | 124 - src/lib/libcrypto/perlasm/x86asm.pl | 135 -- src/lib/libcrypto/pkcs12/p12_add.c | 224 -- src/lib/libcrypto/pkcs12/p12_asn.c | 125 - src/lib/libcrypto/pkcs12/p12_attr.c | 145 -- src/lib/libcrypto/pkcs12/p12_crpt.c | 124 - src/lib/libcrypto/pkcs12/p12_crt.c | 172 -- src/lib/libcrypto/pkcs12/p12_decr.c | 176 -- src/lib/libcrypto/pkcs12/p12_init.c | 92 - src/lib/libcrypto/pkcs12/p12_key.c | 206 -- src/lib/libcrypto/pkcs12/p12_kiss.c | 297 --- src/lib/libcrypto/pkcs12/p12_mutl.c | 182 -- src/lib/libcrypto/pkcs12/p12_npas.c | 217 -- src/lib/libcrypto/pkcs12/p12_p8d.c | 68 - src/lib/libcrypto/pkcs12/p12_p8e.c | 97 - src/lib/libcrypto/pkcs12/p12_utl.c | 146 -- src/lib/libcrypto/pkcs12/pk12err.c | 146 -- src/lib/libcrypto/pkcs12/pkcs12.h | 323 --- src/lib/libcrypto/pkcs7/pk7_asn1.c | 213 -- src/lib/libcrypto/pkcs7/pk7_attr.c | 140 -- src/lib/libcrypto/pkcs7/pk7_doit.c | 1013 -------- src/lib/libcrypto/pkcs7/pk7_lib.c | 500 ---- src/lib/libcrypto/pkcs7/pk7_mime.c | 734 ------ src/lib/libcrypto/pkcs7/pk7_smime.c | 469 ---- src/lib/libcrypto/pkcs7/pkcs7.h | 451 ---- src/lib/libcrypto/pkcs7/pkcs7err.c | 164 -- src/lib/libcrypto/rand/rand.h | 143 -- src/lib/libcrypto/rand/rand_err.c | 105 - src/lib/libcrypto/rand/rand_lib.c | 192 -- src/lib/libcrypto/rand/randfile.c | 285 --- src/lib/libcrypto/rc2/rc2.h | 104 - src/lib/libcrypto/rc2/rc2_cbc.c | 226 -- src/lib/libcrypto/rc2/rc2_ecb.c | 88 - src/lib/libcrypto/rc2/rc2_locl.h | 156 -- src/lib/libcrypto/rc2/rc2_skey.c | 152 -- src/lib/libcrypto/rc2/rc2cfb64.c | 122 - src/lib/libcrypto/rc2/rc2ofb64.c | 111 - src/lib/libcrypto/rc2/rrc2.doc | 219 -- src/lib/libcrypto/rc2/version | 22 - src/lib/libcrypto/rc4/asm/rc4-586.pl | 229 -- src/lib/libcrypto/rc4/asm/rc4-x86_64.pl | 150 -- src/lib/libcrypto/rc4/rc4.h | 91 - src/lib/libcrypto/rc4/rc4_enc.c | 315 --- src/lib/libcrypto/rc4/rc4_locl.h | 5 - src/lib/libcrypto/rc4/rc4_skey.c | 120 - src/lib/libcrypto/ripemd/README | 15 - src/lib/libcrypto/ripemd/asm/rmd-586.pl | 590 ----- src/lib/libcrypto/ripemd/ripemd.h | 106 - src/lib/libcrypto/ripemd/rmd_dgst.c | 495 ---- src/lib/libcrypto/ripemd/rmd_locl.h | 160 -- src/lib/libcrypto/ripemd/rmd_one.c | 78 - src/lib/libcrypto/ripemd/rmdconst.h | 399 ---- src/lib/libcrypto/rsa/rsa.h | 413 ---- src/lib/libcrypto/rsa/rsa_asn1.c | 121 - src/lib/libcrypto/rsa/rsa_chk.c | 184 -- src/lib/libcrypto/rsa/rsa_eay.c | 818 ------- src/lib/libcrypto/rsa/rsa_err.c | 165 -- src/lib/libcrypto/rsa/rsa_gen.c | 201 -- src/lib/libcrypto/rsa/rsa_lib.c | 414 ---- src/lib/libcrypto/rsa/rsa_none.c | 98 - src/lib/libcrypto/rsa/rsa_oaep.c | 212 -- src/lib/libcrypto/rsa/rsa_pk1.c | 224 -- src/lib/libcrypto/rsa/rsa_pss.c | 261 --- src/lib/libcrypto/rsa/rsa_saos.c | 149 -- src/lib/libcrypto/rsa/rsa_sign.c | 249 -- src/lib/libcrypto/rsa/rsa_ssl.c | 154 -- src/lib/libcrypto/rsa/rsa_x931.c | 177 -- src/lib/libcrypto/sha/asm/sha1-586.pl | 425 ---- src/lib/libcrypto/sha/asm/sha1-ia64.pl | 549 ----- src/lib/libcrypto/sha/sha.h | 128 - src/lib/libcrypto/sha/sha1_one.c | 78 - src/lib/libcrypto/sha/sha1dgst.c | 81 - src/lib/libcrypto/sha/sha_locl.h | 481 ---- src/lib/libcrypto/stack/safestack.h | 1574 ------------- src/lib/libcrypto/stack/stack.c | 340 --- src/lib/libcrypto/stack/stack.h | 108 - src/lib/libcrypto/txt_db/txt_db.c | 383 --- src/lib/libcrypto/txt_db/txt_db.h | 108 - src/lib/libcrypto/ui/ui.h | 387 --- src/lib/libcrypto/ui/ui_compat.h | 83 - src/lib/libcrypto/ui/ui_err.c | 115 - src/lib/libcrypto/ui/ui_lib.c | 902 ------- src/lib/libcrypto/ui/ui_locl.h | 148 -- src/lib/libcrypto/ui/ui_openssl.c | 674 ------ src/lib/libcrypto/ui/ui_util.c | 91 - src/lib/libcrypto/util/mkerr.pl | 653 ------ src/lib/libcrypto/util/mkstack.pl | 125 - src/lib/libcrypto/x509/by_dir.c | 380 --- src/lib/libcrypto/x509/by_file.c | 300 --- src/lib/libcrypto/x509/x509.h | 1259 ---------- src/lib/libcrypto/x509/x509_att.c | 326 --- src/lib/libcrypto/x509/x509_cmp.c | 440 ---- src/lib/libcrypto/x509/x509_d2.c | 107 - src/lib/libcrypto/x509/x509_def.c | 81 - src/lib/libcrypto/x509/x509_err.c | 160 -- src/lib/libcrypto/x509/x509_ext.c | 210 -- src/lib/libcrypto/x509/x509_lu.c | 557 ----- src/lib/libcrypto/x509/x509_obj.c | 226 -- src/lib/libcrypto/x509/x509_r2x.c | 112 - src/lib/libcrypto/x509/x509_req.c | 279 --- src/lib/libcrypto/x509/x509_set.c | 150 -- src/lib/libcrypto/x509/x509_trs.c | 287 --- src/lib/libcrypto/x509/x509_txt.c | 165 -- src/lib/libcrypto/x509/x509_v3.c | 268 --- src/lib/libcrypto/x509/x509_vfy.c | 1333 ----------- src/lib/libcrypto/x509/x509_vfy.h | 422 ---- src/lib/libcrypto/x509/x509cset.c | 170 -- src/lib/libcrypto/x509/x509name.c | 383 --- src/lib/libcrypto/x509/x509rset.c | 83 - src/lib/libcrypto/x509/x509spki.c | 120 - src/lib/libcrypto/x509/x509type.c | 115 - src/lib/libcrypto/x509/x_all.c | 489 ---- src/lib/libcrypto/x509v3/ext_dat.h | 118 - src/lib/libcrypto/x509v3/v3_akey.c | 190 -- src/lib/libcrypto/x509v3/v3_akeya.c | 72 - src/lib/libcrypto/x509v3/v3_alt.c | 458 ---- src/lib/libcrypto/x509v3/v3_bcons.c | 124 - src/lib/libcrypto/x509v3/v3_bitst.c | 147 -- src/lib/libcrypto/x509v3/v3_conf.c | 485 ---- src/lib/libcrypto/x509v3/v3_cpols.c | 431 ---- src/lib/libcrypto/x509v3/v3_crld.c | 162 -- src/lib/libcrypto/x509v3/v3_enum.c | 94 - src/lib/libcrypto/x509v3/v3_extku.c | 142 -- src/lib/libcrypto/x509v3/v3_genn.c | 101 - src/lib/libcrypto/x509v3/v3_ia5.c | 116 - src/lib/libcrypto/x509v3/v3_info.c | 194 -- src/lib/libcrypto/x509v3/v3_int.c | 76 - src/lib/libcrypto/x509v3/v3_lib.c | 302 --- src/lib/libcrypto/x509v3/v3_ocsp.c | 275 --- src/lib/libcrypto/x509v3/v3_pci.c | 313 --- src/lib/libcrypto/x509v3/v3_pcia.c | 55 - src/lib/libcrypto/x509v3/v3_pku.c | 108 - src/lib/libcrypto/x509v3/v3_prn.c | 233 -- src/lib/libcrypto/x509v3/v3_purp.c | 647 ----- src/lib/libcrypto/x509v3/v3_skey.c | 144 -- src/lib/libcrypto/x509v3/v3_sxnet.c | 262 --- src/lib/libcrypto/x509v3/v3_utl.c | 535 ----- src/lib/libcrypto/x509v3/v3err.c | 197 -- src/lib/libcrypto/x509v3/x509v3.h | 687 ------ src/lib/libssl/LICENSE | 127 - src/lib/libssl/bio_ssl.c | 598 ----- src/lib/libssl/doc/openssl.cnf | 313 --- src/lib/libssl/doc/openssl.txt | 1235 ---------- src/lib/libssl/doc/standards.txt | 261 --- src/lib/libssl/s23_clnt.c | 616 ----- src/lib/libssl/s23_lib.c | 236 -- src/lib/libssl/s23_pkt.c | 117 - src/lib/libssl/s23_srvr.c | 600 ----- src/lib/libssl/s3_both.c | 635 ----- src/lib/libssl/s3_clnt.c | 1985 ---------------- src/lib/libssl/s3_lib.c | 1799 -------------- src/lib/libssl/s3_pkt.c | 1310 ----------- src/lib/libssl/s3_srvr.c | 2082 ----------------- src/lib/libssl/shlib_version | 2 - src/lib/libssl/ssl.h | 1853 --------------- src/lib/libssl/ssl2.h | 268 --- src/lib/libssl/ssl23.h | 83 - src/lib/libssl/ssl3.h | 526 ----- src/lib/libssl/ssl_algs.c | 111 - src/lib/libssl/ssl_asn1.c | 398 ---- src/lib/libssl/ssl_cert.c | 898 ------- src/lib/libssl/ssl_ciph.c | 1139 --------- src/lib/libssl/ssl_err.c | 462 ---- src/lib/libssl/ssl_err2.c | 70 - src/lib/libssl/ssl_lib.c | 2355 ------------------- src/lib/libssl/ssl_locl.h | 623 ----- src/lib/libssl/ssl_rsa.c | 817 ------- src/lib/libssl/ssl_sess.c | 755 ------ src/lib/libssl/ssl_stat.c | 502 ---- src/lib/libssl/ssl_txt.c | 186 -- src/lib/libssl/t1_clnt.c | 97 - src/lib/libssl/t1_enc.c | 816 ------- src/lib/libssl/t1_lib.c | 149 -- src/lib/libssl/t1_meth.c | 96 - src/lib/libssl/t1_srvr.c | 98 - src/lib/libssl/test/CAss.cnf | 33 - src/lib/libssl/test/CAssdh.cnf | 24 - src/lib/libssl/test/CAssdsa.cnf | 23 - src/lib/libssl/test/CAssrsa.cnf | 24 - src/lib/libssl/test/P1ss.cnf | 37 - src/lib/libssl/test/P2ss.cnf | 45 - src/lib/libssl/test/Sssdsa.cnf | 27 - src/lib/libssl/test/Sssrsa.cnf | 26 - src/lib/libssl/test/Uss.cnf | 36 - src/lib/libssl/test/VMSca-response.1 | 1 - src/lib/libssl/test/VMSca-response.2 | 2 - src/lib/libssl/test/bctest | 111 - src/lib/libssl/test/methtest.c | 105 - src/lib/libssl/test/pkcs7-1.pem | 15 - src/lib/libssl/test/pkcs7.pem | 54 - src/lib/libssl/test/r160test.c | 57 - src/lib/libssl/test/tcrl | 85 - src/lib/libssl/test/test.cnf | 88 - src/lib/libssl/test/testca | 51 - src/lib/libssl/test/testcrl.pem | 16 - src/lib/libssl/test/testenc | 54 - src/lib/libssl/test/testgen | 44 - src/lib/libssl/test/testp7.pem | 46 - src/lib/libssl/test/testreq2.pem | 7 - src/lib/libssl/test/testrsa.pem | 9 - src/lib/libssl/test/testsid.pem | 12 - src/lib/libssl/test/testss | 163 -- src/lib/libssl/test/testssl | 145 -- src/lib/libssl/test/testsslproxy | 10 - src/lib/libssl/test/testx509.pem | 10 - src/lib/libssl/test/times | 113 - src/lib/libssl/test/tpkcs7 | 55 - src/lib/libssl/test/tpkcs7d | 48 - src/lib/libssl/test/treq | 90 - src/lib/libssl/test/trsa | 90 - src/lib/libssl/test/tsid | 85 - src/lib/libssl/test/tx509 | 85 - src/lib/libssl/test/v3-cert1.pem | 16 - src/lib/libssl/test/v3-cert2.pem | 16 - src/lib/libssl/tls1.h | 195 -- 994 files changed, 226696 deletions(-) delete mode 100644 src/lib/libc/crypt/Makefile.inc delete mode 100644 src/lib/libc/crypt/arc4random.3 delete mode 100644 src/lib/libc/crypt/arc4random.c delete mode 100644 src/lib/libc/crypt/bcrypt.c delete mode 100644 src/lib/libc/crypt/blowfish.3 delete mode 100644 src/lib/libc/crypt/blowfish.c delete mode 100644 src/lib/libc/crypt/cast.c delete mode 100644 src/lib/libc/crypt/crypt.3 delete mode 100644 src/lib/libc/crypt/crypt.c delete mode 100644 src/lib/libc/crypt/crypt2.c delete mode 100644 src/lib/libc/crypt/md5crypt.c delete mode 100644 src/lib/libc/crypt/skipjack.c delete mode 100644 src/lib/libc/include/ctype_private.h delete mode 100644 src/lib/libc/include/namespace.h delete mode 100644 src/lib/libc/include/thread_private.h delete mode 100644 src/lib/libc/net/Makefile.inc delete mode 100644 src/lib/libc/net/base64.c delete mode 100644 src/lib/libc/net/byteorder.3 delete mode 100644 src/lib/libc/net/ethers.3 delete mode 100644 src/lib/libc/net/ethers.c delete mode 100644 src/lib/libc/net/freeaddrinfo.c delete mode 100644 src/lib/libc/net/gai_strerror.3 delete mode 100644 src/lib/libc/net/gai_strerror.c delete mode 100644 src/lib/libc/net/getaddrinfo.3 delete mode 100644 src/lib/libc/net/getaddrinfo.c delete mode 100644 src/lib/libc/net/gethostbyname.3 delete mode 100644 src/lib/libc/net/gethostnamadr.c delete mode 100644 src/lib/libc/net/getifaddrs.3 delete mode 100644 src/lib/libc/net/getifaddrs.c delete mode 100644 src/lib/libc/net/getnameinfo.3 delete mode 100644 src/lib/libc/net/getnameinfo.c delete mode 100644 src/lib/libc/net/getnetbyaddr.c delete mode 100644 src/lib/libc/net/getnetbyname.c delete mode 100644 src/lib/libc/net/getnetent.3 delete mode 100644 src/lib/libc/net/getnetent.c delete mode 100644 src/lib/libc/net/getnetnamadr.c delete mode 100644 src/lib/libc/net/getproto.c delete mode 100644 src/lib/libc/net/getprotoent.3 delete mode 100644 src/lib/libc/net/getprotoent.c delete mode 100644 src/lib/libc/net/getprotoname.c delete mode 100644 src/lib/libc/net/getrrsetbyname.3 delete mode 100644 src/lib/libc/net/getrrsetbyname.c delete mode 100644 src/lib/libc/net/getservbyname.c delete mode 100644 src/lib/libc/net/getservbyport.c delete mode 100644 src/lib/libc/net/getservent.3 delete mode 100644 src/lib/libc/net/getservent.c delete mode 100644 src/lib/libc/net/herror.c delete mode 100644 src/lib/libc/net/htonl.c delete mode 100644 src/lib/libc/net/htons.c delete mode 100644 src/lib/libc/net/if_indextoname.3 delete mode 100644 src/lib/libc/net/if_indextoname.c delete mode 100644 src/lib/libc/net/if_nameindex.c delete mode 100644 src/lib/libc/net/if_nametoindex.c delete mode 100644 src/lib/libc/net/inet.3 delete mode 100644 src/lib/libc/net/inet6_opt_init.3 delete mode 100644 src/lib/libc/net/inet6_option_space.3 delete mode 100644 src/lib/libc/net/inet6_rth_space.3 delete mode 100644 src/lib/libc/net/inet6_rthdr_space.3 delete mode 100644 src/lib/libc/net/inet_addr.c delete mode 100644 src/lib/libc/net/inet_lnaof.c delete mode 100644 src/lib/libc/net/inet_makeaddr.c delete mode 100644 src/lib/libc/net/inet_net.3 delete mode 100644 src/lib/libc/net/inet_net_ntop.c delete mode 100644 src/lib/libc/net/inet_net_pton.c delete mode 100644 src/lib/libc/net/inet_neta.c delete mode 100644 src/lib/libc/net/inet_netof.c delete mode 100644 src/lib/libc/net/inet_network.c delete mode 100644 src/lib/libc/net/inet_ntoa.c delete mode 100644 src/lib/libc/net/inet_ntop.c delete mode 100644 src/lib/libc/net/inet_pton.c delete mode 100644 src/lib/libc/net/ip6opt.c delete mode 100644 src/lib/libc/net/link_addr.3 delete mode 100644 src/lib/libc/net/linkaddr.c delete mode 100644 src/lib/libc/net/net_addrcmp.3 delete mode 100644 src/lib/libc/net/net_addrcmp.c delete mode 100644 src/lib/libc/net/nsap_addr.c delete mode 100644 src/lib/libc/net/ntohl.c delete mode 100644 src/lib/libc/net/ntohs.c delete mode 100644 src/lib/libc/net/rcmd.3 delete mode 100644 src/lib/libc/net/rcmd.c delete mode 100644 src/lib/libc/net/rcmdsh.3 delete mode 100644 src/lib/libc/net/rcmdsh.c delete mode 100644 src/lib/libc/net/recv.c delete mode 100644 src/lib/libc/net/res_comp.c delete mode 100644 src/lib/libc/net/res_data.c delete mode 100644 src/lib/libc/net/res_debug.c delete mode 100644 src/lib/libc/net/res_debug_syms.c delete mode 100644 src/lib/libc/net/res_init.c delete mode 100644 src/lib/libc/net/res_mkquery.c delete mode 100644 src/lib/libc/net/res_query.c delete mode 100644 src/lib/libc/net/res_random.c delete mode 100644 src/lib/libc/net/res_send.c delete mode 100644 src/lib/libc/net/resolver.3 delete mode 100644 src/lib/libc/net/rresvport.c delete mode 100644 src/lib/libc/net/rthdr.c delete mode 100644 src/lib/libc/net/send.c delete mode 100644 src/lib/libc/net/sethostent.c delete mode 100644 src/lib/libc/net/vars6.c delete mode 100644 src/lib/libc/stdlib/Makefile.inc delete mode 100644 src/lib/libc/stdlib/_Exit.c delete mode 100644 src/lib/libc/stdlib/_rand48.c delete mode 100644 src/lib/libc/stdlib/a64l.3 delete mode 100644 src/lib/libc/stdlib/a64l.c delete mode 100644 src/lib/libc/stdlib/abort.3 delete mode 100644 src/lib/libc/stdlib/abort.c delete mode 100644 src/lib/libc/stdlib/abs.3 delete mode 100644 src/lib/libc/stdlib/abs.c delete mode 100644 src/lib/libc/stdlib/alloca.3 delete mode 100644 src/lib/libc/stdlib/atexit.3 delete mode 100644 src/lib/libc/stdlib/atexit.c delete mode 100644 src/lib/libc/stdlib/atexit.h delete mode 100644 src/lib/libc/stdlib/atof.3 delete mode 100644 src/lib/libc/stdlib/atof.c delete mode 100644 src/lib/libc/stdlib/atoi.3 delete mode 100644 src/lib/libc/stdlib/atoi.c delete mode 100644 src/lib/libc/stdlib/atol.3 delete mode 100644 src/lib/libc/stdlib/atol.c delete mode 100644 src/lib/libc/stdlib/atoll.3 delete mode 100644 src/lib/libc/stdlib/atoll.c delete mode 100644 src/lib/libc/stdlib/bsearch.3 delete mode 100644 src/lib/libc/stdlib/bsearch.c delete mode 100644 src/lib/libc/stdlib/calloc.c delete mode 100644 src/lib/libc/stdlib/cfree.c delete mode 100644 src/lib/libc/stdlib/div.3 delete mode 100644 src/lib/libc/stdlib/div.c delete mode 100644 src/lib/libc/stdlib/drand48.c delete mode 100644 src/lib/libc/stdlib/ecvt.3 delete mode 100644 src/lib/libc/stdlib/ecvt.c delete mode 100644 src/lib/libc/stdlib/erand48.c delete mode 100644 src/lib/libc/stdlib/exit.3 delete mode 100644 src/lib/libc/stdlib/exit.c delete mode 100644 src/lib/libc/stdlib/gcvt.c delete mode 100644 src/lib/libc/stdlib/getenv.3 delete mode 100644 src/lib/libc/stdlib/getenv.c delete mode 100644 src/lib/libc/stdlib/getopt.3 delete mode 100644 src/lib/libc/stdlib/getopt_long.3 delete mode 100644 src/lib/libc/stdlib/getopt_long.c delete mode 100644 src/lib/libc/stdlib/getsubopt.3 delete mode 100644 src/lib/libc/stdlib/getsubopt.c delete mode 100644 src/lib/libc/stdlib/hcreate.3 delete mode 100644 src/lib/libc/stdlib/hcreate.c delete mode 100644 src/lib/libc/stdlib/heapsort.c delete mode 100644 src/lib/libc/stdlib/imaxabs.3 delete mode 100644 src/lib/libc/stdlib/imaxabs.c delete mode 100644 src/lib/libc/stdlib/imaxdiv.3 delete mode 100644 src/lib/libc/stdlib/imaxdiv.c delete mode 100644 src/lib/libc/stdlib/insque.3 delete mode 100644 src/lib/libc/stdlib/insque.c delete mode 100644 src/lib/libc/stdlib/jrand48.c delete mode 100644 src/lib/libc/stdlib/l64a.c delete mode 100644 src/lib/libc/stdlib/labs.3 delete mode 100644 src/lib/libc/stdlib/labs.c delete mode 100644 src/lib/libc/stdlib/lcong48.c delete mode 100644 src/lib/libc/stdlib/ldiv.3 delete mode 100644 src/lib/libc/stdlib/ldiv.c delete mode 100644 src/lib/libc/stdlib/llabs.c delete mode 100644 src/lib/libc/stdlib/lldiv.3 delete mode 100644 src/lib/libc/stdlib/lldiv.c delete mode 100644 src/lib/libc/stdlib/lrand48.c delete mode 100644 src/lib/libc/stdlib/lsearch.3 delete mode 100644 src/lib/libc/stdlib/lsearch.c delete mode 100644 src/lib/libc/stdlib/malloc.3 delete mode 100644 src/lib/libc/stdlib/malloc.c delete mode 100644 src/lib/libc/stdlib/merge.c delete mode 100644 src/lib/libc/stdlib/mrand48.c delete mode 100644 src/lib/libc/stdlib/nrand48.c delete mode 100644 src/lib/libc/stdlib/putenv.c delete mode 100644 src/lib/libc/stdlib/qabs.3 delete mode 100644 src/lib/libc/stdlib/qabs.c delete mode 100644 src/lib/libc/stdlib/qdiv.3 delete mode 100644 src/lib/libc/stdlib/qdiv.c delete mode 100644 src/lib/libc/stdlib/qsort.3 delete mode 100644 src/lib/libc/stdlib/qsort.c delete mode 100644 src/lib/libc/stdlib/radixsort.3 delete mode 100644 src/lib/libc/stdlib/radixsort.c delete mode 100644 src/lib/libc/stdlib/rand.3 delete mode 100644 src/lib/libc/stdlib/rand.c delete mode 100644 src/lib/libc/stdlib/rand48.3 delete mode 100644 src/lib/libc/stdlib/rand48.h delete mode 100644 src/lib/libc/stdlib/random.3 delete mode 100644 src/lib/libc/stdlib/random.c delete mode 100644 src/lib/libc/stdlib/realpath.3 delete mode 100644 src/lib/libc/stdlib/realpath.c delete mode 100644 src/lib/libc/stdlib/remque.c delete mode 100644 src/lib/libc/stdlib/seed48.c delete mode 100644 src/lib/libc/stdlib/setenv.c delete mode 100644 src/lib/libc/stdlib/srand48.c delete mode 100644 src/lib/libc/stdlib/strtod.3 delete mode 100644 src/lib/libc/stdlib/strtod.c delete mode 100644 src/lib/libc/stdlib/strtof.c delete mode 100644 src/lib/libc/stdlib/strtoimax.c delete mode 100644 src/lib/libc/stdlib/strtol.3 delete mode 100644 src/lib/libc/stdlib/strtol.c delete mode 100644 src/lib/libc/stdlib/strtoll.c delete mode 100644 src/lib/libc/stdlib/strtonum.3 delete mode 100644 src/lib/libc/stdlib/strtonum.c delete mode 100644 src/lib/libc/stdlib/strtoul.3 delete mode 100644 src/lib/libc/stdlib/strtoul.c delete mode 100644 src/lib/libc/stdlib/strtoull.c delete mode 100644 src/lib/libc/stdlib/strtoumax.c delete mode 100644 src/lib/libc/stdlib/system.3 delete mode 100644 src/lib/libc/stdlib/system.c delete mode 100644 src/lib/libc/stdlib/tfind.c delete mode 100644 src/lib/libc/stdlib/tsearch.3 delete mode 100644 src/lib/libc/stdlib/tsearch.c delete mode 100644 src/lib/libc/string/Makefile.inc delete mode 100644 src/lib/libc/string/bcmp.3 delete mode 100644 src/lib/libc/string/bcmp.c delete mode 100644 src/lib/libc/string/bcopy.3 delete mode 100644 src/lib/libc/string/bcopy.c delete mode 100644 src/lib/libc/string/bm.3 delete mode 100644 src/lib/libc/string/bm.c delete mode 100644 src/lib/libc/string/bstring.3 delete mode 100644 src/lib/libc/string/bzero.3 delete mode 100644 src/lib/libc/string/bzero.c delete mode 100644 src/lib/libc/string/ffs.3 delete mode 100644 src/lib/libc/string/ffs.c delete mode 100644 src/lib/libc/string/index.c delete mode 100644 src/lib/libc/string/memccpy.3 delete mode 100644 src/lib/libc/string/memccpy.c delete mode 100644 src/lib/libc/string/memchr.3 delete mode 100644 src/lib/libc/string/memchr.c delete mode 100644 src/lib/libc/string/memcmp.3 delete mode 100644 src/lib/libc/string/memcmp.c delete mode 100644 src/lib/libc/string/memcpy.3 delete mode 100644 src/lib/libc/string/memmove.3 delete mode 100644 src/lib/libc/string/memrchr.c delete mode 100644 src/lib/libc/string/memset.3 delete mode 100644 src/lib/libc/string/memset.c delete mode 100644 src/lib/libc/string/rindex.c delete mode 100644 src/lib/libc/string/strcasecmp.3 delete mode 100644 src/lib/libc/string/strcasecmp.c delete mode 100644 src/lib/libc/string/strcasestr.c delete mode 100644 src/lib/libc/string/strcat.3 delete mode 100644 src/lib/libc/string/strcat.c delete mode 100644 src/lib/libc/string/strchr.3 delete mode 100644 src/lib/libc/string/strcmp.3 delete mode 100644 src/lib/libc/string/strcmp.c delete mode 100644 src/lib/libc/string/strcoll.3 delete mode 100644 src/lib/libc/string/strcoll.c delete mode 100644 src/lib/libc/string/strcpy.3 delete mode 100644 src/lib/libc/string/strcpy.c delete mode 100644 src/lib/libc/string/strcspn.3 delete mode 100644 src/lib/libc/string/strcspn.c delete mode 100644 src/lib/libc/string/strdup.3 delete mode 100644 src/lib/libc/string/strdup.c delete mode 100644 src/lib/libc/string/strerror.3 delete mode 100644 src/lib/libc/string/strerror.c delete mode 100644 src/lib/libc/string/strerror_r.c delete mode 100644 src/lib/libc/string/string.3 delete mode 100644 src/lib/libc/string/strlcat.c delete mode 100644 src/lib/libc/string/strlcpy.3 delete mode 100644 src/lib/libc/string/strlcpy.c delete mode 100644 src/lib/libc/string/strlen.3 delete mode 100644 src/lib/libc/string/strlen.c delete mode 100644 src/lib/libc/string/strmode.3 delete mode 100644 src/lib/libc/string/strmode.c delete mode 100644 src/lib/libc/string/strncat.c delete mode 100644 src/lib/libc/string/strncmp.c delete mode 100644 src/lib/libc/string/strncpy.c delete mode 100644 src/lib/libc/string/strpbrk.3 delete mode 100644 src/lib/libc/string/strpbrk.c delete mode 100644 src/lib/libc/string/strrchr.3 delete mode 100644 src/lib/libc/string/strsep.3 delete mode 100644 src/lib/libc/string/strsep.c delete mode 100644 src/lib/libc/string/strsignal.3 delete mode 100644 src/lib/libc/string/strsignal.c delete mode 100644 src/lib/libc/string/strspn.3 delete mode 100644 src/lib/libc/string/strspn.c delete mode 100644 src/lib/libc/string/strstr.3 delete mode 100644 src/lib/libc/string/strstr.c delete mode 100644 src/lib/libc/string/strtok.3 delete mode 100644 src/lib/libc/string/strtok.c delete mode 100644 src/lib/libc/string/strxfrm.3 delete mode 100644 src/lib/libc/string/strxfrm.c delete mode 100644 src/lib/libc/string/swab.3 delete mode 100644 src/lib/libc/string/swab.c delete mode 100644 src/lib/libc/string/wcscat.c delete mode 100644 src/lib/libc/string/wcschr.c delete mode 100644 src/lib/libc/string/wcscmp.c delete mode 100644 src/lib/libc/string/wcscpy.c delete mode 100644 src/lib/libc/string/wcscspn.c delete mode 100644 src/lib/libc/string/wcslcat.c delete mode 100644 src/lib/libc/string/wcslcpy.c delete mode 100644 src/lib/libc/string/wcslen.c delete mode 100644 src/lib/libc/string/wcsncat.c delete mode 100644 src/lib/libc/string/wcsncmp.c delete mode 100644 src/lib/libc/string/wcsncpy.c delete mode 100644 src/lib/libc/string/wcspbrk.c delete mode 100644 src/lib/libc/string/wcsrchr.c delete mode 100644 src/lib/libc/string/wcsspn.c delete mode 100644 src/lib/libc/string/wcsstr.c delete mode 100644 src/lib/libc/string/wcstok.3 delete mode 100644 src/lib/libc/string/wcstok.c delete mode 100644 src/lib/libc/string/wcswcs.c delete mode 100644 src/lib/libc/string/wcswidth.c delete mode 100644 src/lib/libc/string/wmemchr.3 delete mode 100644 src/lib/libc/string/wmemchr.c delete mode 100644 src/lib/libc/string/wmemcmp.c delete mode 100644 src/lib/libc/string/wmemcpy.c delete mode 100644 src/lib/libc/string/wmemmove.c delete mode 100644 src/lib/libc/string/wmemset.c delete mode 100644 src/lib/libcrypto/aes/README delete mode 100644 src/lib/libcrypto/aes/aes.h delete mode 100644 src/lib/libcrypto/aes/aes_cbc.c delete mode 100644 src/lib/libcrypto/aes/aes_cfb.c delete mode 100644 src/lib/libcrypto/aes/aes_core.c delete mode 100644 src/lib/libcrypto/aes/aes_ctr.c delete mode 100644 src/lib/libcrypto/aes/aes_ecb.c delete mode 100644 src/lib/libcrypto/aes/aes_locl.h delete mode 100644 src/lib/libcrypto/aes/aes_misc.c delete mode 100644 src/lib/libcrypto/aes/aes_ofb.c delete mode 100644 src/lib/libcrypto/aes/asm/aes-586.pl delete mode 100644 src/lib/libcrypto/asn1/a_bitstr.c delete mode 100644 src/lib/libcrypto/asn1/a_bool.c delete mode 100644 src/lib/libcrypto/asn1/a_bytes.c delete mode 100644 src/lib/libcrypto/asn1/a_d2i_fp.c delete mode 100644 src/lib/libcrypto/asn1/a_digest.c delete mode 100644 src/lib/libcrypto/asn1/a_dup.c delete mode 100644 src/lib/libcrypto/asn1/a_enum.c delete mode 100644 src/lib/libcrypto/asn1/a_i2d_fp.c delete mode 100644 src/lib/libcrypto/asn1/a_int.c delete mode 100644 src/lib/libcrypto/asn1/a_mbstr.c delete mode 100644 src/lib/libcrypto/asn1/a_object.c delete mode 100644 src/lib/libcrypto/asn1/a_octet.c delete mode 100644 src/lib/libcrypto/asn1/a_print.c delete mode 100644 src/lib/libcrypto/asn1/a_set.c delete mode 100644 src/lib/libcrypto/asn1/a_sign.c delete mode 100644 src/lib/libcrypto/asn1/a_strex.c delete mode 100644 src/lib/libcrypto/asn1/a_strnid.c delete mode 100644 src/lib/libcrypto/asn1/a_time.c delete mode 100644 src/lib/libcrypto/asn1/a_type.c delete mode 100644 src/lib/libcrypto/asn1/a_utf8.c delete mode 100644 src/lib/libcrypto/asn1/a_verify.c delete mode 100644 src/lib/libcrypto/asn1/asn1.h delete mode 100644 src/lib/libcrypto/asn1/asn1_err.c delete mode 100644 src/lib/libcrypto/asn1/asn1_lib.c delete mode 100644 src/lib/libcrypto/asn1/asn1_mac.h delete mode 100644 src/lib/libcrypto/asn1/asn1_par.c delete mode 100644 src/lib/libcrypto/asn1/asn1t.h delete mode 100644 src/lib/libcrypto/asn1/asn_moid.c delete mode 100644 src/lib/libcrypto/asn1/asn_pack.c delete mode 100644 src/lib/libcrypto/asn1/charmap.h delete mode 100644 src/lib/libcrypto/asn1/charmap.pl delete mode 100644 src/lib/libcrypto/asn1/d2i_pr.c delete mode 100644 src/lib/libcrypto/asn1/d2i_pu.c delete mode 100644 src/lib/libcrypto/asn1/evp_asn1.c delete mode 100644 src/lib/libcrypto/asn1/f_enum.c delete mode 100644 src/lib/libcrypto/asn1/f_int.c delete mode 100644 src/lib/libcrypto/asn1/f_string.c delete mode 100644 src/lib/libcrypto/asn1/i2d_pr.c delete mode 100644 src/lib/libcrypto/asn1/i2d_pu.c delete mode 100644 src/lib/libcrypto/asn1/n_pkey.c delete mode 100644 src/lib/libcrypto/asn1/nsseq.c delete mode 100644 src/lib/libcrypto/asn1/p5_pbe.c delete mode 100644 src/lib/libcrypto/asn1/p5_pbev2.c delete mode 100644 src/lib/libcrypto/asn1/p8_pkey.c delete mode 100644 src/lib/libcrypto/asn1/t_bitst.c delete mode 100644 src/lib/libcrypto/asn1/t_crl.c delete mode 100644 src/lib/libcrypto/asn1/t_pkey.c delete mode 100644 src/lib/libcrypto/asn1/t_req.c delete mode 100644 src/lib/libcrypto/asn1/t_spki.c delete mode 100644 src/lib/libcrypto/asn1/t_x509.c delete mode 100644 src/lib/libcrypto/asn1/t_x509a.c delete mode 100644 src/lib/libcrypto/asn1/tasn_dec.c delete mode 100644 src/lib/libcrypto/asn1/tasn_enc.c delete mode 100644 src/lib/libcrypto/asn1/tasn_fre.c delete mode 100644 src/lib/libcrypto/asn1/tasn_new.c delete mode 100644 src/lib/libcrypto/asn1/tasn_prn.c delete mode 100644 src/lib/libcrypto/asn1/tasn_typ.c delete mode 100644 src/lib/libcrypto/asn1/tasn_utl.c delete mode 100644 src/lib/libcrypto/asn1/x_algor.c delete mode 100644 src/lib/libcrypto/asn1/x_attrib.c delete mode 100644 src/lib/libcrypto/asn1/x_bignum.c delete mode 100644 src/lib/libcrypto/asn1/x_crl.c delete mode 100644 src/lib/libcrypto/asn1/x_exten.c delete mode 100644 src/lib/libcrypto/asn1/x_info.c delete mode 100644 src/lib/libcrypto/asn1/x_long.c delete mode 100644 src/lib/libcrypto/asn1/x_name.c delete mode 100644 src/lib/libcrypto/asn1/x_pkey.c delete mode 100644 src/lib/libcrypto/asn1/x_pubkey.c delete mode 100644 src/lib/libcrypto/asn1/x_req.c delete mode 100644 src/lib/libcrypto/asn1/x_sig.c delete mode 100644 src/lib/libcrypto/asn1/x_spki.c delete mode 100644 src/lib/libcrypto/asn1/x_val.c delete mode 100644 src/lib/libcrypto/asn1/x_x509.c delete mode 100644 src/lib/libcrypto/asn1/x_x509a.c delete mode 100644 src/lib/libcrypto/bf/COPYRIGHT delete mode 100644 src/lib/libcrypto/bf/INSTALL delete mode 100644 src/lib/libcrypto/bf/README delete mode 100644 src/lib/libcrypto/bf/VERSION delete mode 100644 src/lib/libcrypto/bf/asm/bf-586.pl delete mode 100644 src/lib/libcrypto/bf/bf_cbc.c delete mode 100644 src/lib/libcrypto/bf/bf_cfb64.c delete mode 100644 src/lib/libcrypto/bf/bf_ecb.c delete mode 100644 src/lib/libcrypto/bf/bf_enc.c delete mode 100644 src/lib/libcrypto/bf/bf_locl.h delete mode 100644 src/lib/libcrypto/bf/bf_ofb64.c delete mode 100644 src/lib/libcrypto/bf/bf_pi.h delete mode 100644 src/lib/libcrypto/bf/bf_skey.c delete mode 100644 src/lib/libcrypto/bf/blowfish.h delete mode 100644 src/lib/libcrypto/bio/b_dump.c delete mode 100644 src/lib/libcrypto/bio/b_print.c delete mode 100644 src/lib/libcrypto/bio/b_sock.c delete mode 100644 src/lib/libcrypto/bio/bf_buff.c delete mode 100644 src/lib/libcrypto/bio/bf_lbuf.c delete mode 100644 src/lib/libcrypto/bio/bf_nbio.c delete mode 100644 src/lib/libcrypto/bio/bf_null.c delete mode 100644 src/lib/libcrypto/bio/bio.h delete mode 100644 src/lib/libcrypto/bio/bio_cb.c delete mode 100644 src/lib/libcrypto/bio/bio_err.c delete mode 100644 src/lib/libcrypto/bio/bio_lib.c delete mode 100644 src/lib/libcrypto/bio/bss_acpt.c delete mode 100644 src/lib/libcrypto/bio/bss_bio.c delete mode 100644 src/lib/libcrypto/bio/bss_conn.c delete mode 100644 src/lib/libcrypto/bio/bss_fd.c delete mode 100644 src/lib/libcrypto/bio/bss_file.c delete mode 100644 src/lib/libcrypto/bio/bss_log.c delete mode 100644 src/lib/libcrypto/bio/bss_mem.c delete mode 100644 src/lib/libcrypto/bio/bss_null.c delete mode 100644 src/lib/libcrypto/bio/bss_sock.c delete mode 100644 src/lib/libcrypto/bn/asm/bn-586.pl delete mode 100644 src/lib/libcrypto/bn/asm/co-586.pl delete mode 100644 src/lib/libcrypto/bn/asm/ia64.S delete mode 100644 src/lib/libcrypto/bn/asm/pa-risc2.s delete mode 100644 src/lib/libcrypto/bn/asm/pa-risc2W.s delete mode 100644 src/lib/libcrypto/bn/asm/ppc.pl delete mode 100644 src/lib/libcrypto/bn/asm/sparcv8.S delete mode 100644 src/lib/libcrypto/bn/asm/sparcv8plus.S delete mode 100644 src/lib/libcrypto/bn/asm/x86.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/add.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/comba.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/div.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/mul.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/mul_add.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/sqr.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86/sub.pl delete mode 100644 src/lib/libcrypto/bn/asm/x86_64-gcc.c delete mode 100644 src/lib/libcrypto/bn/bn.h delete mode 100644 src/lib/libcrypto/bn/bn_add.c delete mode 100644 src/lib/libcrypto/bn/bn_asm.c delete mode 100644 src/lib/libcrypto/bn/bn_blind.c delete mode 100644 src/lib/libcrypto/bn/bn_ctx.c delete mode 100644 src/lib/libcrypto/bn/bn_div.c delete mode 100644 src/lib/libcrypto/bn/bn_err.c delete mode 100644 src/lib/libcrypto/bn/bn_exp.c delete mode 100644 src/lib/libcrypto/bn/bn_exp2.c delete mode 100644 src/lib/libcrypto/bn/bn_gcd.c delete mode 100644 src/lib/libcrypto/bn/bn_kron.c delete mode 100644 src/lib/libcrypto/bn/bn_lcl.h delete mode 100644 src/lib/libcrypto/bn/bn_lib.c delete mode 100644 src/lib/libcrypto/bn/bn_mod.c delete mode 100644 src/lib/libcrypto/bn/bn_mont.c delete mode 100644 src/lib/libcrypto/bn/bn_mpi.c delete mode 100644 src/lib/libcrypto/bn/bn_mul.c delete mode 100644 src/lib/libcrypto/bn/bn_prime.c delete mode 100644 src/lib/libcrypto/bn/bn_prime.h delete mode 100644 src/lib/libcrypto/bn/bn_prime.pl delete mode 100644 src/lib/libcrypto/bn/bn_print.c delete mode 100644 src/lib/libcrypto/bn/bn_rand.c delete mode 100644 src/lib/libcrypto/bn/bn_recp.c delete mode 100644 src/lib/libcrypto/bn/bn_shift.c delete mode 100644 src/lib/libcrypto/bn/bn_sqr.c delete mode 100644 src/lib/libcrypto/bn/bn_sqrt.c delete mode 100644 src/lib/libcrypto/bn/bn_word.c delete mode 100644 src/lib/libcrypto/bn/bn_x931p.c delete mode 100644 src/lib/libcrypto/buffer/buf_err.c delete mode 100644 src/lib/libcrypto/buffer/buffer.c delete mode 100644 src/lib/libcrypto/buffer/buffer.h delete mode 100644 src/lib/libcrypto/cast/asm/cast-586.pl delete mode 100644 src/lib/libcrypto/cast/c_cfb64.c delete mode 100644 src/lib/libcrypto/cast/c_ecb.c delete mode 100644 src/lib/libcrypto/cast/c_enc.c delete mode 100644 src/lib/libcrypto/cast/c_ofb64.c delete mode 100644 src/lib/libcrypto/cast/c_skey.c delete mode 100644 src/lib/libcrypto/cast/cast.h delete mode 100644 src/lib/libcrypto/cast/cast_lcl.h delete mode 100644 src/lib/libcrypto/cast/cast_s.h delete mode 100644 src/lib/libcrypto/comp/c_rle.c delete mode 100644 src/lib/libcrypto/comp/c_zlib.c delete mode 100644 src/lib/libcrypto/comp/comp.h delete mode 100644 src/lib/libcrypto/comp/comp_err.c delete mode 100644 src/lib/libcrypto/comp/comp_lib.c delete mode 100644 src/lib/libcrypto/conf/README delete mode 100644 src/lib/libcrypto/conf/conf.h delete mode 100644 src/lib/libcrypto/conf/conf_api.c delete mode 100644 src/lib/libcrypto/conf/conf_api.h delete mode 100644 src/lib/libcrypto/conf/conf_def.c delete mode 100644 src/lib/libcrypto/conf/conf_def.h delete mode 100644 src/lib/libcrypto/conf/conf_err.c delete mode 100644 src/lib/libcrypto/conf/conf_lib.c delete mode 100644 src/lib/libcrypto/conf/conf_mall.c delete mode 100644 src/lib/libcrypto/conf/conf_mod.c delete mode 100644 src/lib/libcrypto/conf/conf_sap.c delete mode 100644 src/lib/libcrypto/conf/keysets.pl delete mode 100644 src/lib/libcrypto/conf/ssleay.cnf delete mode 100644 src/lib/libcrypto/cpt_err.c delete mode 100644 src/lib/libcrypto/cryptlib.c delete mode 100644 src/lib/libcrypto/cryptlib.h delete mode 100644 src/lib/libcrypto/crypto.h delete mode 100644 src/lib/libcrypto/cversion.c delete mode 100644 src/lib/libcrypto/des/COPYRIGHT delete mode 100644 src/lib/libcrypto/des/asm/crypt586.pl delete mode 100644 src/lib/libcrypto/des/asm/des-586.pl delete mode 100644 src/lib/libcrypto/des/asm/desboth.pl delete mode 100644 src/lib/libcrypto/des/cbc_cksm.c delete mode 100644 src/lib/libcrypto/des/cbc_enc.c delete mode 100644 src/lib/libcrypto/des/cfb64ede.c delete mode 100644 src/lib/libcrypto/des/cfb64enc.c delete mode 100644 src/lib/libcrypto/des/cfb_enc.c delete mode 100644 src/lib/libcrypto/des/des.h delete mode 100644 src/lib/libcrypto/des/des_enc.c delete mode 100644 src/lib/libcrypto/des/des_locl.h delete mode 100644 src/lib/libcrypto/des/ecb3_enc.c delete mode 100644 src/lib/libcrypto/des/ecb_enc.c delete mode 100644 src/lib/libcrypto/des/ede_cbcm_enc.c delete mode 100644 src/lib/libcrypto/des/enc_read.c delete mode 100644 src/lib/libcrypto/des/enc_writ.c delete mode 100644 src/lib/libcrypto/des/fcrypt.c delete mode 100644 src/lib/libcrypto/des/fcrypt_b.c delete mode 100644 src/lib/libcrypto/des/ncbc_enc.c delete mode 100644 src/lib/libcrypto/des/ofb64ede.c delete mode 100644 src/lib/libcrypto/des/ofb64enc.c delete mode 100644 src/lib/libcrypto/des/ofb_enc.c delete mode 100644 src/lib/libcrypto/des/pcbc_enc.c delete mode 100644 src/lib/libcrypto/des/qud_cksm.c delete mode 100644 src/lib/libcrypto/des/rand_key.c delete mode 100644 src/lib/libcrypto/des/set_key.c delete mode 100644 src/lib/libcrypto/des/spr.h delete mode 100644 src/lib/libcrypto/des/str2key.c delete mode 100644 src/lib/libcrypto/des/xcbc_enc.c delete mode 100644 src/lib/libcrypto/dh/dh.h delete mode 100644 src/lib/libcrypto/dh/dh_asn1.c delete mode 100644 src/lib/libcrypto/dh/dh_check.c delete mode 100644 src/lib/libcrypto/dh/dh_err.c delete mode 100644 src/lib/libcrypto/dh/dh_gen.c delete mode 100644 src/lib/libcrypto/dh/dh_key.c delete mode 100644 src/lib/libcrypto/dh/dh_lib.c delete mode 100644 src/lib/libcrypto/doc/DH_generate_key.pod delete mode 100644 src/lib/libcrypto/doc/DH_generate_parameters.pod delete mode 100644 src/lib/libcrypto/doc/DH_get_ex_new_index.pod delete mode 100644 src/lib/libcrypto/doc/DH_new.pod delete mode 100644 src/lib/libcrypto/doc/DH_set_method.pod delete mode 100644 src/lib/libcrypto/doc/DH_size.pod delete mode 100644 src/lib/libcrypto/doc/DSA_SIG_new.pod delete mode 100644 src/lib/libcrypto/doc/DSA_do_sign.pod delete mode 100644 src/lib/libcrypto/doc/DSA_dup_DH.pod delete mode 100644 src/lib/libcrypto/doc/DSA_generate_key.pod delete mode 100644 src/lib/libcrypto/doc/DSA_generate_parameters.pod delete mode 100644 src/lib/libcrypto/doc/DSA_get_ex_new_index.pod delete mode 100644 src/lib/libcrypto/doc/DSA_new.pod delete mode 100644 src/lib/libcrypto/doc/DSA_set_method.pod delete mode 100644 src/lib/libcrypto/doc/DSA_sign.pod delete mode 100644 src/lib/libcrypto/doc/DSA_size.pod delete mode 100644 src/lib/libcrypto/doc/ERR_GET_LIB.pod delete mode 100644 src/lib/libcrypto/doc/ERR_clear_error.pod delete mode 100644 src/lib/libcrypto/doc/ERR_error_string.pod delete mode 100644 src/lib/libcrypto/doc/ERR_get_error.pod delete mode 100644 src/lib/libcrypto/doc/ERR_load_crypto_strings.pod delete mode 100644 src/lib/libcrypto/doc/ERR_load_strings.pod delete mode 100644 src/lib/libcrypto/doc/ERR_print_errors.pod delete mode 100644 src/lib/libcrypto/doc/ERR_put_error.pod delete mode 100644 src/lib/libcrypto/doc/ERR_remove_state.pod delete mode 100644 src/lib/libcrypto/doc/EVP_BytesToKey.pod delete mode 100644 src/lib/libcrypto/doc/EVP_DigestInit.pod delete mode 100644 src/lib/libcrypto/doc/EVP_EncryptInit.pod delete mode 100644 src/lib/libcrypto/doc/EVP_OpenInit.pod delete mode 100644 src/lib/libcrypto/doc/EVP_PKEY_new.pod delete mode 100644 src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod delete mode 100644 src/lib/libcrypto/doc/EVP_SealInit.pod delete mode 100644 src/lib/libcrypto/doc/EVP_SignInit.pod delete mode 100644 src/lib/libcrypto/doc/EVP_VerifyInit.pod delete mode 100644 src/lib/libcrypto/doc/OBJ_nid2obj.pod delete mode 100644 src/lib/libcrypto/doc/OPENSSL_VERSION_NUMBER.pod delete mode 100644 src/lib/libcrypto/doc/OPENSSL_config.pod delete mode 100644 src/lib/libcrypto/doc/OPENSSL_load_builtin_modules.pod delete mode 100644 src/lib/libcrypto/doc/OpenSSL_add_all_algorithms.pod delete mode 100644 src/lib/libcrypto/doc/PKCS12_create.pod delete mode 100644 src/lib/libcrypto/doc/PKCS12_parse.pod delete mode 100644 src/lib/libcrypto/doc/PKCS7_decrypt.pod delete mode 100644 src/lib/libcrypto/doc/PKCS7_encrypt.pod delete mode 100644 src/lib/libcrypto/doc/PKCS7_sign.pod delete mode 100644 src/lib/libcrypto/doc/PKCS7_verify.pod delete mode 100644 src/lib/libcrypto/doc/RAND_add.pod delete mode 100644 src/lib/libcrypto/doc/RAND_bytes.pod delete mode 100644 src/lib/libcrypto/doc/RAND_cleanup.pod delete mode 100644 src/lib/libcrypto/doc/RAND_load_file.pod delete mode 100644 src/lib/libcrypto/doc/RAND_set_rand_method.pod delete mode 100644 src/lib/libcrypto/doc/RSA_blinding_on.pod delete mode 100644 src/lib/libcrypto/doc/RSA_check_key.pod delete mode 100644 src/lib/libcrypto/doc/RSA_generate_key.pod delete mode 100644 src/lib/libcrypto/doc/RSA_get_ex_new_index.pod delete mode 100644 src/lib/libcrypto/doc/RSA_new.pod delete mode 100644 src/lib/libcrypto/doc/RSA_padding_add_PKCS1_type_1.pod delete mode 100644 src/lib/libcrypto/doc/RSA_print.pod delete mode 100644 src/lib/libcrypto/doc/RSA_private_encrypt.pod delete mode 100644 src/lib/libcrypto/doc/RSA_public_encrypt.pod delete mode 100644 src/lib/libcrypto/doc/RSA_set_method.pod delete mode 100644 src/lib/libcrypto/doc/RSA_sign.pod delete mode 100644 src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod delete mode 100644 src/lib/libcrypto/doc/RSA_size.pod delete mode 100644 src/lib/libcrypto/doc/SMIME_read_PKCS7.pod delete mode 100644 src/lib/libcrypto/doc/SMIME_write_PKCS7.pod delete mode 100644 src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod delete mode 100644 src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod delete mode 100644 src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod delete mode 100644 src/lib/libcrypto/doc/X509_NAME_print_ex.pod delete mode 100644 src/lib/libcrypto/doc/X509_new.pod delete mode 100644 src/lib/libcrypto/doc/bn.pod delete mode 100644 src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod delete mode 100644 src/lib/libcrypto/doc/d2i_DHparams.pod delete mode 100644 src/lib/libcrypto/doc/d2i_DSAPublicKey.pod delete mode 100644 src/lib/libcrypto/doc/d2i_RSAPublicKey.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509_ALGOR.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509_CRL.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509_NAME.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509_REQ.pod delete mode 100644 src/lib/libcrypto/doc/d2i_X509_SIG.pod delete mode 100644 src/lib/libcrypto/doc/dh.pod delete mode 100644 src/lib/libcrypto/doc/dsa.pod delete mode 100644 src/lib/libcrypto/doc/engine.pod delete mode 100644 src/lib/libcrypto/doc/evp.pod delete mode 100644 src/lib/libcrypto/doc/lh_stats.pod delete mode 100644 src/lib/libcrypto/doc/rsa.pod delete mode 100644 src/lib/libcrypto/dsa/dsa.h delete mode 100644 src/lib/libcrypto/dsa/dsa_asn1.c delete mode 100644 src/lib/libcrypto/dsa/dsa_err.c delete mode 100644 src/lib/libcrypto/dsa/dsa_gen.c delete mode 100644 src/lib/libcrypto/dsa/dsa_key.c delete mode 100644 src/lib/libcrypto/dsa/dsa_lib.c delete mode 100644 src/lib/libcrypto/dsa/dsa_ossl.c delete mode 100644 src/lib/libcrypto/dsa/dsa_sign.c delete mode 100644 src/lib/libcrypto/dsa/dsa_vrf.c delete mode 100644 src/lib/libcrypto/dso/dso.h delete mode 100644 src/lib/libcrypto/dso/dso_dlfcn.c delete mode 100644 src/lib/libcrypto/dso/dso_err.c delete mode 100644 src/lib/libcrypto/dso/dso_lib.c delete mode 100644 src/lib/libcrypto/dso/dso_null.c delete mode 100644 src/lib/libcrypto/dso/dso_openssl.c delete mode 100644 src/lib/libcrypto/ec/ec.h delete mode 100644 src/lib/libcrypto/ec/ec_cvt.c delete mode 100644 src/lib/libcrypto/ec/ec_err.c delete mode 100644 src/lib/libcrypto/ec/ec_lcl.h delete mode 100644 src/lib/libcrypto/ec/ec_lib.c delete mode 100644 src/lib/libcrypto/ec/ec_mult.c delete mode 100644 src/lib/libcrypto/ec/ecp_mont.c delete mode 100644 src/lib/libcrypto/ec/ecp_nist.c delete mode 100644 src/lib/libcrypto/ec/ecp_smpl.c delete mode 100644 src/lib/libcrypto/engine/README delete mode 100644 src/lib/libcrypto/engine/eng_all.c delete mode 100644 src/lib/libcrypto/engine/eng_cnf.c delete mode 100644 src/lib/libcrypto/engine/eng_ctrl.c delete mode 100644 src/lib/libcrypto/engine/eng_dyn.c delete mode 100644 src/lib/libcrypto/engine/eng_err.c delete mode 100644 src/lib/libcrypto/engine/eng_fat.c delete mode 100644 src/lib/libcrypto/engine/eng_init.c delete mode 100644 src/lib/libcrypto/engine/eng_int.h delete mode 100644 src/lib/libcrypto/engine/eng_lib.c delete mode 100644 src/lib/libcrypto/engine/eng_list.c delete mode 100644 src/lib/libcrypto/engine/eng_openssl.c delete mode 100644 src/lib/libcrypto/engine/eng_pkey.c delete mode 100644 src/lib/libcrypto/engine/eng_table.c delete mode 100644 src/lib/libcrypto/engine/engine.h delete mode 100644 src/lib/libcrypto/engine/tb_cipher.c delete mode 100644 src/lib/libcrypto/engine/tb_dh.c delete mode 100644 src/lib/libcrypto/engine/tb_digest.c delete mode 100644 src/lib/libcrypto/engine/tb_dsa.c delete mode 100644 src/lib/libcrypto/engine/tb_rand.c delete mode 100644 src/lib/libcrypto/engine/tb_rsa.c delete mode 100644 src/lib/libcrypto/err/err.c delete mode 100644 src/lib/libcrypto/err/err.h delete mode 100644 src/lib/libcrypto/err/err_all.c delete mode 100644 src/lib/libcrypto/err/err_prn.c delete mode 100644 src/lib/libcrypto/err/openssl.ec delete mode 100644 src/lib/libcrypto/evp/bio_b64.c delete mode 100644 src/lib/libcrypto/evp/bio_enc.c delete mode 100644 src/lib/libcrypto/evp/bio_md.c delete mode 100644 src/lib/libcrypto/evp/c_all.c delete mode 100644 src/lib/libcrypto/evp/digest.c delete mode 100644 src/lib/libcrypto/evp/e_aes.c delete mode 100644 src/lib/libcrypto/evp/e_bf.c delete mode 100644 src/lib/libcrypto/evp/e_cast.c delete mode 100644 src/lib/libcrypto/evp/e_des.c delete mode 100644 src/lib/libcrypto/evp/e_des3.c delete mode 100644 src/lib/libcrypto/evp/e_idea.c delete mode 100644 src/lib/libcrypto/evp/e_null.c delete mode 100644 src/lib/libcrypto/evp/e_old.c delete mode 100644 src/lib/libcrypto/evp/e_rc2.c delete mode 100644 src/lib/libcrypto/evp/e_rc4.c delete mode 100644 src/lib/libcrypto/evp/e_xcbc_d.c delete mode 100644 src/lib/libcrypto/evp/encode.c delete mode 100644 src/lib/libcrypto/evp/evp.h delete mode 100644 src/lib/libcrypto/evp/evp_enc.c delete mode 100644 src/lib/libcrypto/evp/evp_err.c delete mode 100644 src/lib/libcrypto/evp/evp_key.c delete mode 100644 src/lib/libcrypto/evp/evp_lib.c delete mode 100644 src/lib/libcrypto/evp/evp_locl.h delete mode 100644 src/lib/libcrypto/evp/evp_pbe.c delete mode 100644 src/lib/libcrypto/evp/evp_pkey.c delete mode 100644 src/lib/libcrypto/evp/m_dss.c delete mode 100644 src/lib/libcrypto/evp/m_dss1.c delete mode 100644 src/lib/libcrypto/evp/m_md4.c delete mode 100644 src/lib/libcrypto/evp/m_md5.c delete mode 100644 src/lib/libcrypto/evp/m_null.c delete mode 100644 src/lib/libcrypto/evp/m_ripemd.c delete mode 100644 src/lib/libcrypto/evp/m_sha1.c delete mode 100644 src/lib/libcrypto/evp/names.c delete mode 100644 src/lib/libcrypto/evp/p5_crpt.c delete mode 100644 src/lib/libcrypto/evp/p5_crpt2.c delete mode 100644 src/lib/libcrypto/evp/p_dec.c delete mode 100644 src/lib/libcrypto/evp/p_enc.c delete mode 100644 src/lib/libcrypto/evp/p_lib.c delete mode 100644 src/lib/libcrypto/evp/p_open.c delete mode 100644 src/lib/libcrypto/evp/p_seal.c delete mode 100644 src/lib/libcrypto/evp/p_sign.c delete mode 100644 src/lib/libcrypto/evp/p_verify.c delete mode 100644 src/lib/libcrypto/ex_data.c delete mode 100644 src/lib/libcrypto/hmac/hmac.c delete mode 100644 src/lib/libcrypto/hmac/hmac.h delete mode 100644 src/lib/libcrypto/idea/idea.h delete mode 100644 src/lib/libcrypto/krb5/krb5_asn.c delete mode 100644 src/lib/libcrypto/krb5/krb5_asn.h delete mode 100644 src/lib/libcrypto/lhash/lh_stats.c delete mode 100644 src/lib/libcrypto/lhash/lhash.c delete mode 100644 src/lib/libcrypto/lhash/lhash.h delete mode 100644 src/lib/libcrypto/md32_common.h delete mode 100644 src/lib/libcrypto/md4/md4.h delete mode 100644 src/lib/libcrypto/md4/md4_dgst.c delete mode 100644 src/lib/libcrypto/md4/md4_locl.h delete mode 100644 src/lib/libcrypto/md4/md4_one.c delete mode 100644 src/lib/libcrypto/md5/asm/md5-586.pl delete mode 100644 src/lib/libcrypto/md5/md5.h delete mode 100644 src/lib/libcrypto/md5/md5_dgst.c delete mode 100644 src/lib/libcrypto/md5/md5_locl.h delete mode 100644 src/lib/libcrypto/md5/md5_one.c delete mode 100644 src/lib/libcrypto/mem_clr.c delete mode 100644 src/lib/libcrypto/mem_dbg.c delete mode 100644 src/lib/libcrypto/o_str.c delete mode 100644 src/lib/libcrypto/o_time.c delete mode 100644 src/lib/libcrypto/o_time.h delete mode 100644 src/lib/libcrypto/objects/o_names.c delete mode 100644 src/lib/libcrypto/objects/obj_dat.c delete mode 100644 src/lib/libcrypto/objects/obj_dat.pl delete mode 100644 src/lib/libcrypto/objects/obj_err.c delete mode 100644 src/lib/libcrypto/objects/obj_lib.c delete mode 100644 src/lib/libcrypto/objects/obj_mac.num delete mode 100644 src/lib/libcrypto/objects/objects.README delete mode 100644 src/lib/libcrypto/objects/objects.h delete mode 100644 src/lib/libcrypto/objects/objects.pl delete mode 100644 src/lib/libcrypto/objects/objects.txt delete mode 100644 src/lib/libcrypto/ocsp/ocsp.h delete mode 100644 src/lib/libcrypto/ocsp/ocsp_asn.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_cl.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_err.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_ext.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_ht.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_lib.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_prn.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_srv.c delete mode 100644 src/lib/libcrypto/ocsp/ocsp_vfy.c delete mode 100644 src/lib/libcrypto/opensslv.h delete mode 100644 src/lib/libcrypto/ossl_typ.h delete mode 100644 src/lib/libcrypto/pem/message delete mode 100644 src/lib/libcrypto/pem/pem.h delete mode 100644 src/lib/libcrypto/pem/pem2.h delete mode 100644 src/lib/libcrypto/pem/pem_all.c delete mode 100644 src/lib/libcrypto/pem/pem_err.c delete mode 100644 src/lib/libcrypto/pem/pem_info.c delete mode 100644 src/lib/libcrypto/pem/pem_lib.c delete mode 100644 src/lib/libcrypto/pem/pem_oth.c delete mode 100644 src/lib/libcrypto/pem/pem_pk8.c delete mode 100644 src/lib/libcrypto/pem/pem_pkey.c delete mode 100644 src/lib/libcrypto/pem/pem_seal.c delete mode 100644 src/lib/libcrypto/pem/pem_sign.c delete mode 100644 src/lib/libcrypto/pem/pem_x509.c delete mode 100644 src/lib/libcrypto/pem/pem_xaux.c delete mode 100644 src/lib/libcrypto/pem/pkcs7.lis delete mode 100644 src/lib/libcrypto/perlasm/cbc.pl delete mode 100644 src/lib/libcrypto/perlasm/readme delete mode 100644 src/lib/libcrypto/perlasm/x86asm.pl delete mode 100644 src/lib/libcrypto/pkcs12/p12_add.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_asn.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_attr.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_crpt.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_crt.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_decr.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_init.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_key.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_kiss.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_mutl.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_npas.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_p8d.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_p8e.c delete mode 100644 src/lib/libcrypto/pkcs12/p12_utl.c delete mode 100644 src/lib/libcrypto/pkcs12/pk12err.c delete mode 100644 src/lib/libcrypto/pkcs12/pkcs12.h delete mode 100644 src/lib/libcrypto/pkcs7/pk7_asn1.c delete mode 100644 src/lib/libcrypto/pkcs7/pk7_attr.c delete mode 100644 src/lib/libcrypto/pkcs7/pk7_doit.c delete mode 100644 src/lib/libcrypto/pkcs7/pk7_lib.c delete mode 100644 src/lib/libcrypto/pkcs7/pk7_mime.c delete mode 100644 src/lib/libcrypto/pkcs7/pk7_smime.c delete mode 100644 src/lib/libcrypto/pkcs7/pkcs7.h delete mode 100644 src/lib/libcrypto/pkcs7/pkcs7err.c delete mode 100644 src/lib/libcrypto/rand/rand.h delete mode 100644 src/lib/libcrypto/rand/rand_err.c delete mode 100644 src/lib/libcrypto/rand/rand_lib.c delete mode 100644 src/lib/libcrypto/rand/randfile.c delete mode 100644 src/lib/libcrypto/rc2/rc2.h delete mode 100644 src/lib/libcrypto/rc2/rc2_cbc.c delete mode 100644 src/lib/libcrypto/rc2/rc2_ecb.c delete mode 100644 src/lib/libcrypto/rc2/rc2_locl.h delete mode 100644 src/lib/libcrypto/rc2/rc2_skey.c delete mode 100644 src/lib/libcrypto/rc2/rc2cfb64.c delete mode 100644 src/lib/libcrypto/rc2/rc2ofb64.c delete mode 100644 src/lib/libcrypto/rc2/rrc2.doc delete mode 100644 src/lib/libcrypto/rc2/version delete mode 100644 src/lib/libcrypto/rc4/asm/rc4-586.pl delete mode 100755 src/lib/libcrypto/rc4/asm/rc4-x86_64.pl delete mode 100644 src/lib/libcrypto/rc4/rc4.h delete mode 100644 src/lib/libcrypto/rc4/rc4_enc.c delete mode 100644 src/lib/libcrypto/rc4/rc4_locl.h delete mode 100644 src/lib/libcrypto/rc4/rc4_skey.c delete mode 100644 src/lib/libcrypto/ripemd/README delete mode 100644 src/lib/libcrypto/ripemd/asm/rmd-586.pl delete mode 100644 src/lib/libcrypto/ripemd/ripemd.h delete mode 100644 src/lib/libcrypto/ripemd/rmd_dgst.c delete mode 100644 src/lib/libcrypto/ripemd/rmd_locl.h delete mode 100644 src/lib/libcrypto/ripemd/rmd_one.c delete mode 100644 src/lib/libcrypto/ripemd/rmdconst.h delete mode 100644 src/lib/libcrypto/rsa/rsa.h delete mode 100644 src/lib/libcrypto/rsa/rsa_asn1.c delete mode 100644 src/lib/libcrypto/rsa/rsa_chk.c delete mode 100644 src/lib/libcrypto/rsa/rsa_eay.c delete mode 100644 src/lib/libcrypto/rsa/rsa_err.c delete mode 100644 src/lib/libcrypto/rsa/rsa_gen.c delete mode 100644 src/lib/libcrypto/rsa/rsa_lib.c delete mode 100644 src/lib/libcrypto/rsa/rsa_none.c delete mode 100644 src/lib/libcrypto/rsa/rsa_oaep.c delete mode 100644 src/lib/libcrypto/rsa/rsa_pk1.c delete mode 100644 src/lib/libcrypto/rsa/rsa_pss.c delete mode 100644 src/lib/libcrypto/rsa/rsa_saos.c delete mode 100644 src/lib/libcrypto/rsa/rsa_sign.c delete mode 100644 src/lib/libcrypto/rsa/rsa_ssl.c delete mode 100644 src/lib/libcrypto/rsa/rsa_x931.c delete mode 100644 src/lib/libcrypto/sha/asm/sha1-586.pl delete mode 100644 src/lib/libcrypto/sha/asm/sha1-ia64.pl delete mode 100644 src/lib/libcrypto/sha/sha.h delete mode 100644 src/lib/libcrypto/sha/sha1_one.c delete mode 100644 src/lib/libcrypto/sha/sha1dgst.c delete mode 100644 src/lib/libcrypto/sha/sha_locl.h delete mode 100644 src/lib/libcrypto/stack/safestack.h delete mode 100644 src/lib/libcrypto/stack/stack.c delete mode 100644 src/lib/libcrypto/stack/stack.h delete mode 100644 src/lib/libcrypto/txt_db/txt_db.c delete mode 100644 src/lib/libcrypto/txt_db/txt_db.h delete mode 100644 src/lib/libcrypto/ui/ui.h delete mode 100644 src/lib/libcrypto/ui/ui_compat.h delete mode 100644 src/lib/libcrypto/ui/ui_err.c delete mode 100644 src/lib/libcrypto/ui/ui_lib.c delete mode 100644 src/lib/libcrypto/ui/ui_locl.h delete mode 100644 src/lib/libcrypto/ui/ui_openssl.c delete mode 100644 src/lib/libcrypto/ui/ui_util.c delete mode 100644 src/lib/libcrypto/util/mkerr.pl delete mode 100644 src/lib/libcrypto/util/mkstack.pl delete mode 100644 src/lib/libcrypto/x509/by_dir.c delete mode 100644 src/lib/libcrypto/x509/by_file.c delete mode 100644 src/lib/libcrypto/x509/x509.h delete mode 100644 src/lib/libcrypto/x509/x509_att.c delete mode 100644 src/lib/libcrypto/x509/x509_cmp.c delete mode 100644 src/lib/libcrypto/x509/x509_d2.c delete mode 100644 src/lib/libcrypto/x509/x509_def.c delete mode 100644 src/lib/libcrypto/x509/x509_err.c delete mode 100644 src/lib/libcrypto/x509/x509_ext.c delete mode 100644 src/lib/libcrypto/x509/x509_lu.c delete mode 100644 src/lib/libcrypto/x509/x509_obj.c delete mode 100644 src/lib/libcrypto/x509/x509_r2x.c delete mode 100644 src/lib/libcrypto/x509/x509_req.c delete mode 100644 src/lib/libcrypto/x509/x509_set.c delete mode 100644 src/lib/libcrypto/x509/x509_trs.c delete mode 100644 src/lib/libcrypto/x509/x509_txt.c delete mode 100644 src/lib/libcrypto/x509/x509_v3.c delete mode 100644 src/lib/libcrypto/x509/x509_vfy.c delete mode 100644 src/lib/libcrypto/x509/x509_vfy.h delete mode 100644 src/lib/libcrypto/x509/x509cset.c delete mode 100644 src/lib/libcrypto/x509/x509name.c delete mode 100644 src/lib/libcrypto/x509/x509rset.c delete mode 100644 src/lib/libcrypto/x509/x509spki.c delete mode 100644 src/lib/libcrypto/x509/x509type.c delete mode 100644 src/lib/libcrypto/x509/x_all.c delete mode 100644 src/lib/libcrypto/x509v3/ext_dat.h delete mode 100644 src/lib/libcrypto/x509v3/v3_akey.c delete mode 100644 src/lib/libcrypto/x509v3/v3_akeya.c delete mode 100644 src/lib/libcrypto/x509v3/v3_alt.c delete mode 100644 src/lib/libcrypto/x509v3/v3_bcons.c delete mode 100644 src/lib/libcrypto/x509v3/v3_bitst.c delete mode 100644 src/lib/libcrypto/x509v3/v3_conf.c delete mode 100644 src/lib/libcrypto/x509v3/v3_cpols.c delete mode 100644 src/lib/libcrypto/x509v3/v3_crld.c delete mode 100644 src/lib/libcrypto/x509v3/v3_enum.c delete mode 100644 src/lib/libcrypto/x509v3/v3_extku.c delete mode 100644 src/lib/libcrypto/x509v3/v3_genn.c delete mode 100644 src/lib/libcrypto/x509v3/v3_ia5.c delete mode 100644 src/lib/libcrypto/x509v3/v3_info.c delete mode 100644 src/lib/libcrypto/x509v3/v3_int.c delete mode 100644 src/lib/libcrypto/x509v3/v3_lib.c delete mode 100644 src/lib/libcrypto/x509v3/v3_ocsp.c delete mode 100644 src/lib/libcrypto/x509v3/v3_pci.c delete mode 100644 src/lib/libcrypto/x509v3/v3_pcia.c delete mode 100644 src/lib/libcrypto/x509v3/v3_pku.c delete mode 100644 src/lib/libcrypto/x509v3/v3_prn.c delete mode 100644 src/lib/libcrypto/x509v3/v3_purp.c delete mode 100644 src/lib/libcrypto/x509v3/v3_skey.c delete mode 100644 src/lib/libcrypto/x509v3/v3_sxnet.c delete mode 100644 src/lib/libcrypto/x509v3/v3_utl.c delete mode 100644 src/lib/libcrypto/x509v3/v3err.c delete mode 100644 src/lib/libcrypto/x509v3/x509v3.h delete mode 100644 src/lib/libssl/LICENSE delete mode 100644 src/lib/libssl/bio_ssl.c delete mode 100644 src/lib/libssl/doc/openssl.cnf delete mode 100644 src/lib/libssl/doc/openssl.txt delete mode 100644 src/lib/libssl/doc/standards.txt delete mode 100644 src/lib/libssl/s23_clnt.c delete mode 100644 src/lib/libssl/s23_lib.c delete mode 100644 src/lib/libssl/s23_pkt.c delete mode 100644 src/lib/libssl/s23_srvr.c delete mode 100644 src/lib/libssl/s3_both.c delete mode 100644 src/lib/libssl/s3_clnt.c delete mode 100644 src/lib/libssl/s3_lib.c delete mode 100644 src/lib/libssl/s3_pkt.c delete mode 100644 src/lib/libssl/s3_srvr.c delete mode 100644 src/lib/libssl/shlib_version delete mode 100644 src/lib/libssl/ssl.h delete mode 100644 src/lib/libssl/ssl2.h delete mode 100644 src/lib/libssl/ssl23.h delete mode 100644 src/lib/libssl/ssl3.h delete mode 100644 src/lib/libssl/ssl_algs.c delete mode 100644 src/lib/libssl/ssl_asn1.c delete mode 100644 src/lib/libssl/ssl_cert.c delete mode 100644 src/lib/libssl/ssl_ciph.c delete mode 100644 src/lib/libssl/ssl_err.c delete mode 100644 src/lib/libssl/ssl_err2.c delete mode 100644 src/lib/libssl/ssl_lib.c delete mode 100644 src/lib/libssl/ssl_locl.h delete mode 100644 src/lib/libssl/ssl_rsa.c delete mode 100644 src/lib/libssl/ssl_sess.c delete mode 100644 src/lib/libssl/ssl_stat.c delete mode 100644 src/lib/libssl/ssl_txt.c delete mode 100644 src/lib/libssl/t1_clnt.c delete mode 100644 src/lib/libssl/t1_enc.c delete mode 100644 src/lib/libssl/t1_lib.c delete mode 100644 src/lib/libssl/t1_meth.c delete mode 100644 src/lib/libssl/t1_srvr.c delete mode 100644 src/lib/libssl/test/CAss.cnf delete mode 100644 src/lib/libssl/test/CAssdh.cnf delete mode 100644 src/lib/libssl/test/CAssdsa.cnf delete mode 100644 src/lib/libssl/test/CAssrsa.cnf delete mode 100644 src/lib/libssl/test/P1ss.cnf delete mode 100644 src/lib/libssl/test/P2ss.cnf delete mode 100644 src/lib/libssl/test/Sssdsa.cnf delete mode 100644 src/lib/libssl/test/Sssrsa.cnf delete mode 100644 src/lib/libssl/test/Uss.cnf delete mode 100644 src/lib/libssl/test/VMSca-response.1 delete mode 100644 src/lib/libssl/test/VMSca-response.2 delete mode 100644 src/lib/libssl/test/bctest delete mode 100644 src/lib/libssl/test/methtest.c delete mode 100644 src/lib/libssl/test/pkcs7-1.pem delete mode 100644 src/lib/libssl/test/pkcs7.pem delete mode 100644 src/lib/libssl/test/r160test.c delete mode 100644 src/lib/libssl/test/tcrl delete mode 100644 src/lib/libssl/test/test.cnf delete mode 100644 src/lib/libssl/test/testca delete mode 100644 src/lib/libssl/test/testcrl.pem delete mode 100644 src/lib/libssl/test/testenc delete mode 100644 src/lib/libssl/test/testgen delete mode 100644 src/lib/libssl/test/testp7.pem delete mode 100644 src/lib/libssl/test/testreq2.pem delete mode 100644 src/lib/libssl/test/testrsa.pem delete mode 100644 src/lib/libssl/test/testsid.pem delete mode 100644 src/lib/libssl/test/testss delete mode 100644 src/lib/libssl/test/testssl delete mode 100644 src/lib/libssl/test/testsslproxy delete mode 100644 src/lib/libssl/test/testx509.pem delete mode 100644 src/lib/libssl/test/times delete mode 100644 src/lib/libssl/test/tpkcs7 delete mode 100644 src/lib/libssl/test/tpkcs7d delete mode 100644 src/lib/libssl/test/treq delete mode 100644 src/lib/libssl/test/trsa delete mode 100644 src/lib/libssl/test/tsid delete mode 100644 src/lib/libssl/test/tx509 delete mode 100644 src/lib/libssl/test/v3-cert1.pem delete mode 100644 src/lib/libssl/test/v3-cert2.pem delete mode 100644 src/lib/libssl/tls1.h (limited to 'src/lib') diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc deleted file mode 100644 index d961f36b52..0000000000 --- a/src/lib/libc/crypt/Makefile.inc +++ /dev/null @@ -1,16 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.16 2008/03/16 22:08:12 deraadt Exp $ - -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/crypt ${LIBCSRCDIR}/crypt - -SRCS+= cast.c crypt.c crypt2.c md5crypt.c arc4random.c blowfish.c -SRCS+= bcrypt.c skipjack.c - -MAN+= crypt.3 blowfish.3 arc4random.3 -MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_cipher.3 -MLINKS+=crypt.3 bcrypt_gensalt.3 crypt.3 bcrypt.3 crypt.3 md5crypt.3 -MLINKS+=crypt.3 des_setkey.3 blowfish.3 blf_key.3 blowfish.3 blf_enc.3 -MLINKS+=blowfish.3 blf_dec.3 blowfish.3 blf_ecb_encrypt.3 -MLINKS+=blowfish.3 blf_ecb_decrypt.3 blowfish.3 blf_cbc_encrypt.3 -MLINKS+=blowfish.3 blf_cbc_decrypt.3 -MLINKS+=arc4random.3 arc4random_stir.3 arc4random.3 arc4random_addrandom.3 -MLINKS+=arc4random.3 arc4random_buf.3 arc4random.3 arc4random_uniform.3 diff --git a/src/lib/libc/crypt/arc4random.3 b/src/lib/libc/crypt/arc4random.3 deleted file mode 100644 index 2a12c6d94e..0000000000 --- a/src/lib/libc/crypt/arc4random.3 +++ /dev/null @@ -1,136 +0,0 @@ -.\" $OpenBSD: arc4random.3,v 1.26 2008/06/09 06:04:02 jmc Exp $ -.\" -.\" Copyright 1997 Niels Provos -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Niels Provos. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: June 9 2008 $ -.Dt ARC4RANDOM 3 -.Os -.Sh NAME -.Nm arc4random , -.Nm arc4random_buf , -.Nm arc4random_uniform , -.Nm arc4random_stir , -.Nm arc4random_addrandom -.Nd arc4 random number generator -.Sh SYNOPSIS -.Fd #include -.Ft u_int32_t -.Fn arc4random "void" -.Ft void -.Fn arc4random_buf "void *buf" "size_t nbytes" -.Ft u_int32_t -.Fn arc4random_uniform "u_int32_t upper_bound" -.Ft void -.Fn arc4random_stir "void" -.Ft void -.Fn arc4random_addrandom "u_char *dat" "int datlen" -.Sh DESCRIPTION -The -.Fn arc4random -function provides a high quality 32-bit pseudo-random -number very quickly. -.Fn arc4random -seeds itself on a regular basis from the kernel strong random number -subsystem described in -.Xr random 4 . -On each call, an ARC4 generator is used to generate a new result. -The -.Fn arc4random -function uses the ARC4 cipher key stream generator, -which uses 8*8 8-bit S-Boxes. -The S-Boxes can be in about (2**1700) states. -.Pp -.Fn arc4random -fits into a middle ground not covered by other subsystems such as -the strong, slow, and resource expensive random -devices described in -.Xr random 4 -versus the fast but poor quality interfaces described in -.Xr rand 3 , -.Xr random 3 , -and -.Xr drand48 3 . -.Pp -.Fn arc4random_buf -fills the region -.Fa buf -of length -.Fa nbytes -with ARC4-derived random data. -.Pp -.Fn arc4random_uniform -will return a uniformly distributed random number less than -.Fa upper_bound . -.Fn arc4random_uniform -is recommended over constructions like -.Dq Li arc4random() % upper_bound -as it avoids "modulo bias" when the upper bound is not a power of two. -.Pp -The -.Fn arc4random_stir -function reads data using -.Xr sysctl 3 -from -.Va kern.arandom -and uses it to permute the S-Boxes via -.Fn arc4random_addrandom . -.Pp -There is no need to call -.Fn arc4random_stir -before using -.Fn arc4random , -since -.Fn arc4random -automatically initializes itself. -.Sh RETURN VALUES -These functions are always successful, and no return value is -reserved to indicate an error. -.Sh SEE ALSO -.Xr rand 3 , -.Xr rand48 3 , -.Xr random 3 -.Sh HISTORY -An algorithm called -.Pa RC4 -was designed by RSA Data Security, Inc. -It was considered a trade secret. -Because it was a trade secret, it obviously could not be patented. -A clone of this was posted anonymously to USENET and confirmed to -be equivalent by several sources who had access to the original cipher. -Because of the trade secret situation, RSA Data Security, Inc. can do -nothing about the release of the ARC4 algorithm. -Since -.Pa RC4 -used to be a trade secret, the cipher is now referred to as -.Pa ARC4 . -.Pp -These functions first appeared in -.Ox 2.1 . diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c deleted file mode 100644 index 22b8d1f3c1..0000000000 --- a/src/lib/libc/crypt/arc4random.c +++ /dev/null @@ -1,272 +0,0 @@ -/* $OpenBSD: arc4random.c,v 1.19 2008/06/04 00:50:23 djm Exp $ */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Arc4 random number generator for OpenBSD. - * - * This code is derived from section 17.1 of Applied Cryptography, - * second edition, which describes a stream cipher allegedly - * compatible with RSA Labs "RC4" cipher (the actual description of - * which is a trade secret). The same algorithm is used as a stream - * cipher called "arcfour" in Tatu Ylonen's ssh package. - * - * Here the stream cipher has been modified always to include the time - * when initializing the state. That makes it impossible to - * regenerate the same random sequence twice, so this can't be used - * for encryption, but will generate good random numbers. - * - * RC4 is a registered trademark of RSA Laboratories. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "thread_private.h" - -#ifdef __GNUC__ -#define inline __inline -#else /* !__GNUC__ */ -#define inline -#endif /* !__GNUC__ */ - -struct arc4_stream { - u_int8_t i; - u_int8_t j; - u_int8_t s[256]; -}; - -static int rs_initialized; -static struct arc4_stream rs; -static pid_t arc4_stir_pid; -static int arc4_count; - -static inline u_int8_t arc4_getbyte(void); - -static inline void -arc4_init(void) -{ - int n; - - for (n = 0; n < 256; n++) - rs.s[n] = n; - rs.i = 0; - rs.j = 0; -} - -static inline void -arc4_addrandom(u_char *dat, int datlen) -{ - int n; - u_int8_t si; - - rs.i--; - for (n = 0; n < 256; n++) { - rs.i = (rs.i + 1); - si = rs.s[rs.i]; - rs.j = (rs.j + si + dat[n % datlen]); - rs.s[rs.i] = rs.s[rs.j]; - rs.s[rs.j] = si; - } - rs.j = rs.i; -} - -static void -arc4_stir(void) -{ - int i, mib[2]; - size_t len; - u_char rnd[128]; - - if (!rs_initialized) { - arc4_init(); - rs_initialized = 1; - } - - mib[0] = CTL_KERN; - mib[1] = KERN_ARND; - - len = sizeof(rnd); - sysctl(mib, 2, rnd, &len, NULL, 0); - - arc4_stir_pid = getpid(); - arc4_addrandom(rnd, sizeof(rnd)); - - /* - * Discard early keystream, as per recommendations in: - * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps - */ - for (i = 0; i < 256; i++) - (void)arc4_getbyte(); - arc4_count = 1600000; -} - -static inline u_int8_t -arc4_getbyte(void) -{ - u_int8_t si, sj; - - rs.i = (rs.i + 1); - si = rs.s[rs.i]; - rs.j = (rs.j + si); - sj = rs.s[rs.j]; - rs.s[rs.i] = sj; - rs.s[rs.j] = si; - return (rs.s[(si + sj) & 0xff]); -} - -u_int8_t -__arc4_getbyte(void) -{ - u_int8_t val; - - _ARC4_LOCK(); - if (--arc4_count == 0 || !rs_initialized) - arc4_stir(); - val = arc4_getbyte(); - _ARC4_UNLOCK(); - return val; -} - -static inline u_int32_t -arc4_getword(void) -{ - u_int32_t val; - val = arc4_getbyte() << 24; - val |= arc4_getbyte() << 16; - val |= arc4_getbyte() << 8; - val |= arc4_getbyte(); - return val; -} - -void -arc4random_stir(void) -{ - _ARC4_LOCK(); - arc4_stir(); - _ARC4_UNLOCK(); -} - -void -arc4random_addrandom(u_char *dat, int datlen) -{ - _ARC4_LOCK(); - if (!rs_initialized) - arc4_stir(); - arc4_addrandom(dat, datlen); - _ARC4_UNLOCK(); -} - -u_int32_t -arc4random(void) -{ - u_int32_t val; - _ARC4_LOCK(); - arc4_count -= 4; - if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != getpid()) - arc4_stir(); - val = arc4_getword(); - _ARC4_UNLOCK(); - return val; -} - -void -arc4random_buf(void *_buf, size_t n) -{ - u_char *buf = (u_char *)_buf; - _ARC4_LOCK(); - if (!rs_initialized || arc4_stir_pid != getpid()) - arc4_stir(); - while (n--) { - if (--arc4_count <= 0) - arc4_stir(); - buf[n] = arc4_getbyte(); - } - _ARC4_UNLOCK(); -} - -/* - * Calculate a uniformly distributed random number less than upper_bound - * avoiding "modulo bias". - * - * Uniformity is achieved by generating new random numbers until the one - * returned is outside the range [0, 2**32 % upper_bound). This - * guarantees the selected random number will be inside - * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) - * after reduction modulo upper_bound. - */ -u_int32_t -arc4random_uniform(u_int32_t upper_bound) -{ - u_int32_t r, min; - - if (upper_bound < 2) - return 0; - -#if (ULONG_MAX > 0xffffffffUL) - min = 0x100000000UL % upper_bound; -#else - /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ - if (upper_bound > 0x80000000) - min = 1 + ~upper_bound; /* 2**32 - upper_bound */ - else { - /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ - min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; - } -#endif - - /* - * This could theoretically loop forever but each retry has - * p > 0.5 (worst case, usually far better) of selecting a - * number inside the range we need, so it should rarely need - * to re-roll. - */ - for (;;) { - r = arc4random(); - if (r >= min) - break; - } - - return r % upper_bound; -} - -#if 0 -/*-------- Test code for i386 --------*/ -#include -#include -int -main(int argc, char **argv) -{ - const int iter = 1000000; - int i; - pctrval v; - - v = rdtsc(); - for (i = 0; i < iter; i++) - arc4random(); - v = rdtsc() - v; - v /= iter; - - printf("%qd cycles\n", v); -} -#endif diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c deleted file mode 100644 index 207e76ea46..0000000000 --- a/src/lib/libc/crypt/bcrypt.c +++ /dev/null @@ -1,338 +0,0 @@ -/* $OpenBSD: bcrypt.c,v 1.24 2008/04/02 19:54:05 millert Exp $ */ - -/* - * Copyright 1997 Niels Provos - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* This password hashing algorithm was designed by David Mazieres - * and works as follows: - * - * 1. state := InitState () - * 2. state := ExpandKey (state, salt, password) 3. - * REPEAT rounds: - * state := ExpandKey (state, 0, salt) - * state := ExpandKey(state, 0, password) - * 4. ctext := "OrpheanBeholderScryDoubt" - * 5. REPEAT 64: - * ctext := Encrypt_ECB (state, ctext); - * 6. RETURN Concatenate (salt, ctext); - * - */ - -#include -#include -#include -#include -#include -#include - -/* This implementation is adaptable to current computing power. - * You can have up to 2^31 rounds which should be enough for some - * time to come. - */ - -#define BCRYPT_VERSION '2' -#define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ -#define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ -#define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ - -char *bcrypt_gensalt(u_int8_t); - -static void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t); -static void encode_base64(u_int8_t *, u_int8_t *, u_int16_t); -static void decode_base64(u_int8_t *, u_int16_t, u_int8_t *); - -static char encrypted[_PASSWORD_LEN]; -static char gsalt[7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1]; -static char error[] = ":"; - -const static u_int8_t Base64Code[] = -"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - -const static u_int8_t index_64[128] = { - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 0, 1, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 255, 255, - 255, 255, 255, 255, 255, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 255, 255, 255, 255, 255, 255, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 255, 255, 255, 255, 255 -}; -#define CHAR64(c) ( (c) > 127 ? 255 : index_64[(c)]) - -static void -decode_base64(u_int8_t *buffer, u_int16_t len, u_int8_t *data) -{ - u_int8_t *bp = buffer; - u_int8_t *p = data; - u_int8_t c1, c2, c3, c4; - while (bp < buffer + len) { - c1 = CHAR64(*p); - c2 = CHAR64(*(p + 1)); - - /* Invalid data */ - if (c1 == 255 || c2 == 255) - break; - - *bp++ = (c1 << 2) | ((c2 & 0x30) >> 4); - if (bp >= buffer + len) - break; - - c3 = CHAR64(*(p + 2)); - if (c3 == 255) - break; - - *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); - if (bp >= buffer + len) - break; - - c4 = CHAR64(*(p + 3)); - if (c4 == 255) - break; - *bp++ = ((c3 & 0x03) << 6) | c4; - - p += 4; - } -} - -static void -encode_salt(char *salt, u_int8_t *csalt, u_int16_t clen, u_int8_t logr) -{ - salt[0] = '$'; - salt[1] = BCRYPT_VERSION; - salt[2] = 'a'; - salt[3] = '$'; - - snprintf(salt + 4, 4, "%2.2u$", logr); - - encode_base64((u_int8_t *) salt + 7, csalt, clen); -} -/* Generates a salt for this version of crypt. - Since versions may change. Keeping this here - seems sensible. - */ - -char * -bcrypt_gensalt(u_int8_t log_rounds) -{ - u_int8_t csalt[BCRYPT_MAXSALT]; - u_int16_t i; - u_int32_t seed = 0; - - for (i = 0; i < BCRYPT_MAXSALT; i++) { - if (i % 4 == 0) - seed = arc4random(); - csalt[i] = seed & 0xff; - seed = seed >> 8; - } - - if (log_rounds < 4) - log_rounds = 4; - else if (log_rounds > 31) - log_rounds = 31; - - encode_salt(gsalt, csalt, BCRYPT_MAXSALT, log_rounds); - return gsalt; -} -/* We handle $Vers$log2(NumRounds)$salt+passwd$ - i.e. $2$04$iwouldntknowwhattosayetKdJ6iFtacBqJdKe6aW7ou */ - -char * -bcrypt(const char *key, const char *salt) -{ - blf_ctx state; - u_int32_t rounds, i, k; - u_int16_t j; - u_int8_t key_len, salt_len, logr, minor; - u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; - u_int8_t csalt[BCRYPT_MAXSALT]; - u_int32_t cdata[BCRYPT_BLOCKS]; - int n; - - /* Discard "$" identifier */ - salt++; - - if (*salt > BCRYPT_VERSION) { - /* How do I handle errors ? Return ':' */ - return error; - } - - /* Check for minor versions */ - if (salt[1] != '$') { - switch (salt[1]) { - case 'a': - /* 'ab' should not yield the same as 'abab' */ - minor = salt[1]; - salt++; - break; - default: - return error; - } - } else - minor = 0; - - /* Discard version + "$" identifier */ - salt += 2; - - if (salt[2] != '$') - /* Out of sync with passwd entry */ - return error; - - /* Computer power doesn't increase linear, 2^x should be fine */ - n = atoi(salt); - if (n > 31 || n < 0) - return error; - logr = (u_int8_t)n; - if ((rounds = (u_int32_t) 1 << logr) < BCRYPT_MINROUNDS) - return error; - - /* Discard num rounds + "$" identifier */ - salt += 3; - - if (strlen(salt) * 3 / 4 < BCRYPT_MAXSALT) - return error; - - /* We dont want the base64 salt but the raw data */ - decode_base64(csalt, BCRYPT_MAXSALT, (u_int8_t *) salt); - salt_len = BCRYPT_MAXSALT; - key_len = strlen(key) + (minor >= 'a' ? 1 : 0); - - /* Setting up S-Boxes and Subkeys */ - Blowfish_initstate(&state); - Blowfish_expandstate(&state, csalt, salt_len, - (u_int8_t *) key, key_len); - for (k = 0; k < rounds; k++) { - Blowfish_expand0state(&state, (u_int8_t *) key, key_len); - Blowfish_expand0state(&state, csalt, salt_len); - } - - /* This can be precomputed later */ - j = 0; - for (i = 0; i < BCRYPT_BLOCKS; i++) - cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_BLOCKS, &j); - - /* Now do the encryption */ - for (k = 0; k < 64; k++) - blf_enc(&state, cdata, BCRYPT_BLOCKS / 2); - - for (i = 0; i < BCRYPT_BLOCKS; i++) { - ciphertext[4 * i + 3] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 2] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 1] = cdata[i] & 0xff; - cdata[i] = cdata[i] >> 8; - ciphertext[4 * i + 0] = cdata[i] & 0xff; - } - - - i = 0; - encrypted[i++] = '$'; - encrypted[i++] = BCRYPT_VERSION; - if (minor) - encrypted[i++] = minor; - encrypted[i++] = '$'; - - snprintf(encrypted + i, 4, "%2.2u$", logr); - - encode_base64((u_int8_t *) encrypted + i + 3, csalt, BCRYPT_MAXSALT); - encode_base64((u_int8_t *) encrypted + strlen(encrypted), ciphertext, - 4 * BCRYPT_BLOCKS - 1); - memset(&state, 0, sizeof(state)); - memset(ciphertext, 0, sizeof(ciphertext)); - memset(csalt, 0, sizeof(csalt)); - memset(cdata, 0, sizeof(cdata)); - return encrypted; -} - -static void -encode_base64(u_int8_t *buffer, u_int8_t *data, u_int16_t len) -{ - u_int8_t *bp = buffer; - u_int8_t *p = data; - u_int8_t c1, c2; - while (p < data + len) { - c1 = *p++; - *bp++ = Base64Code[(c1 >> 2)]; - c1 = (c1 & 0x03) << 4; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 4) & 0x0f; - *bp++ = Base64Code[c1]; - c1 = (c2 & 0x0f) << 2; - if (p >= data + len) { - *bp++ = Base64Code[c1]; - break; - } - c2 = *p++; - c1 |= (c2 >> 6) & 0x03; - *bp++ = Base64Code[c1]; - *bp++ = Base64Code[c2 & 0x3f]; - } - *bp = '\0'; -} -#if 0 -void -main() -{ - char blubber[73]; - char salt[100]; - char *p; - salt[0] = '$'; - salt[1] = BCRYPT_VERSION; - salt[2] = '$'; - - snprintf(salt + 3, 4, "%2.2u$", 5); - - printf("24 bytes of salt: "); - fgets(salt + 6, sizeof(salt) - 6, stdin); - salt[99] = 0; - printf("72 bytes of password: "); - fpurge(stdin); - fgets(blubber, sizeof(blubber), stdin); - blubber[72] = 0; - - p = crypt(blubber, salt); - printf("Passwd entry: %s\n\n", p); - - p = bcrypt_gensalt(5); - printf("Generated salt: %s\n", p); - p = crypt(blubber, p); - printf("Passwd entry: %s\n", p); -} -#endif diff --git a/src/lib/libc/crypt/blowfish.3 b/src/lib/libc/crypt/blowfish.3 deleted file mode 100644 index 4defaecc34..0000000000 --- a/src/lib/libc/crypt/blowfish.3 +++ /dev/null @@ -1,106 +0,0 @@ -.\" $OpenBSD: blowfish.3,v 1.20 2007/05/31 19:19:27 jmc Exp $ -.\" -.\" Copyright 1997 Niels Provos -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Niels Provos. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt BLOWFISH 3 -.Os -.Sh NAME -.Nm blf_key , -.Nm blf_enc , -.Nm blf_dec , -.Nm blf_ecb_encrypt , -.Nm blf_ecb_decrypt , -.Nm blf_cbc_encrypt , -.Nm blf_cbc_decrypt -.Nd Blowfish encryption -.Sh SYNOPSIS -.Fd #include -.Ft void -.Fn blf_key "blf_ctx *state" "const u_int8_t *key" "u_int16_t keylen" -.Ft void -.Fn blf_enc "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" -.Ft void -.Fn blf_dec "blf_ctx *state" "u_int32_t *data" "u_int16_t blocks" -.Ft void -.Fn blf_ecb_encrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_ecb_decrypt "blf_ctx *state" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_cbc_encrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" -.Ft void -.Fn blf_cbc_decrypt "blf_ctx *state" "u_int8_t *iv" "u_int8_t *data" "u_int32_t datalen" -.Sh DESCRIPTION -.Em Blowfish -is a fast unpatented block cipher designed by Bruce Schneier. -It basically consists of a 16-round Feistel network. -The block size is 64 bits and the maximum key size is 448 bits. -.Pp -The -.Fn blf_key -function initializes the 4 8-bit S-boxes and the 18 Subkeys with -the hexadecimal digits of Pi. -The key is used for further randomization. -The first argument to -.Fn blf_enc -is the initialized state derived from -.Fn blf_key . -The stream of 32-bit words is encrypted in Electronic Codebook -Mode (ECB) and -.Fa blocks -is the number of 64-bit blocks in the stream. -.Fn blf_dec -is used for decrypting Blowfish encrypted blocks. -.Pp -The functions -.Fn blf_ecb_encrypt -and -.Fn blf_ecb_decrypt -are used for encrypting and decrypting octet streams in ECB mode. -The functions -.Fn blf_cbc_encrypt -and -.Fn blf_cbc_decrypt -are used for encrypting and decrypting octet streams in -Cipherblock Chaining Mode (CBC). -For these functions -.Fa datalen -specifies the number of octets of data to encrypt or decrypt. -It must be a multiple of 8 (64-bit block). -The initialisation vector -.Fa iv -points to an 8-byte buffer. -.Sh SEE ALSO -.Xr passwd 1 , -.Xr crypt 3 , -.Xr passwd 5 -.Sh AUTHORS -.An Niels Provos Aq provos@physnet.uni-hamburg.de diff --git a/src/lib/libc/crypt/blowfish.c b/src/lib/libc/crypt/blowfish.c deleted file mode 100644 index c337df8a0a..0000000000 --- a/src/lib/libc/crypt/blowfish.c +++ /dev/null @@ -1,685 +0,0 @@ -/* $OpenBSD: blowfish.c,v 1.18 2004/11/02 17:23:26 hshoexer Exp $ */ -/* - * Blowfish block cipher for OpenBSD - * Copyright 1997 Niels Provos - * All rights reserved. - * - * Implementation advice by David Mazieres . - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This code is derived from section 14.3 and the given source - * in section V of Applied Cryptography, second edition. - * Blowfish is an unpatented fast block cipher designed by - * Bruce Schneier. - */ - -#if 0 -#include /* used for debugging */ -#include -#endif - -#include -#include - -#undef inline -#ifdef __GNUC__ -#define inline __inline -#else /* !__GNUC__ */ -#define inline -#endif /* !__GNUC__ */ - -/* Function for Feistel Networks */ - -#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \ - + (s)[0x100 + (((x)>>16)&0xFF)]) \ - ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \ - + (s)[0x300 + ( (x) &0xFF)]) - -#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n]) - -void -Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) -{ - u_int32_t Xl; - u_int32_t Xr; - u_int32_t *s = c->S[0]; - u_int32_t *p = c->P; - - Xl = *xl; - Xr = *xr; - - Xl ^= p[0]; - BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2); - BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4); - BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6); - BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8); - BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10); - BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12); - BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14); - BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16); - - *xl = Xr ^ p[17]; - *xr = Xl; -} - -void -Blowfish_decipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr) -{ - u_int32_t Xl; - u_int32_t Xr; - u_int32_t *s = c->S[0]; - u_int32_t *p = c->P; - - Xl = *xl; - Xr = *xr; - - Xl ^= p[17]; - BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15); - BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13); - BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11); - BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9); - BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7); - BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5); - BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3); - BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1); - - *xl = Xr ^ p[0]; - *xr = Xl; -} - -void -Blowfish_initstate(blf_ctx *c) -{ - /* P-box and S-box tables initialized with digits of Pi */ - - static const blf_ctx initstate = - { { - { - 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, - 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, - 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, - 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, - 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, - 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, - 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, - 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, - 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, - 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, - 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, - 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, - 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, - 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, - 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, - 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, - 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, - 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, - 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, - 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, - 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, - 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, - 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, - 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, - 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, - 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, - 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, - 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, - 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, - 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, - 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, - 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, - 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, - 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, - 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, - 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, - 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, - 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, - 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, - 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, - 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, - 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, - 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, - 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, - 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, - 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, - 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, - 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, - 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, - 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, - 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, - 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, - 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, - 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, - 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, - 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, - 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, - 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, - 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, - 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, - 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, - 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, - 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, - 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a}, - { - 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, - 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, - 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, - 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, - 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, - 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, - 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, - 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, - 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, - 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, - 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, - 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, - 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, - 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, - 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, - 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, - 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, - 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, - 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, - 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, - 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, - 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, - 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, - 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, - 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, - 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, - 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, - 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, - 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, - 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, - 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, - 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, - 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, - 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, - 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, - 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, - 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, - 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, - 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, - 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, - 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, - 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, - 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, - 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, - 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, - 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, - 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, - 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, - 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, - 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, - 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, - 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, - 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, - 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, - 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, - 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, - 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, - 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, - 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, - 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, - 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, - 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, - 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, - 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7}, - { - 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, - 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, - 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, - 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, - 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, - 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, - 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, - 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, - 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, - 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, - 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, - 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, - 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, - 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, - 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, - 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, - 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, - 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, - 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, - 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, - 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, - 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, - 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, - 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, - 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, - 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, - 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, - 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, - 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, - 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, - 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, - 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, - 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, - 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, - 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, - 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, - 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, - 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, - 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, - 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, - 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, - 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, - 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, - 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, - 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, - 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, - 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, - 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, - 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, - 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, - 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, - 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, - 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, - 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, - 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, - 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, - 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, - 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, - 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, - 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, - 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, - 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, - 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, - 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0}, - { - 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, - 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, - 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, - 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, - 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, - 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, - 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, - 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, - 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, - 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, - 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, - 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, - 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, - 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, - 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, - 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, - 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, - 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, - 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, - 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, - 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, - 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, - 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, - 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, - 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, - 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, - 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, - 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, - 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, - 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, - 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, - 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, - 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, - 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, - 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, - 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, - 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, - 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, - 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, - 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, - 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, - 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, - 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, - 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, - 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, - 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, - 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, - 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, - 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, - 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, - 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, - 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, - 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, - 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, - 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, - 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, - 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, - 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, - 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, - 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, - 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, - 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, - 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, - 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6} - }, - { - 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, - 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, - 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, - 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, - 0x9216d5d9, 0x8979fb1b - } }; - - *c = initstate; -} - -u_int32_t -Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes, - u_int16_t *current) -{ - u_int8_t i; - u_int16_t j; - u_int32_t temp; - - temp = 0x00000000; - j = *current; - - for (i = 0; i < 4; i++, j++) { - if (j >= databytes) - j = 0; - temp = (temp << 8) | data[j]; - } - - *current = j; - return temp; -} - -void -Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes) -{ - u_int16_t i; - u_int16_t j; - u_int16_t k; - u_int32_t temp; - u_int32_t datal; - u_int32_t datar; - - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } - - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - Blowfish_encipher(c, &datal, &datar); - - c->P[i] = datal; - c->P[i + 1] = datar; - } - - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - Blowfish_encipher(c, &datal, &datar); - - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } -} - - -void -Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes, - const u_int8_t *key, u_int16_t keybytes) -{ - u_int16_t i; - u_int16_t j; - u_int16_t k; - u_int32_t temp; - u_int32_t datal; - u_int32_t datar; - - j = 0; - for (i = 0; i < BLF_N + 2; i++) { - /* Extract 4 int8 to 1 int32 from keystream */ - temp = Blowfish_stream2word(key, keybytes, &j); - c->P[i] = c->P[i] ^ temp; - } - - j = 0; - datal = 0x00000000; - datar = 0x00000000; - for (i = 0; i < BLF_N + 2; i += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); - - c->P[i] = datal; - c->P[i + 1] = datar; - } - - for (i = 0; i < 4; i++) { - for (k = 0; k < 256; k += 2) { - datal ^= Blowfish_stream2word(data, databytes, &j); - datar ^= Blowfish_stream2word(data, databytes, &j); - Blowfish_encipher(c, &datal, &datar); - - c->S[i][k] = datal; - c->S[i][k + 1] = datar; - } - } - -} - -void -blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len) -{ - /* Initialize S-boxes and subkeys with Pi */ - Blowfish_initstate(c); - - /* Transform S-boxes and subkeys with key */ - Blowfish_expand0state(c, k, len); -} - -void -blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks) -{ - u_int32_t *d; - u_int16_t i; - - d = data; - for (i = 0; i < blocks; i++) { - Blowfish_encipher(c, d, d + 1); - d += 2; - } -} - -void -blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks) -{ - u_int32_t *d; - u_int16_t i; - - d = data; - for (i = 0; i < blocks; i++) { - Blowfish_decipher(c, d, d + 1); - d += 2; - } -} - -void -blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i; - - for (i = 0; i < len; i += 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - data += 8; - } -} - -void -blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i; - - for (i = 0; i < len; i += 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - data += 8; - } -} - -void -blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int32_t i, j; - - for (i = 0; i < len; i += 8) { - for (j = 0; j < 8; j++) - data[j] ^= iv[j]; - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_encipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - iv = data; - data += 8; - } -} - -void -blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len) -{ - u_int32_t l, r; - u_int8_t *iv; - u_int32_t i, j; - - iv = data + len - 16; - data = data + len - 8; - for (i = len - 8; i >= 8; i -= 8) { - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - for (j = 0; j < 8; j++) - data[j] ^= iv[j]; - iv -= 8; - data -= 8; - } - l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]; - r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]; - Blowfish_decipher(c, &l, &r); - data[0] = l >> 24 & 0xff; - data[1] = l >> 16 & 0xff; - data[2] = l >> 8 & 0xff; - data[3] = l & 0xff; - data[4] = r >> 24 & 0xff; - data[5] = r >> 16 & 0xff; - data[6] = r >> 8 & 0xff; - data[7] = r & 0xff; - for (j = 0; j < 8; j++) - data[j] ^= iva[j]; -} - -#if 0 -void -report(u_int32_t data[], u_int16_t len) -{ - u_int16_t i; - for (i = 0; i < len; i += 2) - printf("Block %0hd: %08lx %08lx.\n", - i / 2, data[i], data[i + 1]); -} -void -main(void) -{ - - blf_ctx c; - char key[] = "AAAAA"; - char key2[] = "abcdefghijklmnopqrstuvwxyz"; - - u_int32_t data[10]; - u_int32_t data2[] = - {0x424c4f57l, 0x46495348l}; - - u_int16_t i; - - /* First test */ - for (i = 0; i < 10; i++) - data[i] = i; - - blf_key(&c, (u_int8_t *) key, 5); - blf_enc(&c, data, 5); - blf_dec(&c, data, 1); - blf_dec(&c, data + 2, 4); - printf("Should read as 0 - 9.\n"); - report(data, 10); - - /* Second test */ - blf_key(&c, (u_int8_t *) key2, strlen(key2)); - blf_enc(&c, data2, 1); - printf("\nShould read as: 0x324ed0fe 0xf413a203.\n"); - report(data2, 2); - blf_dec(&c, data2, 1); - report(data2, 2); -} -#endif diff --git a/src/lib/libc/crypt/cast.c b/src/lib/libc/crypt/cast.c deleted file mode 100644 index ea026638d6..0000000000 --- a/src/lib/libc/crypt/cast.c +++ /dev/null @@ -1,790 +0,0 @@ -/* $OpenBSD: cast.c,v 1.3 2004/11/03 10:38:50 hshoexer Exp $ */ -/* - * CAST-128 in C - * Written by Steve Reid - * 100% Public Domain - no warranty - * Released 1997.10.11 - */ - -#include - -#include - -/* CAST S-Boxes */ - -static const u_int32_t cast_sbox1[256] = { - 0x30FB40D4, 0x9FA0FF0B, 0x6BECCD2F, 0x3F258C7A, - 0x1E213F2F, 0x9C004DD3, 0x6003E540, 0xCF9FC949, - 0xBFD4AF27, 0x88BBBDB5, 0xE2034090, 0x98D09675, - 0x6E63A0E0, 0x15C361D2, 0xC2E7661D, 0x22D4FF8E, - 0x28683B6F, 0xC07FD059, 0xFF2379C8, 0x775F50E2, - 0x43C340D3, 0xDF2F8656, 0x887CA41A, 0xA2D2BD2D, - 0xA1C9E0D6, 0x346C4819, 0x61B76D87, 0x22540F2F, - 0x2ABE32E1, 0xAA54166B, 0x22568E3A, 0xA2D341D0, - 0x66DB40C8, 0xA784392F, 0x004DFF2F, 0x2DB9D2DE, - 0x97943FAC, 0x4A97C1D8, 0x527644B7, 0xB5F437A7, - 0xB82CBAEF, 0xD751D159, 0x6FF7F0ED, 0x5A097A1F, - 0x827B68D0, 0x90ECF52E, 0x22B0C054, 0xBC8E5935, - 0x4B6D2F7F, 0x50BB64A2, 0xD2664910, 0xBEE5812D, - 0xB7332290, 0xE93B159F, 0xB48EE411, 0x4BFF345D, - 0xFD45C240, 0xAD31973F, 0xC4F6D02E, 0x55FC8165, - 0xD5B1CAAD, 0xA1AC2DAE, 0xA2D4B76D, 0xC19B0C50, - 0x882240F2, 0x0C6E4F38, 0xA4E4BFD7, 0x4F5BA272, - 0x564C1D2F, 0xC59C5319, 0xB949E354, 0xB04669FE, - 0xB1B6AB8A, 0xC71358DD, 0x6385C545, 0x110F935D, - 0x57538AD5, 0x6A390493, 0xE63D37E0, 0x2A54F6B3, - 0x3A787D5F, 0x6276A0B5, 0x19A6FCDF, 0x7A42206A, - 0x29F9D4D5, 0xF61B1891, 0xBB72275E, 0xAA508167, - 0x38901091, 0xC6B505EB, 0x84C7CB8C, 0x2AD75A0F, - 0x874A1427, 0xA2D1936B, 0x2AD286AF, 0xAA56D291, - 0xD7894360, 0x425C750D, 0x93B39E26, 0x187184C9, - 0x6C00B32D, 0x73E2BB14, 0xA0BEBC3C, 0x54623779, - 0x64459EAB, 0x3F328B82, 0x7718CF82, 0x59A2CEA6, - 0x04EE002E, 0x89FE78E6, 0x3FAB0950, 0x325FF6C2, - 0x81383F05, 0x6963C5C8, 0x76CB5AD6, 0xD49974C9, - 0xCA180DCF, 0x380782D5, 0xC7FA5CF6, 0x8AC31511, - 0x35E79E13, 0x47DA91D0, 0xF40F9086, 0xA7E2419E, - 0x31366241, 0x051EF495, 0xAA573B04, 0x4A805D8D, - 0x548300D0, 0x00322A3C, 0xBF64CDDF, 0xBA57A68E, - 0x75C6372B, 0x50AFD341, 0xA7C13275, 0x915A0BF5, - 0x6B54BFAB, 0x2B0B1426, 0xAB4CC9D7, 0x449CCD82, - 0xF7FBF265, 0xAB85C5F3, 0x1B55DB94, 0xAAD4E324, - 0xCFA4BD3F, 0x2DEAA3E2, 0x9E204D02, 0xC8BD25AC, - 0xEADF55B3, 0xD5BD9E98, 0xE31231B2, 0x2AD5AD6C, - 0x954329DE, 0xADBE4528, 0xD8710F69, 0xAA51C90F, - 0xAA786BF6, 0x22513F1E, 0xAA51A79B, 0x2AD344CC, - 0x7B5A41F0, 0xD37CFBAD, 0x1B069505, 0x41ECE491, - 0xB4C332E6, 0x032268D4, 0xC9600ACC, 0xCE387E6D, - 0xBF6BB16C, 0x6A70FB78, 0x0D03D9C9, 0xD4DF39DE, - 0xE01063DA, 0x4736F464, 0x5AD328D8, 0xB347CC96, - 0x75BB0FC3, 0x98511BFB, 0x4FFBCC35, 0xB58BCF6A, - 0xE11F0ABC, 0xBFC5FE4A, 0xA70AEC10, 0xAC39570A, - 0x3F04442F, 0x6188B153, 0xE0397A2E, 0x5727CB79, - 0x9CEB418F, 0x1CACD68D, 0x2AD37C96, 0x0175CB9D, - 0xC69DFF09, 0xC75B65F0, 0xD9DB40D8, 0xEC0E7779, - 0x4744EAD4, 0xB11C3274, 0xDD24CB9E, 0x7E1C54BD, - 0xF01144F9, 0xD2240EB1, 0x9675B3FD, 0xA3AC3755, - 0xD47C27AF, 0x51C85F4D, 0x56907596, 0xA5BB15E6, - 0x580304F0, 0xCA042CF1, 0x011A37EA, 0x8DBFAADB, - 0x35BA3E4A, 0x3526FFA0, 0xC37B4D09, 0xBC306ED9, - 0x98A52666, 0x5648F725, 0xFF5E569D, 0x0CED63D0, - 0x7C63B2CF, 0x700B45E1, 0xD5EA50F1, 0x85A92872, - 0xAF1FBDA7, 0xD4234870, 0xA7870BF3, 0x2D3B4D79, - 0x42E04198, 0x0CD0EDE7, 0x26470DB8, 0xF881814C, - 0x474D6AD7, 0x7C0C5E5C, 0xD1231959, 0x381B7298, - 0xF5D2F4DB, 0xAB838653, 0x6E2F1E23, 0x83719C9E, - 0xBD91E046, 0x9A56456E, 0xDC39200C, 0x20C8C571, - 0x962BDA1C, 0xE1E696FF, 0xB141AB08, 0x7CCA89B9, - 0x1A69E783, 0x02CC4843, 0xA2F7C579, 0x429EF47D, - 0x427B169C, 0x5AC9F049, 0xDD8F0F00, 0x5C8165BF -}; - -static const u_int32_t cast_sbox2[256] = { - 0x1F201094, 0xEF0BA75B, 0x69E3CF7E, 0x393F4380, - 0xFE61CF7A, 0xEEC5207A, 0x55889C94, 0x72FC0651, - 0xADA7EF79, 0x4E1D7235, 0xD55A63CE, 0xDE0436BA, - 0x99C430EF, 0x5F0C0794, 0x18DCDB7D, 0xA1D6EFF3, - 0xA0B52F7B, 0x59E83605, 0xEE15B094, 0xE9FFD909, - 0xDC440086, 0xEF944459, 0xBA83CCB3, 0xE0C3CDFB, - 0xD1DA4181, 0x3B092AB1, 0xF997F1C1, 0xA5E6CF7B, - 0x01420DDB, 0xE4E7EF5B, 0x25A1FF41, 0xE180F806, - 0x1FC41080, 0x179BEE7A, 0xD37AC6A9, 0xFE5830A4, - 0x98DE8B7F, 0x77E83F4E, 0x79929269, 0x24FA9F7B, - 0xE113C85B, 0xACC40083, 0xD7503525, 0xF7EA615F, - 0x62143154, 0x0D554B63, 0x5D681121, 0xC866C359, - 0x3D63CF73, 0xCEE234C0, 0xD4D87E87, 0x5C672B21, - 0x071F6181, 0x39F7627F, 0x361E3084, 0xE4EB573B, - 0x602F64A4, 0xD63ACD9C, 0x1BBC4635, 0x9E81032D, - 0x2701F50C, 0x99847AB4, 0xA0E3DF79, 0xBA6CF38C, - 0x10843094, 0x2537A95E, 0xF46F6FFE, 0xA1FF3B1F, - 0x208CFB6A, 0x8F458C74, 0xD9E0A227, 0x4EC73A34, - 0xFC884F69, 0x3E4DE8DF, 0xEF0E0088, 0x3559648D, - 0x8A45388C, 0x1D804366, 0x721D9BFD, 0xA58684BB, - 0xE8256333, 0x844E8212, 0x128D8098, 0xFED33FB4, - 0xCE280AE1, 0x27E19BA5, 0xD5A6C252, 0xE49754BD, - 0xC5D655DD, 0xEB667064, 0x77840B4D, 0xA1B6A801, - 0x84DB26A9, 0xE0B56714, 0x21F043B7, 0xE5D05860, - 0x54F03084, 0x066FF472, 0xA31AA153, 0xDADC4755, - 0xB5625DBF, 0x68561BE6, 0x83CA6B94, 0x2D6ED23B, - 0xECCF01DB, 0xA6D3D0BA, 0xB6803D5C, 0xAF77A709, - 0x33B4A34C, 0x397BC8D6, 0x5EE22B95, 0x5F0E5304, - 0x81ED6F61, 0x20E74364, 0xB45E1378, 0xDE18639B, - 0x881CA122, 0xB96726D1, 0x8049A7E8, 0x22B7DA7B, - 0x5E552D25, 0x5272D237, 0x79D2951C, 0xC60D894C, - 0x488CB402, 0x1BA4FE5B, 0xA4B09F6B, 0x1CA815CF, - 0xA20C3005, 0x8871DF63, 0xB9DE2FCB, 0x0CC6C9E9, - 0x0BEEFF53, 0xE3214517, 0xB4542835, 0x9F63293C, - 0xEE41E729, 0x6E1D2D7C, 0x50045286, 0x1E6685F3, - 0xF33401C6, 0x30A22C95, 0x31A70850, 0x60930F13, - 0x73F98417, 0xA1269859, 0xEC645C44, 0x52C877A9, - 0xCDFF33A6, 0xA02B1741, 0x7CBAD9A2, 0x2180036F, - 0x50D99C08, 0xCB3F4861, 0xC26BD765, 0x64A3F6AB, - 0x80342676, 0x25A75E7B, 0xE4E6D1FC, 0x20C710E6, - 0xCDF0B680, 0x17844D3B, 0x31EEF84D, 0x7E0824E4, - 0x2CCB49EB, 0x846A3BAE, 0x8FF77888, 0xEE5D60F6, - 0x7AF75673, 0x2FDD5CDB, 0xA11631C1, 0x30F66F43, - 0xB3FAEC54, 0x157FD7FA, 0xEF8579CC, 0xD152DE58, - 0xDB2FFD5E, 0x8F32CE19, 0x306AF97A, 0x02F03EF8, - 0x99319AD5, 0xC242FA0F, 0xA7E3EBB0, 0xC68E4906, - 0xB8DA230C, 0x80823028, 0xDCDEF3C8, 0xD35FB171, - 0x088A1BC8, 0xBEC0C560, 0x61A3C9E8, 0xBCA8F54D, - 0xC72FEFFA, 0x22822E99, 0x82C570B4, 0xD8D94E89, - 0x8B1C34BC, 0x301E16E6, 0x273BE979, 0xB0FFEAA6, - 0x61D9B8C6, 0x00B24869, 0xB7FFCE3F, 0x08DC283B, - 0x43DAF65A, 0xF7E19798, 0x7619B72F, 0x8F1C9BA4, - 0xDC8637A0, 0x16A7D3B1, 0x9FC393B7, 0xA7136EEB, - 0xC6BCC63E, 0x1A513742, 0xEF6828BC, 0x520365D6, - 0x2D6A77AB, 0x3527ED4B, 0x821FD216, 0x095C6E2E, - 0xDB92F2FB, 0x5EEA29CB, 0x145892F5, 0x91584F7F, - 0x5483697B, 0x2667A8CC, 0x85196048, 0x8C4BACEA, - 0x833860D4, 0x0D23E0F9, 0x6C387E8A, 0x0AE6D249, - 0xB284600C, 0xD835731D, 0xDCB1C647, 0xAC4C56EA, - 0x3EBD81B3, 0x230EABB0, 0x6438BC87, 0xF0B5B1FA, - 0x8F5EA2B3, 0xFC184642, 0x0A036B7A, 0x4FB089BD, - 0x649DA589, 0xA345415E, 0x5C038323, 0x3E5D3BB9, - 0x43D79572, 0x7E6DD07C, 0x06DFDF1E, 0x6C6CC4EF, - 0x7160A539, 0x73BFBE70, 0x83877605, 0x4523ECF1 -}; - -static const u_int32_t cast_sbox3[256] = { - 0x8DEFC240, 0x25FA5D9F, 0xEB903DBF, 0xE810C907, - 0x47607FFF, 0x369FE44B, 0x8C1FC644, 0xAECECA90, - 0xBEB1F9BF, 0xEEFBCAEA, 0xE8CF1950, 0x51DF07AE, - 0x920E8806, 0xF0AD0548, 0xE13C8D83, 0x927010D5, - 0x11107D9F, 0x07647DB9, 0xB2E3E4D4, 0x3D4F285E, - 0xB9AFA820, 0xFADE82E0, 0xA067268B, 0x8272792E, - 0x553FB2C0, 0x489AE22B, 0xD4EF9794, 0x125E3FBC, - 0x21FFFCEE, 0x825B1BFD, 0x9255C5ED, 0x1257A240, - 0x4E1A8302, 0xBAE07FFF, 0x528246E7, 0x8E57140E, - 0x3373F7BF, 0x8C9F8188, 0xA6FC4EE8, 0xC982B5A5, - 0xA8C01DB7, 0x579FC264, 0x67094F31, 0xF2BD3F5F, - 0x40FFF7C1, 0x1FB78DFC, 0x8E6BD2C1, 0x437BE59B, - 0x99B03DBF, 0xB5DBC64B, 0x638DC0E6, 0x55819D99, - 0xA197C81C, 0x4A012D6E, 0xC5884A28, 0xCCC36F71, - 0xB843C213, 0x6C0743F1, 0x8309893C, 0x0FEDDD5F, - 0x2F7FE850, 0xD7C07F7E, 0x02507FBF, 0x5AFB9A04, - 0xA747D2D0, 0x1651192E, 0xAF70BF3E, 0x58C31380, - 0x5F98302E, 0x727CC3C4, 0x0A0FB402, 0x0F7FEF82, - 0x8C96FDAD, 0x5D2C2AAE, 0x8EE99A49, 0x50DA88B8, - 0x8427F4A0, 0x1EAC5790, 0x796FB449, 0x8252DC15, - 0xEFBD7D9B, 0xA672597D, 0xADA840D8, 0x45F54504, - 0xFA5D7403, 0xE83EC305, 0x4F91751A, 0x925669C2, - 0x23EFE941, 0xA903F12E, 0x60270DF2, 0x0276E4B6, - 0x94FD6574, 0x927985B2, 0x8276DBCB, 0x02778176, - 0xF8AF918D, 0x4E48F79E, 0x8F616DDF, 0xE29D840E, - 0x842F7D83, 0x340CE5C8, 0x96BBB682, 0x93B4B148, - 0xEF303CAB, 0x984FAF28, 0x779FAF9B, 0x92DC560D, - 0x224D1E20, 0x8437AA88, 0x7D29DC96, 0x2756D3DC, - 0x8B907CEE, 0xB51FD240, 0xE7C07CE3, 0xE566B4A1, - 0xC3E9615E, 0x3CF8209D, 0x6094D1E3, 0xCD9CA341, - 0x5C76460E, 0x00EA983B, 0xD4D67881, 0xFD47572C, - 0xF76CEDD9, 0xBDA8229C, 0x127DADAA, 0x438A074E, - 0x1F97C090, 0x081BDB8A, 0x93A07EBE, 0xB938CA15, - 0x97B03CFF, 0x3DC2C0F8, 0x8D1AB2EC, 0x64380E51, - 0x68CC7BFB, 0xD90F2788, 0x12490181, 0x5DE5FFD4, - 0xDD7EF86A, 0x76A2E214, 0xB9A40368, 0x925D958F, - 0x4B39FFFA, 0xBA39AEE9, 0xA4FFD30B, 0xFAF7933B, - 0x6D498623, 0x193CBCFA, 0x27627545, 0x825CF47A, - 0x61BD8BA0, 0xD11E42D1, 0xCEAD04F4, 0x127EA392, - 0x10428DB7, 0x8272A972, 0x9270C4A8, 0x127DE50B, - 0x285BA1C8, 0x3C62F44F, 0x35C0EAA5, 0xE805D231, - 0x428929FB, 0xB4FCDF82, 0x4FB66A53, 0x0E7DC15B, - 0x1F081FAB, 0x108618AE, 0xFCFD086D, 0xF9FF2889, - 0x694BCC11, 0x236A5CAE, 0x12DECA4D, 0x2C3F8CC5, - 0xD2D02DFE, 0xF8EF5896, 0xE4CF52DA, 0x95155B67, - 0x494A488C, 0xB9B6A80C, 0x5C8F82BC, 0x89D36B45, - 0x3A609437, 0xEC00C9A9, 0x44715253, 0x0A874B49, - 0xD773BC40, 0x7C34671C, 0x02717EF6, 0x4FEB5536, - 0xA2D02FFF, 0xD2BF60C4, 0xD43F03C0, 0x50B4EF6D, - 0x07478CD1, 0x006E1888, 0xA2E53F55, 0xB9E6D4BC, - 0xA2048016, 0x97573833, 0xD7207D67, 0xDE0F8F3D, - 0x72F87B33, 0xABCC4F33, 0x7688C55D, 0x7B00A6B0, - 0x947B0001, 0x570075D2, 0xF9BB88F8, 0x8942019E, - 0x4264A5FF, 0x856302E0, 0x72DBD92B, 0xEE971B69, - 0x6EA22FDE, 0x5F08AE2B, 0xAF7A616D, 0xE5C98767, - 0xCF1FEBD2, 0x61EFC8C2, 0xF1AC2571, 0xCC8239C2, - 0x67214CB8, 0xB1E583D1, 0xB7DC3E62, 0x7F10BDCE, - 0xF90A5C38, 0x0FF0443D, 0x606E6DC6, 0x60543A49, - 0x5727C148, 0x2BE98A1D, 0x8AB41738, 0x20E1BE24, - 0xAF96DA0F, 0x68458425, 0x99833BE5, 0x600D457D, - 0x282F9350, 0x8334B362, 0xD91D1120, 0x2B6D8DA0, - 0x642B1E31, 0x9C305A00, 0x52BCE688, 0x1B03588A, - 0xF7BAEFD5, 0x4142ED9C, 0xA4315C11, 0x83323EC5, - 0xDFEF4636, 0xA133C501, 0xE9D3531C, 0xEE353783 -}; - -static const u_int32_t cast_sbox4[256] = { - 0x9DB30420, 0x1FB6E9DE, 0xA7BE7BEF, 0xD273A298, - 0x4A4F7BDB, 0x64AD8C57, 0x85510443, 0xFA020ED1, - 0x7E287AFF, 0xE60FB663, 0x095F35A1, 0x79EBF120, - 0xFD059D43, 0x6497B7B1, 0xF3641F63, 0x241E4ADF, - 0x28147F5F, 0x4FA2B8CD, 0xC9430040, 0x0CC32220, - 0xFDD30B30, 0xC0A5374F, 0x1D2D00D9, 0x24147B15, - 0xEE4D111A, 0x0FCA5167, 0x71FF904C, 0x2D195FFE, - 0x1A05645F, 0x0C13FEFE, 0x081B08CA, 0x05170121, - 0x80530100, 0xE83E5EFE, 0xAC9AF4F8, 0x7FE72701, - 0xD2B8EE5F, 0x06DF4261, 0xBB9E9B8A, 0x7293EA25, - 0xCE84FFDF, 0xF5718801, 0x3DD64B04, 0xA26F263B, - 0x7ED48400, 0x547EEBE6, 0x446D4CA0, 0x6CF3D6F5, - 0x2649ABDF, 0xAEA0C7F5, 0x36338CC1, 0x503F7E93, - 0xD3772061, 0x11B638E1, 0x72500E03, 0xF80EB2BB, - 0xABE0502E, 0xEC8D77DE, 0x57971E81, 0xE14F6746, - 0xC9335400, 0x6920318F, 0x081DBB99, 0xFFC304A5, - 0x4D351805, 0x7F3D5CE3, 0xA6C866C6, 0x5D5BCCA9, - 0xDAEC6FEA, 0x9F926F91, 0x9F46222F, 0x3991467D, - 0xA5BF6D8E, 0x1143C44F, 0x43958302, 0xD0214EEB, - 0x022083B8, 0x3FB6180C, 0x18F8931E, 0x281658E6, - 0x26486E3E, 0x8BD78A70, 0x7477E4C1, 0xB506E07C, - 0xF32D0A25, 0x79098B02, 0xE4EABB81, 0x28123B23, - 0x69DEAD38, 0x1574CA16, 0xDF871B62, 0x211C40B7, - 0xA51A9EF9, 0x0014377B, 0x041E8AC8, 0x09114003, - 0xBD59E4D2, 0xE3D156D5, 0x4FE876D5, 0x2F91A340, - 0x557BE8DE, 0x00EAE4A7, 0x0CE5C2EC, 0x4DB4BBA6, - 0xE756BDFF, 0xDD3369AC, 0xEC17B035, 0x06572327, - 0x99AFC8B0, 0x56C8C391, 0x6B65811C, 0x5E146119, - 0x6E85CB75, 0xBE07C002, 0xC2325577, 0x893FF4EC, - 0x5BBFC92D, 0xD0EC3B25, 0xB7801AB7, 0x8D6D3B24, - 0x20C763EF, 0xC366A5FC, 0x9C382880, 0x0ACE3205, - 0xAAC9548A, 0xECA1D7C7, 0x041AFA32, 0x1D16625A, - 0x6701902C, 0x9B757A54, 0x31D477F7, 0x9126B031, - 0x36CC6FDB, 0xC70B8B46, 0xD9E66A48, 0x56E55A79, - 0x026A4CEB, 0x52437EFF, 0x2F8F76B4, 0x0DF980A5, - 0x8674CDE3, 0xEDDA04EB, 0x17A9BE04, 0x2C18F4DF, - 0xB7747F9D, 0xAB2AF7B4, 0xEFC34D20, 0x2E096B7C, - 0x1741A254, 0xE5B6A035, 0x213D42F6, 0x2C1C7C26, - 0x61C2F50F, 0x6552DAF9, 0xD2C231F8, 0x25130F69, - 0xD8167FA2, 0x0418F2C8, 0x001A96A6, 0x0D1526AB, - 0x63315C21, 0x5E0A72EC, 0x49BAFEFD, 0x187908D9, - 0x8D0DBD86, 0x311170A7, 0x3E9B640C, 0xCC3E10D7, - 0xD5CAD3B6, 0x0CAEC388, 0xF73001E1, 0x6C728AFF, - 0x71EAE2A1, 0x1F9AF36E, 0xCFCBD12F, 0xC1DE8417, - 0xAC07BE6B, 0xCB44A1D8, 0x8B9B0F56, 0x013988C3, - 0xB1C52FCA, 0xB4BE31CD, 0xD8782806, 0x12A3A4E2, - 0x6F7DE532, 0x58FD7EB6, 0xD01EE900, 0x24ADFFC2, - 0xF4990FC5, 0x9711AAC5, 0x001D7B95, 0x82E5E7D2, - 0x109873F6, 0x00613096, 0xC32D9521, 0xADA121FF, - 0x29908415, 0x7FBB977F, 0xAF9EB3DB, 0x29C9ED2A, - 0x5CE2A465, 0xA730F32C, 0xD0AA3FE8, 0x8A5CC091, - 0xD49E2CE7, 0x0CE454A9, 0xD60ACD86, 0x015F1919, - 0x77079103, 0xDEA03AF6, 0x78A8565E, 0xDEE356DF, - 0x21F05CBE, 0x8B75E387, 0xB3C50651, 0xB8A5C3EF, - 0xD8EEB6D2, 0xE523BE77, 0xC2154529, 0x2F69EFDF, - 0xAFE67AFB, 0xF470C4B2, 0xF3E0EB5B, 0xD6CC9876, - 0x39E4460C, 0x1FDA8538, 0x1987832F, 0xCA007367, - 0xA99144F8, 0x296B299E, 0x492FC295, 0x9266BEAB, - 0xB5676E69, 0x9BD3DDDA, 0xDF7E052F, 0xDB25701C, - 0x1B5E51EE, 0xF65324E6, 0x6AFCE36C, 0x0316CC04, - 0x8644213E, 0xB7DC59D0, 0x7965291F, 0xCCD6FD43, - 0x41823979, 0x932BCDF6, 0xB657C34D, 0x4EDFD282, - 0x7AE5290C, 0x3CB9536B, 0x851E20FE, 0x9833557E, - 0x13ECF0B0, 0xD3FFB372, 0x3F85C5C1, 0x0AEF7ED2 -}; - -static const u_int32_t cast_sbox5[256] = { - 0x7EC90C04, 0x2C6E74B9, 0x9B0E66DF, 0xA6337911, - 0xB86A7FFF, 0x1DD358F5, 0x44DD9D44, 0x1731167F, - 0x08FBF1FA, 0xE7F511CC, 0xD2051B00, 0x735ABA00, - 0x2AB722D8, 0x386381CB, 0xACF6243A, 0x69BEFD7A, - 0xE6A2E77F, 0xF0C720CD, 0xC4494816, 0xCCF5C180, - 0x38851640, 0x15B0A848, 0xE68B18CB, 0x4CAADEFF, - 0x5F480A01, 0x0412B2AA, 0x259814FC, 0x41D0EFE2, - 0x4E40B48D, 0x248EB6FB, 0x8DBA1CFE, 0x41A99B02, - 0x1A550A04, 0xBA8F65CB, 0x7251F4E7, 0x95A51725, - 0xC106ECD7, 0x97A5980A, 0xC539B9AA, 0x4D79FE6A, - 0xF2F3F763, 0x68AF8040, 0xED0C9E56, 0x11B4958B, - 0xE1EB5A88, 0x8709E6B0, 0xD7E07156, 0x4E29FEA7, - 0x6366E52D, 0x02D1C000, 0xC4AC8E05, 0x9377F571, - 0x0C05372A, 0x578535F2, 0x2261BE02, 0xD642A0C9, - 0xDF13A280, 0x74B55BD2, 0x682199C0, 0xD421E5EC, - 0x53FB3CE8, 0xC8ADEDB3, 0x28A87FC9, 0x3D959981, - 0x5C1FF900, 0xFE38D399, 0x0C4EFF0B, 0x062407EA, - 0xAA2F4FB1, 0x4FB96976, 0x90C79505, 0xB0A8A774, - 0xEF55A1FF, 0xE59CA2C2, 0xA6B62D27, 0xE66A4263, - 0xDF65001F, 0x0EC50966, 0xDFDD55BC, 0x29DE0655, - 0x911E739A, 0x17AF8975, 0x32C7911C, 0x89F89468, - 0x0D01E980, 0x524755F4, 0x03B63CC9, 0x0CC844B2, - 0xBCF3F0AA, 0x87AC36E9, 0xE53A7426, 0x01B3D82B, - 0x1A9E7449, 0x64EE2D7E, 0xCDDBB1DA, 0x01C94910, - 0xB868BF80, 0x0D26F3FD, 0x9342EDE7, 0x04A5C284, - 0x636737B6, 0x50F5B616, 0xF24766E3, 0x8ECA36C1, - 0x136E05DB, 0xFEF18391, 0xFB887A37, 0xD6E7F7D4, - 0xC7FB7DC9, 0x3063FCDF, 0xB6F589DE, 0xEC2941DA, - 0x26E46695, 0xB7566419, 0xF654EFC5, 0xD08D58B7, - 0x48925401, 0xC1BACB7F, 0xE5FF550F, 0xB6083049, - 0x5BB5D0E8, 0x87D72E5A, 0xAB6A6EE1, 0x223A66CE, - 0xC62BF3CD, 0x9E0885F9, 0x68CB3E47, 0x086C010F, - 0xA21DE820, 0xD18B69DE, 0xF3F65777, 0xFA02C3F6, - 0x407EDAC3, 0xCBB3D550, 0x1793084D, 0xB0D70EBA, - 0x0AB378D5, 0xD951FB0C, 0xDED7DA56, 0x4124BBE4, - 0x94CA0B56, 0x0F5755D1, 0xE0E1E56E, 0x6184B5BE, - 0x580A249F, 0x94F74BC0, 0xE327888E, 0x9F7B5561, - 0xC3DC0280, 0x05687715, 0x646C6BD7, 0x44904DB3, - 0x66B4F0A3, 0xC0F1648A, 0x697ED5AF, 0x49E92FF6, - 0x309E374F, 0x2CB6356A, 0x85808573, 0x4991F840, - 0x76F0AE02, 0x083BE84D, 0x28421C9A, 0x44489406, - 0x736E4CB8, 0xC1092910, 0x8BC95FC6, 0x7D869CF4, - 0x134F616F, 0x2E77118D, 0xB31B2BE1, 0xAA90B472, - 0x3CA5D717, 0x7D161BBA, 0x9CAD9010, 0xAF462BA2, - 0x9FE459D2, 0x45D34559, 0xD9F2DA13, 0xDBC65487, - 0xF3E4F94E, 0x176D486F, 0x097C13EA, 0x631DA5C7, - 0x445F7382, 0x175683F4, 0xCDC66A97, 0x70BE0288, - 0xB3CDCF72, 0x6E5DD2F3, 0x20936079, 0x459B80A5, - 0xBE60E2DB, 0xA9C23101, 0xEBA5315C, 0x224E42F2, - 0x1C5C1572, 0xF6721B2C, 0x1AD2FFF3, 0x8C25404E, - 0x324ED72F, 0x4067B7FD, 0x0523138E, 0x5CA3BC78, - 0xDC0FD66E, 0x75922283, 0x784D6B17, 0x58EBB16E, - 0x44094F85, 0x3F481D87, 0xFCFEAE7B, 0x77B5FF76, - 0x8C2302BF, 0xAAF47556, 0x5F46B02A, 0x2B092801, - 0x3D38F5F7, 0x0CA81F36, 0x52AF4A8A, 0x66D5E7C0, - 0xDF3B0874, 0x95055110, 0x1B5AD7A8, 0xF61ED5AD, - 0x6CF6E479, 0x20758184, 0xD0CEFA65, 0x88F7BE58, - 0x4A046826, 0x0FF6F8F3, 0xA09C7F70, 0x5346ABA0, - 0x5CE96C28, 0xE176EDA3, 0x6BAC307F, 0x376829D2, - 0x85360FA9, 0x17E3FE2A, 0x24B79767, 0xF5A96B20, - 0xD6CD2595, 0x68FF1EBF, 0x7555442C, 0xF19F06BE, - 0xF9E0659A, 0xEEB9491D, 0x34010718, 0xBB30CAB8, - 0xE822FE15, 0x88570983, 0x750E6249, 0xDA627E55, - 0x5E76FFA8, 0xB1534546, 0x6D47DE08, 0xEFE9E7D4 -}; - -static const u_int32_t cast_sbox6[256] = { - 0xF6FA8F9D, 0x2CAC6CE1, 0x4CA34867, 0xE2337F7C, - 0x95DB08E7, 0x016843B4, 0xECED5CBC, 0x325553AC, - 0xBF9F0960, 0xDFA1E2ED, 0x83F0579D, 0x63ED86B9, - 0x1AB6A6B8, 0xDE5EBE39, 0xF38FF732, 0x8989B138, - 0x33F14961, 0xC01937BD, 0xF506C6DA, 0xE4625E7E, - 0xA308EA99, 0x4E23E33C, 0x79CBD7CC, 0x48A14367, - 0xA3149619, 0xFEC94BD5, 0xA114174A, 0xEAA01866, - 0xA084DB2D, 0x09A8486F, 0xA888614A, 0x2900AF98, - 0x01665991, 0xE1992863, 0xC8F30C60, 0x2E78EF3C, - 0xD0D51932, 0xCF0FEC14, 0xF7CA07D2, 0xD0A82072, - 0xFD41197E, 0x9305A6B0, 0xE86BE3DA, 0x74BED3CD, - 0x372DA53C, 0x4C7F4448, 0xDAB5D440, 0x6DBA0EC3, - 0x083919A7, 0x9FBAEED9, 0x49DBCFB0, 0x4E670C53, - 0x5C3D9C01, 0x64BDB941, 0x2C0E636A, 0xBA7DD9CD, - 0xEA6F7388, 0xE70BC762, 0x35F29ADB, 0x5C4CDD8D, - 0xF0D48D8C, 0xB88153E2, 0x08A19866, 0x1AE2EAC8, - 0x284CAF89, 0xAA928223, 0x9334BE53, 0x3B3A21BF, - 0x16434BE3, 0x9AEA3906, 0xEFE8C36E, 0xF890CDD9, - 0x80226DAE, 0xC340A4A3, 0xDF7E9C09, 0xA694A807, - 0x5B7C5ECC, 0x221DB3A6, 0x9A69A02F, 0x68818A54, - 0xCEB2296F, 0x53C0843A, 0xFE893655, 0x25BFE68A, - 0xB4628ABC, 0xCF222EBF, 0x25AC6F48, 0xA9A99387, - 0x53BDDB65, 0xE76FFBE7, 0xE967FD78, 0x0BA93563, - 0x8E342BC1, 0xE8A11BE9, 0x4980740D, 0xC8087DFC, - 0x8DE4BF99, 0xA11101A0, 0x7FD37975, 0xDA5A26C0, - 0xE81F994F, 0x9528CD89, 0xFD339FED, 0xB87834BF, - 0x5F04456D, 0x22258698, 0xC9C4C83B, 0x2DC156BE, - 0x4F628DAA, 0x57F55EC5, 0xE2220ABE, 0xD2916EBF, - 0x4EC75B95, 0x24F2C3C0, 0x42D15D99, 0xCD0D7FA0, - 0x7B6E27FF, 0xA8DC8AF0, 0x7345C106, 0xF41E232F, - 0x35162386, 0xE6EA8926, 0x3333B094, 0x157EC6F2, - 0x372B74AF, 0x692573E4, 0xE9A9D848, 0xF3160289, - 0x3A62EF1D, 0xA787E238, 0xF3A5F676, 0x74364853, - 0x20951063, 0x4576698D, 0xB6FAD407, 0x592AF950, - 0x36F73523, 0x4CFB6E87, 0x7DA4CEC0, 0x6C152DAA, - 0xCB0396A8, 0xC50DFE5D, 0xFCD707AB, 0x0921C42F, - 0x89DFF0BB, 0x5FE2BE78, 0x448F4F33, 0x754613C9, - 0x2B05D08D, 0x48B9D585, 0xDC049441, 0xC8098F9B, - 0x7DEDE786, 0xC39A3373, 0x42410005, 0x6A091751, - 0x0EF3C8A6, 0x890072D6, 0x28207682, 0xA9A9F7BE, - 0xBF32679D, 0xD45B5B75, 0xB353FD00, 0xCBB0E358, - 0x830F220A, 0x1F8FB214, 0xD372CF08, 0xCC3C4A13, - 0x8CF63166, 0x061C87BE, 0x88C98F88, 0x6062E397, - 0x47CF8E7A, 0xB6C85283, 0x3CC2ACFB, 0x3FC06976, - 0x4E8F0252, 0x64D8314D, 0xDA3870E3, 0x1E665459, - 0xC10908F0, 0x513021A5, 0x6C5B68B7, 0x822F8AA0, - 0x3007CD3E, 0x74719EEF, 0xDC872681, 0x073340D4, - 0x7E432FD9, 0x0C5EC241, 0x8809286C, 0xF592D891, - 0x08A930F6, 0x957EF305, 0xB7FBFFBD, 0xC266E96F, - 0x6FE4AC98, 0xB173ECC0, 0xBC60B42A, 0x953498DA, - 0xFBA1AE12, 0x2D4BD736, 0x0F25FAAB, 0xA4F3FCEB, - 0xE2969123, 0x257F0C3D, 0x9348AF49, 0x361400BC, - 0xE8816F4A, 0x3814F200, 0xA3F94043, 0x9C7A54C2, - 0xBC704F57, 0xDA41E7F9, 0xC25AD33A, 0x54F4A084, - 0xB17F5505, 0x59357CBE, 0xEDBD15C8, 0x7F97C5AB, - 0xBA5AC7B5, 0xB6F6DEAF, 0x3A479C3A, 0x5302DA25, - 0x653D7E6A, 0x54268D49, 0x51A477EA, 0x5017D55B, - 0xD7D25D88, 0x44136C76, 0x0404A8C8, 0xB8E5A121, - 0xB81A928A, 0x60ED5869, 0x97C55B96, 0xEAEC991B, - 0x29935913, 0x01FDB7F1, 0x088E8DFA, 0x9AB6F6F5, - 0x3B4CBF9F, 0x4A5DE3AB, 0xE6051D35, 0xA0E1D855, - 0xD36B4CF1, 0xF544EDEB, 0xB0E93524, 0xBEBB8FBD, - 0xA2D762CF, 0x49C92F54, 0x38B5F331, 0x7128A454, - 0x48392905, 0xA65B1DB8, 0x851C97BD, 0xD675CF2F -}; - -static const u_int32_t cast_sbox7[256] = { - 0x85E04019, 0x332BF567, 0x662DBFFF, 0xCFC65693, - 0x2A8D7F6F, 0xAB9BC912, 0xDE6008A1, 0x2028DA1F, - 0x0227BCE7, 0x4D642916, 0x18FAC300, 0x50F18B82, - 0x2CB2CB11, 0xB232E75C, 0x4B3695F2, 0xB28707DE, - 0xA05FBCF6, 0xCD4181E9, 0xE150210C, 0xE24EF1BD, - 0xB168C381, 0xFDE4E789, 0x5C79B0D8, 0x1E8BFD43, - 0x4D495001, 0x38BE4341, 0x913CEE1D, 0x92A79C3F, - 0x089766BE, 0xBAEEADF4, 0x1286BECF, 0xB6EACB19, - 0x2660C200, 0x7565BDE4, 0x64241F7A, 0x8248DCA9, - 0xC3B3AD66, 0x28136086, 0x0BD8DFA8, 0x356D1CF2, - 0x107789BE, 0xB3B2E9CE, 0x0502AA8F, 0x0BC0351E, - 0x166BF52A, 0xEB12FF82, 0xE3486911, 0xD34D7516, - 0x4E7B3AFF, 0x5F43671B, 0x9CF6E037, 0x4981AC83, - 0x334266CE, 0x8C9341B7, 0xD0D854C0, 0xCB3A6C88, - 0x47BC2829, 0x4725BA37, 0xA66AD22B, 0x7AD61F1E, - 0x0C5CBAFA, 0x4437F107, 0xB6E79962, 0x42D2D816, - 0x0A961288, 0xE1A5C06E, 0x13749E67, 0x72FC081A, - 0xB1D139F7, 0xF9583745, 0xCF19DF58, 0xBEC3F756, - 0xC06EBA30, 0x07211B24, 0x45C28829, 0xC95E317F, - 0xBC8EC511, 0x38BC46E9, 0xC6E6FA14, 0xBAE8584A, - 0xAD4EBC46, 0x468F508B, 0x7829435F, 0xF124183B, - 0x821DBA9F, 0xAFF60FF4, 0xEA2C4E6D, 0x16E39264, - 0x92544A8B, 0x009B4FC3, 0xABA68CED, 0x9AC96F78, - 0x06A5B79A, 0xB2856E6E, 0x1AEC3CA9, 0xBE838688, - 0x0E0804E9, 0x55F1BE56, 0xE7E5363B, 0xB3A1F25D, - 0xF7DEBB85, 0x61FE033C, 0x16746233, 0x3C034C28, - 0xDA6D0C74, 0x79AAC56C, 0x3CE4E1AD, 0x51F0C802, - 0x98F8F35A, 0x1626A49F, 0xEED82B29, 0x1D382FE3, - 0x0C4FB99A, 0xBB325778, 0x3EC6D97B, 0x6E77A6A9, - 0xCB658B5C, 0xD45230C7, 0x2BD1408B, 0x60C03EB7, - 0xB9068D78, 0xA33754F4, 0xF430C87D, 0xC8A71302, - 0xB96D8C32, 0xEBD4E7BE, 0xBE8B9D2D, 0x7979FB06, - 0xE7225308, 0x8B75CF77, 0x11EF8DA4, 0xE083C858, - 0x8D6B786F, 0x5A6317A6, 0xFA5CF7A0, 0x5DDA0033, - 0xF28EBFB0, 0xF5B9C310, 0xA0EAC280, 0x08B9767A, - 0xA3D9D2B0, 0x79D34217, 0x021A718D, 0x9AC6336A, - 0x2711FD60, 0x438050E3, 0x069908A8, 0x3D7FEDC4, - 0x826D2BEF, 0x4EEB8476, 0x488DCF25, 0x36C9D566, - 0x28E74E41, 0xC2610ACA, 0x3D49A9CF, 0xBAE3B9DF, - 0xB65F8DE6, 0x92AEAF64, 0x3AC7D5E6, 0x9EA80509, - 0xF22B017D, 0xA4173F70, 0xDD1E16C3, 0x15E0D7F9, - 0x50B1B887, 0x2B9F4FD5, 0x625ABA82, 0x6A017962, - 0x2EC01B9C, 0x15488AA9, 0xD716E740, 0x40055A2C, - 0x93D29A22, 0xE32DBF9A, 0x058745B9, 0x3453DC1E, - 0xD699296E, 0x496CFF6F, 0x1C9F4986, 0xDFE2ED07, - 0xB87242D1, 0x19DE7EAE, 0x053E561A, 0x15AD6F8C, - 0x66626C1C, 0x7154C24C, 0xEA082B2A, 0x93EB2939, - 0x17DCB0F0, 0x58D4F2AE, 0x9EA294FB, 0x52CF564C, - 0x9883FE66, 0x2EC40581, 0x763953C3, 0x01D6692E, - 0xD3A0C108, 0xA1E7160E, 0xE4F2DFA6, 0x693ED285, - 0x74904698, 0x4C2B0EDD, 0x4F757656, 0x5D393378, - 0xA132234F, 0x3D321C5D, 0xC3F5E194, 0x4B269301, - 0xC79F022F, 0x3C997E7E, 0x5E4F9504, 0x3FFAFBBD, - 0x76F7AD0E, 0x296693F4, 0x3D1FCE6F, 0xC61E45BE, - 0xD3B5AB34, 0xF72BF9B7, 0x1B0434C0, 0x4E72B567, - 0x5592A33D, 0xB5229301, 0xCFD2A87F, 0x60AEB767, - 0x1814386B, 0x30BCC33D, 0x38A0C07D, 0xFD1606F2, - 0xC363519B, 0x589DD390, 0x5479F8E6, 0x1CB8D647, - 0x97FD61A9, 0xEA7759F4, 0x2D57539D, 0x569A58CF, - 0xE84E63AD, 0x462E1B78, 0x6580F87E, 0xF3817914, - 0x91DA55F4, 0x40A230F3, 0xD1988F35, 0xB6E318D2, - 0x3FFA50BC, 0x3D40F021, 0xC3C0BDAE, 0x4958C24C, - 0x518F36B2, 0x84B1D370, 0x0FEDCE83, 0x878DDADA, - 0xF2A279C7, 0x94E01BE8, 0x90716F4B, 0x954B8AA3 -}; - -static const u_int32_t cast_sbox8[256] = { - 0xE216300D, 0xBBDDFFFC, 0xA7EBDABD, 0x35648095, - 0x7789F8B7, 0xE6C1121B, 0x0E241600, 0x052CE8B5, - 0x11A9CFB0, 0xE5952F11, 0xECE7990A, 0x9386D174, - 0x2A42931C, 0x76E38111, 0xB12DEF3A, 0x37DDDDFC, - 0xDE9ADEB1, 0x0A0CC32C, 0xBE197029, 0x84A00940, - 0xBB243A0F, 0xB4D137CF, 0xB44E79F0, 0x049EEDFD, - 0x0B15A15D, 0x480D3168, 0x8BBBDE5A, 0x669DED42, - 0xC7ECE831, 0x3F8F95E7, 0x72DF191B, 0x7580330D, - 0x94074251, 0x5C7DCDFA, 0xABBE6D63, 0xAA402164, - 0xB301D40A, 0x02E7D1CA, 0x53571DAE, 0x7A3182A2, - 0x12A8DDEC, 0xFDAA335D, 0x176F43E8, 0x71FB46D4, - 0x38129022, 0xCE949AD4, 0xB84769AD, 0x965BD862, - 0x82F3D055, 0x66FB9767, 0x15B80B4E, 0x1D5B47A0, - 0x4CFDE06F, 0xC28EC4B8, 0x57E8726E, 0x647A78FC, - 0x99865D44, 0x608BD593, 0x6C200E03, 0x39DC5FF6, - 0x5D0B00A3, 0xAE63AFF2, 0x7E8BD632, 0x70108C0C, - 0xBBD35049, 0x2998DF04, 0x980CF42A, 0x9B6DF491, - 0x9E7EDD53, 0x06918548, 0x58CB7E07, 0x3B74EF2E, - 0x522FFFB1, 0xD24708CC, 0x1C7E27CD, 0xA4EB215B, - 0x3CF1D2E2, 0x19B47A38, 0x424F7618, 0x35856039, - 0x9D17DEE7, 0x27EB35E6, 0xC9AFF67B, 0x36BAF5B8, - 0x09C467CD, 0xC18910B1, 0xE11DBF7B, 0x06CD1AF8, - 0x7170C608, 0x2D5E3354, 0xD4DE495A, 0x64C6D006, - 0xBCC0C62C, 0x3DD00DB3, 0x708F8F34, 0x77D51B42, - 0x264F620F, 0x24B8D2BF, 0x15C1B79E, 0x46A52564, - 0xF8D7E54E, 0x3E378160, 0x7895CDA5, 0x859C15A5, - 0xE6459788, 0xC37BC75F, 0xDB07BA0C, 0x0676A3AB, - 0x7F229B1E, 0x31842E7B, 0x24259FD7, 0xF8BEF472, - 0x835FFCB8, 0x6DF4C1F2, 0x96F5B195, 0xFD0AF0FC, - 0xB0FE134C, 0xE2506D3D, 0x4F9B12EA, 0xF215F225, - 0xA223736F, 0x9FB4C428, 0x25D04979, 0x34C713F8, - 0xC4618187, 0xEA7A6E98, 0x7CD16EFC, 0x1436876C, - 0xF1544107, 0xBEDEEE14, 0x56E9AF27, 0xA04AA441, - 0x3CF7C899, 0x92ECBAE6, 0xDD67016D, 0x151682EB, - 0xA842EEDF, 0xFDBA60B4, 0xF1907B75, 0x20E3030F, - 0x24D8C29E, 0xE139673B, 0xEFA63FB8, 0x71873054, - 0xB6F2CF3B, 0x9F326442, 0xCB15A4CC, 0xB01A4504, - 0xF1E47D8D, 0x844A1BE5, 0xBAE7DFDC, 0x42CBDA70, - 0xCD7DAE0A, 0x57E85B7A, 0xD53F5AF6, 0x20CF4D8C, - 0xCEA4D428, 0x79D130A4, 0x3486EBFB, 0x33D3CDDC, - 0x77853B53, 0x37EFFCB5, 0xC5068778, 0xE580B3E6, - 0x4E68B8F4, 0xC5C8B37E, 0x0D809EA2, 0x398FEB7C, - 0x132A4F94, 0x43B7950E, 0x2FEE7D1C, 0x223613BD, - 0xDD06CAA2, 0x37DF932B, 0xC4248289, 0xACF3EBC3, - 0x5715F6B7, 0xEF3478DD, 0xF267616F, 0xC148CBE4, - 0x9052815E, 0x5E410FAB, 0xB48A2465, 0x2EDA7FA4, - 0xE87B40E4, 0xE98EA084, 0x5889E9E1, 0xEFD390FC, - 0xDD07D35B, 0xDB485694, 0x38D7E5B2, 0x57720101, - 0x730EDEBC, 0x5B643113, 0x94917E4F, 0x503C2FBA, - 0x646F1282, 0x7523D24A, 0xE0779695, 0xF9C17A8F, - 0x7A5B2121, 0xD187B896, 0x29263A4D, 0xBA510CDF, - 0x81F47C9F, 0xAD1163ED, 0xEA7B5965, 0x1A00726E, - 0x11403092, 0x00DA6D77, 0x4A0CDD61, 0xAD1F4603, - 0x605BDFB0, 0x9EEDC364, 0x22EBE6A8, 0xCEE7D28A, - 0xA0E736A0, 0x5564A6B9, 0x10853209, 0xC7EB8F37, - 0x2DE705CA, 0x8951570F, 0xDF09822B, 0xBD691A6C, - 0xAA12E4F2, 0x87451C0F, 0xE0F6A27A, 0x3ADA4819, - 0x4CF1764F, 0x0D771C2B, 0x67CDB156, 0x350D8384, - 0x5938FA0F, 0x42399EF3, 0x36997B07, 0x0E84093D, - 0x4AA93E61, 0x8360D87B, 0x1FA98B0C, 0x1149382C, - 0xE97625A5, 0x0614D1B7, 0x0E25244B, 0x0C768347, - 0x589E8D82, 0x0D2059D1, 0xA466BB1E, 0xF8DA0A82, - 0x04F19130, 0xBA6E4EC0, 0x99265164, 0x1EE7230D, - 0x50B2AD80, 0xEAEE6801, 0x8DB2A283, 0xEA8BF59E -}; - -/* Macros to access 8-bit bytes out of a 32-bit word */ -#define U8a(x) ( (u_int8_t) (x>>24) ) -#define U8b(x) ( (u_int8_t) ((x>>16)&255) ) -#define U8c(x) ( (u_int8_t) ((x>>8)&255) ) -#define U8d(x) ( (u_int8_t) ((x)&255) ) - -/* Circular left shift */ -#define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) ) - -/* CAST-128 uses three different round functions */ -#define F1(l, r, i) \ - t = ROL(key->xkey[i] + r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) - \ - cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; -#define F2(l, r, i) \ - t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) + \ - cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; -#define F3(l, r, i) \ - t = ROL(key->xkey[i] - r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) ^ \ - cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; - - -/***** Encryption Function *****/ - -void -cast_encrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) -{ - u_int32_t t, l, r; - - /* Get inblock into l,r */ - l = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | - ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; - r = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | - ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; - /* Do the work */ - F1(l, r, 0); - F2(r, l, 1); - F3(l, r, 2); - F1(r, l, 3); - F2(l, r, 4); - F3(r, l, 5); - F1(l, r, 6); - F2(r, l, 7); - F3(l, r, 8); - F1(r, l, 9); - F2(l, r, 10); - F3(r, l, 11); - /* Only do full 16 rounds if key length > 80 bits */ - if (key->rounds > 12) { - F1(l, r, 12); - F2(r, l, 13); - F3(l, r, 14); - F1(r, l, 15); - } - /* Put l,r into outblock */ - outblock[0] = U8a(r); - outblock[1] = U8b(r); - outblock[2] = U8c(r); - outblock[3] = U8d(r); - outblock[4] = U8a(l); - outblock[5] = U8b(l); - outblock[6] = U8c(l); - outblock[7] = U8d(l); - /* Wipe clean */ - t = l = r = 0; -} - - -/***** Decryption Function *****/ - -void -cast_decrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) -{ - u_int32_t t, l, r; - - /* Get inblock into l,r */ - r = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | - ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; - l = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | - ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; - /* Do the work */ - /* Only do full 16 rounds if key length > 80 bits */ - if (key->rounds > 12) { - F1(r, l, 15); - F3(l, r, 14); - F2(r, l, 13); - F1(l, r, 12); - } - F3(r, l, 11); - F2(l, r, 10); - F1(r, l, 9); - F3(l, r, 8); - F2(r, l, 7); - F1(l, r, 6); - F3(r, l, 5); - F2(l, r, 4); - F1(r, l, 3); - F3(l, r, 2); - F2(r, l, 1); - F1(l, r, 0); - /* Put l,r into outblock */ - outblock[0] = U8a(l); - outblock[1] = U8b(l); - outblock[2] = U8c(l); - outblock[3] = U8d(l); - outblock[4] = U8a(r); - outblock[5] = U8b(r); - outblock[6] = U8c(r); - outblock[7] = U8d(r); - /* Wipe clean */ - t = l = r = 0; -} - - -/***** Key Schedual *****/ - -void -cast_setkey(cast_key* key, u_int8_t* rawkey, int keybytes) -{ - u_int32_t t[4], z[4], x[4]; - int i; - - /* Set number of rounds to 12 or 16, depending on key length */ - key->rounds = (keybytes <= 10 ? 12 : 16); - - /* Copy key to workspace x */ - for (i = 0; i < 4; i++) { - x[i] = 0; - if ((i*4+0) < keybytes) x[i] = (u_int32_t)rawkey[i*4+0] << 24; - if ((i*4+1) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+1] << 16; - if ((i*4+2) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+2] << 8; - if ((i*4+3) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+3]; - } - /* Generate 32 subkeys, four at a time */ - for (i = 0; i < 32; i+=4) { - switch (i & 4) { - case 0: - t[0] = z[0] = x[0] ^ cast_sbox5[U8b(x[3])] ^ - cast_sbox6[U8d(x[3])] ^ cast_sbox7[U8a(x[3])] ^ - cast_sbox8[U8c(x[3])] ^ cast_sbox7[U8a(x[2])]; - t[1] = z[1] = x[2] ^ cast_sbox5[U8a(z[0])] ^ - cast_sbox6[U8c(z[0])] ^ cast_sbox7[U8b(z[0])] ^ - cast_sbox8[U8d(z[0])] ^ cast_sbox8[U8c(x[2])]; - t[2] = z[2] = x[3] ^ cast_sbox5[U8d(z[1])] ^ - cast_sbox6[U8c(z[1])] ^ cast_sbox7[U8b(z[1])] ^ - cast_sbox8[U8a(z[1])] ^ cast_sbox5[U8b(x[2])]; - t[3] = z[3] = x[1] ^ cast_sbox5[U8c(z[2])] ^ - cast_sbox6[U8b(z[2])] ^ cast_sbox7[U8d(z[2])] ^ - cast_sbox8[U8a(z[2])] ^ cast_sbox6[U8d(x[2])]; - break; - case 4: - t[0] = x[0] = z[2] ^ cast_sbox5[U8b(z[1])] ^ - cast_sbox6[U8d(z[1])] ^ cast_sbox7[U8a(z[1])] ^ - cast_sbox8[U8c(z[1])] ^ cast_sbox7[U8a(z[0])]; - t[1] = x[1] = z[0] ^ cast_sbox5[U8a(x[0])] ^ - cast_sbox6[U8c(x[0])] ^ cast_sbox7[U8b(x[0])] ^ - cast_sbox8[U8d(x[0])] ^ cast_sbox8[U8c(z[0])]; - t[2] = x[2] = z[1] ^ cast_sbox5[U8d(x[1])] ^ - cast_sbox6[U8c(x[1])] ^ cast_sbox7[U8b(x[1])] ^ - cast_sbox8[U8a(x[1])] ^ cast_sbox5[U8b(z[0])]; - t[3] = x[3] = z[3] ^ cast_sbox5[U8c(x[2])] ^ - cast_sbox6[U8b(x[2])] ^ cast_sbox7[U8d(x[2])] ^ - cast_sbox8[U8a(x[2])] ^ cast_sbox6[U8d(z[0])]; - break; - } - switch (i & 12) { - case 0: - case 12: - key->xkey[i+0] = cast_sbox5[U8a(t[2])] ^ - cast_sbox6[U8b(t[2])] ^ cast_sbox7[U8d(t[1])] ^ - cast_sbox8[U8c(t[1])]; - key->xkey[i+1] = cast_sbox5[U8c(t[2])] ^ - cast_sbox6[U8d(t[2])] ^ cast_sbox7[U8b(t[1])] ^ - cast_sbox8[U8a(t[1])]; - key->xkey[i+2] = cast_sbox5[U8a(t[3])] ^ - cast_sbox6[U8b(t[3])] ^ cast_sbox7[U8d(t[0])] ^ - cast_sbox8[U8c(t[0])]; - key->xkey[i+3] = cast_sbox5[U8c(t[3])] ^ - cast_sbox6[U8d(t[3])] ^ cast_sbox7[U8b(t[0])] ^ - cast_sbox8[U8a(t[0])]; - break; - case 4: - case 8: - key->xkey[i+0] = cast_sbox5[U8d(t[0])] ^ - cast_sbox6[U8c(t[0])] ^ cast_sbox7[U8a(t[3])] ^ - cast_sbox8[U8b(t[3])]; - key->xkey[i+1] = cast_sbox5[U8b(t[0])] ^ - cast_sbox6[U8a(t[0])] ^ cast_sbox7[U8c(t[3])] ^ - cast_sbox8[U8d(t[3])]; - key->xkey[i+2] = cast_sbox5[U8d(t[1])] ^ - cast_sbox6[U8c(t[1])] ^ cast_sbox7[U8a(t[2])] ^ - cast_sbox8[U8b(t[2])]; - key->xkey[i+3] = cast_sbox5[U8b(t[1])] ^ - cast_sbox6[U8a(t[1])] ^ cast_sbox7[U8c(t[2])] ^ - cast_sbox8[U8d(t[2])]; - break; - } - switch (i & 12) { - case 0: - key->xkey[i+0] ^= cast_sbox5[U8c(z[0])]; - key->xkey[i+1] ^= cast_sbox6[U8c(z[1])]; - key->xkey[i+2] ^= cast_sbox7[U8b(z[2])]; - key->xkey[i+3] ^= cast_sbox8[U8a(z[3])]; - break; - case 4: - key->xkey[i+0] ^= cast_sbox5[U8a(x[2])]; - key->xkey[i+1] ^= cast_sbox6[U8b(x[3])]; - key->xkey[i+2] ^= cast_sbox7[U8d(x[0])]; - key->xkey[i+3] ^= cast_sbox8[U8d(x[1])]; - break; - case 8: - key->xkey[i+0] ^= cast_sbox5[U8b(z[2])]; - key->xkey[i+1] ^= cast_sbox6[U8a(z[3])]; - key->xkey[i+2] ^= cast_sbox7[U8c(z[0])]; - key->xkey[i+3] ^= cast_sbox8[U8c(z[1])]; - break; - case 12: - key->xkey[i+0] ^= cast_sbox5[U8d(x[0])]; - key->xkey[i+1] ^= cast_sbox6[U8d(x[1])]; - key->xkey[i+2] ^= cast_sbox7[U8a(x[2])]; - key->xkey[i+3] ^= cast_sbox8[U8b(x[3])]; - break; - } - if (i >= 16) { - key->xkey[i+0] &= 31; - key->xkey[i+1] &= 31; - key->xkey[i+2] &= 31; - key->xkey[i+3] &= 31; - } - } - /* Wipe clean */ - for (i = 0; i < 4; i++) { - t[i] = x[i] = z[i] = 0; - } -} - -/* Made in Canada */ - diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3 deleted file mode 100644 index b58894d9ad..0000000000 --- a/src/lib/libc/crypt/crypt.3 +++ /dev/null @@ -1,324 +0,0 @@ -.\" $OpenBSD: crypt.3,v 1.27 2007/10/08 11:55:27 pyr Exp $ -.\" -.\" FreeSec: libcrypt -.\" -.\" Copyright (c) 1994 David Burren -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the author nor the names of other contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" Manual page, using -mandoc macros -.\" -.Dd $Mdocdate: October 8 2007 $ -.Dt CRYPT 3 -.Os -.Sh NAME -.Nm crypt , -.Nm setkey , -.Nm encrypt , -.Nm des_setkey , -.Nm des_cipher , -.Nm bcrypt_gensalt , -.Nm bcrypt , -.Nm md5crypt -.Nd DES encryption -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Ft char * -.Fn crypt "const char *key" "const char *setting" -.Ft int -.Fn setkey "const char *key" -.Ft int -.Fn encrypt "char *block" "int flag" -.Ft int -.Fn des_setkey "const char *key" -.Ft int -.Fn des_cipher "const char *in" "char *out" "int32_t salt" "int count" -.Ft char * -.Fn bcrypt_gensalt "u_int8_t log_rounds" -.Ft char * -.Fn bcrypt "const char *key" "const char *salt" -.Ft char * -.Fn md5crypt "const char *key" "const char *salt" -.Sh DESCRIPTION -The -.Fn crypt -function performs password encryption based on the -.Tn NBS -Data Encryption Standard (DES). -Additional code has been added to deter key search attempts and to use -stronger hashing algorithms. -.Pp -The first argument to -.Fn crypt -is a -.Dv NUL Ns -terminated -string, typically a user's typed password. -The second is in one of three forms: -if it begins with an underscore -.Pq Ql _ -then an extended format is used -in interpreting both the key and the setting, as outlined below. -If it begins -with a string character -.Pq Ql $ -and a number then a different algorithm is used depending on the number. -At the moment a -.Ql $1 -chooses MD5 hashing and a -.Ql $2 -chooses Blowfish hashing; see below for more information. -.Ss Extended crypt -The -.Ar key -is divided into groups of 8 characters (the last group is null-padded) -and the low-order 7 bits of each character (56 bits per group) are -used to form the DES key as follows: -the first group of 56 bits becomes the initial DES key. -For each additional group, the XOR of the encryption of the current DES -key with itself and the group bits becomes the next DES key. -.Pp -The setting is a 9-character array consisting of an underscore followed -by 4 bytes of iteration count and 4 bytes of salt. -These are encoded as printable characters, 6 bits per character, -least significant character first. -The values 0 to 63 are encoded as -.Dq \&./0-9A-Za-z . -This allows 24 bits for both -.Fa count -and -.Fa salt . -.Ss "MD5" crypt -For -.Tn MD5 -crypt the version number, -.Fa salt -and the hashed password are separated by the -.Ql $ -character. -The maximum length of a password is limited by -the length counter of the MD5 context, which is about -2**64. -A valid MD5 password entry looks like this: -.Pp -.Dq $1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1 . -.Pp -The whole MD5 password string is passed as -.Fa setting -for interpretation. -.Ss "Blowfish" crypt -The -.Tn Blowfish -version of crypt has 128 bits of -.Fa salt -in order to make building dictionaries of common passwords space consuming. -The initial state of the -.Tn Blowfish -cipher is expanded using the -.Fa salt -and the -.Fa password -repeating the process a variable number of rounds, which is encoded in -the password string. -The maximum password length is 72. -The final Blowfish password entry is created by encrypting the string -.Pp -.Dq OrpheanBeholderScryDoubt -.Pp -with the -.Tn Blowfish -state 64 times. -.Pp -The version number, the logarithm of the number of rounds and -the concatenation of salt and hashed password are separated by the -.Ql $ -character. -An encoded -.Sq 8 -would specify 256 rounds. -A valid Blowfish password looks like this: -.Pp -.Dq $2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC . -.Pp -The whole Blowfish password string is passed as -.Fa setting -for interpretation. -.Ss "Traditional" crypt -The first 8 bytes of the key are null-padded, and the low-order 7 bits of -each character is used to form the 56-bit -.Tn DES -key. -.Pp -The setting is a 2-character array of the ASCII-encoded salt. -Thus only 12 bits of -.Fa salt -are used. -.Fa count -is set to 25. -.Ss DES Algorithm -The -.Fa salt -introduces disorder in the -.Tn DES -algorithm in one of 16777216 or 4096 possible ways -(i.e., with 24 or 12 bits: if bit -.Em i -of the -.Ar salt -is set, then bits -.Em i -and -.Em i+24 -are swapped in the -.Tn DES -E-box output). -.Pp -The DES key is used to encrypt a 64-bit constant using -.Ar count -iterations of -.Tn DES . -The value returned is a -.Dv NUL Ns -terminated -string, 20 or 13 bytes (plus NUL) in length, consisting of the -.Ar setting -followed by the encoded 64-bit encryption. -.Pp -The functions -.Fn encrypt , -.Fn setkey , -.Fn des_setkey , -and -.Fn des_cipher -provide access to the -.Tn DES -algorithm itself. -.Fn setkey -is passed a 64-byte array of binary values (numeric 0 or 1). -A 56-bit key is extracted from this array by dividing the -array into groups of 8, and ignoring the last bit in each group. -That bit is reserved for a byte parity check by DES, but is ignored -by these functions. -.Pp -The -.Fa block -argument to -.Fn encrypt -is also a 64-byte array of binary values. -If the value of -.Fa flag -is 0, -.Fa block -is encrypted otherwise it is decrypted. -The result is returned in the original array -.Fa block -after using the key specified by -.Fn setkey -to process it. -.Pp -The argument to -.Fn des_setkey -is a character array of length 8. -The least significant bit (the parity bit) in each character is ignored, -and the remaining bits are concatenated to form a 56-bit key. -The function -.Fn des_cipher -encrypts (or decrypts if -.Fa count -is negative) the 64-bits stored in the 8 characters at -.Fa in -using -.Xr abs 3 -of -.Fa count -iterations of -.Tn DES -and stores the 64-bit result in the 8 characters at -.Fa out -(which may be the same as -.Fa in ) . -The -.Fa salt -specifies perturbations to the -.Tn DES -E-box output as described above. -.Pp -The -.Fn crypt , -.Fn setkey , -and -.Fn des_setkey -functions all manipulate the same key space. -.Sh RETURN VALUES -The function -.Fn crypt -returns a pointer to the encrypted value on success, and -.Dv NULL -on failure. -The functions -.Fn setkey , -.Fn encrypt , -.Fn des_setkey , -and -.Fn des_cipher -return 0 on success and 1 on failure. -.Sh SEE ALSO -.Xr login 1 , -.Xr passwd 1 , -.Xr blowfish 3 , -.Xr getpass 3 , -.Xr md5 3 , -.Xr passwd 5 -.Sh HISTORY -A rotor-based -.Fn crypt -function appeared in -.At v3 . -The current style -.Fn crypt -first appeared in -.At v7 . -.Pp -This library (FreeSec 1.0) was developed outside the United States of America -as an unencumbered replacement for the U.S.-only libcrypt encryption -library. -Programs linked against the -.Fn crypt -interface may be exported from the U.S.A. only if they use -.Fn crypt -solely for authentication purposes and avoid use of -the other programmer interfaces listed above. -Special care has been taken -in the library so that programs which only use the -.Fn crypt -interface do not pull in the other components. -.Sh AUTHORS -.An David Burren Aq davidb@werj.com.au -.Sh BUGS -The -.Fn crypt -function returns a pointer to static data, and subsequent calls to -.Fn crypt -will modify the same object. diff --git a/src/lib/libc/crypt/crypt.c b/src/lib/libc/crypt/crypt.c deleted file mode 100644 index 15a784532d..0000000000 --- a/src/lib/libc/crypt/crypt.c +++ /dev/null @@ -1,696 +0,0 @@ -/* $OpenBSD: crypt.c,v 1.20 2005/08/08 08:05:33 espie Exp $ */ - -/* - * FreeSec: libcrypt - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren . - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - */ - -#include -#include -#include -#include -#include - -#ifdef DEBUG -# include -#endif - -static const u_char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 -}; - -static u_char inv_key_perm[64]; -static u_char u_key_perm[56]; -static u_char const key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -static const u_char key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -static u_char inv_comp_perm[56]; -static const u_char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -/* - * No E box is used, as it's replaced by some ANDs, shifts, and ORs. - */ - -static u_char u_sbox[8][64]; -static const u_char sbox[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 - }, - { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 - }, - { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 - }, - { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 - }, - { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 - }, - { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 - }, - { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 - }, - { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } -}; - -static u_char un_pbox[32]; -static const u_char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -const u_int32_t _des_bits32[32] = -{ - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 -}; - -const u_char _des_bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; - -static u_int32_t saltbits; -static int32_t old_salt; -static const u_int32_t *bits28, *bits24; -static u_char init_perm[64], final_perm[64]; -static u_int32_t en_keysl[16], en_keysr[16]; -static u_int32_t de_keysl[16], de_keysr[16]; -int _des_initialised = 0; -static u_char m_sbox[4][4096]; -static u_int32_t psbox[4][256]; -static u_int32_t ip_maskl[8][256], ip_maskr[8][256]; -static u_int32_t fp_maskl[8][256], fp_maskr[8][256]; -static u_int32_t key_perm_maskl[8][128], key_perm_maskr[8][128]; -static u_int32_t comp_maskl[8][128], comp_maskr[8][128]; -static u_int32_t old_rawkey0, old_rawkey1; - -static u_char ascii64[] = - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -/* 0000000000111111111122222222223333333333444444444455555555556666 */ -/* 0123456789012345678901234567890123456789012345678901234567890123 */ - -static __inline int -ascii_to_bin(char ch) -{ - if (ch > 'z') - return(0); - if (ch >= 'a') - return(ch - 'a' + 38); - if (ch > 'Z') - return(0); - if (ch >= 'A') - return(ch - 'A' + 12); - if (ch > '9') - return(0); - if (ch >= '.') - return(ch - '.'); - return(0); -} - -void -_des_init(void) -{ - int i, j, b, k, inbit, obit; - u_int32_t *p, *il, *ir, *fl, *fr; - - old_rawkey0 = old_rawkey1 = 0; - saltbits = 0; - old_salt = 0; - bits24 = (bits28 = _des_bits32 + 4) + 4; - - /* - * Invert the S-boxes, reordering the input bits. - */ - for (i = 0; i < 8; i++) - for (j = 0; j < 64; j++) { - b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); - u_sbox[i][j] = sbox[i][b]; - } - - /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. - */ - for (b = 0; b < 4; b++) - for (i = 0; i < 64; i++) - for (j = 0; j < 64; j++) - m_sbox[b][(i << 6) | j] = - (u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]; - - /* - * Set up the initial & final permutations into a useful form, and - * initialise the inverted key permutation. - */ - for (i = 0; i < 64; i++) { - init_perm[final_perm[i] = IP[i] - 1] = i; - inv_key_perm[i] = 255; - } - - /* - * Invert the key permutation and initialise the inverted key - * compression permutation. - */ - for (i = 0; i < 56; i++) { - u_key_perm[i] = key_perm[i] - 1; - inv_key_perm[key_perm[i] - 1] = i; - inv_comp_perm[i] = 255; - } - - /* - * Invert the key compression permutation. - */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = i; - } - - /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. - */ - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(il = &ip_maskl[k][i]) = 0; - *(ir = &ip_maskr[k][i]) = 0; - *(fl = &fp_maskl[k][i]) = 0; - *(fr = &fp_maskr[k][i]) = 0; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & _des_bits8[j]) { - if ((obit = init_perm[inbit]) < 32) - *il |= _des_bits32[obit]; - else - *ir |= _des_bits32[obit-32]; - if ((obit = final_perm[inbit]) < 32) - *fl |= _des_bits32[obit]; - else - *fr |= _des_bits32[obit - 32]; - } - } - } - for (i = 0; i < 128; i++) { - *(il = &key_perm_maskl[k][i]) = 0; - *(ir = &key_perm_maskr[k][i]) = 0; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & _des_bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit < 28) - *il |= bits28[obit]; - else - *ir |= bits28[obit - 28]; - } - } - *(il = &comp_maskl[k][i]) = 0; - *(ir = &comp_maskr[k][i]) = 0; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & _des_bits8[j + 1]) { - if ((obit=inv_comp_perm[inbit]) == 255) - continue; - if (obit < 24) - *il |= bits24[obit]; - else - *ir |= bits24[obit - 24]; - } - } - } - } - - /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. - */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = i; - - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { - *(p = &psbox[b][i]) = 0; - for (j = 0; j < 8; j++) { - if (i & _des_bits8[j]) - *p |= _des_bits32[un_pbox[8 * b + j]]; - } - } - - _des_initialised = 1; -} - -void -_des_setup_salt(int32_t salt) -{ - u_int32_t obit, saltbit; - int i; - - if (salt == old_salt) - return; - old_salt = salt; - - saltbits = 0; - saltbit = 1; - obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } -} - -int -des_setkey(const char *key) -{ - u_int32_t k0, k1, rawkey0, rawkey1; - int shifts, round; - - if (!_des_initialised) - _des_init(); - - rawkey0 = ntohl(*(u_int32_t *) key); - rawkey1 = ntohl(*(u_int32_t *) (key + 4)); - - if ((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { - /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. - */ - return(0); - } - old_rawkey0 = rawkey0; - old_rawkey1 = rawkey1; - - /* - * Do key permutation and split into two 28-bit subkeys. - */ - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for (round = 0; round < 16; round++) { - u_int32_t t0, t1; - - shifts += key_shifts[round]; - - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - - de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; - - de_keysr[15 - round] = - en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; - } - return(0); -} - -int -_des_do_des(u_int32_t l_in, u_int32_t r_in, u_int32_t *l_out, u_int32_t *r_out, - int count) -{ - /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - u_int32_t l, r, *kl, *kr, *kl1, *kr1; - u_int32_t f, r48l, r48r; - int round; - - if (count == 0) { - return(1); - } else if (count > 0) { - /* - * Encrypting - */ - kl1 = en_keysl; - kr1 = en_keysr; - } else { - /* - * Decrypting - */ - count = -count; - kl1 = de_keysl; - kr1 = de_keysr; - } - - /* - * Do initial permutation (IP). - */ - l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] - | ip_maskl[7][r_in & 0xff]; - r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] - | ip_maskr[7][r_in & 0xff]; - - while (count--) { - /* - * Do each round. - */ - kl = kl1; - kr = kr1; - round = 16; - while (round--) { - /* - * Expand R to 48 bits (simulate the E-box). - */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); - - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. - */ - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* - * Now that we've permuted things, complete f(). - */ - f ^= l; - l = r; - r = f; - } - r = l; - l = f; - } - /* - * Do final permutation (inverse of IP). - */ - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; - return(0); -} - -int -des_cipher(const char *in, char *out, int32_t salt, int count) -{ - u_int32_t l_out, r_out, rawl, rawr; - u_int32_t x[2]; - int retval; - - if (!_des_initialised) - _des_init(); - - _des_setup_salt(salt); - - memcpy(x, in, sizeof x); - rawl = ntohl(x[0]); - rawr = ntohl(x[1]); - retval = _des_do_des(rawl, rawr, &l_out, &r_out, count); - - x[0] = htonl(l_out); - x[1] = htonl(r_out); - memcpy(out, x, sizeof x); - return(retval); -} - -char * -crypt(const char *key, const char *setting) -{ - int i; - u_int32_t count, salt, l, r0, r1, keybuf[2]; - u_char *p, *q; - static u_char output[21]; - extern char *md5crypt(const char *, const char *); - extern char *bcrypt(const char *, const char *); - - if (setting[0] == '$') { - switch (setting[1]) { - case '1': - return (md5crypt(key, setting)); - default: - return bcrypt(key, setting); - } - } - - if (!_des_initialised) - _des_init(); - - /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. - */ - q = (u_char *) keybuf; - while ((q - (u_char *) keybuf) < sizeof(keybuf)) { - if ((*q++ = *key << 1)) - key++; - } - if (des_setkey((char *) keybuf)) - return(NULL); - - if (*setting == _PASSWORD_EFMT1) { - /* - * "new"-style: - * setting - underscore, 4 bytes of count, 4 bytes of salt - * key - unlimited characters - */ - for (i = 1, count = 0; i < 5; i++) - count |= ascii_to_bin(setting[i]) << (i - 1) * 6; - - for (i = 5, salt = 0; i < 9; i++) - salt |= ascii_to_bin(setting[i]) << (i - 5) * 6; - - while (*key) { - /* - * Encrypt the key with itself. - */ - if (des_cipher((char *)keybuf, (char *)keybuf, 0, 1)) - return(NULL); - /* - * And XOR with the next 8 characters of the key. - */ - q = (u_char *) keybuf; - while (((q - (u_char *) keybuf) < sizeof(keybuf)) && - *key) - *q++ ^= *key++ << 1; - - if (des_setkey((char *) keybuf)) - return(NULL); - } - strlcpy((char *)output, setting, 10); - - /* - * Double check that we weren't given a short setting. - * If we were, the above code will probably have created - * weird values for count and salt, but we don't really care. - * Just make sure the output string doesn't have an extra - * NUL in it. - */ - p = output + strlen((const char *)output); - } else { - /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters - */ - count = 25; - - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); - - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; - - p = output + 2; - } - _des_setup_salt(salt); - - /* - * Do it. - */ - if (_des_do_des(0, 0, &r0, &r1, count)) - return(NULL); - /* - * Now encode the result... - */ - l = (r0 >> 8); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = (r0 << 16) | ((r1 >> 16) & 0xffff); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = r1 << 2; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - *p = 0; - - return((char *)output); -} diff --git a/src/lib/libc/crypt/crypt2.c b/src/lib/libc/crypt/crypt2.c deleted file mode 100644 index 63a297e510..0000000000 --- a/src/lib/libc/crypt/crypt2.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $OpenBSD: crypt2.c,v 1.3 2005/08/08 08:05:33 espie Exp $ */ - -/* - * FreeSec: libcrypt - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren . - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - */ - -#include -#include -#include -#include -#include - -#ifdef DEBUG -# include -#endif - -extern const u_char _des_bits8[8]; -extern const u_int32_t _des_bits32[32]; -extern int _des_initialised; - -int -setkey(const char *key) -{ - int i, j; - u_int32_t packed_keys[2]; - u_char *p; - - p = (u_char *) packed_keys; - - for (i = 0; i < 8; i++) { - p[i] = 0; - for (j = 0; j < 8; j++) - if (*key++ & 1) - p[i] |= _des_bits8[j]; - } - return(des_setkey((char *)p)); -} - -int -encrypt(char *block, int flag) -{ - u_int32_t io[2]; - u_char *p; - int i, j, retval; - - if (!_des_initialised) - _des_init(); - - _des_setup_salt(0); - p = (u_char *)block; - for (i = 0; i < 2; i++) { - io[i] = 0L; - for (j = 0; j < 32; j++) - if (*p++ & 1) - io[i] |= _des_bits32[j]; - } - retval = _des_do_des(io[0], io[1], io, io + 1, flag ? -1 : 1); - for (i = 0; i < 2; i++) - for (j = 0; j < 32; j++) - block[(i << 5) | j] = (io[i] & _des_bits32[j]) ? 1 : 0; - return(retval); -} diff --git a/src/lib/libc/crypt/md5crypt.c b/src/lib/libc/crypt/md5crypt.c deleted file mode 100644 index fe1393cf7c..0000000000 --- a/src/lib/libc/crypt/md5crypt.c +++ /dev/null @@ -1,149 +0,0 @@ -/* $OpenBSD: md5crypt.c,v 1.14 2005/08/08 08:05:33 espie Exp $ */ - -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $ - * - */ - -#include -#include -#include -#include -#include - -static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static void to64(char *, u_int32_t, int); - -static void -to64(char *s, u_int32_t v, int n) -{ - while (--n >= 0) { - *s++ = itoa64[v&0x3f]; - v >>= 6; - } -} - -/* - * UNIX password - * - * Use MD5 for what it is best at... - */ - -char *md5crypt(const char *pw, const char *salt); - -char * -md5crypt(const char *pw, const char *salt) -{ - /* - * This string is magic for this algorithm. Having - * it this way, we can get get better later on - */ - static unsigned char *magic = (unsigned char *)"$1$"; - - static char passwd[120], *p; - static const unsigned char *sp,*ep; - unsigned char final[16]; - int sl,pl,i; - MD5_CTX ctx,ctx1; - u_int32_t l; - - /* Refine the Salt first */ - sp = (const unsigned char *)salt; - - /* If it starts with the magic string, then skip that */ - if(!strncmp((const char *)sp,(const char *)magic,strlen((const char *)magic))) - sp += strlen((const char *)magic); - - /* It stops at the first '$', max 8 chars */ - for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++) - continue; - - /* get the length of the true salt */ - sl = ep - sp; - - MD5Init(&ctx); - - /* The password first, since that is what is most unknown */ - MD5Update(&ctx,(const unsigned char *)pw,strlen(pw)); - - /* Then our magic string */ - MD5Update(&ctx,magic,strlen((const char *)magic)); - - /* Then the raw salt */ - MD5Update(&ctx,sp,sl); - - /* Then just as many characters of the MD5(pw,salt,pw) */ - MD5Init(&ctx1); - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Update(&ctx1,sp,sl); - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Final(final,&ctx1); - for(pl = strlen(pw); pl > 0; pl -= 16) - MD5Update(&ctx,final,pl>16 ? 16 : pl); - - /* Don't leave anything around in vm they could use. */ - memset(final,0,sizeof final); - - /* Then something really weird... */ - for (i = strlen(pw); i ; i >>= 1) - if(i&1) - MD5Update(&ctx, final, 1); - else - MD5Update(&ctx, (const unsigned char *)pw, 1); - - /* Now make the output string */ - snprintf(passwd, sizeof(passwd), "%s%.*s$", (char *)magic, - sl, (const char *)sp); - - MD5Final(final,&ctx); - - /* - * and now, just to make sure things don't run too fast - * On a 60 Mhz Pentium this takes 34 msec, so you would - * need 30 seconds to build a 1000 entry dictionary... - */ - for(i=0;i<1000;i++) { - MD5Init(&ctx1); - if(i & 1) - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - else - MD5Update(&ctx1,final,16); - - if(i % 3) - MD5Update(&ctx1,sp,sl); - - if(i % 7) - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - - if(i & 1) - MD5Update(&ctx1,final,16); - else - MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); - MD5Final(final,&ctx1); - } - - p = passwd + strlen(passwd); - - l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; to64(p,l,4); p += 4; - l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; to64(p,l,4); p += 4; - l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; to64(p,l,4); p += 4; - l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; to64(p,l,4); p += 4; - l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; to64(p,l,4); p += 4; - l = final[11] ; to64(p,l,2); p += 2; - *p = '\0'; - - /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof final); - - return passwd; -} - diff --git a/src/lib/libc/crypt/skipjack.c b/src/lib/libc/crypt/skipjack.c deleted file mode 100644 index 2212b984bb..0000000000 --- a/src/lib/libc/crypt/skipjack.c +++ /dev/null @@ -1,260 +0,0 @@ -/* $OpenBSD: skipjack.c,v 1.3 2004/10/01 04:08:45 jsg Exp $ */ - -/* - * Further optimized test implementation of SKIPJACK algorithm - * Mark Tillotson , 25 June 98 - * Optimizations suit RISC (lots of registers) machine best. - * - * based on unoptimized implementation of - * Panu Rissanen 960624 - * - * SKIPJACK and KEA Algorithm Specifications - * Version 2.0 - * 29 May 1998 -*/ - -#include -#include -#include - -static const u_int8_t ftable[0x100] = -{ - 0xa3, 0xd7, 0x09, 0x83, 0xf8, 0x48, 0xf6, 0xf4, - 0xb3, 0x21, 0x15, 0x78, 0x99, 0xb1, 0xaf, 0xf9, - 0xe7, 0x2d, 0x4d, 0x8a, 0xce, 0x4c, 0xca, 0x2e, - 0x52, 0x95, 0xd9, 0x1e, 0x4e, 0x38, 0x44, 0x28, - 0x0a, 0xdf, 0x02, 0xa0, 0x17, 0xf1, 0x60, 0x68, - 0x12, 0xb7, 0x7a, 0xc3, 0xe9, 0xfa, 0x3d, 0x53, - 0x96, 0x84, 0x6b, 0xba, 0xf2, 0x63, 0x9a, 0x19, - 0x7c, 0xae, 0xe5, 0xf5, 0xf7, 0x16, 0x6a, 0xa2, - 0x39, 0xb6, 0x7b, 0x0f, 0xc1, 0x93, 0x81, 0x1b, - 0xee, 0xb4, 0x1a, 0xea, 0xd0, 0x91, 0x2f, 0xb8, - 0x55, 0xb9, 0xda, 0x85, 0x3f, 0x41, 0xbf, 0xe0, - 0x5a, 0x58, 0x80, 0x5f, 0x66, 0x0b, 0xd8, 0x90, - 0x35, 0xd5, 0xc0, 0xa7, 0x33, 0x06, 0x65, 0x69, - 0x45, 0x00, 0x94, 0x56, 0x6d, 0x98, 0x9b, 0x76, - 0x97, 0xfc, 0xb2, 0xc2, 0xb0, 0xfe, 0xdb, 0x20, - 0xe1, 0xeb, 0xd6, 0xe4, 0xdd, 0x47, 0x4a, 0x1d, - 0x42, 0xed, 0x9e, 0x6e, 0x49, 0x3c, 0xcd, 0x43, - 0x27, 0xd2, 0x07, 0xd4, 0xde, 0xc7, 0x67, 0x18, - 0x89, 0xcb, 0x30, 0x1f, 0x8d, 0xc6, 0x8f, 0xaa, - 0xc8, 0x74, 0xdc, 0xc9, 0x5d, 0x5c, 0x31, 0xa4, - 0x70, 0x88, 0x61, 0x2c, 0x9f, 0x0d, 0x2b, 0x87, - 0x50, 0x82, 0x54, 0x64, 0x26, 0x7d, 0x03, 0x40, - 0x34, 0x4b, 0x1c, 0x73, 0xd1, 0xc4, 0xfd, 0x3b, - 0xcc, 0xfb, 0x7f, 0xab, 0xe6, 0x3e, 0x5b, 0xa5, - 0xad, 0x04, 0x23, 0x9c, 0x14, 0x51, 0x22, 0xf0, - 0x29, 0x79, 0x71, 0x7e, 0xff, 0x8c, 0x0e, 0xe2, - 0x0c, 0xef, 0xbc, 0x72, 0x75, 0x6f, 0x37, 0xa1, - 0xec, 0xd3, 0x8e, 0x62, 0x8b, 0x86, 0x10, 0xe8, - 0x08, 0x77, 0x11, 0xbe, 0x92, 0x4f, 0x24, 0xc5, - 0x32, 0x36, 0x9d, 0xcf, 0xf3, 0xa6, 0xbb, 0xac, - 0x5e, 0x6c, 0xa9, 0x13, 0x57, 0x25, 0xb5, 0xe3, - 0xbd, 0xa8, 0x3a, 0x01, 0x05, 0x59, 0x2a, 0x46 -}; - -/* - * For each key byte generate a table to represent the function - * ftable [in ^ keybyte] - * - * These tables used to save an XOR in each stage of the G-function - * the tables are hopefully pointed to by register allocated variables - * k0, k1..k9 - */ -void -subkey_table_gen (u_int8_t *key, u_int8_t **key_tables) -{ - int i, k; - - for (k = 0; k < 10; k++) { - u_int8_t key_byte = key[k]; - u_int8_t * table = (u_int8_t *) malloc(0x100); - /* XXX */ - - key_tables[k] = table; - for (i = 0; i < 0x100; i++) - table[i] = ftable[i ^ key_byte]; - } -} - - -#define g(k0, k1, k2, k3, ih, il, oh, ol) \ -{ \ - oh = k##k0 [il] ^ ih; \ - ol = k##k1 [oh] ^ il; \ - oh = k##k2 [ol] ^ oh; \ - ol = k##k3 [oh] ^ ol; \ -} - -#define g0(ih, il, oh, ol) g(0, 1, 2, 3, ih, il, oh, ol) -#define g4(ih, il, oh, ol) g(4, 5, 6, 7, ih, il, oh, ol) -#define g8(ih, il, oh, ol) g(8, 9, 0, 1, ih, il, oh, ol) -#define g2(ih, il, oh, ol) g(2, 3, 4, 5, ih, il, oh, ol) -#define g6(ih, il, oh, ol) g(6, 7, 8, 9, ih, il, oh, ol) - - -#define g_inv(k0, k1, k2, k3, ih, il, oh, ol) \ -{ \ - ol = k##k3 [ih] ^ il; \ - oh = k##k2 [ol] ^ ih; \ - ol = k##k1 [oh] ^ ol; \ - oh = k##k0 [ol] ^ oh; \ -} - - -#define g0_inv(ih, il, oh, ol) g_inv(0, 1, 2, 3, ih, il, oh, ol) -#define g4_inv(ih, il, oh, ol) g_inv(4, 5, 6, 7, ih, il, oh, ol) -#define g8_inv(ih, il, oh, ol) g_inv(8, 9, 0, 1, ih, il, oh, ol) -#define g2_inv(ih, il, oh, ol) g_inv(2, 3, 4, 5, ih, il, oh, ol) -#define g6_inv(ih, il, oh, ol) g_inv(6, 7, 8, 9, ih, il, oh, ol) - -/* optimized version of Skipjack algorithm - * - * the appropriate g-function is inlined for each round - * - * the data movement is minimized by rotating the names of the - * variables w1..w4, not their contents (saves 3 moves per round) - * - * the loops are completely unrolled (needed to staticize choice of g) - * - * compiles to about 470 instructions on a Sparc (gcc -O) - * which is about 58 instructions per byte, 14 per round. - * gcc seems to leave in some unnecessary and with 0xFF operations - * but only in the latter part of the functions. Perhaps it - * runs out of resources to properly optimize long inlined function? - * in theory should get about 11 instructions per round, not 14 - */ - -void -skipjack_forwards(u_int8_t *plain, u_int8_t *cipher, u_int8_t **key_tables) -{ - u_int8_t wh1 = plain[0]; u_int8_t wl1 = plain[1]; - u_int8_t wh2 = plain[2]; u_int8_t wl2 = plain[3]; - u_int8_t wh3 = plain[4]; u_int8_t wl3 = plain[5]; - u_int8_t wh4 = plain[6]; u_int8_t wl4 = plain[7]; - - u_int8_t * k0 = key_tables [0]; - u_int8_t * k1 = key_tables [1]; - u_int8_t * k2 = key_tables [2]; - u_int8_t * k3 = key_tables [3]; - u_int8_t * k4 = key_tables [4]; - u_int8_t * k5 = key_tables [5]; - u_int8_t * k6 = key_tables [6]; - u_int8_t * k7 = key_tables [7]; - u_int8_t * k8 = key_tables [8]; - u_int8_t * k9 = key_tables [9]; - - /* first 8 rounds */ - g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 1; wh4 ^= wh1; - g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 2; wh3 ^= wh4; - g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 3; wh2 ^= wh3; - g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 4; wh1 ^= wh2; - g6 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 5; wh4 ^= wh1; - g0 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 6; wh3 ^= wh4; - g4 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 7; wh2 ^= wh3; - g8 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 8; wh1 ^= wh2; - - /* second 8 rounds */ - wh2 ^= wh1; wl2 ^= wl1 ^ 9 ; g2 (wh1,wl1, wh1,wl1); - wh1 ^= wh4; wl1 ^= wl4 ^ 10; g6 (wh4,wl4, wh4,wl4); - wh4 ^= wh3; wl4 ^= wl3 ^ 11; g0 (wh3,wl3, wh3,wl3); - wh3 ^= wh2; wl3 ^= wl2 ^ 12; g4 (wh2,wl2, wh2,wl2); - wh2 ^= wh1; wl2 ^= wl1 ^ 13; g8 (wh1,wl1, wh1,wl1); - wh1 ^= wh4; wl1 ^= wl4 ^ 14; g2 (wh4,wl4, wh4,wl4); - wh4 ^= wh3; wl4 ^= wl3 ^ 15; g6 (wh3,wl3, wh3,wl3); - wh3 ^= wh2; wl3 ^= wl2 ^ 16; g0 (wh2,wl2, wh2,wl2); - - /* third 8 rounds */ - g4 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 17; wh4 ^= wh1; - g8 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 18; wh3 ^= wh4; - g2 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 19; wh2 ^= wh3; - g6 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 20; wh1 ^= wh2; - g0 (wh1,wl1, wh1,wl1); wl4 ^= wl1 ^ 21; wh4 ^= wh1; - g4 (wh4,wl4, wh4,wl4); wl3 ^= wl4 ^ 22; wh3 ^= wh4; - g8 (wh3,wl3, wh3,wl3); wl2 ^= wl3 ^ 23; wh2 ^= wh3; - g2 (wh2,wl2, wh2,wl2); wl1 ^= wl2 ^ 24; wh1 ^= wh2; - - /* last 8 rounds */ - wh2 ^= wh1; wl2 ^= wl1 ^ 25; g6 (wh1,wl1, wh1,wl1); - wh1 ^= wh4; wl1 ^= wl4 ^ 26; g0 (wh4,wl4, wh4,wl4); - wh4 ^= wh3; wl4 ^= wl3 ^ 27; g4 (wh3,wl3, wh3,wl3); - wh3 ^= wh2; wl3 ^= wl2 ^ 28; g8 (wh2,wl2, wh2,wl2); - wh2 ^= wh1; wl2 ^= wl1 ^ 29; g2 (wh1,wl1, wh1,wl1); - wh1 ^= wh4; wl1 ^= wl4 ^ 30; g6 (wh4,wl4, wh4,wl4); - wh4 ^= wh3; wl4 ^= wl3 ^ 31; g0 (wh3,wl3, wh3,wl3); - wh3 ^= wh2; wl3 ^= wl2 ^ 32; g4 (wh2,wl2, wh2,wl2); - - /* pack into byte vector */ - cipher [0] = wh1; cipher [1] = wl1; - cipher [2] = wh2; cipher [3] = wl2; - cipher [4] = wh3; cipher [5] = wl3; - cipher [6] = wh4; cipher [7] = wl4; -} - - -void -skipjack_backwards (u_int8_t *cipher, u_int8_t *plain, u_int8_t **key_tables) -{ - /* setup 4 16-bit portions */ - u_int8_t wh1 = cipher[0]; u_int8_t wl1 = cipher[1]; - u_int8_t wh2 = cipher[2]; u_int8_t wl2 = cipher[3]; - u_int8_t wh3 = cipher[4]; u_int8_t wl3 = cipher[5]; - u_int8_t wh4 = cipher[6]; u_int8_t wl4 = cipher[7]; - - u_int8_t * k0 = key_tables [0]; - u_int8_t * k1 = key_tables [1]; - u_int8_t * k2 = key_tables [2]; - u_int8_t * k3 = key_tables [3]; - u_int8_t * k4 = key_tables [4]; - u_int8_t * k5 = key_tables [5]; - u_int8_t * k6 = key_tables [6]; - u_int8_t * k7 = key_tables [7]; - u_int8_t * k8 = key_tables [8]; - u_int8_t * k9 = key_tables [9]; - - /* first 8 rounds */ - g4_inv (wh2,wl2, wh2,wl2); wl3 ^= wl2 ^ 32; wh3 ^= wh2; - g0_inv (wh3,wl3, wh3,wl3); wl4 ^= wl3 ^ 31; wh4 ^= wh3; - g6_inv (wh4,wl4, wh4,wl4); wl1 ^= wl4 ^ 30; wh1 ^= wh4; - g2_inv (wh1,wl1, wh1,wl1); wl2 ^= wl1 ^ 29; wh2 ^= wh1; - g8_inv (wh2,wl2, wh2,wl2); wl3 ^= wl2 ^ 28; wh3 ^= wh2; - g4_inv (wh3,wl3, wh3,wl3); wl4 ^= wl3 ^ 27; wh4 ^= wh3; - g0_inv (wh4,wl4, wh4,wl4); wl1 ^= wl4 ^ 26; wh1 ^= wh4; - g6_inv (wh1,wl1, wh1,wl1); wl2 ^= wl1 ^ 25; wh2 ^= wh1; - - /* second 8 rounds */ - wh1 ^= wh2; wl1 ^= wl2 ^ 24; g2_inv (wh2,wl2, wh2,wl2); - wh2 ^= wh3; wl2 ^= wl3 ^ 23; g8_inv (wh3,wl3, wh3,wl3); - wh3 ^= wh4; wl3 ^= wl4 ^ 22; g4_inv (wh4,wl4, wh4,wl4); - wh4 ^= wh1; wl4 ^= wl1 ^ 21; g0_inv (wh1,wl1, wh1,wl1); - wh1 ^= wh2; wl1 ^= wl2 ^ 20; g6_inv (wh2,wl2, wh2,wl2); - wh2 ^= wh3; wl2 ^= wl3 ^ 19; g2_inv (wh3,wl3, wh3,wl3); - wh3 ^= wh4; wl3 ^= wl4 ^ 18; g8_inv (wh4,wl4, wh4,wl4); - wh4 ^= wh1; wl4 ^= wl1 ^ 17; g4_inv (wh1,wl1, wh1,wl1); - - /* third 8 rounds */ - g0_inv (wh2,wl2, wh2,wl2); wl3 ^= wl2 ^ 16; wh3 ^= wh2; - g6_inv (wh3,wl3, wh3,wl3); wl4 ^= wl3 ^ 15; wh4 ^= wh3; - g2_inv (wh4,wl4, wh4,wl4); wl1 ^= wl4 ^ 14; wh1 ^= wh4; - g8_inv (wh1,wl1, wh1,wl1); wl2 ^= wl1 ^ 13; wh2 ^= wh1; - g4_inv (wh2,wl2, wh2,wl2); wl3 ^= wl2 ^ 12; wh3 ^= wh2; - g0_inv (wh3,wl3, wh3,wl3); wl4 ^= wl3 ^ 11; wh4 ^= wh3; - g6_inv (wh4,wl4, wh4,wl4); wl1 ^= wl4 ^ 10; wh1 ^= wh4; - g2_inv (wh1,wl1, wh1,wl1); wl2 ^= wl1 ^ 9; wh2 ^= wh1; - - /* last 8 rounds */ - wh1 ^= wh2; wl1 ^= wl2 ^ 8; g8_inv (wh2,wl2, wh2,wl2); - wh2 ^= wh3; wl2 ^= wl3 ^ 7; g4_inv (wh3,wl3, wh3,wl3); - wh3 ^= wh4; wl3 ^= wl4 ^ 6; g0_inv (wh4,wl4, wh4,wl4); - wh4 ^= wh1; wl4 ^= wl1 ^ 5; g6_inv (wh1,wl1, wh1,wl1); - wh1 ^= wh2; wl1 ^= wl2 ^ 4; g2_inv (wh2,wl2, wh2,wl2); - wh2 ^= wh3; wl2 ^= wl3 ^ 3; g8_inv (wh3,wl3, wh3,wl3); - wh3 ^= wh4; wl3 ^= wl4 ^ 2; g4_inv (wh4,wl4, wh4,wl4); - wh4 ^= wh1; wl4 ^= wl1 ^ 1; g0_inv (wh1,wl1, wh1,wl1); - - /* pack into byte vector */ - plain [0] = wh1; plain [1] = wl1; - plain [2] = wh2; plain [3] = wl2; - plain [4] = wh3; plain [5] = wl3; - plain [6] = wh4; plain [7] = wl4; -} diff --git a/src/lib/libc/include/ctype_private.h b/src/lib/libc/include/ctype_private.h deleted file mode 100644 index 39cc792ea4..0000000000 --- a/src/lib/libc/include/ctype_private.h +++ /dev/null @@ -1,7 +0,0 @@ -/* $OpenBSD: ctype_private.h,v 1.1 2005/08/08 05:53:00 espie Exp $ */ -/* Written by Marc Espie, public domain */ -#define CTYPE_NUM_CHARS 256 -extern const char _C_ctype_[]; -extern const short _C_toupper_[]; -extern const short _C_tolower_[]; - diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h deleted file mode 100644 index 4a51f15ddf..0000000000 --- a/src/lib/libc/include/namespace.h +++ /dev/null @@ -1,18 +0,0 @@ -/* $OpenBSD: namespace.h,v 1.2 1996/08/19 08:28:08 tholo Exp $ */ - -#define catclose _catclose -#define catgets _catgets -#define catopen _catopen -#define err _err -#define errx _errx -#define strtoq _strtoq -#define strtouq _strtouq -#define sys_errlist _sys_errlist -#define sys_nerr _sys_nerr -#define sys_siglist _sys_siglist -#define verr _verr -#define verrx _verrx -#define vwarn _vwarn -#define vwarnx _vwarnx -#define warn _warn -#define warnx _warnx diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h deleted file mode 100644 index 2d8913e482..0000000000 --- a/src/lib/libc/include/thread_private.h +++ /dev/null @@ -1,160 +0,0 @@ -/* $OpenBSD: thread_private.h,v 1.24 2008/06/14 15:43:43 otto Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ - -#ifndef _THREAD_PRIVATE_H_ -#define _THREAD_PRIVATE_H_ - -/* - * This file defines the thread library interface to libc. Thread - * libraries must implement the functions described here for proper - * inter-operation with libc. libc contains weak versions of the - * described functions for operation in a non-threaded environment. - */ - -/* - * This variable is 0 until a second thread is created. - */ -extern int __isthreaded; - -/* - * Weak symbols are used in libc so that the thread library can - * efficiently wrap libc functions. - * - * Use WEAK_NAME(n) to get a libc-private name for n (_weak_n), - * WEAK_ALIAS(n) to generate the weak symbol n pointing to _weak_n, - * WEAK_PROTOTYPE(n) to generate a prototype for _weak_n (based on n). - */ -#define WEAK_NAME(name) __CONCAT(_weak_,name) -#define WEAK_ALIAS(name) __weak_alias(name, WEAK_NAME(name)) -#ifdef __GNUC__ -#define WEAK_PROTOTYPE(name) __typeof__(name) WEAK_NAME(name) -#else -#define WEAK_PROTOTYPE(name) /* typeof() only in gcc */ -#endif - -/* - * helper macro to make unique names in the thread namespace - */ -#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) - -/* - * helper functions that exist as (weak) null functions in libc and - * (strong) functions in the thread library. These functions: - * - * _thread_tag_lock: - * lock the mutex associated with the given tag. If the given - * tag is NULL a tag is first allocated. - * - * _thread_tag_unlock: - * unlock the mutex associated with the given tag. If the given - * tag is NULL a tag is first allocated. - * - * _thread_tag_storage: - * return a pointer to per thread instance of data associated - * with the given tag. If the given tag is NULL a tag is first - * allocated. - * - * _thread_mutex_lock: - * lock the given mutex. If the given mutex is NULL, - * rely on rthreads/pthreads implementation to initialize - * the mutex before locking. - * - * _thread_mutex_unlock: - * unlock the given mutex. - * - * _thread_mutex_destroy: - * destroy the given mutex. - */ -void _thread_tag_lock(void **); -void _thread_tag_unlock(void **); -void *_thread_tag_storage(void **, void *, size_t, void *); -void _thread_mutex_lock(void **); -void _thread_mutex_unlock(void **); -void _thread_mutex_destroy(void **); - -/* - * Macros used in libc to access thread mutex, keys, and per thread storage. - * _THREAD_PRIVATE_KEY and _THREAD_PRIVATE_MUTEX are different macros for - * historical reasons. They do the same thing, define a static variable - * keyed by 'name' that identifies a mutex and a key to identify per thread - * data. - */ -#define _THREAD_PRIVATE_KEY(name) \ - static void *__THREAD_NAME(name) -#define _THREAD_PRIVATE_MUTEX(name) \ - static void *__THREAD_NAME(name) -#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ - _thread_tag_lock(&(__THREAD_NAME(name))) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ - _thread_tag_unlock(&(__THREAD_NAME(name))) -#define _THREAD_PRIVATE(keyname, storage, error) \ - _thread_tag_storage(&(__THREAD_NAME(keyname)), &(storage), \ - sizeof (storage), error) - -/* - * Macros used in libc to access mutexes. - */ -#define _MUTEX_LOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_lock(mutex); \ - } while (0) -#define _MUTEX_UNLOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_unlock(mutex); \ - } while (0) -#define _MUTEX_DESTROY(mutex) \ - do { \ - if (__isthreaded) \ - _thread_mutex_destroy(mutex); \ - } while (0) - -/* - * Resolver code is special cased in that it uses global keys. - */ -extern void *__THREAD_NAME(_res); -extern void *__THREAD_NAME(_res_ext); -extern void *__THREAD_NAME(serv_mutex); - -/* - * malloc lock/unlock prototypes and definitions - */ -void _thread_malloc_lock(void); -void _thread_malloc_unlock(void); - -#define _MALLOC_LOCK() do { \ - if (__isthreaded) \ - _thread_malloc_lock(); \ - } while (0) -#define _MALLOC_UNLOCK() do { \ - if (__isthreaded) \ - _thread_malloc_unlock();\ - } while (0) - -void _thread_atexit_lock(void); -void _thread_atexit_unlock(void); - -#define _ATEXIT_LOCK() do { \ - if (__isthreaded) \ - _thread_atexit_lock(); \ - } while (0) -#define _ATEXIT_UNLOCK() do { \ - if (__isthreaded) \ - _thread_atexit_unlock();\ - } while (0) - -void _thread_arc4_lock(void); -void _thread_arc4_unlock(void); - -#define _ARC4_LOCK() do { \ - if (__isthreaded) \ - _thread_arc4_lock(); \ - } while (0) -#define _ARC4_UNLOCK() do { \ - if (__isthreaded) \ - _thread_arc4_unlock();\ - } while (0) - -#endif /* _THREAD_PRIVATE_H_ */ diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc deleted file mode 100644 index 7599f02832..0000000000 --- a/src/lib/libc/net/Makefile.inc +++ /dev/null @@ -1,101 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.44 2007/06/05 18:04:46 henning Exp $ - -# net sources -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net ${LIBCSRCDIR}/net - -CFLAGS+=-DRESOLVSORT - -SRCS+= base64.c freeaddrinfo.c gai_strerror.c getaddrinfo.c gethostnamadr.c \ - getifaddrs.c getnameinfo.c getnetbyaddr.c getnetbyname.c getnetent.c \ - getnetnamadr.c getproto.c getprotoent.c getprotoname.c \ - getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ - herror.c if_indextoname.c if_nameindex.c if_nametoindex.c inet_addr.c \ - inet_lnaof.c inet_makeaddr.c inet_neta.c inet_netof.c inet_network.c \ - inet_net_ntop.c inet_net_pton.c inet_ntoa.c inet_ntop.c inet_pton.c \ - linkaddr.c net_addrcmp.c nsap_addr.c \ - rcmd.c rresvport.c recv.c res_comp.c res_data.c res_debug.c \ - res_debug_syms.c \ - res_init.c res_mkquery.c res_query.c res_random.c res_send.c send.c \ - sethostent.c ethers.c rcmdsh.c - -# IPv6 -SRCS+= ip6opt.c rthdr.c vars6.c - -# machine-dependent net sources -# m-d Makefile.inc must include sources for: -# htonl() htons() ntohl() ntohs() - -.include "${LIBCSRCDIR}/arch/${MACHINE_ARCH}/net/Makefile.inc" - -MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ - getifaddrs.3 getnameinfo.3 getnetent.3 getprotoent.3 \ - getrrsetbyname.3 getservent.3 if_indextoname.3 inet.3 \ - inet_net.3 inet6_option_space.3 inet6_rthdr_space.3 \ - inet6_opt_init.3 inet6_rth_space.3 \ - link_addr.3 net_addrcmp.3 \ - rcmd.3 rcmdsh.3 resolver.3 - -MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ - byteorder.3 ntohs.3 byteorder.3 htobe16.3 byteorder.3 htobe32.3 \ - byteorder.3 htobe64.3 byteorder.3 betoh16.3 byteorder.3 betoh32.3 \ - byteorder.3 betoh64.3 byteorder.3 htole16.3 byteorder.3 htole32.3 \ - byteorder.3 htole64.3 byteorder.3 letoh16.3 byteorder.3 letoh32.3 \ - byteorder.3 letoh64.3 byteorder.3 swap16.3 byteorder.3 swap32.3 \ - byteorder.3 swap64.3 -MLINKS+=ethers.3 ether_aton.3 ethers.3 ether_hostton.3 ethers.3 ether_line.3 \ - ethers.3 ether_ntoa.3 ethers.3 ether_ntohost.3 -MLINKS+=getaddrinfo.3 freeaddrinfo.3 -MLINKS+=gethostbyname.3 endhostent.3 gethostbyname.3 gethostbyaddr.3 \ - gethostbyname.3 sethostent.3 gethostbyname.3 gethostent.3 \ - gethostbyname.3 herror.3 gethostbyname.3 gethostbyname2.3 \ - gethostbyname.3 hstrerror.3 -MLINKS+=getifaddrs.3 freeifaddrs.3 -MLINKS+=getnetent.3 endnetent.3 getnetent.3 getnetbyaddr.3 \ - getnetent.3 getnetbyname.3 getnetent.3 setnetent.3 -MLINKS+=getprotoent.3 endprotoent.3 getprotoent.3 getprotobyname.3 \ - getprotoent.3 getprotobynumber.3 getprotoent.3 setprotoent.3 \ - getprotoent.3 getprotoent_r.3 getprotoent.3 getprotobyname_r.3 \ - getprotoent.3 getprotobynumber_r.3 getprotoent.3 setprotoent_r.3 \ - getprotoent.3 endprotoent_r.3 -MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ - getservent.3 getservbyport.3 getservent.3 setservent.3 \ - getservent.3 getservent_r.3 getservent.3 getservbyname_r.3 \ - getservent.3 getservbyport_r.3 setservent.3 setservent_r.3 \ - setservent.3 endservent_r.3 -MLINKS+= if_indextoname.3 if_nametoindex.3 if_indextoname.3 if_nameindex.3 \ - if_indextoname.3 if_freenameindex.3 -MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_aton.3 \ - inet.3 inet_lnaof.3 inet.3 inet_makeaddr.3 inet.3 inet_netof.3 \ - inet.3 inet_network.3 inet.3 inet_ntoa.3 inet.3 network.3 \ - inet.3 ntoa.3 inet.3 inet_ntop.3 inet.3 inet_pton.3 -MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 -MLINKS+=link_addr.3 link_ntoa.3 -MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ - rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 -MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ - resolver.3 res_mkquery.3 resolver.3 res_send.3 resolver.3 res_query.3 \ - resolver.3 res_search.3 -MLINKS+=getrrsetbyname.3 freerrset.3 -MLINKS+=inet6_option_space.3 inet6_option_init.3 \ - inet6_option_space.3 inet6_option_append.3 \ - inet6_option_space.3 inet6_option_alloc.3 \ - inet6_option_space.3 inet6_option_next.3 \ - inet6_option_space.3 inet6_option_find.3 -MLINKS+=inet6_rthdr_space.3 inet6_rthdr_init.3 \ - inet6_rthdr_space.3 inet6_rthdr_add.3 \ - inet6_rthdr_space.3 inet6_rthdr_lasthop.3 \ - inet6_rthdr_space.3 inet6_rthdr_reverse.3 \ - inet6_rthdr_space.3 inet6_rthdr_segments.3 \ - inet6_rthdr_space.3 inet6_rthdr_getaddr.3 \ - inet6_rthdr_space.3 inet6_rthdr_getflags.3 -MLINKS+=inet6_opt_init.3 inet6_opt_append.3 \ - inet6_opt_init.3 inet6_opt_finish.3 \ - inet6_opt_init.3 inet6_opt_set_val.3 \ - inet6_opt_init.3 inet6_opt_next.3 \ - inet6_opt_init.3 inet6_opt_find.3 \ - inet6_opt_init.3 inet6_opt_get_val.3 -MLINKS+=inet6_rth_space.3 inet6_rth_init.3 \ - inet6_rth_space.3 inet6_rth_add.3 \ - inet6_rth_space.3 inet6_rth_reverse.3 \ - inet6_rth_space.3 inet6_rth_segments.3 \ - inet6_rth_space.3 inet6_rth_getaddr.3 \ diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c deleted file mode 100644 index d432c48d5c..0000000000 --- a/src/lib/libc/net/base64.c +++ /dev/null @@ -1,308 +0,0 @@ -/* $OpenBSD: base64.c,v 1.5 2006/10/21 09:55:03 otto Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -/* - * Portions Copyright (c) 1995 by International Business Machines, Inc. - * - * International Business Machines, Inc. (hereinafter called IBM) grants - * permission under its copyrights to use, copy, modify, and distribute this - * Software with or without fee, provided that the above copyright notice and - * all paragraphs of this notice appear in all copies, and that the name of IBM - * not be used in connection with the marketing of any product incorporating - * the Software or modifications thereof, without specific, written prior - * permission. - * - * To the extent it has a right to do so, IBM grants an immunity from suit - * under its patents, if any, for the use, sale or manufacture of products to - * the extent that such products are used for performing Domain Name System - * dynamic updates in TCP/IP networks by means of the Software. No immunity is - * granted for any product per se or for any other function of any product. - * - * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, - * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN - * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static const char Pad64 = '='; - -/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) - The following encoding technique is taken from RFC 1521 by Borenstein - and Freed. It is reproduced here in a slightly edited form for - convenience. - - A 65-character subset of US-ASCII is used, enabling 6 bits to be - represented per printable character. (The extra 65th character, "=", - is used to signify a special processing function.) - - The encoding process represents 24-bit groups of input bits as output - strings of 4 encoded characters. Proceeding from left to right, a - 24-bit input group is formed by concatenating 3 8-bit input groups. - These 24 bits are then treated as 4 concatenated 6-bit groups, each - of which is translated into a single digit in the base64 alphabet. - - Each 6-bit group is used as an index into an array of 64 printable - characters. The character referenced by the index is placed in the - output string. - - Table 1: The Base64 Alphabet - - Value Encoding Value Encoding Value Encoding Value Encoding - 0 A 17 R 34 i 51 z - 1 B 18 S 35 j 52 0 - 2 C 19 T 36 k 53 1 - 3 D 20 U 37 l 54 2 - 4 E 21 V 38 m 55 3 - 5 F 22 W 39 n 56 4 - 6 G 23 X 40 o 57 5 - 7 H 24 Y 41 p 58 6 - 8 I 25 Z 42 q 59 7 - 9 J 26 a 43 r 60 8 - 10 K 27 b 44 s 61 9 - 11 L 28 c 45 t 62 + - 12 M 29 d 46 u 63 / - 13 N 30 e 47 v - 14 O 31 f 48 w (pad) = - 15 P 32 g 49 x - 16 Q 33 h 50 y - - Special processing is performed if fewer than 24 bits are available - at the end of the data being encoded. A full encoding quantum is - always completed at the end of a quantity. When fewer than 24 input - bits are available in an input group, zero bits are added (on the - right) to form an integral number of 6-bit groups. Padding at the - end of the data is performed using the '=' character. - - Since all base64 input is an integral number of octets, only the - ------------------------------------------------- - following cases can arise: - - (1) the final quantum of encoding input is an integral - multiple of 24 bits; here, the final unit of encoded - output will be an integral multiple of 4 characters - with no "=" padding, - (2) the final quantum of encoding input is exactly 8 bits; - here, the final unit of encoded output will be two - characters followed by two "=" padding characters, or - (3) the final quantum of encoding input is exactly 16 bits; - here, the final unit of encoded output will be three - characters followed by one "=" padding character. - */ - -int -b64_ntop(src, srclength, target, targsize) - u_char const *src; - size_t srclength; - char *target; - size_t targsize; -{ - size_t datalength = 0; - u_char input[3]; - u_char output[4]; - int i; - - while (2 < srclength) { - input[0] = *src++; - input[1] = *src++; - input[2] = *src++; - srclength -= 3; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - output[3] = input[2] & 0x3f; - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - target[datalength++] = Base64[output[2]]; - target[datalength++] = Base64[output[3]]; - } - - /* Now we worry about padding. */ - if (0 != srclength) { - /* Get what's left. */ - input[0] = input[1] = input[2] = '\0'; - for (i = 0; i < srclength; i++) - input[i] = *src++; - - output[0] = input[0] >> 2; - output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); - output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); - - if (datalength + 4 > targsize) - return (-1); - target[datalength++] = Base64[output[0]]; - target[datalength++] = Base64[output[1]]; - if (srclength == 1) - target[datalength++] = Pad64; - else - target[datalength++] = Base64[output[2]]; - target[datalength++] = Pad64; - } - if (datalength >= targsize) - return (-1); - target[datalength] = '\0'; /* Returned value doesn't count \0. */ - return (datalength); -} - -/* skips all whitespace anywhere. - converts characters, four at a time, starting at (or after) - src from base - 64 numbers into three 8 bit bytes in the target area. - it returns the number of data bytes stored at the target, or -1 on error. - */ - -int -b64_pton(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; -{ - int tarindex, state, ch; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ - continue; - - if (ch == Pad64) - break; - - pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ - return (-1); - - switch (state) { - case 0: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] = (pos - Base64) << 2; - } - state = 1; - break; - case 1: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - target[tarindex+1] = ((pos - Base64) & 0x0f) - << 4 ; - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex + 1 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - target[tarindex+1] = ((pos - Base64) & 0x03) - << 6; - } - tarindex++; - state = 3; - break; - case 3: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64); - } - tarindex++; - state = 0; - break; - } - } - - /* - * We are done decoding Base-64 chars. Let's see if we ended - * on a byte boundary, and/or with erroneous trailing characters. - */ - - if (ch == Pad64) { /* We got a pad char. */ - ch = *src++; /* Skip it, get next. */ - switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ - return (-1); - - case 2: /* Valid, means one byte of info */ - /* Skip any number of spaces. */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = *src++; /* Skip the = */ - /* Fall through to "single trailing =" case. */ - /* FALLTHROUGH */ - - case 3: /* Valid, means two bytes of info */ - /* - * We know this char is an =. Is there anything but - * whitespace after it? - */ - for (; ch != '\0'; ch = *src++) - if (!isspace(ch)) - return (-1); - - /* - * Now make sure for cases 2 and 3 that the "extra" - * bits that slopped past the last full byte were - * zeros. If we don't check them, they become a - * subliminal channel. - */ - if (target && target[tarindex] != 0) - return (-1); - } - } else { - /* - * We ended by seeing the end of the string. Make sure we - * have no partial bytes lying around. - */ - if (state != 0) - return (-1); - } - - return (tarindex); -} diff --git a/src/lib/libc/net/byteorder.3 b/src/lib/libc/net/byteorder.3 deleted file mode 100644 index 7f22794caa..0000000000 --- a/src/lib/libc/net/byteorder.3 +++ /dev/null @@ -1,206 +0,0 @@ -.\" $OpenBSD: byteorder.3,v 1.15 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt BYTEORDER 3 -.Os -.Sh NAME -.Nm htonl , -.Nm htons , -.Nm ntohl , -.Nm ntohs , -.Nm htobe64 , -.Nm htobe32 , -.Nm htobe16 , -.Nm betoh64 , -.Nm betoh32 , -.Nm betoh16 , -.Nm htole64 , -.Nm htole32 , -.Nm htole16 , -.Nm letoh64 , -.Nm letoh32 , -.Nm letoh16 , -.Nm swap64 , -.Nm swap32 , -.Nm swap16 -.Nd convert values between different byte orderings -.Sh SYNOPSIS -.Fd #include -.Ft u_int32_t -.Fn htonl "u_int32_t host32" -.Ft u_int16_t -.Fn htons "u_int16_t host16" -.Ft u_int32_t -.Fn ntohl "u_int32_t net32" -.Ft u_int16_t -.Fn ntohs "u_int16_t net16" -.Ft u_int64_t -.Fn htobe64 "u_int64_t host64" -.Ft u_int32_t -.Fn htobe32 "u_int32_t host32" -.Ft u_int16_t -.Fn htobe16 "u_int16_t host16" -.Ft u_int64_t -.Fn betoh64 "u_int64_t big64" -.Ft u_int32_t -.Fn betoh32 "u_int32_t big32" -.Ft u_int16_t -.Fn betoh16 "u_int16_t big16" -.Ft u_int64_t -.Fn htole64 "u_int64_t host64" -.Ft u_int32_t -.Fn htole32 "u_int32_t host32" -.Ft u_int16_t -.Fn htole16 "u_int16_t host16" -.Ft u_int64_t -.Fn letoh64 "u_int64_t little64" -.Ft u_int32_t -.Fn letoh32 "u_int32_t little32" -.Ft u_int16_t -.Fn letoh16 "u_int16_t little16" -.Ft u_int64_t -.Fn swap64 "u_int32_t val64" -.Ft u_int32_t -.Fn swap32 "u_int32_t val32" -.Ft u_int16_t -.Fn swap16 "u_int16_t val16" -.Sh DESCRIPTION -These routines convert 16, 32 and 64-bit quantities between different -byte orderings. -The -.Dq swap -functions reverse the byte ordering of -the given quantity; the others convert either from/to the native -byte order used by the host to/from either little- or big-endian (a.k.a -network) order. -.Pp -Apart from the swap functions, the names can be described by this form: -{src-order}to{dst-order}{size}. -Both {src-order} and {dst-order} can take the following forms: -.Pp -.Bl -tag -width "be " -offset indent -compact -.It h -Host order. -.It n -Network order (big-endian). -.It be -Big-endian (most significant byte first). -.It le -Little-endian (least significant byte first). -.El -.Pp -One of the specified orderings must be -.Sq h . -{size} will take these forms: -.Pp -.Bl -tag -width "32 " -offset indent -compact -.It l -Long (32-bit, used in conjunction with forms involving -.Sq n ) . -.It s -Short (16-bit, used in conjunction with forms involving -.Sq n ) . -.It 16 -16-bit. -.It 32 -32-bit. -.It 64 -64-bit. -.El -.Pp -The swap functions are of the form: swap{size}. -.Pp -Names involving -.Sq n -convert quantities between network -byte order and host byte order. -The last letter -.Pf ( Sq s -or -.Sq l ) -is a mnemonic -for the traditional names for such quantities, -.Li short -and -.Li long , -respectively. -Today, the C concept of -.Li short -and -.Li long -integers need not coincide with this traditional misunderstanding. -On machines which have a byte order which is the same as the network -order, routines are defined as null macros. -.Pp -The functions involving either -.Dq be , -.Dq le , -or -.Dq swap -use the numbers -16, 32, or 64 for specifying the bitwidth of the quantities they operate on. -Currently all supported architectures are either big- or little-endian -so either the -.Dq be -or -.Dq le -variants are implemented as null macros. -.Pp -The routines mentioned above which have either {src-order} or {dst-order} -set to -.Sq n -are most often used in -conjunction with Internet addresses and ports as returned by -.Xr gethostbyname 3 -and -.Xr getservent 3 . -.Sh SEE ALSO -.Xr gethostbyname 3 , -.Xr getservent 3 -.Sh STANDARDS -The -.Fn htonl , -.Fn htons , -.Fn ntohl , -and -.Fn ntohs -functions conform to -.St -p1003.1 . -The other functions are extensions that should not be used when portability -is required. -.Sh HISTORY -The -.Nm byteorder -functions appeared in -.Bx 4.2 . -.Sh BUGS -On the vax, alpha, i386, and some mips architectures, -bytes are handled backwards from most everyone else in the world. -This is not expected to be fixed in the near future. diff --git a/src/lib/libc/net/ethers.3 b/src/lib/libc/net/ethers.3 deleted file mode 100644 index 435a52696a..0000000000 --- a/src/lib/libc/net/ethers.3 +++ /dev/null @@ -1,122 +0,0 @@ -.\" $OpenBSD: ethers.3,v 1.19 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Written by roland@frob.com. Public domain. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt ETHERS 3 -.Os -.Sh NAME -.Nm ether_aton , -.Nm ether_ntoa , -.Nm ether_ntohost , -.Nm ether_hostton , -.Nm ether_line -.Nd get ethers entry -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft char * -.Fn ether_ntoa "struct ether_addr *e" -.Ft struct ether_addr * -.Fn ether_aton "const char *s" -.Ft int -.Fn ether_ntohost "char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_hostton "const char *hostname" "struct ether_addr *e" -.Ft int -.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" -.Sh DESCRIPTION -Ethernet addresses are represented by the -following structure: -.Bd -literal -offset indent -struct ether_addr { - u_int8_t ether_addr_octet[6]; -}; -.Ed -.Pp -The -.Fn ether_ntoa -function converts this structure into an -.Tn ASCII -string of the form -.Dq xx:xx:xx:xx:xx:xx , -consisting of 6 hexadecimal numbers separated -by colons. -It returns a pointer to a static buffer that is reused for each call. -The -.Fn ether_aton -converts an -.Tn ASCII -string of the same form and to a structure -containing the 6 octets of the address. -It returns a pointer to a static structure that is reused for each call. -.Pp -The -.Fn ether_ntohost -and -.Fn ether_hostton -functions interrogate the database mapping host names to Ethernet -addresses, -.Pa /etc/ethers . -The -.Fn ether_ntohost -function looks up the given Ethernet address and writes the associated -host name into the character buffer passed. -This buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -The -.Fn ether_hostton -function looks up the given host name and writes the associated -Ethernet address into the structure passed. -Both functions return -zero if they find the requested host name or address, and \-1 if not. -.Pp -Each call reads -.Pa /etc/ethers -from the beginning; if a -.Ql + -appears alone on a line in the file, then -.Fn ether_hostton -will consult the -.Pa ethers.byname -YP map, and -.Fn ether_ntohost -will consult the -.Pa ethers.byaddr -YP map. -.Pp -The -.Fn ether_line -function parses a line from the -.Pa /etc/ethers -file and fills in the passed -.Li struct ether_addr -and character buffer with the Ethernet address and host name on the line. -It returns zero if the line was successfully parsed and \-1 if not. -The character buffer should be -.Dv MAXHOSTNAMELEN -characters in size. -.Sh FILES -.Bl -tag -width /etc/ethers -compact -.It Pa /etc/ethers -.El -.Sh SEE ALSO -.Xr ethers 5 -.Sh HISTORY -The -.Fn ether_ntoa , -.Fn ether_aton , -.Fn ether_ntohost , -.Fn ether_hostton , -and -.Fn ether_line -functions were adopted from SunOS and appeared in -.Nx 0.9 b. -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls to -these functions overwrite it. diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c deleted file mode 100644 index d4243ff1da..0000000000 --- a/src/lib/libc/net/ethers.c +++ /dev/null @@ -1,232 +0,0 @@ -/* $OpenBSD: ethers.c,v 1.20 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * ethers(3) a la Sun. - * Originally Written by Roland McGrath 10/14/93. - * Substantially modified by Todd C. Miller - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef YP -#include -#endif - -#ifndef _PATH_ETHERS -#define _PATH_ETHERS "/etc/ethers" -#endif - -static char * _ether_aton(const char *, struct ether_addr *); - -char * -ether_ntoa(struct ether_addr *e) -{ - static char a[] = "xx:xx:xx:xx:xx:xx"; - - (void)snprintf(a, sizeof a, "%02x:%02x:%02x:%02x:%02x:%02x", - e->ether_addr_octet[0], e->ether_addr_octet[1], - e->ether_addr_octet[2], e->ether_addr_octet[3], - e->ether_addr_octet[4], e->ether_addr_octet[5]); - - return (a); -} - -static char * -_ether_aton(const char *s, struct ether_addr *e) -{ - int i; - long l; - char *pp; - - while (isspace(*s)) - s++; - - /* expect 6 hex octets separated by ':' or space/NUL if last octet */ - for (i = 0; i < 6; i++) { - l = strtol(s, &pp, 16); - if (pp == s || l > 0xFF || l < 0) - return (NULL); - if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0')))) - return (NULL); - e->ether_addr_octet[i] = (u_char)l; - s = pp + 1; - } - - /* return character after the octets ala strtol(3) */ - return (pp); -} - -struct ether_addr * -ether_aton(const char *s) -{ - static struct ether_addr n; - - return (_ether_aton(s, &n) ? &n : NULL); -} - -int -ether_ntohost(char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - size_t len; - struct ether_addr try; -#ifdef YP - char trybuf[sizeof("xx:xx:xx:xx:xx:xx")]; - int trylen; -#endif - -#ifdef YP - snprintf(trybuf, sizeof trybuf, "%x:%x:%x:%x:%x:%x", - e->ether_addr_octet[0], e->ether_addr_octet[1], - e->ether_addr_octet[2], e->ether_addr_octet[3], - e->ether_addr_octet[4], e->ether_addr_octet[5]); - trylen = strlen(trybuf); -#endif - - f = fopen(_PATH_ETHERS, "r"); - if (f == NULL) - return (-1); - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - (void)memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; -#ifdef YP - /* A + in the file means try YP now. */ - if (!strncmp(buf, "+\n", sizeof(buf))) { - char *ypbuf, *ypdom; - int ypbuflen; - - if (yp_get_default_domain(&ypdom)) - continue; - if (yp_match(ypdom, "ethers.byaddr", trybuf, - trylen, &ypbuf, &ypbuflen)) - continue; - if (ether_line(ypbuf, &try, hostname) == 0) { - free(ypbuf); - (void)fclose(f); - return (0); - } - free(ypbuf); - continue; - } -#endif - if (ether_line(buf, &try, hostname) == 0 && - memcmp((void *)&try, (void *)e, sizeof(try)) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_hostton(const char *hostname, struct ether_addr *e) -{ - FILE *f; - char buf[BUFSIZ+1], *p; - char try[MAXHOSTNAMELEN]; - size_t len; -#ifdef YP - int hostlen = strlen(hostname); -#endif - - f = fopen(_PATH_ETHERS, "r"); - if (f==NULL) - return (-1); - - while ((p = fgetln(f, &len)) != NULL) { - if (p[len-1] == '\n') - len--; - if (len > sizeof(buf) - 2) - continue; - memcpy(buf, p, len); - buf[len] = '\n'; /* code assumes newlines later on */ - buf[len+1] = '\0'; -#ifdef YP - /* A + in the file means try YP now. */ - if (!strncmp(buf, "+\n", sizeof(buf))) { - char *ypbuf, *ypdom; - int ypbuflen; - - if (yp_get_default_domain(&ypdom)) - continue; - if (yp_match(ypdom, "ethers.byname", hostname, hostlen, - &ypbuf, &ypbuflen)) - continue; - if (ether_line(ypbuf, e, try) == 0) { - free(ypbuf); - (void)fclose(f); - return (0); - } - free(ypbuf); - continue; - } -#endif - if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) { - (void)fclose(f); - return (0); - } - } - (void)fclose(f); - errno = ENOENT; - return (-1); -} - -int -ether_line(const char *line, struct ether_addr *e, char *hostname) -{ - char *p; - size_t n; - - /* Parse "xx:xx:xx:xx:xx:xx" */ - if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t')) - goto bad; - - /* Now get the hostname */ - while (isspace(*p)) - p++; - if (*p == '\0') - goto bad; - n = strcspn(p, " \t\n"); - if (n >= MAXHOSTNAMELEN) - goto bad; - strlcpy(hostname, p, n + 1); - return (0); - -bad: - errno = EINVAL; - return (-1); -} diff --git a/src/lib/libc/net/freeaddrinfo.c b/src/lib/libc/net/freeaddrinfo.c deleted file mode 100644 index 58702d0b18..0000000000 --- a/src/lib/libc/net/freeaddrinfo.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: freeaddrinfo.c,v 1.6 2005/03/25 13:24:11 otto Exp $ */ - -/* - * Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -void -freeaddrinfo(struct addrinfo *ai) -{ - struct addrinfo *p; - - do { - p = ai; - ai = ai->ai_next; - if (p->ai_canonname) - free(p->ai_canonname); - free((void *)p); - } while (ai); -} diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 deleted file mode 100644 index 9a12d9cb57..0000000000 --- a/src/lib/libc/net/gai_strerror.3 +++ /dev/null @@ -1,93 +0,0 @@ -.\" $OpenBSD: gai_strerror.3,v 1.6 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GAI_STRERROR 3 -.Os -.Sh NAME -.Nm gai_strerror -.Nd get error message string from EAI_xxx error code -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft "const char *" -.Fn gai_strerror "int ecode" -.Sh DESCRIPTION -The -.Fn gai_strerror -function returns an error message string corresponding to the error code -returned by -.Xr getaddrinfo 3 -or -.Xr getnameinfo 3 . -.Pp -The following error codes and their meaning are defined in -.Aq Pa netdb.h : -.Pp -.Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact -.It Dv EAI_ADDRFAMILY -address family for -.Fa hostname -not supported -.It Dv EAI_AGAIN -temporary failure in name resolution -.It Dv EAI_BADFLAGS -invalid value for -.Fa ai_flags -.It Dv EAI_BADHINTS -invalid value for -.Fa hints -.It Dv EAI_FAIL -non-recoverable failure in name resolution -.It Dv EAI_FAMILY -.Fa ai_family -not supported. -.It Dv EAI_MEMORY -memory allocation failure -.It Dv EAI_NODATA -no address associated with -.Fa hostname -.It Dv EAI_NONAME -.Fa hostname -or -.Fa servname -not provided, or not known -.It Dv EAI_PROTOCOL -resolved protocol is unknown -.It Dv EAI_SERVICE -.Fa servname -not supported for -.Fa ai_socktype -.It Dv EAI_SOCKTYPE -.Fa ai_socktype -not supported -.It Dv EAI_SYSTEM -system error returned in -.Va errno -.El -.Sh RETURN VALUES -.Fn gai_strerror -returns a pointer to the error message string corresponding to -.Fa ecode . -If -.Fa ecode -is out of range, an implementation-specific error message string is returned. -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 diff --git a/src/lib/libc/net/gai_strerror.c b/src/lib/libc/net/gai_strerror.c deleted file mode 100644 index 767bc2f7e8..0000000000 --- a/src/lib/libc/net/gai_strerror.c +++ /dev/null @@ -1,76 +0,0 @@ -/* $OpenBSD: gai_strerror.c,v 1.6 2004/12/20 22:35:32 millert Exp $ */ - -/* - * Copyright (c) 1997-1999, Craig Metz, All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Craig Metz and - * by other contributors. - * 4. Neither the name of the author nor the names of contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* gai_strerror() v1.38 */ - -#include -#include -#include - -const char * -gai_strerror(int errnum) -{ - switch (errnum) { - case 0: - return "no error"; - case EAI_BADFLAGS: - return "invalid value for ai_flags"; - case EAI_NONAME: - return "name or service is not known"; - case EAI_AGAIN: - return "temporary failure in name resolution"; - case EAI_FAIL: - return "non-recoverable failure in name resolution"; - case EAI_NODATA: - return "no address associated with name"; - case EAI_FAMILY: - return "ai_family not supported"; - case EAI_SOCKTYPE: - return "ai_socktype not supported"; - case EAI_SERVICE: - return "service not supported for ai_socktype"; - case EAI_ADDRFAMILY: - return "address family for name not supported"; - case EAI_MEMORY: - return "memory allocation failure"; - case EAI_SYSTEM: - return "system error"; - case EAI_BADHINTS: - return "invalid value for hints"; - case EAI_PROTOCOL: - return "resolved protocol is unknown"; - default: - return "unknown/invalid error"; - } -} diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 deleted file mode 100644 index ba42a8e8bd..0000000000 --- a/src/lib/libc/net/getaddrinfo.3 +++ /dev/null @@ -1,437 +0,0 @@ -.\" $OpenBSD: getaddrinfo.3,v 1.45 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETADDRINFO 3 -.Os -.Sh NAME -.Nm getaddrinfo , -.Nm freeaddrinfo -.Nd host and service name to socket address structure -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getaddrinfo "const char *hostname" "const char *servname" \ - "const struct addrinfo *hints" "struct addrinfo **res" -.Ft void -.Fn freeaddrinfo "struct addrinfo *ai" -.Sh DESCRIPTION -The -.Fn getaddrinfo -function is used to get a list of -.Tn IP -addresses and port numbers for host -.Fa hostname -and service -.Fa servname . -It is a replacement for and provides more flexibility than the -.Xr gethostbyname 3 -and -.Xr getservbyname 3 -functions. -.Pp -The -.Fa hostname -and -.Fa servname -arguments are either pointers to NUL-terminated strings or the null pointer. -An acceptable value for -.Fa hostname -is either a valid host name or a numeric host address string consisting -of a dotted decimal IPv4 address or an IPv6 address. -The -.Fa servname -is either a decimal port number or a service name listed in -.Xr services 5 . -At least one of -.Fa hostname -and -.Fa servname -must be non-null. -.Pp -.Fa hints -is an optional pointer to a -.Li struct addrinfo , -as defined by -.Aq Pa netdb.h : -.Bd -literal -struct addrinfo { - int ai_flags; /* input flags */ - int ai_family; /* protocol family for socket */ - int ai_socktype; /* socket type */ - int ai_protocol; /* protocol for socket */ - socklen_t ai_addrlen; /* length of socket-address */ - struct sockaddr *ai_addr; /* socket-address for socket */ - char *ai_canonname; /* canonical name for service location */ - struct addrinfo *ai_next; /* pointer to next in list */ -}; -.Ed -.Pp -This structure can be used to provide hints concerning the type of socket -that the caller supports or wishes to use. -The caller can supply the following structure elements in -.Fa hints : -.Bl -tag -width "ai_socktypeXX" -.It Fa ai_family -The protocol family that should be used. -When -.Fa ai_family -is set to -.Dv PF_UNSPEC , -it means the caller will accept any protocol family supported by the -operating system. -.It Fa ai_socktype -Denotes the type of socket that is wanted: -.Dv SOCK_STREAM , -.Dv SOCK_DGRAM , -or -.Dv SOCK_RAW . -When -.Fa ai_socktype -is zero the caller will accept any socket type. -.It Fa ai_protocol -Indicates which transport protocol is desired, -.Dv IPPROTO_UDP -or -.Dv IPPROTO_TCP . -If -.Fa ai_protocol -is zero the caller will accept any protocol. -.It Fa ai_flags -.Fa ai_flags -is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "AI_CANONNAMEXX" -.It Dv AI_CANONNAME -If the -.Dv AI_CANONNAME -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the canonical name -of the specified hostname in the -.Fa ai_canonname -element of the first -.Li addrinfo -structure returned. -.It Dv AI_NUMERICHOST -If the -.Dv AI_NUMERICHOST -bit is set, it indicates that -.Fa hostname -should be treated as a numeric string defining an IPv4 or IPv6 address -and no name resolution should be attempted. -.It Dv AI_PASSIVE -If the -.Dv AI_PASSIVE -bit is set it indicates that the returned socket address structure -is intended for use in a call to -.Xr bind 2 . -In this case, if the -.Fa hostname -argument is the null pointer, then the IP address portion of the -socket address structure will be set to -.Dv INADDR_ANY -for an IPv4 address or -.Dv IN6ADDR_ANY_INIT -for an IPv6 address. -.Pp -If the -.Dv AI_PASSIVE -bit is not set, the returned socket address structure will be ready -for use in a call to -.Xr connect 2 -for a connection-oriented protocol or -.Xr connect 2 , -.Xr sendto 2 , -or -.Xr sendmsg 2 -if a connectionless protocol was chosen. -The -.Tn IP -address portion of the socket address structure will be set to the -loopback address if -.Fa hostname -is the null pointer and -.Dv AI_PASSIVE -is not set. -.El -.El -.Pp -All other elements of the -.Li addrinfo -structure passed via -.Fa hints -must be zero or the null pointer. -.Pp -If -.Fa hints -is the null pointer, -.Fn getaddrinfo -behaves as if the caller provided a -.Li struct addrinfo -with -.Fa ai_family -set to -.Dv PF_UNSPEC -and all other elements set to zero or -.Dv NULL . -.Pp -After a successful call to -.Fn getaddrinfo , -.Fa *res -is a pointer to a linked list of one or more -.Li addrinfo -structures. -The list can be traversed by following the -.Fa ai_next -pointer in each -.Li addrinfo -structure until a null pointer is encountered. -The three members -.Fa ai_family , -.Fa ai_socktype , -and -.Fa ai_protocol -in each returned -.Li addrinfo -structure are suitable for a call to -.Xr socket 2 . -For each -.Li addrinfo -structure in the list, the -.Fa ai_addr -member points to a filled-in socket address structure of length -.Fa ai_addrlen . -.Pp -This implementation of -.Fn getaddrinfo -allows numeric IPv6 address notation with scope identifier, -as documented in chapter 11 of draft-ietf-ipv6-scoping-arch-02.txt. -By appending the percent character and scope identifier to addresses, -one can fill the -.Li sin6_scope_id -field for addresses. -This would make management of scoped addresses easier -and allows cut-and-paste input of scoped addresses. -.Pp -At this moment the code supports only link-local addresses with the format. -The scope identifier is hardcoded to the name of the hardware interface -associated -with the link -.Po -such as -.Li ne0 -.Pc . -An example is -.Dq Li fe80::1%ne0 , -which means -.Do -.Li fe80::1 -on the link associated with the -.Li ne0 -interface -.Dc . -.Pp -The current implementation assumes a one-to-one relationship between -the interface and link, which is not necessarily true from the specification. -.Pp -All of the information returned by -.Fn getaddrinfo -is dynamically allocated: the -.Li addrinfo -structures themselves as well as the socket address structures and -the canonical host name strings included in the -.Li addrinfo -structures. -.Pp -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getaddrinfo -is released by the -.Fn freeaddrinfo -function. -The -.Fa ai -pointer should be a -.Li addrinfo -structure created by a call to -.Fn getaddrinfo . -.Sh RETURN VALUES -.Fn getaddrinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -If an error occurs, no memory is allocated by -.Fn getaddrinfo , -therefore it is not necessary to release the -.Li addrinfo -structure(s). -.Sh EXAMPLES -The following code tries to connect to -.Dq Li www.kame.net -service -.Dq Li www -via a stream socket. -It loops through all the addresses available, regardless of address family. -If the destination resolves to an IPv4 address, it will use an -.Dv AF_INET -socket. -Similarly, if it resolves to IPv6, an -.Dv AF_INET6 -socket is used. -Observe that there is no hardcoded reference to a particular address family. -The code works even if -.Fn getaddrinfo -returns addresses that are not IPv4/v6. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = PF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -error = getaddrinfo("www.kame.net", "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -s = -1; -for (res = res0; res; res = res->ai_next) { - s = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s < 0) { - cause = "socket"; - continue; - } - - if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { - cause = "connect"; - save_errno = errno; - close(s); - errno = save_errno; - s = -1; - continue; - } - - break; /* okay we got one */ -} -if (s < 0) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Pp -The following example tries to open a wildcard listening socket onto service -.Dq Li www , -for all the address families available. -.Bd -literal -offset indent -struct addrinfo hints, *res, *res0; -int error; -int save_errno; -int s[MAXSOCK]; -int nsock; -const char *cause = NULL; - -memset(&hints, 0, sizeof(hints)); -hints.ai_family = PF_UNSPEC; -hints.ai_socktype = SOCK_STREAM; -hints.ai_flags = AI_PASSIVE; -error = getaddrinfo(NULL, "www", &hints, &res0); -if (error) - errx(1, "%s", gai_strerror(error)); -nsock = 0; -for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { - s[nsock] = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (s[nsock] < 0) { - cause = "socket"; - continue; - } - - if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0) { - cause = "bind"; - save_errno = errno; - close(s[nsock]); - errno = save_errno; - continue; - } - (void) listen(s[nsock], 5); - - nsock++; -} -if (nsock == 0) - err(1, "%s", cause); -freeaddrinfo(res0); -.Ed -.Sh SEE ALSO -.Xr bind 2 , -.Xr connect 2 , -.Xr send 2 , -.Xr socket 2 , -.Xr gai_strerror 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr getservbyname 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 , -.Xr named 8 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 3493 -.%D February 2003 -.Re -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%T "IPv6 Scoped Address Architecture" -.%R internet draft -.%N draft-ietf-ipv6-scoping-arch-02.txt -.%O work in progress material -.Re -.Rs -.%A Craig Metz -.%T Protocol Independence Using the Sockets API -.%B "Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference" -.%D June 2000 -.Re -.Sh STANDARDS -The -.Fn getaddrinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in -.Dv "RFC 3493" , -.Dq Basic Socket Interface Extensions for IPv6 . -.Sh BUGS -The implementation of -.Fn getaddrinfo -is not thread-safe. diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c deleted file mode 100644 index 0f3b6319f4..0000000000 --- a/src/lib/libc/net/getaddrinfo.c +++ /dev/null @@ -1,1748 +0,0 @@ -/* $OpenBSD: getaddrinfo.c,v 1.67 2007/05/20 03:54:52 ray Exp $ */ -/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Issues to be discussed: - * - Thread safe-ness must be checked. - * - Return values. There are nonstandard return values defined and used - * in the source code. This is because RFC2553 is silent about which error - * code must be returned for which situation. - * - IPv4 classful (shortened) form. RFC2553 is silent about it. XNET 5.2 - * says to use inet_aton() to convert IPv4 numeric to binary (allows - * classful form as a result). - * current code - disallow classful form for IPv4 (due to use of inet_pton). - * - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is - * invalid. - * current code - SEGV on freeaddrinfo(NULL) - * Note: - * - We use getipnodebyname() just for thread-safeness. There's no intent - * to let it do PF_UNSPEC (actually we never pass PF_UNSPEC to - * getipnodebyname(). - * - The code filters out AFs that are not supported by the kernel, - * when globbing NULL hostname (to loopback, or wildcard). Is it the right - * thing to do? What is the relationship with post-RFC2553 AI_ADDRCONFIG - * in ai_flags? - * - (post-2553) semantics of AI_ADDRCONFIG itself is too vague. - * (1) what should we do against numeric hostname (2) what should we do - * against NULL hostname (3) what is AI_ADDRCONFIG itself. AF not ready? - * non-loopback address configured? global address configured? - * - To avoid search order issue, we have a big amount of code duplicate - * from gethnamaddr.c and some other places. The issues that there's no - * lower layer function to lookup "IPv4 or IPv6" record. Calling - * gethostbyname2 from getaddrinfo will end up in wrong search order, as - * follows: - * - The code makes use of following calls when asked to resolver with - * ai_family = PF_UNSPEC: - * getipnodebyname(host, AF_INET6); - * getipnodebyname(host, AF_INET); - * This will result in the following queries if the node is configure to - * prefer /etc/hosts than DNS: - * lookup /etc/hosts for IPv6 address - * lookup DNS for IPv6 address - * lookup /etc/hosts for IPv4 address - * lookup DNS for IPv4 address - * which may not meet people's requirement. - * The right thing to happen is to have underlying layer which does - * PF_UNSPEC lookup (lookup both) and return chain of addrinfos. - * This would result in a bit of code duplicate with _dns_ghbyname() and - * friends. - */ - -#ifndef INET6 -#define INET6 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef YP -#include -#include -#include -#include "ypinternal.h" -#endif - -#include "thread_private.h" - -#define SUCCESS 0 -#define ANY 0 -#define YES 1 -#define NO 0 - -static const char in_addrany[] = { 0, 0, 0, 0 }; -static const char in6_addrany[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; -static const char in_loopback[] = { 127, 0, 0, 1 }; -static const char in6_loopback[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 -}; - -static const struct afd { - int a_af; - int a_addrlen; - int a_socklen; - int a_off; - const char *a_addrany; - const char *a_loopback; - int a_scoped; -} afdl [] = { -#ifdef INET6 - {PF_INET6, sizeof(struct in6_addr), - sizeof(struct sockaddr_in6), - offsetof(struct sockaddr_in6, sin6_addr), - in6_addrany, in6_loopback, 1}, -#endif - {PF_INET, sizeof(struct in_addr), - sizeof(struct sockaddr_in), - offsetof(struct sockaddr_in, sin_addr), - in_addrany, in_loopback, 0}, - {0, 0, 0, 0, NULL, NULL, 0}, -}; - -struct explore { - int e_af; - int e_socktype; - int e_protocol; - const char *e_protostr; - int e_wild; -#define WILD_AF(ex) ((ex)->e_wild & 0x01) -#define WILD_SOCKTYPE(ex) ((ex)->e_wild & 0x02) -#define WILD_PROTOCOL(ex) ((ex)->e_wild & 0x04) -}; - -static const struct explore explore[] = { -#if 0 - { PF_LOCAL, 0, ANY, ANY, NULL, 0x01 }, -#endif -#ifdef INET6 - { PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET6, SOCK_RAW, ANY, NULL, 0x05 }, -#endif - { PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_INET, SOCK_RAW, ANY, NULL, 0x05 }, - { PF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07 }, - { PF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07 }, - { PF_UNSPEC, SOCK_RAW, ANY, NULL, 0x05 }, - { -1, 0, 0, NULL, 0 }, -}; - -#ifdef INET6 -#define PTON_MAX 16 -#else -#define PTON_MAX 4 -#endif - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -struct res_target { - struct res_target *next; - const char *name; /* domain name */ - int qclass, qtype; /* class and type of query */ - u_char *answer; /* buffer to put answer */ - int anslen; /* size of answer buffer */ - int n; /* result length */ -}; - -static int explore_fqdn(const struct addrinfo *, const char *, - const char *, struct addrinfo **); -static int explore_null(const struct addrinfo *, - const char *, struct addrinfo **); -static int explore_numeric(const struct addrinfo *, const char *, - const char *, struct addrinfo **, const char *); -static int explore_numeric_scope(const struct addrinfo *, const char *, - const char *, struct addrinfo **); -static int get_canonname(const struct addrinfo *, - struct addrinfo *, const char *); -static struct addrinfo *get_ai(const struct addrinfo *, - const struct afd *, const char *); -static int get_portmatch(const struct addrinfo *, const char *); -static int get_port(struct addrinfo *, const char *, int); -static const struct afd *find_afd(int); -#ifdef INET6 -static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *); -#endif - -static struct addrinfo * _gethtent(const char *, const struct addrinfo *, - FILE *); -static struct addrinfo *_files_getaddrinfo(const char *, - const struct addrinfo *); - -#ifdef YP -static struct addrinfo *_yphostent(char *, const struct addrinfo *); -static struct addrinfo *_yp_getaddrinfo(const char *, - const struct addrinfo *); -#endif - -static struct addrinfo *getanswer(const querybuf *, int, const char *, int, - const struct addrinfo *); -static int res_queryN(const char *, struct res_target *); -static int res_searchN(const char *, struct res_target *); -static int res_querydomainN(const char *, const char *, struct res_target *); -static struct addrinfo *_dns_getaddrinfo(const char *, const struct addrinfo *); - - -/* XXX macros that make external reference is BAD. */ - -#define GET_AI(ai, afd, addr) \ -do { \ - /* external reference: pai, error, and label free */ \ - (ai) = get_ai(pai, (afd), (addr)); \ - if ((ai) == NULL) { \ - error = EAI_MEMORY; \ - goto free; \ - } \ -} while (/*CONSTCOND*/0) - -#define GET_PORT(ai, serv) \ -do { \ - /* external reference: error and label free */ \ - error = get_port((ai), (serv), 0); \ - if (error != 0) \ - goto free; \ -} while (/*CONSTCOND*/0) - -#define GET_CANONNAME(ai, str) \ -do { \ - /* external reference: pai, error and label free */ \ - error = get_canonname(pai, (ai), (str)); \ - if (error != 0) \ - goto free; \ -} while (/*CONSTCOND*/0) - -#define ERR(err) \ -do { \ - /* external reference: error, and label bad */ \ - error = (err); \ - goto bad; \ - /*NOTREACHED*/ \ -} while (/*CONSTCOND*/0) - -#define MATCH_FAMILY(x, y, w) \ - ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC))) -#define MATCH(x, y, w) \ - ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) - -int -getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res) -{ - struct addrinfo sentinel; - struct addrinfo *cur; - int error = 0; - struct addrinfo ai; - struct addrinfo ai0; - struct addrinfo *pai; - const struct explore *ex; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - pai = &ai; - pai->ai_flags = 0; - pai->ai_family = PF_UNSPEC; - pai->ai_socktype = ANY; - pai->ai_protocol = ANY; - pai->ai_addrlen = 0; - pai->ai_canonname = NULL; - pai->ai_addr = NULL; - pai->ai_next = NULL; - - if (hostname == NULL && servname == NULL) - return EAI_NONAME; - if (hints) { - /* error check for hints */ - if (hints->ai_addrlen || hints->ai_canonname || - hints->ai_addr || hints->ai_next) - ERR(EAI_BADHINTS); /* xxx */ - if (hints->ai_flags & ~AI_MASK) - ERR(EAI_BADFLAGS); - switch (hints->ai_family) { - case PF_UNSPEC: - case PF_INET: -#ifdef INET6 - case PF_INET6: -#endif - break; - default: - ERR(EAI_FAMILY); - } - memcpy(pai, hints, sizeof(*pai)); - - /* - * if both socktype/protocol are specified, check if they - * are meaningful combination. - */ - if (pai->ai_socktype != ANY && pai->ai_protocol != ANY) { - for (ex = explore; ex->e_af >= 0; ex++) { - if (pai->ai_family != ex->e_af) - continue; - if (ex->e_socktype == ANY) - continue; - if (ex->e_protocol == ANY) - continue; - if (pai->ai_socktype == ex->e_socktype - && pai->ai_protocol != ex->e_protocol) { - ERR(EAI_BADHINTS); - } - } - } - } - - /* - * check for special cases. (1) numeric servname is disallowed if - * socktype/protocol are left unspecified. (2) servname is disallowed - * for raw and other inet{,6} sockets. - */ - if (MATCH_FAMILY(pai->ai_family, PF_INET, 1) -#ifdef PF_INET6 - || MATCH_FAMILY(pai->ai_family, PF_INET6, 1) -#endif - ) { - ai0 = *pai; /* backup *pai */ - - if (pai->ai_family == PF_UNSPEC) { -#ifdef PF_INET6 - pai->ai_family = PF_INET6; -#else - pai->ai_family = PF_INET; -#endif - } - error = get_portmatch(pai, servname); - if (error) - ERR(error); - - *pai = ai0; - } - - ai0 = *pai; - - /* NULL hostname, or numeric hostname */ - for (ex = explore; ex->e_af >= 0; ex++) { - *pai = ai0; - - /* PF_UNSPEC entries are prepared for DNS queries only */ - if (ex->e_af == PF_UNSPEC) - continue; - - if (!MATCH_FAMILY(pai->ai_family, ex->e_af, WILD_AF(ex))) - continue; - if (!MATCH(pai->ai_socktype, ex->e_socktype, WILD_SOCKTYPE(ex))) - continue; - if (!MATCH(pai->ai_protocol, ex->e_protocol, WILD_PROTOCOL(ex))) - continue; - - if (pai->ai_family == PF_UNSPEC) - pai->ai_family = ex->e_af; - if (pai->ai_socktype == ANY && ex->e_socktype != ANY) - pai->ai_socktype = ex->e_socktype; - if (pai->ai_protocol == ANY && ex->e_protocol != ANY) - pai->ai_protocol = ex->e_protocol; - - if (hostname == NULL) - error = explore_null(pai, servname, &cur->ai_next); - else - error = explore_numeric_scope(pai, hostname, servname, - &cur->ai_next); - - if (error) - goto free; - - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - /* - * XXX - * If numeric representation of AF1 can be interpreted as FQDN - * representation of AF2, we need to think again about the code below. - */ - if (sentinel.ai_next) - goto good; - - if (hostname == NULL) - ERR(EAI_NODATA); - if (pai->ai_flags & AI_NUMERICHOST) - ERR(EAI_NONAME); - - /* - * hostname as alphabetical name. - * we would like to prefer AF_INET6 than AF_INET, so we'll make an - * outer loop by AFs. - */ - for (ex = explore; ex->e_af >= 0; ex++) { - *pai = ai0; - - /* require exact match for family field */ - if (pai->ai_family != ex->e_af) - continue; - - if (!MATCH(pai->ai_socktype, ex->e_socktype, - WILD_SOCKTYPE(ex))) { - continue; - } - if (!MATCH(pai->ai_protocol, ex->e_protocol, - WILD_PROTOCOL(ex))) { - continue; - } - - if (pai->ai_socktype == ANY && ex->e_socktype != ANY) - pai->ai_socktype = ex->e_socktype; - if (pai->ai_protocol == ANY && ex->e_protocol != ANY) - pai->ai_protocol = ex->e_protocol; - - error = explore_fqdn(pai, hostname, servname, - &cur->ai_next); - - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - /* XXX */ - if (sentinel.ai_next) - error = 0; - - if (error == 0) { - if (sentinel.ai_next) { - good: - *res = sentinel.ai_next; - return SUCCESS; - } else - error = EAI_FAIL; - } - free: - bad: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - *res = NULL; - return error; -} - -/* - * FQDN hostname, DNS lookup - */ - -static int -explore_fqdn(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - struct addrinfo *result; - struct addrinfo *cur; - int error = 0; - char lookups[MAXDNSLUS]; - int i; - _THREAD_PRIVATE_MUTEX(_explore_mutex); - - result = NULL; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) { - return 0; - } - - if (_res_init(0) == -1) - strlcpy(lookups, "f", sizeof lookups); - else { - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - } - - /* - * The yp/dns/files getaddrinfo functions are not thread safe. - * Protect them with a mutex. - */ - _THREAD_PRIVATE_MUTEX_LOCK(_explore_mutex); - for (i = 0; i < MAXDNSLUS && result == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - result = _yp_getaddrinfo(hostname, pai); - break; -#endif - case 'b': - result = _dns_getaddrinfo(hostname, pai); - break; - case 'f': - result = _files_getaddrinfo(hostname, pai); - break; - } - } - _THREAD_PRIVATE_MUTEX_UNLOCK(_explore_mutex); - if (result) { - for (cur = result; cur; cur = cur->ai_next) { - GET_PORT(cur, servname); - /* canonname should be filled already */ - } - *res = result; - return 0; - } else { - /* translate error code */ - switch (h_errno) { - case NETDB_SUCCESS: - error = EAI_FAIL; /*XXX strange */ - break; - case HOST_NOT_FOUND: - error = EAI_NODATA; - break; - case TRY_AGAIN: - error = EAI_AGAIN; - break; - case NO_RECOVERY: - error = EAI_FAIL; - break; - case NO_DATA: -#if NO_ADDRESS != NO_DATA - case NO_ADDRESS: -#endif - error = EAI_NODATA; - break; - default: /* unknown ones */ - error = EAI_FAIL; - break; - } - } - -free: - if (result) - freeaddrinfo(result); - return error; -} - -/* - * hostname == NULL. - * passive socket -> anyaddr (0.0.0.0 or ::) - * non-passive socket -> localhost (127.0.0.1 or ::1) - */ -static int -explore_null(const struct addrinfo *pai, const char *servname, - struct addrinfo **res) -{ - int s; - const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; - int error; - - *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; - - /* - * filter out AFs that are not supported by the kernel - * XXX errno? - */ - s = socket(pai->ai_family, SOCK_DGRAM, 0); - if (s < 0) { - if (errno != EMFILE) - return 0; - } else - close(s); - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - if (pai->ai_flags & AI_PASSIVE) { - GET_AI(cur->ai_next, afd, afd->a_addrany); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "anyaddr"); - */ - } else { - GET_AI(cur->ai_next, afd, afd->a_loopback); - /* xxx meaningless? - * GET_CANONNAME(cur->ai_next, "localhost"); - */ - } - GET_PORT(cur->ai_next, servname); - cur = cur->ai_next; - - *res = sentinel.ai_next; - return 0; - -free: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - return error; -} - -/* - * numeric hostname - */ -static int -explore_numeric(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res, const char *canonname) -{ - const struct afd *afd; - struct addrinfo *cur; - struct addrinfo sentinel; - int error; - char pton[PTON_MAX]; - - *res = NULL; - sentinel.ai_next = NULL; - cur = &sentinel; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - switch (afd->a_af) { -#if 0 /*X/Open spec*/ - case AF_INET: - error = inet_aton(hostname, (struct in_addr *)pton); - break; -#endif - default: - error = inet_pton(afd->a_af, hostname, pton); - break; - } - if (error == 1) { - if (pai->ai_family == afd->a_af || - pai->ai_family == PF_UNSPEC /*?*/) { - GET_AI(cur->ai_next, afd, pton); - GET_PORT(cur->ai_next, servname); - if ((pai->ai_flags & AI_CANONNAME)) { - /* - * Set the numeric address itself as - * the canonical name, based on a - * clarification in rfc2553bis-03. - */ - GET_CANONNAME(cur->ai_next, canonname); - } - while (cur && cur->ai_next) - cur = cur->ai_next; - } else - ERR(EAI_FAMILY); /*xxx*/ - } - - *res = sentinel.ai_next; - return 0; - -free: -bad: - if (sentinel.ai_next) - freeaddrinfo(sentinel.ai_next); - return error; -} - -/* - * numeric hostname with scope - */ -static int -explore_numeric_scope(const struct addrinfo *pai, const char *hostname, - const char *servname, struct addrinfo **res) -{ -#if !defined(SCOPE_DELIMITER) || !defined(INET6) - return explore_numeric(pai, hostname, servname, res, hostname); -#else - const struct afd *afd; - struct addrinfo *cur; - int error; - char *cp, *hostname2 = NULL, *scope, *addr; - struct sockaddr_in6 *sin6; - - /* - * if the servname does not match socktype/protocol, ignore it. - */ - if (get_portmatch(pai, servname) != 0) - return 0; - - afd = find_afd(pai->ai_family); - if (afd == NULL) - return 0; - - if (!afd->a_scoped) - return explore_numeric(pai, hostname, servname, res, hostname); - - cp = strchr(hostname, SCOPE_DELIMITER); - if (cp == NULL) - return explore_numeric(pai, hostname, servname, res, hostname); - - /* - * Handle special case of - */ - hostname2 = strdup(hostname); - if (hostname2 == NULL) - return EAI_MEMORY; - /* terminate at the delimiter */ - hostname2[cp - hostname] = '\0'; - addr = hostname2; - scope = cp + 1; - - error = explore_numeric(pai, addr, servname, res, hostname); - if (error == 0) { - u_int32_t scopeid; - - for (cur = *res; cur; cur = cur->ai_next) { - if (cur->ai_family != AF_INET6) - continue; - sin6 = (struct sockaddr_in6 *)(void *)cur->ai_addr; - if (ip6_str2scopeid(scope, sin6, &scopeid) == -1) { - free(hostname2); - return(EAI_NODATA); /* XXX: is return OK? */ - } - sin6->sin6_scope_id = scopeid; - } - } - - free(hostname2); - - return error; -#endif -} - -static int -get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str) -{ - if ((pai->ai_flags & AI_CANONNAME) != 0) { - ai->ai_canonname = strdup(str); - if (ai->ai_canonname == NULL) - return EAI_MEMORY; - } - return 0; -} - -static struct addrinfo * -get_ai(const struct addrinfo *pai, const struct afd *afd, const char *addr) -{ - char *p; - struct addrinfo *ai; - - ai = (struct addrinfo *)malloc(sizeof(struct addrinfo) - + (afd->a_socklen)); - if (ai == NULL) - return NULL; - - memcpy(ai, pai, sizeof(struct addrinfo)); - ai->ai_addr = (struct sockaddr *)(void *)(ai + 1); - memset(ai->ai_addr, 0, (size_t)afd->a_socklen); - ai->ai_addr->sa_len = afd->a_socklen; - ai->ai_addrlen = afd->a_socklen; - ai->ai_addr->sa_family = ai->ai_family = afd->a_af; - p = (char *)(void *)(ai->ai_addr); - memcpy(p + afd->a_off, addr, (size_t)afd->a_addrlen); - return ai; -} - -static int -get_portmatch(const struct addrinfo *ai, const char *servname) -{ - - /* get_port does not touch first argument. when matchonly == 1. */ - /* LINTED const cast */ - return get_port((struct addrinfo *)ai, servname, 1); -} - -static int -get_port(struct addrinfo *ai, const char *servname, int matchonly) -{ - const char *errstr, *proto; - int port; - int allownumeric; - - if (servname == NULL) - return 0; - switch (ai->ai_family) { - case AF_INET: -#ifdef AF_INET6 - case AF_INET6: -#endif - break; - default: - return 0; - } - - switch (ai->ai_socktype) { - case SOCK_RAW: - return EAI_SERVICE; - case SOCK_DGRAM: - case SOCK_STREAM: - allownumeric = 1; - break; - case ANY: - allownumeric = 0; - break; - default: - return EAI_SOCKTYPE; - } - - port = (int)strtonum(servname, 0, USHRT_MAX, &errstr); - if (!errstr) { - if (!allownumeric) - return EAI_SERVICE; - port = htons(port); - } else { - struct servent sp; - struct servent_data sd; - - if (errno == ERANGE) - return EAI_SERVICE; - if (ai->ai_flags & AI_NUMERICSERV) - return EAI_NONAME; - - switch (ai->ai_socktype) { - case SOCK_DGRAM: - proto = "udp"; - break; - case SOCK_STREAM: - proto = "tcp"; - break; - default: - proto = NULL; - break; - } - - (void)memset(&sd, 0, sizeof(sd)); - if (getservbyname_r(servname, proto, &sp, &sd) == -1) - return EAI_SERVICE; - port = sp.s_port; - endservent_r(&sd); - } - - if (!matchonly) { - switch (ai->ai_family) { - case AF_INET: - ((struct sockaddr_in *)(void *) - ai->ai_addr)->sin_port = port; - break; -#ifdef INET6 - case AF_INET6: - ((struct sockaddr_in6 *)(void *) - ai->ai_addr)->sin6_port = port; - break; -#endif - } - } - - return 0; -} - -static const struct afd * -find_afd(int af) -{ - const struct afd *afd; - - if (af == PF_UNSPEC) - return NULL; - for (afd = afdl; afd->a_af; afd++) { - if (afd->a_af == af) - return afd; - } - return NULL; -} - -#ifdef INET6 -/* convert a string to a scope identifier. XXX: IPv6 specific */ -static int -ip6_str2scopeid(char *scope, struct sockaddr_in6 *sin6, u_int32_t *scopeid) -{ - struct in6_addr *a6 = &sin6->sin6_addr; - const char *errstr; - - /* empty scopeid portion is invalid */ - if (*scope == '\0') - return -1; - - if (IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || - IN6_IS_ADDR_MC_INTFACELOCAL(a6)) { - /* - * We currently assume a one-to-one mapping between links - * and interfaces, so we simply use interface indices for - * like-local scopes. - */ - *scopeid = if_nametoindex(scope); - if (*scopeid == 0) - goto trynumeric; - return 0; - } - - /* still unclear about literal, allow numeric only - placeholder */ - if (IN6_IS_ADDR_SITELOCAL(a6) || IN6_IS_ADDR_MC_SITELOCAL(a6)) - goto trynumeric; - if (IN6_IS_ADDR_MC_ORGLOCAL(a6)) - goto trynumeric; - else - goto trynumeric; /* global */ - - /* try to convert to a numeric id as a last resort */ - trynumeric: - *scopeid = (u_int32_t)strtonum(scope, 0, UINT32_MAX, &errstr); - if (errstr) - return (-1); - return (0); -} -#endif - -/* code duplicate with gethnamaddr.c */ - -static const char AskedForGot[] = - "gethostby*.getanswer: asked for \"%s\", got \"%s\""; - -static struct addrinfo * -getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, - const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo ai; - const struct afd *afd; - char *canonname; - const HEADER *hp; - const u_char *cp; - int n; - const u_char *eom; - char *bp, *ep; - int type, class, ancount, qdcount; - int haveanswer, had_error; - char tbuf[MAXDNAME]; - int (*name_ok)(const char *); - char hostbuf[8*1024]; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - canonname = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: - case T_ANY: /*use T_ANY only for T_A/T_AAAA lookup*/ - name_ok = res_hnok; - break; - default: - return (NULL); /* XXX should be abort() -- but that is illegal */ - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - ep = hostbuf + sizeof hostbuf; - cp = answer->buf + HFIXEDSZ; - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return (NULL); - } - cp += n + QFIXEDSZ; - if (qtype == T_A || qtype == T_AAAA || qtype == T_ANY) { - size_t len; - - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - len = strlen(bp) + 1; /* for the \0 */ - if (len >= MAXHOSTNAMELEN) { - h_errno = NO_RECOVERY; - return (NULL); - } - canonname = bp; - bp += len; - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = canonname; - } - haveanswer = 0; - had_error = 0; - while (ancount-- > 0 && cp < eom && !had_error) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - type = _getshort(cp); - cp += INT16SZ; /* type */ - class = _getshort(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ - n = _getshort(cp); - cp += INT16SZ; /* len */ - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) && - type == T_CNAME) { - size_t len; - - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp || len >= MAXHOSTNAMELEN) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - canonname = bp; - bp += len; - continue; - } - if (qtype == T_ANY) { - if (!(type == T_A || type == T_AAAA)) { - cp += n; - continue; - } - } else if (type != qtype) { - if (type != T_KEY && type != T_SIG) { - struct syslog_data sdata = SYSLOG_DATA_INIT; - - syslog_r(LOG_NOTICE|LOG_AUTH, &sdata, - "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - } - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_A: - case T_AAAA: - if (strcasecmp(canonname, bp) != 0) { - struct syslog_data sdata = SYSLOG_DATA_INIT; - - syslog_r(LOG_NOTICE|LOG_AUTH, &sdata, - AskedForGot, canonname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (type == T_A && n != INADDRSZ) { - cp += n; - continue; - } - if (type == T_AAAA && n != IN6ADDRSZ) { - cp += n; - continue; - } - if (type == T_AAAA) { - struct in6_addr in6; - memcpy(&in6, cp, IN6ADDRSZ); - if (IN6_IS_ADDR_V4MAPPED(&in6)) { - cp += n; - continue; - } - } - if (!haveanswer) { - canonname = bp; - bp += strlen(bp) + 1; /* for the \0 */ - } - - /* don't overwrite pai */ - ai = *pai; - ai.ai_family = (type == T_A) ? AF_INET : AF_INET6; - afd = find_afd(ai.ai_family); - if (afd == NULL) { - cp += n; - continue; - } - cur->ai_next = get_ai(&ai, afd, (const char *)cp); - if (cur->ai_next == NULL) - had_error++; - while (cur && cur->ai_next) - cur = cur->ai_next; - cp += n; - break; - default: - abort(); /* XXX abort illegal in library */ - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - if (!canonname) - (void)get_canonname(pai, sentinel.ai_next, qname); - else - (void)get_canonname(pai, sentinel.ai_next, canonname); - h_errno = NETDB_SUCCESS; - return sentinel.ai_next; - } - - h_errno = NO_RECOVERY; - return NULL; -} - -/*ARGSUSED*/ -static struct addrinfo * -_dns_getaddrinfo(const char *name, const struct addrinfo *pai) -{ - struct addrinfo *ai; - querybuf *buf, *buf2; - struct addrinfo sentinel, *cur; - struct res_target q, q2; - - memset(&q, 0, sizeof(q)); - memset(&q2, 0, sizeof(q2)); - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - buf = malloc(sizeof(*buf)); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return NULL; - } - buf2 = malloc(sizeof(*buf2)); - if (buf2 == NULL) { - free(buf); - h_errno = NETDB_INTERNAL; - return NULL; - } - - switch (pai->ai_family) { - case AF_UNSPEC: - /* prefer IPv6 */ - q.qclass = C_IN; - q.qtype = T_AAAA; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - q.next = &q2; - q2.qclass = C_IN; - q2.qtype = T_A; - q2.answer = buf2->buf; - q2.anslen = sizeof(buf2->buf); - break; - case AF_INET: - q.qclass = C_IN; - q.qtype = T_A; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - break; - case AF_INET6: - q.qclass = C_IN; - q.qtype = T_AAAA; - q.answer = buf->buf; - q.anslen = sizeof(buf->buf); - break; - default: - free(buf); - free(buf2); - return NULL; - } - if (res_searchN(name, &q) < 0) { - free(buf); - free(buf2); - return NULL; - } - ai = getanswer(buf, q.n, q.name, q.qtype, pai); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - if (q.next) { - ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai); - if (ai) - cur->ai_next = ai; - } - free(buf); - free(buf2); - return sentinel.ai_next; -} - -static struct addrinfo * -_gethtent(const char *name, const struct addrinfo *pai, FILE *hostf) -{ - char *p; - char *cp, *tname, *cname; - struct addrinfo hints, *res0, *res; - int error; - const char *addr; - char hostbuf[8*1024]; - - again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) - return (NULL); - if (*p == '#') - goto again; - if (!(cp = strpbrk(p, "#\n"))) - goto again; - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - addr = p; - /* if this is not something we're looking for, skip it. */ - cname = NULL; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (!cname) - cname = cp; - tname = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - if (strcasecmp(name, tname) == 0) - goto found; - } - goto again; - -found: - hints = *pai; - hints.ai_flags = AI_NUMERICHOST; - error = getaddrinfo(addr, NULL, &hints, &res0); - if (error) - goto again; - for (res = res0; res; res = res->ai_next) { - /* cover it up */ - res->ai_flags = pai->ai_flags; - - if (pai->ai_flags & AI_CANONNAME) { - if (get_canonname(pai, res, cname) != 0) { - freeaddrinfo(res0); - goto again; - } - } - } - return res0; -} - -/*ARGSUSED*/ -static struct addrinfo * -_files_getaddrinfo(const char *name, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo *p; - FILE *hostf; - - hostf = fopen(_PATH_HOSTS, "r"); - if (hostf == NULL) - return NULL; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - while ((p = _gethtent(name, pai, hostf)) != NULL) { - cur->ai_next = p; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - fclose(hostf); - - return sentinel.ai_next; -} - -#ifdef YP -static char *__ypdomain; - -/*ARGSUSED*/ -static struct addrinfo * -_yphostent(char *line, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo hints, *res, *res0; - int error; - char *p = line; - const char *addr, *canonname; - char *nextline; - char *cp; - - addr = canonname = NULL; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - -nextline: - /* terminate line */ - cp = strchr(p, '\n'); - if (cp) { - *cp++ = '\0'; - nextline = cp; - } else - nextline = NULL; - - cp = strpbrk(p, " \t"); - if (cp == NULL) { - if (canonname == NULL) - return (NULL); - else - goto done; - } - *cp++ = '\0'; - - addr = p; - - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (!canonname) - canonname = cp; - if ((cp = strpbrk(cp, " \t")) != NULL) - *cp++ = '\0'; - } - - hints = *pai; - hints.ai_flags = AI_NUMERICHOST; - error = getaddrinfo(addr, NULL, &hints, &res0); - if (error == 0) { - for (res = res0; res; res = res->ai_next) { - /* cover it up */ - res->ai_flags = pai->ai_flags; - - if (pai->ai_flags & AI_CANONNAME) - (void)get_canonname(pai, res, canonname); - } - } else - res0 = NULL; - if (res0) { - cur->ai_next = res0; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - - if (nextline) { - p = nextline; - goto nextline; - } - -done: - return sentinel.ai_next; -} - -/*ARGSUSED*/ -static struct addrinfo * -_yp_getaddrinfo(const char *name, const struct addrinfo *pai) -{ - struct addrinfo sentinel, *cur; - struct addrinfo *ai = NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return NULL; - } - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - - /* hosts.byname is only for IPv4 (Solaris8) */ - if (pai->ai_family == PF_UNSPEC || pai->ai_family == PF_INET) { - r = yp_match(__ypdomain, "hosts.byname", name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) { - struct addrinfo ai4; - - ai4 = *pai; - ai4.ai_family = AF_INET; - ai = _yphostent(__ypcurrent, &ai4); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - } - } - - /* ipnodes.byname can hold both IPv4/v6 */ - r = yp_match(__ypdomain, "ipnodes.byname", name, - (int)strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) { - ai = _yphostent(__ypcurrent, pai); - if (ai) { - cur->ai_next = ai; - while (cur && cur->ai_next) - cur = cur->ai_next; - } - } - - return sentinel.ai_next; -} -#endif - - -/* resolver logic */ - -extern const char *__hostalias(const char *); -extern int h_errno; -extern int res_opt(int, u_char *, int, int); - -/* - * Formulate a normal query, send, and await answer. - * Returned answer is placed in supplied buffer "answer". - * Perform preliminary check of answer, returning success only - * if no error is indicated and the answer count is nonzero. - * Return the size of the response on success, -1 on error. - * Error number is left in h_errno. - * - * Caller must parse answer and determine whether it answers the question. - */ -static int -res_queryN(const char *name, struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - u_char *buf; - HEADER *hp; - int n; - struct res_target *t; - int rcode; - int ancount; - - buf = malloc(MAXPACKET); - if (buf == NULL) { - h_errno = NETDB_INTERNAL; - return (-1); - } - - rcode = NOERROR; - ancount = 0; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - free(buf); - return (-1); - } - - for (t = target; t; t = t->next) { - int class, type; - u_char *answer; - int anslen; - - hp = (HEADER *)(void *)t->answer; - hp->rcode = NOERROR; /* default */ - - /* make it easier... */ - class = t->qclass; - type = t->qtype; - answer = t->answer; - anslen = t->anslen; -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query(%s, %d, %d)\n", name, class, type); -#endif - - n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL, - buf, MAXPACKET); - if (n > 0 && (_resp->options & RES_USE_EDNS0) != 0) - n = res_opt(n, buf, MAXPACKET, anslen); - if (n <= 0) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query: mkquery failed\n"); -#endif - h_errno = NO_RECOVERY; - free(buf); - return (n); - } - n = res_send(buf, n, answer, anslen); -#if 0 - if (n < 0) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_query: send error\n"); -#endif - h_errno = TRY_AGAIN; - free(buf); - return (n); - } -#endif - - if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) { - rcode = hp->rcode; /* record most recent error */ -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; rcode = %u, ancount=%u\n", hp->rcode, - ntohs(hp->ancount)); -#endif - continue; - } - - ancount += ntohs(hp->ancount); - - t->n = n; - } - - if (ancount == 0) { - switch (rcode) { - case NXDOMAIN: - h_errno = HOST_NOT_FOUND; - break; - case SERVFAIL: - h_errno = TRY_AGAIN; - break; - case NOERROR: - h_errno = NO_DATA; - break; - case FORMERR: - case NOTIMP: - case REFUSED: - default: - h_errno = NO_RECOVERY; - break; - } - free(buf); - return (-1); - } - free(buf); - return (ancount); -} - -/* - * Formulate a normal query, send, and retrieve answer in supplied buffer. - * Return the size of the response on success, -1 on error. - * If enabled, implement search rules until answer or unrecoverable failure - * is detected. Error code, if any, is left in h_errno. - */ -static int -res_searchN(const char *name, struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const char *cp, * const *domain; - HEADER *hp = (HEADER *)(void *)target->answer; /*XXX*/ - u_int dots; - int trailing_dot, ret, saved_herrno; - int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } - - errno = 0; - h_errno = HOST_NOT_FOUND; /* default, if we never query */ - dots = 0; - for (cp = name; *cp; cp++) - dots += (*cp == '.'); - trailing_dot = 0; - if (cp > name && *--cp == '.') - trailing_dot++; - - /* - * if there aren't any dots, it could be a user-level alias - */ - if (!dots && (cp = __hostalias(name)) != NULL) - return (res_queryN(cp, target)); - - /* - * If there are dots in the name already, let's just give it a try - * 'as is'. The threshold can be set with the "ndots" option. - */ - saved_herrno = -1; - if (dots >= _resp->ndots) { - ret = res_querydomainN(name, NULL, target); - if (ret > 0) - return (ret); - saved_herrno = h_errno; - tried_as_is++; - } - - /* - * We do at least one level of search if - * - there is no dot and RES_DEFNAME is set, or - * - there is at least one dot, there is no trailing dot, - * and RES_DNSRCH is set. - */ - if ((!dots && (_resp->options & RES_DEFNAMES)) || - (dots && !trailing_dot && (_resp->options & RES_DNSRCH))) { - int done = 0; - - for (domain = (const char * const *)_resp->dnsrch; - *domain && !done; - domain++) { - - ret = res_querydomainN(name, *domain, target); - if (ret > 0) - return (ret); - - /* - * If no server present, give up. - * If name isn't found in this domain, - * keep trying higher domains in the search list - * (if that's enabled). - * On a NO_DATA error, keep trying, otherwise - * a wildcard entry of another type could keep us - * from finding this entry higher in the domain. - * If we get some other error (negative answer or - * server failure), then stop searching up, - * but try the input name below in case it's - * fully-qualified. - */ - if (errno == ECONNREFUSED) { - h_errno = TRY_AGAIN; - return (-1); - } - - switch (h_errno) { - case NO_DATA: - got_nodata++; - /* FALLTHROUGH */ - case HOST_NOT_FOUND: - /* keep trying */ - break; - case TRY_AGAIN: - if (hp->rcode == SERVFAIL) { - /* try next search element, if any */ - got_servfail++; - break; - } - /* FALLTHROUGH */ - default: - /* anything else implies that we're done */ - done++; - } - /* - * if we got here for some reason other than DNSRCH, - * we only wanted one iteration of the loop, so stop. - */ - if (!(_resp->options & RES_DNSRCH)) - done++; - } - } - - /* - * if we have not already tried the name "as is", do that now. - * note that we do this regardless of how many dots were in the - * name or whether it ends with a dot. - */ - if (!tried_as_is) { - ret = res_querydomainN(name, NULL, target); - if (ret > 0) - return (ret); - } - - /* - * if we got here, we didn't satisfy the search. - * if we did an initial full query, return that query's h_errno - * (note that we wouldn't be here if that query had succeeded). - * else if we ever got a nodata, send that back as the reason. - * else send back meaningless h_errno, that being the one from - * the last DNSRCH we did. - */ - if (saved_herrno != -1) - h_errno = saved_herrno; - else if (got_nodata) - h_errno = NO_DATA; - else if (got_servfail) - h_errno = TRY_AGAIN; - return (-1); -} - -/* - * Perform a call on res_query on the concatenation of name and domain, - * removing a trailing dot from name if domain is NULL. - */ -static int -res_querydomainN(const char *name, const char *domain, - struct res_target *target) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - char nbuf[MAXDNAME]; - const char *longname = nbuf; - size_t len; - - if (_res_init(0) == -1) { - h_errno = NETDB_INTERNAL; - return (-1); - } -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf(";; res_querydomain(%s, %s)\n", - name, domain?domain:""); -#endif - if (domain == NULL) { - /* - * Check for trailing '.'; - * copy without '.' if present. - */ - len = strlcpy(nbuf, name, sizeof(nbuf)); - if (len >= sizeof(nbuf)) { - h_errno = NO_RECOVERY; - return (-1); - } - if (len > 0 && nbuf[len - 1] == '.') - nbuf[len - 1] = '\0'; - } else { - int i; - - i = snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain); - if (i < 0 || i >= sizeof(nbuf)) { - h_errno = NO_RECOVERY; - return (-1); - } - } - return (res_queryN(longname, target)); -} diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 deleted file mode 100644 index 1a05460da4..0000000000 --- a/src/lib/libc/net/gethostbyname.3 +++ /dev/null @@ -1,297 +0,0 @@ -.\" $OpenBSD: gethostbyname.3,v 1.25 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1987, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETHOSTBYNAME 3 -.Os -.Sh NAME -.Nm gethostbyname , -.Nm gethostbyname2 , -.Nm gethostbyaddr , -.Nm gethostent , -.Nm sethostent , -.Nm endhostent , -.Nm hstrerror , -.Nm herror -.Nd get network host entry -.Sh SYNOPSIS -.Fd #include -.Vt extern int h_errno ; -.Ft struct hostent * -.Fn gethostbyname "const char *name" -.Ft struct hostent * -.Fn gethostbyname2 "const char *name" "int af" -.Ft struct hostent * -.Fn gethostbyaddr "const void *addr" "socklen_t len" "int af" -.Ft struct hostent * -.Fn gethostent void -.Ft void -.Fn sethostent "int stayopen" -.Ft void -.Fn endhostent void -.Ft void -.Fn herror "const char *string" -.Ft const char * -.Fn hstrerror "int err" -.Sh DESCRIPTION -The -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -functions each return a pointer to an object with the following structure -describing an Internet host referenced by name or by address, respectively. -This structure contains either information obtained from the name server (i.e., -.Xr resolver 3 -and -.Xr named 8 ) , -broken-out fields from a line in -.Pa /etc/hosts , -or database entries supplied by the -.Xr yp 8 -system. -.Xr resolv.conf 5 -describes how the particular database is chosen. -.Bd -literal -offset indent -struct hostent { - char *h_name; /* official name of host */ - char **h_aliases; /* alias list */ - int h_addrtype; /* host address type */ - int h_length; /* length of address */ - char **h_addr_list; /* list of returned addresses */ -}; -#define h_addr h_addr_list[0] /* address, for backward compat */ -.Ed -.Pp -The members of this structure are: -.Bl -tag -width h_addr_list -.It Fa h_name -Official name of the host. -.It Fa h_aliases -A null-terminated array of alternate names for the host. -.It Fa h_addrtype -The type of address being returned. -.It Fa h_length -The length, in bytes, of the address. -.It Fa h_addr_list -A null-terminated array of network addresses for the host. -Host addresses are returned in network byte order. -.It Fa h_addr -The first address in -.Fa h_addr_list ; -this is for backward compatibility. -.El -.Pp -The function -.Fn gethostbyname -will search for the named host in the current domain and its parents -using the search lookup semantics detailed in -.Xr resolv.conf 5 -and -.Xr hostname 7 . -.Pp -.Fn gethostbyname2 -is an advanced form of -.Fn gethostbyname -which allows lookups in address families other than -.Dv AF_INET . -Currently, the only supported address family besides -.Dv AF_INET -is -.Dv AF_INET6 . -.Pp -The -.Fn gethostbyaddr -function will search for the specified address of length -.Fa len -in the address family -.Fa af . -The only address family currently supported is -.Dv AF_INET . -.Pp -The -.Fn sethostent -function may be used to request the use of a connected -.Tn TCP -socket for queries. -If the -.Fa stayopen -flag is non-zero, -this sets the option to send all queries to the name server using -.Tn TCP -and to retain the connection after each call to -.Fn gethostbyname -or -.Fn gethostbyaddr . -Otherwise, queries are performed using -.Tn UDP -datagrams. -.Pp -The -.Fn endhostent -function closes the -.Tn TCP -connection. -.Pp -The -.Fn herror -function prints an error message describing the failure. -If its argument -.Fa string -is non-null, -it is prepended to the message string and separated from it by a colon -.Pq Ql \&: -and a space. -The error message is printed with a trailing newline. -The contents of the error message is the same as that returned by -.Fn hstrerror -with argument -.Fa h_errno . -.Sh ENVIRONMENT -.Bl -tag -width HOSTALIASES -.It HOSTALIASES -A file containing local host aliases. -See -.Xr hostname 7 -for more information. -.It RES_OPTIONS -A list of options to override the resolver's internal defaults. -See -.Xr resolver 3 -for more information. -.El -.Sh FILES -.Bl -tag -width /etc/resolv.conf -compact -.It Pa /etc/hosts -.It Pa /etc/resolv.conf -.El -.Sh DIAGNOSTICS -Error return status from -.Fn gethostbyname , -.Fn gethostbyname2 , -and -.Fn gethostbyaddr -is indicated by return of a null pointer. -The external integer -.Va h_errno -may then be checked to see whether this is a temporary failure -or an invalid or unknown host. -.Pp -The variable -.Va h_errno -can have the following values: -.Bl -tag -width HOST_NOT_FOUND -.It Dv HOST_NOT_FOUND -No such host is known. -.It Dv TRY_AGAIN -This is usually a temporary error -and means that the local server did not receive -a response from an authoritative server. -A retry at some later time may succeed. -.It Dv NO_RECOVERY -Some unexpected server failure was encountered. -This is a non-recoverable error. -.It Dv NO_DATA -The requested name is valid but does not have an IP address; -this is not a temporary error. -This means that the name is known to the name server but there is no address -associated with this name. -Another type of request to the name server using this domain name -will result in an answer; -for example, a mail-forwarder may be registered for this domain. -.It Dv NETDB_INTERNAL -An internal error occurred. -This may occur when an address family other than -.Dv AF_INET -or -.Dv AF_INET6 -is specified or when a resource is unable to be allocated. -.It Dv NETDB_SUCCESS -The function completed successfully. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr hostname 7 , -.Xr named 8 -.Sh HISTORY -The -.Fn herror -function appeared in -.Bx 4.3 . -The -.Fn endhostent , -.Fn gethostbyaddr , -.Fn gethostbyname , -.Fn gethostent , -and -.Fn sethostent -functions appeared in -.Bx 4.2 . -.Sh CAVEATS -If the search routines in -.Xr resolv.conf 5 -decide to read the -.Pa /etc/hosts -file, -.Fn gethostent -and other functions will -read the next line of the file, -re-opening the file if necessary. -.Pp -The -.Fn sethostent -function opens and/or rewinds the file -.Pa /etc/hosts . -If the -.Fa stayopen -argument is non-zero, the file will not be closed after each call to -.Fn gethostbyname , -.Fn gethostbyname2 , -or -.Fn gethostbyaddr . -.Pp -The -.Fn endhostent -function closes the file. -.Sh BUGS -These functions use static data storage; -if the data is needed for future use, it should be -copied before any subsequent calls overwrite it. -.Pp -Only the Internet -address formats are currently understood. -.Pp -YP does not support any address families other than -.Dv AF_INET -and uses -the traditional database format. diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c deleted file mode 100644 index d49b9cdd7d..0000000000 --- a/src/lib/libc/net/gethostnamadr.c +++ /dev/null @@ -1,1129 +0,0 @@ -/* $OpenBSD: gethostnamadr.c,v 1.72 2007/10/11 18:36:41 jakob Exp $ */ -/*- - * Copyright (c) 1985, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef YP -#include -#include -#include -#include "ypinternal.h" -#endif -#include "thread_private.h" - -#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ - -#define MAXALIASES 35 -#define MAXADDRS 35 - -static char *h_addr_ptrs[MAXADDRS + 1]; - -#ifdef YP -static char *__ypdomain; -#endif - -static struct hostent host; -static char *host_aliases[MAXALIASES]; -static char hostbuf[BUFSIZ+1]; -static union { - struct in_addr _host_in_addr; - u_char _host_addr[16]; /* IPv4 or IPv6 */ -} _host_addr_u; -#define host_addr _host_addr_u._host_addr -static FILE *hostf = NULL; -static int stayopen = 0; - -static void map_v4v6_address(const char *src, char *dst); -static void map_v4v6_hostent(struct hostent *hp, char **bp, char *); - -#ifdef RESOLVSORT -static void addrsort(char **, int); -#endif - -int _hokchar(const char *); - -static const char AskedForGot[] = - "gethostby*.getanswer: asked for \"%s\", got \"%s\""; - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - int32_t al; - char ac; -} align; - -static struct hostent *getanswer(const querybuf *, int, const char *, int); - -extern int h_errno; - -int -_hokchar(const char *p) -{ - char c; - - /* - * Many people do not obey RFC 822 and 1035. The valid - * characters are a-z, A-Z, 0-9, '-' and . But the others - * tested for below can happen, and we must be more permissive - * than the resolver until those idiots clean up their act. - * We let '/' through, but not '..' - */ - while ((c = *p++)) { - if (('a' <= c && c <= 'z') || - ('A' <= c && c <= 'Z') || - ('0' <= c && c <= '9')) - continue; - if (strchr("-_/", c)) - continue; - if (c == '.' && *p != '.') - continue; - return 0; - } - return 1; -} - -static struct hostent * -getanswer(const querybuf *answer, int anslen, const char *qname, int qtype) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const HEADER *hp; - const u_char *cp, *eom; - char tbuf[MAXDNAME]; - char *bp, **ap, **hap, *ep; - int type, class, ancount, qdcount, n; - int haveanswer, had_error, toobig = 0; - const char *tname; - int (*name_ok)(const char *); - - tname = qname; - host.h_name = NULL; - eom = answer->buf + anslen; - switch (qtype) { - case T_A: - case T_AAAA: -#ifdef USE_RESOLV_NAME_OK - name_ok = res_hnok; - break; -#endif - case T_PTR: -#ifdef USE_RESOLV_NAME_OK - name_ok = res_dnok; -#else - name_ok = _hokchar; -#endif - break; - default: - return (NULL); - } - /* - * find first satisfactory answer - */ - hp = &answer->hdr; - ancount = ntohs(hp->ancount); - qdcount = ntohs(hp->qdcount); - bp = hostbuf; - ep = hostbuf + sizeof hostbuf; - cp = answer->buf + HFIXEDSZ; - if (qdcount != 1) { - h_errno = NO_RECOVERY; - return (NULL); - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - h_errno = NO_RECOVERY; - return (NULL); - } - cp += n + QFIXEDSZ; - if (qtype == T_A || qtype == T_AAAA) { - /* res_send() has already verified that the query name is the - * same as the one we sent; this just gets the expanded name - * (i.e., with the succeeding search-domain tacked on). - */ - host.h_name = bp; - bp += strlen(bp) + 1; /* for the \0 */ - /* The qname can be abbreviated, but h_name is now absolute. */ - qname = host.h_name; - } - ap = host_aliases; - *ap = NULL; - host.h_aliases = host_aliases; - hap = h_addr_ptrs; - *hap = NULL; - host.h_addr_list = h_addr_ptrs; - haveanswer = 0; - had_error = 0; - while (ancount-- > 0 && cp < eom && !had_error) { - size_t len; - - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); - if ((n < 0) || !(*name_ok)(bp)) { - had_error++; - continue; - } - cp += n; /* name */ - if (cp >= eom) - break; - type = _getshort(cp); - cp += INT16SZ; /* type */ - if (cp >= eom) - break; - class = _getshort(cp); - cp += INT16SZ + INT32SZ; /* class, TTL */ - if (cp >= eom) - break; - n = _getshort(cp); - cp += INT16SZ; /* len */ - if (cp >= eom) - break; - if (type == T_SIG || type == T_RRSIG) { - /* XXX - ignore signatures as we don't use them yet */ - cp += n; - continue; - } - if (class != C_IN) { - /* XXX - debug? syslog? */ - cp += n; - continue; /* XXX - had_error++ ? */ - } - if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) { - if (ap >= &host_aliases[MAXALIASES-1]) - continue; - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if ((n < 0) || !(*name_ok)(tbuf)) { - had_error++; - continue; - } - cp += n; - /* Store alias. */ - *ap++ = bp; - bp += strlen(bp) + 1; /* for the \0 */ - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - host.h_name = bp; - bp += len; - continue; - } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(tbuf)) { -#else - if ((n < 0) || !_hokchar(tbuf)) { -#endif - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - len = strlen(tbuf) + 1; /* for the \0 */ - if (len > ep - bp) { - had_error++; - continue; - } - strlcpy(bp, tbuf, ep - bp); - tname = bp; - bp += len; - continue; - } - if (type != qtype) { - syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(C_IN), p_type(qtype), - p_type(type)); - cp += n; - continue; /* XXX - had_error++ ? */ - } - switch (type) { - case T_PTR: - if (strcasecmp(tname, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, qname, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(bp)) { -#else - if ((n < 0) || !_hokchar(bp)) { -#endif - had_error++; - break; - } -#if MULTI_PTRS_ARE_ALIASES - cp += n; - if (!haveanswer) - host.h_name = bp; - else if (ap < &host_aliases[MAXALIASES-1]) - *ap++ = bp; - else - n = -1; - if (n != -1) { - n = strlen(bp) + 1; /* for the \0 */ - bp += n; - } - break; -#else - host.h_name = bp; - if (_resp->options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - bp += n; - map_v4v6_hostent(&host, &bp, ep); - } - h_errno = NETDB_SUCCESS; - return (&host); -#endif - case T_A: - case T_AAAA: - if (strcasecmp(host.h_name, bp) != 0) { - syslog(LOG_NOTICE|LOG_AUTH, - AskedForGot, host.h_name, bp); - cp += n; - continue; /* XXX - had_error++ ? */ - } - if (n != host.h_length) { - cp += n; - continue; - } - if (type == T_AAAA) { - struct in6_addr in6; - memcpy(&in6, cp, IN6ADDRSZ); - if (IN6_IS_ADDR_V4MAPPED(&in6)) { - cp += n; - continue; - } - } - if (!haveanswer) { - host.h_name = bp; - bp += strlen(bp) + 1; /* for the \0 */ - } - - bp += sizeof(align) - ((u_long)bp % sizeof(align)); - - if (bp + n >= &hostbuf[sizeof hostbuf]) { -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("size (%d) too big\n", n); -#endif - had_error++; - continue; - } - if (hap >= &h_addr_ptrs[MAXADDRS-1]) { - if (!toobig++) -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("Too many addresses (%d)\n", MAXADDRS); -#endif - cp += n; - continue; - } - bcopy(cp, *hap++ = bp, n); - bp += n; - cp += n; - break; - } - if (!had_error) - haveanswer++; - } - if (haveanswer) { - *ap = NULL; - *hap = NULL; -# if defined(RESOLVSORT) - /* - * Note: we sort even if host can take only one address - * in its return structures - should give it the "best" - * address in that case, not some random one - */ - if (_resp->nsort && haveanswer > 1 && qtype == T_A) - addrsort(h_addr_ptrs, haveanswer); -# endif /*RESOLVSORT*/ - if (!host.h_name) { - size_t len; - - len = strlen(qname) + 1; - if (len > ep - bp) /* for the \0 */ - goto try_again; - strlcpy(bp, qname, ep - bp); - host.h_name = bp; - bp += len; - } - if (_resp->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return (&host); - } - try_again: - h_errno = TRY_AGAIN; - return (NULL); -} - -#ifdef notyet -/* - * XXX This is an extremely bogus implementation. - * - * FreeBSD has this interface: - * int gethostbyaddr_r(const char *addr, int len, int type, - * struct hostent *result, struct hostent_data *buffer) - */ - -struct hostent * -gethostbyname_r(const char *name, struct hostent *hp, char *buf, int buflen, - int *errorp) -{ - struct hostent *res; - - res = gethostbyname(name); - *errorp = h_errno; - if (res == NULL) - return NULL; - memcpy(hp, res, sizeof *hp); /* XXX not sufficient */ - return hp; -} - -/* - * XXX This is an extremely bogus implementation. - */ -struct hostent * -gethostbyaddr_r(const char *addr, int len, int af, struct hostent *he, - char *buf, int buflen, int *errorp) -{ - struct hostent * res; - - res = gethostbyaddr(addr, len, af); - *errorp = h_errno; - if (res == NULL) - return NULL; - memcpy(he, res, sizeof *he); /* XXX not sufficient */ - return he; -} - -/* XXX RFC2133 expects a gethostbyname2_r() -- unimplemented */ -#endif - -struct hostent * -gethostbyname(const char *name) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - struct hostent *hp; - extern struct hostent *_gethtbyname2(const char *, int); - - if (_res_init(0) == -1) - hp = _gethtbyname2(name, AF_INET); - - else if (_resp->options & RES_USE_INET6) { - hp = gethostbyname2(name, AF_INET6); - if (hp == NULL) - hp = gethostbyname2(name, AF_INET); - } - else - hp = gethostbyname2(name, AF_INET); - return hp; -} - -struct hostent * -gethostbyname2(const char *name, int af) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - querybuf *buf; - const char *cp; - char *bp, *ep; - int n, size, type, i; - struct hostent *hp; - char lookups[MAXDNSLUS]; - extern struct hostent *_gethtbyname2(const char *, int); -#ifdef YP - extern struct hostent *_yp_gethtbyname(const char *); -#endif - - if (_res_init(0) == -1) - return (_gethtbyname2(name, af)); - - switch (af) { - case AF_INET: - size = INADDRSZ; - type = T_A; - break; - case AF_INET6: - size = IN6ADDRSZ; - type = T_AAAA; - break; - default: - h_errno = NETDB_INTERNAL; - errno = EAFNOSUPPORT; - return (NULL); - } - - host.h_addrtype = af; - host.h_length = size; - - /* - * if there aren't any dots, it could be a user-level alias. - * this is also done in res_query() since we are not the only - * function that looks up host names. - */ - if (!strchr(name, '.') && (cp = __hostalias(name))) - name = cp; - - /* - * disallow names consisting only of digits/dots, unless - * they end in a dot. - */ - if (isdigit(name[0])) - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-numeric, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strlcpy(hostbuf, name, MAXHOSTNAMELEN); - bp = hostbuf + MAXHOSTNAMELEN; - ep = hostbuf + sizeof(hostbuf); - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - if (_resp->options & RES_USE_INET6) - map_v4v6_hostent(&host, &bp, ep); - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isdigit(*cp) && *cp != '.') - break; - } - if ((isxdigit(name[0]) && strchr(name, ':') != NULL) || - name[0] == ':') - for (cp = name;; ++cp) { - if (!*cp) { - if (*--cp == '.') - break; - /* - * All-IPv6-legal, no dot at the end. - * Fake up a hostent as if we'd actually - * done a lookup. - */ - if (inet_pton(af, name, host_addr) <= 0) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - strlcpy(hostbuf, name, MAXHOSTNAMELEN); - bp = hostbuf + MAXHOSTNAMELEN; - ep = hostbuf + sizeof(hostbuf); - host.h_name = hostbuf; - host.h_aliases = host_aliases; - host_aliases[0] = NULL; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - h_errno = NETDB_SUCCESS; - return (&host); - } - if (!isxdigit(*cp) && *cp != ':' && *cp != '.') - break; - } - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - hp = (struct hostent *)NULL; - for (i = 0; i < MAXDNSLUS && hp == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* YP only supports AF_INET. */ - if (af == AF_INET) - hp = _yp_gethtbyname(name); - break; -#endif - case 'b': - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - if ((n = res_search(name, C_IN, type, buf->buf, - sizeof(buf->buf))) < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_search failed\n"); -#endif - break; - } - hp = getanswer(buf, n, name, type); - free(buf); - break; - case 'f': - hp = _gethtbyname2(name, af); - break; - } - } - /* XXX h_errno not correct in all cases... */ - return (hp); -} - -struct hostent * -gethostbyaddr(const void *addr, socklen_t len, int af) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - const u_char *uaddr = (const u_char *)addr; - int n, size, i; - querybuf *buf; - struct hostent *hp; - char qbuf[MAXDNAME+1], *qp, *ep; - char lookups[MAXDNSLUS]; - struct hostent *res; - extern struct hostent *_gethtbyaddr(const void *, socklen_t, int); -#ifdef YP - extern struct hostent *_yp_gethtbyaddr(const void *); -#endif - - if (_res_init(0) == -1) { - res = _gethtbyaddr(addr, len, af); - return (res); - } - - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)uaddr) || - IN6_IS_ADDR_SITELOCAL((struct in6_addr *)uaddr))) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)uaddr) || - IN6_IS_ADDR_V4COMPAT((struct in6_addr *)uaddr))) { - /* Unmap. */ - uaddr += IN6ADDRSZ - INADDRSZ; - af = AF_INET; - len = INADDRSZ; - } - switch (af) { - case AF_INET: - size = INADDRSZ; - break; - case AF_INET6: - size = IN6ADDRSZ; - break; - default: - errno = EAFNOSUPPORT; - h_errno = NETDB_INTERNAL; - return (NULL); - } - if (size != len) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return (NULL); - } - ep = qbuf + sizeof(qbuf); - switch (af) { - case AF_INET: - (void) snprintf(qbuf, sizeof qbuf, "%u.%u.%u.%u.in-addr.arpa", - (uaddr[3] & 0xff), (uaddr[2] & 0xff), - (uaddr[1] & 0xff), (uaddr[0] & 0xff)); - break; - case AF_INET6: - qp = qbuf; - for (n = IN6ADDRSZ - 1; n >= 0; n--) { - i = snprintf(qp, ep - qp, "%x.%x.", - uaddr[n] & 0xf, (uaddr[n] >> 4) & 0xf); - if (i <= 0 || i >= ep - qp) { - errno = EINVAL; - h_errno = NETDB_INTERNAL; - return (NULL); - } - qp += i; - } - strlcpy(qp, "ip6.arpa", ep - qp); - break; - } - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - hp = (struct hostent *)NULL; - for (i = 0; i < MAXDNSLUS && hp == NULL && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* YP only supports AF_INET. */ - if (af == AF_INET) - hp = _yp_gethtbyaddr(uaddr); - break; -#endif - case 'b': - buf = malloc(sizeof(*buf)); - if (!buf) - break; - n = res_query(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (n < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - if (!(hp = getanswer(buf, n, qbuf, T_PTR))) { - free(buf); - break; - } - free(buf); - hp->h_addrtype = af; - hp->h_length = len; - bcopy(uaddr, host_addr, len); - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - if (af == AF_INET && (_resp->options & RES_USE_INET6)) { - map_v4v6_address((char*)host_addr, - (char*)host_addr); - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - } - h_errno = NETDB_SUCCESS; - break; - case 'f': - hp = _gethtbyaddr(uaddr, len, af); - break; - } - } - /* XXX h_errno not correct in all cases... */ - return (hp); -} - -void -_sethtent(int f) -{ - if (hostf == NULL) - hostf = fopen(_PATH_HOSTS, "r" ); - else - rewind(hostf); - stayopen = f; -} - -void -_endhtent(void) -{ - if (hostf && !stayopen) { - (void) fclose(hostf); - hostf = NULL; - } -} - -static struct hostent * -_gethtent(void) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - char *p, *cp, **q; - int af; - size_t len; - - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - again: - if ((p = fgetln(hostf, &len)) == NULL) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - if (p[len-1] == '\n') - len--; - if (len >= sizeof(hostbuf) || len == 0) - goto again; - p = memcpy(hostbuf, p, len); - hostbuf[len] = '\0'; - if (*p == '#') - goto again; - if ((cp = strchr(p, '#'))) - *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) - goto again; - *cp++ = '\0'; - if (inet_pton(AF_INET6, p, host_addr) > 0) { - af = AF_INET6; - len = IN6ADDRSZ; - } else if (inet_pton(AF_INET, p, host_addr) > 0) { - if (_resp->options & RES_USE_INET6) { - map_v4v6_address((char*)host_addr, (char*)host_addr); - af = AF_INET6; - len = IN6ADDRSZ; - } else { - af = AF_INET; - len = INADDRSZ; - } - } else { - goto again; - } - /* if this is not something we're looking for, skip it. */ - if (host.h_addrtype != AF_UNSPEC && host.h_addrtype != af) - goto again; - if (host.h_length != 0 && host.h_length != len) - goto again; - h_addr_ptrs[0] = (char *)host_addr; - h_addr_ptrs[1] = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = len; - host.h_addrtype = af; - while (*cp == ' ' || *cp == '\t') - cp++; - host.h_name = cp; - q = host.h_aliases = host_aliases; - if ((cp = strpbrk(cp, " \t"))) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - if ((cp = strpbrk(cp, " \t"))) - *cp++ = '\0'; - } - *q = NULL; - if (_resp->options & RES_USE_INET6) { - char *bp = hostbuf; - char *ep = hostbuf + sizeof hostbuf; - - map_v4v6_hostent(&host, &bp, ep); - } - h_errno = NETDB_SUCCESS; - return (&host); -} - -struct hostent * -_gethtbyname2(const char *name, int af) -{ - struct hostent *p; - char **cp; - - _sethtent(0); - while ((p = _gethtent())) { - if (p->h_addrtype != af) - continue; - if (strcasecmp(p->h_name, name) == 0) - break; - for (cp = p->h_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } - found: - _endhtent(); - return (p); -} - -struct hostent * -_gethtbyaddr(const void *addr, socklen_t len, int af) -{ - struct hostent *p; - - host.h_length = len; - host.h_addrtype = af; - - _sethtent(0); - while ((p = _gethtent())) - if (p->h_addrtype == af && p->h_length == len && - !bcmp(p->h_addr, addr, len)) - break; - _endhtent(); - return (p); -} - -#ifdef YP -struct hostent * -_yphostent(char *line) -{ - static struct in_addr host_addrs[MAXADDRS]; - char *p = line; - char *cp, **q; - char **hap; - struct in_addr *buf; - int more; - - host.h_name = NULL; - host.h_addr_list = h_addr_ptrs; - host.h_length = INADDRSZ; - host.h_addrtype = AF_INET; - hap = h_addr_ptrs; - buf = host_addrs; - q = host.h_aliases = host_aliases; - -nextline: - /* check for host_addrs overflow */ - if (buf >= &host_addrs[sizeof(host_addrs) / sizeof(host_addrs[0])]) - goto done; - - more = 0; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto done; - *cp++ = '\0'; - - *hap++ = (char *)buf; - (void) inet_aton(p, buf++); - - while (*cp == ' ' || *cp == '\t') - cp++; - p = cp; - cp = strpbrk(p, " \t\n"); - if (cp != NULL) { - if (*cp == '\n') - more = 1; - *cp++ = '\0'; - } - if (!host.h_name) - host.h_name = p; - else if (strcmp(host.h_name, p)==0) - ; - else if (q < &host_aliases[MAXALIASES - 1]) - *q++ = p; - p = cp; - if (more) - goto nextline; - - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (*cp == '\n') { - cp++; - goto nextline; - } - if (q < &host_aliases[MAXALIASES - 1]) - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } -done: - if (host.h_name == NULL) - return (NULL); - *q = NULL; - *hap = NULL; - return (&host); -} - -struct hostent * -_yp_gethtbyaddr(const void *addr) -{ - struct hostent *hp = NULL; - const u_char *uaddr = (const u_char *)addr; - static char *__ypcurrent; - int __ypcurrentlen, r; - char name[sizeof("xxx.xxx.xxx.xxx")]; - - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return (hp); - } - snprintf(name, sizeof name, "%u.%u.%u.%u", (uaddr[0] & 0xff), - (uaddr[1] & 0xff), (uaddr[2] & 0xff), (uaddr[3] & 0xff)); - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - r = yp_match(__ypdomain, "hosts.byaddr", name, - strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r==0) - hp = _yphostent(__ypcurrent); - if (hp==NULL) - h_errno = HOST_NOT_FOUND; - return (hp); -} - -struct hostent * -_yp_gethtbyname(const char *name) -{ - struct hostent *hp = (struct hostent *)NULL; - static char *__ypcurrent; - int __ypcurrentlen, r; - - if (strlen(name) >= MAXHOSTNAMELEN) - return (NULL); - if (!__ypdomain) { - if (_yp_check(&__ypdomain) == 0) - return (hp); - } - if (__ypcurrent) - free(__ypcurrent); - __ypcurrent = NULL; - r = yp_match(__ypdomain, "hosts.byname", name, - strlen(name), &__ypcurrent, &__ypcurrentlen); - if (r == 0) - hp = _yphostent(__ypcurrent); - if (hp == NULL) - h_errno = HOST_NOT_FOUND; - return (hp); -} -#endif - -static void -map_v4v6_address(const char *src, char *dst) -{ - u_char *p = (u_char *)dst; - char tmp[INADDRSZ]; - int i; - - /* Stash a temporary copy so our caller can update in place. */ - bcopy(src, tmp, INADDRSZ); - /* Mark this ipv6 addr as a mapped ipv4. */ - for (i = 0; i < 10; i++) - *p++ = 0x00; - *p++ = 0xff; - *p++ = 0xff; - /* Retrieve the saved copy and we're done. */ - bcopy(tmp, (void*)p, INADDRSZ); -} - -static void -map_v4v6_hostent(struct hostent *hp, char **bpp, char *ep) -{ - char **ap; - - if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ) - return; - hp->h_addrtype = AF_INET6; - hp->h_length = IN6ADDRSZ; - for (ap = hp->h_addr_list; *ap; ap++) { - int i = sizeof(align) - ((u_long)*bpp % sizeof(align)); - - if (ep - *bpp < (i + IN6ADDRSZ)) { - /* Out of memory. Truncate address list here. XXX */ - *ap = NULL; - return; - } - *bpp += i; - map_v4v6_address(*ap, *bpp); - *ap = *bpp; - *bpp += IN6ADDRSZ; - } -} - -struct hostent * -gethostent(void) -{ - host.h_addrtype = AF_UNSPEC; - host.h_length = 0; - return (_gethtent()); -} - -#ifdef RESOLVSORT -static void -addrsort(char **ap, int num) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _resp->nsort; j++) - if (_resp->sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & - _resp->sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - } else - break; - } - needsort++; - } -} -#endif diff --git a/src/lib/libc/net/getifaddrs.3 b/src/lib/libc/net/getifaddrs.3 deleted file mode 100644 index f282e26960..0000000000 --- a/src/lib/libc/net/getifaddrs.3 +++ /dev/null @@ -1,157 +0,0 @@ -.\" $OpenBSD: getifaddrs.3,v 1.14 2007/05/31 19:19:30 jmc Exp $ -.\" BSDI getifaddrs.3,v 2.5 2000/02/23 14:51:59 dab Exp -.\" -.\" Copyright (c) 1995, 1999 -.\" Berkeley Software Design, Inc. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.Dd $Mdocdate: May 31 2007 $ -.Dt GETIFADDRS 3 -.Os -.Sh NAME -.Nm getifaddrs -.Nd get interface addresses -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getifaddrs "struct ifaddrs **ifap" -.Ft void -.Fn freeifaddrs "struct ifaddrs *ifap" -.Sh DESCRIPTION -The -.Fn getifaddrs -function stores a reference to a linked list of the network interfaces -on the local machine in the memory referenced by -.Fa ifap . -The list consists of -.Nm ifaddrs -structures, as defined in the include file -.Aq Pa ifaddrs.h . -The -.Nm ifaddrs -structure contains at least the following entries: -.Bd -literal - struct ifaddrs *ifa_next; /* Pointer to next struct */ - char *ifa_name; /* Interface name */ - u_int ifa_flags; /* Interface flags */ - struct sockaddr *ifa_addr; /* Interface address */ - struct sockaddr *ifa_netmask; /* Interface netmask */ - struct sockaddr *ifa_broadaddr; /* Interface broadcast address */ - struct sockaddr *ifa_dstaddr; /* P2P interface destination */ - void *ifa_data; /* Address specific data */ -.Ed -.Bl -tag -width ifa_broadaddr -.It Fa ifa_next -Contains a pointer to the next structure on the list. -This field is set to -.Dv NULL -in the last structure on the list. -.It Fa ifa_name -Contains the interface name. -.It Fa ifa_flags -Contains the interface flags, as set by -.Xr ifconfig 8 . -.It Fa ifa_addr -References either the address of the interface or the link level -address of the interface, if one exists, otherwise it is -.Dv NULL . -(The -.Fa sa_family -field of the -.Fa ifa_addr -field should be consulted to determine the format of the -.Fa ifa_addr -address.) -.It Fa ifa_netmask -References the netmask associated with -.Fa ifa_addr , -if one is set, otherwise it is -.Dv NULL . -.It Fa ifa_broadaddr -This field, which should only be referenced for non-P2P interfaces, -references the broadcast address associated with -.Fa ifa_addr , -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_dstaddr -References the destination address on a P2P interface, -if one exists, otherwise it is -.Dv NULL . -.It Fa ifa_data -References address family specific data. -For -.Dv AF_LINK -addresses it contains a pointer to the -.Li struct if_data -(as defined in include file -.Aq Pa net/if.h ) -which contains various interface attributes and statistics. -For all other address families, -.Fa ifa_data -is -.Dv NULL . -.El -.Pp -The data returned by -.Fn getifaddrs -is dynamically allocated and should be freed using -.Fn freeifaddrs -when no longer needed. -.Sh RETURN VALUES -Upon successful completion, a value of 0 is returned. -Otherwise, a value of \-1 is returned and -.Va errno -is set to indicate the error. -.Sh ERRORS -The -.Fn getifaddrs -may fail and set -.Va errno -for any of the errors specified for the library routines -.Xr ioctl 2 , -.Xr socket 2 , -.Xr malloc 3 , -or -.Xr sysctl 3 . -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr socket 2 , -.Xr sysctl 3 , -.Xr networking 4 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn getifaddrs -function first appeared in BSDI BSD/OS. -The function has been available on -.Ox -since -.Ox 2.7 . -.Sh BUGS -If both -.Aq Pa net/if.h -and -.Aq Pa ifaddrs.h -are being included, -.Aq Pa net/if.h -.Em must -be included before -.Aq Pa ifaddrs.h . diff --git a/src/lib/libc/net/getifaddrs.c b/src/lib/libc/net/getifaddrs.c deleted file mode 100644 index 0db89f6c19..0000000000 --- a/src/lib/libc/net/getifaddrs.c +++ /dev/null @@ -1,277 +0,0 @@ -/* $OpenBSD: getifaddrs.c,v 1.9 2002/08/09 06:12:25 itojun Exp $ */ - -/* - * Copyright (c) 1995, 1999 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define SALIGN (sizeof(long) - 1) -#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1)) - -int -getifaddrs(struct ifaddrs **pif) -{ - int icnt = 1; - int dcnt = 0; - int ncnt = 0; - int mib[6]; - size_t needed; - char *buf; - char *next; - struct ifaddrs *cif = 0; - char *p, *p0; - struct rt_msghdr *rtm; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct sockaddr_dl *dl; - struct sockaddr *sa; - u_short index = 0; - size_t len, alen; - struct ifaddrs *ifa, *ift; - int i; - char *data; - char *names; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* wildcard address family */ - mib[4] = NET_RT_IFLIST; - mib[5] = 0; /* no flags */ - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - return (-1); - if ((buf = malloc(needed)) == NULL) - return (-1); - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - free(buf); - return (-1); - } - - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - ++icnt; - dl = (struct sockaddr_dl *)(ifm + 1); - dcnt += SA_RLEN((struct sockaddr *)dl) + - ALIGNBYTES; - dcnt += sizeof(ifm->ifm_data); - ncnt += dl->sdl_nlen + 1; - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - -#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD) - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - p = (char *)(ifam + 1); - ++icnt; - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_NETMASK && sa->sa_len == 0) - dcnt += alen; - else - dcnt += len; - p += len; - } - break; - } - } - - if (icnt + dcnt + ncnt == 1) { - *pif = NULL; - free(buf); - return (0); - } - data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); - if (data == NULL) { - free(buf); - return(-1); - } - - ifa = (struct ifaddrs *)data; - data += sizeof(struct ifaddrs) * icnt; - names = data + dcnt; - - memset(ifa, 0, sizeof(struct ifaddrs) * icnt); - ift = ifa; - - index = 0; - for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - if (rtm->rtm_version != RTM_VERSION) - continue; - switch (rtm->rtm_type) { - case RTM_IFINFO: - ifm = (struct if_msghdr *)rtm; - if (ifm->ifm_addrs & RTA_IFP) { - index = ifm->ifm_index; - dl = (struct sockaddr_dl *)(ifm + 1); - - cif = ift; - ift->ifa_name = names; - ift->ifa_flags = (int)ifm->ifm_flags; - memcpy(names, dl->sdl_data, dl->sdl_nlen); - names[dl->sdl_nlen] = 0; - names += dl->sdl_nlen + 1; - - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, dl, - ((struct sockaddr *)dl)->sa_len); - data += SA_RLEN((struct sockaddr *)dl); - - /* ifm_data needs to be aligned */ - ift->ifa_data = data = (void *)ALIGN(data); - memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data)); - data += sizeof(ifm->ifm_data); - - ift = (ift->ifa_next = ift + 1); - } else - index = 0; - break; - - case RTM_NEWADDR: - ifam = (struct ifa_msghdr *)rtm; - if (index && ifam->ifam_index != index) - abort(); /* XXX abort illegal in library */ - - if (index == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0) - break; - ift->ifa_name = cif->ifa_name; - ift->ifa_flags = cif->ifa_flags; - ift->ifa_data = NULL; - p = (char *)(ifam + 1); - /* Scan to look for length of address */ - alen = 0; - for (p0 = p, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - if (i == RTAX_IFA) { - alen = len; - break; - } - p += len; - } - for (p = p0, i = 0; i < RTAX_MAX; i++) { - if ((RTA_MASKS & ifam->ifam_addrs & (1 << i)) - == 0) - continue; - sa = (struct sockaddr *)p; - len = SA_RLEN(sa); - switch (i) { - case RTAX_IFA: - ift->ifa_addr = (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - - case RTAX_NETMASK: - ift->ifa_netmask = - (struct sockaddr *)data; - if (sa->sa_len == 0) { - memset(data, 0, alen); - data += alen; - break; - } - memcpy(data, p, len); - data += len; - break; - - case RTAX_BRD: - ift->ifa_broadaddr = - (struct sockaddr *)data; - memcpy(data, p, len); - data += len; - break; - } - p += len; - } - - - ift = (ift->ifa_next = ift + 1); - break; - } - } - - free(buf); - if (--ift >= ifa) { - ift->ifa_next = NULL; - *pif = ifa; - } else { - *pif = NULL; - free(ifa); - } - return (0); -} - -void -freeifaddrs(struct ifaddrs *ifp) -{ - free(ifp); -} diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 deleted file mode 100644 index 9b7e591149..0000000000 --- a/src/lib/libc/net/getnameinfo.3 +++ /dev/null @@ -1,266 +0,0 @@ -.\" $OpenBSD: getnameinfo.3,v 1.40 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: getnameinfo.3,v 1.37 2005/01/05 03:23:05 itojun Exp $ -.\" -.\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -.\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -.\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -.\" PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETNAMEINFO 3 -.Os -.Sh NAME -.Nm getnameinfo -.Nd socket address structure to hostname and service name -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft int -.Fn getnameinfo "const struct sockaddr *sa" "socklen_t salen" "char *host" \ - "size_t hostlen" "char *serv" "size_t servlen" "int flags" -.Sh DESCRIPTION -The -.Fn getnameinfo -function is used to convert a -.Li sockaddr -structure to a pair of host name and service strings. -It is a replacement for and provides more flexibility than the -.Xr gethostbyaddr 3 -and -.Xr getservbyport 3 -functions and is the converse of the -.Xr getaddrinfo 3 -function. -.Pp -The -.Li sockaddr -structure -.Fa sa -should point to either a -.Li sockaddr_in -or -.Li sockaddr_in6 -structure (for IPv4 or IPv6 respectively) that is -.Fa salen -bytes long. -.Pp -The host and service names associated with -.Fa sa -are stored in -.Fa host -and -.Fa serv -which have length parameters -.Fa hostlen -and -.Fa servlen . -The maximum value for -.Fa hostlen -is -.Dv NI_MAXHOST -and -the maximum value for -.Fa servlen -is -.Dv NI_MAXSERV , -as defined by -.Aq Pa netdb.h . -If a length parameter is zero, no string will be stored. -Otherwise, enough space must be provided to store the -host name or service string plus a byte for the NUL terminator. -.Pp -The -.Fa flags -argument is formed by -.Tn OR Ns 'ing -the following values: -.Bl -tag -width "NI_NUMERICHOSTXX" -.It Dv NI_NOFQDN -A fully qualified domain name is not required for local hosts. -The local part of the fully qualified domain name is returned instead. -.It Dv NI_NUMERICHOST -Return the address in numeric form, as if calling -.Xr inet_ntop 3 , -instead of a host name. -.It Dv NI_NAMEREQD -A name is required. -If the host name cannot be found in DNS and this flag is set, -a non-zero error code is returned. -If the host name is not found and the flag is not set, the -address is returned in numeric form. -.It NI_NUMERICSERV -The service name is returned as a digit string representing the port number. -.It NI_DGRAM -Specifies that the service being looked up is a datagram -service, and causes -.Xr getservbyport 3 -to be called with a second argument of -.Dq udp -instead of its default of -.Dq tcp . -This is required for the few ports (512\-514) that have different services -for -.Tn UDP -and -.Tn TCP . -.El -.Pp -This implementation allows numeric IPv6 address notation with scope identifier, -as documented in chapter 11 of draft-ietf-ipv6-scoping-arch-02.txt. -IPv6 link-local address will appear as a string like -.Dq Li fe80::1%ne0 . -Refer to -.Xr getaddrinfo 3 -for more information. -.Sh RETURN VALUES -.Fn getnameinfo -returns zero on success or one of the error codes listed in -.Xr gai_strerror 3 -if an error occurs. -.Sh EXAMPLES -The following code tries to get a numeric host name, and service name, -for a given socket address. -Observe that there is no hardcoded reference to a particular address family. -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, - sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) - errx(1, "could not get numeric hostname"); -printf("host=%s, serv=%s\en", hbuf, sbuf); -.Ed -.Pp -The following version checks if the socket address has a reverse address mapping: -.Bd -literal -offset indent -struct sockaddr *sa; /* input */ -char hbuf[NI_MAXHOST]; - -if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, - NI_NAMEREQD)) - errx(1, "could not resolve hostname"); -printf("host=%s\en", hbuf); -.Ed -.Sh SEE ALSO -.Xr gai_strerror 3 , -.Xr getaddrinfo 3 , -.Xr gethostbyaddr 3 , -.Xr getservbyport 3 , -.Xr inet_ntop 3 , -.Xr resolver 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 , -.Xr named 8 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 2553 -.%D March 1999 -.Re -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%T "IPv6 Scoped Address Architecture" -.%R internet draft -.%N draft-ietf-ipv6-scoping-arch-02.txt -.%O work in progress material -.Re -.Rs -.%A Craig Metz -.%T Protocol Independence Using the Sockets API -.%B "Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference" -.%D June 2000 -.Re -.Sh STANDARDS -The -.Fn getnameinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in -.Tn "RFC 2553" , -.Dq Basic Socket Interface Extensions for IPv6 . -.Sh CAVEATS -.Fn getnameinfo -can return both numeric and FQDN forms of the address specified in -.Fa sa . -There is no return value that indicates whether the string returned in -.Fa host -is a result of binary to numeric-text translation (like -.Xr inet_ntop 3 ) , -or is the result of a DNS reverse lookup. -Because of this, malicious parties could set up a PTR record as follows: -.Bd -literal -offset indent -1.0.0.127.in-addr.arpa. IN PTR 10.1.1.1 -.Ed -.Pp -and trick the caller of -.Fn getnameinfo -into believing that -.Fa sa -is -.Li 10.1.1.1 -when it is actually -.Li 127.0.0.1 . -.Pp -To prevent such attacks, the use of -.Dv NI_NAMEREQD -is recommended when the result of -.Fn getnameinfo -is used -for access control purposes: -.Bd -literal -offset indent -struct sockaddr *sa; -socklen_t salen; -char addr[NI_MAXHOST]; -struct addrinfo hints, *res; -int error; - -error = getnameinfo(sa, salen, addr, sizeof(addr), - NULL, 0, NI_NAMEREQD); -if (error == 0) { - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(addr, "0", &hints, &res) == 0) { - /* malicious PTR record */ - freeaddrinfo(res); - printf("bogus PTR record\en"); - return -1; - } - /* addr is FQDN as a result of PTR lookup */ -} else { - /* addr is numeric string */ - error = getnameinfo(sa, salen, addr, sizeof(addr), - NULL, 0, NI_NUMERICHOST); -} -.Ed -.Sh BUGS -The implementation of -.Fn getnameinfo -is not thread-safe. -.Pp -.Ox -intentionally uses a different -.Dv NI_MAXHOST -value from what -.Tn "RFC 2553" -suggests, to avoid buffer length handling mistakes. diff --git a/src/lib/libc/net/getnameinfo.c b/src/lib/libc/net/getnameinfo.c deleted file mode 100644 index 7041a4ee48..0000000000 --- a/src/lib/libc/net/getnameinfo.c +++ /dev/null @@ -1,351 +0,0 @@ -/* $OpenBSD: getnameinfo.c,v 1.33 2007/02/15 04:25:35 ray Exp $ */ -/* $KAME: getnameinfo.c,v 1.45 2000/09/25 22:43:56 itojun Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Issues to be discussed: - * - Thread safe-ness must be checked - * - RFC2553 says that we should raise error on short buffer. X/Open says - * we need to truncate the result. We obey RFC2553 (and X/Open should be - * modified). ipngwg rough consensus seems to follow RFC2553. - * - What is "local" in NI_FQDN? - * - NI_NAMEREQD and NI_NUMERICHOST conflict with each other. - * - (KAME extension) always attach textual scopeid (fe80::1%lo0), if - * sin6_scope_id is filled - standardization status? - * XXX breaks backward compat for code that expects no scopeid. - * beware on merge. - */ - -#ifndef INET6 -#define INET6 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -static const struct afd { - int a_af; - int a_addrlen; - int a_socklen; - int a_off; -} afdl [] = { -#ifdef INET6 - {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6), - offsetof(struct sockaddr_in6, sin6_addr)}, -#endif - {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in), - offsetof(struct sockaddr_in, sin_addr)}, - {0, 0, 0}, -}; - -struct sockinet { - u_char si_len; - u_char si_family; - u_short si_port; -}; - -#ifdef INET6 -static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, - size_t, int); -static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); -#endif - -void *__THREAD_NAME(serv_mutex); - -int -getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags) -{ - const struct afd *afd; - struct hostent *hp; - u_short port; - int family, i; - const char *addr; - u_int32_t v4a; - char numserv[512]; - char numaddr[512]; - - if (sa == NULL) - return EAI_FAIL; - - family = sa->sa_family; - for (i = 0; afdl[i].a_af; i++) - if (afdl[i].a_af == family) { - afd = &afdl[i]; - goto found; - } - return EAI_FAMILY; - - found: - if (salen != afd->a_socklen) - return EAI_FAIL; - - /* network byte order */ - port = ((const struct sockinet *)sa)->si_port; - addr = (const char *)sa + afd->a_off; - - if (serv == NULL || servlen == 0) { - /* - * do nothing in this case. - * in case you are wondering if "&&" is more correct than - * "||" here: rfc2553bis-03 says that serv == NULL OR - * servlen == 0 means that the caller does not want the result. - */ - } else if (!(flags & NI_NUMERICSERV)) { - struct servent sp; - struct servent_data sd; - - (void)memset(&sd, 0, sizeof(sd)); - if (getservbyport_r(port, - (flags & NI_DGRAM) ? "udp" : "tcp", &sp, &sd) == -1) - goto numeric; - - if (strlen(sp.s_name) + 1 > servlen) { - endservent_r(&sd); - return EAI_MEMORY; - } - strlcpy(serv, sp.s_name, servlen); - endservent_r(&sd); - } else { - numeric: - i = snprintf(numserv, sizeof(numserv), "%u", ntohs(port)); - if (i < 0 || i >= servlen || i >= sizeof(numserv)) - return EAI_MEMORY; - strlcpy(serv, numserv, servlen); - } - - switch (sa->sa_family) { - case AF_INET: - v4a = (u_int32_t) - ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr); - if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) - flags |= NI_NUMERICHOST; - v4a >>= IN_CLASSA_NSHIFT; - if (v4a == 0) - flags |= NI_NUMERICHOST; - break; -#ifdef INET6 - case AF_INET6: - { - const struct sockaddr_in6 *sin6; - sin6 = (const struct sockaddr_in6 *)sa; - switch (sin6->sin6_addr.s6_addr[0]) { - case 0x00: - if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) - ; - else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)) - ; - else - flags |= NI_NUMERICHOST; - break; - default: - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { - flags |= NI_NUMERICHOST; - } - else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) - flags |= NI_NUMERICHOST; - break; - } - } - break; -#endif - } - if (host == NULL || hostlen == 0) { - /* - * do nothing in this case. - * in case you are wondering if "&&" is more correct than - * "||" here: rfc2553bis-03 says that host == NULL or - * hostlen == 0 means that the caller does not want the result. - */ - } else if (flags & NI_NUMERICHOST) { - int numaddrlen; - - /* NUMERICHOST and NAMEREQD conflicts with each other */ - if (flags & NI_NAMEREQD) - return EAI_NONAME; - - switch(afd->a_af) { -#ifdef INET6 - case AF_INET6: - { - int error; - - if ((error = ip6_parsenumeric(sa, addr, host, - hostlen, flags)) != 0) - return(error); - break; - } -#endif - default: - if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) - == NULL) - return EAI_SYSTEM; - numaddrlen = strlen(numaddr); - if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return EAI_MEMORY; - strlcpy(host, numaddr, hostlen); - break; - } - } else { - _THREAD_PRIVATE_MUTEX_LOCK(serv_mutex); - hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af); - _THREAD_PRIVATE_MUTEX_UNLOCK(serv_mutex); - - if (hp) { -#if 0 - /* - * commented out, since "for local host" is not - * implemented here - see RFC2553 p30 - */ - if (flags & NI_NOFQDN) { - char *p; - p = strchr(hp->h_name, '.'); - if (p) - *p = '\0'; - } -#endif - if (strlen(hp->h_name) + 1 > hostlen) { - return EAI_MEMORY; - } - strlcpy(host, hp->h_name, hostlen); - } else { - if (flags & NI_NAMEREQD) - return EAI_NONAME; - switch(afd->a_af) { -#ifdef INET6 - case AF_INET6: - { - int error; - - if ((error = ip6_parsenumeric(sa, addr, host, - hostlen, - flags)) != 0) - return(error); - break; - } -#endif - default: - if (inet_ntop(afd->a_af, addr, host, - hostlen) == NULL) - return EAI_SYSTEM; - break; - } - } - } - return(0); -} - -#ifdef INET6 -static int -ip6_parsenumeric(const struct sockaddr *sa, const char *addr, char *host, - size_t hostlen, int flags) -{ - int numaddrlen; - char numaddr[512]; - - if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL) - return EAI_SYSTEM; - - numaddrlen = strlen(numaddr); - if (numaddrlen + 1 > hostlen) /* don't forget terminator */ - return EAI_MEMORY; - strlcpy(host, numaddr, hostlen); - - if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) { - char zonebuf[MAXHOSTNAMELEN]; - int zonelen; - - zonelen = ip6_sa2str( - (const struct sockaddr_in6 *)(const void *)sa, - zonebuf, sizeof(zonebuf), flags); - if (zonelen < 0) - return EAI_MEMORY; - if (zonelen + 1 + numaddrlen + 1 > hostlen) - return EAI_MEMORY; - - /* construct */ - memcpy(host + numaddrlen + 1, zonebuf, - (size_t)zonelen); - host[numaddrlen] = SCOPE_DELIMITER; - host[numaddrlen + 1 + zonelen] = '\0'; - } - - return 0; -} - -/* ARGSUSED */ -static int -ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) -{ - unsigned int ifindex; - const struct in6_addr *a6; - int n; - - ifindex = (unsigned int)sa6->sin6_scope_id; - a6 = &sa6->sin6_addr; - -#ifdef notdef - if ((flags & NI_NUMERICSCOPE) != 0) { - n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id); - if (n < 0 || n >= bufsiz) - return -1; - else - return n; - } -#endif - - /* if_indextoname() does not take buffer size. not a good api... */ - if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6) || - IN6_IS_ADDR_MC_INTFACELOCAL(a6)) && bufsiz >= IF_NAMESIZE) { - char *p = if_indextoname(ifindex, buf); - if (p) { - return(strlen(p)); - } - } - - /* last resort */ - n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id); - if (n < 0 || n >= bufsiz) - return -1; - else - return n; -} -#endif /* INET6 */ diff --git a/src/lib/libc/net/getnetbyaddr.c b/src/lib/libc/net/getnetbyaddr.c deleted file mode 100644 index a85106630c..0000000000 --- a/src/lib/libc/net/getnetbyaddr.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: getnetbyaddr.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -extern int _net_stayopen; - -struct netent * -_getnetbyaddr(in_addr_t net, int type) -{ - struct netent *p; - - setnetent(_net_stayopen); - while ((p = getnetent())) - if (p->n_addrtype == type && p->n_net == net) - break; - if (!_net_stayopen) - endnetent(); - return (p); -} diff --git a/src/lib/libc/net/getnetbyname.c b/src/lib/libc/net/getnetbyname.c deleted file mode 100644 index e6540cf12c..0000000000 --- a/src/lib/libc/net/getnetbyname.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: getnetbyname.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -extern int _net_stayopen; - -struct netent * -_getnetbyname(const char *name) -{ - struct netent *p; - char **cp; - - setnetent(_net_stayopen); - while ((p = getnetent())) { - if (strcasecmp(p->n_name, name) == 0) - break; - for (cp = p->n_aliases; *cp != 0; cp++) - if (strcasecmp(*cp, name) == 0) - goto found; - } -found: - if (!_net_stayopen) - endnetent(); - return (p); -} diff --git a/src/lib/libc/net/getnetent.3 b/src/lib/libc/net/getnetent.3 deleted file mode 100644 index 00fd543ec4..0000000000 --- a/src/lib/libc/net/getnetent.3 +++ /dev/null @@ -1,140 +0,0 @@ -.\" $OpenBSD: getnetent.3,v 1.15 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETNETENT 3 -.Os -.Sh NAME -.Nm getnetent , -.Nm getnetbyaddr , -.Nm getnetbyname , -.Nm setnetent , -.Nm endnetent -.Nd get network entry -.Sh SYNOPSIS -.Fd #include -.Ft struct netent * -.Fn getnetent "void" -.Ft struct netent * -.Fn getnetbyname "const char *name" -.Ft struct netent * -.Fn getnetbyaddr "in_addr_t net" "int type" -.Ft void -.Fn setnetent "int stayopen" -.Ft void -.Fn endnetent "void" -.Sh DESCRIPTION -The -.Fn getnetent , -.Fn getnetbyname , -and -.Fn getnetbyaddr -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network database, -.Pa /etc/networks . -.Bd -literal -offset indent -struct netent { - char *n_name; /* official name of net */ - char **n_aliases; /* alias list */ - int n_addrtype; /* net number type */ - in_addr_t n_net; /* net number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width n_addrtype -.It Fa n_name -The official name of the network. -.It Fa n_aliases -A null-terminated list of alternate names for the network. -.It Fa n_addrtype -The type of the network number returned; currently only -.Dv AF_INET . -.It Fa n_net -The network number. -Network numbers are returned in machine byte order. -.El -.Pp -The -.Fn getnetent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setnetent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the net database will not be closed after each call to -.Fn getnetbyname -or -.Fn getnetbyaddr . -.Pp -The -.Fn endnetent -function closes the file. -.Pp -The -.Fn getnetbyname -and -.Fn getnetbyaddr -functions search the domain name server if the system is configured to use one. -If the search fails, or no name server is configured, they sequentially -search from the beginning of the file until a matching net name or -net address and type is found, or until -.Dv EOF -is encountered. -Network numbers are supplied in host order. -.Sh FILES -.Bl -tag -width /etc/networks -compact -.It Pa /etc/networks -.El -.Sh DIAGNOSTICS -Null pointer (0) returned on -.Dv EOF -or error. -.Sh SEE ALSO -.Xr resolver 3 , -.Xr networks 5 -.Sh HISTORY -The -.Fn getnetent , -.Fn getnetbyaddr , -.Fn getnetbyname , -.Fn setnetent , -and -.Fn endnetent -functions appeared in -.Bx 4.2 . -.Sh BUGS -The data space used by these functions is static; if future use -requires the data, it should be copied before any subsequent calls -to these functions overwrite it. -Only Internet network numbers are currently understood. -Expecting network numbers to fit in no more than 32 bits is naive. diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c deleted file mode 100644 index 1bec6fb98c..0000000000 --- a/src/lib/libc/net/getnetent.c +++ /dev/null @@ -1,121 +0,0 @@ -/* $OpenBSD: getnetent.c,v 1.12 2006/01/17 15:37:58 millert Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include - -#define MAXALIASES 35 - -static FILE *netf; -static char line[BUFSIZ+1]; -static struct netent net; -static char *net_aliases[MAXALIASES]; -int _net_stayopen; - -void -setnetent(int f) -{ - if (netf == NULL) - netf = fopen(_PATH_NETWORKS, "r" ); - else - rewind(netf); - _net_stayopen |= f; -} - -void -endnetent(void) -{ - if (netf) { - fclose(netf); - netf = NULL; - } - _net_stayopen = 0; -} - -struct netent * -getnetent(void) -{ - char *p, *cp, **q; - size_t len; - - if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) - return (NULL); -again: - if ((p = fgetln(netf, &len)) == NULL) - return (NULL); - if (p[len-1] == '\n') - len--; - if (len >= sizeof(line) || len == 0) - goto again; - p = memcpy(line, p, len); - line[len] = '\0'; - if (*p == '#') - goto again; - if ((cp = strchr(p, '#')) != NULL) - *cp = '\0'; - net.n_name = p; - if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) - net.n_name[MAXHOSTNAMELEN-1] = '\0'; - cp = strpbrk(p, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - net.n_net = inet_network(cp); - net.n_addrtype = AF_INET; - q = net.n_aliases = net_aliases; - if (p != NULL) - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &net_aliases[MAXALIASES - 1]) { - *q++ = cp; - if (strlen(cp) >= MAXHOSTNAMELEN-1) - cp[MAXHOSTNAMELEN-1] = '\0'; - } - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (&net); -} diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c deleted file mode 100644 index 7b770f1ce7..0000000000 --- a/src/lib/libc/net/getnetnamadr.c +++ /dev/null @@ -1,384 +0,0 @@ -/* $OpenBSD: getnetnamadr.c,v 1.26 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1997, Jason Downs. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -extern int h_errno; - -struct netent *_getnetbyaddr(in_addr_t net, int type); -struct netent *_getnetbyname(const char *name); - -int _hokchar(const char *); - -#define BYADDR 0 -#define BYNAME 1 -#define MAXALIASES 35 - -#define MAXPACKET (64*1024) - -typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; -} querybuf; - -typedef union { - long al; - char ac; -} align; - -static struct netent * -getnetanswer(querybuf *answer, int anslen, int net_i) -{ - - HEADER *hp; - u_char *cp; - int n; - u_char *eom; - int type, class, ancount, qdcount, haveanswer, i, nchar; - char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN]; - char *in, *st, *pauxt, *bp, **ap, *ep; - char *paux1 = &aux1[0], *paux2 = &aux2[0]; - static struct netent net_entry; - static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; - - /* - * find first satisfactory answer - * - * answer --> +------------+ ( MESSAGE ) - * | Header | - * +------------+ - * | Question | the question for the name server - * +------------+ - * | Answer | RRs answering the question - * +------------+ - * | Authority | RRs pointing toward an authority - * | Additional | RRs holding additional information - * +------------+ - */ - eom = answer->buf + anslen; - hp = &answer->hdr; - ancount = ntohs(hp->ancount); /* #/records in the answer section */ - qdcount = ntohs(hp->qdcount); /* #/entries in the question section */ - bp = netbuf; - ep = netbuf + sizeof(netbuf); - cp = answer->buf + HFIXEDSZ; - if (!qdcount) { - if (hp->aa) - h_errno = HOST_NOT_FOUND; - else - h_errno = TRY_AGAIN; - return (NULL); - } - while (qdcount-- > 0) { - n = __dn_skipname(cp, eom); - if (n < 0 || (cp + n + QFIXEDSZ) > eom) { - h_errno = NO_RECOVERY; - return(NULL); - } - cp += n + QFIXEDSZ; - } - ap = net_aliases; - *ap = NULL; - net_entry.n_aliases = net_aliases; - haveanswer = 0; - while (--ancount >= 0 && cp < eom) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_dnok(bp)) -#else - if ((n < 0) || !_hokchar(bp)) -#endif - break; - cp += n; - ans[0] = '\0'; - strlcpy(&ans[0], bp, sizeof ans); - GETSHORT(type, cp); - GETSHORT(class, cp); - cp += INT32SZ; /* TTL */ - GETSHORT(n, cp); - if (class == C_IN && type == T_PTR) { - n = dn_expand(answer->buf, eom, cp, bp, ep - bp); -#ifdef USE_RESOLV_NAME_OK - if ((n < 0) || !res_hnok(bp)) -#else - if ((n < 0) || !_hokchar(bp)) -#endif - { - cp += n; - return (NULL); - } - cp += n; - if ((ap + 2) < &net_aliases[MAXALIASES]) { - *ap++ = bp; - bp += strlen(bp) + 1; - net_entry.n_addrtype = - (class == C_IN) ? AF_INET : AF_UNSPEC; - haveanswer++; - } - } - } - if (haveanswer) { - *ap = NULL; - switch (net_i) { - case BYADDR: - net_entry.n_name = *net_entry.n_aliases; - net_entry.n_net = 0L; - break; - case BYNAME: - ap = net_entry.n_aliases; - next_alias: - in = *ap++; - if (in == NULL) { - h_errno = HOST_NOT_FOUND; - return (NULL); - } - net_entry.n_name = ans; - aux2[0] = '\0'; - for (i = 0; i < 4; i++) { - for (st = in, nchar = 0; - isdigit((unsigned char)*st); - st++, nchar++) - ; - if (*st != '.' || nchar == 0 || nchar > 3) - goto next_alias; - if (i != 0) - nchar++; - strlcpy(paux1, in, nchar+1); - strlcat(paux1, paux2, MAXHOSTNAMELEN); - pauxt = paux2; - paux2 = paux1; - paux1 = pauxt; - in = ++st; - } - if (strcasecmp(in, "IN-ADDR.ARPA") != 0) - goto next_alias; - net_entry.n_net = inet_network(paux2); - break; - } - net_entry.n_aliases++; - return (&net_entry); - } - h_errno = TRY_AGAIN; - return (NULL); -} - -struct netent * -getnetbyaddr(in_addr_t net, int net_type) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - unsigned int netbr[4]; - int nn, anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - in_addr_t net2; - struct netent *net_entry = NULL; - char lookups[MAXDNSLUS]; - int i; - - if (_res_init(0) == -1) - return(_getnetbyaddr(net, net_type)); - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* There is no YP support. */ - break; -#endif /* YP */ - case 'b': - if (net_type != AF_INET) - break; /* DNS only supports AF_INET? */ - - for (nn = 4, net2 = net; net2; net2 >>= 8) - netbr[--nn] = net2 & 0xff; - switch (nn) { - case 3: /* Class A */ - snprintf(qbuf, sizeof(qbuf), - "0.0.0.%u.in-addr.arpa", netbr[3]); - break; - case 2: /* Class B */ - snprintf(qbuf, sizeof(qbuf), - "0.0.%u.%u.in-addr.arpa", - netbr[3], netbr[2]); - break; - case 1: /* Class C */ - snprintf(qbuf, sizeof(qbuf), - "0.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1]); - break; - case 0: /* Class D - E */ - snprintf(qbuf, sizeof(qbuf), - "%u.%u.%u.%u.in-addr.arpa", - netbr[3], netbr[2], netbr[1], netbr[0]); - break; - } - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - anslen = res_query(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - net_entry = getnetanswer(buf, anslen, BYADDR); - free(buf); - if (net_entry != NULL) { - unsigned u_net = net; /* maybe net should be unsigned ? */ - - /* Strip trailing zeros */ - while ((u_net & 0xff) == 0 && u_net != 0) - u_net >>= 8; - net_entry->n_net = u_net; - return (net_entry); - } - break; - case 'f': - net_entry = _getnetbyaddr(net, net_type); - if (net_entry != NULL) - return (net_entry); - } - } - - /* Nothing matched. */ - return (NULL); -} - -struct netent * -getnetbyname(const char *net) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int anslen; - querybuf *buf; - char qbuf[MAXDNAME]; - struct netent *net_entry = NULL; - char lookups[MAXDNSLUS]; - int i; - - if (_res_init(0) == -1) - return (_getnetbyname(net)); - - bcopy(_resp->lookups, lookups, sizeof lookups); - if (lookups[0] == '\0') - strlcpy(lookups, "bf", sizeof lookups); - - for (i = 0; i < MAXDNSLUS && lookups[i]; i++) { - switch (lookups[i]) { -#ifdef YP - case 'y': - /* There is no YP support. */ - break; -#endif /* YP */ - case 'b': - strlcpy(qbuf, net, sizeof qbuf); - buf = malloc(sizeof(*buf)); - if (buf == NULL) - break; - anslen = res_search(qbuf, C_IN, T_PTR, buf->buf, - sizeof(buf->buf)); - if (anslen < 0) { - free(buf); -#ifdef DEBUG - if (_resp->options & RES_DEBUG) - printf("res_query failed\n"); -#endif - break; - } - net_entry = getnetanswer(buf, anslen, BYNAME); - free(buf); - if (net_entry != NULL) - return (net_entry); - break; - case 'f': - net_entry = _getnetbyname(net); - if (net_entry != NULL) - return (net_entry); - break; - } - } - - /* Nothing matched. */ - return (NULL); -} diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c deleted file mode 100644 index 07fa33288d..0000000000 --- a/src/lib/libc/net/getproto.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: getproto.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -int -getprotobynumber_r(int num, struct protoent *pe, struct protoent_data *pd) -{ - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) - if (pe->p_proto == num) - break; - if (!pd->stayopen && pd->fp != NULL) { - (void)fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} - -struct protoent * -getprotobynumber(int num) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobynumber_r(num, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoent.3 b/src/lib/libc/net/getprotoent.3 deleted file mode 100644 index df4cd0c323..0000000000 --- a/src/lib/libc/net/getprotoent.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: getprotoent.3,v 1.17 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETPROTOENT 3 -.Os -.Sh NAME -.Nm getprotoent , -.Nm getprotoent_r , -.Nm getprotobynumber , -.Nm getprotobynumber_r , -.Nm getprotobyname , -.Nm getprotobyname_r , -.Nm setprotoent , -.Nm setprotoent_r , -.Nm endprotoent , -.Nm endprotoent_r -.Nd get protocol entry -.Sh SYNOPSIS -.Fd #include -.Ft struct protoent * -.Fn getprotoent "void" -.Ft int -.Fn getprotoent_r "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobyname "const char *name" -.Ft int -.Fn getprotobyname_r "const char *name" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft struct protoent * -.Fn getprotobynumber "int proto" -.Ft int -.Fn getprotobynumber_r "int proto" "struct protoent *protoent" "struct protoent_data *protoent_data" -.Ft void -.Fn setprotoent "int stayopen" -.Ft void -.Fn setprotoent_r "int stayopen" "struct protoent_data *protoent_data" -.Ft void -.Fn endprotoent "void" -.Ft void -.Fn endprotoent_r "struct protoent_data *protoent_data" -.Sh DESCRIPTION -The -.Fn getprotoent , -.Fn getprotobyname , -and -.Fn getprotobynumber -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network protocol database, -.Pa /etc/protocols . -.Bd -literal -offset indent -.Pp -struct protoent { - char *p_name; /* official name of protocol */ - char **p_aliases; /* alias list */ - int p_proto; /* protocol number */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width p_aliases -.It Fa p_name -The official name of the protocol. -.It Fa p_aliases -A null-terminated list of alternate names for the protocol. -.It Fa p_proto -The protocol number. -.El -.Pp -The -.Fn getprotoent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setprotoent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the protocol database will not be closed after each call to -.Fn getprotobyname -or -.Fn getprotobynumber . -.Pp -The -.Fn endprotoent -function closes the file. -.Pp -The -.Fn getprotobyname -and -.Fn getprotobynumber -functions sequentially search from the beginning of the file until a -matching protocol name or protocol number is found, or until -.Dv EOF -is encountered. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Vt protoent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions -also take a pointer to a -.Vt protoent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getprotoent , -.Fn getprotobyport , -and -.Fn getprotobyname -functions return a pointer to a -.Vt protoent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -and -.Fn getprotobyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/protocols -compact -.It Pa /etc/protocols -.El -.Sh SEE ALSO -.Xr protocols 5 -.Sh STANDARDS -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getprotoent , -.Fn getprotobynumber , -.Fn getprotobyname , -.Fn setprotoent , -and -.Fn endprotoent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getprotoent_r , -.Fn getprotobyport_r , -.Fn getprotobyname_r , -.Fn setprotoent_r , -and -.Fn endprotoent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use a static data space; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Only the Internet protocols are currently understood. diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c deleted file mode 100644 index f0705e0765..0000000000 --- a/src/lib/libc/net/getprotoent.c +++ /dev/null @@ -1,166 +0,0 @@ -/* $OpenBSD: getprotoent.c,v 1.10 2007/09/02 15:19:17 deraadt Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setprotoent_r(int f, struct protoent_data *pd) -{ - if (pd->fp == NULL) - pd->fp = fopen(_PATH_PROTOCOLS, "r" ); - else - rewind(pd->fp); - pd->stayopen |= f; -} - -void -endprotoent_r(struct protoent_data *pd) -{ - if (pd->fp) { - fclose(pd->fp); - pd->fp = NULL; - } - free(pd->aliases); - pd->aliases = NULL; - pd->maxaliases = 0; - free(pd->line); - pd->line = NULL; - pd->stayopen = 0; -} - -int -getprotoent_r(struct protoent *pe, struct protoent_data *pd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (pd->fp == NULL && (pd->fp = fopen(_PATH_PROTOCOLS, "r" )) == NULL) - return (-1); -again: - if ((p = fgetln(pd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(pd->line, len + 1); - if (cp == NULL) - return (-1); - pd->line = pe->p_name = memcpy(cp, p, len); - cp[len] = '\0'; - cp = strpbrk(cp, " \t"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - l = strtol(cp, &endp, 10); - if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) - goto again; - pe->p_proto = l; - if (pd->aliases == NULL) { - pd->maxaliases = 5; - pd->aliases = calloc(pd->maxaliases, sizeof(char *)); - if (pd->aliases == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - } - q = pe->p_aliases = pd->aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &pe->p_aliases[pd->maxaliases - 1]) { - p = realloc(pe->p_aliases, - 2 * pd->maxaliases * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endprotoent_r(pd); - errno = serrno; - return (-1); - } - pd->maxaliases *= 2; - q = (char **)p + (q - pe->p_aliases); - pe->p_aliases = pd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - } - *q = NULL; - return (0); -} - -struct protoent_data _protoent_data; /* shared with getproto{,name}.c */ - -void -setprotoent(int f) -{ - setprotoent_r(f, &_protoent_data); -} - -void -endprotoent(void) -{ - endprotoent_r(&_protoent_data); -} - -struct protoent * -getprotoent(void) -{ - static struct protoent proto; - - if (getprotoent_r(&proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getprotoname.c b/src/lib/libc/net/getprotoname.c deleted file mode 100644 index 749b6b3f13..0000000000 --- a/src/lib/libc/net/getprotoname.c +++ /dev/null @@ -1,67 +0,0 @@ -/* $OpenBSD: getprotoname.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getprotobyname_r(const char *name, struct protoent *pe, - struct protoent_data *pd) -{ - char **cp; - int error; - - setprotoent_r(pd->stayopen, pd); - while ((error = getprotoent_r(pe, pd)) == 0) { - if (strcmp(pe->p_name, name) == 0) - break; - for (cp = pe->p_aliases; *cp != 0; cp++) - if (strcmp(*cp, name) == 0) - goto found; - } -found: - if (!pd->stayopen && pd->fp != NULL) { - fclose(pd->fp); - pd->fp = NULL; - } - return (error); -} - -struct protoent * -getprotobyname(const char *name) -{ - extern struct protoent_data _protoent_data; - static struct protoent proto; - - if (getprotobyname_r(name, &proto, &_protoent_data) != 0) - return (NULL); - return (&proto); -} diff --git a/src/lib/libc/net/getrrsetbyname.3 b/src/lib/libc/net/getrrsetbyname.3 deleted file mode 100644 index 121cb67fcc..0000000000 --- a/src/lib/libc/net/getrrsetbyname.3 +++ /dev/null @@ -1,166 +0,0 @@ -.\" $OpenBSD: getrrsetbyname.3,v 1.15 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (C) 2000, 2001 Internet Software Consortium. -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM -.\" DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL -.\" INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, -.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING -.\" FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -.\" NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION -.\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETRRSETBYNAME 3 -.Os -.Sh NAME -.Nm freerrset , -.Nm getrrsetbyname -.Nd retrieve DNS records -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn getrrsetbyname "const char *hostname" "unsigned int rdclass" \ -"unsigned int rdtype" "unsigned int flags" "struct rrsetinfo **res" -.Ft void -.Fn freerrset "struct rrsetinfo *rrset" -.Sh DESCRIPTION -.Fn getrrsetbyname -gets a set of resource records associated with a -.Fa hostname , -.Fa rdclass , -and -.Fa rdtype . -.Fa hostname -is a pointer to a NUL-terminated string. -The -.Fa flags -field is currently unused and must be zero. -.Pp -After a successful call to -.Fn getrrsetbyname , -.Fa *res -is a pointer to an -.Li rrsetinfo -structure, containing a list of one or more -.Li rdatainfo -structures containing resource records and potentially another list of -.Li rdatainfo -structures containing SIG resource records associated with those records. -The members -.Li rri_rdclass -and -.Li rri_rdtype -are copied from the parameters. -.Li rri_ttl -and -.Li rri_name -are properties of the obtained rrset. -The resource records contained in -.Li rri_rdatas -and -.Li rri_sigs -are in uncompressed DNS wire format. -Properties of the rdataset are represented in the -.Li rri_flags -bitfield. -If the -.Dv RRSET_VALIDATED -bit is set, the data has been DNSSEC -validated and the signatures verified. -.Pp -The following structures are used: -.Bd -literal -offset indent -struct rdatainfo { - unsigned int rdi_length; /* length of data */ - unsigned char *rdi_data; /* record data */ -}; - -struct rrsetinfo { - unsigned int rri_flags; /* RRSET_VALIDATED ... */ - unsigned int rri_rdclass; /* class number */ - unsigned int rri_rdtype; /* RR type number */ - unsigned int rri_ttl; /* time to live */ - unsigned int rri_nrdatas; /* size of rdatas array */ - unsigned int rri_nsigs; /* size of sigs array */ - char *rri_name; /* canonical name */ - struct rdatainfo *rri_rdatas; /* individual records */ - struct rdatainfo *rri_sigs; /* individual signatures */ -}; -.Ed -.Pp -All of the information returned by -.Fn getrrsetbyname -is dynamically allocated: the -.Li rrsetinfo -and -.Li rdatainfo -structures, -and the canonical host name strings pointed to by the -.Li rrsetinfo -structure. -Memory allocated for the dynamically allocated structures created by -a successful call to -.Fn getrrsetbyname -is released by -.Fn freerrset . -.Li rrset -is a pointer to a -.Li struct rrsetinfo -created by a call to -.Fn getrrsetbyname . -.Pp -If the EDNS0 option is activated in -.Xr resolv.conf 5 , -.Fn getrrsetbyname -will request DNSSEC authentication using the EDNS0 DNSSEC OK (DO) bit. -.Sh RETURN VALUES -.Fn getrrsetbyname -returns zero on success, and one of the following error -codes if an error occurred: -.Pp -.Bl -tag -width ERRSET_NOMEMORY -.It Bq Er ERRSET_NONAME -The name does not exist. -.It Bq Er ERRSET_NODATA -The name exists, but does not have data of the desired type. -.It Bq Er ERRSET_NOMEMORY -Memory could not be allocated. -.It Bq Er ERRSET_INVAL -A parameter is invalid. -.It Bq Er ERRSET_FAIL -Other failure. -.El -.Sh SEE ALSO -.Xr resolver 3 , -.Xr resolv.conf 5 , -.Xr named 8 -.Sh HISTORY -.Fn getrrsetbyname -first appeared in -.Ox 3.0 . -The API first appeared in ISC BIND version 9. -.Sh AUTHORS -.An Jakob Schlyter Aq jakob@openbsd.org -.Sh CAVEATS -The -.Dv RRSET_VALIDATED -flag in -.Li rri_flags -is set if the AD (authenticated data) bit in the DNS answer is -set. -This flag -.Em should not -be trusted unless the transport between the nameserver and the resolver -is secure (e.g. IPsec, trusted network, loopback communication). -.Sh BUGS -The data in -.Li *rdi_data -should be returned in uncompressed wire format. -Currently, the data is in compressed format and the caller can't -uncompress since it doesn't have the full message. diff --git a/src/lib/libc/net/getrrsetbyname.c b/src/lib/libc/net/getrrsetbyname.c deleted file mode 100644 index 89aa592ba0..0000000000 --- a/src/lib/libc/net/getrrsetbyname.c +++ /dev/null @@ -1,514 +0,0 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.11 2007/10/11 18:36:41 jakob Exp $ */ - -/* - * Copyright (c) 2001 Jakob Schlyter. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Portions Copyright (c) 1999-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "thread_private.h" - -#define ANSWER_BUFFER_SIZE 1024*64 - -struct dns_query { - char *name; - u_int16_t type; - u_int16_t class; - struct dns_query *next; -}; - -struct dns_rr { - char *name; - u_int16_t type; - u_int16_t class; - u_int16_t ttl; - u_int16_t size; - void *rdata; - struct dns_rr *next; -}; - -struct dns_response { - HEADER header; - struct dns_query *query; - struct dns_rr *answer; - struct dns_rr *authority; - struct dns_rr *additional; -}; - -static struct dns_response *parse_dns_response(const u_char *, int); -static struct dns_query *parse_dns_qsection(const u_char *, int, - const u_char **, int); -static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **, - int); - -static void free_dns_query(struct dns_query *); -static void free_dns_rr(struct dns_rr *); -static void free_dns_response(struct dns_response *); - -static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t); - -int -getrrsetbyname(const char *hostname, unsigned int rdclass, - unsigned int rdtype, unsigned int flags, - struct rrsetinfo **res) -{ - struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - int result; - struct rrsetinfo *rrset = NULL; - struct dns_response *response = NULL; - struct dns_rr *rr; - struct rdatainfo *rdata; - int length; - unsigned int index_ans, index_sig; - u_char answer[ANSWER_BUFFER_SIZE]; - - /* check for invalid class and type */ - if (rdclass > 0xffff || rdtype > 0xffff) { - result = ERRSET_INVAL; - goto fail; - } - - /* don't allow queries of class or type ANY */ - if (rdclass == 0xff || rdtype == 0xff) { - result = ERRSET_INVAL; - goto fail; - } - - /* don't allow flags yet, unimplemented */ - if (flags) { - result = ERRSET_INVAL; - goto fail; - } - - /* initialize resolver */ - if (_res_init(0) == -1) { - result = ERRSET_FAIL; - goto fail; - } - -#ifdef DEBUG - _resp->options |= RES_DEBUG; -#endif /* DEBUG */ - -#ifdef RES_USE_DNSSEC - /* turn on DNSSEC if EDNS0 is configured */ - if (_resp->options & RES_USE_EDNS0) - _resp->options |= RES_USE_DNSSEC; -#endif /* RES_USE_DNSEC */ - - /* make query */ - length = res_query(hostname, (signed int) rdclass, (signed int) rdtype, - answer, sizeof(answer)); - if (length < 0) { - switch(h_errno) { - case HOST_NOT_FOUND: - result = ERRSET_NONAME; - goto fail; - case NO_DATA: - result = ERRSET_NODATA; - goto fail; - default: - result = ERRSET_FAIL; - goto fail; - } - } - - /* parse result */ - response = parse_dns_response(answer, length); - if (response == NULL) { - result = ERRSET_FAIL; - goto fail; - } - - if (response->header.qdcount != 1) { - result = ERRSET_FAIL; - goto fail; - } - - /* initialize rrset */ - rrset = calloc(1, sizeof(struct rrsetinfo)); - if (rrset == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - rrset->rri_rdclass = response->query->class; - rrset->rri_rdtype = response->query->type; - rrset->rri_ttl = response->answer->ttl; - rrset->rri_nrdatas = response->header.ancount; - - /* check for authenticated data */ - if (response->header.ad == 1) - rrset->rri_flags |= RRSET_VALIDATED; - - /* copy name from answer section */ - rrset->rri_name = strdup(response->answer->name); - if (rrset->rri_name == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* count answers */ - rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, - rrset->rri_rdtype); - rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, - T_RRSIG); - - /* allocate memory for answers */ - rrset->rri_rdatas = calloc(rrset->rri_nrdatas, - sizeof(struct rdatainfo)); - if (rrset->rri_rdatas == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* allocate memory for signatures */ - rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); - if (rrset->rri_sigs == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - - /* copy answers & signatures */ - for (rr = response->answer, index_ans = 0, index_sig = 0; - rr; rr = rr->next) { - - rdata = NULL; - - if (rr->class == rrset->rri_rdclass && - rr->type == rrset->rri_rdtype) - rdata = &rrset->rri_rdatas[index_ans++]; - - if (rr->class == rrset->rri_rdclass && - rr->type == T_RRSIG) - rdata = &rrset->rri_sigs[index_sig++]; - - if (rdata) { - rdata->rdi_length = rr->size; - rdata->rdi_data = malloc(rr->size); - - if (rdata->rdi_data == NULL) { - result = ERRSET_NOMEMORY; - goto fail; - } - memcpy(rdata->rdi_data, rr->rdata, rr->size); - } - } - free_dns_response(response); - - *res = rrset; - return (ERRSET_SUCCESS); - -fail: - if (rrset != NULL) - freerrset(rrset); - if (response != NULL) - free_dns_response(response); - return (result); -} - -void -freerrset(struct rrsetinfo *rrset) -{ - u_int16_t i; - - if (rrset == NULL) - return; - - if (rrset->rri_rdatas) { - for (i = 0; i < rrset->rri_nrdatas; i++) { - if (rrset->rri_rdatas[i].rdi_data == NULL) - break; - free(rrset->rri_rdatas[i].rdi_data); - } - free(rrset->rri_rdatas); - } - - if (rrset->rri_sigs) { - for (i = 0; i < rrset->rri_nsigs; i++) { - if (rrset->rri_sigs[i].rdi_data == NULL) - break; - free(rrset->rri_sigs[i].rdi_data); - } - free(rrset->rri_sigs); - } - - if (rrset->rri_name) - free(rrset->rri_name); - free(rrset); -} - -/* - * DNS response parsing routines - */ -static struct dns_response * -parse_dns_response(const u_char *answer, int size) -{ - struct dns_response *resp; - const u_char *cp; - - /* allocate memory for the response */ - resp = calloc(1, sizeof(*resp)); - if (resp == NULL) - return (NULL); - - /* initialize current pointer */ - cp = answer; - - /* copy header */ - memcpy(&resp->header, cp, HFIXEDSZ); - cp += HFIXEDSZ; - - /* fix header byte order */ - resp->header.qdcount = ntohs(resp->header.qdcount); - resp->header.ancount = ntohs(resp->header.ancount); - resp->header.nscount = ntohs(resp->header.nscount); - resp->header.arcount = ntohs(resp->header.arcount); - - /* there must be at least one query */ - if (resp->header.qdcount < 1) { - free_dns_response(resp); - return (NULL); - } - - /* parse query section */ - resp->query = parse_dns_qsection(answer, size, &cp, - resp->header.qdcount); - if (resp->header.qdcount && resp->query == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse answer section */ - resp->answer = parse_dns_rrsection(answer, size, &cp, - resp->header.ancount); - if (resp->header.ancount && resp->answer == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse authority section */ - resp->authority = parse_dns_rrsection(answer, size, &cp, - resp->header.nscount); - if (resp->header.nscount && resp->authority == NULL) { - free_dns_response(resp); - return (NULL); - } - - /* parse additional section */ - resp->additional = parse_dns_rrsection(answer, size, &cp, - resp->header.arcount); - if (resp->header.arcount && resp->additional == NULL) { - free_dns_response(resp); - return (NULL); - } - - return (resp); -} - -static struct dns_query * -parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count) -{ - struct dns_query *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_query)); - if (curr == NULL) { - free_dns_query(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_query(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_query(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - } - - return (head); -} - -static struct dns_rr * -parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, - int count) -{ - struct dns_rr *head, *curr, *prev; - int i, length; - char name[MAXDNAME]; - - for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) { - - /* allocate and initialize struct */ - curr = calloc(1, sizeof(struct dns_rr)); - if (curr == NULL) { - free_dns_rr(head); - return (NULL); - } - if (head == NULL) - head = curr; - if (prev != NULL) - prev->next = curr; - - /* name */ - length = dn_expand(answer, answer + size, *cp, name, - sizeof(name)); - if (length < 0) { - free_dns_rr(head); - return (NULL); - } - curr->name = strdup(name); - if (curr->name == NULL) { - free_dns_rr(head); - return (NULL); - } - *cp += length; - - /* type */ - curr->type = _getshort(*cp); - *cp += INT16SZ; - - /* class */ - curr->class = _getshort(*cp); - *cp += INT16SZ; - - /* ttl */ - curr->ttl = _getlong(*cp); - *cp += INT32SZ; - - /* rdata size */ - curr->size = _getshort(*cp); - *cp += INT16SZ; - - /* rdata itself */ - curr->rdata = malloc(curr->size); - if (curr->rdata == NULL) { - free_dns_rr(head); - return (NULL); - } - memcpy(curr->rdata, *cp, curr->size); - *cp += curr->size; - } - - return (head); -} - -static void -free_dns_query(struct dns_query *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - free_dns_query(p->next); - free(p); -} - -static void -free_dns_rr(struct dns_rr *p) -{ - if (p == NULL) - return; - - if (p->name) - free(p->name); - if (p->rdata) - free(p->rdata); - free_dns_rr(p->next); - free(p); -} - -static void -free_dns_response(struct dns_response *p) -{ - if (p == NULL) - return; - - free_dns_query(p->query); - free_dns_rr(p->answer); - free_dns_rr(p->authority); - free_dns_rr(p->additional); - free(p); -} - -static int -count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type) -{ - int n = 0; - - while(p) { - if (p->class == class && p->type == type) - n++; - p = p->next; - } - - return (n); -} diff --git a/src/lib/libc/net/getservbyname.c b/src/lib/libc/net/getservbyname.c deleted file mode 100644 index beb8943af6..0000000000 --- a/src/lib/libc/net/getservbyname.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $OpenBSD: getservbyname.c,v 1.10 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getservbyname_r(const char *name, const char *proto, struct servent *se, - struct servent_data *sd) -{ - char **cp; - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (strcmp(name, se->s_name) == 0) - goto gotname; - for (cp = se->s_aliases; *cp; cp++) - if (strcmp(name, *cp) == 0) - goto gotname; - continue; -gotname: - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} - -struct servent * -getservbyname(const char *name, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyname_r(name, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c deleted file mode 100644 index 46679ba366..0000000000 --- a/src/lib/libc/net/getservbyport.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: getservbyport.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -int -getservbyport_r(int port, const char *proto, struct servent *se, - struct servent_data *sd) -{ - int error; - - setservent_r(sd->stayopen, sd); - while ((error = getservent_r(se, sd)) == 0) { - if (se->s_port != port) - continue; - if (proto == 0 || strcmp(se->s_proto, proto) == 0) - break; - } - if (!sd->stayopen && sd->fp != NULL) { - fclose(sd->fp); - sd->fp = NULL; - } - return (error); -} - -struct servent * -getservbyport(int port, const char *proto) -{ - extern struct servent_data _servent_data; - static struct servent serv; - - if (getservbyport_r(port, proto, &serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/getservent.3 b/src/lib/libc/net/getservent.3 deleted file mode 100644 index 7888b5f1b8..0000000000 --- a/src/lib/libc/net/getservent.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: getservent.3,v 1.20 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt GETSERVENT 3 -.Os -.Sh NAME -.Nm getservent , -.Nm getservent_r , -.Nm getservbyport , -.Nm getservbyport_r , -.Nm getservbyname , -.Nm getservbyname_r , -.Nm setservent , -.Nm setservent_r , -.Nm endservent , -.Nm endservent_r -.Nd get service entry -.Sh SYNOPSIS -.Fd #include -.Ft struct servent * -.Fn getservent "void" -.Ft int -.Fn getservent_r "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyname "const char *name" "const char *proto" -.Ft int -.Fn getservbyname_r "const char *name" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft struct servent * -.Fn getservbyport "int port" "const char *proto" -.Ft int -.Fn getservbyport_r "int port" "const char *proto" "struct servent *servent" "struct servent_data *servent_data" -.Ft void -.Fn setservent "int stayopen" -.Ft void -.Fn setservent_r "int stayopen" "struct servent_data *servent_data" -.Ft void -.Fn endservent "void" -.Ft void -.Fn endservent_r "struct servent_data *servent_data" -.Sh DESCRIPTION -The -.Fn getservent , -.Fn getservbyname , -and -.Fn getservbyport -functions each return a pointer to an object with the following structure -containing the broken-out fields of a line in the network services database, -.Pa /etc/services . -.Bd -literal -offset indent -struct servent { - char *s_name; /* official name of service */ - char **s_aliases; /* alias list */ - int s_port; /* port service resides at */ - char *s_proto; /* protocol to use */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width s_aliases -.It Fa s_name -The official name of the service. -.It Fa s_aliases -A null-terminated list of alternate names for the service. -.It Fa s_port -The port number at which the service resides. -Port numbers are returned in network byte order. -.It Fa s_proto -The name of the protocol to use when contacting the service. -.El -.Pp -The -.Fn getservent -function reads the next line of the file, opening the file if necessary. -.Pp -The -.Fn setservent -function opens and rewinds the file. -If the -.Fa stayopen -flag is non-zero, -the services database will not be closed after each call to -.Fn getservbyname -or -.Fn getservbyport . -.Pp -The -.Fn endservent -function closes the file. -.Pp -The -.Fn getservbyname -and -.Fn getservbyport -functions sequentially search from the beginning of the file until a -matching protocol name or port number (specified in network byte order) -is found, or until -.Dv EOF -is encountered. -If a protocol name is also supplied (non-null), -searches must also match the protocol. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are reentrant versions of the above functions that take a -pointer to a -.Fa servent_data -structure which is used to store state information. -The structure must be zero-filled before it is used -and should be considered opaque for the sake of portability. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions -also take a pointer to a -.Fa servent -structure which is used to store the results of the database lookup. -.Sh RETURN VALUES -The -.Fn getservent , -.Fn getservbyport , -and -.Fn getservbyname -functions return a pointer to a -.Fa servent -structure on success or a null pointer if end-of-file -is reached or an error occurs. -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -and -.Fn getservbyname_r -functions return 0 on success or \-1 if end-of-file -is reached or an error occurs. -.Sh FILES -.Bl -tag -width /etc/services -compact -.It Pa /etc/services -.El -.Sh SEE ALSO -.Xr getprotoent 3 , -.Xr services 5 -.Sh STANDARDS -The -.Fn getservent , -.Fn getservbynumber , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions conform to -.St -p1003.1-2004 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions are not currently standardized. -This implementation follows the API used by HP, IBM, and Digital. -.Sh HISTORY -The -.Fn getservent , -.Fn getservbyport , -.Fn getservbyname , -.Fn setservent , -and -.Fn endservent -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn getservent_r , -.Fn getservbyport_r , -.Fn getservbyname_r , -.Fn setservent_r , -and -.Fn endservent_r -functions appeared in -.Ox 3.7 . -.Sh BUGS -The non-reentrant functions use static data storage; if the data is needed -for future use, it should be copied before any subsequent calls overwrite it. -Expecting port numbers to fit in a 32-bit quantity is probably naive. diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c deleted file mode 100644 index c81a4cf3e2..0000000000 --- a/src/lib/libc/net/getservent.c +++ /dev/null @@ -1,168 +0,0 @@ -/* $OpenBSD: getservent.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -void -setservent_r(int f, struct servent_data *sd) -{ - if (sd->fp == NULL) - sd->fp = fopen(_PATH_SERVICES, "r" ); - else - rewind(sd->fp); - sd->stayopen |= f; -} - -void -endservent_r(struct servent_data *sd) -{ - if (sd->fp) { - fclose(sd->fp); - sd->fp = NULL; - } - free(sd->aliases); - sd->aliases = NULL; - sd->maxaliases = 0; - free(sd->line); - sd->line = NULL; - sd->stayopen = 0; -} - -int -getservent_r(struct servent *se, struct servent_data *sd) -{ - char *p, *cp, **q, *endp; - size_t len; - long l; - int serrno; - - if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "r" )) == NULL) - return (-1); -again: - if ((p = fgetln(sd->fp, &len)) == NULL) - return (-1); - if (len == 0 || *p == '#' || *p == '\n') - goto again; - if (p[len-1] == '\n') - len--; - if ((cp = memchr(p, '#', len)) != NULL) - len = cp - p; - cp = realloc(sd->line, len + 1); - if (cp == NULL) - return (-1); - sd->line = se->s_name = memcpy(cp, p, len); - cp[len] = '\0'; - p = strpbrk(cp, " \t"); - if (p == NULL) - goto again; - *p++ = '\0'; - while (*p == ' ' || *p == '\t') - p++; - cp = strpbrk(p, ",/"); - if (cp == NULL) - goto again; - *cp++ = '\0'; - l = strtol(p, &endp, 10); - if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) - goto again; - se->s_port = htons((in_port_t)l); - se->s_proto = cp; - if (sd->aliases == NULL) { - sd->maxaliases = 10; - sd->aliases = calloc(sd->maxaliases, sizeof(char *)); - if (sd->aliases == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - } - q = se->s_aliases = sd->aliases; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q == &se->s_aliases[sd->maxaliases - 1]) { - p = realloc(se->s_aliases, - 2 * sd->maxaliases * sizeof(char *)); - if (p == NULL) { - serrno = errno; - endservent_r(sd); - errno = serrno; - return (-1); - } - sd->maxaliases *= 2; - q = (char **)p + (q - se->s_aliases); - se->s_aliases = sd->aliases = (char **)p; - } - *q++ = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } - *q = NULL; - return (0); -} - -struct servent_data _servent_data; /* shared with getservby{name,port}.c */ - -void -setservent(int f) -{ - setservent_r(f, &_servent_data); -} - -void -endservent(void) -{ - endservent_r(&_servent_data); -} - -struct servent * -getservent(void) -{ - static struct servent serv; - - if (getservent_r(&serv, &_servent_data) != 0) - return (NULL); - return (&serv); -} diff --git a/src/lib/libc/net/herror.c b/src/lib/libc/net/herror.c deleted file mode 100644 index 7787115a9d..0000000000 --- a/src/lib/libc/net/herror.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: herror.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ - -/* - * ++Copyright++ 1987, 1993 - * - - * Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include -#include - -const char * const h_errlist[] = { - "Resolver Error 0 (no error)", - "Unknown host", /* 1 HOST_NOT_FOUND */ - "Host name lookup failure", /* 2 TRY_AGAIN */ - "Unknown server error", /* 3 NO_RECOVERY */ - "No address associated with name", /* 4 NO_ADDRESS */ -}; -const int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; - -extern int h_errno; - -/* - * herror -- - * print the error indicated by the h_errno value. - */ -void -herror(const char *s) -{ - struct iovec iov[4]; - struct iovec *v = iov; - - if (s && *s) { - v->iov_base = (char *)s; - v->iov_len = strlen(s); - v++; - v->iov_base = ": "; - v->iov_len = 2; - v++; - } - v->iov_base = (char *)hstrerror(h_errno); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = "\n"; - v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); -} - -const char * -hstrerror(int err) -{ - if (err < 0) - return ("Resolver internal error"); - else if (err < h_nerr) - return (h_errlist[err]); - return ("Unknown resolver error"); -} diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c deleted file mode 100644 index 5ab4189597..0000000000 --- a/src/lib/libc/net/htonl.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: htonl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef htonl - -u_int32_t -htonl(u_int32_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c deleted file mode 100644 index c8b73fdbb7..0000000000 --- a/src/lib/libc/net/htons.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: htons.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef htons - -u_int16_t -htons(u_int16_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3 deleted file mode 100644 index 8ffc35a5fa..0000000000 --- a/src/lib/libc/net/if_indextoname.3 +++ /dev/null @@ -1,144 +0,0 @@ -.\" $OpenBSD: if_indextoname.3,v 1.11 2007/05/31 19:19:30 jmc Exp $ -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt IF_NAMETOINDEX 3 -.Os -.Sh NAME -.Nm if_nametoindex , -.Nm if_indextoname , -.Nm if_nameindex , -.Nm if_freenameindex -.Nd convert interface index to name, and vice versa -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft "unsigned int" -.Fn if_nametoindex "const char *ifname" -.Ft "char *" -.Fn if_indextoname "unsigned int ifindex" "char *ifname" -.Ft "struct if_nameindex *" -.Fn if_nameindex "void" -.Ft "void" -.Fn if_freenameindex "struct if_nameindex *ptr" -.Sh DESCRIPTION -These functions map interface indexes to interface names (such as -.Dq lo0 ) , -and vice versa. -.Pp -The -.Fn if_nametoindex -function converts an interface name specified by the -.Fa ifname -argument to an interface index (positive integer value). -If the specified interface does not exist, 0 will be returned. -.Pp -.Fn if_indextoname -converts an interface index specified by the -.Fa ifindex -argument to an interface name. -The -.Fa ifname -argument must point to a buffer of at least -.Dv IF_NAMESIZE -bytes into which the interface name corresponding to the specified index is -returned. -.Pf ( Dv IF_NAMESIZE -is also defined in -.Aq Pa net/if.h -and its value includes a terminating NUL byte at the end of the -interface name.) -This pointer is also the return value of the function. -If there is no interface corresponding to the specified index, -.Dv NULL -is returned. -.Pp -.Fn if_nameindex -returns an array of -.Vt if_nameindex -structures. -.Vt if_nameindex -is also defined in -.Aq Pa net/if.h , -and is as follows: -.Bd -literal -offset indent -struct if_nameindex { - unsigned int if_index; /* 1, 2, ... */ - char *if_name; /* NUL-terminated name */ -}; -.Ed -.Pp -The end of the array of structures is indicated by a structure with -an -.Fa if_index -of 0 and an -.Fa if_name -of -.Dv NULL . -The function returns a null pointer on error. -The memory used for this array of structures along with the interface -names pointed to by the -.Fa if_name -members is obtained dynamically. -This memory is freed by the -.Fn if_freenameindex -function. -.Pp -.Fn if_freenameindex -takes a pointer that was returned by -.Fn if_nameindex -as argument -.Pq Fa ptr , -and it reclaims the region allocated. -.Sh DIAGNOSTICS -.Fn if_nametoindex -returns 0 on error, positive integer on success. -.Fn if_indextoname -and -.Fn if_nameindex -return -.Dv NULL -on errors. -.Sh SEE ALSO -.Xr getifaddrs 3 , -.Xr networking 4 -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A W. Stevens -.%T Basic Socket Interface Extensions for IPv6 -.%R RFC 2553 -.%D March 1999 -.Re -.Sh STANDARDS -These functions are defined in ``Basic Socket Interface Extensions for IPv6'' -.Pq RFC 2533 . diff --git a/src/lib/libc/net/if_indextoname.c b/src/lib/libc/net/if_indextoname.c deleted file mode 100644 index f99e52e387..0000000000 --- a/src/lib/libc/net/if_indextoname.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $OpenBSD: if_indextoname.c,v 1.9 2002/03/07 22:40:23 millert Exp $ */ -/* $KAME: if_indextoname.c,v 1.6 2000/11/07 22:33:25 jinmei Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_indextoname.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2533: - * - * The second function maps an interface index into its corresponding - * name. - * - * #include - * - * char *if_indextoname(unsigned int ifindex, char *ifname); - * - * The ifname argument must point to a buffer of at least IF_NAMESIZE - * bytes into which the interface name corresponding to the specified - * index is returned. (IF_NAMESIZE is also defined in and - * its value includes a terminating null byte at the end of the - * interface name.) This pointer is also the return value of the - * function. If there is no interface corresponding to the specified - * index, NULL is returned, and errno is set to ENXIO, if there was a - * system error (such as running out of memory), if_indextoname returns - * NULL and errno would be set to the proper value (e.g., ENOMEM). - */ - -char * -if_indextoname(unsigned int ifindex, char *ifname) -{ - struct ifaddrs *ifaddrs, *ifa; - int error = 0; - - if (getifaddrs(&ifaddrs) < 0) - return(NULL); /* getifaddrs properly set errno */ - - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK && - ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index) - break; - } - - if (ifa == NULL) { - error = ENXIO; - ifname = NULL; - } - else - strlcpy(ifname, ifa->ifa_name, IFNAMSIZ); - - freeifaddrs(ifaddrs); - - errno = error; - return(ifname); -} diff --git a/src/lib/libc/net/if_nameindex.c b/src/lib/libc/net/if_nameindex.c deleted file mode 100644 index 3675a2a450..0000000000 --- a/src/lib/libc/net/if_nameindex.c +++ /dev/null @@ -1,140 +0,0 @@ -/* $OpenBSD: if_nameindex.c,v 1.9 2002/03/07 22:40:23 millert Exp $ */ -/* $KAME: if_nameindex.c,v 1.7 2000/11/24 08:17:20 itojun Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_nameindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.3 Return All Interface Names and Indexes - * - * The if_nameindex structure holds the information about a single - * interface and is defined as a result of including the - * header. - * - * struct if_nameindex { - * unsigned int if_index; - * char *if_name; - * }; - * - * The final function returns an array of if_nameindex structures, one - * structure per interface. - * - * struct if_nameindex *if_nameindex(void); - * - * The end of the array of structures is indicated by a structure with - * an if_index of 0 and an if_name of NULL. The function returns a NULL - * pointer upon an error, and would set errno to the appropriate value. - * - * The memory used for this array of structures along with the interface - * names pointed to by the if_name members is obtained dynamically. - * This memory is freed by the next function. - * - * 4.4. Free Memory - * - * The following function frees the dynamic memory that was allocated by - * if_nameindex(). - * - * #include - * - * void if_freenameindex(struct if_nameindex *ptr); - * - * The argument to this function must be a pointer that was returned by - * if_nameindex(). - */ - -struct if_nameindex * -if_nameindex(void) -{ - struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - size_t nbytes; - struct if_nameindex *ifni, *ifni2; - char *cp; - - if (getifaddrs(&ifaddrs) < 0) - return(NULL); - - /* - * First, find out how many interfaces there are, and how - * much space we need for the string names. - */ - ni = 0; - nbytes = 0; - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK) { - nbytes += strlen(ifa->ifa_name) + 1; - ni++; - } - } - - /* - * Next, allocate a chunk of memory, use the first part - * for the array of structures, and the last part for - * the strings. - */ - cp = malloc((ni + 1) * sizeof(struct if_nameindex) + nbytes); - ifni = (struct if_nameindex *)cp; - if (ifni == NULL) - goto out; - cp += (ni + 1) * sizeof(struct if_nameindex); - - /* - * Now just loop through the list of interfaces again, - * filling in the if_nameindex array and making copies - * of all the strings. - */ - ifni2 = ifni; - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK) { - ifni2->if_index = - ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; - ifni2->if_name = cp; - nbytes = strlen(ifa->ifa_name) + 1; - memcpy(cp, ifa->ifa_name, nbytes); - ifni2++; - cp += nbytes; - } - } - /* - * Finally, don't forget to terminate the array. - */ - ifni2->if_index = 0; - ifni2->if_name = NULL; -out: - freeifaddrs(ifaddrs); - return(ifni); -} diff --git a/src/lib/libc/net/if_nametoindex.c b/src/lib/libc/net/if_nametoindex.c deleted file mode 100644 index 8bd792b949..0000000000 --- a/src/lib/libc/net/if_nametoindex.c +++ /dev/null @@ -1,81 +0,0 @@ -/* $OpenBSD: if_nametoindex.c,v 1.8 2002/03/07 22:40:23 millert Exp $ */ -/* $KAME: if_nametoindex.c,v 1.5 2000/11/24 08:04:40 itojun Exp $ */ - -/*- - * Copyright (c) 1997, 2000 - * Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * BSDI Id: if_nametoindex.c,v 2.3 2000/04/17 22:38:05 dab Exp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * From RFC 2553: - * - * 4.1 Name-to-Index - * - * - * The first function maps an interface name into its corresponding - * index. - * - * #include - * - * unsigned int if_nametoindex(const char *ifname); - * - * If the specified interface name does not exist, the return value is - * 0, and errno is set to ENXIO. If there was a system error (such as - * running out of memory), the return value is 0 and errno is set to the - * proper value (e.g., ENOMEM). - */ - -unsigned int -if_nametoindex(const char *ifname) -{ - struct ifaddrs *ifaddrs, *ifa; - unsigned int ni; - - if (getifaddrs(&ifaddrs) < 0) - return(0); - - ni = 0; - - for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && - ifa->ifa_addr->sa_family == AF_LINK && - strcmp(ifa->ifa_name, ifname) == 0) { - ni = ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index; - break; - } - } - - freeifaddrs(ifaddrs); - if (!ni) - errno = ENXIO; - return(ni); -} diff --git a/src/lib/libc/net/inet.3 b/src/lib/libc/net/inet.3 deleted file mode 100644 index c650df360b..0000000000 --- a/src/lib/libc/net/inet.3 +++ /dev/null @@ -1,345 +0,0 @@ -.\" $OpenBSD: inet.3,v 1.21 2007/06/12 16:50:06 jmc Exp $ -.\" $NetBSD: inet.3,v 1.7 1997/06/18 02:25:24 lukem Exp $ -.\" -.\" Copyright (c) 1983, 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)inet.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd $Mdocdate: June 12 2007 $ -.Dt INET 3 -.Os -.Sh NAME -.Nm inet_addr , -.Nm inet_aton , -.Nm inet_lnaof , -.Nm inet_makeaddr , -.Nm inet_netof , -.Nm inet_network , -.Nm inet_ntoa , -.Nm inet_ntop , -.Nm inet_pton -.Nd Internet address manipulation routines -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft in_addr_t -.Fn inet_addr "const char *cp" -.Ft int -.Fn inet_aton "const char *cp" "struct in_addr *addr" -.Ft in_addr_t -.Fn inet_lnaof "struct in_addr in" -.Ft struct in_addr -.Fn inet_makeaddr "in_addr_t net" "in_addr_t lna" -.Ft in_addr_t -.Fn inet_netof "struct in_addr in" -.Ft in_addr_t -.Fn inet_network "const char *cp" -.Ft char * -.Fn inet_ntoa "struct in_addr in" -.Ft const char * -.Fn inet_ntop "int af" "const void *src" "char *dst" "size_t size" -.Ft int -.Fn inet_pton "int af" "const char *src" "void *dst" -.Sh DESCRIPTION -The routines -.Fn inet_aton , -.Fn inet_addr , -and -.Fn inet_network -interpret character strings representing -numbers expressed in the Internet standard -.Dq dot -notation. -The -.Fn inet_pton -function converts a presentation format address (that is, printable form -as held in a character string) to network format (usually a -.Li struct in_addr -or some other internal binary representation, in network byte order). -It returns 1 if the address was valid for the specified address family; -0 if the address wasn't parseable in the specified address family; or \-1 -if some system error occurred (in which case -.Va errno -will have been set). -This function is presently valid for -.Dv AF_INET -and -.Dv AF_INET6 . -The -.Fn inet_aton -routine interprets the specified character string as an Internet address, -placing the address into the structure provided. -It returns 1 if the string was successfully interpreted, -or 0 if the string was invalid. -The -.Fn inet_addr -and -.Fn inet_network -functions return numbers suitable for use -as Internet addresses and Internet network -numbers, respectively. -.Pp -The function -.Fn inet_ntop -converts an address from network format (usually a -.Li struct in_addr -or some other binary form, in network byte order) to presentation format -(suitable for external display purposes). -It returns -.Dv NULL -if a system -error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -The routine -.Fn inet_ntoa -takes an Internet address and returns an -ASCII string representing the address in dot notation. -The routine -.Fn inet_makeaddr -takes an Internet network number and a local -network address and constructs an Internet address -from it. -The routines -.Fn inet_netof -and -.Fn inet_lnaof -break apart Internet host addresses, returning -the network number and local network address part, -respectively. -.Pp -All Internet addresses are returned in network -order (bytes ordered from left to right). -All network numbers and local address parts are -returned as machine format integer values. -.Sh INTERNET ADDRESSES (IP VERSION 4) -Values specified using dot notation take one of the following forms: -.Bd -literal -offset indent -a.b.c.d -a.b.c -a.b -a -.Ed -.Pp -When four parts are specified, each is interpreted -as a byte of data and assigned, from left to right, -to the four bytes of an Internet address. -Note that when an Internet address is viewed as a 32-bit -integer quantity on a system that uses little-endian -byte order -(such as the Intel 386, 486 and Pentium processors) -the bytes referred to above appear as -.Dq Li d.c.b.a . -That is, little-endian bytes are ordered from right to left. -.Pp -When a three part address is specified, the last -part is interpreted as a 16-bit quantity and placed -in the rightmost two bytes of the network address. -This makes the three part address format convenient -for specifying Class B network addresses as -.Dq Li 128.net.host . -.Pp -When a two part address is supplied, the last part -is interpreted as a 24-bit quantity and placed in -the rightmost three bytes of the network address. -This makes the two part address format convenient -for specifying Class A network addresses as -.Dq Li net.host . -.Pp -When only one part is given, the value is stored -directly in the network address without any byte -rearrangement. -.Pp -All numbers supplied as -.Dq parts -in a dot notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh INTERNET ADDRESSES (IP VERSION 6) -In order to support scoped IPv6 addresses, -.Xr getaddrinfo 3 -and -.Xr getnameinfo 3 -are recommended rather than the functions presented here. -.Pp -The presentation format of an IPv6 address is given in RFC 2373: -.Pp -There are three conventional forms for representing IPv6 addresses as -text strings: -.Bl -enum -.It -The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the -hexadecimal values of the eight 16-bit pieces of the address. -Examples: -.Bd -literal -offset indent -FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 -1080:0:0:0:8:800:200C:417A -.Ed -.Pp -Note that it is not necessary to write the leading zeros in an -individual field, but there must be at least one numeral in -every field (except for the case described in 2.). -.It -Due to the method of allocating certain styles of IPv6 -addresses, it will be common for addresses to contain long -strings of zero bits. -In order to make writing addresses -containing zero bits easier, a special syntax is available to -compress the zeros. -The use of -.Dq \&:\&: -indicates multiple groups -of 16 bits of zeros. -The -.Dq \&:\&: -can only appear once in an -address. -The -.Dq \&:\&: -can also be used to compress the leading and/or trailing zeros in an address. -.Pp -For example the following addresses: -.Bd -literal -offset indent -1080:0:0:0:8:800:200C:417A a unicast address -FF01:0:0:0:0:0:0:43 a multicast address -0:0:0:0:0:0:0:1 the loopback address -0:0:0:0:0:0:0:0 the unspecified addresses -.Ed -.Pp -may be represented as: -.Bd -literal -offset indent -1080::8:800:200C:417A a unicast address -FF01::43 a multicast address -::1 the loopback address -:: the unspecified addresses -.Ed -.It -An alternative form that is sometimes more convenient when -dealing with a mixed environment of IPv4 and IPv6 nodes is -x:x:x:x:x:x:d.d.d.d, where the 'x's are the hexadecimal values -of the six high-order 16-bit pieces of the address, and the 'd's -are the decimal values of the four low-order 8-bit pieces of the -address (standard IPv4 representation). -Examples: -.Bd -literal -offset indent -0:0:0:0:0:0:13.1.68.3 -0:0:0:0:0:FFFF:129.144.52.38 -.Ed -.Pp -or in compressed form: -.Bd -literal -offset indent -::13.1.68.3 -::FFFF:129.144.52.38 -.Ed -.El -.Sh DIAGNOSTICS -The constant -.Dv INADDR_NONE -is returned by -.Fn inet_addr -and -.Fn inet_network -for malformed requests. -.Sh SEE ALSO -.Xr byteorder 3 , -.Xr gethostbyname 3 , -.Xr getnetent 3 , -.Xr inet_net 3 , -.Xr hosts 5 , -.Xr networks 5 -.Rs -.%R RFC 2373 -.%D July 1998 -.%T "IP Version 6 Addressing Architecture" -.Re -.Rs -.%R RFC 3493 -.%D February 2003 -.%T "Basic Socket Interface Extensions for IPv6" -.Re -.Sh STANDARDS -The -.Nm inet_ntop -and -.Nm inet_pton -functions conform to the IETF IPv6 BSD API and address formatting -specifications. -Note that -.Nm inet_pton -does not accept 1-, 2-, or 3-part dotted addresses; all four parts -must be specified. -This is a narrower input set than that accepted by -.Nm inet_aton . -.Sh HISTORY -The -.Nm inet_addr , -.Nm inet_network , -.Nm inet_makeaddr , -.Nm inet_lnaof , -and -.Nm inet_netof -functions appeared in -.Bx 4.2 . -The -.Nm inet_aton -and -.Nm inet_ntoa -functions appeared in -.Bx 4.3 . -The -.Nm inet_pton -and -.Nm inet_ntop -functions appeared in BIND 4.9.4. -.Sh BUGS -The value -.Dv INADDR_NONE -(0xffffffff) is a valid broadcast address, but -.Fn inet_addr -cannot return that value without indicating failure. -Also, -.Fn inet_addr -should have been designed to return a -.Li struct in_addr . -The newer -.Fn inet_aton -function does not share these problems, and almost all existing code -should be modified to use -.Fn inet_aton -instead. -.Pp -The problem of host byte ordering versus network byte ordering is -confusing. -.Pp -The string returned by -.Fn inet_ntoa -resides in a static memory area. diff --git a/src/lib/libc/net/inet6_opt_init.3 b/src/lib/libc/net/inet6_opt_init.3 deleted file mode 100644 index 21880a6382..0000000000 --- a/src/lib/libc/net/inet6_opt_init.3 +++ /dev/null @@ -1,338 +0,0 @@ -.\" $OpenBSD: inet6_opt_init.3,v 1.3 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_OPT_INIT 3 -.Os -.\" -.Sh NAME -.Nm inet6_opt_init , -.Nm inet6_opt_append , -.Nm inet6_opt_finish , -.Nm inet6_opt_set_val , -.Nm inet6_opt_next , -.Nm inet6_opt_find , -.Nm inet6_opt_get_val -.Nd IPv6 Hop-by-Hop and Destination Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft "int" -.Fn inet6_opt_init "void *extbuf" "socklen_t extlen" -.Ft "int" -.Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" -.Ft "int" -.Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" -.Ft "int" -.Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" -.Ft "int" -.Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" -.Ft "int" -.Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" -.\" -.Sh DESCRIPTION -Building and parsing the Hop-by-Hop and Destination options is -complicated. -The advanced sockets API defines a set of functions to -help applications create and manipulate Hop-by-Hop and Destination -options. -.\"This man page describes the functions specified in -.\"IETF Draft RFC 3542 while the -.\".Xr inet6_options_space 3 -.\"man page documents the functions defined in RFC 2292. -.\"It is expected -.\"that this set of functions will supersede those in RFC 2292 but for -.\"the time being both APIs are retained. -These functions use the -formatting rules specified in Appendix B in RFC 2460, i.e. that the -largest field is placed last in the option. -The function prototypes -for these functions are all contained in the header file -.Aq Pa netinet/in.h . -.\" -.Ss inet6_opt_init -The -.Fn inet6_opt_init -function -returns the number of bytes needed for an empty -extension header, one without any options. -If the -.Va extbuf -argument points to a valid section of memory -then the -.Fn inet6_opt_init -function also initializes the extension header's length field. -When attempting to initialize an extension buffer passed in the -.Va extbuf -argument, -.Fa extlen -must be a positive multiple of 8 or else the function fails and -returns \-1 to the caller. -.\" -.Ss inet6_opt_append -The -.Fn inet6_opt_append -function can perform different jobs. -When a valid -.Fa extbuf -argument is supplied it appends an option to the extension buffer and -returns the updated total length as well as a pointer to the newly -created option in -.Fa databufp . -If the value -of -.Fa extbuf -is -.Dv NULL -then the -.Fn inet6_opt_append -function only reports what the total length would -be if the option were actually appended. -The -.Fa len -and -.Fa align -arguments specify the length of the option and the required data -alignment which must be used when appending the option. -The -.Fa offset -argument should be the length returned by the -.Fn inet6_opt_init -function or a previous call to -.Fn inet6_opt_append . -.Pp -The -.Fa type -argument is the 8-bit option type. -.Pp -After -.Fn inet6_opt_append -has been called, the application can use the buffer pointed to by -.Fa databufp -directly, or use -.Fn inet6_opt_set_val -to specify the data to be contained in the option. -.Pp -Option types of -.Li 0 -and -.Li 1 -are reserved for the -.Li Pad1 -and -.Li PadN -options. -All other values from 2 through 255 may be used by applications. -.Pp -The length of the option data is contained in an 8-bit value and so -may contain any value from 0 through 255. -.Pp -The -.Fa align -parameter must have a value of 1, 2, 4, or 8 and cannot exceed the -value of -.Fa len . -The alignment values represent no alignment, 16-bit, 32-bit and 64-bit -alignments respectively. -.\" -.Ss inet6_opt_finish -The -.Fn inet6_opt_finish -calculates the final padding necessary to make the extension header a -multiple of 8 bytes, as required by the IPv6 extension header -specification, and returns the extension header's updated total -length. -The -.Fa offset -argument should be the length returned by -.Fn inet6_opt_init -or -.Fn inet6_opt_append . -When -.Fa extbuf -is not -.Dv NULL -the function also sets up the appropriate padding bytes by inserting a -Pad1 or PadN option of the proper length. -.Pp -If the extension header is too small to contain the proper padding -then an error of \-1 is returned to the caller. -.\" -.Ss inet6_opt_set_val -The -.Fn inet6_opt_set_val -function inserts data items of various sizes into the data portion of -the option. -The -.Fa databuf -argument is a pointer to memory that was returned by the -.Fn inet6_opt_append -call and the -.Fa offset -argument specifies where the option should be placed in the -data buffer. -The -.Fa val -argument points to an area of memory containing the data to be -inserted into the extension header, and the -.Fa vallen -argument indicates how much data to copy. -.Pp -The caller should ensure that each field is aligned on its natural -boundaries as described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field which is calculated as -.Fa offset -+ -.Fa vallen -and is used when composing options with multiple fields. -.\" -.Ss inet6_opt_next -The -.Fn inet6_opt_next -function parses received extension headers. -The -.Fa extbuf -and -.Fa extlen -arguments specify the location and length of the extension header -being parsed. -The -.Fa offset -argument should either be zero, for the first option, or the length value -returned by a previous call to -.Fn inet6_opt_next -or -.Fn inet6_opt_find . -The return value specifies the position where to continue scanning the -extension buffer. -The option is returned in the arguments -.Fa typep , lenp , -and -.Fa databufp . -.Fa typep , lenp , -and -.Fa databufp -point to the 8-bit option type, the 8-bit option length and the option -data respectively. -This function does not return any PAD1 or PADN options. -When an error occurs or there are no more options the return -value is \-1. -.\" -.Ss inet6_opt_find -The -.Fn inet6_opt_find -function searches the extension buffer for a particular option type, -passed in through the -.Fa type -argument. -If the option is found then the -.Fa lenp -and -.Fa databufp -arguments are updated to point to the option's length and data -respectively. -.Fa extbuf -and -.Fa extlen -must point to a valid extension buffer and give its length. -The -.Fa offset -argument can be used to search from a location anywhere in the -extension header. -.Ss inet6_opt_get_val -The -.Fn inet6_opt_get_val -function extracts data items of various sizes in the data portion of -the option. -The -.Fa databuf -is a pointer returned by the -.Fn inet6_opt_next -or -.Fn inet6_opt_find -functions. -The -.Fa val -argument points to where the data will be extracted. -The -.Fa offset -argument specifies from where in the data portion of the option the -value should be extracted; the first byte of option data is specified -by an offset of zero. -.Pp -It is expected that each field is aligned on its natural boundaries as -described in Appendix B of RFC 2460. -.Pp -The function returns the offset for the next field -by calculating -.Fa offset -+ -.Fa vallen -which can be used when extracting option content with multiple fields. -Robust receivers must verify alignment before calling this function. -.\" -.Sh EXAMPLES -RFC 3542 gives comprehensive examples in Section 23. -KAME also provides examples in the -.Pa advapitest -directory of its kit. -.\" -.Sh DIAGNOSTICS -All the functions return -\-1 -on an error. -.\" -.Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%T "Advanced Sockets API for IPv6" -.%N RFC 3542 -.%D October 2002 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.Sh STANDARDS -The functions are documented in -.Dq Advanced Sockets API for IPv6 -.Pq RFC 3542 . -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. -.\" diff --git a/src/lib/libc/net/inet6_option_space.3 b/src/lib/libc/net/inet6_option_space.3 deleted file mode 100644 index 8aa79a6d0b..0000000000 --- a/src/lib/libc/net/inet6_option_space.3 +++ /dev/null @@ -1,444 +0,0 @@ -.\" $OpenBSD: inet6_option_space.3,v 1.21 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_option_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_OPTION_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_option_space , -.Nm inet6_option_init , -.Nm inet6_option_append , -.Nm inet6_option_alloc , -.Nm inet6_option_next , -.Nm inet6_option_find -.Nd IPv6 Hop-by-Hop and Destination Option Manipulation -.\" -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft "int" -.Fn inet6_option_space "int nbytes" -.Ft "int" -.Fn inet6_option_init "void *bp" "struct cmsghdr **cmsgp" "int type" -.Ft "int" -.Fn inet6_option_append "struct cmsghdr *cmsg" "const u_int8_t *typep" "int multx" "int plusy" -.Ft "u_int8_t *" -.Fn inet6_option_alloc "struct cmsghdr *cmsg" "int datalen" "int multx" "int plusy" -.Ft "int" -.Fn inet6_option_next "const struct cmsghdr *cmsg" "u_int8_t **tptrp" -.Ft "int" -.Fn inet6_option_find "const struct cmsghdr *cmsg" "u_int8_t **tptrp" "int type" -.\" -.Sh DESCRIPTION -.\" -Note: -RFC 2292 has been superseded by RFC 3542. -The use of functions described in this page is deprecated. -See -.Xr inet6_opt_init 3 . -.Pp -Manipulating and parsing IPv6's Hop-by-Hop and Destination options is -complicated by the need to properly align and pad data as well as the -need to manipulate ancillary information that is not part of the data -stream. -RFC 2292 defines a set of functions, which are implemented as -part of the Kame libraries, to help developers create, change, -and parse Hop-by-Hop and Destination options. -All of the prototypes -for the option functions are defined in the -.Aq Pa netinet/in.h -header file. -.\" -.Ss inet6_option_space -In order to determine the amount of space necessary to hold any option -the -.Fn inet6_option_space -function is called. -It returns the number of bytes required to hold -an option when it is stored as ancillary data, including the -.Li cmsghdr -structure at the beginning, and any necessary padding at the end. -The -.Fa nbytes -argument indicates the size of the structure defining the option, -and must include any pad bytes at the beginning (the value -.Li y -in the alignment term -.Dq Li "xn + y" ) , -the type byte, the length byte, and the option data. -.Pp -Note: If multiple options are stored in a single ancillary data -object, which is the recommended technique, the -.Fn inet6_option_space -function overestimates the amount of space required by the size of -.Li N-1 -.Li cmsghdr -structures, where -.Li N -is the number of options to be stored in the object. -Usually this has -no impact because it is assumed that most Hop-by-Hop and Destination -option headers carry only one option as indicated in appendix B of RFC 2460. -.\" -.Ss inet6_option_init -The -.Fn inet6_option_init -function is called to initialize any ancillary data object that will contain -a Hop-by-Hop or Destination option. -It returns -.Li 0 -on success and -.Li \-1 -when an error occurs. -.Pp -The -.Fa bp -argument points to a previously allocated area of memory which must be -large enough to contain all the arguments that the application intends -to add later via the -.Fn inet6_option_append -and -.Fn inet6_option_alloc -routines. -.Pp -The -.Fa cmsgp -argument is a pointer to a pointer to a -.Li cmsghdr -structure. -The -.Fa *cmsgp -argument -points to a -.Li cmsghdr -structure which is constructed by this function and stored in the -area of memory pointed to by -.Fa bp . -.Pp -The -.Fa type -is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS -and is stored in the -.Li cmsg_type -member of the -.Li cmsghdr -structure mentioned above. -.\" -.Ss inet6_option_append -This function appends a Hop-by-Hop option or a Destination option into -an ancillary data object previously initialized by a call to -.Fn inet6_option_init . -The -.Fn inet6_option_append -function returns -.Li 0 -if it succeeds or -.Li \-1 -when an error occurs. -.Pp -The -.Fa cmsg -argument is a pointer to the -.Li cmsghdr -structure that was initialized by a call to -.Fn inet6_option_init . -.Pp -The -.Fa typep -argument is a pointer to the 8-bit option type. -All options are -encoded as type-length-value tuples and it is assumed that -the -.Fa typep -field is immediately followed by the 8-bit option data length field, -which is then followed by the option data. -.Pp -The option types of -.Li 0 -and -.Li 1 -are reserved for the -.Li Pad1 -and -.Li PadN -options respectively. -All other values from -.Li 2 -through -.Li 255 -are available for applications to use. -.Pp -The option data length, since it is stored in 8 bites, must have a -value between -.Li 0 -and -.Li 255 , -inclusive. -.Pp -The -.Fa multx -argument -is the value -.Li x -in the alignment term -.Dq Li xn + y -and indicates the byte alignment necessary for the data. -Alignments may be specified as -.Li 1 , -.Li 2 , -.Li 4 , -or -.Li 8 -bytes, which is no alignment, 16-bit, 32-bit and 64-bit alignments -respectively. -.Pp -The -.Fa plusy -argument -is the value -.Li y -in the alignment term -.Dq Li xn + y -and must have a value between -.Li 0 -and -.Li 7 , -inclusive, indicating the amount of padding that is necessary for an -option. -.\" -.Ss inet6_option_alloc -The -.Fn inet6_option_alloc -function appends a Hop-by-Hop option or a Destination option into an -ancillary data object that has previously been initialized by a call to -.Fn inet6_option_init . -A successful call to the -.Fn inet6_option_alloc -function returns a pointer to the 8-bit option type field, -which is at the beginning of the allocated region. -.Fn inet6_option_alloc -returns -.Dv NULL -when an error has occurred. -.Pp -The difference between the -.Fn inet6_option_alloc -and -.Fn inet6_option_append -functions is that the latter copies the contents of a previously built -option into the ancillary data object while the former returns a -pointer to the place in the data object where the option's TLV must -then be built by the application. -.Pp -The -.Fa cmsg -argument is a pointer to a -.Li cmsghdr -structure that was initialized by -.Fn inet6_option_init . -.Pp -The -.Fa datalen -argument is the value of the option data length byte for this option. -This value is required as an argument to allow the function to -determine if padding must be appended at the end of the option. -(The -.Fn inet6_option_append -function does not need a data length argument -since the option data length must already be stored by the caller.) -.Pp -The -.Fa multx -and -.Fa plusy -arguments -are identical to the arguments of the same name described in the -.Fn inet6_option_init -function above. -.\" -.Ss inet6_option_next -The -.Fn inet6_option_next -function is used to process Hop-by-Hop and Destination options that -are present in an ancillary data object. -When an option remains to -be processed, the return value of the -.Fn inet6_option_next -function is -.Li 0 -and the -.Fa *tptrp -argument points to the 8-bit option type field, which is followed by -the 8-bit option data length, and then the option data. -When no more -options remain to be processed, the return value is -.Li \-1 -and -.Fa *tptrp -is -.Dv NULL . -When an error occurs, the return value is -.Li \-1 , -but the -.Fa *tptrp -argument is not -.Dv NULL . -This set of return values allows a program to easily loop through all -the options in an ancillary data object, checking for the error and -end of stream conditions along the way. -.Pp -When a valid option is returned, the -.Fa cmsg -argument points to a -.Li cmsghdr -where the -.Li cmsg_level -element equals -.Dv IPPROTO_IPV6 -and the -.Li cmsg_type -element is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is a pointer to a pointer to an 8-bit byte and -.Fa *tptrp -is used by the function to remember its place in the ancillary data -object each time the function is called. -When the -.Fn inet6_option_next -function is called for the first time on a given ancillary data object, -.Fa *tptrp -must be set to -.Dv NULL . -.Pp -Each time the function returns success, -the -.Fa *tptrp -argument points to the 8-bit option type field for the next option to -be processed. -.\" -.Ss inet6_option_find -The -.Fn inet6_option_find -function allows an application to search for a particular option type -in an ancillary data object. -The -.Fa cmsg -argument is a pointer to a -.Li cmsghdr -structure in which the -.Li cmsg_level -element equals -.Dv IPPROTO_IPV6 -and the -.Li cmsg_type -element is either -.Dv IPV6_HOPOPTS -or -.Dv IPV6_DSTOPTS . -.Pp -The -.Fa tptrp -argument is handled exactly as in the -.Fn inet6_option_next -function described above. -.Pp -The -.Fn inet6_option_find -function starts searching for an option of the specified type -beginning after the value of -.Fa *tptrp . -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 6. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_option_init -and -.Fn inet6_option_append -functions return -.Li 0 -on success or -.Li \-1 -on an error. -.Pp -The -.Fn inet6_option_alloc -function returns -.Dv NULL -on an error. -.Pp -When -.Fn inet6_option_next -or -.Fn inet6_option_find -detect an error they return -.Li \-1 , -setting -.Fa *tptrp -to a non -.Dv NULL -value. -.\" -.Sh SEE ALSO -.Xr inet6 4 , -.Xr ip6 4 -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh STANDARDS -The functions are documented in -.Dq Advanced Sockets API for IPv6 -(RFC 2292). -.\" -.Sh HISTORY -This implementation first appeared in the KAME advanced networking kit. -.\" diff --git a/src/lib/libc/net/inet6_rth_space.3 b/src/lib/libc/net/inet6_rth_space.3 deleted file mode 100644 index 326521def7..0000000000 --- a/src/lib/libc/net/inet6_rth_space.3 +++ /dev/null @@ -1,219 +0,0 @@ -.\" $OpenBSD: inet6_rth_space.3,v 1.3 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_RTH_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_rth_space , -.Nm inet6_rth_init , -.Nm inet6_rth_add , -.Nm inet6_rth_reverse , -.Nm inet6_rth_segments , -.Nm inet6_rth_getaddr -.Nd IPv6 Routing Header Options manipulation -.\" -.Sh SYNOPSIS -.In netinet/in.h -.Ft socklen_t -.Fn inet6_rth_space "int" "int" -.Ft "void *" -.Fn inet6_rth_init "void *" "socklen_t" "int" "int" -.Ft int -.Fn inet6_rth_add "void *" "const struct in6_addr *" -.Ft int -.Fn inet6_rth_reverse "const void *" "void *" -.Ft int -.Fn inet6_rth_segments "const void *" -.Ft "struct in6_addr *" -.Fn inet6_rth_getaddr "const void *" "int" -.\" -.Sh DESCRIPTION -The IPv6 Advanced API, RFC 3542, defines the functions that an -application calls to build and examine IPv6 Routing headers. -Routing headers are used to perform source routing in IPv6 networks. -The RFC uses the word -.Dq segments -to describe addresses and that is the term used here as well. -All of the functions are defined in the header file -.Aq Pa netinet/in.h . -The functions described in this manual page all operate -on routing header structures which are defined in -.Aq Pa netinet/ip6.h -but which should not need to be modified outside the use of this API. -The size and shape of the route header structures may change, so using -the APIs is a more portable, long term, solution. -.Pp -The functions in the API are split into two groups, those that build a -routing header and those that parse a received routing header. -The builder functions are described first, followed by the parser functions. -.Ss inet6_rth_space -The -.Fn inet6_rth_space -function returns the number of bytes required to hold a Routing Header -of the type, specified in the -.Fa type -argument and containing the number of addresses specified in the -.Fa segments -argument. -When the type is -.Dv IPV6_RTHDR_TYPE_0 -the number of segments must be from 0 through 127. -The return value from this function is the number of bytes required to -store the routing header. -If the value 0 is returned then either the -route header type was not recognized or another error occurred. -.Ss inet6_rth_init -The -.Fn inet6_rth_init -function initializes the pre-allocated buffer pointed to by -.Fa bp -to contain a routing header of the specified type. -The -.Fa bp_len -argument is used to verify that the buffer is large enough. -The caller must allocate the buffer pointed to by bp. -The necessary buffer size should be determined by calling -.Fn inet6_rth_space -described in the previous sections. -.Pp -The -.Fn inet6_rth_init -function returns a pointer to -.Fa bp -on success and -.Dv NULL -when there is an error. -.Ss inet6_rth_add -The -.Fn inet6_rth_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the routing header being constructed. -.Pp -A successful addition results in the function returning 0, otherwise -\-1 is returned. -.Ss inet6_rth_reverse -The -.Fn inet6_rth_reverse -function takes a routing header, pointed to by the -argument -.Fa in , -and writes a new routing header into the argument pointed to by -.Fa out . -The routing header at that sends datagrams along the reverse of that -route. -Both arguments are allowed to point to the same buffer meaning -that the reversal can occur in place. -.Pp -The return value of the function is 0 on success, or \-1 when -there is an error. -.\" -.Pp -The next set of functions operate on a routing header that the -application wants to parse. -In the usual case such a routing header -is received from the network, although these functions can also be -used with routing headers that the application itself created. -.Ss inet6_rth_segments -The -.Fn inet6_rth_segments -function returns the number of segments contained in the -routing header pointed to by -.Fa bp . -The return value is the number of segments contained in the routing -header, or \-1 if an error occurred. -It is not an error for 0 to be -returned as a routing header may contain 0 segments. -.\" -.Ss inet6_rth_getaddr -The -.Fn inet6_rth_getaddr -function is used to retrieve a single address from a routing header. -The -.Fa index -is the location in the routing header from which the application wants -to retrieve an address. -The -.Fa index -parameter must have a value between 0 and one less than the number of -segments present in the routing header. -The -.Fn inet6_rth_segments -function, described in the last section, should be used to determine -the total number of segments in the routing header. -The -.Fn inet6_rth_getaddr -function returns a pointer to an IPv6 address on success or -.Dv NULL -when an error has occurred. -.\" -.Sh EXAMPLES -RFC 3542 gives extensive examples in Section 21, Appendix B. -KAME also provides examples in the advapitest directory of its kit. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rth_space -and -.Fn inet6_rth_getaddr -functions return 0 on errors. -.Pp -The -.Fn inet6_rthdr_init -function returns -.Dv NULL -on error. -The -.Fn inet6_rth_add -and -.Fn inet6_rth_reverse -functions return 0 on success, or \-1 upon an error. -.\" -.Sh SEE ALSO -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%T "Advanced Sockets API for IPv6" -.%N RFC 3542 -.%D May 2003 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. diff --git a/src/lib/libc/net/inet6_rthdr_space.3 b/src/lib/libc/net/inet6_rthdr_space.3 deleted file mode 100644 index 3287bfe009..0000000000 --- a/src/lib/libc/net/inet6_rthdr_space.3 +++ /dev/null @@ -1,314 +0,0 @@ -.\" $OpenBSD: inet6_rthdr_space.3,v 1.20 2007/05/31 19:19:30 jmc Exp $ -.\" $KAME: inet6_rthdr_space.3,v 1.11 2005/01/05 03:00:44 itojun Exp $ -.\" -.\" Copyright (C) 2004 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt INET6_RTHDR_SPACE 3 -.Os -.\" -.Sh NAME -.Nm inet6_rthdr_space , -.Nm inet6_rthdr_init , -.Nm inet6_rthdr_add , -.Nm inet6_rthdr_lasthop , -.Nm inet6_rthdr_reverse , -.Nm inet6_rthdr_segments , -.Nm inet6_rthdr_getaddr , -.Nm inet6_rthdr_getflags -.Nd IPv6 Routing Header Options Manipulation -.\" -.Sh SYNOPSIS -.In sys/types.h -.In netinet/in.h -.Ft size_t -.Fn inet6_rthdr_space "int type" "int segments" -.Ft "struct cmsghdr *" -.Fn inet6_rthdr_init "void *bp" "int type" -.Ft int -.Fn inet6_rthdr_add "struct cmsghdr *cmsg" "const struct in6_addr *addr" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_lasthop "struct cmsghdr *cmsg" "unsigned int flags" -.Ft int -.Fn inet6_rthdr_reverse "const struct cmsghdr *in" "struct cmsghdr *out" -.Ft int -.Fn inet6_rthdr_segments "const struct cmsghdr *cmsg" -.Ft "struct in6_addr *" -.Fn inet6_rthdr_getaddr "struct cmsghdr *cmsg" "int index" -.Ft int -.Fn inet6_rthdr_getflags "const struct cmsghdr *cmsg" "int index" -.\" -.Sh DESCRIPTION -.\"The RFC 2292 IPv6 Advanced API has been deprecated in favor of the -.\"newer, RFC 3542 APIs. -.\"On platforms that support it, currently only -.\"FreeBSD, please use the newer API to manipulate routing header -.\"options. -.\".Pp -Note: -RFC 2292 has been superseded by RFC 3542. -The use of functions described in this page is deprecated. -See -.Xr inet6_rth_space 3 . -.Pp -The RFC 2292 IPv6 Advanced API defined eight functions for -applications to use for building and parsing routing headers. -The -eight functions are split into two groups, the first of which builds -the header and the second of which can parse it. -The function prototypes for these functions are all in the -.Aq Pa netinet/in.h -header. -Although direct manipulation of a routing header is possible, -this set of APIs make it unnecessary and such direct manipulation -should be avoided so that changes to the underlying structures do not -break applications. -.Pp -Please note that RFC 2292 uses the term -.Dq segments -instead of the term -.Dq addresses -but they are considered equivalent for this manual page. -.\" -.Ss inet6_rthdr_space -The -.Fn inet6_rthdr_space -function returns the number of bytes required to hold a routing header -of the specified -.Fa type -and containing the specified number of -.Fa segments . -Only one -.Fa type -is supported, -.Dv IPV6_RTHDR_TYPE_0 , -and it can hold from 1 to 23 segments. -The return value includes the -size of the -.Vt cmsghdr -structure that precedes the routing header and -any required padding. -.Pp -A return value of 0 indicates an error. -Either the type was specified -incorrectly, or the number of segments was less than one or greater -than 23. -.Pp -Note: The -.Fn inet6_rthdr_space -function only returns the size required by the routing header and does -not allocate memory for the caller. -.\" -.Ss inet6_rthdr_init -The -.Fn inet6_rthdr_init -function initializes a buffer, pointed to by -.Fa bp -with an appropriate -.Li cmsghdr -structure followed by a routing header of the specified -.Fa type . -.Pp -The caller must use the -.Fn inet6_rthdr_space -function to determine the size of the buffer, and then allocate that -buffer before calling -.Fn inet6_rthdr_init . -.Pp -The return value is a pointer to a -.Li cmsghdr -structure, which is used as the first argument to the -.Fn inet6_rthdr_add -and -.Fn inet6_rthdr_lasthop -functions in order to construct the routing header. -When an error occurs the return value is -.Dv NULL . -.\" -.Ss inet6_rthdr_add -The -.Fn inet6_rthdr_add -function adds the IPv6 address pointed to by -.Fa addr -to the end of the -routing header being constructed and sets the type of this address to the -value of -.Fa flags . -The -.Fa flags -must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing is required. -.Pp -When the function succeeds it returns 0, otherwise \-1 is returned. -.\" -.Ss inet6_rthdr_lasthop -The -.Fn inet6_rthdr_lasthop -function specifies the strict or loose flag for the final hop of a -routing header. -The -.Fa flags -argument must be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT . -.Pp -The return value of the function is 0 upon success, and \-1 when an -error has occurred. -.Pp -Please note that a routing header specifying -.Li N -intermediate nodes requires -.Li N+1 -strict or loose flags meaning that -.Fn inet6_rthdr_add -must be called -.Li N -times and then -.Fn inet6_rthdr_lasthop -must be called once. -.\" -.Ss inet6_rthdr_reverse -This function was never implemented. -.Pp -The following three functions provide an API for parsing a received -routing header: -.\" -.Ss inet6_rthdr_segments -The -.Fn inet6_rthdr_segments -function returns the number of segments contained in the routing -header pointed to by the -.Fa cmsg -argument. -On success the return value is from 1 to 23. -When an error occurs, \-1 is returned. -.\" -.Ss inet6_rthdr_getaddr -The -.Fn inet6_rthdr_getaddr -function returns a pointer to the IPv6 address specified by the -.Fa index -argument from the routing header pointed to by -.Fa cmsg . -The index must be between 1 and the number returned by -.Fn inet6_rthdr_segments , -described above. -An application must call -.Fn inet6_rthdr_segments -to obtain the number of segments in the routing header. -.Pp -If an error occurs, -.Dv NULL -is returned. -.\" -.Ss inet6_rthdr_getflags -The -.Fn inet6_rthdr_getflags -function returns the flags value of the segment specified by -.Fa index -of the routing header pointed to by -.Fa cmsg . -The -.Fa index -argument must be between 0 and the value returned by -.Fn inet6_rthdr_segments . -The return value will be either -.Dv IPV6_RTHDR_LOOSE -or -.Dv IPV6_RTHDR_STRICT -indicating whether loose or strict source routing was requested for -that segment. -.Pp -When an error occurs, \-1 is returned. -.Pp -Note: Flags begin at index 0 while segments begin at index 1, to -maintain consistency with the terminology and figures in RFC 2460. -.\" -.Sh EXAMPLES -RFC 2292 gives comprehensive examples in chapter 8. -.\" -.Sh DIAGNOSTICS -The -.Fn inet6_rthdr_space -function returns 0 when an error occurs. -.Pp -The -.Fn inet6_rthdr_add -and -.Fn inet6_rthdr_lasthop -functions return 0 on success, and \-1 on error. -.Pp -The -.Fn inet6_rthdr_init -and -.Fn inet6_rthdr_getaddr -functions -return -.Dv NULL -on error. -.Pp -The -.Fn inet6_rthdr_segments -and -.Fn inet6_rthdr_getflags -functions return \-1 on error. -.\" -.Sh SEE ALSO -.Xr inet6 4 , -.Xr ip6 4 -.Rs -.%A W. Stevens -.%A M. Thomas -.%T "Advanced Sockets API for IPv6" -.%N RFC 2292 -.%D February 1998 -.Re -.Rs -.%A S. Deering -.%A R. Hinden -.%T "Internet Protocol, Version 6 (IPv6) Specification" -.%N RFC 2460 -.%D December 1998 -.Re -.\" -.Sh HISTORY -This implementation first appeared in the KAME advanced networking kit. -.\" -.Sh BUGS -The -.Fn inet6_rthdr_reverse -function was never implemented. -.\".Pp -.\"This API is deprecated in favor of -.\".Xr inet6_rth_space 3 -.\".Sh SEE ALSO -.\".Xr inet6_rth_space 3 diff --git a/src/lib/libc/net/inet_addr.c b/src/lib/libc/net/inet_addr.c deleted file mode 100644 index c962a03382..0000000000 --- a/src/lib/libc/net/inet_addr.c +++ /dev/null @@ -1,171 +0,0 @@ -/* $OpenBSD: inet_addr.c,v 1.9 2005/08/06 20:30:03 espie Exp $ */ - -/* - * ++Copyright++ 1983, 1990, 1993 - * - - * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include -#include - -/* - * Ascii internet address interpretation routine. - * The value returned is in network order. - */ -in_addr_t -inet_addr(const char *cp) -{ - struct in_addr val; - - if (inet_aton(cp, &val)) - return (val.s_addr); - return (INADDR_NONE); -} - -/* - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ -int -inet_aton(const char *cp, struct in_addr *addr) -{ - in_addr_t val; - int base, n; - char c; - u_int parts[4]; - u_int *pp = parts; - - c = *cp; - for (;;) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if (!isdigit(c)) - return (0); - val = 0; base = 10; - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; - else - base = 8; - } - for (;;) { - if (isascii(c) && isdigit(c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; - } else - break; - } - if (c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if (pp >= parts + 3) - return (0); - *pp++ = val; - c = *++cp; - } else - break; - } - /* - * Check for trailing characters. - */ - if (c != '\0' && (!isascii(c) || !isspace(c))) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch (n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if ((val > 0xffffff) || (parts[0] > 0xff)) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if (addr) - addr->s_addr = htonl(val); - return (1); -} diff --git a/src/lib/libc/net/inet_lnaof.c b/src/lib/libc/net/inet_lnaof.c deleted file mode 100644 index b1a58cd2c1..0000000000 --- a/src/lib/libc/net/inet_lnaof.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: inet_lnaof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Return the local network address portion of an - * internet address; handles class a/b/c network - * number formats. - */ -in_addr_t -inet_lnaof(struct in_addr in) -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return ((i)&IN_CLASSA_HOST); - else if (IN_CLASSB(i)) - return ((i)&IN_CLASSB_HOST); - else - return ((i)&IN_CLASSC_HOST); -} diff --git a/src/lib/libc/net/inet_makeaddr.c b/src/lib/libc/net/inet_makeaddr.c deleted file mode 100644 index 87d9325231..0000000000 --- a/src/lib/libc/net/inet_makeaddr.c +++ /dev/null @@ -1,54 +0,0 @@ -/* $OpenBSD: inet_makeaddr.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Formulate an Internet address from network + host. Used in - * building addresses stored in the ifnet structure. - */ -struct in_addr -inet_makeaddr(in_addr_t net, in_addr_t host) -{ - in_addr_t addr; - - if (net < 128) - addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); - else if (net < 65536) - addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); - else if (net < 16777216L) - addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); - else - addr = net | host; - addr = htonl(addr); - return (*(struct in_addr *)&addr); -} diff --git a/src/lib/libc/net/inet_net.3 b/src/lib/libc/net/inet_net.3 deleted file mode 100644 index 648d82c780..0000000000 --- a/src/lib/libc/net/inet_net.3 +++ /dev/null @@ -1,176 +0,0 @@ -.\" $OpenBSD: inet_net.3,v 1.14 2008/06/26 05:42:05 ray Exp $ -.\" $NetBSD: inet_net.3,v 1.1 1997/06/18 02:25:27 lukem Exp $ -.\" -.\" Copyright (c) 1997 The NetBSD Foundation, Inc. -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Luke Mewburn. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE -.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: June 26 2008 $ -.Dt INET_NET 3 -.Os -.Sh NAME -.Nm inet_net_ntop , -.Nm inet_net_pton -.Nd Internet network number manipulation routines -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Fd #include -.Ft char * -.Fn inet_net_ntop "int af" "const void *src" "int bits" "char *dst" "size_t size" -.Ft int -.Fn inet_net_pton "int af" "const char *src" "void *dst" "size_t size" -.Sh DESCRIPTION -The -.Fn inet_net_ntop -function converts an Internet network number from network format (usually a -.Li struct in_addr -or some other binary form, in network byte order) to CIDR presentation format -(suitable for external display purposes). -.Fa bits -is the number of bits in -.Fa src -that are the network number. -It returns -.Dv NULL -if a system error occurs (in which case, -.Va errno -will have been set), or it returns a pointer to the destination string. -.Pp -The -.Fn inet_net_pton -function converts a presentation format Internet network number (that is, -printable form as held in a character string) to network format (usually a -.Li struct in_addr -or some other internal binary representation, in network byte order). -It returns the number of bits (either computed based on the class, or -specified with /CIDR), or \-1 if a failure occurred -(in which case -.Va errno -will have been set. -It will be set to -.Er ENOENT -if the Internet network number was not valid). -.Pp -Caution: -The -.Fa dst -field should be zeroed before calling -.Fn inet_net_pton -as the function will only fill the number of bytes necessary to -encode the network number in network byte order. -.Pp -The only value for -.Fa af -currently supported is -.Dv AF_INET . -.Fa size -is the size of the result buffer -.Fa dst . -.Sh NETWORK NUMBERS (IP VERSION 4) -The external representation of Internet network numbers may be specified in -one of the following forms: -.Bd -literal -offset indent -a -a.b -a.b.c -a.b.c.d -.Ed -.Pp -Any of the above four forms may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-32 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified the number of bits in the network address is calculated -as the larger of the number of bits in the class to which the address -belongs and the number of bits provided rounded up modulo 8. -Examples: -.Pp -.Bl -tag -width 10.1.2.3/24 -offset indent -compact -.It Li 10 -an 8-bit network number (class A), value -.Li 10.0.0.0 . -.It Li 192 -a 24-bit network number (class C), value -.Li 192.0.0.0 . -.It Li 10.10 -a 16-bit network number, value -.Li 10.10.0.0 . -.It Li 10.1.2 -a 24-bit network number, value -.Li 10.1.2.0 . -.It Li 10.1.2.3 -a 32-bit network number, value -.Li 10.1.2.3 . -.It Li 10.1.2.3/24 -a 24-bit network number (explicit), value -.Li 10.1.2.3 . -.El -.Pp -Note that when the number of bits is specified using -.Dq Li /bits -notation, the value of the address still includes all bits supplied -in the external representation, even those bits which are the host -part of an Internet address. -Also, unlike -.Xr inet_pton 3 -where the external representation is assumed to be a host address, the -external representation for -.Fn inet_net_pton -is assumed to be a network address. -Thus -.Dq Li 10.1 -is assumed to be -.Dq Li 10.1.0.0 -not -.Dq Li 10.0.0.1 -.Pp -All numbers supplied as -.Dq parts -in a -.Ql \&. -notation -may be decimal, octal, or hexadecimal, as specified -in the C language (i.e., a leading 0x or 0X implies -hexadecimal; otherwise, a leading 0 implies octal; -otherwise, the number is interpreted as decimal). -.Sh SEE ALSO -.Xr byteorder 3 , -.Xr inet 3 , -.Xr inet_pton 3 , -.Xr networks 5 -.Sh HISTORY -The -.Nm inet_net_ntop -and -.Nm inet_net_pton -functions first appeared in BIND 4.9.4. diff --git a/src/lib/libc/net/inet_net_ntop.c b/src/lib/libc/net/inet_net_ntop.c deleted file mode 100644 index fc9071798a..0000000000 --- a/src/lib/libc/net/inet_net_ntop.c +++ /dev/null @@ -1,135 +0,0 @@ -/* $OpenBSD: inet_net_ntop.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -static char *inet_net_ntop_ipv4(const u_char *, int, char *, size_t); - -/* - * char * - * inet_net_ntop(af, src, bits, dst, size) - * convert network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_ntop_ipv4(src, bits, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } -} - -/* - * static char * - * inet_net_ntop_ipv4(src, bits, dst, size) - * convert IPv4 network number from network to presentation format. - * generates CIDR style result always. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), July 1996 - */ -static char * -inet_net_ntop_ipv4(const u_char *src, int bits, char *dst, size_t size) -{ - char *odst = dst; - u_int m; - int b; - char *ep; - int advance; - - ep = dst + size; - if (ep <= dst) - goto emsgsize; - - if (bits < 0 || bits > 32) { - errno = EINVAL; - return (NULL); - } - if (bits == 0) { - if (ep - dst < sizeof "0") - goto emsgsize; - *dst++ = '0'; - *dst = '\0'; - } - - /* Format whole octets. */ - for (b = bits / 8; b > 0; b--) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", *src++); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (b > 1) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - - /* Format partial octet. */ - b = bits % 8; - if (b > 0) { - if (ep - dst < sizeof ".255") - goto emsgsize; - if (dst != odst) - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - m = ((1 << b) - 1) << (8 - b); - advance = snprintf(dst, ep - dst, "%u", *src & m); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - } - - /* Format CIDR /width. */ - if (ep - dst < sizeof "/32") - goto emsgsize; - advance = snprintf(dst, ep - dst, "/%u", bits); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/src/lib/libc/net/inet_net_pton.c b/src/lib/libc/net/inet_net_pton.c deleted file mode 100644 index 9bb35478ca..0000000000 --- a/src/lib/libc/net/inet_net_pton.c +++ /dev/null @@ -1,191 +0,0 @@ -/* $OpenBSD: inet_net_pton.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -static int inet_net_pton_ipv4(const char *, u_char *, size_t); - -/* - * static int - * inet_net_pton(af, src, dst, size) - * convert network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not a valid network specification. - * author: - * Paul Vixie (ISC), June 1996 - */ -int -inet_net_pton(int af, const char *src, void *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_net_pton_ipv4(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (-1); - } -} - -/* - * static int - * inet_net_pton_ipv4(src, dst, size) - * convert IPv4 network number from presentation to network format. - * accepts hex octets, hex strings, decimal octets, and /CIDR. - * "size" is in bytes and describes "dst". - * return: - * number of bits, either imputed classfully or specified with /CIDR, - * or -1 if some failure occurred (check errno). ENOENT means it was - * not an IPv4 network specification. - * note: - * network byte order assumed. this means 192.5.5.240/28 has - * 0x11110000 in its fourth octet. - * author: - * Paul Vixie (ISC), June 1996 - */ -static int -inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) -{ - static const char - xdigits[] = "0123456789abcdef", - digits[] = "0123456789"; - int n, ch, tmp, dirty, bits; - const u_char *odst = dst; - - ch = *src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii(src[1]) && isxdigit(src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size <= 0) - goto emsgsize; - *dst = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = *src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - *dst |= n; - if (!dirty++) - *dst <<= 4; - else if (size-- > 0) - *++dst = 0, dirty = 0; - else - goto emsgsize; - } - if (dirty) - size--; - } else if (isascii(ch) && isdigit(ch)) { - /* Decimal: eat dotted digit string. */ - for (;;) { - tmp = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - tmp *= 10; - tmp += n; - if (tmp > 255) - goto enoent; - } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (size-- <= 0) - goto emsgsize; - *dst++ = (u_char) tmp; - if (ch == '\0' || ch == '/') - break; - if (ch != '.') - goto enoent; - ch = *src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = *src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - } while ((ch = *src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - if (bits > 32) - goto emsgsize; - } - - /* Firey death and destruction unless we prefetched EOS. */ - if (ch != '\0') - goto enoent; - - /* If nothing was written to the destination, we found no address. */ - if (dst == odst) - goto enoent; - /* If no CIDR spec was given, infer width from net class. */ - if (bits == -1) { - if (*odst >= 240) /* Class E */ - bits = 32; - else if (*odst >= 224) /* Class D */ - bits = 4; - else if (*odst >= 192) /* Class C */ - bits = 24; - else if (*odst >= 128) /* Class B */ - bits = 16; - else /* Class A */ - bits = 8; - /* If imputed mask is narrower than specified octets, widen. */ - if (bits < ((dst - odst) * 8)) - bits = (dst - odst) * 8; - } - /* Extend network to cover the actual mask. */ - while (bits > ((dst - odst) * 8)) { - if (size-- <= 0) - goto emsgsize; - *dst++ = '\0'; - } - return (bits); - - enoent: - errno = ENOENT; - return (-1); - - emsgsize: - errno = EMSGSIZE; - return (-1); -} diff --git a/src/lib/libc/net/inet_neta.c b/src/lib/libc/net/inet_neta.c deleted file mode 100644 index e3e7d0eb71..0000000000 --- a/src/lib/libc/net/inet_neta.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $OpenBSD: inet_neta.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include - -#include -#include -#include - -/* - * char * - * inet_neta(src, dst, size) - * format an in_addr_t network number into presentation format. - * return: - * pointer to dst, or NULL if an error occurred (check errno). - * note: - * format of ``src'' is as for inet_network(). - * author: - * Paul Vixie (ISC), July 1996 - */ -char * -inet_neta(in_addr_t src, char *dst, size_t size) -{ - char *odst = dst; - char *ep; - int advance; - - if (src == 0x00000000) { - if (size < sizeof "0.0.0.0") - goto emsgsize; - strlcpy(dst, "0.0.0.0", size); - return dst; - } - ep = dst + size; - if (ep <= dst) - goto emsgsize; - while (src & 0xffffffff) { - u_char b = (src & 0xff000000) >> 24; - - src <<= 8; - if (b || src) { - if (ep - dst < sizeof "255.") - goto emsgsize; - advance = snprintf(dst, ep - dst, "%u", b); - if (advance <= 0 || advance >= ep - dst) - goto emsgsize; - dst += advance; - if (src != 0L) { - if (dst + 1 >= ep) - goto emsgsize; - *dst++ = '.'; - *dst = '\0'; - } - } - } - return (odst); - - emsgsize: - errno = EMSGSIZE; - return (NULL); -} diff --git a/src/lib/libc/net/inet_netof.c b/src/lib/libc/net/inet_netof.c deleted file mode 100644 index 2f468c3aca..0000000000 --- a/src/lib/libc/net/inet_netof.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: inet_netof.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Return the network number from an internet - * address; handles class a/b/c network #'s. - */ -in_addr_t -inet_netof(struct in_addr in) -{ - in_addr_t i = ntohl(in.s_addr); - - if (IN_CLASSA(i)) - return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); - else if (IN_CLASSB(i)) - return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); - else - return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); -} diff --git a/src/lib/libc/net/inet_network.c b/src/lib/libc/net/inet_network.c deleted file mode 100644 index 8b26ba8ff9..0000000000 --- a/src/lib/libc/net/inet_network.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: inet_network.c,v 1.10 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* - * Internet network address interpretation routine. - * The library routines call this routine to interpret - * network numbers. - */ -in_addr_t -inet_network(const char *cp) -{ - in_addr_t val, base, n; - char c; - in_addr_t parts[4], *pp = parts; - int i; - -again: - val = 0; base = 10; - if (*cp == '0') - base = 8, cp++; - if (*cp == 'x' || *cp == 'X') - base = 16, cp++; - while ((c = *cp)) { - if (isdigit(c)) { - val = (val * base) + (c - '0'); - cp++; - continue; - } - if (base == 16 && isxdigit(c)) { - val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); - cp++; - continue; - } - break; - } - if (*cp == '.') { - if (pp >= parts + 3) - return (INADDR_NONE); - *pp++ = val, cp++; - goto again; - } - if (*cp && !isspace(*cp)) - return (INADDR_NONE); - *pp++ = val; - n = pp - parts; - for (val = 0, i = 0; i < 4; i++) { - val <<= 8; - if (i < n) - val |= parts[i] & 0xff; - } - return (val); -} diff --git a/src/lib/libc/net/inet_ntoa.c b/src/lib/libc/net/inet_ntoa.c deleted file mode 100644 index ff5d93ded2..0000000000 --- a/src/lib/libc/net/inet_ntoa.c +++ /dev/null @@ -1,51 +0,0 @@ -/* $OpenBSD: inet_ntoa.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Convert network-format internet address - * to base 256 d.d.d.d representation. - */ -#include -#include -#include -#include - -char * -inet_ntoa(struct in_addr in) -{ - static char b[18]; - char *p; - - p = (char *)∈ -#define UC(b) (((int)b)&0xff) - (void)snprintf(b, sizeof(b), - "%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); - return (b); -} diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c deleted file mode 100644 index d36a0d7889..0000000000 --- a/src/lib/libc/net/inet_ntop.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $OpenBSD: inet_ntop.c,v 1.7 2005/08/06 20:30:03 espie Exp $ */ - -/* Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static const char *inet_ntop4(const u_char *src, char *dst, size_t size); -static const char *inet_ntop6(const u_char *src, char *dst, size_t size); - -/* char * - * inet_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -inet_ntop(int af, const void *src, char *dst, size_t size) -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); - case AF_INET6: - return (inet_ntop6(src, dst, size)); - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address, more or less like inet_ntoa() - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a u_char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const u_char *src, char *dst, size_t size) -{ - static const char fmt[] = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; - int l; - - l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]); - if (l <= 0 || l >= size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} - -/* const char * - * inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop6(const u_char *src, char *dst, size_t size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; - char *tp, *ep; - struct { int base, len; } best, cur; - u_int words[IN6ADDRSZ / INT16SZ]; - int i; - int advance; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - cur.base = -1; - for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - ep = tmp + sizeof(tmp); - for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, (size_t)(ep - tp))) - return (NULL); - tp += strlen(tp); - break; - } - advance = snprintf(tp, ep - tp, "%x", words[i]); - if (advance <= 0 || advance >= ep - tp) - return (NULL); - tp += advance; - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) { - if (tp + 1 >= ep) - return (NULL); - *tp++ = ':'; - } - if (tp + 1 >= ep) - return (NULL); - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - strlcpy(dst, tmp, size); - return (dst); -} diff --git a/src/lib/libc/net/inet_pton.c b/src/lib/libc/net/inet_pton.c deleted file mode 100644 index 096ff65772..0000000000 --- a/src/lib/libc/net/inet_pton.c +++ /dev/null @@ -1,212 +0,0 @@ -/* $OpenBSD: inet_pton.c,v 1.7 2006/12/30 23:37:37 itojun Exp $ */ - -/* Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static int inet_pton4(const char *src, u_char *dst); -static int inet_pton6(const char *src, u_char *dst); - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -int -inet_pton(int af, const char *src, void *dst) -{ - switch (af) { - case AF_INET: - return (inet_pton4(src, dst)); - case AF_INET6: - return (inet_pton6(src, dst)); - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, u_char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - u_char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - u_int new = *tp * 10 + (pch - digits); - - if (new > 255) - return (0); - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - *tp = new; - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - memcpy(dst, tmp, INADDRSZ); - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, u_char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit, count_xdigit; - u_int val; - - memset((tp = tmp), '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = count_xdigit = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - if (count_xdigit >= 4) - return (0); - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - count_xdigit++; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } else if (*src == '\0') { - return (0); - } - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - saw_xdigit = 0; - count_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - count_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (u_char) (val >> 8) & 0xff; - *tp++ = (u_char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; - - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); -} diff --git a/src/lib/libc/net/ip6opt.c b/src/lib/libc/net/ip6opt.c deleted file mode 100644 index b215f9ac3e..0000000000 --- a/src/lib/libc/net/ip6opt.c +++ /dev/null @@ -1,596 +0,0 @@ -/* $OpenBSD: ip6opt.c,v 1.4 2006/12/09 01:12:28 itojun Exp $ */ -/* $KAME: ip6opt.c,v 1.18 2005/06/15 07:11:35 keiichi Exp $ */ - -/* - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include -#include - -static int ip6optlen(u_int8_t *opt, u_int8_t *lim); -static void inet6_insert_padopt(u_char *p, int len); - -/* - * This function returns the number of bytes required to hold an option - * when it is stored as ancillary data, including the cmsghdr structure - * at the beginning, and any padding at the end (to make its size a - * multiple of 8 bytes). The argument is the size of the structure - * defining the option, which must include any pad bytes at the - * beginning (the value y in the alignment term "xn + y"), the type - * byte, the length byte, and the option data. - */ -int -inet6_option_space(int nbytes) -{ - nbytes += 2; /* we need space for nxt-hdr and length fields */ - return (CMSG_SPACE((nbytes + 7) & ~7)); -} - -/* - * This function is called once per ancillary data object that will - * contain either Hop-by-Hop or Destination options. It returns 0 on - * success or -1 on an error. - */ -int -inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type) -{ - struct cmsghdr *ch = (struct cmsghdr *)bp; - - /* argument validation */ - if (type != IPV6_HOPOPTS && type != IPV6_DSTOPTS) - return (-1); - - ch->cmsg_level = IPPROTO_IPV6; - ch->cmsg_type = type; - ch->cmsg_len = CMSG_LEN(0); - - *cmsgp = ch; - return (0); -} - -/* - * This function appends a Hop-by-Hop option or a Destination option - * into an ancillary data object that has been initialized by - * inet6_option_init(). This function returns 0 if it succeeds or -1 on - * an error. - * multx is the value x in the alignment term "xn + y" described - * earlier. It must have a value of 1, 2, 4, or 8. - * plusy is the value y in the alignment term "xn + y" described - * earlier. It must have a value between 0 and 7, inclusive. - */ -int -inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, int multx, - int plusy) -{ - int padlen, optlen, off; - u_char *bp = (u_char *)cmsg + cmsg->cmsg_len; - struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); - - /* argument validation */ - if (multx != 1 && multx != 2 && multx != 4 && multx != 8) - return (-1); - if (plusy < 0 || plusy > 7) - return (-1); -#if 0 - if (typep[0] > 255) - return (-1); -#endif - - /* - * If this is the first option, allocate space for the - * first 2 bytes(for next header and length fields) of - * the option header. - */ - if (bp == (u_char *)eh) { - bp += 2; - cmsg->cmsg_len += 2; - } - - /* calculate pad length before the option. */ - off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); - padlen += plusy; - padlen %= multx; /* keep the pad as short as possible */ - /* insert padding */ - inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; - bp += padlen; - - /* copy the option */ - if (typep[0] == IP6OPT_PAD1) - optlen = 1; - else - optlen = typep[1] + 2; - memcpy(bp, typep, optlen); - bp += optlen; - cmsg->cmsg_len += optlen; - - /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)eh; - padlen = ((off + 7) & ~7) - off; - inet6_insert_padopt(bp, padlen); - bp += padlen; - cmsg->cmsg_len += padlen; - - /* update the length field of the ip6 option header */ - eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; - - return (0); -} - -/* - * This function appends a Hop-by-Hop option or a Destination option - * into an ancillary data object that has been initialized by - * inet6_option_init(). This function returns a pointer to the 8-bit - * option type field that starts the option on success, or NULL on an - * error. - * The difference between this function and inet6_option_append() is - * that the latter copies the contents of a previously built option into - * the ancillary data object while the current function returns a - * pointer to the space in the data object where the option's TLV must - * then be built by the caller. - * - */ -u_int8_t * -inet6_option_alloc(struct cmsghdr *cmsg, int datalen, int multx, int plusy) -{ - int padlen, off; - u_int8_t *bp = (u_char *)cmsg + cmsg->cmsg_len; - u_int8_t *retval; - struct ip6_ext *eh = (struct ip6_ext *)CMSG_DATA(cmsg); - - /* argument validation */ - if (multx != 1 && multx != 2 && multx != 4 && multx != 8) - return (NULL); - if (plusy < 0 || plusy > 7) - return (NULL); - - /* - * If this is the first option, allocate space for the - * first 2 bytes(for next header and length fields) of - * the option header. - */ - if (bp == (u_char *)eh) { - bp += 2; - cmsg->cmsg_len += 2; - } - - /* calculate pad length before the option. */ - off = bp - (u_char *)eh; - padlen = (((off % multx) + (multx - 1)) & ~(multx - 1)) - - (off % multx); - padlen += plusy; - padlen %= multx; /* keep the pad as short as possible */ - /* insert padding */ - inet6_insert_padopt(bp, padlen); - cmsg->cmsg_len += padlen; - bp += padlen; - - /* keep space to store specified length of data */ - retval = bp; - bp += datalen; - cmsg->cmsg_len += datalen; - - /* calculate pad length after the option and insert the padding */ - off = bp - (u_char *)eh; - padlen = ((off + 7) & ~7) - off; - inet6_insert_padopt(bp, padlen); - bp += padlen; - cmsg->cmsg_len += padlen; - - /* update the length field of the ip6 option header */ - eh->ip6e_len = ((bp - (u_char *)eh) >> 3) - 1; - - return (retval); -} - -/* - * This function processes the next Hop-by-Hop option or Destination - * option in an ancillary data object. If another option remains to be - * processed, the return value of the function is 0 and *tptrp points to - * the 8-bit option type field (which is followed by the 8-bit option - * data length, followed by the option data). If no more options remain - * to be processed, the return value is -1 and *tptrp is NULL. If an - * error occurs, the return value is -1 and *tptrp is not NULL. - * (RFC 2292, 6.3.5) - */ -int -inet6_option_next(const struct cmsghdr *cmsg, u_int8_t **tptrp) -{ - struct ip6_ext *ip6e; - int hdrlen, optlen; - u_int8_t *lim; - - if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) - return (-1); - - /* message length validation */ - if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) - return (-1); - ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); - hdrlen = (ip6e->ip6e_len + 1) << 3; - if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) - return (-1); - - /* - * If the caller does not specify the starting point, - * simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - lim = (u_int8_t *)ip6e + hdrlen; - if (*tptrp == NULL) - *tptrp = (u_int8_t *)(ip6e + 1); - else { - if ((optlen = ip6optlen(*tptrp, lim)) == 0) - return (-1); - - *tptrp = *tptrp + optlen; - } - if (*tptrp >= lim) { /* there is no option */ - *tptrp = NULL; - return (-1); - } - /* - * Finally, checks if the next option is safely stored in the - * cmsg data. - */ - if (ip6optlen(*tptrp, lim) == 0) - return (-1); - else - return (0); -} - -/* - * This function is similar to the inet6_option_next() function, - * except this function lets the caller specify the option type to be - * searched for, instead of always returning the next option in the - * ancillary data object. - * Note: RFC 2292 says the type of tptrp is u_int8_t *, but we think - * it's a typo. The variable should be type of u_int8_t **. - */ -int -inet6_option_find(const struct cmsghdr *cmsg, u_int8_t **tptrp, int type) -{ - struct ip6_ext *ip6e; - int hdrlen, optlen; - u_int8_t *optp, *lim; - - if (cmsg->cmsg_level != IPPROTO_IPV6 || - (cmsg->cmsg_type != IPV6_HOPOPTS && - cmsg->cmsg_type != IPV6_DSTOPTS)) - return (-1); - - /* message length validation */ - if (cmsg->cmsg_len < CMSG_SPACE(sizeof(struct ip6_ext))) - return (-1); - ip6e = (struct ip6_ext *)CMSG_DATA(cmsg); - hdrlen = (ip6e->ip6e_len + 1) << 3; - if (cmsg->cmsg_len < CMSG_SPACE(hdrlen)) - return (-1); - - /* - * If the caller does not specify the starting point, - * search from the beginning of the option list. - * Otherwise, search from *the next option* of the specified point. - */ - lim = (u_int8_t *)ip6e + hdrlen; - if (*tptrp == NULL) - *tptrp = (u_int8_t *)(ip6e + 1); - else { - if ((optlen = ip6optlen(*tptrp, lim)) == 0) - return (-1); - - *tptrp = *tptrp + optlen; - } - for (optp = *tptrp; optp < lim; optp += optlen) { - if (*optp == type) { - *tptrp = optp; - return (0); - } - if ((optlen = ip6optlen(optp, lim)) == 0) - return (-1); - } - - /* search failed */ - *tptrp = NULL; - return (-1); -} - -/* - * Calculate the length of a given IPv6 option. Also checks - * if the option is safely stored in user's buffer according to the - * calculated length and the limitation of the buffer. - */ -static int -ip6optlen(u_int8_t *opt, u_int8_t *lim) -{ - int optlen; - - if (*opt == IP6OPT_PAD1) - optlen = 1; - else { - /* is there enough space to store type and len? */ - if (opt + 2 > lim) - return (0); - optlen = *(opt + 1) + 2; - } - if (opt + optlen <= lim) - return (optlen); - - return (0); -} - -static void -inet6_insert_padopt(u_char *p, int len) -{ - switch(len) { - case 0: - return; - case 1: - p[0] = IP6OPT_PAD1; - return; - default: - p[0] = IP6OPT_PADN; - p[1] = len - 2; - memset(&p[2], 0, len - 2); - return; - } -} - -/* - * The following functions are defined in RFC3542, which is a successor - * of RFC2292. - */ - -int -inet6_opt_init(void *extbuf, socklen_t extlen) -{ - struct ip6_ext *ext = (struct ip6_ext *)extbuf; - - if (extlen < 0 || (extlen % 8)) - return (-1); - - if (ext) { - if (extlen == 0) - return (-1); - ext->ip6e_len = (extlen >> 3) - 1; - } - - return (2); /* sizeof the next and the length fields */ -} - -int -inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t len, u_int8_t align, void **databufp) -{ - int currentlen = offset, padlen = 0; - - /* - * The option type must have a value from 2 to 255, inclusive. - * (0 and 1 are reserved for the Pad1 and PadN options, respectively.) - */ -#if 0 /* always false */ - if (type < 2 || type > 255) -#else - if (type < 2) -#endif - return (-1); - - /* - * The option data length must have a value between 0 and 255, - * inclusive, and is the length of the option data that follows. - */ - if (len < 0 || len > 255) - return (-1); - - /* - * The align parameter must have a value of 1, 2, 4, or 8. - * The align value can not exceed the value of len. - */ - if (align != 1 && align != 2 && align != 4 && align != 8) - return (-1); - if (align > len) - return (-1); - - /* Calculate the padding length. */ - currentlen += 2 + len; /* 2 means "type + len" */ - if (currentlen % align) - padlen = align - (currentlen % align); - - /* The option must fit in the extension header buffer. */ - currentlen += padlen; - if (extlen && /* XXX: right? */ - currentlen > extlen) - return (-1); - - if (extbuf) { - u_int8_t *optp = (u_int8_t *)extbuf + offset; - - if (padlen == 1) { - /* insert a Pad1 option */ - *optp = IP6OPT_PAD1; - optp++; - } else if (padlen > 0) { - /* insert a PadN option for alignment */ - *optp++ = IP6OPT_PADN; - *optp++ = padlen - 2; - memset(optp, 0, padlen - 2); - optp += (padlen - 2); - } - - *optp++ = type; - *optp++ = len; - - *databufp = optp; - } - - return (currentlen); -} - -int -inet6_opt_finish(void *extbuf, socklen_t extlen, int offset) -{ - int updatelen = offset > 0 ? (1 + ((offset - 1) | 7)) : 0;; - - if (extbuf) { - u_int8_t *padp; - int padlen = updatelen - offset; - - if (updatelen > extlen) - return (-1); - - padp = (u_int8_t *)extbuf + offset; - if (padlen == 1) - *padp = IP6OPT_PAD1; - else if (padlen > 0) { - *padp++ = IP6OPT_PADN; - *padp++ = (padlen - 2); - memset(padp, 0, padlen - 2); - } - } - - return (updatelen); -} - -int -inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - memcpy((u_int8_t *)databuf + offset, val, vallen); - return (offset + vallen); -} - -int -inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the next option skipping any padding options. */ - while (optp < lim) { - switch(*optp) { - case IP6OPT_PAD1: - optp++; - break; - case IP6OPT_PADN: - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - optp += optlen; - break; - default: /* found */ - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - *typep = *optp; - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, - socklen_t *lenp, void **databufp) -{ - u_int8_t *optp, *lim; - int optlen; - - /* Validate extlen. XXX: is the variable really necessary?? */ - if (extlen == 0 || (extlen % 8)) - return (-1); - lim = (u_int8_t *)extbuf + extlen; - - /* - * If this is the first time this function called for this options - * header, simply return the 1st option. - * Otherwise, search the option list for the next option. - */ - if (offset == 0) - optp = (u_int8_t *)((struct ip6_hbh *)extbuf + 1); - else - optp = (u_int8_t *)extbuf + offset; - - /* Find the specified option */ - while (optp < lim) { - if ((optlen = ip6optlen(optp, lim)) == 0) - goto optend; - - if (*optp == type) { /* found */ - *lenp = optlen - 2; - *databufp = optp + 2; - return (optp + optlen - (u_int8_t *)extbuf); - } - - optp += optlen; - } - - optend: - *databufp = NULL; /* for safety */ - return (-1); -} - -int -inet6_opt_get_val(void *databuf, int offset, void *val, socklen_t vallen) -{ - - /* we can't assume alignment here */ - memcpy(val, (u_int8_t *)databuf + offset, vallen); - - return (offset + vallen); -} diff --git a/src/lib/libc/net/link_addr.3 b/src/lib/libc/net/link_addr.3 deleted file mode 100644 index e6210ef2d0..0000000000 --- a/src/lib/libc/net/link_addr.3 +++ /dev/null @@ -1,127 +0,0 @@ -.\" $OpenBSD: link_addr.3,v 1.12 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Donn Seeley at BSDI. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt LINK_ADDR 3 -.Os -.Sh NAME -.Nm link_addr , -.Nm link_ntoa -.Nd elementary address specification routines for link level access -.Sh SYNOPSIS -.Fd #include -.Fd #include -.Fd #include -.Ft void -.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The -.Fn link_addr -function interprets character strings representing -link-level addresses, returning binary information suitable -for use in system calls. -.Fn link_ntoa -takes -a link-level -address and returns an -.Tn ASCII -string representing some of the information present, -including the link level address itself, and the interface name -or number, if present. -This facility is experimental and is -still subject to change. -.Pp -For -.Fn link_addr , -the string -.Fa addr -may contain -an optional network interface identifier of the form -.Dq name unit-number , -suitable for the first argument to -.Xr ifconfig 8 , -followed in all cases by a colon and -an interface address in the form of -groups of hexadecimal digits -separated by periods. -Each group represents a byte of address; -address bytes are filled left to right from -low order bytes through high order bytes. -.Pp -.\" A regular expression may make this format clearer: -.\" .Bd -literal -offset indent -.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* -.\" .Ed -.\" .Pp -Thus -.Li le0:8.0.9.13.d.30 -represents an Ethernet address -to be transmitted on the first Lance Ethernet interface. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a NUL-terminated string. -.Fn link_addr -has no return value. -(See -.Sx BUGS . ) -.Sh SEE ALSO -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn link_addr -and -.Fn link_ntoa -functions appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for -.Fn link_ntoa -reside in a static memory area. -.Pp -The function -.Fn link_addr -should diagnose improperly formed input, and there should be an unambiguous -way to recognize this. -.Pp -If the -.Fa sdl_len -field of the link socket address -.Fa sdl -is 0, -.Fn link_ntoa -will not insert a colon before the interface address bytes. -If this translated address is given to -.Fn link_addr -without inserting an initial colon, -the latter will not interpret it correctly. diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c deleted file mode 100644 index ac96f3acdf..0000000000 --- a/src/lib/libc/net/linkaddr.c +++ /dev/null @@ -1,148 +0,0 @@ -/* $OpenBSD: linkaddr.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* States*/ -#define NAMING 0 -#define GOTONE 1 -#define GOTTWO 2 -#define RESET 3 -/* Inputs */ -#define DIGIT (4*0) -#define END (4*1) -#define DELIM (4*2) -#define LETTER (4*3) - -void -link_addr(const char *addr, struct sockaddr_dl *sdl) -{ - char *cp = sdl->sdl_data; - char *cplim = sdl->sdl_len + (char *)sdl; - int byte = 0, state = NAMING, new; - - bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); - sdl->sdl_family = AF_LINK; - do { - state &= ~LETTER; - if ((*addr >= '0') && (*addr <= '9')) { - new = *addr - '0'; - } else if ((*addr >= 'a') && (*addr <= 'f')) { - new = *addr - 'a' + 10; - } else if ((*addr >= 'A') && (*addr <= 'F')) { - new = *addr - 'A' + 10; - } else if (*addr == 0) { - state |= END; - } else if (state == NAMING && - (((*addr >= 'A') && (*addr <= 'Z')) || - ((*addr >= 'a') && (*addr <= 'z')))) - state |= LETTER; - else - state |= DELIM; - addr++; - switch (state /* | INPUT */) { - case NAMING | DIGIT: - case NAMING | LETTER: - *cp++ = addr[-1]; - continue; - case NAMING | DELIM: - state = RESET; - sdl->sdl_nlen = cp - sdl->sdl_data; - continue; - case GOTTWO | DIGIT: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | DIGIT: - state = GOTONE; - byte = new; - continue; - case GOTONE | DIGIT: - state = GOTTWO; - byte = new + (byte << 4); - continue; - default: /* | DELIM */ - state = RESET; - *cp++ = byte; - byte = 0; - continue; - case GOTONE | END: - case GOTTWO | END: - *cp++ = byte; - /* FALLTHROUGH */ - case RESET | END: - break; - } - break; - } while (cp < cplim); - sdl->sdl_alen = cp - LLADDR(sdl); - new = cp - (char *)sdl; - if (new > sizeof(*sdl)) - sdl->sdl_len = new; - return; -} - -static char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(const struct sockaddr_dl *sdl) -{ - static char obuf[64]; - char *out = obuf; - int i; - u_char *in = (u_char *)LLADDR(sdl); - u_char *inlim = in + sdl->sdl_alen; - int firsttime = 1; - - if (sdl->sdl_nlen) { - bcopy(sdl->sdl_data, obuf, sdl->sdl_nlen); - out += sdl->sdl_nlen; - if (sdl->sdl_alen) - *out++ = ':'; - } - while (in < inlim) { - if (firsttime) - firsttime = 0; - else - *out++ = '.'; - i = *in++; - if (i > 0xf) { - out[1] = hexlist[i & 0xf]; - i >>= 4; - out[0] = hexlist[i]; - out += 2; - } else - *out++ = hexlist[i]; - } - *out = 0; - return (obuf); -} diff --git a/src/lib/libc/net/net_addrcmp.3 b/src/lib/libc/net/net_addrcmp.3 deleted file mode 100644 index a02e6e2619..0000000000 --- a/src/lib/libc/net/net_addrcmp.3 +++ /dev/null @@ -1,91 +0,0 @@ -.\" $OpenBSD: net_addrcmp.3,v 1.4 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1999 Theo de Raadt -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt NET_ADDRCMP 3 -.Os -.Sh NAME -.Nm net_addrcmp -.Nd compare socket address structures -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn net_addrcmp "struct sockaddr *sa1" "struct sockaddr *sa2" -.Sh DESCRIPTION -The -.Fn net_addrcmp -function compares two socket address structures, -.Fa sa1 -and -.Fa sa2 . -.Sh RETURN VALUES -If -.Fa sa1 -and -.Fa sa2 -are for the same address, -.Fn net_addrcmp -returns 0. -.Pp -The -.Fa sa_len -fields are compared first. -If they do not match, -.Fn net_addrcmp -returns \-1 or 1 if -.Li sa1->sa_len -is less than or greater than -.Li sa2->sa_len , -respectively. -.Pp -Next, the -.Fa sa_family -members are compared. -If they do not match, -.Fn net_addrcmp -returns \-1 or 1 if -.Li sa1->sa_family -is less than or greater than -.Li sa2->sa_family , -respectively. -.Pp -Lastly, if each socket address structure's -.Fa sa_len -and -.Fa sa_family -fields match, -the protocol-specific data (the -.Fa sa_data -field) is compared. -If there's a match, both -.Fa sa1 -and -.Fa sa2 -must refer to the same address, and 0 is returned; otherwise, a value >0 -or <0 is returned. -.Sh HISTORY -A -.Fn net_addrcmp -function was added in -.Ox 2.5 . diff --git a/src/lib/libc/net/net_addrcmp.c b/src/lib/libc/net/net_addrcmp.c deleted file mode 100644 index c2630a5265..0000000000 --- a/src/lib/libc/net/net_addrcmp.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD: net_addrcmp.c,v 1.10 2005/06/17 20:36:16 henning Exp $ */ - -/* - * Copyright (c) 1999 Theo de Raadt - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -int -net_addrcmp(struct sockaddr *sa1, struct sockaddr *sa2) -{ - - if (sa1->sa_len != sa2->sa_len) - return (sa1->sa_len < sa2->sa_len) ? -1 : 1; - if (sa1->sa_family != sa2->sa_family) - return (sa1->sa_family < sa2->sa_family) ? -1 : 1; - - switch(sa1->sa_family) { - case AF_INET: - return (memcmp(&((struct sockaddr_in *)sa1)->sin_addr, - &((struct sockaddr_in *)sa2)->sin_addr, - sizeof(struct in_addr))); - case AF_INET6: - if (((struct sockaddr_in6 *)sa1)->sin6_scope_id != - ((struct sockaddr_in6 *)sa2)->sin6_scope_id) - return (((struct sockaddr_in6 *)sa1)->sin6_scope_id < - ((struct sockaddr_in6 *)sa2)->sin6_scope_id) - ? -1 : 1; - return memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr, - &((struct sockaddr_in6 *)sa2)->sin6_addr, - sizeof(struct in6_addr)); - case AF_LOCAL: - return (strcmp(((struct sockaddr_un *)sa1)->sun_path, - ((struct sockaddr_un *)sa1)->sun_path)); - default: - return -1; - } -} diff --git a/src/lib/libc/net/nsap_addr.c b/src/lib/libc/net/nsap_addr.c deleted file mode 100644 index 8cfe86f475..0000000000 --- a/src/lib/libc/net/nsap_addr.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: nsap_addr.c,v 1.7 2006/03/31 05:35:44 deraadt Exp $ */ - -/* - * Copyright (c) 1996 by Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS - * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE - * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include - -static u_char -xtob(int c) -{ - return (c - (((c >= '0') && (c <= '9')) ? '0' : '7')); -} - -u_int -inet_nsap_addr(const char *ascii, u_char *binary, int maxlen) -{ - u_char c, nib; - u_int len = 0; - - while ((c = *ascii++) != '\0' && len < maxlen) { - if (c == '.' || c == '+' || c == '/') - continue; - if (!isascii(c)) - return (0); - if (islower(c)) - c = (u_char)toupper(c); - if (isxdigit(c)) { - nib = xtob(c); - if ((c = *ascii++)) { - c = (u_char)toupper(c); - if (isxdigit(c)) { - *binary++ = (nib << 4) | xtob(c); - len++; - } else - return (0); - } - else - return (0); - } - else - return (0); - } - return (len); -} - -char * -inet_nsap_ntoa(int binlen, const u_char *binary, char *ascii) -{ - int nib; - int i; - static char tmpbuf[255*3]; - char *start; - - if (ascii) - start = ascii; - else { - ascii = tmpbuf; - start = tmpbuf; - } - - if (binlen > 255) - binlen = 255; - - for (i = 0; i < binlen; i++) { - nib = *binary >> 4; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - nib = *binary++ & 0x0f; - *ascii++ = nib + (nib < 10 ? '0' : '7'); - if (((i % 2) == 0 && (i + 1) < binlen)) - *ascii++ = '.'; - } - *ascii = '\0'; - return (start); -} diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c deleted file mode 100644 index 36414b7a13..0000000000 --- a/src/lib/libc/net/ntohl.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: ntohl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef ntohl - -u_int32_t -ntohl(u_int32_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *)&x; - return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c deleted file mode 100644 index 8f345e84ad..0000000000 --- a/src/lib/libc/net/ntohs.c +++ /dev/null @@ -1,21 +0,0 @@ -/* $OpenBSD: ntohs.c,v 1.8 2005/08/06 20:30:03 espie Exp $ */ -/* - * Written by J.T. Conklin . - * Public domain. - */ - -#include -#include - -#undef ntohs - -u_int16_t -ntohs(u_int16_t x) -{ -#if BYTE_ORDER == LITTLE_ENDIAN - u_char *s = (u_char *) &x; - return (u_int16_t)(s[0] << 8 | s[1]); -#else - return x; -#endif -} diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 deleted file mode 100644 index 87e9a760a8..0000000000 --- a/src/lib/libc/net/rcmd.3 +++ /dev/null @@ -1,266 +0,0 @@ -.\" $OpenBSD: rcmd.3,v 1.27 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt RCMD 3 -.Os -.Sh NAME -.Nm rcmd , -.Nm rcmd_af , -.Nm rresvport , -.Nm rresvport_af , -.Nm iruserok , -.Nm ruserok , -.Nm iruserok_sa -.Nd routines for returning a stream to a remote command -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" -.Ft int -.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" -.Ft int -.Fn rresvport "int *port" -.Ft int -.Fn rresvport_af "int *port" "int af" -.Ft int -.Fn iruserok "u_int32_t raddr" "int superuser" "const char *ruser" "const char *luser" -.Ft int -.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" -.Ft int -.Fn iruserok_sa "const void *sa" "int salen" "int superuser" "const char *ruser" "const char *luser" -.Sh DESCRIPTION -The -.Fn rcmd -function is used by the superuser to execute a command on a remote -machine using an authentication scheme based on reserved -port numbers. -If the calling process is not setuid, the -.Ev RSH -environment variable is set, and -.Fa inport -is -.Dq shell/tcp , -.Xr rcmdsh 3 -is called instead with the value of -.Ev RSH . -Alternately, if the user is not the superuser, -.Fn rcmd -will invoke -.Xr rcmdsh 3 -to run the command via -.Xr rsh 1 . -While -.Fn rcmd -can handle IPv4 cases only, -the -.Fn rcmd_af -function can handle other cases as well. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a descriptor to a socket -with an address in the privileged port space. -The -.Fn iruserok -and -.Fn ruserok -functions are used by servers -to authenticate clients requesting service with -.Fn rcmd . -All four functions are present in the same file and are used -by the -.Xr rshd 8 -server (among others). -.Fn iruserok_sa -is an address family independent variant of -.Fn iruserok . -.Pp -The -.Fn rcmd -function looks up the host -.Fa *ahost -using -.Xr gethostbyname 3 , -returning \-1 if the host does not exist. -Otherwise -.Fa *ahost -is set to the standard name of the host -and a connection is established to a server -residing at the well-known Internet port -.Fa inport . -If the user is not the superuser, the only valid port is -.Dq shell/tcp -(usually port 514). -.Pp -If the connection succeeds, -a socket in the Internet domain of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout. -If -.Fa fd2p -is non-zero, then an auxiliary channel to a control -process will be set up, and a descriptor for it will be placed -in -.Fa *fd2p . -The control process will return diagnostic -output from the command (unit 2) on this channel, and will also -accept bytes on this channel as being -.Tn UNIX -signal numbers, to be -forwarded to the process group of the command. -If -.Fa fd2p -is -.Va NULL , -then the standard error (unit 2 of the remote command) will be made -the same as the standard output and no provision is made for sending -arbitrary signals to the remote process, although you may be able to -get its attention by using out-of-band data. -Note that if the user is not the superuser, -.Fa fd2p -must be -.Va NULL . -.Pp -.Fn rcmd_af -takes address family in the last argument. -If the last argument is -.Dv PF_UNSPEC , -interpretation of -.Fa *ahost -will obey the underlying address resolution like DNS. -.Pp -The protocol is described in detail in -.Xr rshd 8 . -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions are used to obtain a socket with a privileged -address bound to it. -This socket is suitable for use by -.Fn rcmd -and several other functions. -Privileged Internet ports are those in the range 0 to -.Va IPPORT_RESERVED - 1 , -which happens to be 1023. -Only the superuser is allowed to bind an address of this sort to a socket. -.Fn rresvport -and -.Fn rresvport_af -need to be seeded with a port number; if that port -is not available these functions will find another. -.Pp -The -.Fn iruserok -and -.Fn ruserok -functions take a remote host's IP address or name, respectively, -two user names and a flag indicating whether the local user's -name is that of the superuser. -Then, if the user is -.Em not -the superuser, it checks the -.Pa /etc/hosts.equiv -file. -If that lookup is not done, or is unsuccessful, the -.Pa .rhosts -in the local user's home directory is checked to see if the request for -service is allowed. -.Pp -If this file does not exist, is not a regular file, is owned by anyone -other than the user or the superuser, or is writeable by anyone other -than the owner, the check automatically fails. -Zero is returned if the machine name is listed in the -.Pa hosts.equiv -file, or the host and remote user name are found in the -.Pa .rhosts -file; otherwise -.Fn iruserok -and -.Fn ruserok -return \-1. -If the local domain (as obtained from -.Xr gethostname 3 ) -is the same as the remote domain, only the machine name need be specified. -.Pp -If the IP address of the remote host is known, -.Fn iruserok -should be used in preference to -.Fn ruserok , -as it does not require trusting the DNS server for the remote host's domain. -.Pp -While -.Fn iruserok -can handle IPv4 addresses only, -.Fn iruserok_sa -and -.Fn ruserok -can handle other address families as well, like IPv6. -The first argument of -.Fn iruserok_sa -is typed as -.Li "void *" -to avoid dependency between -.Aq Pa unistd.h -and -.Aq Pa sys/socket.h . -.Sh DIAGNOSTICS -The -.Fn rcmd -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Pp -The -.Fn rresvport -and -.Fn rresvport_af -functions return a valid, bound socket descriptor on success. -It returns \-1 on error with the global value -.Va errno -set according to the reason for failure. -The error code -.Er EAGAIN -is overloaded to mean -.Dq all network ports in use . -.Sh SEE ALSO -.Xr rsh 1 , -.Xr intro 2 , -.Xr bindresvport 3 , -.Xr bindresvport_sa 3 , -.Xr rcmdsh 3 , -.Xr rshd 8 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c deleted file mode 100644 index 30ca6710c4..0000000000 --- a/src/lib/libc/net/rcmd.c +++ /dev/null @@ -1,691 +0,0 @@ -/* - * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. - * Copyright (c) 1983, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int __ivaliduser(FILE *, in_addr_t, const char *, const char *); -int __ivaliduser_sa(FILE *, struct sockaddr *, socklen_t, - const char *, const char *); -static int __icheckhost(struct sockaddr *, socklen_t, const char *); -static char *__gethostloop(struct sockaddr *, socklen_t); - -int -rcmd(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, int *fd2p) -{ - return rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, AF_INET); -} - -int -rcmd_af(char **ahost, int porta, const char *locuser, const char *remuser, - const char *cmd, int *fd2p, int af) -{ - static char hbuf[MAXHOSTNAMELEN]; - char pbuf[NI_MAXSERV]; - struct addrinfo hints, *res, *r; - int error; - struct sockaddr_storage from; - fd_set *readsp = NULL; - sigset_t oldmask, mask; - pid_t pid; - int s, lport, timo; - char c, *p; - int refused; - in_port_t rport = porta; - - /* call rcmdsh() with specified remote shell if appropriate. */ - if (!issetugid() && (p = getenv("RSH")) && *p) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, p)); - } - - /* use rsh(1) if non-root and remote port is shell. */ - if (geteuid()) { - struct servent *sp = getservbyname("shell", "tcp"); - - if (sp && sp->s_port == rport) - return (rcmdsh(ahost, rport, locuser, remuser, - cmd, NULL)); - } - - pid = getpid(); - snprintf(pbuf, sizeof(pbuf), "%u", ntohs(rport)); - memset(&hints, 0, sizeof(hints)); - hints.ai_family = af; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_CANONNAME; - error = getaddrinfo(*ahost, pbuf, &hints, &res); - if (error) { -#if 0 - warnx("%s: %s", *ahost, gai_strerror(error)); -#endif - return (-1); - } - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } else - ; /*XXX*/ - - r = res; - refused = 0; - sigemptyset(&mask); - sigaddset(&mask, SIGURG); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - for (timo = 1, lport = IPPORT_RESERVED - 1;;) { - s = rresvport_af(&lport, r->ai_family); - if (s < 0) { - if (errno == EAGAIN) - (void)fprintf(stderr, - "rcmd: socket: All ports in use\n"); - else - (void)fprintf(stderr, "rcmd: socket: %s\n", - strerror(errno)); - if (r->ai_next) { - r = r->ai_next; - continue; - } else { - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - } - fcntl(s, F_SETOWN, pid); - if (connect(s, r->ai_addr, r->ai_addrlen) >= 0) - break; - (void)close(s); - if (errno == EADDRINUSE) { - lport--; - continue; - } - if (errno == ECONNREFUSED) - refused++; - if (r->ai_next) { - int oerrno = errno; - char hbuf[NI_MAXHOST]; - const int niflags = NI_NUMERICHOST; - - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "connect to address %s: ", hbuf); - errno = oerrno; - perror(0); - r = r->ai_next; - hbuf[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, - hbuf, sizeof(hbuf), NULL, 0, niflags) != 0) - strlcpy(hbuf, "(invalid)", sizeof hbuf); - (void)fprintf(stderr, "Trying %s...\n", hbuf); - continue; - } - if (refused && timo <= 16) { - (void)sleep(timo); - timo *= 2; - r = res; - refused = 0; - continue; - } - (void)fprintf(stderr, "%s: %s\n", res->ai_canonname, - strerror(errno)); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - freeaddrinfo(res); - return (-1); - } - /* given "af" can be PF_UNSPEC, we need the real af for "s" */ - af = r->ai_family; - freeaddrinfo(res); -#if 0 - /* - * try to rresvport() to the same port. This will make rresvport() - * fail it's first bind, resulting in it choosing a random port. - */ - lport--; -#endif - if (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - char num[8]; - int s2 = rresvport_af(&lport, af), s3; - socklen_t len = sizeof(from); - int fdssize = howmany(MAX(s, s2)+1, NFDBITS) * sizeof(fd_mask); - - if (s2 < 0) - goto bad; - readsp = (fd_set *)malloc(fdssize); - if (readsp == NULL) { - close(s2); - goto bad; - } - listen(s2, 1); - (void)snprintf(num, sizeof(num), "%d", lport); - if (write(s, num, strlen(num)+1) != strlen(num)+1) { - (void)fprintf(stderr, - "rcmd: write (setting up stderr): %s\n", - strerror(errno)); - (void)close(s2); - goto bad; - } -again: - bzero(readsp, fdssize); - FD_SET(s, readsp); - FD_SET(s2, readsp); - errno = 0; - if (select(MAX(s, s2) + 1, readsp, 0, 0, 0) < 1 || - !FD_ISSET(s2, readsp)) { - if (errno != 0) - (void)fprintf(stderr, - "rcmd: select (setting up stderr): %s\n", - strerror(errno)); - else - (void)fprintf(stderr, - "select: protocol failure in circuit setup\n"); - (void)close(s2); - goto bad; - } - s3 = accept(s2, (struct sockaddr *)&from, &len); - if (s3 < 0) { - (void)fprintf(stderr, - "rcmd: accept: %s\n", strerror(errno)); - lport = 0; - close(s2); - goto bad; - } - - /* - * XXX careful for ftp bounce attacks. If discovered, shut them - * down and check for the real auxiliary channel to connect. - */ - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) == 0 && - atoi(num) != 20) { - break; - } - close(s3); - goto again; - default: - break; - } - (void)close(s2); - - *fd2p = s3; - switch (from.ss_family) { - case AF_INET: - case AF_INET6: - if (getnameinfo((struct sockaddr *)&from, len, - NULL, 0, num, sizeof(num), NI_NUMERICSERV) != 0 || - (atoi(num) >= IPPORT_RESERVED || - atoi(num) < IPPORT_RESERVED / 2)) { - (void)fprintf(stderr, - "socket: protocol failure in circuit setup.\n"); - goto bad2; - } - break; - default: - break; - } - } - (void)write(s, locuser, strlen(locuser)+1); - (void)write(s, remuser, strlen(remuser)+1); - (void)write(s, cmd, strlen(cmd)+1); - if (read(s, &c, 1) != 1) { - (void)fprintf(stderr, - "rcmd: %s: %s\n", *ahost, strerror(errno)); - goto bad2; - } - if (c != 0) { - while (read(s, &c, 1) == 1) { - (void)write(STDERR_FILENO, &c, 1); - if (c == '\n') - break; - } - goto bad2; - } - sigprocmask(SIG_SETMASK, &oldmask, NULL); - free(readsp); - return (s); -bad2: - if (lport) - (void)close(*fd2p); -bad: - if (readsp) - free(readsp); - (void)close(s); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - return (-1); -} - -int __check_rhosts_file = 1; -char *__rcmd_errstr; - -int -ruserok(const char *rhost, int superuser, const char *ruser, const char *luser) -{ - struct addrinfo hints, *res, *r; - int error; - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - error = getaddrinfo(rhost, "0", &hints, &res); - if (error) - return (-1); - - for (r = res; r; r = r->ai_next) { - if (iruserok_sa(r->ai_addr, r->ai_addrlen, superuser, ruser, - luser) == 0) { - freeaddrinfo(res); - return (0); - } - } - freeaddrinfo(res); - return (-1); -} - -/* - * New .rhosts strategy: We are passed an ip address. We spin through - * hosts.equiv and .rhosts looking for a match. When the .rhosts only - * has ip addresses, we don't have to trust a nameserver. When it - * contains hostnames, we spin through the list of addresses the nameserver - * gives us and look for a match. - * - * Returns 0 if ok, -1 if not ok. - */ -int -iruserok(u_int32_t raddr, int superuser, const char *ruser, const char *luser) -{ - struct sockaddr_in sin; - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_len = sizeof(struct sockaddr_in); - memcpy(&sin.sin_addr, &raddr, sizeof(sin.sin_addr)); - return iruserok_sa(&sin, sizeof(struct sockaddr_in), superuser, ruser, - luser); -} - -int -iruserok_sa(const void *raddr, int rlen, int superuser, const char *ruser, - const char *luser) -{ - struct sockaddr *sa; - char *cp; - struct stat sbuf; - struct passwd *pwd; - FILE *hostf; - uid_t uid; - int first; - char pbuf[MAXPATHLEN]; - - sa = (struct sockaddr *)raddr; - first = 1; - hostf = superuser ? NULL : fopen(_PATH_HEQUIV, "r"); -again: - if (hostf) { - if (__ivaliduser_sa(hostf, sa, rlen, luser, ruser) == 0) { - (void)fclose(hostf); - return (0); - } - (void)fclose(hostf); - } - if (first == 1 && (__check_rhosts_file || superuser)) { - int len; - - first = 0; - if ((pwd = getpwnam(luser)) == NULL) - return (-1); - len = snprintf(pbuf, sizeof pbuf, "%s/.rhosts", pwd->pw_dir); - if (len < 0 || len >= sizeof pbuf) - return (-1); - - /* - * Change effective uid while opening .rhosts. If root and - * reading an NFS mounted file system, can't read files that - * are protected read/write owner only. - */ - uid = geteuid(); - (void)seteuid(pwd->pw_uid); - hostf = fopen(pbuf, "r"); - (void)seteuid(uid); - - if (hostf == NULL) - return (-1); - /* - * If not a regular file, or is owned by someone other than - * user or root or if writeable by anyone but the owner, quit. - */ - cp = NULL; - if (lstat(pbuf, &sbuf) < 0) - cp = ".rhosts lstat failed"; - else if (!S_ISREG(sbuf.st_mode)) - cp = ".rhosts not regular file"; - else if (fstat(fileno(hostf), &sbuf) < 0) - cp = ".rhosts fstat failed"; - else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) - cp = "bad .rhosts owner"; - else if (sbuf.st_mode & (S_IWGRP|S_IWOTH)) - cp = ".rhosts writable by other than owner"; - /* If there were any problems, quit. */ - if (cp) { - __rcmd_errstr = cp; - (void)fclose(hostf); - return (-1); - } - goto again; - } - return (-1); -} - -/* - * XXX - * Don't make static, used by lpd(8). - * - * Returns 0 if ok, -1 if not ok. - */ -int -__ivaliduser(FILE *hostf, in_addr_t raddrl, const char *luser, - const char *ruser) -{ - struct sockaddr_in sin; - - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_len = sizeof(struct sockaddr_in); - memcpy(&sin.sin_addr, &raddrl, sizeof(sin.sin_addr)); - return __ivaliduser_sa(hostf, (struct sockaddr *)&sin, sin.sin_len, - luser, ruser); -} - -int -__ivaliduser_sa(FILE *hostf, struct sockaddr *raddr, socklen_t salen, - const char *luser, const char *ruser) -{ - char *user, *p; - char *buf; - const char *auser, *ahost; - int hostok, userok; - char *rhost = (char *)-1; - char domain[MAXHOSTNAMELEN]; - size_t buflen; - - getdomainname(domain, sizeof(domain)); - - while ((buf = fgetln(hostf, &buflen))) { - p = buf; - if (*p == '#') - continue; - while (p < buf + buflen && *p != '\n' && *p != ' ' && *p != '\t') { - if (!isprint(*p)) - goto bail; - *p = isupper(*p) ? tolower(*p) : *p; - p++; - } - if (p >= buf + buflen) - continue; - if (*p == ' ' || *p == '\t') { - *p++ = '\0'; - while (p < buf + buflen && (*p == ' ' || *p == '\t')) - p++; - if (p >= buf + buflen) - continue; - user = p; - while (p < buf + buflen && *p != '\n' && *p != ' ' && - *p != '\t') { - if (!isprint(*p)) - goto bail; - p++; - } - } else - user = p; - *p = '\0'; - - if (p == buf) - continue; - - auser = *user ? user : luser; - ahost = buf; - - if (strlen(ahost) >= MAXHOSTNAMELEN) - continue; - - /* - * innetgr() must lookup a hostname (we do not attempt - * to change the semantics so that netgroups may have - * #.#.#.# addresses in the list.) - */ - if (ahost[0] == '+') - switch (ahost[1]) { - case '\0': - hostok = 1; - break; - case '@': - if (rhost == (char *)-1) - rhost = __gethostloop(raddr, salen); - hostok = 0; - if (rhost) - hostok = innetgr(&ahost[2], rhost, - NULL, domain); - break; - default: - hostok = __icheckhost(raddr, salen, &ahost[1]); - break; - } - else if (ahost[0] == '-') - switch (ahost[1]) { - case '\0': - hostok = -1; - break; - case '@': - if (rhost == (char *)-1) - rhost = __gethostloop(raddr, salen); - hostok = 0; - if (rhost) - hostok = -innetgr(&ahost[2], rhost, - NULL, domain); - break; - default: - hostok = -__icheckhost(raddr, salen, &ahost[1]); - break; - } - else - hostok = __icheckhost(raddr, salen, ahost); - - - if (auser[0] == '+') - switch (auser[1]) { - case '\0': - userok = 1; - break; - case '@': - userok = innetgr(&auser[2], NULL, ruser, - domain); - break; - default: - userok = strcmp(ruser, &auser[1]) ? 0 : 1; - break; - } - else if (auser[0] == '-') - switch (auser[1]) { - case '\0': - userok = -1; - break; - case '@': - userok = -innetgr(&auser[2], NULL, ruser, - domain); - break; - default: - userok = strcmp(ruser, &auser[1]) ? 0 : -1; - break; - } - else - userok = strcmp(ruser, auser) ? 0 : 1; - - /* Check if one component did not match */ - if (hostok == 0 || userok == 0) - continue; - - /* Check if we got a forbidden pair */ - if (userok <= -1 || hostok <= -1) - return (-1); - - /* Check if we got a valid pair */ - if (hostok >= 1 && userok >= 1) - return (0); - } -bail: - return (-1); -} - -/* - * Returns "true" if match, 0 if no match. If we do not find any - * semblance of an A->PTR->A loop, allow a simple #.#.#.# match to work. - */ -static int -__icheckhost(struct sockaddr *raddr, socklen_t salen, const char *lhost) -{ - struct addrinfo hints, *res, *r; - char h1[NI_MAXHOST], h2[NI_MAXHOST]; - int error; - const int niflags = NI_NUMERICHOST; - - h1[0] = '\0'; - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, - niflags) != 0) - return (0); - - /* Resolve laddr into sockaddr */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = raddr->sa_family; - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - res = NULL; - error = getaddrinfo(lhost, "0", &hints, &res); - if (error) - return (0); - - /* - * Try string comparisons between raddr and laddr. - */ - for (r = res; r; r = r->ai_next) { - h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) - continue; - if (strcmp(h1, h2) == 0) { - freeaddrinfo(res); - return (1); - } - } - - /* No match. */ - freeaddrinfo(res); - return (0); -} - -/* - * Return the hostname associated with the supplied address. - * Do a reverse lookup as well for security. If a loop cannot - * be found, pack the result of inet_ntoa() into the string. - */ -static char * -__gethostloop(struct sockaddr *raddr, socklen_t salen) -{ - static char remotehost[NI_MAXHOST]; - char h1[NI_MAXHOST], h2[NI_MAXHOST]; - struct addrinfo hints, *res, *r; - int error; - const int niflags = NI_NUMERICHOST; - - h1[0] = remotehost[0] = '\0'; - if (getnameinfo(raddr, salen, remotehost, sizeof(remotehost), - NULL, 0, NI_NAMEREQD) != 0) - return (NULL); - if (getnameinfo(raddr, salen, h1, sizeof(h1), NULL, 0, - niflags) != 0) - return (NULL); - - /* - * Look up the name and check that the supplied - * address is in the list - */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = raddr->sa_family; - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - hints.ai_flags = AI_CANONNAME; - res = NULL; - error = getaddrinfo(remotehost, "0", &hints, &res); - if (error) - return (NULL); - - for (r = res; r; r = r->ai_next) { - h2[0] = '\0'; - if (getnameinfo(r->ai_addr, r->ai_addrlen, h2, sizeof(h2), - NULL, 0, niflags) != 0) - continue; - if (strcmp(h1, h2) == 0) { - freeaddrinfo(res); - return (remotehost); - } - } - - /* - * either the DNS adminstrator has made a configuration - * mistake, or someone has attempted to spoof us - */ - syslog(LOG_NOTICE, "rcmd: address %s not listed for host %s", - h1, res->ai_canonname ? res->ai_canonname : remotehost); - freeaddrinfo(res); - return (NULL); -} diff --git a/src/lib/libc/net/rcmdsh.3 b/src/lib/libc/net/rcmdsh.3 deleted file mode 100644 index 07a28beeba..0000000000 --- a/src/lib/libc/net/rcmdsh.3 +++ /dev/null @@ -1,96 +0,0 @@ -.\" $OpenBSD: rcmdsh.3,v 1.12 2007/05/31 19:19:30 jmc Exp $ -.\" -.\" Copyright (c) 1983, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd $Mdocdate: May 31 2007 $ -.Dt RCMDSH 3 -.Os -.Sh NAME -.Nm rcmdsh -.Nd return a stream to a remote command without superuser -.Sh SYNOPSIS -.Fd #include -.Ft int -.Fn rcmdsh "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "char *rshprog" -.Sh DESCRIPTION -The -.Fn rcmdsh -function is used by normal users to execute a command on a remote machine -using an authentication scheme based on reserved port numbers using -.Xr rsh 1 -or the value of -.Fa rshprog -(if non-null). -.Fa rshprog -may be a fully-qualified path, a non-qualified command, or a command containing -space-separated command line arguments. -.Pp -The -.Fn rcmdsh -function looks up the host -.Fa *ahost -using -.Xr gethostbyname 3 , -returning \-1 if the host does not exist. -Otherwise -.Fa *ahost -is set to the standard name of the host and a connection is established to -a server residing at the well-known Internet port -.Li shell/tcp -(or whatever port is used by -.Fa rshprog ) . -The parameter -.Fa inport -is ignored; it is only included to provide an interface similar to -.Xr rcmd 3 . -.Pp -If the connection succeeds, a socket in the -.Tn UNIX -domain of type -.Dv SOCK_STREAM -is returned to the caller, and given to the remote -command as stdin and stdout, and stderr. -.Sh DIAGNOSTICS -The -.Fn rcmdsh -function returns a valid socket descriptor on success. -It returns \-1 on error and prints a diagnostic message on the standard error. -.Sh SEE ALSO -.Xr rsh 1 , -.Xr socketpair 2 , -.Xr rcmd 3 , -.Xr rshd 8 -.Sh HISTORY -The -.Fn rcmdsh -function first appeared in -.Ox 2.0 . -.Sh BUGS -If -.Xr rsh 1 -encounters an error, a file descriptor is still returned instead of \-1. diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c deleted file mode 100644 index a472162711..0000000000 --- a/src/lib/libc/net/rcmdsh.c +++ /dev/null @@ -1,186 +0,0 @@ -/* $OpenBSD: rcmdsh.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ - -/* - * Copyright (c) 2001, MagniComp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * 3. Neither the name of the MagniComp nor the names of its contributors may - * be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This is an rcmd() replacement originally by - * Chris Siebenmann . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * This is a replacement rcmd() function that uses the rsh(1) - * program in place of a direct rcmd(3) function call so as to - * avoid having to be root. Note that rport is ignored. - */ -/* ARGSUSED */ -int -rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, char *rshprog) -{ - struct hostent *hp; - int sp[2]; - pid_t cpid; - char *p; - struct passwd *pw; - - /* What rsh/shell to use. */ - if (rshprog == NULL) - rshprog = _PATH_RSH; - - /* locuser must exist on this host. */ - if ((pw = getpwnam(locuser)) == NULL) { - (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); - return(-1); - } - - /* Validate remote hostname. */ - if (strcmp(*ahost, "localhost") != 0) { - if (((hp = gethostbyname2(*ahost, AF_INET)) == NULL) && - ((hp = gethostbyname2(*ahost, AF_INET6)) == NULL)) { - herror(*ahost); - return(-1); - } - *ahost = hp->h_name; - } - - /* Get a socketpair we'll use for stdin and stdout. */ - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0) { - perror("rcmdsh: socketpair"); - return(-1); - } - - cpid = fork(); - if (cpid < 0) { - perror("rcmdsh: fork failed"); - return(-1); - } else if (cpid == 0) { - /* - * Child. We use sp[1] to be stdin/stdout, and close sp[0]. - */ - (void) close(sp[0]); - if (dup2(sp[1], 0) < 0 || dup2(0, 1) < 0) { - perror("rcmdsh: dup2 failed"); - _exit(255); - } - /* Fork again to lose parent. */ - cpid = fork(); - if (cpid < 0) { - perror("rcmdsh: fork to lose parent failed"); - _exit(255); - } - if (cpid > 0) - _exit(0); - - /* In grandchild here. Become local user for rshprog. */ - if (setuid(pw->pw_uid)) { - (void) fprintf(stderr, "rcmdsh: setuid(%u): %s\n", - pw->pw_uid, strerror(errno)); - _exit(255); - } - - /* - * If remote host is "localhost" and local and remote user - * are the same, avoid running remote shell for efficiency. - */ - if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) { - char *argv[4]; - if (pw->pw_shell[0] == '\0') - rshprog = _PATH_BSHELL; - else - rshprog = pw->pw_shell; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-c"; - argv[2] = (char *)cmd; - argv[3] = NULL; - execvp(rshprog, argv); - } else if ((p = strchr(rshprog, ' ')) == NULL) { - /* simple case */ - char *argv[6]; - p = strrchr(rshprog, '/'); - argv[0] = p ? p + 1 : rshprog; - argv[1] = "-l"; - argv[2] = (char *)remuser; - argv[3] = *ahost; - argv[4] = (char *)cmd; - argv[5] = NULL; - execvp(rshprog, argv); - } else { - /* must pull args out of rshprog and dyn alloc argv */ - char **argv, **ap; - int n; - for (n = 7; (p = strchr(++p, ' ')) != NULL; n++) - continue; - rshprog = strdup(rshprog); - ap = argv = calloc(sizeof(char *), n); - if (rshprog == NULL || argv == NULL) { - perror("rcmdsh"); - _exit(255); - } - while ((p = strsep(&rshprog, " ")) != NULL) { - if (*p == '\0') - continue; - *ap++ = p; - } - if (ap != argv) /* all spaces?!? */ - rshprog = argv[0]; - if ((p = strrchr(argv[0], '/')) != NULL) - argv[0] = p + 1; - *ap++ = "-l"; - *ap++ = (char *)remuser; - *ap++ = *ahost; - *ap++ = (char *)cmd; - *ap++ = NULL; - execvp(rshprog, argv); - } - (void) fprintf(stderr, "rcmdsh: execvp %s failed: %s\n", - rshprog, strerror(errno)); - _exit(255); - } else { - /* Parent. close sp[1], return sp[0]. */ - (void) close(sp[1]); - /* Reap child. */ - (void) wait(NULL); - return(sp[0]); - } - /* NOTREACHED */ -} diff --git a/src/lib/libc/net/recv.c b/src/lib/libc/net/recv.c deleted file mode 100644 index 6241cc6b12..0000000000 --- a/src/lib/libc/net/recv.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: recv.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include - -ssize_t -recv(int s, void *buf, size_t len, int flags) -{ - return (recvfrom(s, buf, len, flags, NULL, 0)); -} diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c deleted file mode 100644 index 69a6ce0abb..0000000000 --- a/src/lib/libc/net/res_comp.c +++ /dev/null @@ -1,475 +0,0 @@ -/* $OpenBSD: res_comp.c,v 1.14 2008/04/16 22:35:23 deraadt Exp $ */ - -/* - * ++Copyright++ 1985, 1993 - * - - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -static int dn_find(u_char *, u_char *, u_char **, u_char **); - -/* - * Expand compressed domain name 'comp_dn' to full domain name. - * 'msg' is a pointer to the begining of the message, - * 'eomorig' points to the first location after the message, - * 'exp_dn' is a pointer to a buffer of size 'length' for the result. - * Return size of compressed name or -1 if there was an error. - */ -int -dn_expand(const u_char *msg, const u_char *eomorig, const u_char *comp_dn, - char *exp_dn, int length) -{ - const u_char *cp; - char *dn; - int n, c; - char *eom; - int len = -1, checked = 0; - - dn = exp_dn; - cp = comp_dn; - if (length > MAXHOSTNAMELEN-1) - length = MAXHOSTNAMELEN-1; - eom = exp_dn + length; - /* - * fetch next label in domain name - */ - while ((n = *cp++)) { - /* - * Check for indirection - */ - switch (n & INDIR_MASK) { - case 0: - if (dn != exp_dn) { - if (dn >= eom) - return (-1); - *dn++ = '.'; - } - if (dn+n >= eom) - return (-1); - checked += n + 1; - while (--n >= 0) { - if (((c = *cp++) == '.') || (c == '\\')) { - if (dn + n + 2 >= eom) - return (-1); - *dn++ = '\\'; - } - *dn++ = c; - if (cp >= eomorig) /* out of range */ - return (-1); - } - break; - - case INDIR_MASK: - if (len < 0) - len = cp - comp_dn + 1; - cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); - if (cp < msg || cp >= eomorig) /* out of range */ - return (-1); - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eomorig - msg) - return (-1); - break; - - default: - return (-1); /* flag error */ - } - } - *dn = '\0'; - if (len < 0) - len = cp - comp_dn; - return (len); -} - -/* - * Compress domain name 'exp_dn' into 'comp_dn'. - * Return the size of the compressed name or -1. - * 'length' is the size of the array pointed to by 'comp_dn'. - * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0] - * is a pointer to the beginning of the message. The list ends with NULL. - * 'lastdnptr' is a pointer to the end of the arrary pointed to - * by 'dnptrs'. Side effect is to update the list of pointers for - * labels inserted into the message as we compress the name. - * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' - * is NULL, we don't update the list. - */ -int -dn_comp(const char *exp_dn, u_char *comp_dn, int length, u_char **dnptrs, - u_char **lastdnptr) -{ - u_char *cp, *dn; - int c, l; - u_char **cpp, **lpp, *sp, *eob; - u_char *msg; - - dn = (u_char *)exp_dn; - cp = comp_dn; - eob = cp + length; - lpp = cpp = NULL; - if (dnptrs != NULL) { - if ((msg = *dnptrs++) != NULL) { - for (cpp = dnptrs; *cpp != NULL; cpp++) - ; - lpp = cpp; /* end of list to search */ - } - } else - msg = NULL; - for (c = *dn++; c != '\0'; ) { - /* look to see if we can use pointers */ - if (msg != NULL) { - if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) { - if (cp+1 >= eob) - return (-1); - *cp++ = (l >> 8) | INDIR_MASK; - *cp++ = l % 256; - return (cp - comp_dn); - } - /* not found, save it */ - if (lastdnptr != NULL && cpp < lastdnptr-1) { - *cpp++ = cp; - *cpp = NULL; - } - } - sp = cp++; /* save ptr to length byte */ - do { - if (c == '.') { - c = *dn++; - break; - } - if (c == '\\') { - if ((c = *dn++) == '\0') - break; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = c; - } while ((c = *dn++) != '\0'); - /* catch trailing '.'s but not '..' */ - if ((l = cp - sp - 1) == 0 && c == '\0') { - cp--; - break; - } - if (l <= 0 || l > MAXLABEL) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *sp = l; - } - if (cp >= eob) { - if (msg != NULL) - *lpp = NULL; - return (-1); - } - *cp++ = '\0'; - return (cp - comp_dn); -} - -/* - * Skip over a compressed domain name. Return the size or -1. - */ -int -__dn_skipname(const u_char *comp_dn, const u_char *eom) -{ - const u_char *cp; - int n; - - cp = comp_dn; - while (cp < eom && (n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - cp += n; - continue; - case INDIR_MASK: /* indirection */ - cp++; - break; - default: /* illegal type */ - return (-1); - } - break; - } - if (cp > eom) - return (-1); - return (cp - comp_dn); -} - -static int -mklower(int ch) -{ - if (isascii(ch) && isupper(ch)) - return (tolower(ch)); - return (ch); -} - -/* - * Search for expanded name from a list of previously compressed names. - * Return the offset from msg if found or -1. - * dnptrs is the pointer to the first name on the list, - * not the pointer to the start of the message. - */ -static int -dn_find(u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr) -{ - u_char *dn, *cp, **cpp; - int n; - u_char *sp; - - for (cpp = dnptrs; cpp < lastdnptr; cpp++) { - dn = exp_dn; - sp = cp = *cpp; - while ((n = *cp++)) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - while (--n >= 0) { - if (*dn == '.') - goto next; - if (*dn == '\\') - dn++; - if (mklower(*dn++) != mklower(*cp++)) - goto next; - } - if ((n = *dn++) == '\0' && *cp == '\0') - return (sp - msg); - if (n == '.') - continue; - goto next; - - case INDIR_MASK: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - - default: /* illegal type */ - return (-1); - } - } - if (*dn == '\0') - return (sp - msg); - next: ; - } - return (-1); -} - -/* - * Verify that a domain name uses an acceptable character set. - */ - -/* - * Note the conspicuous absence of ctype macros in these definitions. On - * non-ASCII hosts, we can't depend on string literals or ctype macros to - * tell us anything about network-format data. The rest of the BIND system - * is not careful about this, but for some reason, we're doing it right here. - */ -#define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) -#define bslashchar(c) ((c) == 0x5c) -#define underscorechar(c) ((c) == 0x5f) -#define periodchar(c) ((c) == PERIOD) -#define asterchar(c) ((c) == 0x2a) -#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \ - || ((c) >= 0x61 && (c) <= 0x7a)) -#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39) - -#define borderchar(c) (alphachar(c) || digitchar(c)) -#define middlechar(c) (borderchar(c) || hyphenchar(c) || underscorechar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) - -int -res_hnok(const char *dn) -{ - int pch = PERIOD, ch = *dn++; - - while (ch != '\0') { - int nch = *dn++; - - if (periodchar(ch)) { - ; - } else if (periodchar(pch)) { - if (!borderchar(ch)) - return (0); - } else if (periodchar(nch) || nch == '\0') { - if (!borderchar(ch)) - return (0); - } else { - if (!middlechar(ch)) - return (0); - } - pch = ch, ch = nch; - } - return (1); -} - -/* - * hostname-like (A, MX, WKS) owners can have "*" as their first label - * but must otherwise be as a host name. - */ -int -res_ownok(const char *dn) -{ - if (asterchar(dn[0])) { - if (periodchar(dn[1])) - return (res_hnok(dn+2)); - if (dn[1] == '\0') - return (1); - } - return (res_hnok(dn)); -} - -/* - * SOA RNAMEs and RP RNAMEs can have any printable character in their first - * label, but the rest of the name has to look like a host name. - */ -int -res_mailok(const char *dn) -{ - int ch, escaped = 0; - - /* "." is a valid missing representation */ - if (*dn == '\0') - return(1); - - /* otherwise