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=%ld\n",
163 s->service, xf->uid, xf->urfid - s->fids);
178 mntnull(int n, Rpccall *cmd, Rpccall *reply)
186 Str2str(String s, char *buf, int nbuf)
192 memmove(buf, s.s, i);
198 mntmnt(int n, Rpccall *cmd, Rpccall *reply)
202 uchar *argptr = cmd->args;
203 uchar *dataptr = reply->results;
210 return garbage(reply, "n too small");
211 argptr += string2S(argptr, &root);
212 if(argptr != &((uchar *)cmd->args)[n])
213 return garbage(reply, "bad count");
214 clog("host=%I, port=%ld, root=\"%.*s\"...",
215 cmd->host, cmd->port, utfnlen(root.s, root.n), root.s);
216 if(auth2unix(&cmd->cred, &au) != 0){
217 chat("auth flavor=%ld, count=%ld\n",
218 cmd->cred.flavor, cmd->cred.count);
219 for(i=0; i<cmd->cred.count; i++)
220 chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
222 clog("auth: bad credentials");
223 return error(reply, 1);
225 clog("auth: %ld %.*s u=%ld g=%ld",
226 au.stamp, utfnlen(au.mach.s, au.mach.n), au.mach.s, au.uid, au.gid);
227 for(i=0; i<au.gidlen; i++)
228 chat(", %ld", au.gids[i]);
230 if(getdom(cmd->host, dom, sizeof(dom))<0){
231 clog("auth: unknown ip address");
232 return error(reply, 1);
234 chat("dom=%s...", dom);
235 xp = xfroot(root.s, root.n);
238 clog("mntmnt: no fs");
239 return error(reply, 3);
243 dataptr += xp2fhandle(xp, dataptr);
245 return dataptr - (uchar *)reply->results;
249 mntdump(int n, Rpccall *cmd, Rpccall *reply)
252 return garbage(reply, "mntdump");
255 return error(reply, FALSE);
259 mntumnt(int n, Rpccall *cmd, Rpccall *reply)
262 return garbage(reply, "mntumnt");
269 mntumntall(int n, Rpccall *cmd, Rpccall *reply)
272 return garbage(reply, "mntumntall");
274 chat("mntumntall\n");
279 mntexport(int n, Rpccall *cmd, Rpccall *reply)
281 uchar *dataptr = reply->results;
285 chat("mntexport...");
287 return garbage(reply, "mntexport");
288 if(auth2unix(&cmd->cred, &au) != 0){
289 chat("auth flavor=%ld, count=%ld\n",
290 cmd->cred.flavor, cmd->cred.count);
291 for(i=0; i<cmd->cred.count; i++)
292 chat(" %.2ux", ((uchar *)cmd->cred.data)[i]);
296 chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s);
303 PPTR(au.mach.s, au.mach.n);
308 return dataptr - (uchar *)reply->results;
312 xfroot(char *name, int n)
319 chat("xfroot: %.*s...", utfnlen(name, n), name);
320 if(n == 1 && name[0] == '/')
322 for(s=head; s; s=s->next){
323 if(strncmp(name, s->service, n) == 0)
325 p = strrchr(s->service, '!'); /* for -a tcp!foo */
326 if(p && strncmp(name, p+1, n) == 0)
328 p = strrchr(s->service, '/'); /* for -f /srv/foo */
329 if(p && strncmp(name, p+1, n) == 0)