* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)rexecd.c 8.1 (Berkeley) 6/4/93";
if (getpeername(0, (struct sockaddr
*)&from
, &fromlen
) < 0) {
"rexecd: getpeername: %s\n", strerror(errno
));
char username
[20] = "USER=";
char homedir
[64] = "HOME=";
char shell
[64] = "SHELL=";
char path
[sizeof(_PATH_DEFPATH
) + sizeof("PATH=")] = "PATH=";
{homedir
, shell
, path
, username
, 0};
struct sockaddr_in asin
= { AF_INET
};
struct sockaddr_in
*fromp
;
char cmdbuf
[NCARGS
+1], *cp
, *namep
;
int pv
[2], pid
, ready
, readfrom
, cc
;
(void) signal(SIGINT
, SIG_DFL
);
(void) signal(SIGQUIT
, SIG_DFL
);
(void) signal(SIGTERM
, SIG_DFL
);
{ int t
= open(_PATH_TTY
, 2);
ioctl(t
, TIOCNOTTY
, (char *)0);
port
= port
* 10 + c
- '0';
s
= socket(AF_INET
, SOCK_STREAM
, 0);
if (bind(s
, (struct sockaddr
*)&asin
, sizeof (asin
)) < 0)
fromp
->sin_port
= htons(port
);
if (connect(s
, (struct sockaddr
*)fromp
, sizeof (*fromp
)) < 0)
getstr(user
, sizeof(user
), "username");
getstr(pass
, sizeof(pass
), "password");
getstr(cmdbuf
, sizeof(cmdbuf
), "command");
error("Login incorrect.\n");
if (*pwd
->pw_passwd
!= '\0') {
namep
= crypt(pass
, pwd
->pw_passwd
);
if (strcmp(namep
, pwd
->pw_passwd
)) {
error("Password incorrect.\n");
if (chdir(pwd
->pw_dir
) < 0) {
error("No remote directory.\n");
(void) write(2, "\0", 1);
(void) close(0); (void) close(1); (void) close(2);
(void) close(f
); (void) close(pv
[1]);
readfrom
= (1<<s
) | (1<<pv
[0]);
ioctl(pv
[1], FIONBIO
, (char *)&one
);
(void) select(16, (fd_set
*)&ready
,
(fd_set
*)NULL
, (fd_set
*)NULL
,
if (read(s
, &sig
, 1) <= 0)
if (ready
& (1<<pv
[0])) {
cc
= read(pv
[0], buf
, sizeof (buf
));
(void) write(s
, buf
, cc
);
(void) close(s
); (void)close(pv
[0]);
if (*pwd
->pw_shell
== '\0')
pwd
->pw_shell
= _PATH_BSHELL
;
(void) setgid((gid_t
)pwd
->pw_gid
);
initgroups(pwd
->pw_name
, pwd
->pw_gid
);
(void) setuid((uid_t
)pwd
->pw_uid
);
(void)strcat(path
, _PATH_DEFPATH
);
strncat(homedir
, pwd
->pw_dir
, sizeof(homedir
)-6);
strncat(shell
, pwd
->pw_shell
, sizeof(shell
)-7);
strncat(username
, pwd
->pw_name
, sizeof(username
)-6);
cp
= strrchr(pwd
->pw_shell
, '/');
execl(pwd
->pw_shell
, cp
, "-c", cmdbuf
, 0);
(void) sprintf(buf
+1, fmt
, a1
, a2
, a3
);
(void) write(2, buf
, strlen(buf
));
error("%s too long\n", err
);