shithub: riscv

Download patch

ref: db7290d79e86abfdab490e793073a4936c8e1e5f
parent: 064bce08419857817e0b851ea43ae66b2aee0843
author: cinap_lenrek <cinap_lenrek@localhost>
date: Sun May 1 03:07:32 EDT 2011

cwfs: fix network listener, relay auth errors. boot(8): split bootargs only on first ! char, prepare /net so cwfs can announce 9fs

--- a/sys/src/9/boot/bootrc
+++ b/sys/src/9/boot/bootrc
@@ -70,7 +70,7 @@
 		}
 		if not bootargs=$nobootprompt
 		mn=`{echo $bootargs | awk -F! '{print $1}'}
-		ma=`{echo $bootargs | awk -F! '{print $2}'}
+		ma=`{echo $bootargs | sed 's/[^!]+!//'}
 		for(i in `{seq 1 $#mt}){
 			if(~ $mt($i) m^$mn)
 				mp=$$mt($i)
@@ -77,13 +77,6 @@
 		}
 	}
 
-	switch($mn){
-	case local
-		islocal=1
-	case hybrid
-		ishybrid=1
-	}
-
 	# config method
 	$mp(1) $ma
 
@@ -148,6 +141,10 @@
 	if(test -r $"kbmap)
 		cat $"kbmap >/dev/kbmap
 }
+
+# bind in an ip interface
+for(i in I l`{seq 0 3})
+	bind -qa '#'$i /net
 
 configlocal	# add partitions and binds
 
--- a/sys/src/9/boot/tcp.rc
+++ b/sys/src/9/boot/tcp.rc
@@ -1,10 +1,6 @@
 #!/bin/rc
 
 fn configtcp{
-	# bind in an ip interface
-	for(i in I l`{seq 0 3})
-		bind -qa '#'$i /net
-
 	must ip/ipconfig -p $*
 	
 	if(~ $#fs 0)
--- a/sys/src/cmd/cwfs/9p2.c
+++ b/sys/src/cmd/cwfs/9p2.c
@@ -242,7 +242,7 @@
 	}
 
 	/* fake read to get auth info */
-	authread(af, nil, 0);
+	authread(chan, af, nil, 0);
 	uid = af->uid;
 	if(db)
 		print("authorize: uid is %d\n", uid);
@@ -1001,7 +1001,7 @@
 		goto out;
 	}
 	if(file->qid.type & QTAUTH){
-		nread = authread(file, (uchar*)data, count);
+		nread = authread(chan, file, (uchar*)data, count);
 		if(nread < 0)
 			error = Eauth2;
 		goto out;
@@ -1198,7 +1198,7 @@
 	}
 
 	if(file->qid.type & QTAUTH){
-		nwrite = authwrite(file, (uchar*)f->data, count);
+		nwrite = authwrite(chan, file, (uchar*)f->data, count);
 		if(nwrite < 0)
 			error = Eauth2;
 		goto out;
@@ -1733,6 +1733,7 @@
 	r.tag = f.tag;
 	error = 0;
 	data = nil;
+	chan->err[0] = 0;
 
 	switch(type){
 	default:
@@ -1786,7 +1787,9 @@
 
 	if(error != 0){
 		r.type = Rerror;
-		if(error >= MAXERR){
+		if(chan->err[0])
+			r.ename = chan->err;
+		else if(error >= MAXERR){
 			snprint(ename, sizeof(ename), "error %d", error);
 			r.ename = ename;
 		} else
--- a/sys/src/cmd/cwfs/auth.c
+++ b/sys/src/cmd/cwfs/auth.c
@@ -119,43 +119,62 @@
 }
 
 int
-authread(File *file, uchar *data, int count)
+authread(Chan *chan, File *file, uchar *data, int count)
 {
 	AuthInfo *ai;
 	AuthRpc *rpc;
 
-	if((rpc = file->auth) == nil)
+	if((rpc = file->auth) == nil){
+		snprint(chan->err, sizeof(chan->err),
+			"not an auth fid");
 		return -1;
+	}
+
 	switch(auth_rpc(rpc, "read", nil, 0)){
+	default:
+		snprint(chan->err, sizeof(chan->err),
+			"authread: auth protocol not finished");
+		return -1;
 	case ARdone:
 		if((ai = auth_getinfo(rpc)) == nil)
-			return -1;
+			goto Phase;
 		file->uid = strtouid(ai->cuid);
 		auth_freeAI(ai);
-		if(file->uid < 0)
+		if(file->uid < 0){
+			snprint(chan->err, sizeof(chan->err),
+				"unknown user '%s'", ai->cuid);
 			return -1;
+		}
 		return 0;
 	case ARok:
-		if(count < rpc->narg)
+		if(count < rpc->narg){
+			snprint(chan->err, sizeof(chan->err),
+				"not enough data in auth read");
 			return -1;
+		}
 		memmove(data, rpc->arg, rpc->narg);
 		return rpc->narg;
 	case ARphase:
+	Phase:
+		rerrstr(chan->err, sizeof(chan->err));
 		return -1;
-	default:
-		return -1;
 	}
 }
 
 int
-authwrite(File *file, uchar *data, int count)
+authwrite(Chan *chan, File *file, uchar *data, int count)
 {
 	AuthRpc *rpc;
 
-	if((rpc = file->auth) == nil)
+	if((rpc = file->auth) == nil){
+		snprint(chan->err, sizeof(chan->err),
+			"not an auth fid");
 		return -1;
-	if(auth_rpc(rpc, "write", data, count) != ARok)
+	}
+	if(auth_rpc(rpc, "write", data, count) != ARok){
+		rerrstr(chan->err, sizeof(chan->err));
 		return -1;
+	}
 	return count;
 }
 
--- a/sys/src/cmd/cwfs/net.c
+++ b/sys/src/cmd/cwfs/net.c
@@ -54,19 +54,18 @@
 	Network *net;
 
 	net = v;
-	print("net%di\n", net->ctlrno);
-Listen:
-	if((lisfd = listen(net->anndir, net->lisdir)) < 0){
-		print("listen %s failed: %r\n", net->anndir);
-		return;
-	}
+	if(chatty)
+		print("net%di\n", net->ctlrno);
 	for(;;) {
+		if((lisfd = listen(net->anndir, net->lisdir)) < 0){
+			fprint(2, "listen %s failed: %r\n", net->anndir);
+			break;
+		}
 		/* got new call on lisfd */
 		if((accfd = accept(lisfd, net->lisdir)) < 0){
-			print("accept %d (from %s) failed: %r\n",
-				lisfd, net->lisdir);
+			fprint(2, "accept %d (from %s) failed: %r\n", lisfd, net->lisdir);
 			close(lisfd);
-			goto Listen;
+			continue;
 		}
 		nci = getnetconninfo(net->lisdir, accfd);
 		srvchan(accfd, nci->raddr);
@@ -97,10 +96,11 @@
 		if(net->dialstr == nil)
 			continue;
 		if((net->annfd = announce(net->dialstr, net->anndir)) < 0){
-			print("can't announce %s: %r", net->dialstr);
+			fprint(2, "can't announce %s: %r", net->dialstr);
 			net->dialstr = nil;
 			continue;
 		}
-		print("netinit: announced on %s\n", net->dialstr);
+		if(chatty)
+			print("netinit: announced on %s\n", net->dialstr);
 	}
 }
--- a/sys/src/cmd/cwfs/portdat.h
+++ b/sys/src/cmd/cwfs/portdat.h
@@ -267,6 +267,8 @@
 	uchar	authinfo[64];
 
 	void*	pdata;			/* sometimes is a Netconn* */
+
+	char	err[ERRMAX];
 };
 
 struct	Filsys
--- a/sys/src/cmd/cwfs/portfns.h
+++ b/sys/src/cmd/cwfs/portfns.h
@@ -4,8 +4,8 @@
 void	arginit(void);
 void*	authnew(void);
 void	authfree(void*);
-int	authread(File*, uchar*, int);
-int	authwrite(File*, uchar*, int);
+int	authread(Chan*, File*, uchar*, int);
+int	authwrite(Chan*, File*, uchar*, int);
 void	cdiag(char*, int);
 int	cnumb(void);
 Device*	config(void);