shithub: gefs

Download patch

ref: 5bdac7aa918b452953323093051c758938e381fe
parent: 17b3e44bd031c2d1fbbab32ced6ef91190891402
author: Ori Bernstein <ori@eigenstate.org>
date: Sun May 7 13:48:47 EDT 2023

fs: send a message in the AuthDone phase to get user info

--- a/fs.c
+++ b/fs.c
@@ -723,6 +723,59 @@
 	return rpc;
 }
 
+static char*
+authread(Fid *f, Fcall *r, void *data, vlong count)
+{
+	AuthInfo *ai;
+	AuthRpc *rpc;
+	User *u;
+
+	if((rpc = f->auth) == nil)
+		return Etype;
+
+	switch(auth_rpc(rpc, "read", nil, 0)){
+	default:
+		return Eauthp;
+	case ARdone:
+		if((ai = auth_getinfo(rpc)) == nil)
+			goto Phase;
+		rlock(&fs->userlk);
+		u = name2user(ai->cuid);
+		auth_freeAI(ai);
+		if(u == nil){
+			runlock(&fs->userlk);
+			return Enouser;
+		}
+		f->uid = u->id;
+		runlock(&fs->userlk);
+		return nil;
+	case ARok:
+		if(count < rpc->narg)
+			return Eauthd;
+		memmove(data, rpc->arg, rpc->narg);
+		r->count = rpc->narg;
+		return nil;
+	case ARphase:
+	Phase:
+		return Ephase;
+	}
+}
+
+static char*
+authwrite(Fid *f, Fcall *r, void *data, vlong count)
+{
+	AuthRpc *rpc;
+
+	if((rpc = f->auth) == nil)
+		return Etype;
+	if(auth_rpc(rpc, "write", data, count) != ARok)
+		return Ebotch;
+	r->type = Rwrite;
+	r->count = count;
+	return nil;
+
+}
+
 static void
 fsauth(Fmsg *m)
 {
@@ -891,10 +944,17 @@
 	runlock(&fs->userlk);
 
 	if(m->afid != NOFID){
+		r.data = nil;
+		r.count = 0;
 		if((af = getfid(m->conn, m->afid)) == nil){
 			rerror(m, Enofid);
 			goto Out;
 		}
+		if((e = authread(af, &r, nil, 0)) != nil){
+			rerror(m, e);
+			putfid(af);
+			goto Out;
+		}
 		if(af->uid != uid){
 			rerror(m, Ebadu);
 			putfid(af);
@@ -1676,44 +1736,6 @@
 }
 
 static char*
-readauth(Fmsg *m, Fid *f, Fcall *r)
-{
-	AuthInfo *ai;
-	AuthRpc *rpc;
-	User *u;
-
-	if((rpc = f->auth) == nil)
-		return Etype;
-
-	switch(auth_rpc(rpc, "read", nil, 0)){
-	default:
-		return Eauthp;
-	case ARdone:
-		if((ai = auth_getinfo(rpc)) == nil)
-			goto Phase;
-		rlock(&fs->userlk);
-		u = name2user(ai->cuid);
-		auth_freeAI(ai);
-		if(u == nil){
-			runlock(&fs->userlk);
-			return Enouser;
-		}
-		f->uid = u->id;
-		runlock(&fs->userlk);
-		return nil;
-	case ARok:
-		if(m->count < rpc->narg)
-			return Eauthd;
-		memmove(r->data, rpc->arg, rpc->narg);
-		r->count = rpc->narg;
-		return nil;
-	case ARphase:
-	Phase:
-		return Ephase;
-	}
-}
-
-static char*
 readsnap(Fmsg *m, Fid *f, Fcall *r)
 {
 	char pfx[1], *p, *e;
@@ -1890,7 +1912,7 @@
 		return;
 	}
 	if(f->dent->qid.type & QTAUTH)
-		e = readauth(m, f, &r);
+		e = authread(f, &r, r.data, m->count);
 	else if(f->dent->qid.path == Qdump)
 		e = readsnap(m, f, &r);
 	else if(f->dent->qid.type & QTDIR)
@@ -1905,22 +1927,6 @@
 	putfid(f);
 }
 
-static char*
-writeauth(Fmsg *m, Fid *f, Fcall *r)
-{
-	AuthRpc *rpc;
-
-	if((rpc = f->auth) == nil)
-		return Etype;
-	if(auth_rpc(rpc, "write", m->data, m->count) != ARok)
-		return Ebotch;
-	r->type = Rwrite;
-	r->count = m->count;
-	return nil;
-
-}
-
-
 static void
 fswrite(Fmsg *m)
 {
@@ -1950,7 +1956,7 @@
 		return;
 	}
 	if(f->dent->qid.type == QTAUTH){
-		e = writeauth(m, f, &r);
+		e = authwrite(f, &r, m->data, m->count);
 		if(e != nil)
 			rerror(m, e);
 		else