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>
32 #include <readline/readline.h>
33 #include <readline/history.h>
47 struct tls_config *tlsconf;
55 read_line(const char *prompt)
60 if ((line = readline(prompt)) == NULL)
62 /* XXX: trim spaces? */
73 read_line(const char *prompt)
75 char *ch, *line = NULL;
79 linelen = getline(&line, &linesize, stdin);
83 if ((ch = strchr(line, '\n')) != NULL)
92 fprintf(stderr, "usage: %s [-c] host[:port] [path]\n",
94 fprintf(stderr, PACKAGE_NAME " suite version " PACKAGE VERSION "\n");
101 tversion(VERSION9P, MSIZE9P);
102 /* TODO: get reply */
106 do_attach(const char *path)
111 /* TODO: do attach */
115 do_connect(const char *connspec, const char *path)
121 host = xstrdup(connspec);
122 if ((colon = strchr(host, ':')) != NULL) {
129 fatalx("non-tls mode is not supported");
131 if ((tlsconf = tls_config_new()) == NULL)
132 fatalx("tls_config_new");
133 tls_config_insecure_noverifycert(tlsconf);
134 tls_config_insecure_noverifyname(tlsconf);
135 if (tls_config_set_keypair_file(tlsconf, crtpath, keypath) == -1)
136 fatalx("can't load certs (%s, %s)", crtpath, keypath);
138 if ((ctx = tls_client()) == NULL)
140 if (tls_configure(ctx, tlsconf) == -1)
141 fatalx("tls_configure: %s", tls_error(ctx));
143 printf("connecting to %s:%s...", host, port);
146 if (tls_connect(ctx, host, port) == -1)
147 fatalx("can't connect to %s:%s: %s", host, port,
150 for (handshake = 0; !handshake;) {
151 switch (tls_handshake(ctx)) {
153 fatalx("tls_handshake: %s", tls_error(ctx));
169 main(int argc, char **argv)
173 log_init(1, LOG_DAEMON);
175 log_procinit(getprogname());
177 while ((ch = getopt(argc, argv, "C:cK:")) != -1) {
198 if ((evb = evbuffer_new()) == NULL)
199 fatal("evbuffer_new");
201 do_connect(argv[0], argv[1]);
206 if ((line = read_line("ftp> ")) == NULL)
208 printf("read: %s\n", line);