This patch adds a -z flag to import(4) to match the behavior of exportfs(4) for exports made with the -r or -S flag, which bypass the tree negotiation part of the protocol. This solves a conflict between exportfs(4) flags. Currently, if an exportfs listener is using the -a flag for authentication, the -r and -S flags to specify a subtree or service become unusable although no error condition is reported. It is desirable to enable a command like this to work as intended: aux/listen1 tcp!*!port /bin/exportfs -a -r /usr/me/pubauth and similarly with authenticated listeners for exportfs -S service mounts. The suggested patch is completely minimal and non-invasive. It adds a -z flag for import(4) to exist in symmetry with the -r and -S flags to exportfs(4). Import(4) is the intended client for exportfs(4) so the option of skipping tree negotiation should be present for import(4) as well. This patch does not change any existing behaviors or currently documented functions. It simply makes import(4) function correctly in combination with an exportfs(4) using -a in combination with -r or -S. This patch does not affect the function of "backwards" mode and requires no new logic other than a single if statement and controlling flag. The ability to create authenticated public exportfs(4) listeners for a given -r subtree or -S service is useful and seems entirely consistent with the intended functions of import/export. Currently, non-authenticated -r or -S exports can be attached with srv(4) and mount(1) (or used in backwards mode) but adding the -a option makes them unmountable when acting as public listeners, unless this patch is used. Included are manpage adjustments for both import(4) and exportfs(4) to explain the use of the new -z flag to import, as well as a few additional examples of import usage. The changes in exportfs(4) man page explain the use of import, there is no changed code or behavior in exportfs. TESTING NOTES: Current behavior: server: aux/listen1 tcp!*!port /bin/exportfs -a -r /some/path client attempts: import tcp!server!port /some/path /n/path import: bad remote tree: can't read tree import tcp!server!port / /n/path (waits and does nothing) srv tcp!server!port remote /n/remote srv tcp!server!port: mount failed: bad fversion conversion on reply Behavior with import -z: server (same as above): aux/listen1 tcp!*!port /bin/exportfs -a -r /some/path client: import -z tcp!server!port anything /mount/point ls /mount/point And we have a mounted fs assuming we had the right key in our factotum(4). It should be noted that with this modification, import -A -z will mount non-authenticated exportfs -r and -S services in the manner of a srv and mount sequence. Notes: Fri Aug 2 17:46:03 EDT 2013 geoff declined in favour of the import-m patch Reference: /n/sources/patch/sorry/import-z Date: Wed Feb 27 11:52:08 CET 2013 Signed-off-by: mycroftiv@sphericalharmony.com Reviewed-by: geoff --- /sys/src/cmd/import.c Tue Feb 26 02:57:29 2013 +++ /sys/src/cmd/import.c Tue Feb 26 02:57:27 2013 @@ -25,6 +25,7 @@ int debug; int doauth = 1; int timedout; +int skiptree; int connect(char*, char*, int); int passive(void); @@ -34,6 +35,7 @@ void usage(void); int filter(int, char *, char *); + static void mksecret(char *, uchar *); /* @@ -145,6 +147,9 @@ case 'B': backwards = 1; break; + case 'z': + skiptree = 1; + break; default: usage(); }ARGEND; @@ -312,20 +317,22 @@ sysfatal("%r: %s", system); } - procsetname("writing tree name %s", tree); - n = write(fd, tree, strlen(tree)); - if(n < 0) - sysfatal("can't write tree: %r"); - - strcpy(buf, "can't read tree"); - - procsetname("awaiting OK for %s", tree); - n = read(fd, buf, sizeof buf - 1); - if(n!=2 || buf[0]!='O' || buf[1]!='K'){ - if (timedout) - sysfatal("timed out connecting to %s", na); - buf[sizeof buf - 1] = '\0'; - sysfatal("bad remote tree: %s", buf); + if(!skiptree){ + procsetname("writing tree name %s", tree); + n = write(fd, tree, strlen(tree)); + if(n < 0) + sysfatal("can't write tree: %r"); + + strcpy(buf, "can't read tree"); + + procsetname("awaiting OK for %s", tree); + n = read(fd, buf, sizeof buf - 1); + if(n!=2 || buf[0]!='O' || buf[1]!='K'){ + if (timedout) + sysfatal("timed out connecting to %s", na); + buf[sizeof buf - 1] = '\0'; + sysfatal("bad remote tree: %s", buf); + } } if(oldserver) @@ -363,7 +370,7 @@ usage(void) { fprint(2, "usage: import [-abcC] [-A] [-E clear|ssl|tls] " -"[-e 'crypt auth'|clear] [-k keypattern] [-p] host remotefs [mountpoint]\n"); +"[-e 'crypt auth'|clear] [-k keypattern] [-p] [-z] host remotefs [mountpoint]\n"); exits("usage"); } --- /sys/man/4/import Tue Feb 26 02:57:33 2013 +++ /sys/man/4/import Tue Feb 26 02:57:31 2013 @@ -68,6 +68,19 @@ Skip the authentication protocol. This is useful for connecting to foreign systems like Inferno. .TP +.B -z +Bypass the initial protocol request for which remote tree to serve. The +.I file +parameter must still be provided but is not sent to the server. This is necessary when the remote +.IR exportfs (4) +is running with the +.B -r +or +.B -S +options which pre-select a file tree to serve. The exception is if both sides are operating in the +.B -B +backwards mode. +.TP .B -B Run in ``backwards'' mode, described below. .TP @@ -134,6 +147,32 @@ .I cmd .IR args . .SH EXAMPLES +Connect to the cpu server +.B kremvax +and allow local access to its +.IR proc (3) +directory: +.IP +.EX +import kremvax /proc /n/kremproc +.EE +.PP +Assume a user on +.B kremvax +wishes to provide an authenticated export of their +.IR upas (4) +mailbox for access from another machine. That user issues this command on kremvax: +.IP +.EX +aux/listen1 tcp!*!8888 /bin/exportfs -a -S /srv/upasfs.$user +.EE +.PP +Then, to connect to the mailbox from a remote machine: +.IP +.EX +import -c -z tcp!kremvax!8888 mail /mail/fs +.EE +.PP Assume a machine .B kremvax that has IP interfaces for the company intranet and the global --- /sys/man/4/exportfs Tue Feb 26 02:57:37 2013 +++ /sys/man/4/exportfs Tue Feb 26 02:57:35 2013 @@ -83,7 +83,7 @@ The remote system should run .B import .B -B -to handle the call. +to handle the call. Referred to as ``backwards'' mode. See .IR import (4) for an example. @@ -139,6 +139,13 @@ .B -r \fIroot Bypass the initial protocol, serving the name space rooted at .IR root . +This option requires the use of of the +.B -z +flag to +.IR import (4) +to instruct it to bypass this part of the protocol also, unless the connection is made in +.B -B +backwards mode. .TP .B -S \fIservice bypass the initial protocol, serving the result of mounting @@ -150,6 +157,13 @@ corresponds to a different client .IR e.g. , ( .IR rio (4)). +This also requires that +.IR import (4) +clients use the +.B -z +flag to bypass tree negotiation if +.B -B +mode is not in use. .TP .B -s equivalent to