changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/rconnect

changeset 5096: 65abc13ef7a1
child: c392f6b2122c
author: cinap_lenrek@felloff.net
date: Sun, 14 Feb 2016 05:18:33 +0100
permissions: -rwxr-xr-x
description: adding experimental rcpu service

this is a reimplementation of cpu and import utilities in rc using a tlsclient
and tlssrv as the encryption and authentication layers. there is only one new
service, which after authentication and encryption setup accepts an arbitrary
rc script over the network and executes it with the standard filedescriptors
redirected to the conversaion (this is *after* authentication and in the
context of the authorized user).

the new rcpu program has a few improvements over cpu(1):

- doesnt mangle program arguments
- the remote process will get the clients standard file descriptors, so error
and output are separated and you can consume the clients input from the
remote side :-)
- forwards error status of remote process

theres no backwards mode for rimport, but a new program called rexport
for the same purpose.

all these services use exportfs without the bolted on initial handshake,
so the hope is to clean up exportfs in the future and remove all the ugly
crap in there.
1 #!/bin/rc
2 rfork e
3 
4 argv0=$0
5 fn usage {
6  echo 'usage:' $argv0 '[-p] [-u user] [-k keyspec] host remotescript localcommand ...' >[1=2]
7  exit 'usage'
8 }
9 
10 fn pvar {
11  while(! ~ $#* 0){
12  ~ $#$1 0 || path=/dev/null builtin whatis $1
13  shift
14  }
15 }
16 
17 filter=()
18 keyspec=()
19 while(~ $1 -*){
20  switch($1){
21  case -p; filter=aan
22  case *
23  ~ $#* 1 && usage
24  switch($1){
25  case -k; keyspec=($keyspec $2)
26  case -u; keyspec=($keyspec `{user=$2 pvar user})
27  case *; usage
28  }
29  shift
30  }
31  shift
32 }
33 
34 ~ $#* 0 1 2 && usage
35 
36 host=$1
37 shift
38 
39 fn sendscript {
40  echo -n $host >/proc/$pid/args
41  cat $1 >/env/v; wc -c </env/v; cat /env/v; rm /env/v
42  shift
43  $*
44 }
45 
46 if(~ $filter aan){
47  fn aanserver {
48  ~ $#netdir 1 || netdir=/net/tcp/clone
49  netdir=`{basename -d $netdir} || exit
50  <>$netdir/clone {
51  netdir=$netdir/`{read} || exit
52  >[3] $netdir/ctl {
53  echo -n 'announce *!0' >[1=3]
54  echo `{cat $netdir/local} || exit
55  bind '#|' /mnt/aan || exit
56  exec aan $netdir <>/mnt/aan/data1 >[1=0] >[2]/dev/null &
57  }
58  }
59  <>/mnt/aan/data >[1=0] >[2]/dev/null {
60  rfork n
61  fn server {
62  echo -n aanserver $netdir >/proc/$pid/args
63  . <{n=`{read} && ! ~ $#n 0 && read -c $n} >[2=1]
64  }
65  rm -f /env/^'fn#aanserver'
66  exec tlssrv -A /bin/rc -c server
67  exit
68  }
69  }
70  fn aanclient {
71  host=`{echo $host | sed 's/(.*)!([^!]+)$/\1/'}^!^`{read | sed 's/(.*)!([^!]+)$/\2/'} || exit
72  tlsclient -a -o <>{rfork s; aan -c $host >[1=0]} /bin/rc -c 'sendscript $*' $*
73  }
74  exec $argv0 -k $"keyspec $host <{builtin whatis aanserver; echo aanserver} aanclient $*
75  exit
76 }
77 
78 switch($host){
79 case *!*!*;
80 case *!*; host=$host!rcpu
81 case *; host=net!$host!rcpu
82 }
83 
84 exec tlsclient -ak $"keyspec $host /bin/rc -c 'sendscript $*' $*