changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: rx: rcpu service support

changeset 5097: 7235a8f6c8a5
parent 5096: 65abc13ef7a1
child 5098: af29fcb06bf2
author: cinap_lenrek@felloff.net
date: Sun, 14 Feb 2016 05:37:55 +0100
files: sys/src/cmd/rx.c
description: rx: rcpu service support
     1.1--- a/sys/src/cmd/rx.c
     1.2+++ b/sys/src/cmd/rx.c
     1.3@@ -1,6 +1,7 @@
     1.4 #include <u.h>
     1.5 #include <libc.h>
     1.6 #include <auth.h>
     1.7+#include <libsec.h>
     1.8 
     1.9 int	eof;		/* send an eof if true */
    1.10 int	crtonl;		/* convert all received \r to \n */
    1.11@@ -9,7 +10,8 @@ char	*note = "die: yankee dog";
    1.12 char	*ruser;		/* for BSD authentication */
    1.13 char *key;
    1.14 
    1.15-void	rex(int, char*, char*);
    1.16+void	rex(int, char*);
    1.17+void	rcpu(int, char*);
    1.18 void	tcpexec(int, char*, char*);
    1.19 int	call(char *, char*, char*, char**);
    1.20 char	*buildargs(char*[]);
    1.21@@ -30,6 +32,8 @@ main(int argc, char *argv[])
    1.22 	char *host, *addr, *args;
    1.23 	int fd;
    1.24 
    1.25+	quotefmtinstall();
    1.26+
    1.27 	key = "";
    1.28 	eof = 1;
    1.29 	crtonl = 0;
    1.30@@ -59,9 +63,12 @@ main(int argc, char *argv[])
    1.31 	host = argv[0];
    1.32 	args = buildargs(&argv[1]);
    1.33 
    1.34+	fd = call(0, host, "rcpu", &addr);
    1.35+	if(fd >= 0)
    1.36+		rcpu(fd, args);
    1.37 	fd = call(0, host, "rexexec", &addr);
    1.38 	if(fd >= 0)
    1.39-		rex(fd, args, "p9any");
    1.40+		rex(fd, args);
    1.41 	close(fd);
    1.42 
    1.43 	/* if there's an ssh port, try that */
    1.44@@ -89,18 +96,53 @@ call(char *net, char *host, char *servic
    1.45 }
    1.46 
    1.47 void
    1.48-rex(int fd, char *cmd, char *proto)
    1.49+rcpu(int fd, char *cmd)
    1.50+{
    1.51+	char buf[4096];
    1.52+	int kid, n;
    1.53+	TLSconn *conn;
    1.54+	AuthInfo *ai;
    1.55+
    1.56+	ai = auth_proxy(fd, auth_getkey, "proto=p9any role=client %s", key);
    1.57+	if(ai == nil)
    1.58+		error("auth_proxy", nil);
    1.59+
    1.60+	conn = (TLSconn*)mallocz(sizeof *conn, 1);
    1.61+	conn->pskID = "p9secret";
    1.62+	conn->psk = ai->secret;
    1.63+	conn->psklen = ai->nsecret;
    1.64+	fd = tlsClient(fd, conn);
    1.65+	if(fd < 0)
    1.66+		error("tlsClient", nil);
    1.67+
    1.68+	auth_freeAI(ai);
    1.69+
    1.70+	cmd = smprint("service=rx exec rc -lc %q\n", cmd);
    1.71+	if(fprint(fd, "%7ld\n%s", strlen(cmd), cmd) < 0)
    1.72+		error("write", nil);
    1.73+	free(cmd);
    1.74+	
    1.75+	kid = send(fd);
    1.76+	while((n=read(fd, buf, sizeof buf))>0)
    1.77+		if(write(1, buf, n)!=n)
    1.78+			error("write error", 0);
    1.79+	sleep(250);
    1.80+	postnote(PNPROC, kid, note);/**/
    1.81+	exits(0);
    1.82+}
    1.83+
    1.84+void
    1.85+rex(int fd, char *cmd)
    1.86 {
    1.87 	char buf[4096];
    1.88 	int kid, n;
    1.89 	AuthInfo *ai;
    1.90 
    1.91-	ai = auth_proxy(fd, auth_getkey, "proto=%s role=client %s", proto, key);
    1.92-	if(ai == nil){
    1.93-		if(strcmp(proto, "p9any") == 0)
    1.94-			return;
    1.95+	ai = auth_proxy(fd, auth_getkey, "proto=p9any role=client %s", key);
    1.96+	if(ai == nil)
    1.97 		error("auth_proxy", nil);
    1.98-	}
    1.99+	auth_freeAI(ai);
   1.100+
   1.101 	write(fd, cmd, strlen(cmd)+1);
   1.102 
   1.103 	kid = send(fd);
   1.104@@ -222,7 +264,7 @@ send(int fd)
   1.105 void
   1.106 error(char *s, char *z)
   1.107 {
   1.108-	if(z == 0)
   1.109+	if(z == nil)
   1.110 		fprint(2, "%s: %s: %r\n", argv0, s);
   1.111 	else
   1.112 		fprint(2, "%s: %s %s: %r\n", argv0, s, z);