/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* rlogin - remote login
*/
#include <sys/resource.h>
#include <priv_utils.h>
#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <setjmp.h>
#include <netdb.h>
#include <fcntl.h>
#include <locale.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <k5-int.h>
#include <profile/prof_int.h>
#include <com_err.h>
#include <kcmd.h>
#include <krb5.h>
/* signal disposition - signal handler or SIG_IGN, SIG_ERR, etc. */
typedef void (*sigdisp_t)(int);
/* needs to be > largest read size */
/* needs to be > largest write size */
static char *krb_realm;
{ "autologin", &krb5auth_flag, 0 },
};
/* Flag set, if -PN / -PO is specified */
/* Flags set, if corres. cmd line options are turned on */
{ "encrypt", &encrypt_flag, 0 },
{ "forward", &fflag, 0 },
{ "forwardable", &Fflag, 0 },
};
static char *rcmdproto;
{ "rcmd_protocol", &rcmdproto, 0 },
};
#ifndef TIOCPKT_WINDOW
#endif /* TIOCPKT_WINDOW */
#ifndef sigmask
#endif
#ifdef DEBUG
#else
#endif /* DEBUG */
static char *host;
static int port_number;
/*
* Note that this list of speeds is shorter than the list of speeds
* supported by termios. This is because we can't be sure other rlogind's
* in the world will correctly cope with values other than what 4.2/4.3BSD
* supported.
*/
static char *speeds[] =
{ "0", "50", "75", "110", "134", "150", "200", "300",
"600", "1200", "1800", "2400", "4800", "9600", "19200",
"38400" };
static void lostpeer(void);
static void sigwinch(int);
static void oob(void);
static void doit(int);
static void catchild(int);
/* LINTED */
static void copytochild(int);
static void writeroob(int);
static int deflflags;
(char)-1, (char)-1, (char)-1 };
(char)-1, (char)-1, (char)-1 };
static void done(int);
static void mode(int);
static int reader(int);
static void writer(void);
static void prf(const char *, ...);
static void sendwindow(void);
static int compat_ioctl(int, int, void *);
static void
{
}
static int
{
}
static void
if (ttcompat) {
/*
* Pop ttcompat module
*/
}
}
static void
usage(void) {
gettext("usage: rlogin [-option] [-option...] "
"[-k realm] [-l username] host"),
gettext(" where option is e, 8, E, L, A, a, K, x, "
"PN / PO, f or F"));
}
/* PRINTFLIKE(0) */
static void
{
usage();
}
static void
usage_forward(void)
{
}
int
{
int c;
int getattr_ret;
char *tmp;
int sock;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
gettext("Insufficient privileges, "
"rlogin must be set-uid root\n"));
exit(1);
}
{
int it;
perror("tcgetattr");
if (it < 0) {
perror("ioctl I_FIND ttcompat");
return (EXIT_FAILURE);
}
if (it == 0) {
perror("ioctl I_PUSH ttcompat");
}
}
}
/*
* Determine command name used to invoke to rlogin(1). Users can
* create links named by a host pointing to the binary and type
* "hostname" to log into that host afterwards.
*/
if (argc < 2)
usage();
argc--;
argv++;
}
} else {
}
switch (c) {
case '8':
break;
case 'A':
break;
#ifdef DEBUG
case 'D':
break;
#endif /* DEBUG */
case 'E':
break;
case 'F':
if (fflag)
Fflag = 1;
break;
case 'f':
if (Fflag)
fflag = 1;
break;
case 'L':
break;
case 'P':
else
"allowed.\n"));
if (rcmdoption_done)
"allowed.\n"));
break;
case 'a':
case 'K':
/*
* Force the remote host to prompt for a password by sending
* a NULL username. These options are mutually exclusive with
* the -A, -x, -f, -F, -k <realm> options.
*/
break;
case 'd':
break;
case 'e': {
int c;
if ((c = *cp) != '\\') {
cmdchar = c;
} else {
c = cp[1];
if (c == '\0' || c == '\\') {
cmdchar = '\\';
} else if (c >= '0' && c <= '7') {
long lc;
"escape character %s too "
"large.\n"), cp);
} else {
"escape character option %s.\n"),
cp);
}
}
break;
}
case 'k':
break;
case 'l':
break;
case 'x':
encrypt_flag = 1;
break;
default:
usage();
}
}
if (argc == 0)
usage();
argc--;
}
if (argc > 0)
usage();
"password entry for user id %d."), uid);
return (EXIT_FAILURE);
}
/*
* If the `-a or -K' options are issued on the cmd line, we reset
* all flags associated with other KRB5 specific options, since
* these options are mutually exclusive with the rest.
*/
if (null_local_username) {
krb5auth_flag = 0;
gettext("Note: The -a (or -K) option nullifies "
"all other Kerberos-specific\noptions "
"you may have used.\n"));
} else if (!krb5auth_flag) {
/* is autologin set in krb5.conf? */
/* don't sweat failure here */
if (!status) {
/*
* note that the call to profile_get_options_boolean
* with autologin_option can affect value of
* krb5auth_flag
*/
}
}
if (krb5auth_flag) {
if (!bsd_context) {
if (status) {
gettext("while initializing krb5"));
return (EXIT_FAILURE);
}
}
/*
* Set up buffers for desread and deswrite.
*/
/*
* Get our local realm to look up local realm options.
*/
if (status) {
gettext("while getting default realm"));
return (EXIT_FAILURE);
}
/*
* Check the realms section in krb5.conf for encryption,
* forward & forwardable info
*/
/*
* Check the appdefaults section
*/
/*
* Set the *_flag variables, if the corresponding *_done are
* set to 1, because we dont want the config file values
* overriding the command line options.
*/
if (encrypt_done)
encrypt_flag = 1;
if (fwd_done) {
fflag = 1;
Fflag = 0;
} else if (fwdable_done) {
Fflag = 1;
fflag = 0;
}
} else {
"KCMD protocol (%s)"), rcmdproto);
return (EXIT_FAILURE);
}
}
if (encrypt_flag && (!krb5_privacy_allowed())) {
"Encryption not supported.\n"));
return (EXIT_FAILURE);
}
}
if (port_number == 0) {
if (krb5auth_flag) {
/*
* If the krb5auth_flag is set (via -A, -f, -F, -k) &
* login, attempt to login with Kerberos. If we fail
* at any step, use the standard rlogin
*/
"eklogin" : "klogin", "tcp");
} else {
}
} else {
}
}
if (cp) {
}
if (getattr_ret == 0) {
/*
* "Be conservative in what we send" -- Only send baud rates
* which at least all 4.x BSD derivatives are known to handle
* correctly.
* NOTE: This code assumes new termios speed values will
* be "higher" speeds.
*/
}
/*
* Only put the terminal speed info in if we have room
* so we don't overflow the buffer, and only if we have
* a speed we recognize.
*/
sizeof (term)) {
}
/* will use SIGUSR1 for window size hack, so hold it off */
/*
* Determine if v4 literal address and if so store it to one
* side. This is to correct the undesired behaviour of rcmd_af
* which converts a passed in v4 literal address to a v4 mapped
* v6 literal address. If it was a v4 literal we then re-assign
* it to host.
*/
if (krb5auth_flag) {
/* Piggy-back forwarding flags on top of authopts; */
/* they will be reset in kcmd */
if (Fflag)
&cred,
NULL, /* No need for sequence number */
NULL, /* No need for server seq # */
0, /* Not any port # */
&kcmd_proto);
if (status != 0) {
/*
* If new protocol requested, we dont fallback to
* less secure ones.
*/
if (kcmd_proto == KCMD_NEW_PROTOCOL) {
"to host %s failed - %s\n"
"Fallback to normal rlogin denied."),
return (EXIT_FAILURE);
}
if (status != -1) {
"to host %s failed - %s,\n"
"trying normal rlogin...\n\n"),
} else {
gettext("trying normal rlogin...\n"));
}
/*
* kcmd() failed, so we have to
* fallback to normal rlogin
*/
krb5auth_flag = 0;
} else {
gettext("connected with Kerberos V5\n"));
/*
* Setup eblock for desread and deswrite.
*/
if (kcmd_proto == KCMD_NEW_PROTOCOL) {
&session_key);
if (status) {
"determining subkey for session");
return (EXIT_FAILURE);
}
if (session_key == NULL) {
"no subkey negotiated for "
"connection");
return (EXIT_FAILURE);
}
}
if (rem < 0)
}
}
/*
* Don't merge this with the "if" statement above because
* "krb5auth_flag" might be set to false inside it.
*/
if (!krb5auth_flag) {
if (rem < 0)
}
/* Never need our privilege again */
sizeof (on)) < 0)
perror("rlogin: setsockopt (SO_DEBUG)");
{
sizeof (int));
}
return (0);
}
static void
{
int atmark;
perror("ioctl TIOCGETP");
perror("ioctl TIOCLGET");
perror("ioctl TIOCGETC");
perror("ioctl TIOCGLTC");
perror("rlogin: fork");
}
if (child == 0) {
mode(1);
}
(void) sleep(1);
}
/*
* We may still own the socket, and may have a pending SIGURG (or might
* receive one soon) that we really want to send to the reader. Set a
* trap that simply copies such signals to the child.
*/
#ifdef F_SETOWN_BUG_FIXED
#else
#endif /* F_SETOWN_BUG_FIXED */
/*
* Of course, if the urgent byte already arrived, allowing SIGURG
* won't get us notification. So, we check to see if we've got
* an urgent byte. If so, force a call to writeroob() to pretend
* we got SIGURG.
*/
if (atmark)
writeroob(0);
}
writer();
}
/*
* Get signal disposition (or signal handler) for a given signal
*/
static sigdisp_t
{
return (act.sa_handler);
}
static void
{
pid_t w;
mode(0);
if (child > 0) {
/* make sure catchild does not snap it up */
/* void */;
}
}
/*
* Copy SIGURGs to the child process.
*/
/* ARGSUSED */
static void
{
}
/*
* This is called when the reader process gets the out-of-band (urgent)
* request to turn on the window-changing protocol.
*/
/* ARGSUSED */
static void
{
int mask;
if (!dosigwinch) {
/*
* Start tracking window size. It doesn't matter which
* order the next two are in, because we'll be unconditionally
* sending a size notification in a moment.
*/
dosigwinch = B_TRUE;
/*
* It would be bad if a SIGWINCH came in between the ioctl
* and sending the data. It could result in the SIGWINCH
* handler sending a good message, and then us sending an
* outdated or inconsistent message.
*
* Instead, if the change is made before the
* ioctl, the sigwinch handler will send a size message
* and we'll send another, identical, one. If the change
* is made after the ioctl, we'll send a message with the
* old value, and then the sigwinch handler will send
* a revised, correct one.
*/
sendwindow();
}
}
/* ARGSUSED */
static void
{
int options;
int error;
for (;;) {
if (error != 0)
return;
return;
continue;
continue;
}
}
/*
* writer: write to remote: 0 -> line.
* ~. terminate
* ~^Z suspend rlogin process.
* ~^Y suspend rlogin process, but leave reader alone.
*/
static void
writer(void)
{
char c;
int n;
for (;;) {
if (n <= 0) {
if (n == 0)
break;
continue;
else {
break;
}
}
/*
* If we're at the beginning of the line
* and recognize a command character, then
* we echo locally. Otherwise, characters
* are echo'd remotely. If the command
* character is doubled, this acts as a
* force and local echo is suppressed.
*/
if (c == cmdchar) {
continue;
}
} else if (local) {
echo(c);
break;
}
echo(c);
stop(c);
continue;
}
if (c != cmdchar) {
"Write error to network: %s"),
break;
}
}
}
if (n == 0)
else
break;
}
c == '\r' || c == '\n';
}
}
static void
echo(char c)
{
char *p = buf;
c &= 0177;
*p++ = cmdchar;
if (c < ' ') {
*p++ = '^';
*p++ = c + '@';
} else if (c == 0177) {
*p++ = '^';
*p++ = '?';
} else
*p++ = c;
*p++ = '\r';
*p++ = '\n';
}
static void
{
mode(0);
mode(1);
sigwinch(0); /* check for size changes */
}
/* ARGSUSED */
static void
{
sendwindow();
}
}
/*
* Send the window size to the server via the magic escape.
* Note: SIGWINCH should be blocked when this is called, lest
* winsize change underneath us and chaos result.
*/
static void
sendwindow(void)
{
obuf[0] = -1;
}
/*
* reader: read from remote: remote -> stdout
*/
static int rcvcnt;
static int rcvstate;
static void
oob(void)
{
int rcvd = 0;
int ret;
timerclear(&tv);
/*
* We may get an extra signal at start up time since we are trying
* to take all precautions not to miss the urgent byte. This
* means we may get here without any urgent data to process, in which
* case we do nothing and just return.
*/
if (ret <= 0)
return;
do {
break;
}
if (!atmark) {
/*
* Urgent data not here yet.
* It may not be possible to send it yet
* if we are blocked for output
* and our input buffer is full.
*/
if (n <= 0)
return;
rcvd += n;
rcvcnt += n;
} else {
/*
* We still haven't gotten to the urgent mark
* and we're out of buffer space. Since we
* must clear our receive window to allow it
* to arrive, we will have to throw away
* these bytes.
*/
if (n <= 0)
return;
}
}
} while (atmark == 0);
switch (errno) {
case EWOULDBLOCK:
/*
* We've reached the urgent mark, so the next
* data to arrive will be the urgent, but it must
* not have arrived yet.
*/
(void) sleep(1);
continue;
default:
return;
}
}
if (mark & TIOCPKT_WINDOW) {
/*
* Let server know about window size changes
*/
}
perror("ioctl TIOCGETP");
perror("ioctl TIOCSETP 1");
perror("ioctl TIOCSETC");
}
perror("ioctl TIOCGETP");
perror("ioctl TIOCSETP 2");
perror("ioctl TIOCSETC");
}
if (mark & TIOCPKT_FLUSHWRITE) {
perror("ioctl TIOCFLUSH");
for (;;) {
perror("ioctl SIOCATMARK");
break;
}
if (atmark)
break;
if (n <= 0) {
if (n < 0)
"Read error from network: %s"),
break;
}
}
/*
* Don't want any pending data to be output,
* so clear the recv buffer.
* If we were hanging on a write when interrupted,
* don't want it to restart. If we were reading,
* restart anyway.
*/
rcvcnt = 0;
}
/*
* If we filled the receive buffer while a read was pending,
* longjmp to the top to restart appropriately. Don't abort
* a pending write, however, or we won't know how much was written.
*/
}
/*
* reader: read from remote: line -> 1
*/
static int
{
/*
* 4.3bsd or later and SunOS 4.0 or later use the posiitive
* pid; otherwise use the negative.
*/
int n, remaining;
perror("fcntl F_SETOWN");
/*
* A SIGURG may have been posted before we were completely forked,
* which means we may not have received it. To insure we do not miss
* any urgent data, we force the signal. The signal hander will be
* able to determine if in fact there is urgent data or not.
*/
for (;;) {
if (n < 0) {
"Write error to terminal: %s"),
return (-1);
}
continue;
}
bufp += n;
}
rcvcnt = 0;
if (rcvcnt == 0)
return (0);
if (rcvcnt < 0) {
continue;
return (-1);
}
}
}
static void
mode(int f)
{
int lflags;
perror("ioctl TIOCGETP");
perror("ioctl TIOCLGET");
switch (f) {
case 0:
break;
case 1:
/* preserve tab delays, but turn off XTABS */
if (litout)
break;
default:
/*NOTREACHED*/
return;
}
perror("ioctl TIOCSLTC");
perror("ioctl TIOCSETC");
perror("ioctl TIOCSETP 3");
perror("ioctl TIOCLSET");
}
/* PRINTFLIKE(0) */
static void
{
}
static void
lostpeer(void)
{
}
static int
{
return (-1);
return (-1);
}
}
}