From 2f425cb9e9d28c8e7f017a4fbe1203c7431e745b Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 22 Aug 2022 00:27:47 +0200 Subject: Implement command execution --- src/rcopy.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/rcopy.c (limited to 'src/rcopy.c') diff --git a/src/rcopy.c b/src/rcopy.c new file mode 100644 index 0000000..8858f07 --- /dev/null +++ b/src/rcopy.c @@ -0,0 +1,43 @@ +#if HAVE_STDBOOL_H +#include +#endif + +#include "rexec.h" + + +#include +#include +#include + +static char *alloc_cmd(const char *restrict format, ...) { + va_list ap; + va_start(ap, format); + int len = vsnprintf(NULL, 0, format, ap); + va_end(ap); + + char *buf = malloc(len+1); + va_start(ap, format); + (void)vsnprintf(buf, len+1, format, ap); + va_end(ap); + + return buf; +} + +int sk_rcopy_file( + const char *restrict src, const char *restrict target_host, + const char *restrict dst) { + char *remote_cmd = alloc_cmd("cat >%s && chmod 0700 %s", dst, dst); + FILE *sfil = fopen(src, "r"); + + /* TODO: set correct stdout and stderr */ + int rv = sk_rexec_command( + target_host, remote_cmd, + fileno(sfil), fileno(stdout), fileno(stderr), + NULL); + + /* clean up */ + fclose(sfil); + free(remote_cmd); + + return rv; +} -- cgit v1.2.3