2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
20 #include <sys/socket.h>
31 #include <readline/readline.h>
32 #include <readline/history.h>
45 struct tls_config *tlsconf;
54 fprintf(stderr, "usage: %s [-c] host[:port] [path]\n",
56 fprintf(stderr, PACKAGE_NAME " suite version " PACKAGE VERSION "\n");
63 tversion(VERSION9P, MSIZE9P);
68 do_attach(const char *path)
77 do_connect(const char *connspec, const char *path)
83 host = xstrdup(connspec);
84 if ((colon = strchr(host, ':')) != NULL) {
91 fatalx("non-tls mode is not supported");
93 if ((tlsconf = tls_config_new()) == NULL)
94 fatalx("tls_config_new");
95 tls_config_insecure_noverifycert(tlsconf);
96 tls_config_insecure_noverifyname(tlsconf);
97 if (tls_config_set_keypair_file(tlsconf, crtpath, keypath) == -1)
98 fatalx("can't load certs (%s, %s)", crtpath, keypath);
100 if ((ctx = tls_client()) == NULL)
102 if (tls_configure(ctx, tlsconf) == -1)
103 fatalx("tls_configure: %s", tls_error(ctx));
105 printf("connecting to %s:%s...", host, port);
108 if (tls_connect(ctx, host, port) == -1)
109 fatalx("can't connect to %s:%s: %s", host, port,
112 for (handshake = 0; !handshake;) {
113 switch (tls_handshake(ctx)) {
115 fatalx("tls_handshake: %s", tls_error(ctx));
131 main(int argc, char **argv)
135 log_init(1, LOG_DAEMON);
137 log_procinit(getprogname());
139 while ((ch = getopt(argc, argv, "C:cK:")) != -1) {
160 if ((evb = evbuffer_new()) == NULL)
161 fatal("evbuffer_new");
163 do_connect(argv[0], argv[1]);
168 if ((line = readline("ftp> ")) == NULL)
170 /* XXX: trim spaces */