96 |
|
|
97 |
fromlen = sizeof (from); |
fromlen = sizeof (from); |
98 |
if (getpeername(sockfd, (struct sockaddr *)&from, &fromlen) < 0) { |
if (getpeername(sockfd, (struct sockaddr *)&from, &fromlen) < 0) { |
99 |
(void)fprintf(stderr, |
fprintf(stderr, |
100 |
"rexecd: getpeername: %s\n", strerror(errno)); |
"rexecd: getpeername: %s\n", strerror(errno)); |
101 |
exit(1); |
exit(1); |
102 |
} |
} |
103 |
doit(sockfd, &from); |
doit(sockfd, &from); |
134 |
char buf[BUFSIZ], sig; |
char buf[BUFSIZ], sig; |
135 |
int one = 1; |
int one = 1; |
136 |
|
|
137 |
(void) signal(SIGINT, SIG_DFL); |
signal(SIGINT, SIG_DFL); |
138 |
(void) signal(SIGQUIT, SIG_DFL); |
signal(SIGQUIT, SIG_DFL); |
139 |
(void) signal(SIGTERM, SIG_DFL); |
signal(SIGTERM, SIG_DFL); |
140 |
#ifdef DEBUG |
#ifdef DEBUG |
141 |
{ int t = open(_PATH_TTY, O_RDWR); |
{ int t = open(_PATH_TTY, O_RDWR); |
142 |
if (t >= 0) { |
if (t >= 0) { |
143 |
ioctl(t, TIOCNOTTY, (char *)0); |
ioctl(t, TIOCNOTTY, (char *)0); |
144 |
(void) close(t); |
close(t); |
145 |
} |
} |
146 |
} |
} |
147 |
#endif |
#endif |
151 |
dup2(f, STDERR_FILENO); |
dup2(f, STDERR_FILENO); |
152 |
} |
} |
153 |
|
|
154 |
(void) alarm(60); |
alarm(60); |
155 |
port = 0; |
port = 0; |
156 |
for (;;) { |
for (;;) { |
157 |
char c; |
char c; |
161 |
break; |
break; |
162 |
port = port * 10 + c - '0'; |
port = port * 10 + c - '0'; |
163 |
} |
} |
164 |
(void) alarm(0); |
alarm(0); |
165 |
if (port != 0) { |
if (port != 0) { |
166 |
s = socket(AF_INET, SOCK_STREAM, 0); |
s = socket(AF_INET, SOCK_STREAM, 0); |
167 |
if (s < 0) |
if (s < 0) |
168 |
exit(1); |
exit(1); |
169 |
if (bind(s, (struct sockaddr *)&asin, sizeof (asin)) < 0) |
if (bind(s, (struct sockaddr *)&asin, sizeof (asin)) < 0) |
170 |
exit(1); |
exit(1); |
171 |
(void) alarm(60); |
alarm(60); |
172 |
fromp->sin_port = htons(port); |
fromp->sin_port = htons(port); |
173 |
if (connect(s, (struct sockaddr *)fromp, sizeof (*fromp)) < 0) |
if (connect(s, (struct sockaddr *)fromp, sizeof (*fromp)) < 0) |
174 |
exit(1); |
exit(1); |
175 |
(void) alarm(0); |
alarm(0); |
176 |
} |
} |
177 |
|
|
178 |
user = getstr ("username"); |
user = getstr ("username"); |
193 |
exit(1); |
exit(1); |
194 |
} |
} |
195 |
} |
} |
196 |
if (chdir(pwd->pw_dir) < 0) { |
write(STDERR_FILENO, "\0", 1); |
|
error("No remote directory.\n"); |
|
|
exit(1); |
|
|
} |
|
|
(void) write(STDERR_FILENO, "\0", 1); |
|
197 |
if (port) { |
if (port) { |
198 |
(void) pipe(pv); |
pipe(pv); |
199 |
pid = fork(); |
pid = fork(); |
200 |
if (pid == -1) { |
if (pid == -1) { |
201 |
error("Try again.\n"); |
error("Try again.\n"); |
202 |
exit(1); |
exit(1); |
203 |
} |
} |
204 |
if (pid) { |
if (pid) { |
205 |
(void) close(STDIN_FILENO); |
close(STDIN_FILENO); |
206 |
(void) close(STDOUT_FILENO); |
close(STDOUT_FILENO); |
207 |
(void) close(STDERR_FILENO); |
close(STDERR_FILENO); |
208 |
(void) close(f); (void) close(pv[1]); |
close(f); close(pv[1]); |
209 |
FD_ZERO(&readfrom); |
FD_ZERO(&readfrom); |
210 |
FD_SET(s, &readfrom); |
FD_SET(s, &readfrom); |
211 |
FD_SET(pv[0], &readfrom); |
FD_SET(pv[0], &readfrom); |
216 |
ready = readfrom; |
ready = readfrom; |
217 |
if (pv[0] > maxfd) |
if (pv[0] > maxfd) |
218 |
maxfd = pv[0]; |
maxfd = pv[0]; |
219 |
(void) select(maxfd + 1, (fd_set *)&ready, |
select(maxfd + 1, (fd_set *)&ready, |
220 |
(fd_set *)NULL, (fd_set *)NULL, |
(fd_set *)NULL, (fd_set *)NULL, |
221 |
(struct timeval *)NULL); |
(struct timeval *)NULL); |
222 |
if (FD_ISSET(s, &ready)) { |
if (FD_ISSET(s, &ready)) { |
231 |
shutdown(s, 1+1); |
shutdown(s, 1+1); |
232 |
FD_CLR(pv[0], &readfrom); |
FD_CLR(pv[0], &readfrom); |
233 |
} else |
} else |
234 |
(void) write(s, buf, cc); |
write(s, buf, cc); |
235 |
} |
} |
236 |
} while (FD_ISSET(pv[0], &readfrom) || |
} while (FD_ISSET(pv[0], &readfrom) || |
237 |
FD_ISSET(s, &readfrom)); |
FD_ISSET(s, &readfrom)); |
238 |
exit(0); |
exit(0); |
239 |
} |
} |
240 |
setpgid (0, getpid()); |
setpgid (0, getpid()); |
241 |
(void) close(s); (void)close(pv[0]); |
close(s); |
242 |
|
close(pv[0]); |
243 |
dup2(pv[1], STDERR_FILENO); |
dup2(pv[1], STDERR_FILENO); |
244 |
} |
} |
245 |
if (*pwd->pw_shell == '\0') |
if (*pwd->pw_shell == '\0') |
246 |
pwd->pw_shell = PATH_BSHELL; |
pwd->pw_shell = PATH_BSHELL; |
247 |
if (f > 2) |
if (f > 2) |
248 |
(void) close(f); |
close(f); |
249 |
(void) setegid((gid_t)pwd->pw_gid); |
setegid((gid_t)pwd->pw_gid); |
250 |
(void) setgid((gid_t)pwd->pw_gid); |
setgid((gid_t)pwd->pw_gid); |
251 |
#ifdef HAVE_INITGROUPS |
#ifdef HAVE_INITGROUPS |
252 |
initgroups(pwd->pw_name, pwd->pw_gid); |
initgroups(pwd->pw_name, pwd->pw_gid); |
253 |
#endif |
#endif |
254 |
(void) seteuid((uid_t)pwd->pw_uid); |
setuid((uid_t)pwd->pw_uid); |
255 |
(void) setuid((uid_t)pwd->pw_uid); |
if (chdir(pwd->pw_dir) < 0) { |
256 |
(void)strcat(path, PATH_DEFPATH); |
error("No remote directory.\n"); |
257 |
|
exit(1); |
258 |
|
} |
259 |
|
strcat(path, PATH_DEFPATH); |
260 |
environ = envinit; |
environ = envinit; |
261 |
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6); |
strncat(homedir, pwd->pw_dir, sizeof(homedir)-6); |
262 |
strncat(shell, pwd->pw_shell, sizeof(shell)-7); |
strncat(shell, pwd->pw_shell, sizeof(shell)-7); |