]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/ip/rexexec.c
etheriwl: don't break controller on command flush timeout
[plan9front.git] / sys / src / cmd / ip / rexexec.c
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <auth.h>
5
6 /*
7  * called by listen as rexexec rexexec net dir ...
8  */
9 void
10 main(int argc, char **argv)
11 {
12         char buf[8192];
13         int n, nn;
14         AuthInfo *ai;
15         Dir nd;
16
17         ARGBEGIN{
18         }ARGEND;
19
20         ai = auth_proxy(0, auth_getkey, "proto=p9any role=server");
21         if(ai == nil)
22                 sysfatal("auth_proxy: %r");
23         if(strcmp(ai->cuid, "none") == 0)
24                 sysfatal("rexexec by none disallowed");
25         if(auth_chuid(ai, nil) < 0)
26                 sysfatal("auth_chuid: %r");
27
28         /* chown network connection */
29         nulldir(&nd);
30         nd.mode = 0660;
31         nd.uid = ai->cuid;
32         dirfwstat(0, &nd);
33
34         auth_freeAI(ai);
35
36         n = 0;
37         do {
38                 nn = read(0, buf+n, 1);
39                 if(nn <= 0)
40                         sysfatal("can't read command");
41                 n += nn;
42                 if(n == sizeof buf)
43                         buf[n-1] = '\0';
44         } while (buf[n-1] != '\0');
45
46         putenv("service", "rx");
47         execl("/bin/rc", "rc", "-lc", buf, nil);
48         sysfatal("can't exec rc");
49 }