shithub: tlsclient

Download patch

ref: 3e18b560f030c488fd57deae9a38b67e3f388e3b
parent: 80cf8cd0acd5039d149bc86d640b1c2eca7a1f19
author: Jacob Moody <moody@posixcafe.org>
date: Sat May 22 16:27:03 EDT 2021

add -R flag to tlsclient that execs on the remote
makes more sense to put this in tlsclient then to hack it in the shell
9cpu is kept, but more as a convience

--- a/9cpu
+++ b/9cpu
@@ -30,13 +30,4 @@
 	cmd=$*
 fi
 
-len=`echo $cmd | wc -c`
-
-cmd=`cat <<EOF
-printf '%7d\n' $len;
-echo $cmd;
-cat </dev/tty 2>/dev/null &
-cat >/dev/tty 2>/dev/null;
-EOF
-`
-USER=$user AUTH=$auth CPU=$cpu tlsclient -p 17019 sh -c "$cmd"
+USER=$user AUTH=$auth CPU=$cpu tlsclient -R -p 17019 $cmd
--- a/README
+++ b/README
@@ -7,7 +7,7 @@
 Most of the tlsclient code is pillaged from jsdrawterm: https://github.com/aiju/jsdrawterm
 
 Usage:
-	tlsclient [ -u user] [ -h host ] [ -a auth ] -p port cmd...
+	tlsclient [ -R ] [ -u user] [ -h host ] [ -a auth ] -p port cmd...
 	9cpu [ -u user ] [ -h host ] [ -a auth ] cmd...
 
 Example:
--- a/cpu.c
+++ b/cpu.c
@@ -98,7 +98,7 @@
 void
 usage(void)
 {
-	fprint(2, "Usage: %s [ -u user ] [ -h host ] [ -a authserver ] -p port cmd...\n", argv0);
+	fprint(2, "Usage: %s [ -R ] [ -u user ] [ -h host ] [ -a authserver ] -p port cmd...\n", argv0);
 	exits("usage");
 }
 
@@ -105,8 +105,9 @@
 int
 main(int argc, char **argv)
 {
+	int Rflag;
 	int fd, res;
-	char *cmd;
+	char buf2[1024];
 	char buf[1024];
 	size_t n;
 	char *port;
@@ -113,9 +114,11 @@
 	int pin[2];
 	int pout[2];
 	int infd, outfd;
+	int i;
 	pid_t execc, xferc;
 
 	execc = xferc = 0;
+	Rflag = 0;
 	infd = 0;
 	outfd = 1;
 	user = getenv("USER");	
@@ -129,6 +132,7 @@
 		case 'h': host = EARGF(usage()); break;
 		case 'a': authserver = EARGF(usage()); break;
 		case 'p': port = EARGF(usage()); break;
+		case 'R': Rflag++; break;
 	} ARGEND
 
 	if(user == nil || host == nil || authserver == nil || port == nil)
@@ -143,7 +147,7 @@
 		sysfatal("could not init session");
 	}
 
-	if(*argv){
+	if(*argv && !Rflag){
 		pipe(pin);
 		pipe(pout);
 		switch((execc = fork())){
@@ -169,6 +173,19 @@
 	}
 
 	p9authtls(fd);
+
+	if(*argv && Rflag) {
+		for(i=0,n=0; i<argc; i++)
+			n += snprint(buf+n, sizeof buf - n - 1, "%s ", argv[i]);
+		if(n <= 0)
+			usage();
+		buf[n-1] = '\n';
+		buf[n] = '\0';
+		i = strlen(buf);
+		snprint(buf2, sizeof buf2, "%7d\n", i);
+		tls_send(-1, buf2, strlen(buf2));
+		tls_send(-1, buf, i);
+	}
 
 	switch((xferc = fork())){
 	case -1: