With the -9 flag, we can run drawterm on a remote system over ssh, and have it export the remotes namespace. Thru the /cmd interface (see os(1)), one can launch native programs on the remote host and access the remote file system.
Unified · Split
| @@ -27,6 +27,7 @@ static int aanto = 3600 * 24; · 26 unmodified lines | |||
| 27 | static int norcpu; | 27 | static int norcpu; |
| 28 | static int nokbd; | 28 | static int nokbd; |
| 29 | static int nogfx; | 29 | static int nogfx; |
| 30 | static int nineflag; | ||
| 30 | 31 | ||
| 31 | static char *ealgs = "rc4_256 sha1"; | 32 | static char *ealgs = "rc4_256 sha1"; |
| 32 | 33 | ||
| @@ -176,7 +177,7 @@ rcpu(char *host, char *cmd) · 143 unmodified lines | |||
| 176 | atexit(rcpuexit); | 177 | atexit(rcpuexit); |
| 177 | 178 | ||
| 178 | /* Begin serving the namespace */ | 179 | /* Begin serving the namespace */ |
| 179 | exportfs(fd); | 180 | exportfs(fd, fd); |
| 180 | } | 181 | } |
| 181 | 182 | ||
| 182 | void | 183 | void |
| @@ -236,13 +237,13 @@ ncpu(char *host, char *cmd) · 53 unmodified lines | |||
| 236 | write(fd, "OK", 2); | 237 | write(fd, "OK", 2); |
| 237 | 238 | ||
| 238 | /* Begin serving the gnot namespace */ | 239 | /* Begin serving the gnot namespace */ |
| 239 | exportfs(fd); | 240 | exportfs(fd, fd); |
| 240 | } | 241 | } |
| 241 | 242 | ||
| 242 | void | 243 | void |
| 243 | usage(void) | 244 | usage(void) |
| 244 | { | 245 | { |
| 245 | fprint(2, "usage: %s [-GBO] " | 246 | fprint(2, "usage: %s [-9GBO] " |
| 246 | "[-h host] [-u user] [-a authserver] [-s secstore] " | 247 | "[-h host] [-u user] [-a authserver] [-s secstore] " |
| 247 | "[-e 'crypt hash'] [-k keypattern] " | 248 | "[-e 'crypt hash'] [-k keypattern] " |
| 248 | "[-p] [-t timeout] " | 249 | "[-p] [-t timeout] " |
| @@ -262,12 +263,13 @@ cpumain(int argc, char **argv) · 13 unmodified lines | |||
| 262 | char *s; | 263 | char *s; |
| 263 | 264 | ||
| 264 | user = getenv("USER"); | 265 | user = getenv("USER"); |
| 265 | if((pass = getenv("PASS")) != nil) | ||
| 266 | remove("/env/PASS"); | ||
| 267 | host = getenv("cpu"); | 266 | host = getenv("cpu"); |
| 268 | authserver = getenv("auth"); | 267 | authserver = getenv("auth"); |
| 269 | 268 | ||
| 270 | ARGBEGIN{ | 269 | ARGBEGIN{ |
| 270 | case '9': | ||
| 271 | nineflag = 1; | ||
| 272 | /* wet floor */ | ||
| 271 | case 'G': | 273 | case 'G': |
| 272 | nogfx = 1; | 274 | nogfx = 1; |
| 273 | /* wet floor */ | 275 | /* wet floor */ |
| @@ -320,8 +322,8 @@ cpumain(int argc, char **argv) · 46 unmodified lines | |||
| 320 | break; | 322 | break; |
| 321 | case 'g': | 323 | case 'g': |
| 322 | /* X11 geometry string | 324 | /* X11 geometry string |
| 323 | [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>] | 325 | * [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>] |
| 324 | */ | 326 | */ |
| 325 | geometry = EARGF(usage()); | 327 | geometry = EARGF(usage()); |
| 326 | break; | 328 | break; |
| 327 | default: | 329 | default: |
| @@ -331,6 +333,14 @@ cpumain(int argc, char **argv) · 3 unmodified lines | |||
| 331 | if(argc != 0) | 333 | if(argc != 0) |
| 332 | usage(); | 334 | usage(); |
| 333 | 335 | ||
| 336 | if(nineflag){ | ||
| 337 | exportfs(lfdfd(0), lfdfd(1)); | ||
| 338 | return; | ||
| 339 | } | ||
| 340 | |||
| 341 | if((pass = getenv("PASS")) != nil) | ||
| 342 | remove("/env/PASS"); | ||
| 343 | |||
| 334 | if(!nogfx) | 344 | if(!nogfx) |
| 335 | guimain(); | 345 | guimain(); |
| 336 | else | 346 | else |
| @@ -6,7 +6,7 @@ drawterm \- connection to cpu, fs, and auth servers · 5 unmodified lines | |||
| 6 | .SH SYNOPSIS | 6 | .SH SYNOPSIS |
| 7 | .B drawterm | 7 | .B drawterm |
| 8 | [ | 8 | [ |
| 9 | .B -GBO | 9 | .B -9GBO |
| 10 | ] [ | 10 | ] [ |
| 11 | .B -h | 11 | .B -h |
| 12 | .I host | 12 | .I host |
| @@ -50,6 +50,12 @@ The goal of drawterm is to provide an abstraction layer from the client operatin · 37 unmodified lines | |||
| 50 | The options are: | 50 | The options are: |
| 51 | .PD | 51 | .PD |
| 52 | 52 | ||
| 53 | .TP | ||
| 54 | .B -9 | ||
| 55 | Start drawterm in 9P mode; | ||
| 56 | exporting the namespace over 9P on standard input and output. | ||
| 57 | Graphics and keyboard input are disabled. | ||
| 58 | |||
| 53 | .TP | 59 | .TP |
| 54 | .B -G | 60 | .B -G |
| 55 | Start drawterm in text-only mode (no graphics). | 61 | Start drawterm in text-only mode (no graphics). |
| @@ -2,7 +2,7 @@ extern int havesecstore(char *addr, char *owner); · 1 unmodified line | |||
| 2 | extern char *secstore; | 2 | extern char *secstore; |
| 3 | extern char *secstorefetch(char *addr, char *owner, char *passwd); | 3 | extern char *secstorefetch(char *addr, char *owner, char *passwd); |
| 4 | extern char *authserver; | 4 | extern char *authserver; |
| 5 | extern int exportfs(int); | 5 | extern int exportfs(int, int); |
| 6 | extern int dialfactotum(void); | 6 | extern int dialfactotum(void); |
| 7 | extern char *getuser(void); | 7 | extern char *getuser(void); |
| 8 | extern void cpumain(int, char**); | 8 | extern void cpumain(int, char**); |
| @@ -9,7 +9,6 @@ · 8 unmodified lines | |||
| 9 | #define Extern | 9 | #define Extern |
| 10 | #include "exportfs.h" | 10 | #include "exportfs.h" |
| 11 | 11 | ||
| 12 | /* #define QIDPATH ((1LL<<48)-1) */ | ||
| 13 | #define QIDPATH ((((vlong)1)<<48)-1) | 12 | #define QIDPATH ((((vlong)1)<<48)-1) |
| 14 | vlong newqid = 0; | 13 | vlong newqid = 0; |
| 15 | 14 | ||
| @@ -21,15 +20,16 @@ int freecnt; · 5 unmodified lines | |||
| 21 | int qidcnt; | 20 | int qidcnt; |
| 22 | int qfreecnt; | 21 | int qfreecnt; |
| 23 | int ncollision; | 22 | int ncollision; |
| 24 | int netfd; | 23 | int netfd[2]; |
| 25 | 24 | ||
| 26 | int | 25 | int |
| 27 | exportfs(int fd) | 26 | exportfs(int rfd, int wfd) |
| 28 | { | 27 | { |
| 29 | char buf[ERRMAX], ebuf[ERRMAX]; | 28 | char buf[ERRMAX], ebuf[ERRMAX]; |
| 30 | Fsrpc *r; | 29 | Fsrpc *r; |
| 31 | int i, n; | 30 | int i, n; |
| 32 | 31 | ||
| 32 | |||
| 33 | fcalls[Tversion] = Xversion; | 33 | fcalls[Tversion] = Xversion; |
| 34 | fcalls[Tauth] = Xauth; | 34 | fcalls[Tauth] = Xauth; |
| 35 | fcalls[Tflush] = Xflush; | 35 | fcalls[Tflush] = Xflush; |
| @@ -45,22 +45,18 @@ exportfs(int fd) · 9 unmodified lines | |||
| 45 | fcalls[Twstat] = Xwstat; | 45 | fcalls[Twstat] = Xwstat; |
| 46 | 46 | ||
| 47 | srvfd = -1; | 47 | srvfd = -1; |
| 48 | netfd = fd; | 48 | netfd[0] = rfd; |
| 49 | //dbg = 1; | 49 | netfd[1] = wfd; |
| 50 | 50 | ||
| 51 | strcpy(buf, "this is buf"); | 51 | strcpy(buf, "this is buf"); |
| 52 | strcpy(ebuf, "this is ebuf"); | 52 | strcpy(ebuf, "this is ebuf"); |
| 53 | DEBUG(DFD, "exportfs: started\n"); | 53 | DEBUG(DFD, "exportfs: started\n"); |
| 54 | 54 | ||
| 55 | // rfork(RFNOTEG); | 55 | messagesize = iounit(rfd); |
| 56 | |||
| 57 | messagesize = iounit(netfd); | ||
| 58 | if(messagesize == 0) | 56 | if(messagesize == 0) |
| 59 | messagesize = IOUNIT+IOHDRSZ; | 57 | messagesize = IOUNIT+IOHDRSZ; |
| 60 | 58 | ||
| 61 | Workq = emallocz(sizeof(Fsrpc)*Nr_workbufs); | 59 | Workq = emallocz(sizeof(Fsrpc)*Nr_workbufs); |
| 62 | // for(i=0; i<Nr_workbufs; i++) | ||
| 63 | // Workq[i].buf = emallocz(messagesize); | ||
| 64 | fhash = emallocz(sizeof(Fid*)*FHASHSIZE); | 60 | fhash = emallocz(sizeof(Fid*)*FHASHSIZE); |
| 65 | 61 | ||
| 66 | fmtinstall('F', fcallfmt); | 62 | fmtinstall('F', fcallfmt); |
| @@ -78,7 +74,7 @@ exportfs(int fd) · 11 unmodified lines | |||
| 78 | fatal("Out of service buffers"); | 74 | fatal("Out of service buffers"); |
| 79 | 75 | ||
| 80 | DEBUG(DFD, "read9p..."); | 76 | DEBUG(DFD, "read9p..."); |
| 81 | n = read9pmsg(netfd, r->buf, messagesize); | 77 | n = read9pmsg(netfd[0], r->buf, messagesize); |
| 82 | if(n <= 0) | 78 | if(n <= 0) |
| 83 | fatal(nil); | 79 | fatal(nil); |
| 84 | 80 | ||
| @@ -122,7 +118,7 @@ if(0) iprint("-> %F\n", t); · 37 unmodified lines | |||
| 122 | if(data == nil) | 118 | if(data == nil) |
| 123 | fatal(Enomem); | 119 | fatal(Enomem); |
| 124 | n = convS2M(t, data, messagesize); | 120 | n = convS2M(t, data, messagesize); |
| 125 | if((m=write(netfd, data, n))!=n){ | 121 | if((m=write(netfd[1], data, n))!=n){ |
| 126 | iprint("wrote %d got %d (%r)\n", n, m); | 122 | iprint("wrote %d got %d (%r)\n", n, m); |
| 127 | fatal("write"); | 123 | fatal("write"); |
| 128 | } | 124 | } |
| @@ -15,7 +15,7 @@ char Enomem[] = "No memory"; · 14 unmodified lines | |||
| 15 | char Eversion[] = "Bad 9P2000 version"; | 15 | char Eversion[] = "Bad 9P2000 version"; |
| 16 | 16 | ||
| 17 | void* | 17 | void* |
| 18 | emallocz(ulong n) | 18 | emallocz(uint n) |
| 19 | { | 19 | { |
| 20 | void *v; | 20 | void *v; |
| 21 | 21 | ||
| @@ -23,6 +23,26 @@ lfdchan(void *fd) · 22 unmodified lines | |||
| 23 | return c; | 23 | return c; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | /* | ||
| 27 | * only good for stdin/stdout/stderr | ||
| 28 | */ | ||
| 29 | int | ||
| 30 | lfdfd(int fd) | ||
| 31 | { | ||
| 32 | HANDLE h; | ||
| 33 | |||
| 34 | switch(fd){ | ||
| 35 | case 0: h = GetStdHandle(STD_INPUT_HANDLE); break; | ||
| 36 | case 1: h = GetStdHandle(STD_OUTPUT_HANDLE); break; | ||
| 37 | case 2: h = GetStdHandle(STD_ERROR_HANDLE); break; | ||
| 38 | default: | ||
| 39 | return -1; | ||
| 40 | } | ||
| 41 | if(h == INVALID_HANDLE_VALUE) | ||
| 42 | return -1; | ||
| 43 | return newfd(lfdchan((void*)h)); | ||
| 44 | } | ||
| 45 | |||
| 26 | static Chan* | 46 | static Chan* |
| 27 | lfdattach(char *x) | 47 | lfdattach(char *x) |
| 28 | { | 48 | { |