version 1.37, 2005/04/01 04:06:40 |
version 1.38, 2005/07/04 01:54:10 |
|
|
struct passwd *pw; |
struct passwd *pw; |
struct servent *sp; |
struct servent *sp; |
sigset_t mask, omask; |
sigset_t mask, omask; |
int argoff = 0, asrsh = 0, ch, dflag = 0, nflag = 0, one = 1, rem, uid; |
int argoff = 0, asrsh = 0, ch, dflag = 0, nflag = 0, one = 1, rem; |
char *args, *host = NULL, *user = NULL; |
char *args, *host = NULL, *user = NULL; |
pid_t pid = 0; |
pid_t pid = 0; |
extern char *__progname; |
extern char *__progname; |
|
uid_t uid; |
|
|
/* if called as something other than "rsh", use it as the host name */ |
/* if called as something other than "rsh", use it as the host name */ |
if (strcmp(__progname, "rsh") != 0) |
if (strcmp(__progname, "rsh") != 0) |
|
|
} |
} |
optind += argoff; |
optind += argoff; |
|
|
|
uid = getuid(); |
|
|
/* if haven't gotten a host yet, do so */ |
/* if haven't gotten a host yet, do so */ |
if (!host && !(host = argv[optind++])) |
if (!host && !(host = argv[optind++])) |
usage(); |
usage(); |
|
|
/* if no command, login to remote host via ssh. */ |
/* if no command, login to remote host via ssh. */ |
if (!argv[optind]) { |
if (!argv[optind]) { |
seteuid(getuid()); |
if (setresuid(uid, uid, uid) == -1) |
setuid(getuid()); |
err(1, "setresuid"); |
if (asrsh) |
if (asrsh) |
*argv = "ssh"; |
*argv = "ssh"; |
execv(_PATH_SSH, argv); |
execv(_PATH_SSH, argv); |
|
|
|
|
if (geteuid() != 0) |
if (geteuid() != 0) |
errx(1, "must be setuid root"); |
errx(1, "must be setuid root"); |
if ((pw = getpwuid(uid = getuid())) == NULL) |
if ((pw = getpwuid(uid)) == NULL) |
errx(1, "unknown user ID %u", uid); |
errx(1, "unknown user ID %u", uid); |
if (user == NULL) |
if (user == NULL) |
user = pw->pw_name; |
user = pw->pw_name; |
|
|
if (rfd2 < 0) |
if (rfd2 < 0) |
errx(1, "can't establish stderr"); |
errx(1, "can't establish stderr"); |
|
|
(void)seteuid(uid); |
if (setresuid(uid, uid, uid) == -1) |
(void)setuid(uid); |
err(1, "setresuid"); |
|
|
if (dflag) { |
if (dflag) { |
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, |
if (setsockopt(rem, SOL_SOCKET, SO_DEBUG, &one, |