pre-lib9p servers: fix incorrect Tversion handling

version(5) says:

	If the server does not understand the client's version
	string, it should respond with an Rversion message (not
	Rerror) with the version string the 7 characters
	``unknown''.

Pre-lib9p file servers -- all except cwfs(4) -- do return Rerror.

lib9p(2) follows the above spec, although ignoring the next part
concerning comparison after period-stripping.  It assumes an
Fcall.version starting with "9P" is correctly formed and returns
the only supported version of the protocol, which seems alright.

This patch brings pre-lib9p servers in accordance with the spec.
This commit is contained in:
kvik 2020-08-01 15:27:28 +02:00
parent 88a468f205
commit e5894dccea
22 changed files with 66 additions and 65 deletions

View file

@ -254,6 +254,8 @@ rversion(void)
else
rep->msize = req->msize;
rep->version = "9P2000";
if(strncmp(req->version, "9P", 2) != 0)
rep->version = "unknown";
}
void

View file

@ -325,9 +325,9 @@ fsysversion(Xfid *x, Fid*)
return respond(x, &t, "version: message size too small");
messagesize = x->msize;
t.msize = messagesize;
if(strncmp(x->version, "9P2000", 6) != 0)
return respond(x, &t, "unrecognized 9P version");
t.version = "9P2000";
if(strncmp(x->version, "9P", 2) != 0)
t.version = "unknown";
return respond(x, &t, nil);
}

View file

@ -258,9 +258,9 @@ Version(Fid*)
else
thdr.msize = rhdr.msize;
messagesize = thdr.msize;
if(strncmp(rhdr.version, "9P2000", 6) != 0)
return "bad 9P version";
thdr.version = "9P2000";
if(strncmp(rhdr.version, "9P", 2) != 0)
thdr.version = "unknown";
return 0;
}

View file

@ -57,7 +57,7 @@ watch(int fd)
}
if(n == 0)
print("server eof\n");
else
else if(n == -1)
print("read9pmsg from server: %r\n");
}

View file

@ -763,12 +763,10 @@ fsversion(Fs *fs, Request *r, Fid*)
if(messagesize > 8192+IOHDRSZ)
messagesize = 8192+IOHDRSZ;
r->f.msize = messagesize;
if(strncmp(r->f.version, "9P2000", 6) != 0){
fsreply(fs, r, "unrecognized 9P version");
return;
}
if(strncmp(r->f.version, "9P", 2) != 0)
r->f.version = "unknown";
else
r->f.version = "9P2000";
fsreply(fs, r, nil);
}

View file

@ -472,6 +472,9 @@ fsversion(Fs *fs, Request *r, Fid*)
if(messagesize > r->f.msize)
messagesize = r->f.msize;
r->f.msize = messagesize;
if(strncmp(r->f.version, "9P", 2) != 0)
r->f.version = "unknown";
else
r->f.version = "9P2000";
fsreply(fs, r, nil);
}

View file

@ -687,8 +687,9 @@ fsversion(Fs *, Fcall *rpc)
if(rpc->msize > messagesize)
rpc->msize = messagesize;
messagesize = rpc->msize;
if(strncmp(rpc->version, "9P2000", 6) != 0)
return "unrecognized 9P version";
if(strncmp(rpc->version, "9P", 2) != 0)
rpc->version = "unknown";
else
rpc->version = "9P2000";
return nil;
}

View file

@ -116,7 +116,6 @@ char Enotowner[] = "not owner";
char Eisopen[] = "file already open for I/O";
char Excl[] = "exclusive use file already open";
char Ename[] = "illegal name";
char Eversion[] = "unknown 9P version";
int debug;
@ -228,9 +227,9 @@ rversion(Fid*)
else
rhdr.msize = thdr.msize;
messagesize = rhdr.msize;
if(strncmp(thdr.version, "9P2000", 6) != 0)
return Eversion;
rhdr.version = "9P2000";
if(strncmp(thdr.version, "9P", 2) != 0)
rhdr.version = "unknown";
return 0;
}

View file

@ -15,6 +15,8 @@ rversion(void)
else
rep->msize = req->msize;
rep->version = "9P2000";
if(strncmp(req->version, "9P", 2) != 0)
rep->version = "unknown";
}
void

View file

@ -15,7 +15,6 @@ char Exmnt[] = "Cannot .. past mount point";
char Emip[] = "Mount in progress";
char Enopsmt[] = "Out of pseudo mount points";
char Enomem[] = "No memory";
char Eversion[] = "Bad 9P2000 version";
char Ereadonly[] = "File system read only";
char Enoprocs[] = "Out of processes";
@ -35,13 +34,10 @@ Xversion(Fsrpc *t)
if(t->work.msize > messagesize)
t->work.msize = messagesize;
messagesize = t->work.msize;
if(strncmp(t->work.version, "9P2000", 6) != 0){
reply(&t->work, &rhdr, Eversion);
putsbuf(t);
return;
}
rhdr.version = "9P2000";
rhdr.msize = t->work.msize;
rhdr.version = "9P2000";
if(strncmp(t->work.version, "9P", 2) != 0)
rhdr.version = "unknown";
reply(&t->work, &rhdr, 0);
putsbuf(t);
}

View file

@ -314,9 +314,9 @@ rversion(Fid*)
rhdr.msize = thdr.msize;
messagesize = rhdr.msize;
if(strncmp(thdr.version, "9P2000", 6) != 0)
return "unknown 9P version";
rhdr.version = "9P2000";
if(strncmp(thdr.version, "9P", 2) != 0)
rhdr.version = "unknown";
return nil;
}

View file

@ -90,7 +90,6 @@ char Enotowner[] = "not owner";
char Eisopen[] = "file already open for I/O";
char Excl[] = "exclusive use file already open";
char Ename[] = "illegal name";
char Eversion[] = "unknown 9P version";
void
usage(void)
@ -195,9 +194,9 @@ rversion(Fid*)
else
rhdr.msize = thdr.msize;
messagesize = rhdr.msize;
if(strncmp(thdr.version, "9P2000", 6) != 0)
return Eversion;
rhdr.version = "9P2000";
if(strncmp(thdr.version, "9P", 2) != 0)
rhdr.version = "unknown";
return nil;
}

View file

@ -510,12 +510,10 @@ rversion(Job *job)
job->reply.msize = IOHDRSZ + Maxfdata;
else
job->reply.msize = job->request.msize;
if(strncmp(job->request.version, "9P2000", 6) != 0)
sendmsg(job, "unknown 9P version");
else{
job->reply.version = "9P2000";
if(strncmp(job->request.version, "9P", 2) != 0)
job->reply.version = "unknown";
sendmsg(job, nil);
}
}
void

View file

@ -485,12 +485,10 @@ rversion(Job *job)
job->reply.msize = IOHDRSZ + Maxfdata;
else
job->reply.msize = job->request.msize;
if(strncmp(job->request.version, "9P2000", 6) != 0)
sendmsg(job, "unknown 9P version");
else{
job->reply.version = "9P2000";
sendmsg(job, 0);
}
if(strncmp(job->request.version, "9P", 2) != 0)
job->reply.version = "unknown";
sendmsg(job, nil);
}
void

View file

@ -135,7 +135,6 @@ char Excl[] = "exclusive use file already open";
char Ename[] = "illegal name";
char Erdonly[] = "read only file system";
char Ebadblock[] = "bad block";
char Eversion[] = "bad version of P9";
char Edirtoobig[] = "directory entry too big";
int debug;
@ -270,9 +269,9 @@ rversion(Fid*)
thdr.msize = mesgsize;
else
thdr.msize = rhdr.msize;
if(strcmp(rhdr.version, "9P2000") != 0)
return Eversion;
thdr.version = "9P2000";
if(strncmp(rhdr.version, "9P", 2) != 0)
thdr.version = "unknown";
return 0;
}

View file

@ -563,10 +563,9 @@ fsysversion(Fcall *t, uchar *buf, Fid*)
if(t->msize < messagesize)
messagesize = t->msize;
t->msize = messagesize;
if(strncmp(t->version, "9P2000", 6) != 0){
fsysrespond(t, buf, "unrecognized 9P version");
return t;
}
if(strncmp(t->version, "9P", 2) != 0)
t->version = "unknown";
else
t->version = "9P2000";
fsysrespond(t, buf, nil);
return t;

View file

@ -131,9 +131,16 @@ newfid(int fid)
static void
rversion(Fcall *f)
{
f->version = "9P2000";
if(f->msize < 256){
reply(f, "version: message size too small");
return;
}
if(f->msize > MAXRPC)
f->msize = MAXRPC;
if(strncmp(f->version, "9P", 2) != 0)
f->version = "unknown";
else
f->version = "9P2000";
reply(f, 0);
}

View file

@ -294,9 +294,9 @@ filsysversion(Filsys *fs, Xfid *x, Fid*)
return filsysrespond(x->fs, x, &t, "version: message size too small");
messagesize = x->msize;
t.msize = messagesize;
if(strncmp(x->version, "9P2000", 6) != 0)
return filsysrespond(x->fs, x, &t, "unrecognized 9P version");
t.version = "9P2000";
if(strncmp(x->version, "9P", 2) != 0)
t.version = "unknown";
return filsysrespond(fs, x, &t, nil);
}

View file

@ -160,9 +160,9 @@ rversion(Fid *unused)
else
messagesize = rhdr.msize;
thdr.msize = messagesize;
if(strncmp(rhdr.version, "9P2000", 6) != 0)
return "unrecognized 9P version";
thdr.version = "9P2000";
if(strncmp(rhdr.version, "9P", 2) != 0)
thdr.version = "unknown";
for(f = fids; f; f = f->next)
if(f->busy)

View file

@ -519,9 +519,9 @@ rversion(Fid *)
if(messagesize > sizeof mdata)
messagesize = sizeof mdata;
rhdr.msize = messagesize;
if(strncmp(thdr.version, "9P2000", 6) != 0)
return "unrecognized 9P version";
rhdr.version = "9P2000";
if(strncmp(thdr.version, "9P", 2) != 0)
rhdr.version = "unknown";
return 0;
}

View file

@ -726,10 +726,10 @@ rversion(Fid*)
if(thdr.msize < messagesize)
messagesize = thdr.msize;
rhdr.msize = messagesize;
if(strncmp(thdr.version, "9P2000", 6) != 0)
return "unknown 9P version";
else
rhdr.version = "9P2000";
if(strncmp(thdr.version, "9P", 2) != 0)
rhdr.version = "unknown";
for(f = fids; f; f = f->next)
if(f->busy)
rclunk(f);

View file

@ -255,13 +255,13 @@ rversion(Fid *unused)
if(messagesize > sizeof mdata)
messagesize = sizeof mdata;
thdr.msize = messagesize;
if(strncmp(rhdr.version, "9P2000", 6) != 0)
return vtstrdup("unrecognized 9P version");
thdr.version = "9P2000";
if(strncmp(rhdr.version, "9P", 2) != 0)
thdr.version = "unknown";
if(strncmp(rhdr.version, "9P2000.u", 8) == 0){
dotu = 1;
thdr.version = "9P2000.u";
}
}else
thdr.version = "9P2000";
return nil;
}