12 static char *encprotos[] = {
21 char *ealgs = "rc4_256 sha1";
22 int encproto = Encnone;
28 int connectez(char*, char*);
29 void sysfatal(char*, ...);
31 int filter(int, char *, char *);
34 catcher(void *v, char *msg)
37 if(strcmp(msg, "alarm") == 0)
43 lookup(char *s, char *l[])
47 for (i = 0; l[i] != 0; i++)
48 if (strcmp(l[i], s) == 0)
58 for(i=0; i<strlen(addr); i++){
66 threadmain(int argc, char **argv)
68 char *mntpt, *srvpost, srvfile[64];
81 if ((encproto = lookup(EARGF(usage()), encprotos)) < 0)
85 ealgs = EARGF(usage());
86 if(*ealgs == 0 || strcmp(ealgs, "clear") == 0)
90 keyspec = EARGF(usage());
93 filterp = unsharp("#9/bin/aan");
96 srvpost = EARGF(usage());
102 mntpt = 0; /* to shut up compiler */
114 if(encproto != Encnone)
115 sysfatal("%s: tls and ssl have not yet been implemented", argv[0]);
117 threadnotify(catcher, 1);
120 fd = connectez(argv[0], argv[1]);
122 fprint(fd, "impo %s %s\n", filterp? "aan": "nofilter",
123 encprotos[encproto]);
126 fd = filter(fd, filterp, argv[0]);
129 srvpost = srvname(argv[0]);
130 sprint(srvfile, "%s", srvpost);
132 if(post9pservice(fd, srvfile, mntpt) < 0)
133 sysfatal("can't post %s: %r", argv[1]);
139 /* the name "connect" is special */
141 connectez(char *system, char *tree)
143 char buf[ERRMAX], *na;
147 na = netmkaddr(system, "tcp", "exportfs");
148 threadsetname("dial %s", na);
149 if((fd = dial(na, nil, nil, nil)) < 0)
150 sysfatal("can't dial %s: %r", system);
154 threadsetname("auth_proxy auth_getkey proto=%q role=client %s",
156 ai = auth_proxy(fd, auth_getkey, "proto=%q role=client %s",
159 sysfatal("%r: %s", system);
162 threadsetname("writing tree name %s", tree);
163 n = write(fd, tree, strlen(tree));
165 sysfatal("can't write tree: %r");
167 strcpy(buf, "can't read tree");
169 threadsetname("awaiting OK for %s", tree);
170 n = read(fd, buf, sizeof buf - 1);
171 if(n!=2 || buf[0]!='O' || buf[1]!='K'){
173 sysfatal("timed out connecting to %s", na);
174 buf[sizeof buf - 1] = '\0';
175 sysfatal("bad remote tree: %s", buf);
184 fprint(2, "usage: 9import [-A] [-E clear|ssl|tls] "
185 "[-e 'crypt auth'|clear] [-k keypattern] [-p] [-s srv] host remotefs [mountpoint]\n");
186 threadexitsall("usage");
189 /* Network on fd1, mount driver on fd0 */
191 filter(int fd, char *cmd, char *host)
194 char newport[256], buf[256], *s;
195 char *argv[16], *file, *pbuf;
197 if ((len = read(fd, newport, sizeof newport - 1)) < 0)
198 sysfatal("filter: cannot write port; %r");
201 if ((s = strchr(newport, '!')) == nil)
202 sysfatal("filter: illegally formatted port %s", newport);
204 strecpy(buf, buf+sizeof buf, netmkaddr(host, "tcp", "0"));
205 pbuf = strrchr(buf, '!');
206 strecpy(pbuf, buf+sizeof buf, s);
209 fprint(2, "filter: remote port %s\n", newport);
211 argc = tokenize(cmd, argv, nelem(argv)-2);
213 sysfatal("filter: empty command");
218 if (s = strrchr(argv[0], '/'))
222 sysfatal("pipe: %r");
224 switch(rfork(RFNOWAIT|RFPROC|RFFDG)) {
226 sysfatal("rfork record module: %r");
233 sysfatal("exec record module: %r");