From eb8dd9dca1228af0cd132f515509051ecfabf6f6 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Mon, 14 Apr 2025 17:32:06 +0000 Subject: This commit was manufactured by cvs2git to create tag 'tb_20250414'. --- src/lib/libc/crypt/Makefile.inc | 8 - src/lib/libc/crypt/arc4random.3 | 116 -- src/lib/libc/crypt/arc4random.c | 204 --- src/lib/libc/crypt/arc4random.h | 61 - src/lib/libc/crypt/arc4random_uniform.c | 57 - src/lib/libc/crypt/bcrypt.c | 397 ----- src/lib/libc/crypt/blowfish.3 | 103 -- src/lib/libc/crypt/blowfish.c | 688 -------- src/lib/libc/crypt/chacha_private.h | 222 --- src/lib/libc/crypt/crypt.3 | 144 -- src/lib/libc/crypt/crypt.c | 22 - src/lib/libc/crypt/crypt_checkpass.3 | 113 -- src/lib/libc/crypt/cryptutil.c | 97 -- src/lib/libc/include/DETAILS | 133 -- src/lib/libc/include/README | 110 -- src/lib/libc/include/atfork.h | 45 - src/lib/libc/include/cancel.h | 78 - src/lib/libc/include/ctype_private.h | 9 - src/lib/libc/include/localedef.h | 106 -- src/lib/libc/include/mpool.h | 122 -- src/lib/libc/include/namespace.h | 98 -- src/lib/libc/include/thread_private.h | 427 ----- src/lib/libc/net/Makefile.inc | 31 - src/lib/libc/net/base64.c | 307 ---- src/lib/libc/net/ether_aton.3 | 114 -- src/lib/libc/net/ethers.c | 183 -- src/lib/libc/net/freeaddrinfo.c | 50 - src/lib/libc/net/gai_strerror.3 | 95 -- src/lib/libc/net/gai_strerror.c | 79 - src/lib/libc/net/getaddrinfo.3 | 477 ------ src/lib/libc/net/gethostbyname.3 | 271 --- src/lib/libc/net/getifaddrs.3 | 157 -- src/lib/libc/net/getifaddrs.c | 298 ---- src/lib/libc/net/getnameinfo.3 | 264 --- src/lib/libc/net/getnetent.3 | 147 -- src/lib/libc/net/getnetent.c | 49 - src/lib/libc/net/getpeereid.3 | 121 -- src/lib/libc/net/getpeereid.c | 36 - src/lib/libc/net/getproto.c | 60 - src/lib/libc/net/getprotoent.3 | 213 --- src/lib/libc/net/getprotoent.c | 169 -- src/lib/libc/net/getprotoname.c | 69 - src/lib/libc/net/getrrsetbyname.3 | 164 -- src/lib/libc/net/getservbyname.c | 72 - src/lib/libc/net/getservbyport.c | 65 - src/lib/libc/net/getservent.3 | 220 --- src/lib/libc/net/getservent.c | 171 -- src/lib/libc/net/herror.c | 106 -- src/lib/libc/net/htobe64.3 | 164 -- src/lib/libc/net/htonl.3 | 102 -- src/lib/libc/net/htonl.c | 15 - src/lib/libc/net/htons.c | 15 - src/lib/libc/net/if_indextoname.3 | 143 -- src/lib/libc/net/if_indextoname.c | 78 - src/lib/libc/net/if_nameindex.c | 145 -- src/lib/libc/net/if_nametoindex.c | 77 - src/lib/libc/net/inet6_opt_init.3 | 328 ---- src/lib/libc/net/inet6_rth_space.3 | 220 --- src/lib/libc/net/inet_addr.3 | 195 --- src/lib/libc/net/inet_addr.c | 175 -- src/lib/libc/net/inet_lnaof.3 | 89 - src/lib/libc/net/inet_lnaof.c | 50 - src/lib/libc/net/inet_makeaddr.c | 53 - src/lib/libc/net/inet_net_ntop.3 | 195 --- src/lib/libc/net/inet_net_ntop.c | 160 -- src/lib/libc/net/inet_net_pton.c | 246 --- src/lib/libc/net/inet_neta.c | 80 - src/lib/libc/net/inet_netof.c | 49 - src/lib/libc/net/inet_network.c | 85 - src/lib/libc/net/inet_ntoa.c | 51 - src/lib/libc/net/inet_ntop.3 | 213 --- src/lib/libc/net/inet_ntop.c | 205 --- src/lib/libc/net/inet_pton.c | 213 --- src/lib/libc/net/ip6opt.c | 285 ---- src/lib/libc/net/link_ntoa.3 | 78 - src/lib/libc/net/linkaddr.c | 85 - src/lib/libc/net/ntohl.c | 15 - src/lib/libc/net/ntohs.c | 15 - src/lib/libc/net/rcmd.3 | 232 --- src/lib/libc/net/rcmd.c | 296 ---- src/lib/libc/net/rcmdsh.3 | 95 -- src/lib/libc/net/rcmdsh.c | 194 --- src/lib/libc/net/recv.c | 41 - src/lib/libc/net/res_comp.c | 466 ------ src/lib/libc/net/res_data.c | 104 -- src/lib/libc/net/res_debug_syms.c | 192 --- src/lib/libc/net/res_init.3 | 441 ----- src/lib/libc/net/res_random.c | 281 ---- src/lib/libc/net/rresvport.c | 107 -- src/lib/libc/net/rthdr.c | 198 --- src/lib/libc/net/ruserok.c | 392 ----- src/lib/libc/net/send.c | 41 - src/lib/libc/net/sockatmark.3 | 122 -- src/lib/libc/net/sockatmark.c | 40 - src/lib/libc/net/vars6.c | 42 - src/lib/libc/stdlib/Makefile.inc | 33 - src/lib/libc/stdlib/_Exit.c | 22 - src/lib/libc/stdlib/__mktemp4.c | 83 - 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 | 77 - src/lib/libc/stdlib/abort.c | 64 - src/lib/libc/stdlib/abs.3 | 75 - src/lib/libc/stdlib/abs.c | 38 - src/lib/libc/stdlib/alloca.3 | 74 - src/lib/libc/stdlib/atexit.3 | 97 -- src/lib/libc/stdlib/atexit.c | 256 --- src/lib/libc/stdlib/atexit.h | 61 - src/lib/libc/stdlib/atof.3 | 81 - src/lib/libc/stdlib/atof.c | 37 - src/lib/libc/stdlib/atoi.3 | 89 - src/lib/libc/stdlib/atoi.c | 38 - src/lib/libc/stdlib/atol.3 | 68 - src/lib/libc/stdlib/atol.c | 37 - src/lib/libc/stdlib/atoll.3 | 68 - src/lib/libc/stdlib/atoll.c | 37 - src/lib/libc/stdlib/bsearch.3 | 84 - src/lib/libc/stdlib/bsearch.c | 69 - src/lib/libc/stdlib/div.3 | 63 - src/lib/libc/stdlib/div.c | 72 - src/lib/libc/stdlib/drand48.c | 30 - src/lib/libc/stdlib/ecvt.3 | 166 -- src/lib/libc/stdlib/ecvt.c | 104 -- src/lib/libc/stdlib/erand48.c | 26 - src/lib/libc/stdlib/exit.3 | 102 -- src/lib/libc/stdlib/exit.c | 57 - src/lib/libc/stdlib/gcvt.c | 123 -- src/lib/libc/stdlib/getenv.3 | 191 --- src/lib/libc/stdlib/getenv.c | 78 - src/lib/libc/stdlib/getopt.3 | 365 ---- src/lib/libc/stdlib/getopt_long.3 | 460 ----- src/lib/libc/stdlib/getopt_long.c | 513 ------ src/lib/libc/stdlib/getsubopt.3 | 162 -- src/lib/libc/stdlib/getsubopt.c | 92 - src/lib/libc/stdlib/hcreate.3 | 234 --- src/lib/libc/stdlib/hcreate.c | 189 --- src/lib/libc/stdlib/heapsort.c | 175 -- src/lib/libc/stdlib/icdb.c | 391 ----- src/lib/libc/stdlib/icdb_new.3 | 68 - src/lib/libc/stdlib/imaxabs.3 | 70 - src/lib/libc/stdlib/imaxabs.c | 38 - src/lib/libc/stdlib/imaxdiv.3 | 65 - src/lib/libc/stdlib/imaxdiv.c | 50 - src/lib/libc/stdlib/insque.3 | 103 -- src/lib/libc/stdlib/insque.c | 54 - src/lib/libc/stdlib/jrand48.c | 22 - src/lib/libc/stdlib/l64a.c | 42 - src/lib/libc/stdlib/labs.3 | 88 - src/lib/libc/stdlib/labs.c | 37 - src/lib/libc/stdlib/lcong48.c | 36 - src/lib/libc/stdlib/ldiv.3 | 71 - src/lib/libc/stdlib/ldiv.c | 50 - src/lib/libc/stdlib/llabs.c | 40 - src/lib/libc/stdlib/lldiv.3 | 73 - src/lib/libc/stdlib/lldiv.c | 52 - src/lib/libc/stdlib/lrand48.c | 24 - src/lib/libc/stdlib/lsearch.3 | 106 -- src/lib/libc/stdlib/lsearch.c | 70 - src/lib/libc/stdlib/malloc.3 | 860 ---------- src/lib/libc/stdlib/malloc.c | 2781 ------------------------------- src/lib/libc/stdlib/merge.c | 336 ---- src/lib/libc/stdlib/mkdtemp.c | 41 - src/lib/libc/stdlib/mkstemp.c | 64 - src/lib/libc/stdlib/mktemp.3 | 431 ----- src/lib/libc/stdlib/mktemp.c | 48 - src/lib/libc/stdlib/mrand48.c | 24 - src/lib/libc/stdlib/nrand48.c | 22 - src/lib/libc/stdlib/posix_memalign.3 | 97 -- src/lib/libc/stdlib/posix_openpt.3 | 102 -- src/lib/libc/stdlib/posix_pty.c | 120 -- src/lib/libc/stdlib/ptsname.3 | 160 -- src/lib/libc/stdlib/qsort.3 | 276 --- src/lib/libc/stdlib/qsort.c | 238 --- src/lib/libc/stdlib/radixsort.3 | 151 -- src/lib/libc/stdlib/radixsort.c | 294 ---- src/lib/libc/stdlib/rand.3 | 135 -- src/lib/libc/stdlib/rand.c | 74 - src/lib/libc/stdlib/rand48.3 | 240 --- src/lib/libc/stdlib/rand48.h | 38 - src/lib/libc/stdlib/random.3 | 197 --- src/lib/libc/stdlib/random.c | 419 ----- src/lib/libc/stdlib/reallocarray.c | 39 - src/lib/libc/stdlib/realpath.3 | 165 -- src/lib/libc/stdlib/realpath.c | 42 - src/lib/libc/stdlib/recallocarray.c | 81 - src/lib/libc/stdlib/remque.c | 48 - src/lib/libc/stdlib/seed48.c | 45 - src/lib/libc/stdlib/setenv.c | 185 -- src/lib/libc/stdlib/srand48.c | 38 - src/lib/libc/stdlib/strtod.3 | 176 -- src/lib/libc/stdlib/strtoimax.c | 151 -- src/lib/libc/stdlib/strtol.3 | 273 --- src/lib/libc/stdlib/strtol.c | 151 -- src/lib/libc/stdlib/strtoll.c | 156 -- src/lib/libc/stdlib/strtonum.3 | 152 -- src/lib/libc/stdlib/strtonum.c | 66 - src/lib/libc/stdlib/strtoul.3 | 260 --- src/lib/libc/stdlib/strtoul.c | 110 -- src/lib/libc/stdlib/strtoull.c | 114 -- src/lib/libc/stdlib/strtoumax.c | 109 -- src/lib/libc/stdlib/system.3 | 116 -- src/lib/libc/stdlib/system.c | 89 - src/lib/libc/stdlib/tfind.c | 40 - src/lib/libc/stdlib/thread_atexit.c | 44 - src/lib/libc/stdlib/tsearch.3 | 126 -- src/lib/libc/stdlib/tsearch.c | 118 -- src/lib/libc/string/Makefile.inc | 35 - src/lib/libc/string/bcmp.3 | 67 - src/lib/libc/string/bcmp.c | 52 - src/lib/libc/string/bcopy.3 | 67 - src/lib/libc/string/bcopy.c | 113 -- src/lib/libc/string/bzero.3 | 92 - src/lib/libc/string/bzero.c | 45 - src/lib/libc/string/explicit_bzero.c | 20 - src/lib/libc/string/ffs.3 | 61 - src/lib/libc/string/ffs.c | 40 - src/lib/libc/string/memccpy.3 | 81 - src/lib/libc/string/memccpy.c | 49 - src/lib/libc/string/memchr.3 | 102 -- src/lib/libc/string/memchr.c | 49 - src/lib/libc/string/memcmp.3 | 86 - src/lib/libc/string/memcmp.c | 52 - src/lib/libc/string/memcpy.3 | 79 - src/lib/libc/string/memcpy.c | 109 -- src/lib/libc/string/memmem.3 | 77 - src/lib/libc/string/memmem.c | 184 -- src/lib/libc/string/memmove.3 | 76 - src/lib/libc/string/memmove.c | 113 -- src/lib/libc/string/memrchr.c | 39 - src/lib/libc/string/memset.3 | 75 - src/lib/libc/string/memset.c | 48 - src/lib/libc/string/stpcpy.3 | 184 -- src/lib/libc/string/stpcpy.c | 44 - src/lib/libc/string/stpncpy.c | 57 - src/lib/libc/string/strcasecmp.3 | 128 -- src/lib/libc/string/strcasecmp.c | 107 -- src/lib/libc/string/strcasecmp_l.c | 21 - src/lib/libc/string/strcasestr.c | 61 - src/lib/libc/string/strcat.3 | 76 - src/lib/libc/string/strcat.c | 47 - src/lib/libc/string/strchr.3 | 116 -- src/lib/libc/string/strchr.c | 46 - src/lib/libc/string/strcmp.3 | 95 -- src/lib/libc/string/strcmp.c | 48 - src/lib/libc/string/strcoll.3 | 103 -- src/lib/libc/string/strcoll.c | 45 - src/lib/libc/string/strcoll_l.c | 14 - src/lib/libc/string/strcpy.3 | 82 - src/lib/libc/string/strcpy.c | 46 - src/lib/libc/string/strcspn.3 | 108 -- src/lib/libc/string/strcspn.c | 59 - src/lib/libc/string/strdup.3 | 119 -- src/lib/libc/string/strdup.c | 50 - src/lib/libc/string/strerror.3 | 154 -- src/lib/libc/string/strerror.c | 42 - src/lib/libc/string/strerror_l.c | 33 - src/lib/libc/string/strerror_r.c | 107 -- src/lib/libc/string/strlcat.c | 56 - src/lib/libc/string/strlcpy.3 | 195 --- src/lib/libc/string/strlcpy.c | 51 - src/lib/libc/string/strlen.3 | 103 -- src/lib/libc/string/strlen.c | 44 - src/lib/libc/string/strmode.3 | 153 -- src/lib/libc/string/strmode.c | 139 -- src/lib/libc/string/strncat.3 | 132 -- src/lib/libc/string/strncat.c | 58 - src/lib/libc/string/strncmp.c | 48 - src/lib/libc/string/strncpy.3 | 138 -- src/lib/libc/string/strncpy.c | 59 - src/lib/libc/string/strndup.c | 40 - src/lib/libc/string/strnlen.c | 33 - src/lib/libc/string/strpbrk.3 | 80 - src/lib/libc/string/strpbrk.c | 49 - src/lib/libc/string/strrchr.3 | 118 -- src/lib/libc/string/strrchr.c | 48 - src/lib/libc/string/strsep.3 | 110 -- src/lib/libc/string/strsep.c | 71 - src/lib/libc/string/strsignal.3 | 78 - src/lib/libc/string/strsignal.c | 40 - src/lib/libc/string/strspn.3 | 92 - src/lib/libc/string/strspn.c | 52 - src/lib/libc/string/strstr.3 | 101 -- src/lib/libc/string/strstr.c | 189 --- src/lib/libc/string/strtok.3 | 169 -- src/lib/libc/string/strtok.c | 87 - src/lib/libc/string/strxfrm.3 | 105 -- src/lib/libc/string/strxfrm.c | 52 - src/lib/libc/string/strxfrm_l.c | 14 - src/lib/libc/string/swab.3 | 79 - src/lib/libc/string/swab.c | 35 - src/lib/libc/string/timingsafe_bcmp.3 | 87 - src/lib/libc/string/timingsafe_bcmp.c | 30 - src/lib/libc/string/timingsafe_memcmp.c | 47 - src/lib/libc/string/wcscasecmp.3 | 134 -- src/lib/libc/string/wcscasecmp.c | 63 - src/lib/libc/string/wcscasecmp_l.c | 63 - src/lib/libc/string/wcscat.3 | 115 -- src/lib/libc/string/wcscat.c | 56 - src/lib/libc/string/wcschr.3 | 85 - src/lib/libc/string/wcschr.c | 50 - src/lib/libc/string/wcscmp.3 | 92 - src/lib/libc/string/wcscmp.c | 52 - src/lib/libc/string/wcscpy.3 | 129 -- src/lib/libc/string/wcscpy.c | 52 - src/lib/libc/string/wcscspn.3 | 83 - src/lib/libc/string/wcscspn.c | 54 - src/lib/libc/string/wcsdup.3 | 97 -- src/lib/libc/string/wcsdup.c | 32 - src/lib/libc/string/wcslcat.c | 56 - src/lib/libc/string/wcslcpy.3 | 160 -- src/lib/libc/string/wcslcpy.c | 51 - src/lib/libc/string/wcslen.3 | 102 -- src/lib/libc/string/wcslen.c | 45 - src/lib/libc/string/wcsncat.c | 53 - src/lib/libc/string/wcsncmp.c | 53 - src/lib/libc/string/wcsncpy.c | 51 - src/lib/libc/string/wcsnlen.c | 45 - src/lib/libc/string/wcspbrk.3 | 81 - src/lib/libc/string/wcspbrk.c | 53 - src/lib/libc/string/wcsrchr.3 | 85 - src/lib/libc/string/wcsrchr.c | 50 - src/lib/libc/string/wcsspn.3 | 79 - src/lib/libc/string/wcsspn.c | 56 - src/lib/libc/string/wcsstr.3 | 88 - src/lib/libc/string/wcsstr.c | 71 - src/lib/libc/string/wcstok.3 | 151 -- src/lib/libc/string/wcstok.c | 93 -- src/lib/libc/string/wcswcs.c | 5 - src/lib/libc/string/wcswidth.3 | 69 - src/lib/libc/string/wcswidth.c | 51 - src/lib/libc/string/wmemchr.3 | 81 - src/lib/libc/string/wmemchr.c | 47 - src/lib/libc/string/wmemcmp.3 | 78 - src/lib/libc/string/wmemcmp.c | 51 - src/lib/libc/string/wmemcpy.3 | 79 - src/lib/libc/string/wmemcpy.c | 41 - src/lib/libc/string/wmemmove.3 | 78 - src/lib/libc/string/wmemmove.c | 41 - src/lib/libc/string/wmemset.3 | 73 - src/lib/libc/string/wmemset.c | 47 - 341 files changed, 41066 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/arc4random.h delete mode 100644 src/lib/libc/crypt/arc4random_uniform.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/chacha_private.h 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/crypt_checkpass.3 delete mode 100644 src/lib/libc/crypt/cryptutil.c delete mode 100644 src/lib/libc/include/DETAILS delete mode 100644 src/lib/libc/include/README delete mode 100644 src/lib/libc/include/atfork.h delete mode 100644 src/lib/libc/include/cancel.h delete mode 100644 src/lib/libc/include/ctype_private.h delete mode 100644 src/lib/libc/include/localedef.h delete mode 100644 src/lib/libc/include/mpool.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/ether_aton.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/gethostbyname.3 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/getnetent.3 delete mode 100644 src/lib/libc/net/getnetent.c delete mode 100644 src/lib/libc/net/getpeereid.3 delete mode 100644 src/lib/libc/net/getpeereid.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/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/htobe64.3 delete mode 100644 src/lib/libc/net/htonl.3 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/inet6_opt_init.3 delete mode 100644 src/lib/libc/net/inet6_rth_space.3 delete mode 100644 src/lib/libc/net/inet_addr.3 delete mode 100644 src/lib/libc/net/inet_addr.c delete mode 100644 src/lib/libc/net/inet_lnaof.3 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_ntop.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.3 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_ntoa.3 delete mode 100644 src/lib/libc/net/linkaddr.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_syms.c delete mode 100644 src/lib/libc/net/res_init.3 delete mode 100644 src/lib/libc/net/res_random.c 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/ruserok.c delete mode 100644 src/lib/libc/net/send.c delete mode 100644 src/lib/libc/net/sockatmark.3 delete mode 100644 src/lib/libc/net/sockatmark.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/__mktemp4.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/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/icdb.c delete mode 100644 src/lib/libc/stdlib/icdb_new.3 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/mkdtemp.c delete mode 100644 src/lib/libc/stdlib/mkstemp.c delete mode 100644 src/lib/libc/stdlib/mktemp.3 delete mode 100644 src/lib/libc/stdlib/mktemp.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/posix_memalign.3 delete mode 100644 src/lib/libc/stdlib/posix_openpt.3 delete mode 100644 src/lib/libc/stdlib/posix_pty.c delete mode 100644 src/lib/libc/stdlib/ptsname.3 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/reallocarray.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/recallocarray.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/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/thread_atexit.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/bzero.3 delete mode 100644 src/lib/libc/string/bzero.c delete mode 100644 src/lib/libc/string/explicit_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/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/memcpy.c delete mode 100644 src/lib/libc/string/memmem.3 delete mode 100644 src/lib/libc/string/memmem.c delete mode 100644 src/lib/libc/string/memmove.3 delete mode 100644 src/lib/libc/string/memmove.c 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/stpcpy.3 delete mode 100644 src/lib/libc/string/stpcpy.c delete mode 100644 src/lib/libc/string/stpncpy.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/strcasecmp_l.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/strchr.c 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/strcoll_l.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_l.c delete mode 100644 src/lib/libc/string/strerror_r.c 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.3 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.3 delete mode 100644 src/lib/libc/string/strncpy.c delete mode 100644 src/lib/libc/string/strndup.c delete mode 100644 src/lib/libc/string/strnlen.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/strrchr.c 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/strxfrm_l.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/timingsafe_bcmp.3 delete mode 100644 src/lib/libc/string/timingsafe_bcmp.c delete mode 100644 src/lib/libc/string/timingsafe_memcmp.c delete mode 100644 src/lib/libc/string/wcscasecmp.3 delete mode 100644 src/lib/libc/string/wcscasecmp.c delete mode 100644 src/lib/libc/string/wcscasecmp_l.c delete mode 100644 src/lib/libc/string/wcscat.3 delete mode 100644 src/lib/libc/string/wcscat.c delete mode 100644 src/lib/libc/string/wcschr.3 delete mode 100644 src/lib/libc/string/wcschr.c delete mode 100644 src/lib/libc/string/wcscmp.3 delete mode 100644 src/lib/libc/string/wcscmp.c delete mode 100644 src/lib/libc/string/wcscpy.3 delete mode 100644 src/lib/libc/string/wcscpy.c delete mode 100644 src/lib/libc/string/wcscspn.3 delete mode 100644 src/lib/libc/string/wcscspn.c delete mode 100644 src/lib/libc/string/wcsdup.3 delete mode 100644 src/lib/libc/string/wcsdup.c delete mode 100644 src/lib/libc/string/wcslcat.c delete mode 100644 src/lib/libc/string/wcslcpy.3 delete mode 100644 src/lib/libc/string/wcslcpy.c delete mode 100644 src/lib/libc/string/wcslen.3 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/wcsnlen.c delete mode 100644 src/lib/libc/string/wcspbrk.3 delete mode 100644 src/lib/libc/string/wcspbrk.c delete mode 100644 src/lib/libc/string/wcsrchr.3 delete mode 100644 src/lib/libc/string/wcsrchr.c delete mode 100644 src/lib/libc/string/wcsspn.3 delete mode 100644 src/lib/libc/string/wcsspn.c delete mode 100644 src/lib/libc/string/wcsstr.3 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.3 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.3 delete mode 100644 src/lib/libc/string/wmemcmp.c delete mode 100644 src/lib/libc/string/wmemcpy.3 delete mode 100644 src/lib/libc/string/wmemcpy.c delete mode 100644 src/lib/libc/string/wmemmove.3 delete mode 100644 src/lib/libc/string/wmemmove.c delete mode 100644 src/lib/libc/string/wmemset.3 delete mode 100644 src/lib/libc/string/wmemset.c (limited to 'src/lib/libc') diff --git a/src/lib/libc/crypt/Makefile.inc b/src/lib/libc/crypt/Makefile.inc deleted file mode 100644 index e9263b09fe..0000000000 --- a/src/lib/libc/crypt/Makefile.inc +++ /dev/null @@ -1,8 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.27 2016/03/30 06:38:41 jmc Exp $ - -.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/crypt ${LIBCSRCDIR}/crypt - -SRCS+= crypt.c cryptutil.c arc4random.c arc4random_uniform.c \ - blowfish.c bcrypt.c - -MAN+= crypt.3 crypt_checkpass.3 blowfish.3 arc4random.3 diff --git a/src/lib/libc/crypt/arc4random.3 b/src/lib/libc/crypt/arc4random.3 deleted file mode 100644 index 411860c28f..0000000000 --- a/src/lib/libc/crypt/arc4random.3 +++ /dev/null @@ -1,116 +0,0 @@ -.\" $OpenBSD: arc4random.3,v 1.37 2019/09/29 16:30:35 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: September 29 2019 $ -.Dt ARC4RANDOM 3 -.Os -.Sh NAME -.Nm arc4random , -.Nm arc4random_buf , -.Nm arc4random_uniform -.Nd random number generator -.Sh SYNOPSIS -.In stdlib.h -.Ft uint32_t -.Fn arc4random "void" -.Ft void -.Fn arc4random_buf "void *buf" "size_t nbytes" -.Ft uint32_t -.Fn arc4random_uniform "uint32_t upper_bound" -.Sh DESCRIPTION -This family of functions provides higher quality data than those -described in -.Xr rand 3 , -.Xr random 3 , -and -.Xr rand48 3 . -.Pp -Use of these functions is encouraged for almost all random number -consumption because the other interfaces are deficient in either -quality, portability, standardization, or availability. -These functions can be called in almost all coding environments, -including -.Xr pthreads 3 -and -.Xr chroot 2 . -.Pp -High quality 32-bit pseudo-random numbers are generated very quickly. -On each call, a cryptographic pseudo-random number generator is used -to generate a new result. -One data pool is used for all consumers in a process, so that consumption -under program flow can act as additional stirring. -The subsystem is re-seeded from the kernel -.Xr random 4 -subsystem using -.Xr getentropy 2 -on a regular basis, and also upon -.Xr fork 2 . -.Pp -The -.Fn arc4random -function returns a single 32-bit value. -.Pp -.Fn arc4random_buf -fills the region -.Fa buf -of length -.Fa nbytes -with random data. -.Pp -.Fn arc4random_uniform -will return a single 32-bit value, uniformly distributed but less than -.Fa upper_bound . -This 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. -In the worst case, this function may consume multiple iterations -to ensure uniformity; see the source code to understand the problem -and solution. -.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 -These functions first appeared in -.Ox 2.1 . -.Pp -The original version of this random number generator used the -RC4 (also known as ARC4) algorithm. -In -.Ox 5.5 -it was replaced with the ChaCha20 cipher, and it may be replaced -again in the future as cryptographic techniques advance. -A good mnemonic is -.Dq A Replacement Call for Random . diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c deleted file mode 100644 index 2da8e010ad..0000000000 --- a/src/lib/libc/crypt/arc4random.c +++ /dev/null @@ -1,204 +0,0 @@ -/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * Copyright (c) 2013, Markus Friedl - * Copyright (c) 2014, Theo de Raadt - * - * 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. - */ - -/* - * ChaCha based random number generator for OpenBSD. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define KEYSTREAM_ONLY -#include "chacha_private.h" - -#define minimum(a, b) ((a) < (b) ? (a) : (b)) - -#if defined(__GNUC__) || defined(_MSC_VER) -#define inline __inline -#else /* __GNUC__ || _MSC_VER */ -#define inline -#endif /* !__GNUC__ && !_MSC_VER */ - -#define KEYSZ 32 -#define IVSZ 8 -#define BLOCKSZ 64 -#define RSBUFSZ (16*BLOCKSZ) - -#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */ - -/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */ -static struct _rs { - size_t rs_have; /* valid bytes at end of rs_buf */ - size_t rs_count; /* bytes till reseed */ -} *rs; - -/* Maybe be preserved in fork children, if _rs_allocate() decides. */ -static struct _rsx { - chacha_ctx rs_chacha; /* chacha context for random keystream */ - u_char rs_buf[RSBUFSZ]; /* keystream blocks */ -} *rsx; - -static inline int _rs_allocate(struct _rs **, struct _rsx **); -static inline void _rs_forkdetect(void); -#include "arc4random.h" - -static inline void _rs_rekey(u_char *dat, size_t datlen); - -static inline void -_rs_init(u_char *buf, size_t n) -{ - if (n < KEYSZ + IVSZ) - return; - - if (rs == NULL) { - if (_rs_allocate(&rs, &rsx) == -1) - _exit(1); - } - - chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8); - chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ); -} - -static void -_rs_stir(void) -{ - u_char rnd[KEYSZ + IVSZ]; - uint32_t rekey_fuzz = 0; - - if (getentropy(rnd, sizeof rnd) == -1) - _getentropy_fail(); - - if (!rs) - _rs_init(rnd, sizeof(rnd)); - else - _rs_rekey(rnd, sizeof(rnd)); - explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */ - - /* invalidate rs_buf */ - rs->rs_have = 0; - memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); - - /* rekey interval should not be predictable */ - chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz, - (uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz)); - rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE); -} - -static inline void -_rs_stir_if_needed(size_t len) -{ - _rs_forkdetect(); - if (!rs || rs->rs_count <= len) - _rs_stir(); - if (rs->rs_count <= len) - rs->rs_count = 0; - else - rs->rs_count -= len; -} - -static inline void -_rs_rekey(u_char *dat, size_t datlen) -{ -#ifndef KEYSTREAM_ONLY - memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); -#endif - /* fill rs_buf with the keystream */ - chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf, - rsx->rs_buf, sizeof(rsx->rs_buf)); - /* mix in optional user provided data */ - if (dat) { - size_t i, m; - - m = minimum(datlen, KEYSZ + IVSZ); - for (i = 0; i < m; i++) - rsx->rs_buf[i] ^= dat[i]; - } - /* immediately reinit for backtracking resistance */ - _rs_init(rsx->rs_buf, KEYSZ + IVSZ); - memset(rsx->rs_buf, 0, KEYSZ + IVSZ); - rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ; -} - -static inline void -_rs_random_buf(void *_buf, size_t n) -{ - u_char *buf = (u_char *)_buf; - u_char *keystream; - size_t m; - - _rs_stir_if_needed(n); - while (n > 0) { - if (rs->rs_have > 0) { - m = minimum(n, rs->rs_have); - keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - - rs->rs_have; - memcpy(buf, keystream, m); - memset(keystream, 0, m); - buf += m; - n -= m; - rs->rs_have -= m; - } - if (rs->rs_have == 0) - _rs_rekey(NULL, 0); - } -} - -static inline void -_rs_random_u32(uint32_t *val) -{ - u_char *keystream; - - _rs_stir_if_needed(sizeof(*val)); - if (rs->rs_have < sizeof(*val)) - _rs_rekey(NULL, 0); - keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; - memcpy(val, keystream, sizeof(*val)); - memset(keystream, 0, sizeof(*val)); - rs->rs_have -= sizeof(*val); -} - -uint32_t -arc4random(void) -{ - uint32_t val; - - _ARC4_LOCK(); - _rs_random_u32(&val); - _ARC4_UNLOCK(); - return val; -} -DEF_WEAK(arc4random); - -void -arc4random_buf(void *buf, size_t n) -{ - _ARC4_LOCK(); - _rs_random_buf(buf, n); - _ARC4_UNLOCK(); -} -DEF_WEAK(arc4random_buf); diff --git a/src/lib/libc/crypt/arc4random.h b/src/lib/libc/crypt/arc4random.h deleted file mode 100644 index 4abd15321a..0000000000 --- a/src/lib/libc/crypt/arc4random.h +++ /dev/null @@ -1,61 +0,0 @@ -/* $OpenBSD: arc4random.h,v 1.4 2015/01/15 06:57:18 deraadt Exp $ */ - -/* - * Copyright (c) 1996, David Mazieres - * Copyright (c) 2008, Damien Miller - * Copyright (c) 2013, Markus Friedl - * Copyright (c) 2014, Theo de Raadt - * - * 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. - */ - -/* - * Stub functions for portability. - */ -#include - -#include - -#include "thread_private.h" - -static inline void -_getentropy_fail(void) -{ - raise(SIGKILL); -} - -static inline int -_rs_allocate(struct _rs **rsp, struct _rsx **rsxp) -{ - struct { - struct _rs rs; - struct _rsx rsx; - } *p; - - if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) - return (-1); - if (minherit(p, sizeof(*p), MAP_INHERIT_ZERO) == -1) { - munmap(p, sizeof(*p)); - return (-1); - } - - *rsp = &p->rs; - *rsxp = &p->rsx; - return (0); -} - -static inline void -_rs_forkdetect(void) -{ -} diff --git a/src/lib/libc/crypt/arc4random_uniform.c b/src/lib/libc/crypt/arc4random_uniform.c deleted file mode 100644 index a18b5b1238..0000000000 --- a/src/lib/libc/crypt/arc4random_uniform.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */ - -/* - * 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. - */ - -#include -#include - -/* - * 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. - */ -uint32_t -arc4random_uniform(uint32_t upper_bound) -{ - uint32_t r, min; - - if (upper_bound < 2) - return 0; - - /* 2**32 % x == (2**32 - x) % x */ - min = -upper_bound % upper_bound; - - /* - * 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; -} -DEF_WEAK(arc4random_uniform); diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c deleted file mode 100644 index ba45b104ed..0000000000 --- a/src/lib/libc/crypt/bcrypt.c +++ /dev/null @@ -1,397 +0,0 @@ -/* $OpenBSD: bcrypt.c,v 1.58 2020/07/06 13:33:05 pirofti Exp $ */ - -/* - * Copyright (c) 2014 Ted Unangst - * Copyright (c) 1997 Niels Provos - * - * 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. - */ -/* 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, password) - * state := ExpandKey (state, 0, salt) - * 4. ctext := "OrpheanBeholderScryDoubt" - * 5. REPEAT 64: - * ctext := Encrypt_ECB (state, ctext); - * 6. RETURN Concatenate (salt, ctext); - * - */ - -#include -#include -#include -#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_WORDS 6 /* Ciphertext words */ -#define BCRYPT_MINLOGROUNDS 4 /* we have log2(rounds) in salt */ - -#define BCRYPT_SALTSPACE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1) -#define BCRYPT_HASHSPACE 61 - -char *bcrypt_gensalt(u_int8_t); - -static int encode_base64(char *, const u_int8_t *, size_t); -static int decode_base64(u_int8_t *, size_t, const char *); - -/* - * Generates a salt for this version of crypt. - */ -static int -bcrypt_initsalt(int log_rounds, uint8_t *salt, size_t saltbuflen) -{ - uint8_t csalt[BCRYPT_MAXSALT]; - - if (saltbuflen < BCRYPT_SALTSPACE) { - errno = EINVAL; - return -1; - } - - arc4random_buf(csalt, sizeof(csalt)); - - if (log_rounds < 4) - log_rounds = 4; - else if (log_rounds > 31) - log_rounds = 31; - - snprintf(salt, saltbuflen, "$2b$%2.2u$", log_rounds); - encode_base64(salt + 7, csalt, sizeof(csalt)); - - return 0; -} - -/* - * the core bcrypt function - */ -static int -bcrypt_hashpass(const char *key, const char *salt, char *encrypted, - size_t encryptedlen) -{ - blf_ctx state; - u_int32_t rounds, i, k; - u_int16_t j; - size_t key_len; - u_int8_t salt_len, logr, minor; - u_int8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt"; - u_int8_t csalt[BCRYPT_MAXSALT]; - u_int32_t cdata[BCRYPT_WORDS]; - - if (encryptedlen < BCRYPT_HASHSPACE) - goto inval; - - /* Check and discard "$" identifier */ - if (salt[0] != '$') - goto inval; - salt += 1; - - if (salt[0] != BCRYPT_VERSION) - goto inval; - - /* Check for minor versions */ - switch ((minor = salt[1])) { - case 'a': - key_len = (u_int8_t)(strlen(key) + 1); - break; - case 'b': - /* strlen() returns a size_t, but the function calls - * below result in implicit casts to a narrower integer - * type, so cap key_len at the actual maximum supported - * length here to avoid integer wraparound */ - key_len = strlen(key); - if (key_len > 72) - key_len = 72; - key_len++; /* include the NUL */ - break; - default: - goto inval; - } - if (salt[2] != '$') - goto inval; - /* Discard version + "$" identifier */ - salt += 3; - - /* Check and parse num rounds */ - if (!isdigit((unsigned char)salt[0]) || - !isdigit((unsigned char)salt[1]) || salt[2] != '$') - goto inval; - logr = (salt[1] - '0') + ((salt[0] - '0') * 10); - if (logr < BCRYPT_MINLOGROUNDS || logr > 31) - goto inval; - /* Computer power doesn't increase linearly, 2^x should be fine */ - rounds = 1U << logr; - - /* Discard num rounds + "$" identifier */ - salt += 3; - - if (strlen(salt) * 3 / 4 < BCRYPT_MAXSALT) - goto inval; - - /* We dont want the base64 salt but the raw data */ - if (decode_base64(csalt, BCRYPT_MAXSALT, salt)) - goto inval; - salt_len = BCRYPT_MAXSALT; - - /* 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_WORDS; i++) - cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j); - - /* Now do the encryption */ - for (k = 0; k < 64; k++) - blf_enc(&state, cdata, BCRYPT_WORDS / 2); - - for (i = 0; i < BCRYPT_WORDS; 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; - } - - - snprintf(encrypted, 8, "$2%c$%2.2u$", minor, logr); - encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT); - encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1); - explicit_bzero(&state, sizeof(state)); - explicit_bzero(ciphertext, sizeof(ciphertext)); - explicit_bzero(csalt, sizeof(csalt)); - explicit_bzero(cdata, sizeof(cdata)); - return 0; - -inval: - errno = EINVAL; - return -1; -} - -/* - * user friendly functions - */ -int -bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen) -{ - char salt[BCRYPT_SALTSPACE]; - - if (bcrypt_initsalt(log_rounds, salt, sizeof(salt)) != 0) - return -1; - - if (bcrypt_hashpass(pass, salt, hash, hashlen) != 0) - return -1; - - explicit_bzero(salt, sizeof(salt)); - return 0; -} -DEF_WEAK(bcrypt_newhash); - -int -bcrypt_checkpass(const char *pass, const char *goodhash) -{ - char hash[BCRYPT_HASHSPACE]; - - if (bcrypt_hashpass(pass, goodhash, hash, sizeof(hash)) != 0) - return -1; - if (strlen(hash) != strlen(goodhash) || - timingsafe_bcmp(hash, goodhash, strlen(goodhash)) != 0) { - errno = EACCES; - return -1; - } - - explicit_bzero(hash, sizeof(hash)); - return 0; -} -DEF_WEAK(bcrypt_checkpass); - -/* - * Measure this system's performance by measuring the time for 8 rounds. - * We are aiming for something that takes around 0.1s, but not too much over. - */ -int -_bcrypt_autorounds(void) -{ - struct timespec before, after; - int r = 8; - char buf[_PASSWORD_LEN]; - int duration; - - WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &before); - bcrypt_newhash("testpassword", r, buf, sizeof(buf)); - WRAP(clock_gettime)(CLOCK_THREAD_CPUTIME_ID, &after); - - duration = after.tv_sec - before.tv_sec; - duration *= 1000000; - duration += (after.tv_nsec - before.tv_nsec) / 1000; - - /* too quick? slow it down. */ - while (r < 16 && duration <= 60000) { - r += 1; - duration *= 2; - } - /* too slow? speed it up. */ - while (r > 6 && duration > 120000) { - r -= 1; - duration /= 2; - } - - return r; -} - -/* - * internal utilities - */ -static const u_int8_t Base64Code[] = -"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - -static const 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)]) - -/* - * read buflen (after decoding) bytes of data from b64data - */ -static int -decode_base64(u_int8_t *buffer, size_t len, const char *b64data) -{ - u_int8_t *bp = buffer; - const u_int8_t *p = b64data; - u_int8_t c1, c2, c3, c4; - - while (bp < buffer + len) { - c1 = CHAR64(*p); - /* Invalid data */ - if (c1 == 255) - return -1; - - c2 = CHAR64(*(p + 1)); - if (c2 == 255) - return -1; - - *bp++ = (c1 << 2) | ((c2 & 0x30) >> 4); - if (bp >= buffer + len) - break; - - c3 = CHAR64(*(p + 2)); - if (c3 == 255) - return -1; - - *bp++ = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2); - if (bp >= buffer + len) - break; - - c4 = CHAR64(*(p + 3)); - if (c4 == 255) - return -1; - *bp++ = ((c3 & 0x03) << 6) | c4; - - p += 4; - } - return 0; -} - -/* - * Turn len bytes of data into base64 encoded data. - * This works without = padding. - */ -static int -encode_base64(char *b64buffer, const u_int8_t *data, size_t len) -{ - u_int8_t *bp = b64buffer; - const 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'; - return 0; -} - -/* - * classic interface - */ -char * -bcrypt_gensalt(u_int8_t log_rounds) -{ - static char gsalt[BCRYPT_SALTSPACE]; - - bcrypt_initsalt(log_rounds, gsalt, sizeof(gsalt)); - - return gsalt; -} - -char * -bcrypt(const char *pass, const char *salt) -{ - static char gencrypted[BCRYPT_HASHSPACE]; - - if (bcrypt_hashpass(pass, salt, gencrypted, sizeof(gencrypted)) != 0) - return NULL; - - return gencrypted; -} -DEF_WEAK(bcrypt); diff --git a/src/lib/libc/crypt/blowfish.3 b/src/lib/libc/crypt/blowfish.3 deleted file mode 100644 index c64ccb684b..0000000000 --- a/src/lib/libc/crypt/blowfish.3 +++ /dev/null @@ -1,103 +0,0 @@ -.\" $OpenBSD: blowfish.3,v 1.24 2021/11/29 01:04:45 djm 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. 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: November 29 2021 $ -.Dt BLF_KEY 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 -.In blf.h -.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 Mt 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 05ad00d7a1..0000000000 --- a/src/lib/libc/crypt/blowfish.c +++ /dev/null @@ -1,688 +0,0 @@ -/* $OpenBSD: blowfish.c,v 1.21 2022/08/28 11:11:25 jsg 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. 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 - -/* 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; -} -DEF_WEAK(Blowfish_encipher); - -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; -} -DEF_WEAK(Blowfish_decipher); - -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; -} -DEF_WEAK(Blowfish_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; -} -DEF_WEAK(Blowfish_stream2word); - -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; - } - } -} -DEF_WEAK(Blowfish_expand0state); - - -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; - } - } - -} -DEF_WEAK(Blowfish_expandstate); - -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); -} -DEF_WEAK(blf_key); - -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; - } -} -DEF_WEAK(blf_enc); - -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; - } -} -DEF_WEAK(blf_dec); - -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; - } -} -DEF_WEAK(blf_ecb_encrypt); - -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; - } -} -DEF_WEAK(blf_ecb_decrypt); - -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; - } -} -DEF_WEAK(blf_cbc_encrypt); - -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]; -} -DEF_WEAK(blf_cbc_decrypt); - -#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/chacha_private.h b/src/lib/libc/crypt/chacha_private.h deleted file mode 100644 index b0427b6b3e..0000000000 --- a/src/lib/libc/crypt/chacha_private.h +++ /dev/null @@ -1,222 +0,0 @@ -/* -chacha-merged.c version 20080118 -D. J. Bernstein -Public domain. -*/ - -/* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */ - -typedef unsigned char u8; -typedef unsigned int u32; - -typedef struct -{ - u32 input[16]; /* could be compressed */ -} chacha_ctx; - -#define U8C(v) (v##U) -#define U32C(v) (v##U) - -#define U8V(v) ((u8)(v) & U8C(0xFF)) -#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) - -#define ROTL32(v, n) \ - (U32V((v) << (n)) | ((v) >> (32 - (n)))) - -#define U8TO32_LITTLE(p) \ - (((u32)((p)[0]) ) | \ - ((u32)((p)[1]) << 8) | \ - ((u32)((p)[2]) << 16) | \ - ((u32)((p)[3]) << 24)) - -#define U32TO8_LITTLE(p, v) \ - do { \ - (p)[0] = U8V((v) ); \ - (p)[1] = U8V((v) >> 8); \ - (p)[2] = U8V((v) >> 16); \ - (p)[3] = U8V((v) >> 24); \ - } while (0) - -#define ROTATE(v,c) (ROTL32(v,c)) -#define XOR(v,w) ((v) ^ (w)) -#define PLUS(v,w) (U32V((v) + (w))) -#define PLUSONE(v) (PLUS((v),1)) - -#define QUARTERROUND(a,b,c,d) \ - a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \ - a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ - c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); - -static const char sigma[16] = "expand 32-byte k"; -static const char tau[16] = "expand 16-byte k"; - -static void -chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits) -{ - const char *constants; - - x->input[4] = U8TO32_LITTLE(k + 0); - x->input[5] = U8TO32_LITTLE(k + 4); - x->input[6] = U8TO32_LITTLE(k + 8); - x->input[7] = U8TO32_LITTLE(k + 12); - if (kbits == 256) { /* recommended */ - k += 16; - constants = sigma; - } else { /* kbits == 128 */ - constants = tau; - } - x->input[8] = U8TO32_LITTLE(k + 0); - x->input[9] = U8TO32_LITTLE(k + 4); - x->input[10] = U8TO32_LITTLE(k + 8); - x->input[11] = U8TO32_LITTLE(k + 12); - x->input[0] = U8TO32_LITTLE(constants + 0); - x->input[1] = U8TO32_LITTLE(constants + 4); - x->input[2] = U8TO32_LITTLE(constants + 8); - x->input[3] = U8TO32_LITTLE(constants + 12); -} - -static void -chacha_ivsetup(chacha_ctx *x,const u8 *iv) -{ - x->input[12] = 0; - x->input[13] = 0; - x->input[14] = U8TO32_LITTLE(iv + 0); - x->input[15] = U8TO32_LITTLE(iv + 4); -} - -static void -chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes) -{ - u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; - u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; - u8 *ctarget = NULL; - u8 tmp[64]; - u_int i; - - if (!bytes) return; - - j0 = x->input[0]; - j1 = x->input[1]; - j2 = x->input[2]; - j3 = x->input[3]; - j4 = x->input[4]; - j5 = x->input[5]; - j6 = x->input[6]; - j7 = x->input[7]; - j8 = x->input[8]; - j9 = x->input[9]; - j10 = x->input[10]; - j11 = x->input[11]; - j12 = x->input[12]; - j13 = x->input[13]; - j14 = x->input[14]; - j15 = x->input[15]; - - for (;;) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) tmp[i] = m[i]; - m = tmp; - ctarget = c; - c = tmp; - } - x0 = j0; - x1 = j1; - x2 = j2; - x3 = j3; - x4 = j4; - x5 = j5; - x6 = j6; - x7 = j7; - x8 = j8; - x9 = j9; - x10 = j10; - x11 = j11; - x12 = j12; - x13 = j13; - x14 = j14; - x15 = j15; - for (i = 20;i > 0;i -= 2) { - QUARTERROUND( x0, x4, x8,x12) - QUARTERROUND( x1, x5, x9,x13) - QUARTERROUND( x2, x6,x10,x14) - QUARTERROUND( x3, x7,x11,x15) - QUARTERROUND( x0, x5,x10,x15) - QUARTERROUND( x1, x6,x11,x12) - QUARTERROUND( x2, x7, x8,x13) - QUARTERROUND( x3, x4, x9,x14) - } - x0 = PLUS(x0,j0); - x1 = PLUS(x1,j1); - x2 = PLUS(x2,j2); - x3 = PLUS(x3,j3); - x4 = PLUS(x4,j4); - x5 = PLUS(x5,j5); - x6 = PLUS(x6,j6); - x7 = PLUS(x7,j7); - x8 = PLUS(x8,j8); - x9 = PLUS(x9,j9); - x10 = PLUS(x10,j10); - x11 = PLUS(x11,j11); - x12 = PLUS(x12,j12); - x13 = PLUS(x13,j13); - x14 = PLUS(x14,j14); - x15 = PLUS(x15,j15); - -#ifndef KEYSTREAM_ONLY - x0 = XOR(x0,U8TO32_LITTLE(m + 0)); - x1 = XOR(x1,U8TO32_LITTLE(m + 4)); - x2 = XOR(x2,U8TO32_LITTLE(m + 8)); - x3 = XOR(x3,U8TO32_LITTLE(m + 12)); - x4 = XOR(x4,U8TO32_LITTLE(m + 16)); - x5 = XOR(x5,U8TO32_LITTLE(m + 20)); - x6 = XOR(x6,U8TO32_LITTLE(m + 24)); - x7 = XOR(x7,U8TO32_LITTLE(m + 28)); - x8 = XOR(x8,U8TO32_LITTLE(m + 32)); - x9 = XOR(x9,U8TO32_LITTLE(m + 36)); - x10 = XOR(x10,U8TO32_LITTLE(m + 40)); - x11 = XOR(x11,U8TO32_LITTLE(m + 44)); - x12 = XOR(x12,U8TO32_LITTLE(m + 48)); - x13 = XOR(x13,U8TO32_LITTLE(m + 52)); - x14 = XOR(x14,U8TO32_LITTLE(m + 56)); - x15 = XOR(x15,U8TO32_LITTLE(m + 60)); -#endif - - j12 = PLUSONE(j12); - if (!j12) { - j13 = PLUSONE(j13); - /* stopping at 2^70 bytes per nonce is user's responsibility */ - } - - U32TO8_LITTLE(c + 0,x0); - U32TO8_LITTLE(c + 4,x1); - U32TO8_LITTLE(c + 8,x2); - U32TO8_LITTLE(c + 12,x3); - U32TO8_LITTLE(c + 16,x4); - U32TO8_LITTLE(c + 20,x5); - U32TO8_LITTLE(c + 24,x6); - U32TO8_LITTLE(c + 28,x7); - U32TO8_LITTLE(c + 32,x8); - U32TO8_LITTLE(c + 36,x9); - U32TO8_LITTLE(c + 40,x10); - U32TO8_LITTLE(c + 44,x11); - U32TO8_LITTLE(c + 48,x12); - U32TO8_LITTLE(c + 52,x13); - U32TO8_LITTLE(c + 56,x14); - U32TO8_LITTLE(c + 60,x15); - - if (bytes <= 64) { - if (bytes < 64) { - for (i = 0;i < bytes;++i) ctarget[i] = c[i]; - } - x->input[12] = j12; - x->input[13] = j13; - return; - } - bytes -= 64; - c += 64; -#ifndef KEYSTREAM_ONLY - m += 64; -#endif - } -} diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3 deleted file mode 100644 index 6a21571ddb..0000000000 --- a/src/lib/libc/crypt/crypt.3 +++ /dev/null @@ -1,144 +0,0 @@ -.\" $OpenBSD: crypt.3,v 1.46 2025/01/09 23:18:08 jsg 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: January 9 2025 $ -.Dt CRYPT 3 -.Os -.Sh NAME -.Nm crypt , -.Nm bcrypt_gensalt , -.Nm bcrypt -.Nd password hashing -.Sh SYNOPSIS -.In stdlib.h -.Pp -.In unistd.h -.Ft char * -.Fn crypt "const char *key" "const char *setting" -.In pwd.h -.Ft char * -.Fn bcrypt_gensalt "u_int8_t log_rounds" -.Ft char * -.Fn bcrypt "const char *key" "const char *salt" -.Sh DESCRIPTION -These functions are deprecated in favor of -.Xr crypt_checkpass 3 -and -.Xr crypt_newhash 3 . -.Pp -The -.Fn crypt -function performs password hashing. -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 NUL-terminated -string -.Fa key , -typically a user's typed password. -The second, -.Fa setting , -currently supports a single form. -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 -.Ql $2 -chooses Blowfish hashing; see below for more information. -.Ss Blowfish crypt -The 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 -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 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 $2b$12$FPWWO2RJ3CK4FINTw0Hi8OiPKJcX653gzSS.jqltHFMxyDmmQ0Hqq . -.Pp -The whole Blowfish password string is passed as -.Fa setting -for interpretation. -.Sh RETURN VALUES -The function -.Fn crypt -returns a pointer to the encrypted value on success, and -.Dv NULL -on failure. -.Sh SEE ALSO -.Xr encrypt 1 , -.Xr login 1 , -.Xr passwd 1 , -.Xr blowfish 3 , -.Xr crypt_checkpass 3 , -.Xr getpass 3 , -.Xr passwd 5 -.Sh HISTORY -An M-209 based -.Fn crypt -function appeared in -.At v3 . -A DES-based -.Fn crypt -first appeared in -.At v7 . -.Fn bcrypt -first appeared in -.Ox 2.1 . -.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 40d5503544..0000000000 --- a/src/lib/libc/crypt/crypt.c +++ /dev/null @@ -1,22 +0,0 @@ -/* $OpenBSD: crypt.c,v 1.31 2015/09/12 14:56:50 guenther Exp $ */ - -#include -#include -#include - -char * -crypt(const char *key, const char *setting) -{ - if (setting[0] == '$') { - switch (setting[1]) { - case '2': - return bcrypt(key, setting); - default: - errno = EINVAL; - return (NULL); - } - } - errno = EINVAL; - return (NULL); -} -DEF_WEAK(crypt); diff --git a/src/lib/libc/crypt/crypt_checkpass.3 b/src/lib/libc/crypt/crypt_checkpass.3 deleted file mode 100644 index 07a77ae7c0..0000000000 --- a/src/lib/libc/crypt/crypt_checkpass.3 +++ /dev/null @@ -1,113 +0,0 @@ -.\" $OpenBSD: crypt_checkpass.3,v 1.13 2021/10/29 10:54:33 deraadt Exp $ -.\" -.\" Copyright (c) 2014 Ted Unangst -.\" -.\" 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. -.\" -.Dd $Mdocdate: October 29 2021 $ -.Dt CRYPT_CHECKPASS 3 -.Os -.Sh NAME -.Nm crypt_checkpass , -.Nm crypt_newhash -.Nd password hashing -.Sh SYNOPSIS -.In pwd.h -.In unistd.h -.Ft int -.Fn crypt_checkpass "const char *password" "const char *hash" -.Ft int -.Fn crypt_newhash "const char *password" "const char *pref" "char *hash" "size_t hashsize" -.Sh DESCRIPTION -The -.Fn crypt_checkpass -function simplifies checking a user's password. -If both the -.Fa hash -and the -.Fa password -are the empty string, authentication -is a success. -Otherwise, the -.Fa password -is hashed and compared to the provided -.Fa hash . -If the -.Fa hash -is -.Dv NULL , -authentication will always fail, but a default -amount of work is performed to simulate the hashing operation. -A successful match will return 0. -A failure will return \-1 and set -.Xr errno 2 . -.Pp -The -.Fn crypt_newhash -function simplifies the creation of new password hashes. -The provided -.Fa password -is randomly salted and hashed and stored in -.Fa hash . -The size of the available space is specified by -.Fa hashsize , -which should be -.Dv _PASSWORD_LEN . -The -.Fa pref -argument identifies the preferred hashing algorithm and parameters. -Possible values are: -.Bl -tag -width Ds -.It Dq bcrypt, -The bcrypt algorithm, where the value of rounds can be between 4 and 31 and -specifies the base 2 logarithm of the number of rounds. -If rounds is omitted or the special value -.Sq a , -an appropriate number of rounds is automatically selected based on system -performance. -.El -.Sh RETURN VALUES -.Rv -std crypt_checkpass crypt_newhash -.Sh ERRORS -The -.Fn crypt_checkpass -function sets -.Va errno -to -.Er EACCES -when authentication fails. -.Pp -The -.Fn crypt_newhash -function sets -.Va errno -to -.Er EINVAL -if -.Fa pref -is unsupported or insufficient space is provided. -.Sh SEE ALSO -.Xr crypt 3 , -.Xr login.conf 5 , -.Xr passwd 5 -.Sh HISTORY -The function -.Fn crypt_checkpass -first appeared in -.Ox 5.6 , -and -.Fn crypt_newhash -in -.Ox 5.7 . -.Sh AUTHORS -.An Ted Unangst Aq Mt tedu@openbsd.org diff --git a/src/lib/libc/crypt/cryptutil.c b/src/lib/libc/crypt/cryptutil.c deleted file mode 100644 index f5fdb29589..0000000000 --- a/src/lib/libc/crypt/cryptutil.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: cryptutil.c,v 1.13 2024/01/22 19:26:55 deraadt Exp $ */ -/* - * Copyright (c) 2014 Ted Unangst - * - * 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. - */ -#include -#include -#include -#include -#include -#include - -int -crypt_checkpass(const char *pass, const char *goodhash) -{ - char dummy[_PASSWORD_LEN]; - - if (goodhash == NULL) { - /* fake it */ - goto fake; - } - - /* empty password */ - if (strlen(goodhash) == 0 && strlen(pass) == 0) - return 0; - - if (goodhash[0] == '$' && goodhash[1] == '2') { - if (bcrypt_checkpass(pass, goodhash)) - goto fail; - return 0; - } - - /* unsupported. fake it. */ -fake: - bcrypt_newhash(pass, 8, dummy, sizeof(dummy)); -fail: - errno = EACCES; - return -1; -} -DEF_WEAK(crypt_checkpass); - -int -crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen) -{ - int rv = -1; - const char *defaultpref = "bcrypt,8"; - const char *errstr; - const char *choices[] = { "blowfish", "bcrypt" }; - size_t maxchoice = sizeof(choices) / sizeof(choices[0]); - int i; - int rounds; - - if (pref == NULL) - pref = defaultpref; - - for (i = 0; i < maxchoice; i++) { - const char *choice = choices[i]; - size_t len = strlen(choice); - if (strcmp(pref, choice) == 0) { - rounds = _bcrypt_autorounds(); - break; - } else if (strncmp(pref, choice, len) == 0 && - pref[len] == ',') { - if (strcmp(pref + len + 1, "a") == 0) { - rounds = _bcrypt_autorounds(); - } else { - rounds = strtonum(pref + len + 1, 4, 31, &errstr); - if (errstr) { - errno = EINVAL; - goto err; - } - } - break; - } - } - if (i == maxchoice) { - errno = EINVAL; - goto err; - } - - rv = bcrypt_newhash(pass, rounds, hash, hashlen); - -err: - return rv; -} -DEF_WEAK(crypt_newhash); diff --git a/src/lib/libc/include/DETAILS b/src/lib/libc/include/DETAILS deleted file mode 100644 index 6382cc1c0d..0000000000 --- a/src/lib/libc/include/DETAILS +++ /dev/null @@ -1,133 +0,0 @@ -The goal: calls from inside libc to other libc functions should - * not be overridable (except for the malloc family), and - * not have pointless inefficiencies. - -To achieve this, we arrange that all these internal call be via -identifiers that are of hidden visibility and--to avoid confusion -and work correctly in static executables--are in the reserved -namespace. - -This document describes the details of the naming scheme and how -it is implemented. - -I've chosen a prefix of underbar-libc-underbar ("_libc_") for this. -These are not declared directly; instead, the gcc "asm labels" -extension is used to rename the function. - -We need many of the symbols to be weak in *static* builds, but they -can be strong in the dynamic library, as there's a natural precedence -from the search order there. When the descriptions below say a -name is "weak", that is only necessary for the static library and -not for the shared library. Note: use defined(PIC) to recognize -when compiling the shared objects: some archs define __PIC__ *all* -the time. - ---------- - -For syscalls which are not cancellation points, such as getpid(), -the identifiers are just: - _libc_getpid hidden alias, for use internal to libc only - _thread_sys_getpid global name, for use outside libc only - getpid weak alias, for use outside libc only - -For syscalls which are cancellation points, such as wait4(), there -are identifiers that do not provide cancellation: - _libc_wait4 hidden alias, for use internal to libc only - _thread_sys_wait4 global name, for use outside libc only -...and identifiers that do provide cancellation: - wait4 weak alias, for general use - _libc_wait4_cancel hidden name, for use internal to libc only -Inside libc, the bare name ("wait4") binds to the version *with* -cancellation. If it's necessary to use the syscall without doing -cancellation it can be obtained by calling HIDDEN(x) instead of -just x. - -Some other calls need to be wrapped for reasons other than cancellation, -such as to provide functionality beyond the underlying syscall (e.g., -ptrace). For these, there are identifiers for the raw call, without -the wrapping: - _libc_ptrace hidden alias, for use internal to libc only - _thread_sys_ptrace global name, for use outside libc only -...and identifiers that do provide the libc wrapping: - ptrace weak alias, for general use - _libc_ptrace_wrap hidden name, for use internal to libc only -Inside libc, the bare name ("ptrace") binds to the wrapper; if -the raw version is necessary it can be obtained by calling HIDDEN(x) -instead of just x. - -For syscalls implemented in ASM, the aliases of the raw syscall stub -are provided by the ASM macros. Of the macros used by sys/Makefile.inc: -RSYSCALL(), PSEUDO(), and PSEUDO_NOERROR() generate all three names -(ala getpid() above), while RSYSCALL_HIDDEN() generates just the -_thread_sys_x and _libc_x names. - - - -By using gcc's "asm label" extension, we can usually avoid having -to type those prefixes in the .h and .c files. However, for those -cases where a non-default binding is necessary we can use these macros -to get the desired identifier: - - CANCEL(x) - This expands to the internal, hidden name of a cancellation - wrapper: _libc_x_cancel. ex: CANCEL(fsync)(fd) - - WRAP(x) - This expands to the internal, hidden name of a non-cancellation - wrapper: _libc_x_wrap. ex: WRAP(sigprocmask)(set) - - -In order to actually set up the desired asm labels, we use these in -the internal .h files: - PROTO_NORMAL(x) Symbols used both internally and externally - This makes gcc convert use of x to use _libc_x instead - ex: PROTO_NORMAL(getpid) - - PROTO_STD_DEPRECATED(x) Standard C symbols that we don't want to use - This just marks the symbol as deprecated, with no renaming. - ex: PROTO_STD_DEPRECATED(strcpy) - - PROTO_DEPRECATED(x) Symbols not in ISO C that we don't want to use - This marks the symbol as both weak and deprecated, with no renaming - ex: PROTO_DEPRECATED(creat) - - PROTO_CANCEL(x) Functions that have cancellation wrappers - Like PROTO_NORMAL(x), but also declares _libc_x_cancel - ex: PROTO_CANCEL(wait4) - - PROTO_WRAP(x) Functions that have wrappers for other reasons - Like PROTO_NORMAL(x), but also declares _libc_x_wrap. Internal - calls that want the wrapper's processing should invoke WRAP(x)(...) - ex: PROTO_WRAP(sigaction) - - -Finally, to create the expected aliases, we use these in the .c files -where the definitions are: - DEF_STRONG(x) Symbols reserved to or specified by ISO C - This defines x as a strong alias for _libc_x; this must only - be used for symbols that are reserved by the C standard - (or reserved in the external identifier namespace). - Matches with PROTO_NORMAL() - ex: DEF_STRONG(fopen) - - DEF_WEAK(x) Symbols used internally and not in ISO C - This defines x as a weak alias for _libc_x - Matches with PROTO_NORMAL() - ex: DEF_WEAK(lseek) - - DEF_CANCEL(x) Symbols that have a cancellation wrapper - This defines x as a weak alias for _libc_x_cancel. - Matches with PROTO_CANCEL() - ex: DEF_CANCEL(read) - - DEF_WRAP(x) - This defines x as a weak alias for _libc_x_wrap. - Matches with PROTO_WRAP() - ex: DEF_WRAP(ptrace) - - MAKE_CLONE(dst, src) Symbols that are exact clones of other symbols - This declares _libc_dst as being the same type as dst, and makes - _libc_dst a strong, hidden alias for _libc_src. You still need to - DEF_STRONG(dst) or DEF_WEAK(dst) to alias dst itself - ex: MAKE_CLONE(SHA224Pad, SHA256Pad) - diff --git a/src/lib/libc/include/README b/src/lib/libc/include/README deleted file mode 100644 index 89acee491e..0000000000 --- a/src/lib/libc/include/README +++ /dev/null @@ -1,110 +0,0 @@ -So you want to add an interface to libc... - -CASE I: internal symbols - - A) used in a single file - Duh: use whatever name you want and make it static - - B) used in multiple files - Give it a name in the implementation namespace (leading underbar) - and declare it in a __{BEGIN,END}_HIDDEN_DECLS block in a .h - file inside libc. If it's used in just a single subdir of - libc *and* that subdir has an appropriate .h file in it, then - declare it there. - Example: stdio/local.h. - Otherwise, declare it in one of the hidden/* files. - Example: _mktemp() in hidden/stdio.h - -CASE II: external symbols - - First of all, add your symbol to Symbols.list. MD symbols go in - arch/*/Symbols.list (shock, I know) - - Declare your function in the appropriate header. It almost certainly - should be in a public header installed under /usr/include/. Exceptions - are symbols that are just shared between libc and libpthread/csu/ld.so - which are only declared in libc/include/* or just in each .c file. - - A) objects (variables) - That's it, you're done. - - - B) plain C functions (not syscalls) - 1) functions that are *not* called from inside libc - - If this function is specified in the ISO C standard or its - name begins with an underbar, then in the hidden/* version - of the header where you declared the function, add this line: - PROTO_STD_DEPRECATED(your_function_name); - - Otherwise, this is *not* a function specified in the ISO C - standard and its name begins with a letter. In the hidden/* - version of the header where you declared the function, add - this line: - PROTO_DEPRECATED(your_function_name); - - Note: the "DEPRECATED" suffix is about a detail of - how the macros work and has nothing to do with whether the - function itself is a Good Thing vs deprecated. - - 2) functions that are called from inside libc - - In the hidden/* version of the header where you declared - the function, add this line: - PROTO_NORMAL(your_function_name); - - Then, in the .c file(s) where the function is defined: - - if the function is specified in the ISO C standard or - its name begins with an underbar, add - DEF_STRONG(your_function_name); - - - otherwise, add: - DEF_WEAK(your_function_name); - - - C) syscalls that don't require any wrapping - - In the hidden/* version of the header where you declared the - function, add this line: - PROTO_NORMAL(your_function_name); - - Generate the stub by adding it to the ASM variable in - libc/sys/Makefile.inc - - - D) syscalls that require cancellation or similar wrappers that don't - change the function signature - - Generate the stub by adding it to the HIDDEN (*not* ASM!) - variable in libc/sys/Makefile.inc - - In the hidden/* version of the header where you declared the - function, add this line: - PROTO_WRAP(your_function_name); - - The wrapper function should be defined in - libc/sys/w_your_function_name.c - which should define WRAP(your_function_name) and follow it - with DEF_WRAP(your_function_name). Look at libc/sys/w_sigaction.c - for an example. - - By default, libc code that calls your_function_name() will get - the real syscall and *not* the wrapper. libc calls that need - to go through the wrapper should invoke WRAP(your_function_name) - - - E) syscalls that require libc wrappers for other reasons - First of all, make sure this really is the Right Thing. Talk - with kettenis, deraadt, millert, and guenther. - - If the actual syscall doesn't have the same calling convention - as the C interface, then maybe it shouldn't be exported at all - and you should just have an ASM stub, like SYS___tfork --> - __tfork_thread() or SYS_break --> brk() and sbrk(). If it - _could_ be called from C, then give the syscall a name different - from the C API. Syscalls that fail this for historical reasons - (e.g., exit == _exit(2)) are generated with PSEUDO/PSEUDO_NOERR - in libc/sys/Makefile.inc, so the ASM stub has a leading underbar. - Go read gen/getlogin.c rev 1.13 for an example of how to do - this, but don't pick this option, really. - diff --git a/src/lib/libc/include/atfork.h b/src/lib/libc/include/atfork.h deleted file mode 100644 index f09de4892a..0000000000 --- a/src/lib/libc/include/atfork.h +++ /dev/null @@ -1,45 +0,0 @@ -/* $OpenBSD: atfork.h,v 1.2 2015/08/27 04:37:09 guenther Exp $ */ - -/* - * Copyright (c) 2008 Kurt Miller - * Copyright (c) 2008 Philip Guenther - * Copyright (c) 2003 Daniel Eischen - * 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. Neither the name of the author nor the names of any co-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. - * - * $FreeBSD: /repoman/r/ncvs/src/lib/libc_r/uthread/uthread_atfork.c,v 1.1 2004/12/10 03:36:45 grog Exp $ - */ - -#include - -struct atfork_fn { - TAILQ_ENTRY(atfork_fn) fn_next; - void (*fn_prepare)(void); - void (*fn_parent)(void); - void (*fn_child)(void); - void *fn_dso; -}; - -__BEGIN_HIDDEN_DECLS -extern TAILQ_HEAD(atfork_listhead, atfork_fn) _atfork_list; -__END_HIDDEN_DECLS diff --git a/src/lib/libc/include/cancel.h b/src/lib/libc/include/cancel.h deleted file mode 100644 index c452bf3d4c..0000000000 --- a/src/lib/libc/include/cancel.h +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: cancel.h,v 1.5 2017/09/05 02:40:54 guenther Exp $ */ -/* - * Copyright (c) 2015 Philip Guenther - * - * 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. - */ - -#ifndef _CANCEL_H_ -#define _CANCEL_H_ - -#include -#include "thread_private.h" - -/* process a cancel request at a cancel point */ -__dead void _thread_canceled(void); - -#ifdef __LIBC__ -PROTO_NORMAL(_thread_canceled); -#endif - -#if defined(__LIBC__) && !defined(TCB_HAVE_MD_GET) -/* - * Override TIB_GET macro to use the caching callback - */ -#undef TIB_GET -#define TIB_GET() TCB_TO_TIB(_thread_cb.tc_tcb()) -#endif - -#define PREP_CANCEL_POINT(tib) \ - int _cantcancel = (tib)->tib_cantcancel - -#define ENTER_CANCEL_POINT_INNER(tib, can_cancel, delay) \ - if (_cantcancel == 0) { \ - (tib)->tib_cancel_point = (delay) ? \ - CANCEL_POINT_DELAYED : CANCEL_POINT; \ - if (can_cancel) { \ - __asm volatile("":::"memory"); \ - if (__predict_false((tib)->tib_canceled)) \ - _thread_canceled(); \ - } \ - } - -#define LEAVE_CANCEL_POINT_INNER(tib, can_cancel) \ - if (_cantcancel == 0) { \ - (tib)->tib_cancel_point = 0; \ - if (can_cancel) { \ - __asm volatile("":::"memory"); \ - if (__predict_false((tib)->tib_canceled)) \ - _thread_canceled(); \ - } \ - } - -/* - * Enter or leave a cancelation point, optionally processing pending - * cancelation requests. Note that ENTER_CANCEL_POINT opens a block - * and LEAVE_CANCEL_POINT must close that same block. - */ -#define ENTER_CANCEL_POINT(can_cancel) \ - { \ - struct tib *_tib = TIB_GET(); \ - PREP_CANCEL_POINT(_tib); \ - ENTER_CANCEL_POINT_INNER(_tib, can_cancel, 0) - -#define LEAVE_CANCEL_POINT(can_cancel) \ - LEAVE_CANCEL_POINT_INNER(_tib, can_cancel); \ - } - -#endif /* _CANCEL_H_ */ diff --git a/src/lib/libc/include/ctype_private.h b/src/lib/libc/include/ctype_private.h deleted file mode 100644 index cbe1b20475..0000000000 --- a/src/lib/libc/include/ctype_private.h +++ /dev/null @@ -1,9 +0,0 @@ -/* $OpenBSD: ctype_private.h,v 1.2 2015/08/27 04:37:09 guenther Exp $ */ -/* Written by Marc Espie, public domain */ -#define CTYPE_NUM_CHARS 256 - -__BEGIN_HIDDEN_DECLS -extern const char _C_ctype_[]; -extern const short _C_toupper_[]; -extern const short _C_tolower_[]; -__END_HIDDEN_DECLS diff --git a/src/lib/libc/include/localedef.h b/src/lib/libc/include/localedef.h deleted file mode 100644 index 12dd47fffa..0000000000 --- a/src/lib/libc/include/localedef.h +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: localedef.h,v 1.1 2016/05/23 00:05:15 guenther Exp $ */ -/* $NetBSD: localedef.h,v 1.4 1996/04/09 20:55:31 cgd Exp $ */ - -/* - * Copyright (c) 1994 Winning Strategies, 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. - * 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 Winning Strategies, Inc. - * 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. - */ - -#ifndef _LOCALEDEF_H_ -#define _LOCALEDEF_H_ - -#include - -typedef struct -{ - char *yesexpr; - char *noexpr; - char *yesstr; - char *nostr; -} _MessagesLocale; - - -typedef struct -{ - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -} _MonetaryLocale; - - -typedef struct -{ - const char *decimal_point; - const char *thousands_sep; - const char *grouping; -} _NumericLocale; - - -typedef struct { - const char *abday[7]; - const char *day[7]; - const char *abmon[12]; - const char *mon[12]; - const char *am_pm[2]; - const char *d_t_fmt; - const char *d_fmt; - const char *t_fmt; - const char *t_fmt_ampm; -} _TimeLocale; - - -__BEGIN_HIDDEN_DECLS -extern const _MessagesLocale *_CurrentMessagesLocale; -extern const _MessagesLocale _DefaultMessagesLocale; -extern const _MonetaryLocale *_CurrentMonetaryLocale; -extern const _MonetaryLocale _DefaultMonetaryLocale; -extern const _NumericLocale *_CurrentNumericLocale; -extern const _NumericLocale _DefaultNumericLocale; -extern const _TimeLocale *_CurrentTimeLocale; -extern const _TimeLocale _DefaultTimeLocale; -__END_HIDDEN_DECLS - -#endif /* !_LOCALEDEF_H_ */ diff --git a/src/lib/libc/include/mpool.h b/src/lib/libc/include/mpool.h deleted file mode 100644 index 005b006d17..0000000000 --- a/src/lib/libc/include/mpool.h +++ /dev/null @@ -1,122 +0,0 @@ -/* $OpenBSD: mpool.h,v 1.1 2015/09/09 15:35:24 guenther Exp $ */ -/* $NetBSD: mpool.h,v 1.7 1996/05/03 21:13:41 cgd Exp $ */ - -/*- - * Copyright (c) 1991, 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. - * - * @(#)mpool.h 8.4 (Berkeley) 11/2/95 - */ - -#ifndef _MPOOL_H_ -#define _MPOOL_H_ - -#include - -/* - * The memory pool scheme is a simple one. Each in-memory page is referenced - * by a bucket which is threaded in up to two of three ways. All active pages - * are threaded on a hash chain (hashed by page number) and an lru chain. - * Inactive pages are threaded on a free chain. Each reference to a memory - * pool is handed an opaque MPOOL cookie which stores all of this information. - */ -#define HASHSIZE 128 -#define HASHKEY(pgno) ((pgno - 1 + HASHSIZE) % HASHSIZE) - -/* The BKT structures are the elements of the queues. */ -typedef struct _bkt { - TAILQ_ENTRY(_bkt) hq; /* hash queue */ - TAILQ_ENTRY(_bkt) q; /* lru queue */ - void *page; /* page */ - pgno_t pgno; /* page number */ - -#define MPOOL_DIRTY 0x01 /* page needs to be written */ -#define MPOOL_PINNED 0x02 /* page is pinned into memory */ -#define MPOOL_INUSE 0x04 /* page address is valid */ - u_int8_t flags; /* flags */ -} BKT; - -typedef struct MPOOL { - TAILQ_HEAD(_lqh, _bkt) lqh; /* lru queue head */ - /* hash queue array */ - TAILQ_HEAD(_hqh, _bkt) hqh[HASHSIZE]; - pgno_t curcache; /* current number of cached pages */ - pgno_t maxcache; /* max number of cached pages */ - pgno_t npages; /* number of pages in the file */ - unsigned long pagesize; /* file page size */ - int fd; /* file descriptor */ - /* page in conversion routine */ - void (*pgin)(void *, pgno_t, void *); - /* page out conversion routine */ - void (*pgout)(void *, pgno_t, void *); - void *pgcookie; /* cookie for page in/out routines */ -#ifdef STATISTICS - unsigned long cachehit; - unsigned long cachemiss; - unsigned long pagealloc; - unsigned long pageflush; - unsigned long pageget; - unsigned long pagenew; - unsigned long pageput; - unsigned long pageread; - unsigned long pagewrite; -#endif -} MPOOL; - -#define MPOOL_IGNOREPIN 0x01 /* Ignore if the page is pinned. */ -#define MPOOL_PAGE_REQUEST 0x01 /* Allocate a new page with a - specific page number. */ -#define MPOOL_PAGE_NEXT 0x02 /* Allocate a new page with the next - page number. */ - -__BEGIN_HIDDEN_DECLS -MPOOL *mpool_open(void *, int, pgno_t, pgno_t); -void mpool_filter(MPOOL *, void (*)(void *, pgno_t, void *), - void (*)(void *, pgno_t, void *), void *); -void *mpool_new(MPOOL *, pgno_t *, unsigned int); -void *mpool_get(MPOOL *, pgno_t, unsigned int); -int mpool_delete(MPOOL *, void *); -int mpool_put(MPOOL *, void *, unsigned int); -int mpool_sync(MPOOL *); -int mpool_close(MPOOL *); - -PROTO_NORMAL(mpool_open); -PROTO_NORMAL(mpool_filter); -PROTO_NORMAL(mpool_new); -PROTO_NORMAL(mpool_get); -PROTO_NORMAL(mpool_delete); -PROTO_NORMAL(mpool_put); -PROTO_NORMAL(mpool_sync); -PROTO_NORMAL(mpool_close); - -#ifdef STATISTICS -void mpool_stat(MPOOL *); -PROTO_NORMAL(mpool_stat); -#endif -__END_HIDDEN_DECLS - -#endif diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h deleted file mode 100644 index 8503de47be..0000000000 --- a/src/lib/libc/include/namespace.h +++ /dev/null @@ -1,98 +0,0 @@ -/* $OpenBSD: namespace.h,v 1.16 2023/10/29 14:26:13 millert Exp $ */ - -#ifndef _LIBC_NAMESPACE_H_ -#define _LIBC_NAMESPACE_H_ - -/* - * Copyright (c) 2015 Philip Guenther - * - * 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. - */ - -/* - * ISO C11 or higher is required to build libc. - * This must come _before_ sys/cdefs.h is included. - */ -#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112 -#define _ISOC11_SOURCE 1 -#endif - -/* - * For explanations of how to use these, see README - * For explanations of why we use them and how they work, see DETAILS - */ - -#include /* for __dso_hidden and __{weak,strong}_alias */ - -#define __dso_protected __attribute__((__visibility__("protected"))) - -#define HIDDEN(x) _libc_##x -#define CANCEL(x) _libc_##x##_cancel -#define WRAP(x) _libc_##x##_wrap -#define HIDDEN_STRING(x) "_libc_" __STRING(x) -#define CANCEL_STRING(x) "_libc_" __STRING(x) "_cancel" -#define WRAP_STRING(x) "_libc_" __STRING(x) "_wrap" - -#define PROTO_NORMAL(x) __dso_hidden typeof(x) x asm(HIDDEN_STRING(x)) -#define PROTO_STD_DEPRECATED(x) typeof(x) x __attribute__((deprecated)) -#define PROTO_DEPRECATED(x) typeof(x) x __attribute__((deprecated, weak)) -#define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \ - x asm(CANCEL_STRING(x)) -#define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x) -#define PROTO_PROTECTED(x) __dso_protected typeof(x) x - -#define DEF_STRONG(x) __strong_alias(x, HIDDEN(x)) -#define DEF_WEAK(x) __weak_alias(x, HIDDEN(x)) -#define DEF_CANCEL(x) __weak_alias(x, CANCEL(x)) -#define DEF_WRAP(x) __weak_alias(x, WRAP(x)) -#define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) - -#if !defined(__clang__) && __GNUC__ != 3 -/* our gcc 4.2 handles redirecting builtins via PROTO_NORMAL()'s asm() label */ -#define DEF_BUILTIN(x) DEF_STRONG(x) -#define BUILTIN -#else -/* - * clang and gcc can't redirect builtins via asm() labels, so mark - * them protected instead. - */ -#define DEF_BUILTIN(x) __asm("") -#define BUILTIN __dso_protected -#endif - -#define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) HIDDEN(dst) \ - __attribute__((alias (HIDDEN_STRING(src)))) - -#define __relro __attribute__((section(".data.rel.ro"))) - - -/* - * gcc and clang will generate calls to the functions below. - * Declare and redirect them here so we always go - * directly to our hidden aliases. - */ -#include -BUILTIN void *memmove(void *, const void *, __size_t); -BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); -BUILTIN void *memset(void *, int, __size_t); -BUILTIN void __stack_smash_handler(const char [], int __unused); -#if !defined(__clang__) && __GNUC__ != 3 -PROTO_NORMAL(memmove); -PROTO_NORMAL(memcpy); -PROTO_NORMAL(memset); -PROTO_NORMAL(__stack_smash_handler); -#endif -#undef BUILTIN - -#endif /* _LIBC_NAMESPACE_H_ */ - diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h deleted file mode 100644 index 1ec1071161..0000000000 --- a/src/lib/libc/include/thread_private.h +++ /dev/null @@ -1,427 +0,0 @@ -/* $OpenBSD: thread_private.h,v 1.37 2024/08/18 02:25:51 guenther Exp $ */ - -/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ - -#ifndef _THREAD_PRIVATE_H_ -#define _THREAD_PRIVATE_H_ - -extern int __isthreaded; - -#define _MALLOC_MUTEXES 32 -void _malloc_init(int); -#ifdef __LIBC__ -PROTO_NORMAL(_malloc_init); -#endif /* __LIBC__ */ - -/* - * The callbacks needed by libc to handle the threaded case. - * NOTE: Bump the version when you change the struct contents! - * - * tc_canceled: - * If not NULL, what to do when canceled (otherwise _exit(0)) - * - * tc_flockfile, tc_ftrylockfile, and tc_funlockfile: - * If not NULL, these implement the flockfile() family. - * XXX In theory, you should be able to lock a FILE before - * XXX loading libpthread and have that be a real lock on it, - * XXX but that doesn't work without the libc base version - * XXX tracking the recursion count. - * - * tc_malloc_lock and tc_malloc_unlock: - * tc_atexit_lock and tc_atexit_unlock: - * tc_atfork_lock and tc_atfork_unlock: - * tc_arc4_lock and tc_arc4_unlock: - * The locks used by the malloc, atexit, atfork, and arc4 subsystems. - * These have to be ordered specially in the fork/vfork wrappers - * and may be implemented differently than the general mutexes - * in the callbacks below. - * - * tc_mutex_lock and tc_mutex_unlock: - * Lock and unlock the given mutex. If the given mutex is NULL - * a mutex is allocated and initialized automatically. - * - * tc_mutex_destroy: - * Destroy/deallocate the given mutex. - * - * tc_tag_lock and tc_tag_unlock: - * Lock and unlock the mutex associated with the given tag. - * If the given tag is NULL a tag is allocated and initialized - * automatically. - * - * tc_tag_storage: - * Returns a pointer to per-thread instance of data associated - * with the given tag. If the given tag is NULL a tag is - * allocated and initialized automatically. - * - * tc_fork, tc_vfork: - * If not NULL, they are called instead of the syscall stub, so that - * the thread library can do necessary locking and reinitialization. - * - * tc_thread_release: - * Handles the release of a thread's TIB and struct pthread and the - * notification of other threads...when there are other threads. - * - * tc_thread_key_zero: - * For each thread, zero out the key data associated with the given key. - - * If doesn't define TCB_GET(), then locating the TCB in a - * threaded process requires a syscall (__get_tcb(2)) which is too much - * overhead for single-threaded processes. For those archs, there are two - * additional callbacks, though they are placed first in the struct for - * convenience in ASM: - * - * tc_errnoptr: - * Returns the address of the thread's errno. - * - * tc_tcb: - * Returns the address of the thread's TCB. - */ - -struct __sFILE; -struct pthread; -struct thread_callbacks { - int *(*tc_errnoptr)(void); /* MUST BE FIRST */ - void *(*tc_tcb)(void); - __dead void (*tc_canceled)(void); - void (*tc_flockfile)(struct __sFILE *); - int (*tc_ftrylockfile)(struct __sFILE *); - void (*tc_funlockfile)(struct __sFILE *); - void (*tc_malloc_lock)(int); - void (*tc_malloc_unlock)(int); - void (*tc_atexit_lock)(void); - void (*tc_atexit_unlock)(void); - void (*tc_atfork_lock)(void); - void (*tc_atfork_unlock)(void); - void (*tc_arc4_lock)(void); - void (*tc_arc4_unlock)(void); - void (*tc_mutex_lock)(void **); - void (*tc_mutex_unlock)(void **); - void (*tc_mutex_destroy)(void **); - void (*tc_tag_lock)(void **); - void (*tc_tag_unlock)(void **); - void *(*tc_tag_storage)(void **, void *, size_t, void (*)(void *), - void *); - __pid_t (*tc_fork)(void); - __pid_t (*tc_vfork)(void); - void (*tc_thread_release)(struct pthread *); - void (*tc_thread_key_zero)(int); -}; - -__BEGIN_PUBLIC_DECLS -/* - * Set the callbacks used by libc - */ -void _thread_set_callbacks(const struct thread_callbacks *_cb, size_t _len); -__END_PUBLIC_DECLS - -#ifdef __LIBC__ -__BEGIN_HIDDEN_DECLS -/* the current set */ -extern struct thread_callbacks _thread_cb; -__END_HIDDEN_DECLS -#endif /* __LIBC__ */ - -/* - * helper macro to make unique names in the thread namespace - */ -#define __THREAD_NAME(name) __CONCAT(_thread_tagname_,name) - -/* - * 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) - - -#ifndef __LIBC__ /* building some sort of reach around */ - -#define _THREAD_PRIVATE_MUTEX_LOCK(name) do {} while (0) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) do {} while (0) -#define _THREAD_PRIVATE(keyname, storage, error) &(storage) -#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) &(storage) -#define _MUTEX_LOCK(mutex) do {} while (0) -#define _MUTEX_UNLOCK(mutex) do {} while (0) -#define _MUTEX_DESTROY(mutex) do {} while (0) -#define _MALLOC_LOCK(n) do {} while (0) -#define _MALLOC_UNLOCK(n) do {} while (0) -#define _ATEXIT_LOCK() do {} while (0) -#define _ATEXIT_UNLOCK() do {} while (0) -#define _ATFORK_LOCK() do {} while (0) -#define _ATFORK_UNLOCK() do {} while (0) -#define _ARC4_LOCK() do {} while (0) -#define _ARC4_UNLOCK() do {} while (0) - -#else /* building libc */ -#define _THREAD_PRIVATE_MUTEX_LOCK(name) \ - do { \ - if (_thread_cb.tc_tag_lock != NULL) \ - _thread_cb.tc_tag_lock(&(__THREAD_NAME(name))); \ - } while (0) -#define _THREAD_PRIVATE_MUTEX_UNLOCK(name) \ - do { \ - if (_thread_cb.tc_tag_unlock != NULL) \ - _thread_cb.tc_tag_unlock(&(__THREAD_NAME(name))); \ - } while (0) -#define _THREAD_PRIVATE(keyname, storage, error) \ - (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ - _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ - &(storage), sizeof(storage), NULL, (error))) - -#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) \ - (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ - _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ - &(storage), sizeof(storage), (dt), (error))) - -/* - * Macros used in libc to access mutexes. - */ -#define _MUTEX_LOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_lock(mutex); \ - } while (0) -#define _MUTEX_UNLOCK(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_unlock(mutex); \ - } while (0) -#define _MUTEX_DESTROY(mutex) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_mutex_destroy(mutex); \ - } while (0) - -/* - * malloc lock/unlock prototypes and definitions - */ -#define _MALLOC_LOCK(n) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_malloc_lock(n); \ - } while (0) -#define _MALLOC_UNLOCK(n) \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_malloc_unlock(n); \ - } while (0) - -#define _ATEXIT_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atexit_lock(); \ - } while (0) -#define _ATEXIT_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atexit_unlock(); \ - } while (0) - -#define _ATFORK_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atfork_lock(); \ - } while (0) -#define _ATFORK_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_atfork_unlock(); \ - } while (0) - -#define _ARC4_LOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_arc4_lock(); \ - } while (0) -#define _ARC4_UNLOCK() \ - do { \ - if (__isthreaded) \ - _thread_cb.tc_arc4_unlock(); \ - } while (0) -#endif /* __LIBC__ */ - - -/* - * Copyright (c) 2004,2005 Ted Unangst - * All Rights Reserved. - * - * 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. - */ -/* - * Private data structures that back up the typedefs in pthread.h. - * Since only the thread library cares about their size or arrangement, - * it should be possible to switch libraries without relinking. - * - * Do not reorder _atomic_lock_t and sem_t variables in the structs. - * This is due to alignment requirements of certain arches like hppa. - * The current requirement is 16 bytes. - * - * THE MACHINE DEPENDENT CERROR CODE HAS HARD CODED OFFSETS INTO PTHREAD_T! - */ - -#include -#include -#include -#include - -#define _SPINLOCK_UNLOCKED _ATOMIC_LOCK_UNLOCKED - -struct __sem { - _atomic_lock_t lock; - volatile int waitcount; - volatile int value; - int shared; -}; - -TAILQ_HEAD(pthread_queue, pthread); - -#ifdef FUTEX - -struct pthread_mutex { - volatile unsigned int lock; - int type; - pthread_t owner; - int count; - int prioceiling; -}; - -struct pthread_cond { - volatile unsigned int seq; - clockid_t clock; - struct pthread_mutex *mutex; -}; - -struct pthread_rwlock { - volatile unsigned int value; -}; - -#else - -struct pthread_mutex { - _atomic_lock_t lock; - struct pthread_queue lockers; - int type; - pthread_t owner; - int count; - int prioceiling; -}; - -struct pthread_cond { - _atomic_lock_t lock; - struct pthread_queue waiters; - struct pthread_mutex *mutex; - clockid_t clock; -}; - -struct pthread_rwlock { - _atomic_lock_t lock; - pthread_t owner; - struct pthread_queue writers; - int readers; -}; -#endif /* FUTEX */ - -struct pthread_mutex_attr { - int ma_type; - int ma_protocol; - int ma_prioceiling; -}; - -struct pthread_cond_attr { - clockid_t ca_clock; -}; - -struct pthread_attr { - void *stack_addr; - size_t stack_size; - size_t guard_size; - int detach_state; - int contention_scope; - int sched_policy; - struct sched_param sched_param; - int sched_inherit; -}; - -struct rthread_storage { - int keyid; - struct rthread_storage *next; - void *data; -}; - -struct rthread_cleanup_fn { - void (*fn)(void *); - void *arg; - struct rthread_cleanup_fn *next; -}; - -struct tib; -struct stack; -struct pthread { - struct __sem donesem; - unsigned int flags; - _atomic_lock_t flags_lock; - struct tib *tib; - void *retval; - void *(*fn)(void *); - void *arg; - char name[32]; - struct stack *stack; - LIST_ENTRY(pthread) threads; - TAILQ_ENTRY(pthread) waiting; - pthread_cond_t blocking_cond; - struct pthread_attr attr; - struct rthread_storage *local_storage; - struct rthread_cleanup_fn *cleanup_fns; - - /* cancel received in a delayed cancel block? */ - int delayed_cancel; -}; -/* flags in pthread->flags */ -#define THREAD_DONE 0x001 -#define THREAD_DETACHED 0x002 - -/* flags in tib->tib_thread_flags */ -#define TIB_THREAD_ASYNC_CANCEL 0x001 -#define TIB_THREAD_INITIAL_STACK 0x002 /* has stack from exec */ - -#define ENTER_DELAYED_CANCEL_POINT(tib, self) \ - (self)->delayed_cancel = 0; \ - ENTER_CANCEL_POINT_INNER(tib, 1, 1) - -/* - * Internal functions exported from libc's thread bits for use by libpthread - */ -void _spinlock(volatile _atomic_lock_t *); -int _spinlocktry(volatile _atomic_lock_t *); -void _spinunlock(volatile _atomic_lock_t *); - -void _rthread_debug(int, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); -pid_t _thread_dofork(pid_t (*_sys_fork)(void)); -void _thread_finalize(void); - -/* - * Threading syscalls not declared in system headers - */ -__dead void __threxit(pid_t *); -int __thrsleep(const volatile void *, clockid_t, - const struct timespec *, volatile void *, const int *); -int __thrwakeup(const volatile void *, int n); -int __thrsigdivert(sigset_t, siginfo_t *, const struct timespec *); - -#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 db2c75dad6..0000000000 --- a/src/lib/libc/net/Makefile.inc +++ /dev/null @@ -1,31 +0,0 @@ -# $OpenBSD: Makefile.inc,v 1.61 2024/04/15 14:30:48 naddy Exp $ - -# net sources -.PATH: ${LIBCSRCDIR}/net - -CFLAGS+=-DRESOLVSORT - -SRCS+= base64.c ethers.c freeaddrinfo.c \ - gai_strerror.c getaddrinfo.c gethostnamadr.c \ - getifaddrs.c getnameinfo.c getnetent.c \ - getnetnamadr.c getpeereid.c getproto.c getprotoent.c getprotoname.c \ - getservbyname.c getservbyport.c getservent.c getrrsetbyname.c \ - herror.c htonl.c htons.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 ntohl.c ntohs.c rcmd.c rcmdsh.c ruserok.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 sockatmark.c - -# IPv6 -SRCS+= ip6opt.c rthdr.c vars6.c - -MAN+= htobe64.3 ether_aton.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ - getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ - getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ - inet_addr.3 inet_lnaof.3 inet_net_ntop.3 inet_ntop.3 \ - inet6_opt_init.3 inet6_rth_space.3 link_ntoa.3 \ - rcmd.3 rcmdsh.3 res_init.3 sockatmark.3 diff --git a/src/lib/libc/net/base64.c b/src/lib/libc/net/base64.c deleted file mode 100644 index f36c11a21c..0000000000 --- a/src/lib/libc/net/base64.c +++ /dev/null @@ -1,307 +0,0 @@ -/* $OpenBSD: base64.c,v 1.15 2021/10/25 14:41:09 jca 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 - -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(unsigned char const *src, size_t srclength, char *target, - size_t targsize) -{ - size_t datalength = 0; - unsigned char input[3]; - unsigned 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(char const *src, unsigned char *target, size_t targsize) -{ - int tarindex, state, ch; - unsigned char nextbyte; - char *pos; - - state = 0; - tarindex = 0; - - while ((ch = (unsigned char)*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 >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 4; - nextbyte = ((pos - Base64) & 0x0f) << 4; - if (tarindex + 1 < targsize) - target[tarindex+1] = nextbyte; - else if (nextbyte) - return (-1); - } - tarindex++; - state = 2; - break; - case 2: - if (target) { - if (tarindex >= targsize) - return (-1); - target[tarindex] |= (pos - Base64) >> 2; - nextbyte = ((pos - Base64) & 0x03) << 6; - if (tarindex + 1 < targsize) - target[tarindex+1] = nextbyte; - else if (nextbyte) - return (-1); - } - 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 = (unsigned char)*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 = (unsigned char)*src++) - if (!isspace(ch)) - break; - /* Make sure there is another trailing = sign. */ - if (ch != Pad64) - return (-1); - ch = (unsigned char)*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 = (unsigned char)*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 && tarindex < targsize && - 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/ether_aton.3 b/src/lib/libc/net/ether_aton.3 deleted file mode 100644 index 98562dc44c..0000000000 --- a/src/lib/libc/net/ether_aton.3 +++ /dev/null @@ -1,114 +0,0 @@ -.\" $OpenBSD: ether_aton.3,v 1.3 2022/09/11 06:38:10 jmc Exp $ -.\" -.\" Written by roland@frob.com. Public domain. -.\" -.Dd $Mdocdate: September 11 2022 $ -.Dt ETHER_ATON 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 -.In sys/types.h -.In sys/socket.h -.In net/if.h -.In netinet/in.h -.In netinet/if_ether.h -.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[ETHER_ADDR_LEN]; -}; -.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 -function 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. -.Fn ether_aton -will return NULL if the string does not represent a valid address. -.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. -.Pp -The -.Fn ether_line -function parses a line from the -.Pa /etc/ethers -file and fills in the passed -.Vt 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.9b . -.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 d62be1ca71..0000000000 --- a/src/lib/libc/net/ethers.c +++ /dev/null @@ -1,183 +0,0 @@ -/* $OpenBSD: ethers.c,v 1.27 2019/01/25 00:19:25 millert 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 - -#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((unsigned char)*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((unsigned char)*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; - - f = fopen(_PATH_ETHERS, "re"); - 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'; - /* A + in the file meant try YP, ignore it. */ - if (!strncmp(buf, "+\n", sizeof(buf))) - continue; - if (ether_line(buf, &try, hostname) == 0 && - memcmp(&try, 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[HOST_NAME_MAX+1]; - size_t len; - - f = fopen(_PATH_ETHERS, "re"); - 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'; - /* A + in the file meant try YP, ignore it. */ - if (!strncmp(buf, "+\n", sizeof(buf))) - continue; - 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((unsigned char)*p)) - p++; - if (*p == '\0') - goto bad; - n = strcspn(p, " \t\n"); - if (n >= HOST_NAME_MAX+1) - goto bad; - strlcpy(hostname, p, n + 1); - return (0); - -bad: - errno = EINVAL; - return (-1); -} -DEF_WEAK(ether_line); diff --git a/src/lib/libc/net/freeaddrinfo.c b/src/lib/libc/net/freeaddrinfo.c deleted file mode 100644 index 154f70cd75..0000000000 --- a/src/lib/libc/net/freeaddrinfo.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: freeaddrinfo.c,v 1.9 2016/09/21 04:38:56 guenther 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; - free(p->ai_canonname); - free(p); - } while (ai); -} -DEF_WEAK(freeaddrinfo); diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 deleted file mode 100644 index d271f492c5..0000000000 --- a/src/lib/libc/net/gai_strerror.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" $OpenBSD: gai_strerror.3,v 1.10 2017/05/03 01:58:33 deraadt 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 3 2017 $ -.Dt GAI_STRERROR 3 -.Os -.Sh NAME -.Nm gai_strerror -.Nd get error message string from EAI_xxx error code -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.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 -.In netdb.h : -.Pp -.Bl -tag -width "EAI_ADDRFAMILYXX" -offset indent -compact -.It Dv EAI_ADDRFAMILY -address family for -.Fa name -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 name -.It Dv EAI_NONAME -.Fa name -or -.Fa service -not provided, or not known -.It Dv EAI_OVERFLOW -argument buffer overflow -.It Dv EAI_PROTOCOL -resolved protocol is unknown -.It Dv EAI_SERVICE -.Fa service -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 1e9b585029..0000000000 --- a/src/lib/libc/net/gai_strerror.c +++ /dev/null @@ -1,79 +0,0 @@ -/* $OpenBSD: gai_strerror.c,v 1.8 2015/09/14 07:38:38 guenther 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"; - case EAI_OVERFLOW: - return "argument buffer overflow"; - default: - return "unknown/invalid error"; - } -} -DEF_WEAK(gai_strerror); diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 deleted file mode 100644 index 780c7a409f..0000000000 --- a/src/lib/libc/net/getaddrinfo.3 +++ /dev/null @@ -1,477 +0,0 @@ -.\" $OpenBSD: getaddrinfo.3,v 1.61 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt GETADDRINFO 3 -.Os -.Sh NAME -.Nm getaddrinfo , -.Nm freeaddrinfo -.Nd host and service name to socket address structure -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.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 -.Vt struct addrinfo , -as defined by -.In netdb.h : -.Bd -literal -struct addrinfo { - int ai_flags; /* input flags */ - int ai_family; /* address 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 address family that should be used. -When -.Fa ai_family -is set to -.Dv AF_UNSPEC , -it means the caller will accept any address 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_ADDRCONFIG -If the -.Dv AI_ADDRCONFIG -bit is set, IPv4 addresses will be returned only if an IPv4 address is -configured on an interface, and IPv6 addresses will be returned only if an IPv6 -address is configured on an interface. -Addresses on a loopback interface and link-local IPv6 addresses are not -considered valid as configured addresses. -This bit is only considered when determining whether a DNS query should -be performed or not. -.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 host name in the -.Fa ai_canonname -element of the first -.Vt addrinfo -structure returned. -.It Dv AI_FQDN -If the -.Dv AI_FQDN -bit is set, a successful call to -.Fn getaddrinfo -will return a NUL-terminated string containing the fully qualified domain name -of the specified host name in the -.Fa ai_canonname -element of the first -.Vt addrinfo -structure returned. -.Pp -This is different from the -.Dv AI_CANONNAME -bit flag that returns the canonical name registered in DNS, -which may be different from the fully qualified domain name -that the host name resolved to. -Only one of the -.Dv AI_FQDN -and -.Dv AI_CANONNAME -bits can be set. -.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_NUMERICSERV -If the -.Dv AI_NUMERICSERV -bit is set, it indicates that -.Fa servname -should be treated as a numeric port string -and no service 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 -.Vt 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 -.Vt struct addrinfo -with -.Fa ai_family -set to -.Dv AF_UNSPEC , -.Fa ai_flags -set to -.Dv AI_ADDRCONFIG , -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 -.Vt addrinfo -structures. -The list can be traversed by following the -.Fa ai_next -pointer in each -.Vt addrinfo -structure until a null pointer is encountered. -The three members -.Fa ai_family , -.Fa ai_socktype , -and -.Fa ai_protocol -in each returned -.Vt addrinfo -structure are suitable for a call to -.Xr socket 2 . -For each -.Vt 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 RFC 4007. -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 -.Vt addrinfo -structures themselves as well as the socket address structures and -the canonical host name strings included in the -.Vt 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 an -.Vt 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 -.Vt 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 = AF_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 == -1) { - cause = "socket"; - continue; - } - - if (connect(s, res->ai_addr, res->ai_addrlen) == -1) { - cause = "connect"; - save_errno = errno; - close(s); - errno = save_errno; - s = -1; - continue; - } - - break; /* okay we got one */ -} -if (s == -1) - 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 = AF_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] == -1) { - cause = "socket"; - continue; - } - - if (bind(s[nsock], res->ai_addr, res->ai_addrlen) == -1) { - 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 res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 -.Rs -.%A Craig Metz -.%B Proceedings of the Freenix Track: 2000 USENIX Annual Technical Conference -.%D June 2000 -.%T Protocol Independence Using the Sockets API -.Re -.Sh STANDARDS -The -.Fn getaddrinfo -function is defined by the -.St -p1003.1g-2000 -draft specification and documented in RFC 3493. -.Pp -The -.Dv AI_FQDN -flag bit first appeared in Windows 7. -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%D March 2005 -.%R RFC 4007 -.%T IPv6 Scoped Address Architecture -.Re diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3 deleted file mode 100644 index 06170c3c1a..0000000000 --- a/src/lib/libc/net/gethostbyname.3 +++ /dev/null @@ -1,271 +0,0 @@ -.\" $OpenBSD: gethostbyname.3,v 1.34 2019/08/30 20:20:50 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: August 30 2019 $ -.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 -.In netdb.h -.Vt extern int h_errno ; -.Ft struct hostent * -.Fn gethostbyname "const char *name" -.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" -.In sys/socket.h -.In netdb.h -.Ft struct hostent * -.Fn gethostbyname2 "const char *name" "int af" -.Ft struct hostent * -.Fn gethostbyaddr "const void *addr" "socklen_t len" "int af" -.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 -.Fa name -or -.Fa addr , -respectively. -This structure contains either information obtained from a name server, -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 -.Dv NULL Ns -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 -.Dv NULL Ns -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 similar to -.Fn gethostbyname -except that it supports an -.Fa af -of -.Dv AF_INET6 -in addition to -.Dv AF_INET . -.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 supported is -.Dv AF_INET . -.Pp -The -.Fn sethostent , -.Fn gethostent , -and -.Fn endhostent -functions are deprecated and no longer have any effect. -They could be used in the past for queries over a persistent TCP -connection or to iterate entries in the -.Xr hosts 5 -file. -.Pp -The -.Fn herror -function prints an error message describing the failure. -If its argument -.Fa string -is not -.Dv 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 -.Va h_errno . -.Sh ENVIRONMENT -.Bl -tag -width RES_OPTIONS -.It Ev RES_OPTIONS -A list of options to override the resolver's internal defaults. -See -.Xr resolv.conf 5 -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 -.Dv 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 is always set by -.Fn gethostent . -.It Dv NETDB_SUCCESS -The function completed successfully. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr getnameinfo 3 , -.Xr res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr hostname 7 -.Sh HISTORY -The -.Fn endhostent , -.Fn gethostbyaddr , -.Fn gethostbyname , -.Fn gethostent , -and -.Fn sethostent -functions appeared in -.Bx 4.1c . -The function -.Fn herror -was added in -.Bx 4.3 Tahoe , -.Fn hstrerror -in -.Bx 4.4 , -and -.Fn gethostbyname2 -in -.Ox 2.1 . -.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/getifaddrs.3 b/src/lib/libc/net/getifaddrs.3 deleted file mode 100644 index 8ea08fa3da..0000000000 --- a/src/lib/libc/net/getifaddrs.3 +++ /dev/null @@ -1,157 +0,0 @@ -.\" $OpenBSD: getifaddrs.3,v 1.23 2022/03/29 18:15:52 naddy 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: March 29 2022 $ -.Dt GETIFADDRS 3 -.Os -.Sh NAME -.Nm getifaddrs , -.Nm freeifaddrs -.Nd get interface addresses -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In ifaddrs.h -.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 -.Vt ifaddrs -structures, as defined in the include file -.In ifaddrs.h . -The -.Vt 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 -This field, which should only be referenced for P2P interfaces, -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 -.Vt struct if_data -(as defined in include file -.In 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 -.Rv -std -.Sh ERRORS -The -.Fn getifaddrs -function 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 2 . -.Sh SEE ALSO -.Xr ioctl 2 , -.Xr socket 2 , -.Xr sysctl 2 , -.Xr netintro 4 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn getifaddrs -function first appeared in BSDI -.Bsx . -The function has been available on -.Ox -since -.Ox 2.7 . -.Sh BUGS -If both -.In net/if.h -and -.In ifaddrs.h -are being included, -.In net/if.h -.Em must -be included before -.In ifaddrs.h . diff --git a/src/lib/libc/net/getifaddrs.c b/src/lib/libc/net/getifaddrs.c deleted file mode 100644 index 069ee9afab..0000000000 --- a/src/lib/libc/net/getifaddrs.c +++ /dev/null @@ -1,298 +0,0 @@ -/* $OpenBSD: getifaddrs.c,v 1.14 2021/11/29 03:20:37 deraadt 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 /* ALIGN ALIGNBYTES */ -#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 = NULL, *bufp; - 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, dlen; - 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 */ - while (1) { - if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) { - free(buf); - return (-1); - } - if (needed == 0) - break; - if ((bufp = realloc(buf, needed)) == NULL) { - free(buf); - return (-1); - } - buf = bufp; - if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1) { - if (errno == ENOMEM) - continue; - free(buf); - return (-1); - } - break; - } - - 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 *)(next + - rtm->rtm_hdrlen); - 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 = next + rtm->rtm_hdrlen; - ++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 *)(next + - rtm->rtm_hdrlen); - - 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); - dlen = rtm->rtm_hdrlen - - offsetof(struct if_msghdr, ifm_data); - if (dlen > sizeof(ifm->ifm_data)) - dlen = sizeof(ifm->ifm_data); - memcpy(data, &ifm->ifm_data, dlen); - 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 = next + rtm->rtm_hdrlen; - /* 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); -} -DEF_WEAK(getifaddrs); - -void -freeifaddrs(struct ifaddrs *ifp) -{ - free(ifp); -} -DEF_WEAK(freeifaddrs); diff --git a/src/lib/libc/net/getnameinfo.3 b/src/lib/libc/net/getnameinfo.3 deleted file mode 100644 index 4e97b5d07b..0000000000 --- a/src/lib/libc/net/getnameinfo.3 +++ /dev/null @@ -1,264 +0,0 @@ -.\" $OpenBSD: getnameinfo.3,v 1.49 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt GETNAMEINFO 3 -.Os -.Sh NAME -.Nm getnameinfo -.Nd socket address structure to hostname and service name -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In netdb.h -.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 -.Vt 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 -.Vt sockaddr -structure -.Fa sa -should point to either a -.Vt sockaddr_in -or -.Vt 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 -.In 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 RFC 4007. -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 res_init 3 , -.Xr hosts 5 , -.Xr resolv.conf 5 , -.Xr services 5 , -.Xr hostname 7 -.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 RFC 3493. -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A S. Deering -.%A B. Haberman -.%A T. Jinmei -.%A E. Nordmark -.%A B. Zill -.%D March 2005 -.%R RFC 4007 -.%T IPv6 Scoped Address Architecture -.Re -.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; -char addr[NI_MAXHOST]; -struct addrinfo hints, *res; -int error; - -error = getnameinfo(sa, sa->sa_len, 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, sa->sa_len, 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/getnetent.3 b/src/lib/libc/net/getnetent.3 deleted file mode 100644 index da2c4ef4a3..0000000000 --- a/src/lib/libc/net/getnetent.3 +++ /dev/null @@ -1,147 +0,0 @@ -.\" $OpenBSD: getnetent.3,v 1.19 2019/08/30 20:20:51 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: August 30 2019 $ -.Dt GETNETENT 3 -.Os -.Sh NAME -.Nm getnetent , -.Nm getnetbyaddr , -.Nm getnetbyname , -.Nm setnetent , -.Nm endnetent -.Nd get network entry -.Sh SYNOPSIS -.In netdb.h -.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 getnetbyname -and -.Fn getnetbyaddr -functions return a pointer to an object with the following structure: -.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; it is always -.Dv AF_INET . -.It Fa n_net -The network number. -Network numbers are returned in machine byte order. -.El -.Pp -On -.Ox , -these legacy functions perform a lookup in a similar fashion as -.Xr gethostbyname 3 -and -.Xr gethostbyaddr 3 , -respectively. -On other systems, they may use a separate network database file, -.Pa /etc/networks . -.Pp -In contrast to -.Xr gethostbyaddr 3 , -the -.Fa net -argument is expected in machine byte order. -.Pp -The -.Fn setnetent , -.Fn getnetent , -and -.Fn endnetent -functions are deprecated and no longer have any effect. -They could be used in the past to iterate over entries in the former file -.Pa /etc/networks . -.Sh RETURN VALUES -The -.Fn getnetbyaddr -and -.Fn getnetbyname -functions return -.Dv NULL -if the requested entry is not found. -.Pp -The -.Fn getnetent -function always returns -.Dv NULL . -.Sh FILES -.Bl -tag -width /etc/hosts -compact -.It Pa /etc/hosts -The local host and network name database. -.El -.Sh SEE ALSO -.Xr getaddrinfo 3 , -.Xr gethostbyname 3 , -.Xr getnameinfo 3 , -.Xr res_init 3 , -.Xr hosts 5 -.Sh STANDARDS -These functions conform to -.St -p1003.1-2008 . -.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 b93e442fa9..0000000000 --- a/src/lib/libc/net/getnetent.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: getnetent.c,v 1.18 2018/04/28 15:05:40 schwarze 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 - -void -setnetent(int f) -{ -} - -void -endnetent(void) -{ -} - -struct netent * -getnetent(void) -{ - h_errno = NETDB_INTERNAL; - return NULL; -} diff --git a/src/lib/libc/net/getpeereid.3 b/src/lib/libc/net/getpeereid.3 deleted file mode 100644 index 4475bbd77d..0000000000 --- a/src/lib/libc/net/getpeereid.3 +++ /dev/null @@ -1,121 +0,0 @@ -.\" $OpenBSD: getpeereid.3,v 1.4 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt GETPEEREID 3 -.Os -.Sh NAME -.Nm getpeereid -.Nd get effective user and group identification of locally-connected peer -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.Ft int -.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid" -.Sh DESCRIPTION -.Fn getpeereid -returns the effective user ID and group ID of the peer connected to -a -.Ux Ns -domain -socket (see -.Xr unix 4 ) . -The argument -.Fa s -must be of type -.Dv SOCK_STREAM -or -.Dv SOCK_SEQPACKET . -.Pp -One common use is for -.Ux Ns -domain -servers to determine the credentials of clients that have connected to it. -.Pp -.Fn getpeereid -takes three parameters: -.Bl -bullet -.It -.Fa s -contains the file descriptor of the socket whose peer credentials -should be looked up. -.It -.Fa euid -points to a -.Vt uid_t -variable into which the effective user ID for the connected peer will -be stored. -.It -.Fa egid -points to a -.Vt gid_t -variable into which the effective group ID for the connected peer will -be stored. -.El -.Sh RETURN VALUES -If the call succeeds, a 0 is returned and -.Fa euid -and -.Fa egid -are set to the effective user ID and group ID of the connected peer. -Otherwise, -.Va errno -is set and a value of \-1 is returned. -.Sh ERRORS -On failure, -.Va errno -is set to one of the following: -.Bl -tag -width Er -.It Bq Er EBADF -The argument -.Fa s -is not a valid descriptor. -.It Bq Er ENOTSOCK -The argument -.Fa s -is a file, not a socket. -.It Bq Er EOPNOTSUPP -The socket is not in the -.Ux Ns -domain . -.It Bq Er ENOTCONN -The socket is not connected. -.It Bq Er ENOBUFS -Insufficient resources were available in the system -to perform the operation. -.El -.Sh SEE ALSO -.Xr accept 2 , -.Xr bind 2 , -.Xr getpeername 2 , -.Xr getsockname 2 , -.Xr getsockopt 2 , -.Xr socket 2 , -.Xr unix 4 -.Sh HISTORY -The -.Fn getpeereid -function call appeared in -.Ox 3.0 . diff --git a/src/lib/libc/net/getpeereid.c b/src/lib/libc/net/getpeereid.c deleted file mode 100644 index 208e541f17..0000000000 --- a/src/lib/libc/net/getpeereid.c +++ /dev/null @@ -1,36 +0,0 @@ -/* $OpenBSD: getpeereid.c,v 1.1 2010/07/01 19:15:30 deraadt Exp $ */ - -/* - * Copyright (c) 2010 Theo de Raadt - * - * 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. - */ - -#include -#include - -int -getpeereid(int s, uid_t *euid, gid_t *egid) -{ - struct sockpeercred creds; - socklen_t credslen = sizeof(creds); - int error; - - error = getsockopt(s, SOL_SOCKET, SO_PEERCRED, - &creds, &credslen); - if (error) - return (error); - *euid = creds.uid; - *egid = creds.gid; - return (0); -} diff --git a/src/lib/libc/net/getproto.c b/src/lib/libc/net/getproto.c deleted file mode 100644 index 8e080679d0..0000000000 --- a/src/lib/libc/net/getproto.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $OpenBSD: getproto.c,v 1.8 2015/09/14 07:38:38 guenther 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); -} -DEF_WEAK(getprotobynumber_r); - -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 cc2c69836a..0000000000 --- a/src/lib/libc/net/getprotoent.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: getprotoent.3,v 1.18 2013/06/05 03:39:23 tedu 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: June 5 2013 $ -.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 -.In netdb.h -.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 a218863d07..0000000000 --- a/src/lib/libc/net/getprotoent.c +++ /dev/null @@ -1,169 +0,0 @@ -/* $OpenBSD: getprotoent.c,v 1.13 2015/09/14 07:38:38 guenther 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, "re" ); - else - rewind(pd->fp); - pd->stayopen |= f; -} -DEF_WEAK(setprotoent_r); - -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; -} -DEF_WEAK(endprotoent_r); - -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, "re" )) == 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 = reallocarray(pe->p_aliases, - pd->maxaliases, 2 * 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); -} -DEF_WEAK(getprotoent_r); - -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 f6ed4c49b1..0000000000 --- a/src/lib/libc/net/getprotoname.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $OpenBSD: getprotoname.c,v 1.8 2015/09/14 07:38:38 guenther 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); -} -DEF_WEAK(getprotobyname_r); - -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); -} -DEF_WEAK(getprotobyname); diff --git a/src/lib/libc/net/getrrsetbyname.3 b/src/lib/libc/net/getrrsetbyname.3 deleted file mode 100644 index 314f31665c..0000000000 --- a/src/lib/libc/net/getrrsetbyname.3 +++ /dev/null @@ -1,164 +0,0 @@ -.\" $OpenBSD: getrrsetbyname.3,v 1.22 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt GETRRSETBYNAME 3 -.Os -.Sh NAME -.Nm freerrset , -.Nm getrrsetbyname -.Nd retrieve DNS records -.Sh SYNOPSIS -.In netdb.h -.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 -.Vt rrsetinfo -structure, containing a list of one or more -.Vt rdatainfo -structures containing resource records and potentially another list of -.Vt 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 -.Vt rrsetinfo -and -.Vt rdatainfo -structures, -and the canonical host name strings pointed to by the -.Vt 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 -.Vt 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: -.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 res_init 3 , -.Xr resolv.conf 5 -.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 Mt 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/getservbyname.c b/src/lib/libc/net/getservbyname.c deleted file mode 100644 index 80c7e62a41..0000000000 --- a/src/lib/libc/net/getservbyname.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $OpenBSD: getservbyname.c,v 1.11 2015/09/14 07:38:38 guenther 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); -} -DEF_WEAK(getservbyname_r); - -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); -} -DEF_WEAK(getservbyname); diff --git a/src/lib/libc/net/getservbyport.c b/src/lib/libc/net/getservbyport.c deleted file mode 100644 index 3584fbea3a..0000000000 --- a/src/lib/libc/net/getservbyport.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $OpenBSD: getservbyport.c,v 1.8 2015/09/14 07:38:38 guenther 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); -} -DEF_WEAK(getservbyport_r); - -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 29dd3eb5f4..0000000000 --- a/src/lib/libc/net/getservent.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: getservent.3,v 1.21 2013/06/05 03:39:23 tedu 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: June 5 2013 $ -.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 -.In netdb.h -.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 220a5851ce..0000000000 --- a/src/lib/libc/net/getservent.c +++ /dev/null @@ -1,171 +0,0 @@ -/* $OpenBSD: getservent.c,v 1.15 2015/09/14 07:38:38 guenther 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, "re" ); - else - rewind(sd->fp); - sd->stayopen |= f; -} -DEF_WEAK(setservent_r); - -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; -} -DEF_WEAK(endservent_r); - -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, "re" )) == 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 = reallocarray(se->s_aliases, sd->maxaliases, - 2 * 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); -} -DEF_WEAK(getservent_r); - -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 356c85fa1d..0000000000 --- a/src/lib/libc/net/herror.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $OpenBSD: herror.c,v 1.10 2015/09/14 07:38:38 guenther 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 - -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"); -} -DEF_WEAK(hstrerror); diff --git a/src/lib/libc/net/htobe64.3 b/src/lib/libc/net/htobe64.3 deleted file mode 100644 index e41c9124c4..0000000000 --- a/src/lib/libc/net/htobe64.3 +++ /dev/null @@ -1,164 +0,0 @@ -.\" $OpenBSD: htobe64.3,v 1.2 2024/08/03 23:06:56 guenther 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: August 3 2024 $ -.Dt HTOBE64 3 -.Os -.Sh NAME -.Nm htobe64 , -.Nm htobe32 , -.Nm htobe16 , -.Nm be64toh , -.Nm be32toh , -.Nm be16toh , -.Nm betoh64 , -.Nm betoh32 , -.Nm betoh16 , -.Nm htole64 , -.Nm htole32 , -.Nm htole16 , -.Nm le64toh , -.Nm le32toh , -.Nm le16toh , -.Nm letoh64 , -.Nm letoh32 , -.Nm letoh16 , -.Nm swap64 , -.Nm swap32 , -.Nm swap16 -.Nd convert values between different byte orderings -.Sh SYNOPSIS -.In endian.h -.Ft uint64_t -.Fn htobe64 "uint64_t host64" -.Ft uint32_t -.Fn htobe32 "uint32_t host32" -.Ft uint16_t -.Fn htobe16 "uint16_t host16" -.Ft uint64_t -.Fn be64toh "uint64_t big64" -.Ft uint32_t -.Fn be32toh "uint32_t big32" -.Ft uint16_t -.Fn be16toh "uint16_t big16" -.Ft uint64_t -.Fn betoh64 "uint64_t big64" -.Ft uint32_t -.Fn betoh32 "uint32_t big32" -.Ft uint16_t -.Fn betoh16 "uint16_t big16" -.Ft uint64_t -.Fn htole64 "uint64_t host64" -.Ft uint32_t -.Fn htole32 "uint32_t host32" -.Ft uint16_t -.Fn htole16 "uint16_t host16" -.Ft uint64_t -.Fn letoh64 "uint64_t little64" -.Ft uint64_t -.Fn le64toh "uint64_t little64" -.Ft uint32_t -.Fn le32toh "uint32_t little32" -.Ft uint16_t -.Fn le16toh "uint16_t little16" -.Ft uint32_t -.Fn letoh32 "uint32_t little32" -.Ft uint16_t -.Fn letoh16 "uint16_t little16" -.Ft uint64_t -.Fn swap64 "uint64_t val64" -.Ft uint32_t -.Fn swap32 "uint32_t val32" -.Ft uint16_t -.Fn swap16 "uint16_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 containing -.Dq be -convert between host and big-endian (most significant byte first) order -of the given quantity, while the names containing -.Dq le -convert between host and little-endian (least significant byte first) order -of the given quantity. -.Pp -All these functions 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. -.Sh SEE ALSO -.Xr htonl 3 -.Sh STANDARDS -The -.Fn htobe64 , -.Fn htobe32 , -.Fn htobe16 , -.Fn be64toh , -.Fn be32toh , -.Fn be16toh , -.Fn htole64 , -.Fn htole32 , -.Fn htole16 , -.Fn le64toh , -.Fn le32toh , -and -.Fn le16toh -functions conform to -.St -p1003.1-2024 . -The other functions are extensions that should not be used -when portability is required. -.Sh HISTORY -The -.Nm swap{size} -and -.Nm {src-order}to{dst-order}{size} -functions appeared in -.Bx 4.2 . -The -.Nm {src-order}{size}to{dst-order} -functions appeared in -.Ox 5.6 . -.Sh BUGS -The perceived antagonism between -.Sq host -and -.Sq network -byte order does not allow PDP-11 users to sleep soundly at night. diff --git a/src/lib/libc/net/htonl.3 b/src/lib/libc/net/htonl.3 deleted file mode 100644 index 65fa9a53b5..0000000000 --- a/src/lib/libc/net/htonl.3 +++ /dev/null @@ -1,102 +0,0 @@ -.\" $OpenBSD: htonl.3,v 1.6 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt HTONL 3 -.Os -.Sh NAME -.Nm htonl , -.Nm htons , -.Nm ntohl , -.Nm ntohs -.Nd convert values between host and network byte orderings -.Sh SYNOPSIS -.In arpa/inet.h -.Ft uint32_t -.Fn htonl "uint32_t host32" -.Ft uint16_t -.Fn htons "uint16_t host16" -.Ft uint32_t -.Fn ntohl "uint32_t net32" -.Ft uint16_t -.Fn ntohs "uint16_t net16" -.Sh DESCRIPTION -These routines convert 16 and 32-bit quantities between different -byte orderings. -.Pp -The -.Fn htonl -and -.Fn htons -functions convert quantities from host to network byte order while the -.Fn ntohl -and -.Fn ntohs -functions convert in the other direction. -.Pp -The last letter -.Pf ( Sq s -or -.Sq l ) -is a mnemonic -for the traditional names for such quantities, -short and long, respectively. -Today, the C concept of -.Vt short -and -.Vt 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 -These routines 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 , -.Xr htobe64 3 -.Sh STANDARDS -The -.Fn htonl , -.Fn htons , -.Fn ntohl , -and -.Fn ntohs -functions conform to -.St -p1003.1 . -.Sh HISTORY -These functions appeared in -.Bx 4.2 . -.Sh BUGS -On the alpha, amd64, i386, and some mips and arm 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/htonl.c b/src/lib/libc/net/htonl.c deleted file mode 100644 index 58bfb4699a..0000000000 --- a/src/lib/libc/net/htonl.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: htonl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef htonl - -uint32_t -htonl(uint32_t x) -{ - return htobe32(x); -} diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c deleted file mode 100644 index 28b13cef98..0000000000 --- a/src/lib/libc/net/htons.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: htons.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef htons - -uint16_t -htons(uint16_t x) -{ - return htobe16(x); -} diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3 deleted file mode 100644 index 25d2a2722f..0000000000 --- a/src/lib/libc/net/if_indextoname.3 +++ /dev/null @@ -1,143 +0,0 @@ -.\" $OpenBSD: if_indextoname.3,v 1.16 2015/11/21 07:48:10 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: November 21 2015 $ -.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 -.In sys/types.h -.In sys/socket.h -.In net/if.h -.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 -.In 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 -.In 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 netintro 4 -.Sh STANDARDS -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re diff --git a/src/lib/libc/net/if_indextoname.c b/src/lib/libc/net/if_indextoname.c deleted file mode 100644 index 3c6e8681fb..0000000000 --- a/src/lib/libc/net/if_indextoname.c +++ /dev/null @@ -1,78 +0,0 @@ -/* $OpenBSD: if_indextoname.c,v 1.12 2018/05/10 13:44:43 tb Exp $ */ -/* $KAME: if_indextoname.c,v 1.6 2000/11/07 22:33:25 jinmei Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * 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 - -/* - * From RFC 2553: - * - * 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 if_nameindex *ifni, *ifni2; - - if ((ifni = if_nameindex()) == NULL) - return NULL; - - for (ifni2 = ifni; ifni2->if_index != 0; ifni2++) { - if (ifni2->if_index == ifindex) { - strlcpy(ifname, ifni2->if_name, IFNAMSIZ); - if_freenameindex(ifni); - return ifname; - } - } - - if_freenameindex(ifni); - errno = ENXIO; - return NULL; -} -DEF_WEAK(if_indextoname); diff --git a/src/lib/libc/net/if_nameindex.c b/src/lib/libc/net/if_nameindex.c deleted file mode 100644 index 6e5bc0809a..0000000000 --- a/src/lib/libc/net/if_nameindex.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: if_nameindex.c,v 1.13 2016/12/16 17:44:59 krw Exp $ */ -/* $KAME: if_nameindex.c,v 1.7 2000/11/24 08:17:20 itojun Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * 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 if_nameindex_msg *ifnm = NULL; - struct if_nameindex *ifni = NULL, *ifni2; - char *cp; - size_t needed; - unsigned int ni, i; - int mib[6]; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; /* protocol */ - mib[3] = 0; /* not used */ - mib[4] = NET_RT_IFNAMES; - mib[5] = 0; /* no flags */ - while (1) { - struct if_nameindex_msg *buf = NULL; - - if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) - goto out; - if (needed == 0) - break; - if ((buf = realloc(ifnm, needed)) == NULL) - goto out; - ifnm = buf; - if (sysctl(mib, 6, ifnm, &needed, NULL, 0) == -1) { - if (errno == ENOMEM) - continue; - goto out; - } - break; - } - - /* - * Allocate a chunk of memory, use the first part for the array of - * structures, and the last part for the strings. - */ - ni = needed / sizeof(*ifnm); - ifni = calloc(ni + 1, sizeof(struct if_nameindex) + IF_NAMESIZE); - if (ifni == NULL) - goto out; - cp = (char *)(ifni + (ni + 1)); - - ifni2 = ifni; - for (i = 0; i < ni; i++) { - ifni2->if_index = ifnm[i].if_index; - /* don't care about truncation */ - strlcpy(cp, ifnm[i].if_name, IF_NAMESIZE); - ifni2->if_name = cp; - ifni2++; - cp += IF_NAMESIZE; - } - /* Finally, terminate the array. */ - ifni2->if_index = 0; - ifni2->if_name = NULL; -out: - free(ifnm); - return ifni; -} - -void -if_freenameindex(struct if_nameindex *ptr) -{ - free(ptr); -} -DEF_WEAK(if_nameindex); -DEF_WEAK(if_freenameindex); diff --git a/src/lib/libc/net/if_nametoindex.c b/src/lib/libc/net/if_nametoindex.c deleted file mode 100644 index 7a4492e37d..0000000000 --- a/src/lib/libc/net/if_nametoindex.c +++ /dev/null @@ -1,77 +0,0 @@ -/* $OpenBSD: if_nametoindex.c,v 1.10 2015/10/23 13:09:19 claudio Exp $ */ -/* $KAME: if_nametoindex.c,v 1.5 2000/11/24 08:04:40 itojun Exp $ */ - -/*- - * Copyright (c) 2015 Claudio Jeker - * 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 - -/* - * 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 if_nameindex *ifni, *ifni2; - unsigned int index; - - if ((ifni = if_nameindex()) == NULL) - return(0); - - for (ifni2 = ifni; ifni2->if_index != 0; ifni2++) { - if (strcmp(ifni2->if_name, ifname) == 0) { - index = ifni2->if_index; - if_freenameindex(ifni); - return index; - } - } - - if_freenameindex(ifni); - errno = ENXIO; - return 0; -} -DEF_WEAK(if_nametoindex); 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 41ba842166..0000000000 --- a/src/lib/libc/net/inet6_opt_init.3 +++ /dev/null @@ -1,328 +0,0 @@ -.\" $OpenBSD: inet6_opt_init.3,v 1.8 2022/03/31 17:27:16 naddy 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: March 31 2022 $ -.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. -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 -.In 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 -function 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 STANDARDS -.Rs -.%A S. Deering -.%A R. Hinden -.%D December 1998 -.%R RFC 2460 -.%T Internet Protocol, Version 6 (IPv6) Specification -.Re -.Pp -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%D May 2003 -.%R RFC 3542 -.%T Advanced Sockets Application Program Interface (API) for IPv6 -.Re -.Sh HISTORY -The implementation first appeared in 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 c40b45057e..0000000000 --- a/src/lib/libc/net/inet6_rth_space.3 +++ /dev/null @@ -1,220 +0,0 @@ -.\" $OpenBSD: inet6_rth_space.3,v 1.8 2022/03/31 17:27:16 naddy 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: March 31 2022 $ -.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 -.In netinet/in.h . -The functions described in this manual page all operate -on routing header structures which are defined in -.In 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_rth_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 STANDARDS -.Rs -.%A S. Deering -.%A R. Hinden -.%D December 1998 -.%R RFC 2460 -.%T Internet Protocol, Version 6 (IPv6) Specification -.Re -.Pp -.Rs -.%A W. Stevens -.%A M. Thomas -.%A E. Nordmark -.%A T. Jinmei -.%D May 2003 -.%R RFC 3542 -.%T Advanced Sockets Application Programming Interface (API) for IPv6 -.Re -.Sh HISTORY -The implementation first appeared in KAME advanced networking kit. diff --git a/src/lib/libc/net/inet_addr.3 b/src/lib/libc/net/inet_addr.3 deleted file mode 100644 index cbb9e14f6d..0000000000 --- a/src/lib/libc/net/inet_addr.3 +++ /dev/null @@ -1,195 +0,0 @@ -.\" $OpenBSD: inet_addr.3,v 1.7 2024/03/06 07:29:37 bentley 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: March 6 2024 $ -.Dt INET_ADDR 3 -.Os -.Sh NAME -.Nm inet_aton , -.Nm inet_addr , -.Nm inet_network , -.Nm inet_ntoa -.Nd Internet Protocol version 4 (IPv4) address manipulation routines -.Sh SYNOPSIS -.In arpa/inet.h -.Ft int -.Fn inet_aton "const char *cp" "struct in_addr *addr" -.Ft in_addr_t -.Fn inet_addr "const char *cp" -.Ft in_addr_t -.Fn inet_network "const char *cp" -.Ft char * -.Fn inet_ntoa "struct in_addr in" -.Sh DESCRIPTION -The functions presented here only support IPv4 addresses. -In order to support IPv6 addresses as well, -.Xr inet_ntop 3 -and -.Xr inet_pton 3 -should be used rather than the functions presented here. -Scoped IPv6 addresses are supported via -.Xr getaddrinfo 3 -and -.Xr getnameinfo 3 . -.Pp -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. -.Pp -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. -.Pp -The -.Fn inet_addr -and -.Fn inet_network -functions return numbers suitable for use -as Internet addresses and Internet network -numbers, respectively. -Both functions return the constant -.Dv INADDR_NONE -if the specified character string is malformed. -.Pp -The routine -.Fn inet_ntoa -takes an Internet address and returns an -ASCII string representing the address in dot notation. -.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 AMD64 or ARM 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 SEE ALSO -.Xr gethostbyname 3 , -.Xr htonl 3 , -.Xr inet_lnaof 3 , -.Xr inet_net_ntop 3 , -.Xr inet_ntop 3 , -.Xr hosts 5 -.Sh STANDARDS -The -.Nm inet_addr -and -.Nm inet_ntoa -functions conform to -.St -p1003.1-2008 . -.Sh HISTORY -The -.Nm inet_addr -and -.Nm inet_network -functions appeared in -.Bx 4.2 . -The -.Nm inet_aton -and -.Nm inet_ntoa -functions appeared in -.Bx 4.3 . -.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 -.Vt 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/inet_addr.c b/src/lib/libc/net/inet_addr.c deleted file mode 100644 index 62d46ad664..0000000000 --- a/src/lib/libc/net/inet_addr.c +++ /dev/null @@ -1,175 +0,0 @@ -/* $OpenBSD: inet_addr.c,v 1.12 2015/09/13 21:36:08 guenther 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 - -/* - * 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((unsigned char)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((unsigned char)c) && - isdigit((unsigned char)c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && - isascii((unsigned char)c) && - isxdigit((unsigned char)c)) { - val = (val << 4) | - (c + 10 - (islower((unsigned char)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((unsigned char)c) || !isspace((unsigned char)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); -} -DEF_WEAK(inet_aton); diff --git a/src/lib/libc/net/inet_lnaof.3 b/src/lib/libc/net/inet_lnaof.3 deleted file mode 100644 index 6151f7fe34..0000000000 --- a/src/lib/libc/net/inet_lnaof.3 +++ /dev/null @@ -1,89 +0,0 @@ -.\" $OpenBSD: inet_lnaof.3,v 1.4 2019/08/30 20:06:07 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: August 30 2019 $ -.Dt INET_LNAOF 3 -.Os -.Sh NAME -.Nm inet_makeaddr , -.Nm inet_netof , -.Nm inet_lnaof -.Nd routines for manipulating classful Internet Protocol version 4 (IPv4) addresses -.Sh SYNOPSIS -.In arpa/inet.h -.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_lnaof "struct in_addr in" -.Sh DESCRIPTION -As originally designed, -IP version 4 split each address into a network part and local network -address part, encoding that split into the address itself. -It is frequency-encoded; -the most-significant bit is clear in Class A addresses, -in which the high-order 8 bits are the network number. -Class B addresses use the high-order 16 bits as the network field, -and Class C addresses have a 24-bit network part. -.Pp -The routine -.Fn inet_makeaddr -takes an Internet network number and a local -network address and constructs an Internet address -from it. -.Pp -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 SEE ALSO -.Xr gethostbyname 3 , -.Xr inet_addr 3 , -.Xr inet_net_ntop 3 , -.Xr hosts 5 -.Sh HISTORY -The -.Nm inet_makeaddr , -.Nm inet_lnaof , -and -.Nm inet_netof -functions appeared in -.Bx 4.2 . diff --git a/src/lib/libc/net/inet_lnaof.c b/src/lib/libc/net/inet_lnaof.c deleted file mode 100644 index 92845387d3..0000000000 --- a/src/lib/libc/net/inet_lnaof.c +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: inet_lnaof.c,v 1.7 2015/01/16 16:48:51 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 - -/* - * 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 88ddd2850e..0000000000 --- a/src/lib/libc/net/inet_makeaddr.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $OpenBSD: inet_makeaddr.c,v 1.7 2015/01/16 16:48:51 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 - -/* - * 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_ntop.3 b/src/lib/libc/net/inet_net_ntop.3 deleted file mode 100644 index 4212af3bb6..0000000000 --- a/src/lib/libc/net/inet_net_ntop.3 +++ /dev/null @@ -1,195 +0,0 @@ -.\" $OpenBSD: inet_net_ntop.3,v 1.4 2022/09/11 06:38:10 jmc 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: September 11 2022 $ -.Dt INET_NET_NTOP 3 -.Os -.Sh NAME -.Nm inet_net_ntop , -.Nm inet_net_pton -.Nd Internet network number manipulation routines -.Sh SYNOPSIS -.In sys/socket.h -.In arpa/inet.h -.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 -.Vt 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 -.Vt 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 values for -.Fa af -currently supported are -.Dv AF_INET -and -.Dv AF_INET6 . -.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 NETWORK NUMBERS (IP VERSION 6) -See -.Xr inet_pton 3 -for valid external representations of IP version 6 addresses. -A valid external representation may have -.Dq Li /bits -appended where -.Dq Li bits -is in the range -.Li 0-128 -and is used to explicitly specify the number of bits in the network address. -When -.Dq Li /bits -is not specified, 128 is used. -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. -.Sh SEE ALSO -.Xr htonl 3 , -.Xr inet_pton 3 , -.Xr inet 4 , -.Xr hosts 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 1f1c4bed12..0000000000 --- a/src/lib/libc/net/inet_net_ntop.c +++ /dev/null @@ -1,160 +0,0 @@ -/* $OpenBSD: inet_net_ntop.c,v 1.9 2019/07/03 03:24:04 deraadt Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * 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); -static char *inet_net_ntop_ipv6(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)); - case AF_INET6: - return (inet_net_ntop_ipv6(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) - *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); -} - -static char * -inet_net_ntop_ipv6(const u_char *src, int bits, char *dst, size_t size) -{ - int ret; - char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255:255:255:255/128")]; - - if (bits < 0 || bits > 128) { - errno = EINVAL; - return (NULL); - } - - if (inet_ntop(AF_INET6, src, buf, size) == NULL) - return (NULL); - - ret = snprintf(dst, size, "%s/%d", buf, bits); - if (ret < 0 || ret >= size) { - errno = EMSGSIZE; - return (NULL); - } - - return (dst); -} 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 c5baa4d6f4..0000000000 --- a/src/lib/libc/net/inet_net_pton.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $OpenBSD: inet_net_pton.c,v 1.14 2022/12/27 17:10:06 jmc Exp $ */ - -/* - * Copyright (c) 2012 by Gilles Chehade - * Copyright (c) 1996,1999 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_ipv6(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)); - case AF_INET6: - return (inet_net_pton_ipv6(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 = (unsigned char)*src++; - if (ch == '0' && (src[0] == 'x' || src[0] == 'X') - && isascii((unsigned char)src[1]) && isxdigit((unsigned char)src[1])) { - /* Hexadecimal: Eat nybble string. */ - if (size == 0) - goto emsgsize; - tmp = 0, dirty = 0; - src++; /* skip x or X. */ - while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isxdigit(ch)) { - if (isupper(ch)) - ch = tolower(ch); - n = strchr(xdigits, ch) - xdigits; - assert(n >= 0 && n <= 15); - if (dirty == 0) - tmp = n; - else - tmp = (tmp << 4) | n; - if (++dirty == 2) { - if (size-- == 0) - goto emsgsize; - *dst++ = (u_char) tmp; - dirty = 0; - } - } - if (dirty) { /* Odd trailing nybble? */ - if (size-- == 0) - goto emsgsize; - *dst++ = (u_char) (tmp << 4); - } - } 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 = (unsigned char)*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 = (unsigned char)*src++; - if (!isascii(ch) || !isdigit(ch)) - goto enoent; - } - } else - goto enoent; - - bits = -1; - if (ch == '/' && isascii((unsigned char)src[0]) && - isdigit((unsigned char)src[0]) && dst > odst) { - /* CIDR width specifier. Nothing can follow it. */ - ch = (unsigned char)*src++; /* Skip over the /. */ - bits = 0; - do { - n = strchr(digits, ch) - digits; - assert(n >= 0 && n <= 9); - bits *= 10; - bits += n; - if (bits > 32) - goto emsgsize; - } while ((ch = (unsigned char)*src++) != '\0' && - isascii(ch) && isdigit(ch)); - if (ch != '\0') - goto enoent; - } - - /* Fiery 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); -} - - -static int -inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) -{ - struct in6_addr in6; - int ret; - int bits; - size_t bytes; - char buf[INET6_ADDRSTRLEN + sizeof("/128")]; - char *sep; - const char *errstr; - - if (strlcpy(buf, src, sizeof buf) >= sizeof buf) { - errno = EMSGSIZE; - return (-1); - } - - sep = strchr(buf, '/'); - if (sep != NULL) - *sep++ = '\0'; - - ret = inet_pton(AF_INET6, buf, &in6); - if (ret != 1) - return (-1); - - if (sep == NULL) - bits = 128; - else { - bits = strtonum(sep, 0, 128, &errstr); - if (errstr) { - errno = EINVAL; - return (-1); - } - } - - bytes = (bits + 7) / 8; - if (bytes > size) { - errno = EMSGSIZE; - return (-1); - } - memcpy(dst, &in6.s6_addr, bytes); - return (bits); -} 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 4efceede13..0000000000 --- a/src/lib/libc/net/inet_netof.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $OpenBSD: inet_netof.c,v 1.7 2015/01/16 16:48:51 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 - -/* - * 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 7b0cf50e79..0000000000 --- a/src/lib/libc/net/inet_network.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: inet_network.c,v 1.13 2015/10/22 23:55:51 mmcc 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; - u_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((unsigned char)*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); -} -DEF_WEAK(inet_network); 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.3 b/src/lib/libc/net/inet_ntop.3 deleted file mode 100644 index e5c1c574f8..0000000000 --- a/src/lib/libc/net/inet_ntop.3 +++ /dev/null @@ -1,213 +0,0 @@ -.\" $OpenBSD: inet_ntop.3,v 1.6 2022/09/11 06:38:10 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: September 11 2022 $ -.Dt INET_NTOP 3 -.Os -.Sh NAME -.Nm inet_ntop , -.Nm inet_pton -.Nd convert Internet addresses between presentation and network formats -.Sh SYNOPSIS -.In sys/socket.h -.In arpa/inet.h -.Ft const char * -.Fn inet_ntop "int af" "const void * restrict src" "char * restrict dst" "socklen_t size" -.Ft int -.Fn inet_pton "int af" "const char * restrict src" "void * restrict dst" -.Sh DESCRIPTION -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 -.Vt 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 . -.Pp -The function -.Fn inet_ntop -converts an address from network format to presentation format. -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 -All Internet addresses are returned in network -order (bytes ordered from left to right). -.Sh INTERNET ADDRESSES (IP VERSION 4) -Values must be specified using the standard dot notation: -.Bd -literal -offset indent -a.b.c.d -.Ed -.Pp -All four parts must be decimal numbers between 0 and 255, inclusive, -and are 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 AMD64 or ARM 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. -.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 4291: -.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 SEE ALSO -.Xr gethostbyname 3 , -.Xr inet_addr 3 , -.Xr inet_net_ntop 3 , -.Xr hosts 5 -.Sh STANDARDS -The -.Nm inet_ntop -and -.Nm inet_pton -functions conform to the IETF IPv6 BSD API and address formatting -specifications, as well as -.St -p1003.1-2008 . -.Sh HISTORY -The -.Nm inet_pton -and -.Nm inet_ntop -functions appeared in BIND 4.9.4. -.Sh CAVEATS -Note that -.Nm inet_pton -does not accept 1-, 2-, or 3-part dotted addresses; -all four parts must be specified and must be in decimal -(and not octal or hexadecimal). -This is a narrower input set than that accepted by -.Nm inet_aton . -.Pp -.Rs -.%A R. Gilligan -.%A S. Thomson -.%A J. Bound -.%A J. McCann -.%A W. Stevens -.%D February 2003 -.%R RFC 3493 -.%T Basic Socket Interface Extensions for IPv6 -.Re -.Pp -.Rs -.%A R. Hinden -.%A S. Deering -.%D February 2006 -.%R RFC 4291 -.%T IP Version 6 Addressing Architecture -.Re diff --git a/src/lib/libc/net/inet_ntop.c b/src/lib/libc/net/inet_ntop.c deleted file mode 100644 index 2bb11c2ab2..0000000000 --- a/src/lib/libc/net/inet_ntop.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $OpenBSD: inet_ntop.c,v 1.13 2016/09/21 04:38:56 guenther 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 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); - -/* const 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, socklen_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 */ -} -DEF_WEAK(inet_ntop); - -/* 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) -{ - char tmp[sizeof "255.255.255.255"]; - int l; - - l = snprintf(tmp, sizeof(tmp), "%u.%u.%u.%u", - 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) { - errno = ENOSPC; - return (NULL); - } - *tp++ = ':'; - } - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) { - if (tp + 1 >= ep) { - errno = ENOSPC; - 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, ep - tp)) - return (NULL); - tp += strlen(tp); - break; - } - advance = snprintf(tp, ep - tp, "%x", words[i]); - if (advance <= 0 || advance >= ep - tp) { - errno = ENOSPC; - 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) { - errno = ENOSPC; - return (NULL); - } - *tp++ = ':'; - } - if (tp + 1 >= ep) { - errno = ENOSPC; - 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 45bafd2ffc..0000000000 --- a/src/lib/libc/net/inet_pton.c +++ /dev/null @@ -1,213 +0,0 @@ -/* $OpenBSD: inet_pton.c,v 1.11 2024/09/03 17:05:59 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 - -/* - * 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 */ -} -DEF_WEAK(inet_pton); - -/* 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: - * does not touch `dst' unless it's returning 1. - * 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; - - if (tp == endp) - return (0); - 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 3837489448..0000000000 --- a/src/lib/libc/net/ip6opt.c +++ /dev/null @@ -1,285 +0,0 @@ -/* $OpenBSD: ip6opt.c,v 1.10 2020/01/22 07:52:37 deraadt 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 - -static int ip6optlen(u_int8_t *opt, u_int8_t *lim); - -/* - * 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); -} - -/* - * 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 (ext) { - if (extlen <= 0 || (extlen % 8)) - 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 > 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_ntoa.3 b/src/lib/libc/net/link_ntoa.3 deleted file mode 100644 index 8953677441..0000000000 --- a/src/lib/libc/net/link_ntoa.3 +++ /dev/null @@ -1,78 +0,0 @@ -.\" $OpenBSD: link_ntoa.3,v 1.2 2015/09/10 10:14:20 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: September 10 2015 $ -.Dt LINK_NTOA 3 -.Os -.Sh NAME -.Nm link_ntoa -.Nd elementary address specification routine for link level access -.Sh SYNOPSIS -.In sys/types.h -.In sys/socket.h -.In net/if_dl.h -.Ft char * -.Fn link_ntoa "const struct sockaddr_dl *sdl" -.Sh DESCRIPTION -The -.Fn link_ntoa -function 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. -.Sh RETURN VALUES -.Fn link_ntoa -always returns a NUL-terminated string. -.Sh SEE ALSO -.Xr ifconfig 8 -.Sh HISTORY -The -.Fn link_ntoa -function appeared in -.Bx 4.3 Reno . -.Sh BUGS -The returned values for -.Fn link_ntoa -reside in a static memory area. -.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. diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c deleted file mode 100644 index 9101e23a86..0000000000 --- a/src/lib/libc/net/linkaddr.c +++ /dev/null @@ -1,85 +0,0 @@ -/* $OpenBSD: linkaddr.c,v 1.9 2016/12/08 03:20:50 millert 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 -#include - -static const char hexlist[] = "0123456789abcdef"; - -char * -link_ntoa(const struct sockaddr_dl *sdl) -{ - static char obuf[64]; - char *out; - const u_char *in, *inlim; - int namelen, i, rem; - - namelen = (sdl->sdl_nlen <= IFNAMSIZ) ? sdl->sdl_nlen : IFNAMSIZ; - - out = obuf; - rem = sizeof(obuf); - if (namelen > 0) { - memcpy(out, sdl->sdl_data, namelen); - out += namelen; - rem -= namelen; - if (sdl->sdl_alen > 0) { - *out++ = ':'; - rem--; - } - } - - in = (const u_char *)sdl->sdl_data + sdl->sdl_nlen; - inlim = in + sdl->sdl_alen; - - while (in < inlim && rem > 1) { - if (in != (const u_char *)sdl->sdl_data + sdl->sdl_nlen) { - *out++ = '.'; - rem--; - } - i = *in++; - if (i > 0xf) { - if (rem < 3) - break; - *out++ = hexlist[i >> 4]; - *out++ = hexlist[i & 0xf]; - rem -= 2; - } else { - if (rem < 2) - break; - *out++ = hexlist[i]; - rem--; - } - } - *out = 0; - return (obuf); -} diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c deleted file mode 100644 index 7592398e8c..0000000000 --- a/src/lib/libc/net/ntohl.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: ntohl.c,v 1.8 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef ntohl - -uint32_t -ntohl(uint32_t x) -{ - return be32toh(x); -} diff --git a/src/lib/libc/net/ntohs.c b/src/lib/libc/net/ntohs.c deleted file mode 100644 index ef22ea3068..0000000000 --- a/src/lib/libc/net/ntohs.c +++ /dev/null @@ -1,15 +0,0 @@ -/* $OpenBSD: ntohs.c,v 1.10 2024/04/15 14:30:48 naddy Exp $ */ -/* - * Public domain. - */ - -#include -#include - -#undef ntohs - -uint16_t -ntohs(uint16_t x) -{ - return be16toh(x); -} diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 deleted file mode 100644 index b2a5cdea9b..0000000000 --- a/src/lib/libc/net/rcmd.3 +++ /dev/null @@ -1,232 +0,0 @@ -.\" $OpenBSD: rcmd.3,v 1.34 2016/05/28 15:48:30 millert 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 28 2016 $ -.Dt RCMD 3 -.Os -.Sh NAME -.Nm rcmd , -.Nm rcmd_af , -.Nm rresvport , -.Nm rresvport_af , -.Nm ruserok -.Nd routines for returning a stream to a remote command -.Sh SYNOPSIS -.In unistd.h -.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 ruserok "const char *rhost" "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 ssh 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 ruserok -function is used by servers -to authenticate clients requesting service with -.Fn rcmd . -.Pp -The -.Fn rcmd -function looks up the host -.Fa *ahost -using -.Xr getaddrinfo 3 -and, if the host exists, -.Fa *ahost -is set to the canonical name of the host. -A connection is then 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 AF_UNSPEC , -interpretation of -.Fa *ahost -will obey the underlying address resolution like DNS. -.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 ruserok -function takes a remote host's name, 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 ruserok -returns \-1. -If the local domain (as obtained from -.Xr getaddrinfo 3 ) -is the same as the remote domain, only the machine name need be specified. -.Pp -.Fn ruserok -implicitly requires trusting the DNS server for the remote host's domain. -.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 ssh 1 , -.Xr intro 2 , -.Xr bindresvport 3 , -.Xr bindresvport_sa 3 , -.Xr rcmdsh 3 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . -.Pp -The -.Fn iruserok -and -.Fn iruserok_sa -functions, IP address based versions of -.Fn ruserok , -were removed in -.Ox 6.0 . diff --git a/src/lib/libc/net/rcmd.c b/src/lib/libc/net/rcmd.c deleted file mode 100644 index bf68603649..0000000000 --- a/src/lib/libc/net/rcmd.c +++ /dev/null @@ -1,296 +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 -#include - -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[HOST_NAME_MAX+1]; - char pbuf[NI_MAXSERV]; - struct addrinfo hints, *res, *r; - int error; - struct sockaddr_storage from; - sigset_t oldmask, mask; - pid_t pid; - int s, lport; - struct timespec timo; - char c, *p; - int refused; - in_port_t rport = porta; - int numread; - - /* 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) { - (void)fprintf(stderr, "rcmd: %s: %s\n", *ahost, - gai_strerror(error)); - return (-1); - } - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } else - ; /*XXX*/ - - r = res; - refused = 0; - timespecclear(&timo); - sigemptyset(&mask); - sigaddset(&mask, SIGURG); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - for (timo.tv_sec = 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.tv_sec <= 16) { - (void)nanosleep(&timo, NULL); - timo.tv_sec *= 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 (fd2p == 0) { - write(s, "", 1); - lport = 0; - } else { - struct pollfd pfd[2]; - char num[8]; - int s2 = rresvport_af(&lport, af), s3; - socklen_t len = sizeof(from); - - if (s2 < 0) - 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: - pfd[0].fd = s; - pfd[0].events = POLLIN; - pfd[1].fd = s2; - pfd[1].events = POLLIN; - - errno = 0; - if (poll(pfd, 2, INFTIM) < 1 || - (pfd[1].revents & (POLLIN|POLLHUP)) == 0) { - if (errno != 0) - (void)fprintf(stderr, - "rcmd: poll (setting up stderr): %s\n", - strerror(errno)); - else - (void)fprintf(stderr, - "poll: 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 ((numread = read(s, &c, 1)) != 1) { - (void)fprintf(stderr, - "rcmd: %s: %s\n", *ahost, - numread == -1 ? strerror(errno) : "Short read"); - 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); - return (s); -bad2: - if (lport) - (void)close(*fd2p); -bad: - (void)close(s); - sigprocmask(SIG_SETMASK, &oldmask, NULL); - return (-1); -} -DEF_WEAK(rcmd_af); - diff --git a/src/lib/libc/net/rcmdsh.3 b/src/lib/libc/net/rcmdsh.3 deleted file mode 100644 index 9092d19f81..0000000000 --- a/src/lib/libc/net/rcmdsh.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" $OpenBSD: rcmdsh.3,v 1.18 2016/05/28 15:48:30 millert 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 28 2016 $ -.Dt RCMDSH 3 -.Os -.Sh NAME -.Nm rcmdsh -.Nd return a stream to a remote command without superuser -.Sh SYNOPSIS -.In unistd.h -.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 ssh 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 getaddrinfo 3 -and, if the host exists, -.Fa *ahost -is set to the canonical name of the host. -A connection is then 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 -.Ux Ns -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 ssh 1 , -.Xr socketpair 2 , -.Xr rcmd 3 -.Sh HISTORY -The -.Fn rcmdsh -function first appeared in -.Ox 2.0 . -.Sh BUGS -If -.Xr ssh 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 66caac3f3d..0000000000 --- a/src/lib/libc/net/rcmdsh.c +++ /dev/null @@ -1,194 +0,0 @@ -/* $OpenBSD: rcmdsh.c,v 1.20 2019/06/28 13:32:42 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 -#include - -/* - * This is a replacement rcmd() function that uses the ssh(1) - * program in place of a direct rcmd(3) function call so as to - * avoid having to be root. Note that rport is ignored. - */ -int -rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, - const char *cmd, char *rshprog) -{ - static char hbuf[HOST_NAME_MAX+1]; - struct addrinfo hint, *res; - int sp[2]; - pid_t cpid; - char *p, pwbuf[_PW_BUF_LEN]; - struct passwd pwstore, *pw = NULL; - - /* What rsh/shell to use. */ - if (rshprog == NULL) - rshprog = _PATH_RSH; - - /* locuser must exist on this host. */ - getpwnam_r(locuser, &pwstore, pwbuf, sizeof(pwbuf), &pw); - if (pw == NULL) { - (void) fprintf(stderr, "rcmdsh: unknown user: %s\n", locuser); - return(-1); - } - - /* Validate remote hostname. */ - if (strcmp(*ahost, "localhost") != 0) { - memset(&hint, 0, sizeof(hint)); - hint.ai_family = PF_UNSPEC; - hint.ai_flags = AI_CANONNAME; - if (getaddrinfo(*ahost, NULL, &hint, &res) == 0) { - if (res->ai_canonname) { - strlcpy(hbuf, res->ai_canonname, sizeof(hbuf)); - *ahost = hbuf; - } - freeaddrinfo(res); - } - } - - /* Get a socketpair we'll use for stdin and stdout. */ - if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) == -1) { - perror("rcmdsh: socketpair"); - return(-1); - } - - cpid = fork(); - if (cpid == -1) { - 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) == -1 || dup2(0, 1) == -1) { - perror("rcmdsh: dup2 failed"); - _exit(255); - } - /* Fork again to lose parent. */ - cpid = fork(); - if (cpid == -1) { - 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. */ - while (waitpid(cpid, NULL, 0) == -1 && errno == EINTR) - ; - return(sp[0]); - } - /* NOTREACHED */ -} -DEF_WEAK(rcmdsh); diff --git a/src/lib/libc/net/recv.c b/src/lib/libc/net/recv.c deleted file mode 100644 index 1488ca26bd..0000000000 --- a/src/lib/libc/net/recv.c +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: recv.c,v 1.7 2023/03/25 19:16:34 otto 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, NULL)); -} -DEF_WEAK(recv); diff --git a/src/lib/libc/net/res_comp.c b/src/lib/libc/net/res_comp.c deleted file mode 100644 index ce9f92ae77..0000000000 --- a/src/lib/libc/net/res_comp.c +++ /dev/null @@ -1,466 +0,0 @@ -/* $OpenBSD: res_comp.c,v 1.23 2023/03/15 22:12:00 millert 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 beginning 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; - - if (comp_dn < msg || comp_dn >= eomorig) - return (-1); - - dn = exp_dn; - cp = comp_dn; - if (length > HOST_NAME_MAX) - length = HOST_NAME_MAX; - eom = exp_dn + length; - /* - * fetch next label in domain name - */ - while ((n = *cp++)) { - if (cp >= eomorig) /* out of range */ - return (-1); - - /* - * 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); -} -DEF_WEAK(dn_expand); - -/* - * 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 array 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); -} - -/* - * 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 (tolower((unsigned char)*dn++) != - tolower((unsigned char)*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); -} -DEF_STRONG(__res_hnok); - -/* - * 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