ref: 0f3bdd705bbd22fc6a7a39997df7fb6245ff5573
parent: fc582333b8903ac2af1dada360fbabc502db9427
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Aug 20 23:56:03 EDT 2016
devssl, devtls: merge with 9front
--- a/kern/devssl.c
+++ b/kern/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);
@@ -1458,7 +1439,7 @@
fd = strtoul(p, 0, 0);
if(fd < 0)
error(Ebadarg);
- c = fdtochan(fd, -1, 0, 1); /* error check and inc ref */
+ c = fdtochan(fd, ORDWR, 1, 1); /* error check and inc ref */
if(devtab[c->type] == &ssldevtab){
cclose(c);
error("cannot ssl encrypt devssl files");
--- a/kern/devtls.c
+++ b/kern/devtls.c
@@ -7,7 +7,7 @@
#include "fns.h"
#include "error.h"
-#include "libsec.h"
+#include <libsec.h>
typedef struct OneWay OneWay;
typedef struct Secret Secret;
@@ -421,22 +421,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:
@@ -468,10 +454,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);
@@ -1886,7 +1869,7 @@
fd = strtoul(p, 0, 0);
if(fd < 0)
error(Ebadarg);
- c = fdtochan(fd, -1, 0, 1); /* error check and inc ref */
+ c = fdtochan(fd, ORDWR, 1, 1); /* error check and inc ref */
return c;
}