exportfs: cleanup
This commit is contained in:
parent
7ae4e473da
commit
73d35f9c7d
1 changed files with 47 additions and 49 deletions
|
@ -74,7 +74,7 @@ noteconn(int fd)
|
||||||
NetConnInfo *nci;
|
NetConnInfo *nci;
|
||||||
|
|
||||||
nci = getnetconninfo(nil, fd);
|
nci = getnetconninfo(nil, fd);
|
||||||
if (nci == nil)
|
if(nci == nil)
|
||||||
return;
|
return;
|
||||||
netdir = estrdup(nci->dir);
|
netdir = estrdup(nci->dir);
|
||||||
local = estrdup(nci->lsys);
|
local = estrdup(nci->lsys);
|
||||||
|
@ -165,7 +165,7 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
if(srvfdfile)
|
if(srvfdfile != nil)
|
||||||
usage();
|
usage();
|
||||||
srvfdfile = EARGF(usage());
|
srvfdfile = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
|
@ -192,12 +192,12 @@ main(int argc, char **argv)
|
||||||
putenv("service", "exportfs");
|
putenv("service", "exportfs");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(srvfdfile){
|
if(srvfdfile != nil){
|
||||||
if((srvfd = open(srvfdfile, ORDWR)) < 0)
|
if((srvfd = open(srvfdfile, ORDWR)) < 0)
|
||||||
fatal("open %s: %r", srvfdfile);
|
fatal("open %s: %r", srvfdfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(na){
|
if(na != nil){
|
||||||
if(srv == nil)
|
if(srv == nil)
|
||||||
fatal("-B requires -s");
|
fatal("-B requires -s");
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ main(int argc, char **argv)
|
||||||
close(n);
|
close(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(srvfd >= 0 && srv){
|
if(srvfd >= 0 && srv != nil){
|
||||||
fprint(2, "exportfs: -S cannot be used with -r or -s\n");
|
fprint(2, "exportfs: -S cannot be used with -r or -s\n");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ main(int argc, char **argv)
|
||||||
if(srvfd != -1) {
|
if(srvfd != -1) {
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
else if(srv) {
|
else if(srv != nil) {
|
||||||
if(chdir(srv) < 0) {
|
if(chdir(srv) < 0) {
|
||||||
errstr(ebuf, sizeof ebuf);
|
errstr(ebuf, sizeof ebuf);
|
||||||
fprint(0, "chdir(\"%s\"): %s\n", srv, ebuf);
|
fprint(0, "chdir(\"%s\"): %s\n", srv, ebuf);
|
||||||
|
@ -287,49 +287,49 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
ini = initial;
|
ini = initial;
|
||||||
n = readn(netfd, initial, sizeof(initial));
|
n = readn(netfd, initial, sizeof(initial));
|
||||||
if (n == 0)
|
if(n == 0)
|
||||||
fatal(nil); /* port scan or spurious open/close on exported /srv file (unmount) */
|
fatal(nil); /* port scan or spurious open/close on exported /srv file (unmount) */
|
||||||
if (n < sizeof(initial))
|
if(n < sizeof(initial))
|
||||||
fatal("can't read initial string: %r");
|
fatal("can't read initial string: %r");
|
||||||
|
|
||||||
if (memcmp(ini, "impo", 4) == 0) {
|
if(memcmp(ini, "impo", 4) == 0) {
|
||||||
char buf[128], *p, *args[3];
|
char buf[128], *p, *args[3];
|
||||||
|
|
||||||
ini = nil;
|
ini = nil;
|
||||||
p = buf;
|
p = buf;
|
||||||
for(;;){
|
for(;;){
|
||||||
if ((n = read(netfd, p, 1)) < 0)
|
if((n = read(netfd, p, 1)) < 0)
|
||||||
fatal("can't read impo arguments: %r");
|
fatal("can't read impo arguments: %r");
|
||||||
if (n == 0)
|
if(n == 0)
|
||||||
fatal("connection closed while reading arguments");
|
fatal("connection closed while reading arguments");
|
||||||
if (*p == '\n')
|
if(*p == '\n')
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (*p++ == '\0')
|
if(*p++ == '\0')
|
||||||
break;
|
break;
|
||||||
if(p >= buf + sizeof(buf))
|
if(p >= buf + sizeof(buf))
|
||||||
fatal("import parameters too long");
|
fatal("import parameters too long");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokenize(buf, args, nelem(args)) != 2)
|
if(tokenize(buf, args, nelem(args)) != 2)
|
||||||
fatal("impo arguments invalid: impo%s...", buf);
|
fatal("impo arguments invalid: impo%s...", buf);
|
||||||
|
|
||||||
if (strcmp(args[0], "aan") == 0)
|
if(strcmp(args[0], "aan") == 0)
|
||||||
filterp = aanfilter;
|
filterp = aanfilter;
|
||||||
else if (strcmp(args[0], "nofilter") != 0)
|
else if(strcmp(args[0], "nofilter") != 0)
|
||||||
fatal("import filter argument unsupported: %s", args[0]);
|
fatal("import filter argument unsupported: %s", args[0]);
|
||||||
|
|
||||||
if (strcmp(args[1], "ssl") == 0)
|
if(strcmp(args[1], "ssl") == 0)
|
||||||
encproto = Encssl;
|
encproto = Encssl;
|
||||||
else if (strcmp(args[1], "tls") == 0)
|
else if(strcmp(args[1], "tls") == 0)
|
||||||
encproto = Enctls;
|
encproto = Enctls;
|
||||||
else if (strcmp(args[1], "clear") != 0)
|
else if(strcmp(args[1], "clear") != 0)
|
||||||
fatal("import encryption proto unsupported: %s", args[1]);
|
fatal("import encryption proto unsupported: %s", args[1]);
|
||||||
|
|
||||||
if (encproto == Enctls)
|
if(encproto == Enctls)
|
||||||
fatal("%s: tls has not yet been implemented", argv[0]);
|
fatal("%s: tls has not yet been implemented", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encproto != Encnone && ealgs && ai) {
|
if(encproto != Encnone && ealgs != nil && ai != nil) {
|
||||||
uchar key[16], digest[SHA1dlen];
|
uchar key[16], digest[SHA1dlen];
|
||||||
char fromclientsecret[21];
|
char fromclientsecret[21];
|
||||||
char fromserversecret[21];
|
char fromserversecret[21];
|
||||||
|
@ -343,7 +343,7 @@ main(int argc, char **argv)
|
||||||
for(i = 0; i < 4; i++)
|
for(i = 0; i < 4; i++)
|
||||||
key[i+12] = rand();
|
key[i+12] = rand();
|
||||||
|
|
||||||
if (ini)
|
if(ini != nil)
|
||||||
fatal("Protocol botch: old import");
|
fatal("Protocol botch: old import");
|
||||||
if(readn(netfd, key, 4) != 4)
|
if(readn(netfd, key, 4) != 4)
|
||||||
fatal("can't read key part; %r");
|
fatal("can't read key part; %r");
|
||||||
|
@ -356,10 +356,10 @@ main(int argc, char **argv)
|
||||||
mksecret(fromclientsecret, digest);
|
mksecret(fromclientsecret, digest);
|
||||||
mksecret(fromserversecret, digest+10);
|
mksecret(fromserversecret, digest+10);
|
||||||
|
|
||||||
if (filterp)
|
if(filterp != nil)
|
||||||
netfd = filter(netfd, filterp);
|
netfd = filter(netfd, filterp);
|
||||||
|
|
||||||
switch (encproto) {
|
switch(encproto) {
|
||||||
case Encssl:
|
case Encssl:
|
||||||
netfd = pushssl(netfd, ealgs, fromserversecret,
|
netfd = pushssl(netfd, ealgs, fromserversecret,
|
||||||
fromclientsecret, nil);
|
fromclientsecret, nil);
|
||||||
|
@ -372,13 +372,13 @@ main(int argc, char **argv)
|
||||||
if(netfd < 0)
|
if(netfd < 0)
|
||||||
fatal("can't establish ssl connection: %r");
|
fatal("can't establish ssl connection: %r");
|
||||||
}
|
}
|
||||||
else if (filterp) {
|
else if(filterp != nil) {
|
||||||
if (ini)
|
if(ini != nil)
|
||||||
fatal("Protocol botch: don't know how to deal with this");
|
fatal("Protocol botch: don't know how to deal with this");
|
||||||
netfd = filter(netfd, filterp);
|
netfd = filter(netfd, filterp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ai)
|
if(ai != nil)
|
||||||
auth_freeAI(ai);
|
auth_freeAI(ai);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -386,7 +386,7 @@ main(int argc, char **argv)
|
||||||
*/
|
*/
|
||||||
for(;;) {
|
for(;;) {
|
||||||
r = getsbuf();
|
r = getsbuf();
|
||||||
if(r == 0)
|
if(r == nil)
|
||||||
fatal("Out of service buffers");
|
fatal("Out of service buffers");
|
||||||
|
|
||||||
while((n = localread9pmsg(netfd, r->buf, messagesize, ini)) == 0)
|
while((n = localread9pmsg(netfd, r->buf, messagesize, ini)) == 0)
|
||||||
|
@ -416,7 +416,7 @@ localread9pmsg(int fd, void *abuf, uint n, void *ini)
|
||||||
buf = abuf;
|
buf = abuf;
|
||||||
|
|
||||||
/* read count */
|
/* read count */
|
||||||
if (ini)
|
if(ini != nil)
|
||||||
memcpy(buf, ini, BIT32SZ);
|
memcpy(buf, ini, BIT32SZ);
|
||||||
else {
|
else {
|
||||||
m = readn(fd, buf, BIT32SZ);
|
m = readn(fd, buf, BIT32SZ);
|
||||||
|
@ -446,7 +446,7 @@ reply(Fcall *r, Fcall *t, char *err)
|
||||||
|
|
||||||
t->tag = r->tag;
|
t->tag = r->tag;
|
||||||
t->fid = r->fid;
|
t->fid = r->fid;
|
||||||
if(err) {
|
if(err != nil) {
|
||||||
t->type = Rerror;
|
t->type = Rerror;
|
||||||
t->ename = err;
|
t->ename = err;
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ reply(Fcall *r, Fcall *t, char *err)
|
||||||
if(data == nil)
|
if(data == nil)
|
||||||
fatal(Enomem);
|
fatal(Enomem);
|
||||||
n = convS2M(t, data, messagesize);
|
n = convS2M(t, data, messagesize);
|
||||||
if(write(netfd, data, n)!=n){
|
if(write(netfd, data, n) != n){
|
||||||
/* not fatal, might have got a note due to flush */
|
/* not fatal, might have got a note due to flush */
|
||||||
fprint(2, "exportfs: short write in reply: %r\n");
|
fprint(2, "exportfs: short write in reply: %r\n");
|
||||||
}
|
}
|
||||||
|
@ -471,11 +471,11 @@ getfid(int nr)
|
||||||
{
|
{
|
||||||
Fid *f;
|
Fid *f;
|
||||||
|
|
||||||
for(f = fidhash(nr); f; f = f->next)
|
for(f = fidhash(nr); f != nil; f = f->next)
|
||||||
if(f->nr == nr)
|
if(f->nr == nr)
|
||||||
return f;
|
return f;
|
||||||
|
|
||||||
return 0;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -485,18 +485,18 @@ freefid(int nr)
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
l = &fidhash(nr);
|
l = &fidhash(nr);
|
||||||
for(f = *l; f; f = f->next) {
|
for(f = *l; f != nil; f = f->next) {
|
||||||
if(f->nr == nr) {
|
if(f->nr == nr) {
|
||||||
if(f->mid) {
|
if(f->mid) {
|
||||||
snprint(buf, sizeof(buf), "/mnt/exportfs/%d", f->mid);
|
snprint(buf, sizeof(buf), "/mnt/exportfs/%d", f->mid);
|
||||||
unmount(0, buf);
|
unmount(0, buf);
|
||||||
psmap[f->mid] = 0;
|
psmap[f->mid] = 0;
|
||||||
}
|
}
|
||||||
if(f->f) {
|
if(f->f != nil) {
|
||||||
freefile(f->f);
|
freefile(f->f);
|
||||||
f->f = nil;
|
f->f = nil;
|
||||||
}
|
}
|
||||||
if(f->dir){
|
if(f->dir != nil){
|
||||||
free(f->dir);
|
free(f->dir);
|
||||||
f->dir = nil;
|
f->dir = nil;
|
||||||
}
|
}
|
||||||
|
@ -518,17 +518,17 @@ newfid(int nr)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
l = &fidhash(nr);
|
l = &fidhash(nr);
|
||||||
for(new = *l; new; new = new->next)
|
for(new = *l; new != nil; new = new->next)
|
||||||
if(new->nr == nr)
|
if(new->nr == nr)
|
||||||
return 0;
|
return nil;
|
||||||
|
|
||||||
if(fidfree == 0) {
|
if(fidfree == nil) {
|
||||||
fidfree = emallocz(sizeof(Fid) * Fidchunk);
|
fidfree = emallocz(sizeof(Fid) * Fidchunk);
|
||||||
|
|
||||||
for(i = 0; i < Fidchunk-1; i++)
|
for(i = 0; i < Fidchunk-1; i++)
|
||||||
fidfree[i].next = &fidfree[i+1];
|
fidfree[i].next = &fidfree[i+1];
|
||||||
|
|
||||||
fidfree[Fidchunk-1].next = 0;
|
fidfree[Fidchunk-1].next = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
new = fidfree;
|
new = fidfree;
|
||||||
|
@ -560,7 +560,7 @@ getsbuf(void)
|
||||||
|
|
||||||
lock(&sbufalloc);
|
lock(&sbufalloc);
|
||||||
w = sbufalloc.free;
|
w = sbufalloc.free;
|
||||||
if(w != 0){
|
if(w != nil){
|
||||||
sbufalloc.free = w->next;
|
sbufalloc.free = w->next;
|
||||||
w->next = nil;
|
w->next = nil;
|
||||||
sbufalloc.nfree--;
|
sbufalloc.nfree--;
|
||||||
|
@ -635,7 +635,7 @@ file(File *parent, char *name)
|
||||||
if(dir == nil)
|
if(dir == nil)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
for(f = parent->child; f; f = f->childlist)
|
for(f = parent->child; f != nil; f = f->childlist)
|
||||||
if(strcmp(name, f->name) == 0)
|
if(strcmp(name, f->name) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -696,7 +696,7 @@ initroot(void)
|
||||||
free(dir);
|
free(dir);
|
||||||
|
|
||||||
psmpt = file(psmpt, "mnt");
|
psmpt = file(psmpt, "mnt");
|
||||||
if(psmpt == 0)
|
if(psmpt == nil)
|
||||||
return;
|
return;
|
||||||
psmpt = file(psmpt, "exportfs");
|
psmpt = file(psmpt, "exportfs");
|
||||||
}
|
}
|
||||||
|
@ -815,10 +815,8 @@ uniqueqid(Dir *d)
|
||||||
path |= newqid<<48;
|
path |= newqid<<48;
|
||||||
DEBUG(DFD, "assign qid %.16llux\n", path);
|
DEBUG(DFD, "assign qid %.16llux\n", path);
|
||||||
}
|
}
|
||||||
q = mallocz(sizeof(Qidtab), 1);
|
|
||||||
if(q == nil)
|
|
||||||
fatal("no memory for qid table");
|
|
||||||
qidcnt++;
|
qidcnt++;
|
||||||
|
q = emallocz(sizeof(Qidtab));
|
||||||
q->ref = 1;
|
q->ref = 1;
|
||||||
q->type = d->type;
|
q->type = d->type;
|
||||||
q->dev = d->dev;
|
q->dev = d->dev;
|
||||||
|
@ -837,17 +835,17 @@ fatal(char *s, ...)
|
||||||
va_list arg;
|
va_list arg;
|
||||||
Proc *m;
|
Proc *m;
|
||||||
|
|
||||||
if (s) {
|
if(s != nil) {
|
||||||
va_start(arg, s);
|
va_start(arg, s);
|
||||||
vsnprint(buf, ERRMAX, s, arg);
|
vsnprint(buf, ERRMAX, s, arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear away the slave children */
|
/* Clear away the slave children */
|
||||||
for(m = Proclist; m; m = m->next)
|
for(m = Proclist; m != nil; m = m->next)
|
||||||
postnote(PNPROC, m->pid, "kill");
|
postnote(PNPROC, m->pid, "kill");
|
||||||
|
|
||||||
if (s) {
|
if(s != nil) {
|
||||||
DEBUG(DFD, "%s\n", buf);
|
DEBUG(DFD, "%s\n", buf);
|
||||||
sysfatal("%s", buf); /* caution: buf could contain '%' */
|
sysfatal("%s", buf); /* caution: buf could contain '%' */
|
||||||
} else
|
} else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue