commit - acd6bef3a2ac2c8ce5c818aebd85161f0c869f66
commit + ce3844d20b6390e0ea417bb6c4c3e40f8b75a591
blob - 0a4a442d43a5adc8e65f30ace93df6f9c25dd542
blob + d66373e2c39f38c9784d99526c519fbd3bae5a86
--- .gitignore
+++ .gitignore
kamid
kamictl
+kamiftp
kamirepl
*.o
kamid.conf
blob - 097c562ad77d72934c740dd24b20579939287bce
blob + 23d2f77125ced804fc7d4d7159d2ff6ebd1464fb
--- Makefile.am
+++ Makefile.am
-bin_PROGRAMS = kamictl kamid
+bin_PROGRAMS = kamictl kamid kamiftp
check_PROGRAMS = ninepscript
noinst_PROGRAMS = kamirepl
AM_CFLAGS = @AM_CFLAGS@
LDADD = $(LIBOBJS)
+kamiftp_LDFLAGS = @KAMIFTP_LIBS@
+
BUILT_SOURCES = compile_flags.txt
CLEANFILES = compile_flags.txt
dist_doc_DATA = README.md LICENSE
+dist_man1_MANS = kamiftp.1
dist_man5_MANS = kamid.conf.5
dist_man7_MANS = 9p.7
dist_man8_MANS = kamictl.8 kamid.8
blob - a52a8d80549a86af6121dffe6854e1beb6d8ec75
blob + 59fec4c0abfa887c81a880e6de646b4176ab5c4e
--- configure.ac
+++ configure.ac
AC_MSG_ERROR([requires libtls])
])
+# small hack to avoid linking *everything* to readline.
+libs_orig="${LIBS}"
+AC_CHECK_LIB(readline, readline, [], [
+ AC_MSG_ERROR([requires readline])
+])
+KAMIFTP_LIBS="${LIBS}"
+LIBS="${libs_orig}"
+AC_SUBST([KAMIFTP_LIBS])
+
AS_CASE([$host_os],
[*openbsd*], [AC_CHECK_LIB([event], [event_init], [],
[AC_MSG_ERROR([requires libevent])])],
blob - /dev/null
blob + 129010356d8a295c8cf9db62edd696b4cc0fdecc (mode 644)
--- /dev/null
+++ ftp.c
+/*
+ * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+ *
+ * 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 "compat.h"
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netdb.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <tls.h>
+#include <unistd.h>
+
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#include "9pclib.h"
+#include "kamid.h"
+#include "utils.h"
+#include "log.h"
+
+/* flags */
+int tls;
+const char *crtpath;
+const char *keypath;
+
+/* state */
+struct tls_config *tlsconf;
+struct tls *ctx;
+int sock;
+
+#define PWDFID 0
+
+static void ATTR_DEAD
+usage(int ret)
+{
+ fprintf(stderr, "usage: %s [-c] host[:port] [path]\n",
+ getprogname());
+ fprintf(stderr, PACKAGE_NAME " suite version " PACKAGE VERSION "\n");
+ exit(ret);
+}
+
+static void
+do_version(void)
+{
+ tversion(VERSION9P, MSIZE9P);
+ /* TODO: get reply */
+}
+
+static void
+do_attach(const char *path)
+{
+ if (path == NULL)
+ path = "/";
+
+ /* TODO: do attach */
+}
+
+static void
+do_connect(const char *connspec, const char *path)
+{
+ int handshake;
+ char *host, *colon;
+ const char *port;
+
+ host = xstrdup(connspec);
+ if ((colon = strchr(host, ':')) != NULL) {
+ *colon = '\0';
+ port = ++colon;
+ } else
+ port = "1337";
+
+ if (!tls)
+ fatalx("non-tls mode is not supported");
+
+ if ((tlsconf = tls_config_new()) == NULL)
+ fatalx("tls_config_new");
+ tls_config_insecure_noverifycert(tlsconf);
+ tls_config_insecure_noverifyname(tlsconf);
+ if (tls_config_set_keypair_file(tlsconf, crtpath, keypath) == -1)
+ fatalx("can't load certs (%s, %s)", crtpath, keypath);
+
+ if ((ctx = tls_client()) == NULL)
+ fatal("tls_client");
+ if (tls_configure(ctx, tlsconf) == -1)
+ fatalx("tls_configure: %s", tls_error(ctx));
+
+ printf("connecting to %s:%s...", host, port);
+ fflush(stdout);
+
+ if (tls_connect(ctx, host, port) == -1)
+ fatalx("can't connect to %s:%s: %s", host, port,
+ tls_error(ctx));
+
+ for (handshake = 0; !handshake;) {
+ switch (tls_handshake(ctx)) {
+ case -1:
+ fatalx("tls_handshake: %s", tls_error(ctx));
+ case 0:
+ handshake = 1;
+ break;
+ }
+ }
+
+ printf(" done!\n");
+
+ do_version();
+ do_attach(path);
+
+ free(host);
+}
+
+int
+main(int argc, char **argv)
+{
+ int ch;
+
+ log_init(1, LOG_DAEMON);
+ log_setverbose(1);
+ log_procinit(getprogname());
+
+ while ((ch = getopt(argc, argv, "C:cK:")) != -1) {
+ switch (ch) {
+ case 'C':
+ crtpath = optarg;
+ break;
+ case 'c':
+ tls = 1;
+ break;
+ case 'K':
+ keypath = optarg;
+ break;
+ default:
+ usage(1);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ usage(1);
+
+ if ((evb = evbuffer_new()) == NULL)
+ fatal("evbuffer_new");
+
+ do_connect(argv[0], argv[1]);
+
+ for (;;) {
+ char *line;
+
+ if ((line = readline("ftp> ")) == NULL)
+ break;
+ /* XXX: trim spaces */
+ if (*line == '\0')
+ continue;
+ add_history(line);
+ }
+
+ printf("\n");
+}
blob - /dev/null
blob + 1b88cb698ca30ff9bb277d2af0697b6fa3075734 (mode 644)
--- /dev/null
+++ kamiftp.1
+.\" Copyright (c) 2021 Omar Polo <op@omarpolo.com>
+.\"
+.\" 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: December 14 2021 $
+.Dt KAMIFTP 1
+.Os
+.Sh NAME
+.Nm kamiftp
+.Nd 9p client
+.Sh SYNOPSIS
+.Nm
+.Op Fl c
+.Op Fl C Ar cert
+.Op Fl K Ar key
+.Ar host Op Ar path
+.Sh DESCRIPTION
+.Nm
+is a
+.Xr 9p 7
+client.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl c
+Use TLS for the connection.
+.Fl K
+and
+.Fl C
+are mandatory if
+.Fl c
+is used.
+.It Fl C Ar certificate
+Specify the path to the client
+.Ar certificate
+to be use during the TLS handsahke.
+.It Fl K Ar key
+Specify the path to the client certificate
+.Ar key
+to be used during the TLS handshake.
+.El
+.Sh SEE ALSO
+.Xr 9p 7
+.Xr kamid 8
+.Sh AUTHORS
+The
+.Nm
+utility was written by
+.An Omar Polo Aq Mt op@omarpolo.com .