shithub: riscv

Download patch

ref: 23742053f5ee70cd394c33f28f3e6547e9e8e31d
parent: b241dd11596ac16cb21ba1ffc24abd7a46153a09
author: cinap_lenrek <[email protected]>
date: Mon Aug 10 06:11:45 EDT 2015

mount, srv: add -N flag to skip authentication and attach anonymously as "none"

--- a/sys/man/1/bind
+++ b/sys/man/1/bind
@@ -144,7 +144,7 @@
 .PD
 .PP
 .I Mount
-takes two additional options.
+takes three additional options.
 The first,
 .B -k
 .IR keypattern ,
@@ -156,6 +156,11 @@
 causes
 .I mount
 to skip authentication entirely.
+The third,
+.BR -N ,
+skips authentication and specifies
+.B none
+as the username to the fileserver.
 .PP
 The
 .I spec
--- a/sys/man/4/srv
+++ b/sys/man/4/srv
@@ -4,7 +4,7 @@
 .SH SYNOPSIS
 .B srv
 [
-.B -abcCemnq
+.B -abcCemnNq
 ] [
 .B -s
 .I seconds
@@ -114,7 +114,8 @@
 .BR c ,
 .BR C ,
 and
-.B n
+.BR n ,
+.B N
 options are used to control the mount flags as in
 .I mount
 (see
--- a/sys/src/cmd/mount.c
+++ b/sys/src/cmd/mount.c
@@ -6,6 +6,11 @@
 void	catch(void*, char*);
 
 char *keyspec = "";
+char *spec = "";
+int flag = MREPL;
+int qflag = 0;
+int noauth = 0;
+int asnone = 0;
 
 int
 amount0(int fd, char *mntpt, int flags, char *aname, char *keyspec)
@@ -30,10 +35,6 @@
 void
 main(int argc, char *argv[])
 {
-	char *spec;
-	ulong flag = 0;
-	int qflag = 0;
-	int noauth = 0;
 	int fd, rv;
 
 	ARGBEGIN{
@@ -52,6 +53,9 @@
 	case 'k':
 		keyspec = EARGF(usage());
 		break;
+	case 'N':
+		asnone = 1;
+		/* no break */
 	case 'n':
 		noauth = 1;
 		break;
@@ -62,12 +66,9 @@
 		usage();
 	}ARGEND
 
-	spec = 0;
-	if(argc == 2)
-		spec = "";
-	else if(argc == 3)
+	if(argc == 3)
 		spec = argv[2];
-	else
+	else if(argc != 2)
 		usage();
 
 	if((flag&MAFTER)&&(flag&MBEFORE))
@@ -81,6 +82,16 @@
 		exits("open");
 	}
 
+	if(asnone){
+		rv = open("#c/user", OWRITE);
+		if(rv < 0 || write(rv, "none", 4) != 4){
+			if(qflag)
+				exits(0);
+			fprint(2, "%s: can't become none: %r\n", argv0);
+			exits("becomenone");
+		}
+	}
+
 	notify(catch);
 	if(noauth)
 		rv = mount(fd, -1, argv[1], flag, spec);
@@ -96,10 +107,9 @@
 }
 
 void
-catch(void *x, char *m)
+catch(void *, char *m)
 {
-	USED(x);
-	fprint(2, "mount: %s\n", m);
+	fprint(2, "%s: %s\n", argv0, m);
 	exits(m);
 }
 
@@ -106,6 +116,6 @@
 void
 usage(void)
 {
-	fprint(2, "usage: mount [-a|-b] [-cnq] [-k keypattern] /srv/service dir [spec]\n");
+	fprint(2, "usage: mount [-a|-b] [-cCnNq] [-k keypattern] /srv/service dir [spec]\n");
 	exits("usage");
 }
--- a/sys/src/cmd/srv.c
+++ b/sys/src/cmd/srv.c
@@ -10,12 +10,13 @@
 void	post(char*, int);
 void	mountfs(char*, int);
 int	doauth = 1;
+int	asnone = 0;
 
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-abcCm] [net!]host [srvname [mtpt]]\n", argv0);
-	fprint(2, "    or %s -e [-abcCm] command [srvname [mtpt]]\n", argv0);
+	fprint(2, "usage: %s [-abcCmnNq] [net!]host [srvname [mtpt]]\n", argv0);
+	fprint(2, "    or %s -e [-abcCmnNq] command [srvname [mtpt]]\n", argv0);
 
 	exits("usage");
 }
@@ -106,6 +107,9 @@
 		domount = 1;
 		reallymount = 1;
 		break;
+	case 'N':
+		asnone = 1;
+		/* no break */
 	case 'n':
 		doauth = 0;
 		break;
@@ -196,6 +200,15 @@
 Mount:
 	if(domount == 0 || reallymount == 0)
 		exits(0);
+
+	if(asnone){
+		try = open("#c/user", OWRITE);
+		if(try < 0 || write(try, "none", 4) != 4){
+			fprint(2, "srv %s: can't become none: %r\n", dest);
+			exits("becomenone");
+		}
+		try = 0;
+	}
 
 	if((!doauth && mount(fd, -1, mtpt, mountflag, "") < 0)
 	|| (doauth && amount(fd, mtpt, mountflag, "") < 0)){