7 static int mntnull(int, Rpccall*, Rpccall*);
8 static int mntmnt(int, Rpccall*, Rpccall*);
9 static int mntdump(int, Rpccall*, Rpccall*);
10 static int mntumnt(int, Rpccall*, Rpccall*);
11 static int mntumntall(int, Rpccall*, Rpccall*);
12 static int mntexport(int, Rpccall*, Rpccall*);
29 int staletime = 10*60;
36 for(s=head; s; s=s->next)
43 sysfatal("usage: %s %s [-ns] [-a dialstring] [-c uidmap] [-f srvfile] "
44 "[-T staletime]", argv0, commonopts);
48 mntinit(int argc, char **argv)
54 clog("nfs mount server init, starttime = %lud\n", starttime);
59 srvinit(-1, 0, EARGF(usage()));
62 config = EARGF(usage());
66 srvinit(-1, EARGF(usage()), 0);
76 staletime = atoi(EARGF(usage()));
79 if(argopt(ARGC()) < 0)
80 sysfatal("usage: %s %s [-ns] [-a dialstring] "
81 "[-c uidmap] [-f srvfile] [-T staletime]",
86 if(tries == 0 && head == 0)
87 srvinit(-1, 0, "tcp!fs");
89 panic("can't initialize services");
90 readunixidmaps(config);
94 srvinit(int fd, char *file, char *addr)
96 char fdservice[16], *naddr;
102 s = calloc(1, sizeof(Session));
107 sprint(fdservice, "/fd/%d", s->fd);
108 s->service = strstore(fdservice);
109 chat("fd = %d\n", s->fd);
111 chat("file = \"%s\"\n", file);
113 s->fd = open(file, ORDWR);
115 clog("can't open %s: %r\n", file);
119 chat("addr = \"%s\"\n", addr);
120 naddr = netmkaddr(addr, 0, "9fs");
122 s->fd = dial(naddr, 0, 0, 0);
124 clog("can't dial %s: %r\n", naddr);
131 s->f.msize = Maxfdata+IOHDRSZ;
132 s->f.version = "9P2000";
134 messagesize = IOHDRSZ+s->f.msize;
135 chat("version spec %s size %d\n", s->f.version, s->f.msize);
139 chat("authenticate...");
140 if(authhostowner(s) < 0){
141 clog("auth failed %r\n");
145 chat("attach as none...");
147 s->f.fid = f - s->fids;
150 s->f.aname = s->spec;
151 if(xmesg(s, Tattach)){
152 clog("attach failed\n");
156 xp = xfile(&s->f.qid, s, 1);
160 xf = xfid("none", xp, 1);
162 clog("service=%s uid=%s fid=%zd\n",
163 s->service, xf->uid, xf->urfid - s->fids);
178 mntnull(int n, Rpccall *cmd, Rpccall *reply)
186 mntmnt(int n, Rpccall *cmd, Rpccall *reply)
190 uchar *argptr = cmd->args;
191 uchar *dataptr = reply->results;
198 return garbage(reply, "n too small");
199 argptr += string2S(argptr, &root);
200 if(argptr != &((uchar *)cmd->args)[n])
201 return garbage(reply, "bad count");
202 clog("host=%I, port=%ld, root=\"%.*s\"...",
203 cmd->host, cmd->port, utfnlen(root.s, root.n), root.s);
204 if(auth2unix(&cmd->cred, &au) != 0){
205 chat("auth flavor=%ld, count=%ld\n",
206 cmd->cred.flavor, cmd->cred.count);
207 for(i=0; i<cmd->cred.count; i++)
208 chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
210 clog("auth: bad credentials");
211 return error(reply, 1);
213 clog("auth: %ld %.*s u=%ld g=%ld",
214 au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
215 for(i=0; i<au.gidlen; i++)
216 chat(", %ld", au.gids[i]);
218 if(getdom(cmd->host, dom, sizeof(dom))<0){
219 clog("auth: unknown ip address");
220 return error(reply, 1);
222 chat("dom=%s...", dom);
223 xp = xfroot(root.s, root.n);
226 clog("mntmnt: no fs");
227 return error(reply, 3);
231 dataptr += xp2fhandle(xp, dataptr);
233 return dataptr - (uchar *)reply->results;
237 mntdump(int n, Rpccall *cmd, Rpccall *reply)
240 return garbage(reply, "mntdump");
243 return error(reply, FALSE);
247 mntumnt(int n, Rpccall *cmd, Rpccall *reply)
250 return garbage(reply, "mntumnt");
257 mntumntall(int n, Rpccall *cmd, Rpccall *reply)
260 return garbage(reply, "mntumntall");
262 chat("mntumntall\n");
267 mntexport(int n, Rpccall *cmd, Rpccall *reply)
269 uchar *dataptr = reply->results;
273 chat("mntexport...");
275 return garbage(reply, "mntexport");
276 if(auth2unix(&cmd->cred, &au) != 0){
277 chat("auth flavor=%ld, count=%ld\n",
278 cmd->cred.flavor, cmd->cred.count);
279 for(i=0; i<cmd->cred.count; i++)
280 chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
284 chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s);
291 PPTR(au.mach.s, au.mach.n);
296 return dataptr - (uchar *)reply->results;
300 xfroot(char *name, int n)
307 chat("xfroot: %.*s...", utfnlen(name, n), name);
308 if(n == 1 && name[0] == '/')
310 for(s=head; s; s=s->next){
311 if(strncmp(name, s->service, n) == 0)
313 p = strrchr(s->service, '!'); /* for -a tcp!foo */
314 if(p && strncmp(name, p+1, n) == 0)
316 p = strrchr(s->service, '/'); /* for -f /srv/foo */
317 if(p && strncmp(name, p+1, n) == 0)