|
|
1.1 root 1: /* usage: dispatch <ipc args> */
2: /* TODO: connect input to /dev/null if peer wants no output,
3: connect output to logfile if peer wants no input. */
4:
5: #include <string.h>
6: #include <stdio.h>
7: #include <pwd.h>
8: #include <sys/types.h>
9: #include <sys/socket.h>
10: #include <netinet/in.h>
11: #include <netdb.h>
12: #include "../paths.h"
13:
14: int
15: main(int argc, char *argv[])
16: {
17: char c, d;
18: char *args[4];
19: int fd, i, sz;
20: struct sockaddr_in sin;
21: struct hostent *h;
22: char locname[16], remname[16];
23: struct passwd *pw;
24:
25: if (chdir(LDIR) < 0)
26: exit(1);
27:
28: sz = sizeof sin;
29: if (getpeername(0, (struct sockaddr *) &sin, &sz) < 0)
30: exit(1);
31: if (ntohs(sin.sin_port) >= 1024)
32: exit(1);
33: if (!(h = gethostbyaddr(&sin.sin_addr, sizeof sin.sin_addr, sin.sin_family)))
34: exit(1); /* another silent exit */
35: /* execute the rsh authentication protocol */
36: if (read(0, locname, 1) != 1 || locname[0] != '\0')
37: exit(1);
38: for (i = 0; i < sizeof remname; ++i)
39: if (read(0, remname + i, 1) == 1 && remname[i] == '\0')
40: break;
41: if (i == sizeof remname)
42: exit(1);
43: for (i = 0; i < sizeof locname; ++i)
44: if (read(0, locname + i, 1) == 1 && locname[i] == '\0')
45: break;
46: if (i == sizeof locname)
47: exit(1);
48: if (strcmp(locname, remname) != 0)
49: exit(1);
50: if (!(pw = getpwnam(locname)))
51: exit(1);
52: if (ruserok(h->h_name, pw->pw_uid == 0, remname, locname) != 0)
53: exit(1);
54: write(0, "", 1); /* a NUL byte */
55:
56: setgid(pw->pw_gid);
57: setuid(pw->pw_uid);
58:
59: args[1] = h->h_name;
60: args[2] = pw->pw_name;
61: args[3] = 0;
62:
63: if (read(0, &c, 1) != 1)
64: return 1;
65: do
66: if (read(0, &d, 1) != 1)
67: return 1;
68: while (d);
69:
70: dup2(0, 1);
71: fd = open("/dev/null", 1);
72: dup2(fd, 2);
73: if (fd > 2)
74: close(fd);
75:
76: switch (c) {
77: case 's':
78: args[0] = "showq";
79: execv("showq", args);
80: break;
81: case 't':
82: args[0] = "transmit";
83: execv("transmit", args);
84: break;
85: case 'n':
86: args[0] = "notice";
87: execv("notice", args);
88: break;
89: }
90:
91: return 1;
92: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.