shithub: riscv

Download patch

ref: cb4b187f10ae92aab6689a454d17bbbd382ebe63
parent: a630e17bd7d77df2b88ee3995e35ed1b88f00830
author: cinap_lenrek <[email protected]>
date: Tue May 10 22:10:05 EDT 2016

devssl, devtls: fix permission checks

--- a/sys/src/9/port/devssl.c
+++ b/sys/src/9/port/devssl.c
@@ -263,23 +263,8 @@
 sslopen(Chan *c, int omode)
 {
 	Dstate *s, **pp;
-	int perm;
 	int ft;
 
-	perm = 0;
-	omode &= 3;
-	switch(omode) {
-	case OREAD:
-		perm = 4;
-		break;
-	case OWRITE:
-		perm = 2;
-		break;
-	case ORDWR:
-		perm = 6;
-		break;
-	}
-
 	ft = TYPE(c->qid);
 	switch(ft) {
 	default:
@@ -309,11 +294,7 @@
 		if(s == 0)
 			dsnew(c, pp);
 		else {
-			if((perm & (s->perm>>6)) != perm
-			   && (strcmp(up->user, s->user) != 0
-			     || (perm & s->perm) != perm))
-				error(Eperm);
-
+			devpermcheck(s->user, s->perm, omode);
 			s->ref++;
 		}
 		unlock(&dslock);
--- a/sys/src/9/port/devtls.c
+++ b/sys/src/9/port/devtls.c
@@ -424,22 +424,8 @@
 tlsopen(Chan *c, int omode)
 {
 	TlsRec *tr, **pp;
-	int t, perm;
+	int t;
 
-	perm = 0;
-	omode &= 3;
-	switch(omode) {
-	case OREAD:
-		perm = 4;
-		break;
-	case OWRITE:
-		perm = 2;
-		break;
-	case ORDWR:
-		perm = 6;
-		break;
-	}
-
 	t = TYPE(c->qid);
 	switch(t) {
 	default:
@@ -471,10 +457,7 @@
 		tr = *pp;
 		if(tr == nil)
 			error("must open connection using clone");
-		if((perm & (tr->perm>>6)) != perm
-		&& (strcmp(up->user, tr->user) != 0
-		    || (perm & tr->perm) != perm))
-			error(Eperm);
+		devpermcheck(tr->user, tr->perm, omode);
 		if(t == Qhand){
 			if(waserror()){
 				unlock(&tr->hqlock);