Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-socketcan]: src/usr.bin/nc 727295



details:   https://anonhg.NetBSD.org/src/rev/e1e6dbe0ed9f
branches:  bouyer-socketcan
changeset: 820832:e1e6dbe0ed9f
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Feb 09 21:23:49 2017 +0000

description:
727295

diffstat:

 usr.bin/nc/netcat.c |  1790 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1790 insertions(+), 0 deletions(-)

diffs (truncated from 1794 to 300 lines):

diff -r 6c683854d463 -r e1e6dbe0ed9f usr.bin/nc/netcat.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/nc/netcat.c       Thu Feb 09 21:23:49 2017 +0000
@@ -0,0 +1,1790 @@
+/* $OpenBSD: netcat.c,v 1.172 2017/02/05 01:39:14 jca Exp $ */
+/*
+ * Copyright (c) 2001 Eric Jackson <ericj%monkey.org@localhost>
+ * Copyright (c) 2015 Bob Beck.  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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: netcat.c,v 1.5.4.2 2017/02/09 21:23:49 christos Exp $");
+
+/*
+ * Re-written nc(1) for OpenBSD. Original implementation by
+ * *Hobbit* <hobbit%avian.org@localhost>.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netinet/ip.h>
+#include <arpa/telnet.h>
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <poll.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#ifdef CRYPTO
+#include <tls.h>
+#else
+#define TLS_WANT_POLLIN -2
+#define TLS_WANT_POLLOUT -2
+#endif
+#include "atomicio.h"
+
+#ifdef __NetBSD__
+#define accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
+#endif
+
+#define PORT_MAX       65535
+#define UNIX_DG_TMP_SOCKET_SIZE        19
+
+#define POLL_STDIN 0
+#define POLL_NETOUT 1
+#define POLL_NETIN 2
+#define POLL_STDOUT 3
+#define BUFSIZE 16384
+#define DEFAULT_CA_FILE "/etc/ssl/cert.pem"
+
+#define TLS_ALL        (1 << 1)
+#define TLS_NOVERIFY   (1 << 2)
+#define TLS_NONAME     (1 << 3)
+#define TLS_CCERT      (1 << 4)
+#define TLS_MUSTSTAPLE (1 << 5)
+
+/* Command Line Options */
+int    dflag;                                  /* detached, no stdin */
+int    Fflag;                                  /* fdpass sock to stdout */
+unsigned int iflag;                            /* Interval Flag */
+int    kflag;                                  /* More than one connect */
+int    lflag;                                  /* Bind to local port */
+int    Nflag;                                  /* shutdown() network socket */
+int    nflag;                                  /* Don't do name look up */
+char   *Pflag;                                 /* Proxy username */
+char   *pflag;                                 /* Localport flag */
+int    rflag;                                  /* Random ports flag */
+char   *sflag;                                 /* Source Address */
+int    tflag;                                  /* Telnet Emulation */
+int    uflag;                                  /* UDP - Default to TCP */
+int    vflag;                                  /* Verbosity */
+int    xflag;                                  /* Socks proxy */
+int    zflag;                                  /* Port Scan Flag */
+int    Dflag;                                  /* sodebug */
+int    Iflag;                                  /* TCP receive buffer size */
+int    Oflag;                                  /* TCP send buffer size */
+int    Sflag;                                  /* TCP MD5 signature option */
+int    Tflag = -1;                             /* IP Type of Service */
+#ifdef __OpenBSD__
+int    rtableid = -1;
+#endif
+
+int    usetls;                                 /* use TLS */
+char    *Cflag;                                        /* Public cert file */
+char    *Kflag;                                        /* Private key file */
+char    *oflag;                                        /* OCSP stapling file */
+const char    *Rflag = DEFAULT_CA_FILE;                /* Root CA file */
+int    tls_cachanged;                          /* Using non-default CA file */
+int     TLSopt;                                        /* TLS options */
+char   *tls_expectname;                        /* required name in peer cert */
+char   *tls_expecthash;                        /* required hash of peer cert */
+
+int timeout = -1;
+int family = AF_UNSPEC;
+char *portlist[PORT_MAX+1];
+char *unix_dg_tmp_socket;
+int ttl = -1;
+int minttl = -1;
+
+void   atelnet(int, unsigned char *, unsigned int);
+void   build_ports(char *);
+static void    help(void) __dead;
+int    local_listen(char *, char *, struct addrinfo);
+struct tls;
+void   readwrite(int, struct tls *);
+void   fdpass(int nfd) __dead;
+int    remote_connect(const char *, const char *, struct addrinfo);
+int    timeout_connect(int, const struct sockaddr *, socklen_t);
+int    socks_connect(const char *, const char *, struct addrinfo,
+           const char *, const char *, struct addrinfo, int, const char *);
+int    udptest(int);
+int    unix_bind(char *, int);
+int    unix_connect(char *);
+int    unix_listen(char *);
+void   set_common_sockopts(int, int);
+int    map_tos(char *, int *);
+int    map_tls(char *, int *);
+void   report_connect(const struct sockaddr *, socklen_t, char *);
+void   report_tls(struct tls *tls_ctx, char * host, char *tlsexpectname);
+void   usage(int);
+ssize_t drainbuf(int, unsigned char *, size_t *, struct tls *);
+ssize_t fillbuf(int, unsigned char *, size_t *, struct tls *);
+void   tls_setup_client(struct tls *, int, char *);
+struct tls *tls_setup_server(struct tls *, int, char *);
+
+int
+main(int argc, char *argv[])
+{
+       int ch, s = -1, ret, socksv;
+       char *host, *uport;
+       struct addrinfo hints;
+       struct servent *sv;
+       socklen_t len;
+       struct sockaddr_storage cliaddr;
+       char *proxy = NULL, *proxyport = NULL;
+       int errnum;
+       struct addrinfo proxyhints;
+       char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
+#ifdef CRYPTO
+       struct tls_config *tls_cfg = NULL;
+       struct tls *tls_ctx = NULL;
+#endif
+
+       ret = 1;
+       socksv = 5;
+       host = NULL;
+       uport = NULL;
+       sv = NULL;
+
+       signal(SIGPIPE, SIG_IGN);
+
+       while ((ch = getopt(argc, argv,
+           "46C:cDde:FH:hI:i:K:klM:m:NnO:o:P:p:R:rSs:T:tUuV:vw:X:x:z")) != -1) {
+               switch (ch) {
+               case '4':
+                       family = AF_INET;
+                       break;
+               case '6':
+                       family = AF_INET6;
+                       break;
+               case 'U':
+                       family = AF_UNIX;
+                       break;
+               case 'X':
+                       if (strcasecmp(optarg, "connect") == 0)
+                               socksv = -1; /* HTTP proxy CONNECT */
+                       else if (strcmp(optarg, "4") == 0)
+                               socksv = 4; /* SOCKS v.4 */
+                       else if (strcmp(optarg, "5") == 0)
+                               socksv = 5; /* SOCKS v.5 */
+                       else
+                               errx(1, "unsupported proxy protocol");
+                       break;
+#ifdef CRYPTO
+               case 'C':
+                       Cflag = optarg;
+                       break;
+               case 'c':
+                       usetls = 1;
+                       break;
+#endif
+               case 'd':
+                       dflag = 1;
+                       break;
+               case 'e':
+                       tls_expectname = optarg;
+                       break;
+               case 'F':
+                       Fflag = 1;
+                       break;
+#ifdef CRYPTO
+               case 'H':
+                       tls_expecthash = optarg;
+                       break;
+#endif
+               case 'h':
+                       help();
+                       break;
+               case 'i':
+                       iflag = strtoi(optarg, NULL, 0, 0, UINT_MAX, &errnum);
+                       if (errnum)
+                               errc(1, errnum, "bad interval `%s'", optarg);
+                       break;
+#ifdef CRYPTO
+               case 'K':
+                       Kflag = optarg;
+                       break;
+#endif
+               case 'k':
+                       kflag = 1;
+                       break;
+               case 'l':
+                       lflag = 1;
+                       break;
+               case 'M':
+                       ttl = strtoi(optarg, NULL, 0, 0, 255, &errnum);
+                       if (errnum)
+                               errc(1, errnum, "bad ttl `%s'", optarg);
+                       break;
+               case 'm':
+                       minttl = strtoi(optarg, NULL, 0, 0, 255, &errnum);
+                       if (errnum)
+                               errc(1, errnum, "bad minttl `%s'", optarg);
+                       break;
+               case 'N':
+                       Nflag = 1;
+                       break;
+               case 'n':
+                       nflag = 1;
+                       break;
+               case 'P':
+                       Pflag = optarg;
+                       break;
+               case 'p':
+                       pflag = optarg;
+                       break;
+#ifdef CRYPTO
+               case 'R':
+                       tls_cachanged = 1;
+                       Rflag = optarg;
+                       break;
+#endif
+               case 'r':
+                       rflag = 1;
+                       break;
+               case 's':
+                       sflag = optarg;
+                       break;
+               case 't':
+                       tflag = 1;
+                       break;
+               case 'u':
+                       uflag = 1;
+                       break;
+#ifdef __OpenBSD__
+               case 'V':
+                       rtableid = (int)strtoi(optarg, NULL, 0, 0, 255, &errnum);
+                       if (errnum)
+                               errc(1, errnum, "bad rtable `%s'", optarg);
+                       break;
+#endif
+               case 'v':
+                       vflag = 1;
+                       break;
+               case 'w':
+                       timeout = strtoi(optarg, NULL, 0, 0, INT_MAX / 1000, &errnum);



Home | Main Index | Thread Index | Old Index