* Copyright (c) 1983 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)rexecd.c 5.6 (Berkeley) %G%";
struct passwd
*getpwnam();
char *crypt(), *rindex(), *strncat();
if (getpeername(0, &from
, &fromlen
) < 0) {
fprintf(stderr
, "%s: ", argv
[0]);
char username
[20] = "USER=";
char homedir
[64] = "HOME=";
char shell
[64] = "SHELL=";
{homedir
, shell
, "PATH=:/usr/ucb:/bin:/usr/bin", 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("/dev/tty", 2);
ioctl(t
, TIOCNOTTY
, (char *)0);
port
= port
* 10 + c
- '0';
s
= socket(AF_INET
, SOCK_STREAM
, 0);
if (bind(s
, &asin
, sizeof (asin
)) < 0)
fromp
->sin_port
= htons((u_short
)port
);
if (connect(s
, 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, &ready
, (fd_set
*)0,
(fd_set
*)0, (struct timeval
*)0);
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
= "/bin/sh";
(void) setgid((gid_t
)pwd
->pw_gid
);
initgroups(pwd
->pw_name
, pwd
->pw_gid
);
(void) setuid((uid_t
)pwd
->pw_uid
);
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
= rindex(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
);