003 File Manager
Current Path:
/usr/src/crypto/openssh/openbsd-compat
usr
/
src
/
crypto
/
openssh
/
openbsd-compat
/
📁
..
📄
Makefile.in
(1.77 KB)
📄
arc4random.c
(7.06 KB)
📄
base64.c
(10.25 KB)
📄
base64.h
(2.69 KB)
📄
basename.c
(1.78 KB)
📄
bcrypt_pbkdf.c
(5.38 KB)
📄
bindresvport.c
(3.24 KB)
📄
blf.h
(3.49 KB)
📄
blowfish.c
(23.11 KB)
📄
bsd-asprintf.c
(2.31 KB)
📄
bsd-closefrom.c
(2.84 KB)
📄
bsd-cygwin_util.c
(3.15 KB)
📄
bsd-cygwin_util.h
(2.34 KB)
📄
bsd-err.c
(2.15 KB)
📄
bsd-flock.c
(2.23 KB)
📄
bsd-getline.c
(2.9 KB)
📄
bsd-getpagesize.c
(463 B)
📄
bsd-getpeereid.c
(1.68 KB)
📄
bsd-malloc.c
(1.4 KB)
📄
bsd-misc.c
(5.88 KB)
📄
bsd-misc.h
(3.61 KB)
📄
bsd-nextstep.c
(2.5 KB)
📄
bsd-nextstep.h
(2.22 KB)
📄
bsd-openpty.c
(4.92 KB)
📄
bsd-poll.c
(2.91 KB)
📄
bsd-poll.h
(2.06 KB)
📄
bsd-setres_id.c
(2.34 KB)
📄
bsd-setres_id.h
(930 B)
📄
bsd-signal.c
(1.55 KB)
📄
bsd-signal.h
(1.15 KB)
📄
bsd-snprintf.c
(20.58 KB)
📄
bsd-statvfs.c
(2.09 KB)
📄
bsd-statvfs.h
(2.24 KB)
📄
bsd-waitpid.c
(1.77 KB)
📄
bsd-waitpid.h
(2.02 KB)
📄
chacha_private.h
(5.26 KB)
📄
charclass.h
(702 B)
📄
daemon.c
(2.32 KB)
📄
dirname.c
(1.87 KB)
📄
explicit_bzero.c
(1.09 KB)
📄
fake-rfc2553.c
(6.15 KB)
📄
fake-rfc2553.h
(5.2 KB)
📄
fmt_scaled.c
(7.69 KB)
📄
freezero.c
(1.01 KB)
📄
getcwd.c
(5.95 KB)
📄
getgrouplist.c
(2.7 KB)
📄
getopt.h
(2.71 KB)
📄
getopt_long.c
(14.46 KB)
📄
getrrsetbyname-ldns.c
(7.81 KB)
📄
getrrsetbyname.c
(13.56 KB)
📄
getrrsetbyname.h
(3.62 KB)
📄
glob.c
(25.53 KB)
📄
glob.h
(4.54 KB)
📄
inet_aton.c
(5.23 KB)
📄
inet_ntoa.c
(2.21 KB)
📄
inet_ntop.c
(5.42 KB)
📄
kludge-fd_set.c
(882 B)
📄
libressl-api-compat.c
(16.19 KB)
📄
md5.c
(7.83 KB)
📄
md5.h
(1.85 KB)
📄
mktemp.c
(3.14 KB)
📄
openbsd-compat.h
(8.68 KB)
📄
openssl-compat.c
(2.43 KB)
📄
openssl-compat.h
(7.22 KB)
📄
port-aix.c
(12.61 KB)
📄
port-aix.h
(4.22 KB)
📄
port-irix.c
(2.94 KB)
📄
port-irix.h
(1.65 KB)
📄
port-linux.c
(7.66 KB)
📄
port-linux.h
(1.18 KB)
📄
port-net.c
(8.33 KB)
📄
port-net.h
(1.58 KB)
📄
port-solaris.c
(9.56 KB)
📄
port-solaris.h
(1.27 KB)
📄
port-uw.c
(4.16 KB)
📄
port-uw.h
(1.37 KB)
📄
pwcache.c
(3.22 KB)
📄
readpassphrase.c
(5.79 KB)
📄
readpassphrase.h
(1.75 KB)
📄
reallocarray.c
(1.49 KB)
📄
realpath.c
(6.08 KB)
📄
recallocarray.c
(2.4 KB)
📁
regress
📄
rmd160.c
(11.72 KB)
📄
rmd160.h
(2.81 KB)
📄
rresvport.c
(2.97 KB)
📄
setenv.c
(5.76 KB)
📄
setproctitle.c
(4.55 KB)
📄
sha1.c
(5.18 KB)
📄
sha1.h
(2.23 KB)
📄
sha2.c
(24.88 KB)
📄
sha2.h
(5.66 KB)
📄
sigact.c
(3.82 KB)
📄
sigact.h
(3.66 KB)
📄
strcasestr.c
(2.35 KB)
📄
strlcat.c
(1.76 KB)
📄
strlcpy.c
(1.64 KB)
📄
strmode.c
(3.38 KB)
📄
strndup.c
(1.27 KB)
📄
strnlen.c
(1.18 KB)
📄
strptime.c
(9.28 KB)
📄
strsep.c
(2.59 KB)
📄
strtoll.c
(4.29 KB)
📄
strtonum.c
(1.85 KB)
📄
strtoul.c
(3.07 KB)
📄
strtoull.c
(3.13 KB)
📄
sys-queue.h
(21.04 KB)
📄
sys-tree.h
(24.68 KB)
📄
timingsafe_bcmp.c
(1.17 KB)
📄
vis.c
(5.97 KB)
📄
vis.h
(3.57 KB)
📄
xcrypt.c
(4.26 KB)
Editing: port-net.c
/* * Copyright (c) 2005 Reyk Floeter <reyk@openbsd.org> * * 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 "includes.h" #include <sys/types.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netinet/ip.h> #include <errno.h> #include <fcntl.h> #include <stdarg.h> #include <string.h> #include <unistd.h> #include "openbsd-compat/sys-queue.h" #include "log.h" #include "misc.h" #include "sshbuf.h" #include "channels.h" #include "ssherr.h" /* * This file contains various portability code for network support, * including tun/tap forwarding and routing domains. */ #if defined(SYS_RDOMAIN_LINUX) || defined(SSH_TUN_LINUX) #include <linux/if.h> #endif #if defined(SYS_RDOMAIN_LINUX) char * sys_get_rdomain(int fd) { char dev[IFNAMSIZ + 1]; socklen_t len = sizeof(dev) - 1; if (getsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, dev, &len) == -1) { error("%s: cannot determine VRF for fd=%d : %s", __func__, fd, strerror(errno)); return NULL; } dev[len] = '\0'; return strdup(dev); } int sys_set_rdomain(int fd, const char *name) { if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name)) == -1) { error("%s: setsockopt(%d, SO_BINDTODEVICE, %s): %s", __func__, fd, name, strerror(errno)); return -1; } return 0; } int sys_valid_rdomain(const char *name) { int fd; /* * This is a pretty crappy way to test. It would be better to * check whether "name" represents a VRF device, but apparently * that requires an rtnetlink transaction. */ if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) return 0; if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, name, strlen(name)) == -1) { close(fd); return 0; } close(fd); return 1; } #elif defined(SYS_RDOMAIN_XXX) /* XXX examples */ char * sys_get_rdomain(int fd) { return NULL; } int sys_set_rdomain(int fd, const char *name) { return -1; } int valid_rdomain(const char *name) { return 0; } void sys_set_process_rdomain(const char *name) { fatal("%s: not supported", __func__); } #endif /* defined(SYS_RDOMAIN_XXX) */ /* * This is the portable version of the SSH tunnel forwarding, it * uses some preprocessor definitions for various platform-specific * settings. * * SSH_TUN_LINUX Use the (newer) Linux tun/tap device * SSH_TUN_FREEBSD Use the FreeBSD tun/tap device * SSH_TUN_COMPAT_AF Translate the OpenBSD address family * SSH_TUN_PREPEND_AF Prepend/remove the address family */ /* * System-specific tunnel open function */ #if defined(SSH_TUN_LINUX) #include <linux/if_tun.h> int sys_tun_open(int tun, int mode, char **ifname) { struct ifreq ifr; int fd = -1; const char *name = NULL; if (ifname != NULL) *ifname = NULL; if ((fd = open("/dev/net/tun", O_RDWR)) == -1) { debug("%s: failed to open tunnel control interface: %s", __func__, strerror(errno)); return (-1); } bzero(&ifr, sizeof(ifr)); if (mode == SSH_TUNMODE_ETHERNET) { ifr.ifr_flags = IFF_TAP; name = "tap%d"; } else { ifr.ifr_flags = IFF_TUN; name = "tun%d"; } ifr.ifr_flags |= IFF_NO_PI; if (tun != SSH_TUNID_ANY) { if (tun > SSH_TUNID_MAX) { debug("%s: invalid tunnel id %x: %s", __func__, tun, strerror(errno)); goto failed; } snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), name, tun); } if (ioctl(fd, TUNSETIFF, &ifr) == -1) { debug("%s: failed to configure tunnel (mode %d): %s", __func__, mode, strerror(errno)); goto failed; } if (tun == SSH_TUNID_ANY) debug("%s: tunnel mode %d fd %d", __func__, mode, fd); else debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd); if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)) == NULL) goto failed; return (fd); failed: close(fd); return (-1); } #endif /* SSH_TUN_LINUX */ #ifdef SSH_TUN_FREEBSD #include <sys/socket.h> #include <net/if.h> #ifdef HAVE_NET_IF_TUN_H #include <net/if_tun.h> #endif int sys_tun_open(int tun, int mode, char **ifname) { struct ifreq ifr; char name[100]; int fd = -1, sock, flag; const char *tunbase = "tun"; if (ifname != NULL) *ifname = NULL; if (mode == SSH_TUNMODE_ETHERNET) { #ifdef SSH_TUN_NO_L2 debug("%s: no layer 2 tunnelling support", __func__); return (-1); #else tunbase = "tap"; #endif } /* Open the tunnel device */ if (tun <= SSH_TUNID_MAX) { snprintf(name, sizeof(name), "/dev/%s%d", tunbase, tun); fd = open(name, O_RDWR); } else if (tun == SSH_TUNID_ANY) { for (tun = 100; tun >= 0; tun--) { snprintf(name, sizeof(name), "/dev/%s%d", tunbase, tun); if ((fd = open(name, O_RDWR)) >= 0) break; } } else { debug("%s: invalid tunnel %u\n", __func__, tun); return (-1); } if (fd < 0) { debug("%s: %s open failed: %s", __func__, name, strerror(errno)); return (-1); } /* Turn on tunnel headers */ flag = 1; #if defined(TUNSIFHEAD) && !defined(SSH_TUN_PREPEND_AF) if (mode != SSH_TUNMODE_ETHERNET && ioctl(fd, TUNSIFHEAD, &flag) == -1) { debug("%s: ioctl(%d, TUNSIFHEAD, 1): %s", __func__, fd, strerror(errno)); close(fd); } #endif debug("%s: %s mode %d fd %d", __func__, name, mode, fd); /* Set the tunnel device operation mode */ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", tunbase, tun); if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) goto failed; if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) goto failed; if ((ifr.ifr_flags & IFF_UP) == 0) { ifr.ifr_flags |= IFF_UP; if (ioctl(sock, SIOCSIFFLAGS, &ifr) == -1) goto failed; } if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)) == NULL) goto failed; close(sock); return (fd); failed: if (fd >= 0) close(fd); if (sock >= 0) close(sock); debug("%s: failed to set %s mode %d: %s", __func__, name, mode, strerror(errno)); return (-1); } #endif /* SSH_TUN_FREEBSD */ /* * System-specific channel filters */ #if defined(SSH_TUN_FILTER) /* * The tunnel forwarding protocol prepends the address family of forwarded * IP packets using OpenBSD's numbers. */ #define OPENBSD_AF_INET 2 #define OPENBSD_AF_INET6 24 int sys_tun_infilter(struct ssh *ssh, struct Channel *c, char *buf, int _len) { int r; size_t len; char *ptr = buf; #if defined(SSH_TUN_PREPEND_AF) char rbuf[CHAN_RBUF]; struct ip iph; #endif #if defined(SSH_TUN_PREPEND_AF) || defined(SSH_TUN_COMPAT_AF) u_int32_t af; #endif /* XXX update channel input filter API to use unsigned length */ if (_len < 0) return -1; len = _len; #if defined(SSH_TUN_PREPEND_AF) if (len <= sizeof(iph) || len > sizeof(rbuf) - 4) return -1; /* Determine address family from packet IP header. */ memcpy(&iph, buf, sizeof(iph)); af = iph.ip_v == 6 ? OPENBSD_AF_INET6 : OPENBSD_AF_INET; /* Prepend address family to packet using OpenBSD constants */ memcpy(rbuf + 4, buf, len); len += 4; POKE_U32(rbuf, af); ptr = rbuf; #elif defined(SSH_TUN_COMPAT_AF) /* Convert existing address family header to OpenBSD value */ if (len <= 4) return -1; af = PEEK_U32(buf); /* Put it back */ POKE_U32(buf, af == AF_INET6 ? OPENBSD_AF_INET6 : OPENBSD_AF_INET); #endif if ((r = sshbuf_put_string(c->input, ptr, len)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); return (0); } u_char * sys_tun_outfilter(struct ssh *ssh, struct Channel *c, u_char **data, size_t *dlen) { u_char *buf; u_int32_t af; int r; /* XXX new API is incompatible with this signature. */ if ((r = sshbuf_get_string(c->output, data, dlen)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); if (*dlen < sizeof(af)) return (NULL); buf = *data; #if defined(SSH_TUN_PREPEND_AF) /* skip address family */ *dlen -= sizeof(af); buf = *data + sizeof(af); #elif defined(SSH_TUN_COMPAT_AF) /* translate address family */ af = (PEEK_U32(buf) == OPENBSD_AF_INET6) ? AF_INET6 : AF_INET; POKE_U32(buf, af); #endif return (buf); } #endif /* SSH_TUN_FILTER */
Upload File
Create Folder