Very large style makeover.

1) ANSIfy.
2) Clean up ifdefs so that
   a) ones that never/always apply are appropriately either
      fully removed, or just the #if junk is removed.
   b) change #if defined(FOO) for appropiate values of FOO.
      (currently AUTHENTICATION and ENCRYPTION)
3) WARNS=2 fixing
4) GC other unused stuff

This code can now be unifdef(1)ed to make non-crypto telnet.


git-svn-id: http://svn0.us-east.freebsd.org/base/head/contrib/telnet@87139 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
markm 2001-11-30 21:06:38 +00:00
parent 3352bb6256
commit 820d180830
45 changed files with 2496 additions and 5344 deletions

View File

@ -64,7 +64,7 @@
#define SYNCH 242 /* for telfunc calls */
#ifdef TELCMDS
char *telcmds[] = {
const char *telcmds[] = {
"EOF", "SUSP", "ABORT", "EOR",
"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
@ -126,7 +126,7 @@ extern char *telcmds[];
#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
#ifdef TELOPTS
char *telopts[NTELOPTS+1] = {
const char *telopts[NTELOPTS+1] = {
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
@ -226,7 +226,7 @@ char *telopts[NTELOPTS+1] = {
0
#ifdef SLC_NAMES
char *slc_names[] = {
const char *slc_names[] = {
SLC_NAMELIST
};
#else
@ -287,7 +287,7 @@ extern char *slc_names[];
#define AUTHTYPE_TEST 99
#ifdef AUTH_NAMES
char *authtype_names[] = {
const char *authtype_names[] = {
"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", NULL, "SRA",
0
};
@ -318,12 +318,12 @@ extern char *authtype_names[];
#define ENCTYPE_CNT 3
#ifdef ENCRYPT_NAMES
char *encrypt_names[] = {
const char *encrypt_names[] = {
"IS", "SUPPORT", "REPLY", "START", "END",
"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
0
};
char *enctype_names[] = {
const char *enctype_names[] = {
"ANY", "DES_CFB64", "DES_OFB64",
0
};

View File

@ -62,48 +62,58 @@
#endif
#endif
#if defined(AUTHENTICATION)
Authenticator *findauthenticator P((int, int));
#ifdef AUTHENTICATION
void auth_init P((char *, int));
int auth_cmd P((int, char **));
void auth_request P((void));
void auth_send P((unsigned char *, int));
void auth_send_retry P((void));
void auth_is P((unsigned char *, int));
void auth_reply P((unsigned char *, int));
void auth_finished P((Authenticator *, int));
int auth_wait P((char *));
void auth_disable_name P((char *));
void auth_gen_printsub P((unsigned char *, int, unsigned char *, int));
void auth_name P((unsigned char *, int));
void auth_printsub P((unsigned char *, int, unsigned char *, int));
int auth_sendname P((unsigned char *, int));
void auth_encrypt_user P((char *));
Authenticator *findauthenticator(int, int);
void auth_init(const char *, int);
int auth_cmd(int, char **);
void auth_request(void);
void auth_send(unsigned char *, int);
void auth_send_retry(void);
void auth_is(unsigned char *, int);
void auth_reply(unsigned char *, int);
void auth_finished(Authenticator *, int);
int auth_wait(char *);
void auth_disable_name(char *);
void auth_gen_printsub(unsigned char *, int, unsigned char *, int);
void auth_name(unsigned char *, int);
void auth_printsub(unsigned char *, int, unsigned char *, int);
int auth_sendname(unsigned char *, int);
void auth_encrypt_user(char *);
int auth_disable(char *);
int auth_enable(char *);
int auth_togdebug(int);
int auth_status(void);
int getauthmask(char *, int *);
#ifdef KRB4
int kerberos4_init P((Authenticator *, int));
int kerberos4_send P((Authenticator *));
void kerberos4_is P((Authenticator *, unsigned char *, int));
void kerberos4_reply P((Authenticator *, unsigned char *, int));
int kerberos4_status P((Authenticator *, char *, int));
void kerberos4_printsub P((unsigned char *, int, unsigned char *, int));
int kerberos4_init(Authenticator *, int);
int kerberos4_send(Authenticator *);
void kerberos4_is(Authenticator *, unsigned char *, int);
void kerberos4_reply(Authenticator *, unsigned char *, int);
int kerberos4_status(Authenticator *, char *, int);
void kerberos4_printsub(unsigned char *, int, unsigned char *, int);
#endif
#ifdef KRB5
int kerberos5_init P((Authenticator *, int));
int kerberos5_send P((Authenticator *));
void kerberos5_is P((Authenticator *, unsigned char *, int));
void kerberos5_reply P((Authenticator *, unsigned char *, int));
int kerberos5_status P((Authenticator *, char *, int));
void kerberos5_printsub P((unsigned char *, int, unsigned char *, int));
int kerberos5_init(Authenticator *, int);
int kerberos5_send_mutual(Authenticator *);
int kerberos5_send_oneway(Authenticator *);
void kerberos5_is(Authenticator *, unsigned char *, int);
void kerberos5_reply(Authenticator *, unsigned char *, int);
int kerberos5_status(Authenticator *, char *, int level);
void kerberos5_printsub(unsigned char *, int, unsigned char *, int);
#endif
#ifdef SRA
int sra_init P((Authenticator *, int));
int sra_send P((Authenticator *));
void sra_is P((Authenticator *, unsigned char *, int));
void sra_reply P((Authenticator *, unsigned char *, int));
int sra_status P((Authenticator *, char *, int));
void sra_printsub P((unsigned char *, int, unsigned char *, int));
int sra_init(Authenticator *, int);
int sra_send(Authenticator *);
void sra_is(Authenticator *, unsigned char *, int);
void sra_reply(Authenticator *, unsigned char *, int);
int sra_status(Authenticator *, char *, int);
void sra_printsub(unsigned char *, int, unsigned char *, int);
#endif
#endif

View File

@ -34,6 +34,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -61,28 +62,22 @@ static const char sccsid[] = "@(#)auth.c 8.3 (Berkeley) 5/30/95";
*/
#if defined(AUTHENTICATION)
#include <stdio.h>
#ifdef AUTHENTICATION
#define AUTH_NAMES
#include <sys/types.h>
#include <signal.h>
#define AUTH_NAMES
#include <arpa/telnet.h>
#ifdef __STDC__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include <unistd.h>
#include <arpa/telnet.h>
#include "encrypt.h"
#include "auth.h"
#include "misc-proto.h"
#include "auth-proto.h"
#define typemask(x) (1<<((x)-1))
#define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
#ifdef KRB4_ENCPWD
extern krb4encpwd_init();
@ -103,7 +98,7 @@ extern rsaencpwd_printsub();
#endif
int auth_debug_mode = 0;
static char *Name = "Noname";
static const char *Name = "Noname";
static int Server = 0;
static Authenticator *authenticated = 0;
static int authenticating = 0;
@ -120,27 +115,11 @@ void auth_encrypt_user(char *name);
* in priority order, i.e. try the first one first.
*/
Authenticator authenticators[] = {
#ifdef SPX
{ AUTHTYPE_SPX, AUTH_WHO_CLIENT|AUTH_HOW_MUTUAL,
spx_init,
spx_send,
spx_is,
spx_reply,
spx_status,
spx_printsub },
{ AUTHTYPE_SPX, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
spx_init,
spx_send,
spx_is,
spx_reply,
spx_status,
spx_printsub },
#endif
#ifdef KRB5
# ifdef ENCRYPTION
{ AUTHTYPE_KERBEROS_V5, AUTH_WHO_CLIENT|AUTH_HOW_MUTUAL,
kerberos5_init,
kerberos5_send,
kerberos5_send_mutual,
kerberos5_is,
kerberos5_reply,
kerberos5_status,
@ -148,7 +127,7 @@ Authenticator authenticators[] = {
# endif /* ENCRYPTION */
{ AUTHTYPE_KERBEROS_V5, AUTH_WHO_CLIENT|AUTH_HOW_ONE_WAY,
kerberos5_init,
kerberos5_send,
kerberos5_send_oneway,
kerberos5_is,
kerberos5_reply,
kerberos5_status,
@ -200,18 +179,16 @@ Authenticator authenticators[] = {
sra_printsub },
#endif
{ 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
static Authenticator NoAuth = { 0 };
static Authenticator NoAuth = { 0, 0, 0, 0, 0, 0, 0, 0 };
static int i_support = 0;
static int i_wont_support = 0;
Authenticator *
findauthenticator(type, way)
int type;
int way;
Authenticator *
findauthenticator(int type, int way)
{
Authenticator *ap = authenticators;
@ -220,10 +197,8 @@ findauthenticator(type, way)
return(ap->type ? ap : 0);
}
void
auth_init(name, server)
char *name;
int server;
void
auth_init(const char *name, int server)
{
Authenticator *ap = authenticators;
@ -248,9 +223,8 @@ auth_init(name, server)
}
}
void
auth_disable_name(name)
char *name;
void
auth_disable_name(char *name)
{
int x;
for (x = 0; x < AUTHTYPE_CNT; ++x) {
@ -261,12 +235,10 @@ auth_disable_name(name)
}
}
int
getauthmask(type, maskp)
char *type;
int *maskp;
int
getauthmask(char *type, int *maskp)
{
register int x;
int x;
if (AUTHTYPE_NAME(0) && !strcasecmp(type, AUTHTYPE_NAME(0))) {
*maskp = -1;
@ -282,24 +254,20 @@ getauthmask(type, maskp)
return(0);
}
int
auth_enable(type)
char *type;
int
auth_enable(char *type)
{
return(auth_onoff(type, 1));
}
int
auth_disable(type)
char *type;
int
auth_disable(char *type)
{
return(auth_onoff(type, 0));
}
int
auth_onoff(type, on)
char *type;
int on;
int
auth_onoff(char *type, int on)
{
int i, mask = -1;
Authenticator *ap;
@ -329,9 +297,8 @@ auth_onoff(type, on)
return(1);
}
int
auth_togdebug(on)
int on;
int
auth_togdebug(int on)
{
if (on < 0)
auth_debug_mode ^= 1;
@ -341,8 +308,8 @@ auth_togdebug(on)
return(1);
}
int
auth_status()
int
auth_status(void)
{
Authenticator *ap;
int i, mask;
@ -368,8 +335,8 @@ auth_status()
* This routine is called by the server to start authentication
* negotiation.
*/
void
auth_request()
void
auth_request(void)
{
static unsigned char str_request[64] = { IAC, SB,
TELOPT_AUTHENTICATION,
@ -408,10 +375,8 @@ auth_request()
* with KERBEROS instead of LOGIN (which is against what the
* protocol says)) you will have to hack this code...
*/
void
auth_send(data, cnt)
unsigned char *data;
int cnt;
void
auth_send(unsigned char *data, int cnt)
{
Authenticator *ap;
static unsigned char str_none[] = { IAC, SB, TELOPT_AUTHENTICATION,
@ -435,7 +400,7 @@ auth_send(data, cnt)
*/
if (data < _auth_send_data ||
data > _auth_send_data + sizeof(_auth_send_data)) {
auth_send_cnt = cnt > sizeof(_auth_send_data)
auth_send_cnt = (size_t)cnt > sizeof(_auth_send_data)
? sizeof(_auth_send_data)
: cnt;
memmove((void *)_auth_send_data, (void *)data, auth_send_cnt);
@ -484,18 +449,10 @@ auth_send(data, cnt)
if (auth_debug_mode)
printf(">>>%s: Sent failure message\r\n", Name);
auth_finished(0, AUTH_REJECT);
#ifdef KANNAN
/*
* We requested strong authentication, however no mechanisms worked.
* Therefore, exit on client end.
*/
printf("Unable to securely authenticate user ... exit\n");
exit(0);
#endif /* KANNAN */
}
void
auth_send_retry()
void
auth_send_retry(void)
{
/*
* if auth_send_cnt <= 0 then auth_send will end up rejecting
@ -504,10 +461,8 @@ auth_send_retry()
auth_send(auth_send_data, auth_send_cnt);
}
void
auth_is(data, cnt)
unsigned char *data;
int cnt;
void
auth_is(unsigned char *data, int cnt)
{
Authenticator *ap;
@ -527,10 +482,8 @@ auth_is(data, cnt)
Name, *data);
}
void
auth_reply(data, cnt)
unsigned char *data;
int cnt;
void
auth_reply(unsigned char *data, int cnt)
{
Authenticator *ap;
@ -545,10 +498,8 @@ auth_reply(data, cnt)
Name, *data);
}
void
auth_name(data, cnt)
unsigned char *data;
int cnt;
void
auth_name(unsigned char *data, int cnt)
{
unsigned char savename[256];
@ -557,7 +508,7 @@ auth_name(data, cnt)
printf(">>>%s: Empty name in NAME\r\n", Name);
return;
}
if (cnt > sizeof(savename) - 1) {
if ((size_t)cnt > sizeof(savename) - 1) {
if (auth_debug_mode)
printf(">>>%s: Name in NAME (%d) exceeds %d length\r\n",
Name, cnt, sizeof(savename)-1);
@ -570,15 +521,13 @@ auth_name(data, cnt)
auth_encrypt_user(savename);
}
int
auth_sendname(cp, len)
unsigned char *cp;
int len;
int
auth_sendname(unsigned char *cp, int len)
{
static unsigned char str_request[256+6]
= { IAC, SB, TELOPT_AUTHENTICATION, TELQUAL_NAME, };
register unsigned char *e = str_request + 4;
register unsigned char *ee = &str_request[sizeof(str_request)-2];
unsigned char *e = str_request + 4;
unsigned char *ee = &str_request[sizeof(str_request)-2];
while (--len >= 0) {
if ((*e++ = *cp++) == IAC)
@ -593,27 +542,23 @@ auth_sendname(cp, len)
return(1);
}
void
auth_finished(ap, result)
Authenticator *ap;
int result;
void
auth_finished(Authenticator *ap, int result)
{
if (!(authenticated = ap))
authenticated = &NoAuth;
validuser = result;
}
/* ARGSUSED */
static void
auth_intr(sig)
int sig;
/* ARGSUSED */
static void
auth_intr(int sig __unused)
{
auth_finished(0, AUTH_REJECT);
}
int
auth_wait(name)
char *name;
int
auth_wait(char *name)
{
if (auth_debug_mode)
printf(">>>%s: in auth_wait.\r\n", Name);
@ -644,17 +589,8 @@ auth_wait(name)
return(validuser);
}
void
auth_debug(mode)
int mode;
{
auth_debug_mode = mode;
}
void
auth_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
auth_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
Authenticator *ap;
@ -664,12 +600,10 @@ auth_printsub(data, cnt, buf, buflen)
auth_gen_printsub(data, cnt, buf, buflen);
}
void
auth_gen_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
auth_gen_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
register unsigned char *cp;
unsigned char *cp;
unsigned char tbuf[16];
cnt -= 3;

View File

@ -63,23 +63,15 @@
#define AUTH_USER 3 /* We know he name */
#define AUTH_VALID 4 /* We know him, and he needs no password */
#if !defined(P)
#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif
#endif
typedef struct XauthP {
int type;
int way;
int (*init) P((struct XauthP *, int));
int (*send) P((struct XauthP *));
void (*is) P((struct XauthP *, unsigned char *, int));
void (*reply) P((struct XauthP *, unsigned char *, int));
int (*status) P((struct XauthP *, char *, int));
void (*printsub) P((unsigned char *, int, unsigned char *, int));
int (*init)(struct XauthP *, int);
int (*send)(struct XauthP *);
void (*is)(struct XauthP *, unsigned char *, int);
void (*reply)(struct XauthP *, unsigned char *, int);
int (*status)(struct XauthP *, char *, int);
void (*printsub)(unsigned char *, int, unsigned char *, int);
} Authenticator;
#include "auth-proto.h"

View File

@ -62,68 +62,72 @@
#endif
#ifdef ENCRYPTION
void encrypt_init P((char *, int));
Encryptions *findencryption P((int));
void encrypt_send_supprt P((void));
void encrypt_auto P((int));
void decrypt_auto P((int));
void encrypt_is P((unsigned char *, int));
void encrypt_reply P((unsigned char *, int));
void encrypt_start_input P((int));
void encrypt_session_key P((Session_Key *, int));
void encrypt_end_input P((void));
void encrypt_start_output P((int));
void encrypt_end_output P((void));
void encrypt_send_request_start P((void));
void encrypt_send_request_end P((void));
void encrypt_send_end P((void));
void encrypt_wait P((void));
void encrypt_send_support P((void));
void encrypt_send_keyid P((int, unsigned char *, int, int));
void encrypt_start P((unsigned char *, int));
void encrypt_end P((void));
void encrypt_support P((unsigned char *, int));
void encrypt_request_start P((unsigned char *, int));
void encrypt_request_end P((void));
void encrypt_enc_keyid P((unsigned char *, int));
void encrypt_dec_keyid P((unsigned char *, int));
void encrypt_printsub P((unsigned char *, int, unsigned char *, int));
int net_write P((unsigned char *, int));
void encrypt_init(const char *, int);
Encryptions *findencryption(int);
void encrypt_send_supprt(void);
void encrypt_auto(int);
void decrypt_auto(int);
void encrypt_is(unsigned char *, int);
void encrypt_reply(unsigned char *, int);
void encrypt_start_input(int);
void encrypt_session_key(Session_Key *, int);
void encrypt_end_input(void);
void encrypt_start_output(int);
void encrypt_end_output(void);
void encrypt_send_request_start(void);
void encrypt_send_request_end(void);
void encrypt_send_end(void);
void encrypt_wait(void);
void encrypt_send_support(void);
void encrypt_send_keyid(int, const char *, int, int);
void encrypt_start(unsigned char *, int);
void encrypt_end(void);
void encrypt_support(unsigned char *, int);
void encrypt_request_start(unsigned char *, int);
void encrypt_request_end(void);
void encrypt_enc_keyid(unsigned char *, int);
void encrypt_dec_keyid(unsigned char *, int);
void encrypt_printsub(unsigned char *, int, unsigned char *, int);
void encrypt_gen_printsub(unsigned char *, int, unsigned char *, int);
void encrypt_display(void);
#ifndef TELENTD
int encrypt_cmd P((int, char **));
void encrypt_display P((void));
#endif
void fb64_printsub(unsigned char *, int, unsigned char *, int, const char *);
#ifdef DES_ENCRYPTION
void krbdes_encrypt P((unsigned char *, int));
int krbdes_decrypt P((int));
int krbdes_is P((unsigned char *, int));
int krbdes_reply P((unsigned char *, int));
void krbdes_init P((int));
int krbdes_start P((int, int));
void krbdes_session P((Session_Key *, int));
void krbdes_printsub P((unsigned char *, int, unsigned char *, int));
int EncryptEnable(char *, char *);
int EncryptDisable(char *, char *);
int EncryptStatus(void);
int EncryptDebug(int);
int EncryptVerbose(int);
int EncryptAutoEnc(int);
int EncryptAutoDec(int);
void cfb64_encrypt P((unsigned char *, int));
int cfb64_decrypt P((int));
void cfb64_init P((int));
int cfb64_start P((int, int));
int cfb64_is P((unsigned char *, int));
int cfb64_reply P((unsigned char *, int));
void cfb64_session P((Session_Key *, int));
int cfb64_keyid P((int, unsigned char *, int *));
void cfb64_printsub P((unsigned char *, int, unsigned char *, int));
void krbdes_encrypt(unsigned char *, int);
int krbdes_decrypt(int);
int krbdes_is(unsigned char *, int);
int krbdes_reply(unsigned char *, int);
void krbdes_init(int);
int krbdes_start(int, int);
void krbdes_session(Session_Key *, int);
void krbdes_printsub(unsigned char *, int, unsigned char *, int);
void ofb64_encrypt P((unsigned char *, int));
int ofb64_decrypt P((int));
void ofb64_init P((int));
int ofb64_start P((int, int));
int ofb64_is P((unsigned char *, int));
int ofb64_reply P((unsigned char *, int));
void ofb64_session P((Session_Key *, int));
int ofb64_keyid P((int, unsigned char *, int *));
void ofb64_printsub P((unsigned char *, int, unsigned char *, int));
#endif /* DES_ENCRYPTION */
void cfb64_encrypt(unsigned char *, int);
int cfb64_decrypt(int);
void cfb64_init(int);
int cfb64_start(int, int);
int cfb64_is(unsigned char *, int);
int cfb64_reply(unsigned char *, int);
void cfb64_session(Session_Key *, int);
int cfb64_keyid(int, unsigned char *, int *);
void cfb64_printsub(unsigned char *, int, unsigned char *, int);
void ofb64_encrypt(unsigned char *, int);
int ofb64_decrypt(int);
void ofb64_init(int);
int ofb64_start(int, int);
int ofb64_is(unsigned char *, int);
int ofb64_reply(unsigned char *, int);
void ofb64_session(Session_Key *, int);
int ofb64_keyid(int, unsigned char *, int *);
void ofb64_printsub(unsigned char *, int, unsigned char *, int);
#endif /* ENCRYPTION */

View File

@ -34,6 +34,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -42,15 +43,12 @@ static const char sccsid[] = "@(#)enc_des.c 8.3 (Berkeley) 5/30/95";
#ifdef ENCRYPTION
# ifdef AUTHENTICATION
# ifdef DES_ENCRYPTION
#include <arpa/telnet.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#include <openssl/des.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encrypt.h"
#include "key-proto.h"
#include "misc-proto.h"
@ -92,7 +90,7 @@ struct fb {
static struct fb fb[2];
struct keyidlist {
char *keyid;
const char *keyid;
int keyidlen;
char *key;
int keylen;
@ -127,9 +125,8 @@ static void fb64_session P((Session_Key *, int, struct fb *));
void fb64_stream_key P((Block, struct stinfo *));
int fb64_keyid P((int, unsigned char *, int *, struct fb *));
void
cfb64_init(server)
int server;
void
cfb64_init(int server __unused)
{
fb64_init(&fb[CFB]);
fb[CFB].fb_feed[4] = ENCTYPE_DES_CFB64;
@ -137,9 +134,8 @@ cfb64_init(server)
fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, CFB);
}
void
ofb64_init(server)
int server;
void
ofb64_init(int server __unused)
{
fb64_init(&fb[OFB]);
fb[OFB].fb_feed[4] = ENCTYPE_DES_OFB64;
@ -147,9 +143,8 @@ ofb64_init(server)
fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, OFB);
}
void
fb64_init(fbp)
register struct fb *fbp;
void
fb64_init(struct fb *fbp)
{
memset((void *)fbp, 0, sizeof(*fbp));
fbp->state[0] = fbp->state[1] = FAILED;
@ -167,30 +162,24 @@ fb64_init(fbp)
* 2: Not yet. Other things (like getting the key from
* Kerberos) have to happen before we can continue.
*/
int
cfb64_start(dir, server)
int dir;
int server;
int
cfb64_start(int dir, int server)
{
return(fb64_start(&fb[CFB], dir, server));
}
int
ofb64_start(dir, server)
int dir;
int server;
int
ofb64_start(int dir, int server)
{
return(fb64_start(&fb[OFB], dir, server));
}
static int
fb64_start(fbp, dir, server)
struct fb *fbp;
int dir;
int server;
static int
fb64_start(struct fb *fbp, int dir, int server __unused)
{
int x;
size_t x;
unsigned char *p;
register int state;
int state;
switch (dir) {
case DIR_DECRYPT:
@ -250,29 +239,23 @@ fb64_start(fbp, dir, server)
* 0: Successful, initial negotiation all done.
* 1: successful, negotiation not done yet.
*/
int
cfb64_is(data, cnt)
unsigned char *data;
int cnt;
int
cfb64_is(unsigned char *data, int cnt)
{
return(fb64_is(data, cnt, &fb[CFB]));
}
int
ofb64_is(data, cnt)
unsigned char *data;
int cnt;
int
ofb64_is(unsigned char *data, int cnt)
{
return(fb64_is(data, cnt, &fb[OFB]));
}
int
fb64_is(data, cnt, fbp)
unsigned char *data;
int cnt;
struct fb *fbp;
int
fb64_is(unsigned char *data, int cnt, struct fb *fbp)
{
unsigned char *p;
register int state = fbp->state[DIR_DECRYPT-1];
int state = fbp->state[DIR_DECRYPT-1];
if (cnt-- < 1)
goto failure;
@ -339,29 +322,22 @@ fb64_is(data, cnt, fbp)
* 0: Successful, initial negotiation all done.
* 1: successful, negotiation not done yet.
*/
int
cfb64_reply(data, cnt)
unsigned char *data;
int cnt;
int
cfb64_reply(unsigned char *data, int cnt)
{
return(fb64_reply(data, cnt, &fb[CFB]));
}
int
ofb64_reply(data, cnt)
unsigned char *data;
int cnt;
int
ofb64_reply(unsigned char *data, int cnt)
{
return(fb64_reply(data, cnt, &fb[OFB]));
}
int
fb64_reply(data, cnt, fbp)
unsigned char *data;
int cnt;
struct fb *fbp;
int
fb64_reply(unsigned char *data, int cnt, struct fb *fbp)
{
register int state = fbp->state[DIR_ENCRYPT-1];
int state = fbp->state[DIR_ENCRYPT-1];
if (cnt-- < 1)
goto failure;
@ -372,7 +348,7 @@ fb64_reply(data, cnt, fbp)
if (state == FAILED)
state = IN_PROGRESS;
state &= ~NO_RECV_IV;
encrypt_send_keyid(DIR_ENCRYPT, (unsigned char *)"\0", 1, 1);
encrypt_send_keyid(DIR_ENCRYPT, "\0", 1, 1);
break;
case FB64_IV_BAD:
@ -395,29 +371,21 @@ fb64_reply(data, cnt, fbp)
return(fbp->state[DIR_ENCRYPT-1] = state);
}
void
cfb64_session(key, server)
Session_Key *key;
int server;
void
cfb64_session(Session_Key *key, int server)
{
fb64_session(key, server, &fb[CFB]);
}
void
ofb64_session(key, server)
Session_Key *key;
int server;
void
ofb64_session(Session_Key *key, int server)
{
fb64_session(key, server, &fb[OFB]);
}
static void
fb64_session(key, server, fbp)
Session_Key *key;
int server;
struct fb *fbp;
static void
fb64_session(Session_Key *key, int server, struct fb *fbp)
{
if (!key || key->type != SK_DES) {
if (encrypt_debug_mode)
printf("Can't set krbdes's session key (%d != %d)\r\n",
@ -449,29 +417,22 @@ fb64_session(key, server, fbp)
* We only accept a keyid of 0. If we get a keyid of
* 0, then mark the state as SUCCESS.
*/
int
cfb64_keyid(dir, kp, lenp)
int dir, *lenp;
unsigned char *kp;
int
cfb64_keyid(int dir, unsigned char *kp, int *lenp)
{
return(fb64_keyid(dir, kp, lenp, &fb[CFB]));
}
int
ofb64_keyid(dir, kp, lenp)
int dir, *lenp;
unsigned char *kp;
int
ofb64_keyid(int dir, unsigned char *kp, int *lenp)
{
return(fb64_keyid(dir, kp, lenp, &fb[OFB]));
}
int
fb64_keyid(dir, kp, lenp, fbp)
int dir, *lenp;
unsigned char *kp;
struct fb *fbp;
int
fb64_keyid(int dir, unsigned char *kp, int *lenp, struct fb *fbp)
{
register int state = fbp->state[dir-1];
int state = fbp->state[dir-1];
if (*lenp != 1 || (*kp != '\0')) {
*lenp = 0;
@ -486,13 +447,11 @@ fb64_keyid(dir, kp, lenp, fbp)
return(fbp->state[dir-1] = state);
}
void
fb64_printsub(data, cnt, buf, buflen, type)
unsigned char *data, *buf, *type;
int cnt, buflen;
void
fb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen, const char *type)
{
char lbuf[32];
register int i;
int i;
char *cp;
buf[buflen-1] = '\0'; /* make sure it's NULL terminated */
@ -529,26 +488,20 @@ fb64_printsub(data, cnt, buf, buflen, type)
}
}
void
cfb64_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
cfb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
fb64_printsub(data, cnt, buf, buflen, "CFB64");
}
void
ofb64_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
ofb64_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
fb64_printsub(data, cnt, buf, buflen, "OFB64");
}
void
fb64_stream_iv(seed, stp)
Block seed;
register struct stinfo *stp;
void
fb64_stream_iv(Block seed, struct stinfo *stp)
{
memmove((void *)stp->str_iv, (void *)seed, sizeof(Block));
@ -559,10 +512,8 @@ fb64_stream_iv(seed, stp)
stp->str_index = sizeof(Block);
}
void
fb64_stream_key(key, stp)
Block key;
register struct stinfo *stp;
void
fb64_stream_key(Block key, struct stinfo *stp)
{
memmove((void *)stp->str_ikey, (void *)key, sizeof(Block));
des_key_sched((Block *)key, stp->str_sched);
@ -594,37 +545,34 @@ fb64_stream_key(key, stp)
* V(n+1) = DES(On, key)
*/
void
cfb64_encrypt(s, c)
register unsigned char *s;
int c;
void
cfb64_encrypt(unsigned char *s, int c)
{
register struct stinfo *stp = &fb[CFB].streams[DIR_ENCRYPT-1];
register int index;
struct stinfo *stp = &fb[CFB].streams[DIR_ENCRYPT-1];
int idx;
index = stp->str_index;
idx = stp->str_index;
while (c-- > 0) {
if (index == sizeof(Block)) {
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_output, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
index = 0;
idx = 0;
}
/* On encryption, we store (feed ^ data) which is cypher */
*s = stp->str_output[index] = (stp->str_feed[index] ^ *s);
*s = stp->str_output[idx] = (stp->str_feed[idx] ^ *s);
s++;
index++;
idx++;
}
stp->str_index = index;
stp->str_index = idx;
}
int
cfb64_decrypt(data)
int data;
int
cfb64_decrypt(int data)
{
register struct stinfo *stp = &fb[CFB].streams[DIR_DECRYPT-1];
int index;
struct stinfo *stp = &fb[CFB].streams[DIR_DECRYPT-1];
int idx;
if (data == -1) {
/*
@ -637,18 +585,18 @@ cfb64_decrypt(data)
return(0);
}
index = stp->str_index++;
if (index == sizeof(Block)) {
idx = stp->str_index++;
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_output, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
stp->str_index = 1; /* Next time will be 1 */
index = 0; /* But now use 0 */
idx = 0; /* But now use 0 */
}
/* On decryption we store (data) which is cypher. */
stp->str_output[index] = data;
return(data ^ stp->str_feed[index]);
stp->str_output[idx] = data;
return(data ^ stp->str_feed[idx]);
}
/*
@ -670,34 +618,31 @@ cfb64_decrypt(data)
* V(n+1) = DES(Vn, key)
* On = Dn ^ Vn
*/
void
ofb64_encrypt(s, c)
register unsigned char *s;
int c;
void
ofb64_encrypt(unsigned char *s, int c)
{
register struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1];
register int index;
struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1];
int idx;
index = stp->str_index;
idx = stp->str_index;
while (c-- > 0) {
if (index == sizeof(Block)) {
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
index = 0;
idx = 0;
}
*s++ ^= stp->str_feed[index];
index++;
*s++ ^= stp->str_feed[idx];
idx++;
}
stp->str_index = index;
stp->str_index = idx;
}
int
ofb64_decrypt(data)
int data;
int
ofb64_decrypt(int data)
{
register struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1];
int index;
struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1];
int idx;
if (data == -1) {
/*
@ -710,17 +655,16 @@ ofb64_decrypt(data)
return(0);
}
index = stp->str_index++;
if (index == sizeof(Block)) {
idx = stp->str_index++;
if (idx == sizeof(Block)) {
Block b;
des_ecb_encrypt((Block *)stp->str_feed, (Block *)b, stp->str_sched, 1);
memmove((void *)stp->str_feed, (void *)b, sizeof(Block));
stp->str_index = 1; /* Next time will be 1 */
index = 0; /* But now use 0 */
idx = 0; /* But now use 0 */
}
return(data ^ stp->str_feed[index]);
return(data ^ stp->str_feed[idx]);
}
# endif /* DES_ENCRYPTION */
# endif /* AUTHENTICATION */
#endif /* ENCRYPTION */

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -63,21 +64,14 @@ static const char sccsid[] = "@(#)encrypt.c 8.2 (Berkeley) 5/30/95";
#ifdef ENCRYPTION
#define ENCRYPT_NAMES
#include <stdio.h>
#include <arpa/telnet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encrypt.h"
#include "misc.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
/*
* These functions pointers point to the current routines
* for encrypting and decrypting data.
@ -93,10 +87,6 @@ int EncryptStartOutput(void);
int EncryptStopInput(void);
int EncryptStopOutput(void);
int Ambiguous(char **s);
int isprefix(char *s1, char *s2);
char **genget(char *name, char **table, int stlen);
int encrypt_debug_mode = 0;
static int decrypt_mode = 0;
static int encrypt_mode = 0;
@ -105,19 +95,15 @@ static int autoencrypt = 0;
static int autodecrypt = 0;
static int havesessionkey = 0;
static int Server = 0;
static char *Name = "Noname";
static const char *Name = "Noname";
#define typemask(x) ((x) > 0 ? 1 << ((x)-1) : 0)
static long i_support_encrypt = 0
#ifdef DES_ENCRYPTION
| typemask(ENCTYPE_DES_CFB64) | typemask(ENCTYPE_DES_OFB64)
#endif
|0;
static long i_support_decrypt = 0
#ifdef DES_ENCRYPTION
| typemask(ENCTYPE_DES_CFB64) | typemask(ENCTYPE_DES_OFB64)
#endif
|0;
static long i_wont_support_encrypt = 0;
@ -129,7 +115,6 @@ static long remote_supports_encrypt = 0;
static long remote_supports_decrypt = 0;
static Encryptions encryptions[] = {
#ifdef DES_ENCRYPTION
{ "DES_CFB64", ENCTYPE_DES_CFB64,
cfb64_encrypt,
cfb64_decrypt,
@ -150,8 +135,7 @@ static Encryptions encryptions[] = {
ofb64_session,
ofb64_keyid,
ofb64_printsub },
#endif /* DES_ENCRYPTION */
{ 0, },
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
static unsigned char str_send[64] = { IAC, SB, TELOPT_ENCRYPT,
@ -160,26 +144,24 @@ static unsigned char str_suplen = 0;
static unsigned char str_start[72] = { IAC, SB, TELOPT_ENCRYPT };
static unsigned char str_end[] = { IAC, SB, TELOPT_ENCRYPT, 0, IAC, SE };
Encryptions *
findencryption(type)
int type;
Encryptions *
findencryption(int type)
{
Encryptions *ep = encryptions;
if (!(I_SUPPORT_ENCRYPT & remote_supports_decrypt & typemask(type)))
if (!(I_SUPPORT_ENCRYPT & remote_supports_decrypt & (unsigned)typemask(type)))
return(0);
while (ep->type && ep->type != type)
++ep;
return(ep->type ? ep : 0);
}
Encryptions *
finddecryption(type)
int type;
static Encryptions *
finddecryption(int type)
{
Encryptions *ep = encryptions;
if (!(I_SUPPORT_DECRYPT & remote_supports_encrypt & typemask(type)))
if (!(I_SUPPORT_DECRYPT & remote_supports_encrypt & (unsigned)typemask(type)))
return(0);
while (ep->type && ep->type != type)
++ep;
@ -193,7 +175,7 @@ static struct key_info {
int keylen;
int dir;
int *modep;
Encryptions *(*getcrypt)();
Encryptions *(*getcrypt)(int);
} ki[2] = {
{ { 0 }, 0, DIR_ENCRYPT, &encrypt_mode, findencryption },
{ { 0 }, 0, DIR_DECRYPT, &decrypt_mode, finddecryption },
@ -201,10 +183,8 @@ static struct key_info {
static void encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len);
void
encrypt_init(name, server)
char *name;
int server;
void
encrypt_init(const char *name, int server)
{
Encryptions *ep = encryptions;
@ -216,9 +196,6 @@ encrypt_init(name, server)
decrypt_mode = 0;
encrypt_output = 0;
decrypt_input = 0;
#ifdef notdef
encrypt_verbose = !server;
#endif
str_suplen = 4;
@ -239,8 +216,8 @@ encrypt_init(name, server)
str_send[str_suplen++] = SE;
}
void
encrypt_list_types()
static void
encrypt_list_types(void)
{
Encryptions *ep = encryptions;
@ -251,9 +228,8 @@ encrypt_list_types()
}
}
int
EncryptEnable(type, mode)
char *type, *mode;
int
EncryptEnable(char *type, char *mode)
{
if (isprefix(type, "help") || isprefix(type, "?")) {
printf("Usage: encrypt enable <type> [input|output]\n");
@ -265,11 +241,10 @@ EncryptEnable(type, mode)
return(0);
}
int
EncryptDisable(type, mode)
char *type, *mode;
int
EncryptDisable(char *type, char *mode)
{
register Encryptions *ep;
Encryptions *ep;
int ret = 0;
if (isprefix(type, "help") || isprefix(type, "?")) {
@ -299,12 +274,10 @@ EncryptDisable(type, mode)
return(ret);
}
int
EncryptType(type, mode)
char *type;
char *mode;
int
EncryptType(char *type, char *mode)
{
register Encryptions *ep;
Encryptions *ep;
int ret = 0;
if (isprefix(type, "help") || isprefix(type, "?")) {
@ -332,11 +305,10 @@ EncryptType(type, mode)
return(ret);
}
int
EncryptStart(mode)
char *mode;
int
EncryptStart(char *mode)
{
register int ret = 0;
int ret = 0;
if (mode) {
if (isprefix(mode, "input"))
return(EncryptStartInput());
@ -354,8 +326,8 @@ EncryptStart(mode)
return(ret);
}
int
EncryptStartInput()
int
EncryptStartInput(void)
{
if (decrypt_mode) {
encrypt_send_request_start();
@ -365,8 +337,8 @@ EncryptStartInput()
return(0);
}
int
EncryptStartOutput()
int
EncryptStartOutput(void)
{
if (encrypt_mode) {
encrypt_start_output(encrypt_mode);
@ -376,9 +348,8 @@ EncryptStartOutput()
return(0);
}
int
EncryptStop(mode)
char *mode;
int
EncryptStop(char *mode)
{
int ret = 0;
if (mode) {
@ -398,22 +369,22 @@ EncryptStop(mode)
return(ret);
}
int
EncryptStopInput()
int
EncryptStopInput(void)
{
encrypt_send_request_end();
return(1);
}
int
EncryptStopOutput()
int
EncryptStopOutput(void)
{
encrypt_send_end();
return(1);
}
void
encrypt_display()
void
encrypt_display(void)
{
if (encrypt_output)
printf("Currently encrypting output with %s\r\n",
@ -423,8 +394,8 @@ encrypt_display()
ENCTYPE_NAME(decrypt_mode));
}
int
EncryptStatus()
int
EncryptStatus(void)
{
if (encrypt_output)
printf("Currently encrypting output with %s\r\n",
@ -445,8 +416,8 @@ EncryptStatus()
return 1;
}
void
encrypt_send_support()
void
encrypt_send_support(void)
{
if (str_suplen) {
/*
@ -462,9 +433,8 @@ encrypt_send_support()
}
}
int
EncryptDebug(on)
int on;
int
EncryptDebug(int on)
{
if (on < 0)
encrypt_debug_mode ^= 1;
@ -475,9 +445,8 @@ EncryptDebug(on)
return(1);
}
int
EncryptVerbose(on)
int on;
int
EncryptVerbose(int on)
{
if (on < 0)
encrypt_verbose ^= 1;
@ -488,9 +457,8 @@ EncryptVerbose(on)
return(1);
}
int
EncryptAutoEnc(on)
int on;
int
EncryptAutoEnc(int on)
{
encrypt_auto(on);
printf("Automatic encryption of output is %s\r\n",
@ -498,9 +466,8 @@ EncryptAutoEnc(on)
return(1);
}
int
EncryptAutoDec(on)
int on;
int
EncryptAutoDec(int on)
{
decrypt_auto(on);
printf("Automatic decryption of input is %s\r\n",
@ -511,12 +478,10 @@ EncryptAutoDec(on)
/*
* Called when ENCRYPT SUPPORT is received.
*/
void
encrypt_support(typelist, cnt)
unsigned char *typelist;
int cnt;
void
encrypt_support(unsigned char *typelist, int cnt)
{
register int type, use_type = 0;
int type, use_type = 0;
Encryptions *ep;
/*
@ -553,13 +518,11 @@ encrypt_support(typelist, cnt)
}
}
void
encrypt_is(data, cnt)
unsigned char *data;
int cnt;
void
encrypt_is(unsigned char *data, int cnt)
{
Encryptions *ep;
register int type, ret;
int type, ret;
if (--cnt < 0)
return;
@ -599,13 +562,11 @@ encrypt_is(data, cnt)
}
}
void
encrypt_reply(data, cnt)
unsigned char *data;
int cnt;
void
encrypt_reply(unsigned char *data, int cnt)
{
Encryptions *ep;
register int ret, type;
int ret, type;
if (--cnt < 0)
return;
@ -649,10 +610,8 @@ encrypt_reply(data, cnt)
/*
* Called when a ENCRYPT START command is received.
*/
void
encrypt_start(data, cnt)
unsigned char *data;
int cnt;
void
encrypt_start(unsigned char *data __unused, int cnt __unused)
{
Encryptions *ep;
@ -687,10 +646,8 @@ encrypt_start(data, cnt)
}
}
void
encrypt_session_key(key, server)
Session_Key *key;
int server;
void
encrypt_session_key( Session_Key *key, int server)
{
Encryptions *ep = encryptions;
@ -699,12 +656,6 @@ encrypt_session_key(key, server)
while (ep->type) {
if (ep->session)
(*ep->session)(key, server);
#ifdef notdef
if (!encrypt_output && autoencrypt && !server)
encrypt_start_output(ep->type);
if (!decrypt_input && autodecrypt && !server)
encrypt_send_request_start();
#endif
++ep;
}
}
@ -712,8 +663,8 @@ encrypt_session_key(key, server)
/*
* Called when ENCRYPT END is received.
*/
void
encrypt_end()
void
encrypt_end(void)
{
decrypt_input = 0;
if (encrypt_debug_mode)
@ -725,8 +676,8 @@ encrypt_end()
/*
* Called when ENCRYPT REQUEST-END is received.
*/
void
encrypt_request_end()
void
encrypt_request_end(void)
{
encrypt_send_end();
}
@ -737,10 +688,8 @@ encrypt_request_end()
* other side wants us to start encrypting data as soon as we
* can.
*/
void
encrypt_request_start(data, cnt)
unsigned char *data;
int cnt;
void
encrypt_request_start(unsigned char *data __unused, int cnt __unused)
{
if (encrypt_mode == 0) {
if (Server)
@ -752,31 +701,24 @@ encrypt_request_start(data, cnt)
static unsigned char str_keyid[(MAXKEYLEN*2)+5] = { IAC, SB, TELOPT_ENCRYPT };
void
encrypt_enc_keyid(keyid, len)
unsigned char *keyid;
int len;
void
encrypt_enc_keyid(unsigned char *keyid, int len)
{
encrypt_keyid(&ki[1], keyid, len);
}
void
encrypt_dec_keyid(keyid, len)
unsigned char *keyid;
int len;
void
encrypt_dec_keyid(unsigned char *keyid, int len)
{
encrypt_keyid(&ki[0], keyid, len);
}
void
encrypt_keyid(kp, keyid, len)
struct key_info *kp;
unsigned char *keyid;
int len;
void
encrypt_keyid(struct key_info *kp, unsigned char *keyid, int len)
{
Encryptions *ep;
int dir = kp->dir;
register int ret = 0;
int ret = 0;
if (!(ep = (*kp->getcrypt)(*kp->modep))) {
if (len == 0)
@ -812,12 +754,8 @@ encrypt_keyid(kp, keyid, len)
encrypt_send_keyid(dir, kp->keyid, kp->keylen, 0);
}
void
encrypt_send_keyid(dir, keyid, keylen, saveit)
int dir;
unsigned char *keyid;
int keylen;
int saveit;
void
encrypt_send_keyid(int dir, const char *keyid, int keylen, int saveit)
{
unsigned char *strp;
@ -839,9 +777,8 @@ encrypt_send_keyid(dir, keyid, keylen, saveit)
printsub('>', &str_keyid[2], strp - str_keyid - 2);
}
void
encrypt_auto(on)
int on;
void
encrypt_auto(int on)
{
if (on < 0)
autoencrypt ^= 1;
@ -849,9 +786,8 @@ encrypt_auto(on)
autoencrypt = on ? 1 : 0;
}
void
decrypt_auto(on)
int on;
void
decrypt_auto(int on)
{
if (on < 0)
autodecrypt ^= 1;
@ -859,13 +795,12 @@ decrypt_auto(on)
autodecrypt = on ? 1 : 0;
}
void
encrypt_start_output(type)
int type;
void
encrypt_start_output(int type)
{
Encryptions *ep;
register unsigned char *p;
register int i;
unsigned char *p;
int i;
if (!(ep = findencryption(type))) {
if (encrypt_debug_mode) {
@ -916,8 +851,8 @@ encrypt_start_output(type)
ENCTYPE_NAME(type));
}
void
encrypt_send_end()
void
encrypt_send_end(void)
{
if (!encrypt_output)
return;
@ -937,11 +872,11 @@ encrypt_send_end()
printf("[ Output is now clear text ]\r\n");
}
void
encrypt_send_request_start()
void
encrypt_send_request_start(void)
{
register unsigned char *p;
register int i;
unsigned char *p;
int i;
p = &str_start[3];
*p++ = ENCRYPT_REQSTART;
@ -957,8 +892,8 @@ encrypt_send_request_start()
printf(">>>%s: Request input to be encrypted\r\n", Name);
}
void
encrypt_send_request_end()
void
encrypt_send_request_end(void)
{
str_end[3] = ENCRYPT_REQEND;
net_write(str_end, sizeof(str_end));
@ -968,8 +903,8 @@ encrypt_send_request_end()
printf(">>>%s: Request input to be clear text\r\n", Name);
}
void
encrypt_wait()
void
encrypt_wait(void)
{
if (encrypt_debug_mode)
printf(">>>%s: in encrypt_wait\r\n", Name);
@ -980,17 +915,8 @@ encrypt_wait()
return;
}
void
encrypt_debug(mode)
int mode;
{
encrypt_debug_mode = mode;
}
void
encrypt_gen_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
encrypt_gen_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
char tbuf[16], *cp;
@ -1009,13 +935,11 @@ encrypt_gen_printsub(data, cnt, buf, buflen)
*buf = '\0';
}
void
encrypt_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
encrypt_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
Encryptions *ep;
register int type = data[1];
int type = data[1];
for (ep = encryptions; ep->type && ep->type != type; ep++)
;

View File

@ -81,26 +81,18 @@ typedef struct {
unsigned char *data;
} Session_Key;
# if !defined(P)
# ifdef __STDC__
# define P(x) x
# else
# define P(x) ()
# endif
# endif
typedef struct {
char *name;
const char *name;
int type;
void (*output) P((unsigned char *, int));
int (*input) P((int));
void (*init) P((int));
int (*start) P((int, int));
int (*is) P((unsigned char *, int));
int (*reply) P((unsigned char *, int));
void (*session) P((Session_Key *, int));
int (*keyid) P((int, unsigned char *, int *));
void (*printsub) P((unsigned char *, int, unsigned char *, int));
void (*output)(unsigned char *, int);
int (*input)(int);
void (*init)(int);
int (*start)(int, int);
int (*is)(unsigned char *, int);
int (*reply)(unsigned char *, int);
void (*session)(Session_Key *, int);
int (*keyid)(int, unsigned char *, int *);
void (*printsub)(unsigned char *, int, unsigned char *, int);
} Encryptions;
#define SK_DES 1 /* Matched Kerberos v5 KEYTYPE_DES */
@ -108,7 +100,7 @@ typedef struct {
#include "enc-proto.h"
extern int encrypt_debug_mode;
extern int (*decrypt_input) P((int));
extern void (*encrypt_output) P((unsigned char *, int));
extern int (*decrypt_input)(int);
extern void (*encrypt_output)(unsigned char *, int);
# endif /* __ENCRYPTION__ */
#endif /* ENCRYPTION */

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -43,6 +44,8 @@ static const char sccsid[] = "@(#)genget.c 8.2 (Berkeley) 5/30/95";
#include <ctype.h>
#include "misc-proto.h"
#define LOWER(x) (isupper(x) ? tolower(x) : (x))
/*
* The prefix function returns 0 if *s1 is not a prefix
@ -51,7 +54,7 @@ static const char sccsid[] = "@(#)genget.c 8.2 (Berkeley) 5/30/95";
* the length of *s1 is returned.
*/
int
isprefix(char *s1, char *s2)
isprefix(char *s1, const char *s2)
{
char *os1;
char c1, c2;
@ -98,7 +101,7 @@ genget(char *name, char **table, int stlen)
* Function call version of Ambiguous()
*/
int
Ambiguous(char *s)
Ambiguous(char **s)
{
return((char **)s == &ambiguous);
return(s == &ambiguous);
}

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -40,37 +41,36 @@ static char sccsid[] = "@(#)getent.c 8.2 (Berkeley) 12/15/93";
#endif
#endif /* not lint */
#ifdef HAS_CGETENT
#include <stdlib.h>
#endif
#include <string.h>
#include "misc-proto.h"
static char *area;
static char gettytab[] = "/etc/gettytab";
/*ARGSUSED*/
int
getent(char *cp, char *name)
getent(char *cp __unused, const char *name)
{
#ifdef HAS_CGETENT
char *dba[2];
int retval;
char *tempnam, *dba[2] = { gettytab, NULL };
dba[0] = "/etc/gettytab";
dba[1] = 0;
return((cgetent(&area, dba, name) == 0) ? 1 : 0);
#else
return(0);
#endif
tempnam = strdup(name);
retval = cgetent(&area, dba, tempnam) == 0 ? 1 : 0;
free(tempnam);
return(retval);
}
#ifndef SOLARIS
/*ARGSUSED*/
char *
Getstr(char *id, char **cpp)
Getstr(const char *id, char **cpp __unused)
{
# ifdef HAS_CGETENT
char *answer;
return((cgetstr(area, id, &answer) > 0) ? answer : 0);
# else
return(0);
# endif
int retval;
char *answer, *tempid;
tempid = strdup(id);
retval = cgetstr(area, tempid, &answer);
free(tempid);
return((retval > 0) ? answer : NULL);
}
#endif

View File

@ -29,11 +29,10 @@
* 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
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -63,17 +62,11 @@ static const char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
#ifdef KRB4
#include <sys/types.h>
#include <arpa/telnet.h>
#include <stdio.h>
#include <openssl/des.h> /* BSD wont include this in krb.h, so we do it here */
#include <krb.h>
#ifdef __STDC__
#include <stdio.h>
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include "encrypt.h"
#include "auth.h"
@ -82,7 +75,7 @@ static const char sccsid[] = "@(#)kerberos.c 8.3 (Berkeley) 5/30/95";
int kerberos4_cksum P((unsigned char *, int));
int kuserok P((AUTH_DAT *, char *));
extern auth_debug_mode;
extern int auth_debug_mode;
static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
AUTHTYPE_KERBEROS_V4, };
@ -93,29 +86,26 @@ static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
#define KRB_CHALLENGE 3 /* Challenge for mutual auth. */
#define KRB_RESPONSE 4 /* Response for mutual auth. */
#define KRB_SERVICE_NAME "rcmd"
static KTEXT_ST auth;
static char name[ANAME_SZ];
static AUTH_DAT adat = { 0 };
static AUTH_DAT adat = { 0, "", "", "", 0, {}, 0, 0, 0, { 0, "", 0 } };
#ifdef ENCRYPTION
static Block session_key = { 0 };
static des_key_schedule sched;
static Block challenge = { 0 };
#endif /* ENCRYPTION */
static int
Data(ap, type, d, c)
Authenticator *ap;
int type;
void *d;
int c;
static char krb_service_name[] = "rcmd";
static char empty[] = "";
static int
Data(Authenticator *ap, int type, const unsigned char *d, int c)
{
unsigned char *p = str_data + 4;
unsigned char *cd = (unsigned char *)d;
const unsigned char *cd = d;
if (c == -1)
c = strlen((char *)cd);
c = strlen(cd);
if (auth_debug_mode) {
printf("%s:%d: [%d] (%d)",
@ -139,10 +129,8 @@ Data(ap, type, d, c)
return(net_write(str_data, p - str_data));
}
int
kerberos4_init(ap, server)
Authenticator *ap;
int server;
int
kerberos4_init(Authenticator *ap __unused, int server)
{
FILE *fp;
@ -160,15 +148,12 @@ kerberos4_init(ap, server)
char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
int dst_realm_sz = REALM_SZ;
int
kerberos4_send(ap)
Authenticator *ap;
int
kerberos4_send(Authenticator *ap)
{
KTEXT_ST auth;
KTEXT_ST lauth;
char instance[INST_SZ];
char *realm;
char *krb_realmofhost();
char *krb_get_phost();
CREDENTIALS cred;
int r;
@ -193,11 +178,11 @@ kerberos4_send(ap)
printf("Kerberos V4: no realm for %s\r\n", RemoteHostName);
return(0);
}
if ((r = krb_mk_req(&auth, KRB_SERVICE_NAME, instance, realm, 0L))) {
if ((r = krb_mk_req(&lauth, krb_service_name, instance, realm, 0L))) {
printf("mk_req failed: %s\r\n", krb_err_txt[r]);
return(0);
}
if ((r = krb_get_cred(KRB_SERVICE_NAME, instance, realm, &cred))) {
if ((r = krb_get_cred(krb_service_name, instance, realm, &cred))) {
printf("get_cred failed: %s\r\n", krb_err_txt[r]);
return(0);
}
@ -207,8 +192,8 @@ kerberos4_send(ap)
return(0);
}
if (auth_debug_mode)
printf("Sent %d bytes of authentication data\r\n", auth.length);
if (!Data(ap, KRB_AUTH, (void *)auth.dat, auth.length)) {
printf("Sent %d bytes of authentication data\r\n", lauth.length);
if (!Data(ap, KRB_AUTH, (void *)lauth.dat, lauth.length)) {
if (auth_debug_mode)
printf("Not enough room for authentication data\r\n");
return(0);
@ -242,19 +227,16 @@ kerberos4_send(ap)
#endif /* ENCRYPTION */
if (auth_debug_mode) {
printf("CK: %d:", kerberos4_cksum(auth.dat, auth.length));
printd(auth.dat, auth.length);
printf("CK: %d:", kerberos4_cksum(lauth.dat, lauth.length));
printd(lauth.dat, lauth.length);
printf("\r\n");
printf("Sent Kerberos V4 credentials to server\r\n");
}
return(1);
}
void
kerberos4_is(ap, data, cnt)
Authenticator *ap;
unsigned char *data;
int cnt;
void
kerberos4_is(Authenticator *ap, unsigned char *data, int cnt)
{
#ifdef ENCRYPTION
Session_Key skey;
@ -269,7 +251,7 @@ kerberos4_is(ap, data, cnt)
switch (*data++) {
case KRB_AUTH:
if (krb_get_lrealm(realm, 1) != KSUCCESS) {
Data(ap, KRB_REJECT, (void *)"No local V4 Realm.", -1);
Data(ap, KRB_REJECT, "No local V4 Realm.", -1);
auth_finished(ap, AUTH_REJECT);
if (auth_debug_mode)
printf("No local realm\r\n");
@ -283,11 +265,11 @@ kerberos4_is(ap, data, cnt)
printf("\r\n");
}
instance[0] = '*'; instance[1] = 0;
if ((r = krb_rd_req(&auth, KRB_SERVICE_NAME,
instance, 0, &adat, ""))) {
if ((r = krb_rd_req(&auth, krb_service_name,
instance, 0, &adat, empty))) {
if (auth_debug_mode)
printf("Kerberos failed him as %s\r\n", name);
Data(ap, KRB_REJECT, (void *)krb_err_txt[r], -1);
Data(ap, KRB_REJECT, krb_err_txt[r], -1);
auth_finished(ap, AUTH_REJECT);
return;
}
@ -297,16 +279,15 @@ kerberos4_is(ap, data, cnt)
krb_kntoln(&adat, name);
if (UserNameRequested && !kuserok(&adat, UserNameRequested))
Data(ap, KRB_ACCEPT, (void *)0, 0);
Data(ap, KRB_ACCEPT, NULL, 0);
else
Data(ap, KRB_REJECT,
(void *)"user is not authorized", -1);
Data(ap, KRB_REJECT, "user is not authorized", -1);
auth_finished(ap, AUTH_USER);
break;
case KRB_CHALLENGE:
#ifndef ENCRYPTION
Data(ap, KRB_RESPONSE, (void *)0, 0);
Data(ap, KRB_RESPONSE, NULL, 0);
#else /* ENCRYPTION */
if (!VALIDKEY(session_key)) {
/*
@ -314,7 +295,7 @@ kerberos4_is(ap, data, cnt)
* send back a response with an empty session
* key.
*/
Data(ap, KRB_RESPONSE, (void *)0, 0);
Data(ap, KRB_RESPONSE, NULL, 0);
break;
}
@ -348,23 +329,20 @@ kerberos4_is(ap, data, cnt)
break;
}
des_ecb_encrypt(&challenge, &challenge, sched, 1);
Data(ap, KRB_RESPONSE, (void *)challenge, sizeof(challenge));
Data(ap, KRB_RESPONSE, challenge, sizeof(challenge));
#endif /* ENCRYPTION */
break;
default:
if (auth_debug_mode)
printf("Unknown Kerberos option %d\r\n", data[-1]);
Data(ap, KRB_REJECT, 0, 0);
Data(ap, KRB_REJECT, NULL, 0);
break;
}
}
void
kerberos4_reply(ap, data, cnt)
Authenticator *ap;
unsigned char *data;
int cnt;
void
kerberos4_reply(Authenticator *ap, unsigned char *data, int cnt)
{
#ifdef ENCRYPTION
Session_Key skey;
@ -388,9 +366,9 @@ kerberos4_reply(ap, data, cnt)
* Send over the encrypted challenge.
*/
#ifndef ENCRYPTION
Data(ap, KRB_CHALLENGE, (void *)0, 0);
Data(ap, KRB_CHALLENGE, NULL, 0);
#else /* ENCRYPTION */
Data(ap, KRB_CHALLENGE, (void *)session_key,
Data(ap, KRB_CHALLENGE, session_key,
sizeof(session_key));
des_ecb_encrypt(&session_key, &session_key, sched, 1);
skey.type = SK_DES;
@ -428,17 +406,14 @@ kerberos4_reply(ap, data, cnt)
}
}
int
kerberos4_status(ap, name, level)
Authenticator *ap;
char *name;
int level;
int
kerberos4_status(Authenticator *ap __unused, char *nam, int level)
{
if (level < AUTH_USER)
return(level);
if (UserNameRequested && !kuserok(&adat, UserNameRequested)) {
strcpy(name, UserNameRequested);
strcpy(nam, UserNameRequested);
return(AUTH_VALID);
} else
return(AUTH_USER);
@ -447,10 +422,8 @@ kerberos4_status(ap, name, level)
#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
void
kerberos4_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
void
kerberos4_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
char lbuf[32];
register int i;
@ -502,10 +475,8 @@ kerberos4_printsub(data, cnt, buf, buflen)
}
}
int
kerberos4_cksum(d, n)
unsigned char *d;
int n;
int
kerberos4_cksum(unsigned char *d, int n)
{
int ck = 0;
@ -539,17 +510,3 @@ kerberos4_cksum(d, n)
return(ck);
}
#endif
#ifdef notdef
prkey(msg, key)
char *msg;
unsigned char *key;
{
register int i;
printf("%s:", msg);
for (i = 0; i < 8; i++)
printf(" %3d", key[i]);
printf("\r\n");
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -51,21 +51,15 @@
* permission. M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* $FreeBSD$
*/
#ifndef __KEY_PROTO__
#define __KEY_PROTO__
#if !defined(P)
#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif
#endif
int key_file_exists P((void));
void key_lookup P((unsigned char *, Block));
void key_stream_init P((Block, Block, int));
unsigned char key_stream P((int, int));
int key_file_exists(void);
void key_lookup(unsigned char *, Block);
void key_stream_init(Block, Block, int);
unsigned char key_stream(int, int);
#endif

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -74,20 +75,13 @@ static char sccsid[] = "@(#)krb4encpwd.c 8.3 (Berkeley) 5/30/95";
*/
#include <sys/types.h>
#include <openssl/des.h>
#include <arpa/telnet.h>
#include <krb.h>
#include <pwd.h>
#include <stdio.h>
#include <openssl/des.h>
#include <krb.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include "encrypt.h"
#include "auth.h"
@ -432,17 +426,3 @@ char *name, *passwd;
}
#endif
#ifdef notdef
prkey(msg, key)
char *msg;
unsigned char *key;
{
register int i;
printf("%s:", msg);
for (i = 0; i < 8; i++)
printf(" %3d", key[i]);
printf("\r\n");
}
#endif

View File

@ -65,17 +65,24 @@
#endif
#endif
void auth_encrypt_init P((char *, char *, char *, int));
void auth_encrypt_connect P((int));
void printd P((unsigned char *, int));
void auth_encrypt_init(char *, char *, const char *, int);
void auth_encrypt_connect(int);
void printd(const unsigned char *, int);
int isprefix(char *, const char *);
char **genget(char *, char **, int);
int Ambiguous(char **);
int getent(char *, const char *);
char *Getstr(const char *, char **);
/*
* These functions are imported from the application
*/
int net_write P((unsigned char *, int));
void net_encrypt P((void));
int telnet_spin P((void));
char *telnet_getenv P((char *));
char *telnet_gets P((char *, char *, int, int));
void printsub P((int, unsigned char *, int));
int net_write(unsigned char *, int);
void net_encrypt(void);
int telnet_spin(void);
char *telnet_getenv(char *);
char *telnet_gets(const char *, char *, int, int);
void printsub(char, unsigned char *, int);
#endif

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -42,8 +43,10 @@ static const char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc.h"
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
#include "auth.h"
#endif
#ifdef ENCRYPTION
@ -55,16 +58,18 @@ char *LocalHostName;
char *UserNameRequested = 0;
int ConnectedCount = 0;
void
auth_encrypt_init(local, remote, name, server)
char *local;
char *remote;
char *name;
int server;
#ifndef AUTHENTICATION
#define undef1 __unused
#else
#define undef1
#endif
void
auth_encrypt_init(char *local, char *remote, const char *name undef1, int server undef1)
{
RemoteHostName = remote;
LocalHostName = local;
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
auth_init(name, server);
#endif
#ifdef ENCRYPTION
@ -76,27 +81,23 @@ auth_encrypt_init(local, remote, name, server)
}
}
void
auth_encrypt_user(name)
char *name;
#ifdef ENCRYPTION
void
auth_encrypt_user(char *name)
{
extern char *strdup();
if (UserNameRequested)
free(UserNameRequested);
UserNameRequested = name ? strdup(name) : 0;
}
void
auth_encrypt_connect(cnt)
int cnt;
void
auth_encrypt_connect(int cnt __unused)
{
}
#endif /* ENCRYPTION */
void
printd(data, cnt)
unsigned char *data;
int cnt;
void
printd(const unsigned char *data, int cnt)
{
if (cnt > 16)
cnt = 16;

View File

@ -28,6 +28,10 @@
*
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/* public key routines */
/* functions:
genkeys(char *public, char *secret)
@ -39,19 +43,15 @@
char secret[HEXKEYBYTES + 1];
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/time.h>
#include <openssl/des.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mp.h"
#include "pk.h"
#if defined(SOLARIS2) || defined(LINUX) || defined(__FreeBSD__)
#include <stdlib.h>
#endif
static void adjust(char keyout[HEXKEYBYTES+1], char *keyin);
@ -129,11 +129,7 @@ common_key(char *xsecret, char *xpublic, IdeaData *ideakey, DesData *deskey)
pow(public, secret, modulus, common);
extractdeskey(common, deskey);
extractideakey(common, ideakey);
#if DES_OSTHOLM
des_fixup_key_parity(deskey);
#else
des_set_odd_parity(deskey);
#endif
mfree(common);
mfree(secret);
mfree(public);
@ -143,7 +139,7 @@ common_key(char *xsecret, char *xpublic, IdeaData *ideakey, DesData *deskey)
/*
* Generate a seed
*/
void
static void
getseed(char *seed, int seedsize)
{
int i;
@ -160,7 +156,7 @@ getseed(char *seed, int seedsize)
void
genkeys(char *public, char *secret)
{
int i;
size_t i;
# define BASEBITS (8*sizeof(short) - 1)
# define BASE (1 << BASEBITS)
@ -247,7 +243,8 @@ pk_decode(char *in, char *out, DesData *key)
char buf[256];
DesData i;
des_key_schedule k;
int l,n1,n2,op;
int n1,n2,op;
size_t l;
memset(&i,0,sizeof(i));
memset(buf,0,sizeof(buf));

View File

@ -32,23 +32,11 @@
/* header for the des routines that we will use */
typedef unsigned char byte, DesData[ 8], IdeaData[16];
#if 0
typedef unsigned long word, DesKeys[32];
#else
#define DesKeys des_key_schedule
#endif
#define DES_DECRYPT 0
#define DES_ENCRYPT 1
#if 0
extern void des_fixup_key_parity(); /* (DesData *key) */
extern int des_key_sched(); /* (DesData *key, DesKeys *m) */
extern int des_ecb_encrypt(); /* (DesData *src, *dst, DesKeys *m, int mode) */
extern int des_cbc_encrypt(); /* (char *src, *dst, int length,
DesKeys *m, DesData *init, int mode) */
#endif
/* public key routines */
/* functions:
genkeys(char *public, char *secret)
@ -69,4 +57,3 @@ extern void common_key(char *secret, char *public, IdeaData *common,
DesData *deskey);
extern void pk_encode(char *in, char *out, DesData *deskey);
extern void pk_decode(char *in, char *out, DesData *deskey);

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint

View File

@ -32,6 +32,7 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
@ -77,15 +78,8 @@ static char sccsid[] = "@(#)rsaencpwd.c 8.3 (Berkeley) 5/30/95";
#include <arpa/telnet.h>
#include <pwd.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include "encrypt.h"
#include "auth.h"
@ -479,17 +473,3 @@ char *name, *passwd;
}
#endif
#ifdef notdef
prkey(msg, key)
char *msg;
unsigned char *key;
{
register int i;
printf("%s:", msg);
for (i = 0; i < 8; i++)
printf(" %3d", key[i]);
printf("\r\n");
}
#endif

View File

@ -1,592 +0,0 @@
/*-
* Copyright (c) 1992, 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
* are met:
* 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
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static char sccsid[] = "@(#)spx.c 8.2 (Berkeley) 5/30/95";
#endif
#endif /* not lint */
#ifdef SPX
/*
* COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
* ALL RIGHTS RESERVED
*
* "Digital Equipment Corporation authorizes the reproduction,
* distribution and modification of this software subject to the following
* restrictions:
*
* 1. Any partial or whole copy of this software, or any modification
* thereof, must include this copyright notice in its entirety.
*
* 2. This software is supplied "as is" with no warranty of any kind,
* expressed or implied, for any purpose, including any warranty of fitness
* or merchantibility. DIGITAL assumes no responsibility for the use or
* reliability of this software, nor promises to provide any form of
* support for it on any basis.
*
* 3. Distribution of this software is authorized only if no profit or
* remuneration of any kind is received in exchange for such distribution.
*
* 4. This software produces public key authentication certificates
* bearing an expiration date established by DIGITAL and RSA Data
* Security, Inc. It may cease to generate certificates after the expiration
* date. Any modification of this software that changes or defeats
* the expiration date or its effect is unauthorized.
*
* 5. Software that will renew or extend the expiration date of
* authentication certificates produced by this software may be obtained
* from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
* 94065, (415)595-8782, or from DIGITAL"
*
*/
#include <sys/types.h>
#include <arpa/telnet.h>
#include <stdio.h>
#include "gssapi_defs.h"
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include <pwd.h>
#include "encrypt.h"
#include "auth.h"
#include "misc.h"
extern auth_debug_mode;
static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
AUTHTYPE_SPX, };
static unsigned char str_name[1024] = { IAC, SB, TELOPT_AUTHENTICATION,
TELQUAL_NAME, };
#define SPX_AUTH 0 /* Authentication data follows */
#define SPX_REJECT 1 /* Rejected (reason might follow) */
#define SPX_ACCEPT 2 /* Accepted */
#ifdef ENCRYPTION
static Block session_key = { 0 };
#endif /* ENCRYPTION */
static Block challenge = { 0 };
/*******************************************************************/
gss_OID_set actual_mechs;
gss_OID actual_mech_type, output_name_type;
int major_status, status, msg_ctx = 0, new_status;
int req_flags = 0, ret_flags, lifetime_rec;
gss_cred_id_t gss_cred_handle;
gss_ctx_id_t actual_ctxhandle, context_handle;
gss_buffer_desc output_token, input_token, input_name_buffer;
gss_buffer_desc status_string;
gss_name_t desired_targname, src_name;
gss_channel_bindings input_chan_bindings;
char lhostname[GSS_C_MAX_PRINTABLE_NAME];
char targ_printable[GSS_C_MAX_PRINTABLE_NAME];
int to_addr=0, from_addr=0;
char *address;
gss_buffer_desc fullname_buffer;
gss_OID fullname_type;
gss_cred_id_t gss_delegated_cred_handle;
/*******************************************************************/
static int
Data(ap, type, d, c)
Authenticator *ap;
int type;
void *d;
int c;
{
unsigned char *p = str_data + 4;
unsigned char *cd = (unsigned char *)d;
if (c == -1)
c = strlen((char *)cd);
if (0) {
printf("%s:%d: [%d] (%d)",
str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
str_data[3],
type, c);
printd(d, c);
printf("\r\n");
}
*p++ = ap->type;
*p++ = ap->way;
*p++ = type;
while (c-- > 0) {
if ((*p++ = *cd++) == IAC)
*p++ = IAC;
}
*p++ = IAC;
*p++ = SE;
if (str_data[3] == TELQUAL_IS)
printsub('>', &str_data[2], p - (&str_data[2]));
return(net_write(str_data, p - str_data));
}
int
spx_init(ap, server)
Authenticator *ap;
int server;
{
gss_cred_id_t tmp_cred_handle;
if (server) {
str_data[3] = TELQUAL_REPLY;
gethostname(lhostname, sizeof(lhostname));
strcpy(targ_printable, "SERVICE:rcmd@");
strcat(targ_printable, lhostname);
input_name_buffer.length = strlen(targ_printable);
input_name_buffer.value = targ_printable;
major_status = gss_import_name(&status,
&input_name_buffer,
GSS_C_NULL_OID,
&desired_targname);
major_status = gss_acquire_cred(&status,
desired_targname,
0,
GSS_C_NULL_OID_SET,
GSS_C_ACCEPT,
&tmp_cred_handle,
&actual_mechs,
&lifetime_rec);
if (major_status != GSS_S_COMPLETE) return(0);
} else {
str_data[3] = TELQUAL_IS;
}
return(1);
}
int
spx_send(ap)
Authenticator *ap;
{
Block enckey;
int r;
gss_OID actual_mech_type, output_name_type;
int msg_ctx = 0, new_status, status;
int req_flags = 0, ret_flags, lifetime_rec, major_status;
gss_buffer_desc output_token, input_token, input_name_buffer;
gss_buffer_desc output_name_buffer, status_string;
gss_name_t desired_targname;
gss_channel_bindings input_chan_bindings;
char targ_printable[GSS_C_MAX_PRINTABLE_NAME];
int from_addr=0, to_addr=0, myhostlen, j;
int deleg_flag=1, mutual_flag=0, replay_flag=0, seq_flag=0;
char *address;
printf("[ Trying SPX ... ]\n");
strcpy(targ_printable, "SERVICE:rcmd@");
strcat(targ_printable, RemoteHostName);
input_name_buffer.length = strlen(targ_printable);
input_name_buffer.value = targ_printable;
if (!UserNameRequested) {
return(0);
}
major_status = gss_import_name(&status,
&input_name_buffer,
GSS_C_NULL_OID,
&desired_targname);
major_status = gss_display_name(&status,
desired_targname,
&output_name_buffer,
&output_name_type);
printf("target is '%s'\n", output_name_buffer.value); fflush(stdout);
major_status = gss_release_buffer(&status, &output_name_buffer);
input_chan_bindings = (gss_channel_bindings)
malloc(sizeof(gss_channel_bindings_desc));
input_chan_bindings->initiator_addrtype = GSS_C_AF_INET;
input_chan_bindings->initiator_address.length = 4;
address = (char *) malloc(4);
input_chan_bindings->initiator_address.value = (char *) address;
address[0] = ((from_addr & 0xff000000) >> 24);
address[1] = ((from_addr & 0xff0000) >> 16);
address[2] = ((from_addr & 0xff00) >> 8);
address[3] = (from_addr & 0xff);
input_chan_bindings->acceptor_addrtype = GSS_C_AF_INET;
input_chan_bindings->acceptor_address.length = 4;
address = (char *) malloc(4);
input_chan_bindings->acceptor_address.value = (char *) address;
address[0] = ((to_addr & 0xff000000) >> 24);
address[1] = ((to_addr & 0xff0000) >> 16);
address[2] = ((to_addr & 0xff00) >> 8);
address[3] = (to_addr & 0xff);
input_chan_bindings->application_data.length = 0;
req_flags = 0;
if (deleg_flag) req_flags = req_flags | 1;
if (mutual_flag) req_flags = req_flags | 2;
if (replay_flag) req_flags = req_flags | 4;
if (seq_flag) req_flags = req_flags | 8;
major_status = gss_init_sec_context(&status, /* minor status */
GSS_C_NO_CREDENTIAL, /* cred handle */
&actual_ctxhandle, /* ctx handle */
desired_targname, /* target name */
GSS_C_NULL_OID, /* mech type */
req_flags, /* req flags */
0, /* time req */
input_chan_bindings, /* chan binding */
GSS_C_NO_BUFFER, /* input token */
&actual_mech_type, /* actual mech */
&output_token, /* output token */
&ret_flags, /* ret flags */
&lifetime_rec); /* time rec */
if ((major_status != GSS_S_COMPLETE) &&
(major_status != GSS_S_CONTINUE_NEEDED)) {
gss_display_status(&new_status,
status,
GSS_C_MECH_CODE,
GSS_C_NULL_OID,
&msg_ctx,
&status_string);
printf("%s\n", status_string.value);
return(0);
}
if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) {
return(0);
}
if (!Data(ap, SPX_AUTH, (void *)output_token.value, output_token.length)) {
return(0);
}
return(1);
}
void
spx_is(ap, data, cnt)
Authenticator *ap;
unsigned char *data;
int cnt;
{
Session_Key skey;
Block datablock;
int r;
if (cnt-- < 1)
return;
switch (*data++) {
case SPX_AUTH:
input_token.length = cnt;
input_token.value = (char *) data;
gethostname(lhostname, sizeof(lhostname));
strcpy(targ_printable, "SERVICE:rcmd@");
strcat(targ_printable, lhostname);
input_name_buffer.length = strlen(targ_printable);
input_name_buffer.value = targ_printable;
major_status = gss_import_name(&status,
&input_name_buffer,
GSS_C_NULL_OID,
&desired_targname);
major_status = gss_acquire_cred(&status,
desired_targname,
0,
GSS_C_NULL_OID_SET,
GSS_C_ACCEPT,
&gss_cred_handle,
&actual_mechs,
&lifetime_rec);
major_status = gss_release_name(&status, desired_targname);
input_chan_bindings = (gss_channel_bindings)
malloc(sizeof(gss_channel_bindings_desc));
input_chan_bindings->initiator_addrtype = GSS_C_AF_INET;
input_chan_bindings->initiator_address.length = 4;
address = (char *) malloc(4);
input_chan_bindings->initiator_address.value = (char *) address;
address[0] = ((from_addr & 0xff000000) >> 24);
address[1] = ((from_addr & 0xff0000) >> 16);
address[2] = ((from_addr & 0xff00) >> 8);
address[3] = (from_addr & 0xff);
input_chan_bindings->acceptor_addrtype = GSS_C_AF_INET;
input_chan_bindings->acceptor_address.length = 4;
address = (char *) malloc(4);
input_chan_bindings->acceptor_address.value = (char *) address;
address[0] = ((to_addr & 0xff000000) >> 24);
address[1] = ((to_addr & 0xff0000) >> 16);
address[2] = ((to_addr & 0xff00) >> 8);
address[3] = (to_addr & 0xff);
input_chan_bindings->application_data.length = 0;
major_status = gss_accept_sec_context(&status,
&context_handle,
gss_cred_handle,
&input_token,
input_chan_bindings,
&src_name,
&actual_mech_type,
&output_token,
&ret_flags,
&lifetime_rec,
&gss_delegated_cred_handle);
if (major_status != GSS_S_COMPLETE) {
major_status = gss_display_name(&status,
src_name,
&fullname_buffer,
&fullname_type);
Data(ap, SPX_REJECT, (void *)"auth failed", -1);
auth_finished(ap, AUTH_REJECT);
return;
}
major_status = gss_display_name(&status,
src_name,
&fullname_buffer,
&fullname_type);
Data(ap, SPX_ACCEPT, (void *)output_token.value, output_token.length);
auth_finished(ap, AUTH_USER);
break;
default:
Data(ap, SPX_REJECT, 0, 0);
break;
}
}
void
spx_reply(ap, data, cnt)
Authenticator *ap;
unsigned char *data;
int cnt;
{
Session_Key skey;
if (cnt-- < 1)
return;
switch (*data++) {
case SPX_REJECT:
if (cnt > 0) {
printf("[ SPX refuses authentication because %.*s ]\r\n",
cnt, data);
} else
printf("[ SPX refuses authentication ]\r\n");
auth_send_retry();
return;
case SPX_ACCEPT:
printf("[ SPX accepts you ]\n");
if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
/*
* Send over the encrypted challenge.
*/
input_token.value = (char *) data;
input_token.length = cnt;
major_status = gss_init_sec_context(&status, /* minor stat */
GSS_C_NO_CREDENTIAL, /* cred handle */
&actual_ctxhandle, /* ctx handle */
desired_targname, /* target name */
GSS_C_NULL_OID, /* mech type */
req_flags, /* req flags */
0, /* time req */
input_chan_bindings, /* chan binding */
&input_token, /* input token */
&actual_mech_type, /* actual mech */
&output_token, /* output token */
&ret_flags, /* ret flags */
&lifetime_rec); /* time rec */
if (major_status != GSS_S_COMPLETE) {
gss_display_status(&new_status,
status,
GSS_C_MECH_CODE,
GSS_C_NULL_OID,
&msg_ctx,
&status_string);
printf("[ SPX mutual response fails ... '%s' ]\r\n",
status_string.value);
auth_send_retry();
return;
}
}
auth_finished(ap, AUTH_USER);
return;
default:
return;
}
}
int
spx_status(ap, name, level)
Authenticator *ap;
char *name;
int level;
{
gss_buffer_desc fullname_buffer, acl_file_buffer;
gss_OID fullname_type;
char acl_file[160], fullname[160];
int major_status, status = 0;
struct passwd *pwd;
/*
* hard code fullname to
* "SPX:/C=US/O=Digital/OU=LKG/OU=Sphinx/OU=Users/CN=Kannan Alagappan"
* and acl_file to "~kannan/.sphinx"
*/
pwd = getpwnam(UserNameRequested);
if (pwd == NULL) {
return(AUTH_USER); /* not authenticated */
}
strcpy(acl_file, pwd->pw_dir);
strcat(acl_file, "/.sphinx");
acl_file_buffer.value = acl_file;
acl_file_buffer.length = strlen(acl_file);
major_status = gss_display_name(&status,
src_name,
&fullname_buffer,
&fullname_type);
if (level < AUTH_USER)
return(level);
major_status = gss__check_acl(&status, &fullname_buffer,
&acl_file_buffer);
if (major_status == GSS_S_COMPLETE) {
strcpy(name, UserNameRequested);
return(AUTH_VALID);
} else {
return(AUTH_USER);
}
}
#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
void
spx_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
{
char lbuf[32];
register int i;
buf[buflen-1] = '\0'; /* make sure its NULL terminated */
buflen -= 1;
switch(data[3]) {
case SPX_REJECT: /* Rejected (reason might follow) */
strncpy((char *)buf, " REJECT ", buflen);
goto common;
case SPX_ACCEPT: /* Accepted (name might follow) */
strncpy((char *)buf, " ACCEPT ", buflen);
common:
BUMP(buf, buflen);
if (cnt <= 4)
break;
ADDC(buf, buflen, '"');
for (i = 4; i < cnt; i++)
ADDC(buf, buflen, data[i]);
ADDC(buf, buflen, '"');
ADDC(buf, buflen, '\0');
break;
case SPX_AUTH: /* Authentication data follows */
strncpy((char *)buf, " AUTH", buflen);
goto common2;
default:
sprintf(lbuf, " %d (unknown)", data[3]);
strncpy((char *)buf, lbuf, buflen);
common2:
BUMP(buf, buflen);
for (i = 4; i < cnt; i++) {
sprintf(lbuf, " %d", data[i]);
strncpy((char *)buf, lbuf, buflen);
BUMP(buf, buflen);
}
break;
}
}
#endif
#ifdef notdef
prkey(msg, key)
char *msg;
unsigned char *key;
{
register int i;
printf("%s:", msg);
for (i = 0; i < 8; i++)
printf(" %3d", key[i]);
printf("\r\n");
}
#endif

View File

@ -29,38 +29,33 @@
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifdef SRA
#ifdef ENCRYPTION
#include <sys/types.h>
#include <arpa/telnet.h>
#include <pwd.h>
#include <stdio.h>
#ifdef __STDC__
#include <stdlib.h>
#endif
#ifdef NO_STRING_H
#include <strings.h>
#else
#include <string.h>
#endif
#include <syslog.h>
#include <ttyent.h>
#if !defined(NOPAM)
#ifndef NOPAM
#include <security/pam_appl.h>
#else
#include <unistd.h>
#endif
#include <pwd.h>
#include <syslog.h>
#include <ttyent.h>
#include "auth.h"
#include "misc.h"
#include "encrypt.h"
#include "pk.h"
char pka[HEXKEYBYTES+1], ska[HEXKEYBYTES+1], pkb[HEXKEYBYTES+1];
char *user,*pass,*xuser,*xpass;
char *user, *pass, *xuser, *xpass;
DesData ck;
IdeaData ik;
@ -80,7 +75,7 @@ static unsigned char str_data[1024] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
#define SRA_ACCEPT 4
#define SRA_REJECT 5
static int check_user(const char *, const char *);
static int check_user(char *, char *);
/* support routine to send out authentication message */
static int
@ -115,7 +110,7 @@ Data(Authenticator *ap, int type, void *d, int c)
}
int
sra_init(Authenticator *ap, int server)
sra_init(Authenticator *ap __unused, int server)
{
if (server)
str_data[3] = TELQUAL_REPLY;
@ -212,12 +207,10 @@ sra_is(Authenticator *ap, unsigned char *data, int cnt)
if(valid) {
Data(ap, SRA_ACCEPT, (void *)0, 0);
#ifdef DES_ENCRYPTION
skey.data = ck;
skey.type = SK_DES;
skey.length = 8;
encrypt_session_key(&skey, 1);
#endif
sra_valid = 1;
auth_finished(ap, AUTH_VALID);
@ -252,10 +245,9 @@ bad:
void
sra_reply(Authenticator *ap, unsigned char *data, int cnt)
{
extern char *telnet_gets();
char uprompt[256],tuser[256];
Session_Key skey;
int i;
size_t i;
if (cnt-- < 1)
return;
@ -333,12 +325,10 @@ sra_reply(Authenticator *ap, unsigned char *data, int cnt)
case SRA_ACCEPT:
printf("[ SRA accepts you ]\r\n");
#ifdef DES_ENCRYPTION
skey.data = ck;
skey.type = SK_DES;
skey.length = 8;
encrypt_session_key(&skey, 0);
#endif
auth_finished(ap, AUTH_VALID);
return;
@ -350,7 +340,7 @@ sra_reply(Authenticator *ap, unsigned char *data, int cnt)
}
int
sra_status(Authenticator *ap, char *name, int level)
sra_status(Authenticator *ap __unused, char *name, int level)
{
if (level < AUTH_USER)
return(level);
@ -368,7 +358,7 @@ void
sra_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
{
char lbuf[32];
register int i;
int i;
buf[buflen-1] = '\0'; /* make sure its NULL terminated */
buflen -= 1;
@ -423,70 +413,14 @@ sra_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
}
}
struct passwd *pw;
/*
* Helper function for sgetpwnam().
*/
char *
sgetsave(char *s)
{
char *new = malloc((unsigned) strlen(s) + 1);
if (new == NULL) {
return(NULL);
}
(void) strcpy(new, s);
return (new);
}
struct passwd *
sgetpwnam(char *name)
{
static struct passwd save;
register struct passwd *p;
char *sgetsave();
if ((p = getpwnam(name)) == NULL)
return (p);
if (save.pw_name) {
free(save.pw_name);
free(save.pw_passwd);
free(save.pw_gecos);
free(save.pw_dir);
free(save.pw_shell);
}
save = *p;
save.pw_name = sgetsave(p->pw_name);
save.pw_passwd = sgetsave(p->pw_passwd);
save.pw_gecos = sgetsave(p->pw_gecos);
save.pw_dir = sgetsave(p->pw_dir);
save.pw_shell = sgetsave(p->pw_shell);
#if 0
syslog(LOG_WARNING,"%s\n",save.pw_name);
syslog(LOG_WARNING,"%s\n",save.pw_passwd);
syslog(LOG_WARNING,"%s\n",save.pw_gecos);
syslog(LOG_WARNING,"%s\n",save.pw_dir);
#endif
#ifdef USE_SHADOW
{
struct spwd *sp;
sp = getspnam(name);
free(save.pw_passwd);
save.pw_passwd = sgetsave(sp->sp_pwdp);
}
#endif
return (&save);
}
static int
isroot(const char *user)
isroot(const char *usr)
{
struct passwd *pw;
struct passwd *pwd;
if ((pw=getpwnam(user))==NULL)
if ((pwd=getpwnam(usr))==NULL)
return 0;
return (!pw->pw_uid);
return (!pwd->pw_uid);
}
static int
@ -499,9 +433,9 @@ rootterm(char *ttyn)
#ifdef NOPAM
static int
check_user(const char *name, const char *pass)
check_user(char *name, char *cred)
{
register char *cp;
char *cp;
char *xpasswd, *salt;
if (isroot(name) && !rootterm(line))
@ -517,7 +451,7 @@ check_user(const char *name, const char *pass)
}
salt = pw->pw_passwd;
xpasswd = crypt(pass, salt);
xpasswd = crypt(cred, salt);
/* The strcmp does not catch null passwords! */
if (pw == NULL || *pw->pw_passwd == '\0' ||
strcmp(xpasswd, pw->pw_passwd)) {
@ -545,9 +479,8 @@ struct cred_t {
};
typedef struct cred_t cred_t;
int
auth_conv(int num_msg, const struct pam_message **msg,
struct pam_response **resp, void *appdata)
static int
auth_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata)
{
int i;
cred_t *cred = (cred_t *) appdata;
@ -588,13 +521,13 @@ auth_conv(int num_msg, const struct pam_message **msg,
* The PAM version as a side effect may put a new username in *name.
*/
static int
check_user(const char *name, const char *pass)
check_user(char *name, char *cred)
{
pam_handle_t *pamh = NULL;
const void *item;
int rval;
int e;
cred_t auth_cred = { name, pass };
cred_t auth_cred = { name, cred };
struct pam_conv conv = { &auth_conv, &auth_cred };
e = pam_start("telnetd", name, &conv, &pamh);
@ -634,7 +567,7 @@ check_user(const char *name, const char *pass)
*/
if ((e = pam_get_item(pamh, PAM_USER, &item)) ==
PAM_SUCCESS) {
strcpy((char *) name, (const char *) item);
strcpy(name, item);
} else
syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
pam_strerror(pamh, e));
@ -665,5 +598,5 @@ check_user(const char *name, const char *pass)
#endif
#endif
#endif /* ENCRYPTION */
#endif /* SRA */

View File

@ -31,18 +31,20 @@
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static const char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
__FBSDID("$FreeBSD$");
#ifndef lint
static const char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
#endif
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
#include <sys/types.h>
#include <arpa/telnet.h>
#include <pwd.h>
#include <unistd.h>
#include <libtelnet/encrypt.h>
#include <libtelnet/misc.h>
@ -52,10 +54,8 @@ static const char rcsid[] =
#include "defines.h"
#include "types.h"
int
net_write(str, len)
unsigned char *str;
int len;
int
net_write(unsigned char *str, int len)
{
if (NETROOM() > len) {
ring_supply_data(&netoring, str, len);
@ -66,8 +66,8 @@ net_write(str, len)
return(0);
}
void
net_encrypt()
void
net_encrypt(void)
{
#ifdef ENCRYPTION
if (encrypt_output)
@ -77,40 +77,35 @@ net_encrypt()
#endif /* ENCRYPTION */
}
int
telnet_spin()
int
telnet_spin(void)
{
return(-1);
}
char *
telnet_getenv(val)
char *val;
char *
telnet_getenv(char *val)
{
return((char *)env_getvalue((unsigned char *)val));
}
char *
telnet_gets(prompt, result, length, echo)
char *prompt;
char *result;
int length;
int echo;
char *
telnet_gets(const char *prom, char *result, int length, int echo)
{
extern char *getpass();
extern int globalmode;
int om = globalmode;
char *res;
TerminalNewMode(-1);
if (echo) {
printf("%s", prompt);
printf("%s", prom);
res = fgets(result, length, stdin);
} else if ((res = getpass(prompt))) {
} else if ((res = getpass(prom))) {
strncpy(result, res, length);
res = result;
}
TerminalNewMode(om);
return(res);
}
#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
#endif /* ENCRYPTION */
#endif /* AUTHENTICATION */

File diff suppressed because it is too large Load Diff

View File

@ -31,16 +31,11 @@
* SUCH DAMAGE.
*
* @(#)defines.h 8.1 (Berkeley) 6/6/93
* $FreeBSD$
*/
#define settimer(x) clocks.x = clocks.system++
#if !defined(TN3270)
#define SetIn3270()
#endif /* !defined(TN3270) */
#define NETADD(c) { *netoring.supply = c; ring_supplied(&netoring, 1); }
#define NET2ADD(c1,c2) { NETADD(c1); NETADD(c2); }
#define NETBYTES() (ring_full_count(&netoring))

View File

@ -53,21 +53,13 @@
#include <stdio.h>
#include <setjmp.h>
#ifndef FILIO_H
#include <sys/ioctl.h>
#else
#include <sys/filio.h>
#endif
# include <errno.h>
#include <errno.h>
#ifdef USE_TERMIO
# ifndef VINTR
# ifdef SYSV_TERMIO
# include <sys/termio.h>
# else
# include <sys/termios.h>
# define termio termios
# endif
# include <sys/termios.h>
# endif
# define termio termios
#endif
#if defined(NO_CC_T) || !defined(USE_TERMIO)
# if !defined(USE_TERMIO)
@ -77,11 +69,7 @@ typedef unsigned char cc_t;
# endif
#endif
#ifndef NO_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#if defined(IPSEC)
#include <netinet6/ipsec.h>
@ -120,7 +108,6 @@ extern int
flushout, /* flush output */
connected, /* Are we connected to the other side? */
globalmode, /* Mode tty should be in */
In3270, /* Are we in 3270 mode? */
telnetport, /* Are we connected to the telnet port? */
localflow, /* Flow control handled locally */
restartany, /* If flow control, restart output on any character */
@ -139,13 +126,7 @@ extern int
crmod,
netdata, /* Print out network data flow */
prettydump, /* Print "netdata" output in user readable format */
#if defined(unix)
#if defined(TN3270)
cursesdata, /* Print out curses data flow */
apitrace, /* Trace API transactions */
#endif /* defined(TN3270) */
termdata, /* Print out terminal data flow */
#endif /* defined(unix) */
debug, /* Debug level */
doaddrlookup, /* do a reverse lookup? */
clienteof; /* Client received EOF */
@ -233,6 +214,16 @@ extern int (*decrypt_input) P((int));
#define set_his_want_state_dont set_my_want_state_wont
#define set_his_want_state_wont set_my_want_state_dont
#if defined(USE_TERMIO)
#define SIG_FUNC_RET void
#else
#define SIG_FUNC_RET int
#endif
#ifdef SIGINFO
extern SIG_FUNC_RET
ayt_status P((void));
#endif
extern FILE
*NetTrace; /* Where debugging output goes */
@ -246,23 +237,40 @@ extern jmp_buf
toplevel; /* For error conditions. */
extern void
command P((int, char *, int)),
Dump P((int, unsigned char *, int)),
ExitString P((char *, int)),
init_3270 P((void)),
printoption P((char *, int, int)),
printsub P((int, unsigned char *, int)),
command P((int, const char *, int)),
Dump P((char, unsigned char *, int)),
env_init P((void)),
Exit P((int)),
ExitString P((const char *, int)),
init_network P((void)),
init_sys P((void)),
init_telnet P((void)),
init_terminal P((void)),
intp P((void)),
optionstatus P((void)),
printoption P((const char *, int, int)),
printsub P((char, unsigned char *, int)),
quit P((void)),
sendabort P((void)),
sendbrk P((void)),
sendeof P((void)),
sendsusp P((void)),
sendnaws P((void)),
sendayt P((void)),
setconnmode P((int)),
setcommandmode P((void)),
set_escape_char P((char *s)),
setneturg P((void)),
sys_telnet_init P((void)),
telnet P((char *)),
tel_enter_binary P((int)),
tel_leave_binary P((int)),
TerminalFlushOutput P((void)),
TerminalNewMode P((int)),
TerminalRestoreState P((void)),
TerminalSaveState P((void)),
TerminalDefaultChars P((void)),
TerminalSpeeds P((long *, long *)),
tninit P((void)),
upcase P((char *)),
willoption P((int)),
@ -291,16 +299,25 @@ extern void
slc P((unsigned char *, int)),
slc_check P((void)),
slc_start_reply P((void)),
slc_add_reply P((int, int, int)),
slc_add_reply P((unsigned char, unsigned char, cc_t)),
slc_end_reply P((void));
extern int
getconnmode P((void)),
opt_welldefined P((const char *)),
NetClose P((int)),
netflush P((void)),
process_rings P((int, int, int, int, int, int)),
rlogin_susp P((void)),
SetSockOpt P((int, int, int, int)),
slc_update P((void)),
stilloob P((void)),
telrcv P((void)),
TerminalRead P((char *, int)),
TerminalWrite P((char *, int)),
TerminalAutoFlush P((void)),
TerminalWindowSize P((long *, long *)),
TerminalSpecialChars P((int)),
tn P((int, char **)),
ttyflush P((int));
extern void
@ -312,11 +329,11 @@ extern void
extern unsigned char
*env_default P((int, int)),
*env_getvalue P((unsigned char *));
*env_getvalue P((const unsigned char *));
extern int
get_status P((void)),
dosynch P((void));
get_status P((char *)),
dosynch P((char *));
extern cc_t
*tcval P((int));
@ -468,26 +485,7 @@ extern Ring
ttyoring,
ttyiring;
/* Tn3270 section */
#if defined(TN3270)
extern int
HaveInput, /* Whether an asynchronous I/O indication came in */
noasynchtty, /* Don't do signals on I/O (SIGURG, SIGIO) */
noasynchnet, /* Don't do signals on I/O (SIGURG, SIGIO) */
sigiocount, /* Count of SIGIO receptions */
shell_active; /* Subshell is active */
extern char
*Ibackp, /* Oldest byte of 3270 data */
Ibuf[], /* 3270 buffer */
*Ifrontp, /* Where next 3270 byte goes */
tline[],
*transcom; /* Transparent command */
extern int
settranscom P((int, char**));
extern void
inputAvailable P((int));
#endif /* defined(TN3270) */
xmitAO P((void)),
xmitEC P((void)),
xmitEL P((void));

View File

@ -29,19 +29,15 @@
* 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
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1988, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
#endif /* not lint */
#endif
#include <sys/types.h>
#include <sys/socket.h>
@ -53,10 +49,10 @@ static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
#include "externs.h"
#include "defines.h"
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -69,12 +65,6 @@ static const char sccsid[] = "@(#)main.c 8.3 (Berkeley) 5/30/95";
#define FORWARD
#endif
void init_terminal(void);
void init_network(void);
void init_telnet(void);
void init_sys(void);
void init_3270(void);
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
char *ipsec_policy_in = NULL;
char *ipsec_policy_out = NULL;
@ -85,8 +75,8 @@ int family = AF_UNSPEC;
/*
* Initialize variables.
*/
void
tninit()
void
tninit(void)
{
init_terminal();
@ -95,14 +85,10 @@ tninit()
init_telnet();
init_sys();
#if defined(TN3270)
init_3270();
#endif
}
void
usage()
static void
usage(void)
{
fprintf(stderr, "Usage: %s %s%s%s%s\n",
prompt,
@ -113,12 +99,7 @@ usage()
"[-4] [-6] [-8] [-E] [-L] [-N] [-S tos] [-c] [-d]",
"\n\t[-e char] [-l user] [-n tracefile] ",
#endif
#if defined(TN3270) && defined(unix)
"[-noasynch] [-noasynctty] [-noasyncnet] [-r]\n\t"
"[-s src_addr] [-t transcom] ",
#else
"[-r] [-s src_addr] [-u] ",
#endif
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
"[-P policy] "
#endif
@ -135,10 +116,8 @@ usage()
* main. Parse arguments, invoke the protocol or command parser.
*/
int
main(argc, argv)
int argc;
char *argv[];
int
main(int argc, char *argv[])
{
int ch;
char *user;
@ -165,7 +144,7 @@ main(argc, argv)
autologin = -1;
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
encrypt_auto(1);
decrypt_auto(1);
#endif
@ -244,7 +223,8 @@ main(argc, argv)
set_escape_char(optarg);
break;
case 'f':
#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
#ifdef AUTHENTICATION
#if defined(KRB5) && defined(FORWARD)
if (forward_flags & OPTS_FORWARD_CREDS) {
fprintf(stderr,
"%s: Only one of -f and -F allowed.\n",
@ -252,6 +232,11 @@ main(argc, argv)
usage();
}
forward_flags |= OPTS_FORWARD_CREDS;
#else
fprintf(stderr,
"%s: Warning: -f ignored, no Kerberos V5 support.\n",
prompt);
#endif
#else
fprintf(stderr,
"%s: Warning: -f ignored, no Kerberos V5 support.\n",
@ -259,7 +244,8 @@ main(argc, argv)
#endif
break;
case 'F':
#if defined(AUTHENTICATION) && defined(KRB5) && defined(FORWARD)
#ifdef AUTHENTICATION
#if defined(KRB5) && defined(FORWARD)
if (forward_flags & OPTS_FORWARD_CREDS) {
fprintf(stderr,
"%s: Only one of -f and -F allowed.\n",
@ -268,6 +254,11 @@ main(argc, argv)
}
forward_flags |= OPTS_FORWARD_CREDS;
forward_flags |= OPTS_FORWARDABLE_CREDS;
#else
fprintf(stderr,
"%s: Warning: -F ignored, no Kerberos V5 support.\n",
prompt);
#endif
#else
fprintf(stderr,
"%s: Warning: -F ignored, no Kerberos V5 support.\n",
@ -275,12 +266,18 @@ main(argc, argv)
#endif
break;
case 'k':
#if defined(AUTHENTICATION) && defined(KRB4)
#ifdef AUTHENTICATION
#if defined(KRB4)
{
extern char *dest_realm, dst_realm_buf[], dst_realm_sz;
dest_realm = dst_realm_buf;
(void)strncpy(dest_realm, optarg, dst_realm_sz);
}
#else
fprintf(stderr,
"%s: Warning: -k ignored, no Kerberos V4 support.\n",
prompt);
#endif
#else
fprintf(stderr,
"%s: Warning: -k ignored, no Kerberos V4 support.\n",
@ -296,19 +293,6 @@ main(argc, argv)
user = optarg;
break;
case 'n':
#if defined(TN3270) && defined(unix)
/* distinguish between "-n oasynch" and "-noasynch" */
if (argv[optind - 1][0] == '-' && argv[optind - 1][1]
== 'n' && argv[optind - 1][2] == 'o') {
if (!strcmp(optarg, "oasynch")) {
noasynchtty = 1;
noasynchnet = 1;
} else if (!strcmp(optarg, "oasynchtty"))
noasynchtty = 1;
else if (!strcmp(optarg, "oasynchnet"))
noasynchnet = 1;
} else
#endif /* defined(TN3270) && defined(unix) */
SetNetTrace(optarg);
break;
case 'r':
@ -317,23 +301,11 @@ main(argc, argv)
case 's':
src_addr = optarg;
break;
case 't':
#if defined(TN3270) && defined(unix)
transcom = tline;
(void)strcpy(transcom, optarg);
#else
fprintf(stderr,
"%s: Warning: -t ignored, no TN3270 support.\n",
prompt);
#endif
break;
case 'u':
family = AF_UNIX;
break;
case 'x':
#ifdef ENCRYPTION
/* This is the default now, so ignore it */
#else
#ifndef ENCRYPTION
fprintf(stderr,
"%s: Warning: -x ignored, no ENCRYPT support.\n",
prompt);
@ -378,11 +350,11 @@ main(argc, argv)
usage();
*argp++ = prompt;
if (user) {
*argp++ = "-l";
*argp++ = strdup("-l");
*argp++ = user;
}
if (src_addr) {
*argp++ = "-s";
*argp++ = strdup("-s");
*argp++ = src_addr;
}
*argp++ = argv[0]; /* host */
@ -399,11 +371,6 @@ main(argc, argv)
}
(void)setjmp(toplevel);
for (;;) {
#ifdef TN3270
if (shell_active)
shell_continue();
else
#endif
command(1, 0, 0);
}
return 0;

View File

@ -31,14 +31,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/socket.h>
@ -62,8 +61,8 @@ unsigned char netobuf[2*BUFSIZ], netibuf[BUFSIZ];
* Initialize internal network data structures.
*/
void
init_network()
void
init_network(void)
{
if (ring_init(&netoring, netobuf, sizeof netobuf) != 1) {
exit(1);
@ -80,10 +79,10 @@ init_network()
* Telnet "synch" processing).
*/
int
stilloob()
int
stilloob(void)
{
static struct timeval timeout = { 0 };
static struct timeval timeout = { 0, 0 };
fd_set excepts;
int value;
@ -112,8 +111,8 @@ stilloob()
* Sets "neturg" to the current location.
*/
void
setneturg()
void
setneturg(void)
{
ring_mark(&netoring);
}
@ -128,11 +127,10 @@ setneturg()
* useful work.
*/
int
netflush()
int
netflush(void)
{
register int n, n1;
int n, n1;
#ifdef ENCRYPTION
if (encrypt_output)

View File

@ -31,14 +31,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)ring.c 8.2 (Berkeley) 5/30/95";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
/*
* This defines a structure for a ring buffer.
@ -99,17 +98,10 @@ static u_long ring_clock = 0;
#define ring_full(d) (((d)->supply == (d)->consume) && \
((d)->supplytime > (d)->consumetime))
/* Buffer state transition routines */
int
ring_init(ring, buffer, count)
Ring *ring;
unsigned char *buffer;
int count;
int
ring_init(Ring *ring, unsigned char *buffer, int count)
{
memset((char *)ring, 0, sizeof *ring);
@ -132,9 +124,8 @@ ring_init(ring, buffer, count)
* Mark the most recently supplied byte.
*/
void
ring_mark(ring)
Ring *ring;
void
ring_mark(Ring *ring)
{
ring->mark = ring_decrement(ring, ring->supply, 1);
}
@ -143,9 +134,8 @@ ring_mark(ring)
* Is the ring pointing to the mark?
*/
int
ring_at_mark(ring)
Ring *ring;
int
ring_at_mark(Ring *ring)
{
if (ring->mark == ring->consume) {
return 1;
@ -158,9 +148,8 @@ ring_at_mark(ring)
* Clear any mark set on the ring.
*/
void
ring_clear_mark(ring)
Ring *ring;
void
ring_clear_mark(Ring *ring)
{
ring->mark = 0;
}
@ -168,10 +157,8 @@ ring_clear_mark(ring)
/*
* Add characters from current segment to ring buffer.
*/
void
ring_supplied(ring, count)
Ring *ring;
int count;
void
ring_supplied(Ring *ring, int count)
{
ring->supply = ring_increment(ring, ring->supply, count);
ring->supplytime = ++ring_clock;
@ -180,10 +167,8 @@ ring_supplied(ring, count)
/*
* We have just consumed "c" bytes.
*/
void
ring_consumed(ring, count)
Ring *ring;
int count;
void
ring_consumed(Ring *ring, int count)
{
if (count == 0) /* don't update anything */
return;
@ -217,9 +202,8 @@ ring_consumed(ring, count)
/* Number of bytes that may be supplied */
int
ring_empty_count(ring)
Ring *ring;
int
ring_empty_count(Ring *ring)
{
if (ring_empty(ring)) { /* if empty */
return ring->size;
@ -229,9 +213,8 @@ ring_empty_count(ring)
}
/* number of CONSECUTIVE bytes that may be supplied */
int
ring_empty_consecutive(ring)
Ring *ring;
int
ring_empty_consecutive(Ring *ring)
{
if ((ring->consume < ring->supply) || ring_empty(ring)) {
/*
@ -251,9 +234,8 @@ ring_empty_consecutive(ring)
* (but don't give more than enough to get to cross over set mark)
*/
int
ring_full_count(ring)
Ring *ring;
int
ring_full_count(Ring *ring)
{
if ((ring->mark == 0) || (ring->mark == ring->consume)) {
if (ring_full(ring)) {
@ -270,9 +252,8 @@ ring_full_count(ring)
* Return the number of CONSECUTIVE bytes available for consuming.
* However, don't return more than enough to cross over set mark.
*/
int
ring_full_consecutive(ring)
Ring *ring;
int
ring_full_consecutive(Ring *ring)
{
if ((ring->mark == 0) || (ring->mark == ring->consume)) {
if ((ring->supply < ring->consume) || ring_full(ring)) {
@ -292,11 +273,8 @@ ring_full_consecutive(ring)
/*
* Move data into the "supply" portion of of the ring buffer.
*/
void
ring_supply_data(ring, buffer, count)
Ring *ring;
unsigned char *buffer;
int count;
void
ring_supply_data(Ring *ring, unsigned char *buffer, int count)
{
int i;
@ -309,34 +287,9 @@ ring_supply_data(ring, buffer, count)
}
}
#ifdef notdef
/*
* Move data from the "consume" portion of the ring buffer
*/
void
ring_consume_data(ring, buffer, count)
Ring *ring;
unsigned char *buffer;
int count;
{
int i;
while (count) {
i = MIN(count, ring_full_consecutive(ring));
memcpy(buffer, ring->consume, i);
ring_consumed(ring, i);
count -= i;
buffer += i;
}
}
#endif
#ifdef ENCRYPTION
void
ring_encrypt(ring, encryptor)
Ring *ring;
void (*encryptor)();
void
ring_encrypt(Ring *ring, void (*encryptor)(unsigned char *, int))
{
unsigned char *s, *c;

View File

@ -90,6 +90,7 @@ extern void
/* Buffer state query routines */
extern int
ring_at_mark P((Ring *)),
ring_empty_count P((Ring *ring)),
ring_empty_consecutive P((Ring *ring)),
ring_full_count P((Ring *ring)),
@ -97,10 +98,10 @@ extern int
#ifdef ENCRYPTION
extern void
ring_encrypt P((Ring *ring, void (*func)())),
ring_encrypt P((Ring *ring, void (*func)(unsigned char *, int))),
ring_clearto P((Ring *ring));
#endif /* ENCRYPTION */
extern void
ring_clear_mark P((Ring *)),
ring_mark P((Ring *));
ring_clear_mark P((Ring *)),
ring_mark P((Ring *));

View File

@ -31,48 +31,34 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)sys_bsd.c 8.4 (Berkeley) 5/30/95";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
/*
* The following routines try to encapsulate what is system dependent
* (at least between 4.x and dos) which is used in telnet.c.
*/
#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <signal.h>
#include <sys/time.h>
#include <errno.h>
#include <arpa/telnet.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <arpa/telnet.h>
#include "ring.h"
#include "fdset.h"
#include "defines.h"
#include "externs.h"
#include "types.h"
#if defined(USE_TERMIO) && !defined(SYSV_TERMIO)
#define SIG_FUNC_RET void
#else
#define SIG_FUNC_RET int
#endif
#ifdef SIGINFO
extern SIG_FUNC_RET ayt_status();
#endif
int
tout, /* Output file descriptor */
tin, /* Input file descriptor */
@ -88,8 +74,7 @@ int olmode = 0;
# define old_tc ottyb
#else /* USE_TERMIO */
struct termio old_tc = { 0 };
extern struct termio new_tc;
struct termio old_tc = { 0, 0, 0, 0, {}, 0, 0 };
# ifndef TCSANOW
# ifdef TCSETS
@ -122,9 +107,21 @@ extern struct termio new_tc;
static fd_set ibits, obits, xbits;
#ifdef SIGINT
static SIG_FUNC_RET intr(int);
#endif /* SIGINT */
#ifdef SIGQUIT
static SIG_FUNC_RET intr2(int);
#endif /* SIGQUIT */
#ifdef SIGTSTP
static SIG_FUNC_RET susp(int);
#endif /* SIGTSTP */
#ifdef SIGINFO
static SIG_FUNC_RET ayt(int);
#endif
void
init_sys()
void
init_sys(void)
{
tout = fileno(stdout);
tin = fileno(stdin);
@ -135,19 +132,14 @@ init_sys()
errno = 0;
}
int
TerminalWrite(buf, n)
char *buf;
int n;
int
TerminalWrite(char *buf, int n)
{
return write(tout, buf, n);
}
int
TerminalRead(buf, n)
char *buf;
int n;
int
TerminalRead(char *buf, int n)
{
return read(tin, buf, n);
}
@ -156,8 +148,8 @@ TerminalRead(buf, n)
*
*/
int
TerminalAutoFlush()
int
TerminalAutoFlush(void)
{
#if defined(LNOFLSH)
int flush;
@ -184,11 +176,8 @@ extern int kludgelinemode;
* 1 Do add this character
*/
extern void xmitAO(), xmitEL(), xmitEC(), intp(), sendbrk();
int
TerminalSpecialChars(c)
int c;
int
TerminalSpecialChars(int c)
{
if (c == termIntChar) {
intp();
@ -230,8 +219,8 @@ TerminalSpecialChars(c)
* Flush output to the terminal
*/
void
TerminalFlushOutput()
void
TerminalFlushOutput(void)
{
#ifdef TIOCFLUSH
(void) ioctl(fileno(stdout), TIOCFLUSH, (char *) 0);
@ -240,8 +229,8 @@ TerminalFlushOutput()
#endif
}
void
TerminalSaveState()
void
TerminalSaveState(void)
{
#ifndef USE_TERMIO
ioctl(0, TIOCGETP, (char *)&ottyb);
@ -282,9 +271,8 @@ TerminalSaveState()
#endif /* USE_TERMIO */
}
cc_t *
tcval(func)
register int func;
cc_t *
tcval(int func)
{
switch(func) {
case SLC_IP: return(&termIntChar);
@ -325,8 +313,8 @@ tcval(func)
}
}
void
TerminalDefaultChars()
void
TerminalDefaultChars(void)
{
#ifndef USE_TERMIO
ntc = otc;
@ -359,13 +347,6 @@ TerminalDefaultChars()
#endif /* USE_TERMIO */
}
#ifdef notdef
void
TerminalRestoreState()
{
}
#endif
/*
* TerminalNewMode - set up terminal to a specific mode.
* MODE_ECHO: do local terminal echo
@ -388,10 +369,8 @@ TerminalRestoreState()
* local/no signal mapping
*/
void
TerminalNewMode(f)
register int f;
void
TerminalNewMode(int f)
{
static int prevmode = 0;
#ifndef USE_TERMIO
@ -466,10 +445,6 @@ TerminalNewMode(f)
#else
tmp_tc.c_lflag &= ~ECHO;
tmp_tc.c_oflag &= ~ONLCR;
# ifdef notdef
if (crlf)
tmp_tc.c_iflag &= ~ICRNL;
# endif
#endif
}
@ -616,19 +591,6 @@ TerminalNewMode(f)
}
if (f != -1) {
#ifdef SIGINT
SIG_FUNC_RET intr();
#endif /* SIGINT */
#ifdef SIGQUIT
SIG_FUNC_RET intr2();
#endif /* SIGQUIT */
#ifdef SIGTSTP
SIG_FUNC_RET susp();
#endif /* SIGTSTP */
#ifdef SIGINFO
SIG_FUNC_RET ayt();
#endif
#ifdef SIGINT
(void) signal(SIGINT, intr);
#endif
@ -681,9 +643,7 @@ TerminalNewMode(f)
#endif
} else {
#ifdef SIGINFO
SIG_FUNC_RET ayt_status();
(void) signal(SIGINFO, ayt_status);
(void) signal(SIGINFO, (void (*)(int))ayt_status);
#endif
#ifdef SIGINT
(void) signal(SIGINT, SIG_DFL);
@ -718,17 +678,8 @@ TerminalNewMode(f)
tcsetattr(tin, TCSANOW, &tmp_tc);
#endif
#if (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR))
# if !defined(sysV88)
ioctl(tin, FIONBIO, (char *)&onoff);
ioctl(tout, FIONBIO, (char *)&onoff);
# endif
#endif /* (!defined(TN3270)) || ((!defined(NOT43)) || defined(PUTCHAR)) */
#if defined(TN3270)
if (noasynchtty == 0) {
ioctl(tin, FIOASYNC, (char *)&onoff);
}
#endif /* defined(TN3270) */
}
@ -797,15 +748,13 @@ struct termspeeds {
};
#endif /* DECODE_BAUD */
void
TerminalSpeeds(ispeed, ospeed)
long *ispeed;
long *ospeed;
void
TerminalSpeeds(long *ispeed, long *ospeed)
{
#ifdef DECODE_BAUD
register struct termspeeds *tp;
struct termspeeds *tp;
#endif /* DECODE_BAUD */
register long in, out;
long in, out;
out = cfgetospeed(&old_tc);
in = cfgetispeed(&old_tc);
@ -828,9 +777,8 @@ TerminalSpeeds(ispeed, ospeed)
#endif /* DECODE_BAUD */
}
int
TerminalWindowSize(rows, cols)
long *rows, *cols;
int
TerminalWindowSize(long *rows, long *cols)
{
#ifdef TIOCGWINSZ
struct winsize ws;
@ -844,59 +792,34 @@ TerminalWindowSize(rows, cols)
return 0;
}
int
NetClose(fd)
int fd;
int
NetClose(int fd)
{
return close(fd);
}
void
NetNonblockingIO(fd, onoff)
int fd;
int onoff;
static void
NetNonblockingIO(int fd, int onoff)
{
ioctl(fd, FIONBIO, (char *)&onoff);
}
#if defined(TN3270)
void
NetSigIO(fd, onoff)
int fd;
int onoff;
{
ioctl(fd, FIOASYNC, (char *)&onoff); /* hear about input */
}
void
NetSetPgrp(fd)
int fd;
{
int myPid;
myPid = getpid();
fcntl(fd, F_SETOWN, myPid);
}
#endif /*defined(TN3270)*/
/*
* Various signal handling routines.
*/
/* ARGSUSED */
SIG_FUNC_RET
deadpeer(sig)
int sig;
/* ARGSUSED */
static SIG_FUNC_RET
deadpeer(int sig __unused)
{
setcommandmode();
longjmp(peerdied, -1);
}
/* ARGSUSED */
SIG_FUNC_RET
intr(sig)
int sig;
/* ARGSUSED */
SIG_FUNC_RET
intr(int sig __unused)
{
if (localchars) {
intp();
@ -906,10 +829,9 @@ intr(sig)
longjmp(toplevel, -1);
}
/* ARGSUSED */
SIG_FUNC_RET
intr2(sig)
int sig;
/* ARGSUSED */
SIG_FUNC_RET
intr2(int sig __unused)
{
if (localchars) {
#ifdef KLUDGELINEMODE
@ -923,10 +845,9 @@ intr2(sig)
}
#ifdef SIGTSTP
/* ARGSUSED */
SIG_FUNC_RET
susp(sig)
int sig;
/* ARGSUSED */
SIG_FUNC_RET
susp(int sig __unused)
{
if ((rlogin != _POSIX_VDISABLE) && rlogin_susp())
return;
@ -936,10 +857,9 @@ susp(sig)
#endif
#ifdef SIGWINCH
/* ARGSUSED */
SIG_FUNC_RET
sendwin(sig)
int sig;
/* ARGSUSED */
static SIG_FUNC_RET
sendwin(int sig __unused)
{
if (connected) {
sendnaws();
@ -948,10 +868,9 @@ sendwin(sig)
#endif
#ifdef SIGINFO
/* ARGSUSED */
SIG_FUNC_RET
ayt(sig)
int sig;
/* ARGSUSED */
SIG_FUNC_RET
ayt(int sig __unused)
{
if (connected)
sendayt();
@ -961,8 +880,8 @@ ayt(sig)
#endif
void
sys_telnet_init()
void
sys_telnet_init(void)
{
(void) signal(SIGINT, intr);
(void) signal(SIGQUIT, intr2);
@ -981,13 +900,6 @@ sys_telnet_init()
NetNonblockingIO(net, 1);
#if defined(TN3270)
if (noasynchnet == 0) { /* DBX can't handle! */
NetSigIO(net, 1);
NetSetPgrp(net);
}
#endif /* defined(TN3270) */
#if defined(SO_OOBINLINE)
if (SetSockOpt(net, SOL_SOCKET, SO_OOBINLINE, 1) == -1) {
perror("SetSockOpt");
@ -1006,18 +918,12 @@ sys_telnet_init()
* The return value is 1 if something happened, 0 if not.
*/
int
process_rings(netin, netout, netex, ttyin, ttyout, poll)
int poll; /* If 0, then block until something to do */
int
process_rings(int netin, int netout, int netex, int ttyin, int ttyout, int poll)
{
register int c;
/* One wants to be a bit careful about setting returnValue
* to one, since a one implies we did some useful work,
* and therefore probably won't be called to block next
* time (TN3270 mode only).
*/
int c;
int returnValue = 0;
static struct timeval TimeValue = { 0 };
static struct timeval TimeValue = { 0, 0 };
if (netout) {
FD_SET(net, &obits);
@ -1025,24 +931,12 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
if (ttyout) {
FD_SET(tout, &obits);
}
#if defined(TN3270)
if (ttyin) {
FD_SET(tin, &ibits);
}
#else /* defined(TN3270) */
if (ttyin) {
FD_SET(tin, &ibits);
}
#endif /* defined(TN3270) */
#if defined(TN3270)
if (netin) {
FD_SET(net, &ibits);
}
# else /* !defined(TN3270) */
if (netin) {
FD_SET(net, &ibits);
}
# endif /* !defined(TN3270) */
if (netex) {
FD_SET(net, &xbits);
}
@ -1057,23 +951,6 @@ process_rings(netin, netout, netex, ttyin, ttyout, poll)
if (errno == EINTR) {
return 0;
}
# if defined(TN3270)
/*
* we can get EBADF if we were in transparent
* mode, and the transcom process died.
*/
if (errno == EBADF) {
/*
* zero the bits (even though kernel does it)
* to make sure we are selecting on the right
* ones.
*/
FD_ZERO(&ibits);
FD_ZERO(&obits);
FD_ZERO(&xbits);
return 0;
}
# endif /* defined(TN3270) */
/* I don't like this, does it ever happen? */
printf("sleep(5) from telnet, after select: %s\r\n", strerror(errno));
sleep(5);

File diff suppressed because it is too large Load Diff

View File

@ -31,14 +31,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#include <arpa/telnet.h>
#include <sys/types.h>
@ -48,7 +47,7 @@ static const char rcsid[] =
#include "externs.h"
#include "types.h"
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -97,8 +96,8 @@ cc_t termAytChar;
* initialize the terminal data structures.
*/
void
init_terminal()
void
init_terminal(void)
{
if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
exit(1);
@ -109,7 +108,6 @@ init_terminal()
autoflush = TerminalAutoFlush();
}
/*
* Send as much data as possible to the terminal.
*
@ -120,12 +118,10 @@ init_terminal()
* n: All data - n was written out.
*/
int
ttyflush(drop)
int drop;
int
ttyflush(int drop)
{
register int n, n0, n1;
int n, n0, n1;
n0 = ring_full_count(&ttyoring);
if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
@ -171,8 +167,8 @@ ttyflush(drop)
*/
int
getconnmode()
int
getconnmode(void)
{
extern int linemode;
int mode = 0;
@ -180,9 +176,6 @@ getconnmode()
extern int kludgelinemode;
#endif
if (In3270)
return(MODE_FLOW);
if (my_want_state_is_dont(TELOPT_ECHO))
mode |= MODE_ECHO;
@ -211,14 +204,13 @@ getconnmode()
return(mode);
}
void
setconnmode(force)
int force;
void
setconnmode(int force)
{
#ifdef ENCRYPTION
static int enc_passwd = 0;
#endif /* ENCRYPTION */
register int newmode;
int newmode;
newmode = getconnmode()|(force?MODE_FORCE:0);
@ -241,9 +233,8 @@ setconnmode(force)
}
void
setcommandmode()
void
setcommandmode(void)
{
TerminalNewMode(-1);
}

View File

@ -1,416 +0,0 @@
/*
* Copyright (c) 1988, 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
* are met:
* 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
* SUCH DAMAGE.
*/
#ifndef lint
#if 0
static const char sccsid[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#include <sys/types.h>
#include <arpa/telnet.h>
#include "general.h"
#include "defines.h"
#include "ring.h"
#include "externs.h"
#include "fdset.h"
#if defined(TN3270)
#include "../ctlr/screen.h"
#include "../general/globals.h"
#include "../sys_curses/telextrn.h"
#include "../ctlr/externs.h"
#if defined(unix)
int
HaveInput, /* There is input available to scan */
cursesdata, /* Do we dump curses data? */
sigiocount; /* Number of times we got a SIGIO */
char tline[200];
char *transcom = 0; /* transparent mode command (default: none) */
#endif /* defined(unix) */
char Ibuf[8*BUFSIZ], *Ifrontp, *Ibackp;
static char sb_terminal[] = { IAC, SB,
TELOPT_TTYPE, TELQUAL_IS,
'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
IAC, SE };
#define SBTERMMODEL 13
static int
Sent3270TerminalType; /* Have we said we are a 3270? */
#endif /* defined(TN3270) */
void
init_3270()
{
#if defined(TN3270)
#if defined(unix)
HaveInput = 0;
sigiocount = 0;
#endif /* defined(unix) */
Sent3270TerminalType = 0;
Ifrontp = Ibackp = Ibuf;
init_ctlr(); /* Initialize some things */
init_keyboard();
init_screen();
init_system();
#endif /* defined(TN3270) */
}
#if defined(TN3270)
/*
* DataToNetwork - queue up some data to go to network. If "done" is set,
* then when last byte is queued, we add on an IAC EOR sequence (so,
* don't call us with "done" until you want that done...)
*
* We actually do send all the data to the network buffer, since our
* only client needs for us to do that.
*/
int
DataToNetwork(buffer, count, done)
register char *buffer; /* where the data is */
register int count; /* how much to send */
int done; /* is this the last of a logical block */
{
register int loop, c;
int origCount;
origCount = count;
while (count) {
/* If not enough room for EORs, IACs, etc., wait */
if (NETROOM() < 6) {
fd_set o;
FD_ZERO(&o);
netflush();
while (NETROOM() < 6) {
FD_SET(net, &o);
(void) select(net+1, (fd_set *) 0, &o, (fd_set *) 0,
(struct timeval *) 0);
netflush();
}
}
c = ring_empty_count(&netoring);
if (c > count) {
c = count;
}
loop = c;
while (loop) {
if (((unsigned char)*buffer) == IAC) {
break;
}
buffer++;
loop--;
}
if ((c = c-loop)) {
ring_supply_data(&netoring, buffer-c, c);
count -= c;
}
if (loop) {
NET2ADD(IAC, IAC);
count--;
buffer++;
}
}
if (done) {
NET2ADD(IAC, EOR);
netflush(); /* try to move along as quickly as ... */
}
return(origCount - count);
}
#if defined(unix)
void
inputAvailable(signo)
int signo;
{
HaveInput = 1;
sigiocount++;
}
#endif /* defined(unix) */
void
outputPurge()
{
(void) ttyflush(1);
}
/*
* The following routines are places where the various tn3270
* routines make calls into telnet.c.
*/
/*
* DataToTerminal - queue up some data to go to terminal.
*
* Note: there are people who call us and depend on our processing
* *all* the data at one time (thus the select).
*/
int
DataToTerminal(buffer, count)
register char *buffer; /* where the data is */
register int count; /* how much to send */
{
register int c;
int origCount;
origCount = count;
while (count) {
if (TTYROOM() == 0) {
#if defined(unix)
fd_set o;
FD_ZERO(&o);
#endif /* defined(unix) */
(void) ttyflush(0);
while (TTYROOM() == 0) {
#if defined(unix)
FD_SET(tout, &o);
(void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
(struct timeval *) 0);
#endif /* defined(unix) */
(void) ttyflush(0);
}
}
c = TTYROOM();
if (c > count) {
c = count;
}
ring_supply_data(&ttyoring, buffer, c);
count -= c;
buffer += c;
}
return(origCount);
}
/*
* Push3270 - Try to send data along the 3270 output (to screen) direction.
*/
int
Push3270()
{
int save = ring_full_count(&netiring);
if (save) {
if (Ifrontp+save > Ibuf+sizeof Ibuf) {
if (Ibackp != Ibuf) {
memmove(Ibuf, Ibackp, Ifrontp-Ibackp);
Ifrontp -= (Ibackp-Ibuf);
Ibackp = Ibuf;
}
}
if (Ifrontp+save < Ibuf+sizeof Ibuf) {
(void)telrcv();
}
}
return save != ring_full_count(&netiring);
}
/*
* Finish3270 - get the last dregs of 3270 data out to the terminal
* before quitting.
*/
void
Finish3270()
{
while (Push3270() || !DoTerminalOutput()) {
#if defined(unix)
HaveInput = 0;
#endif /* defined(unix) */
;
}
}
/* StringToTerminal - output a null terminated string to the terminal */
void
StringToTerminal(s)
char *s;
{
int count;
count = strlen(s);
if (count) {
(void) DataToTerminal(s, count); /* we know it always goes... */
}
}
#if ((!defined(NOT43)) || defined(PUTCHAR))
/* _putchar - output a single character to the terminal. This name is so that
* curses(3x) can call us to send out data.
*/
void
_putchar(c)
char c;
{
#if defined(sun) /* SunOS 4.0 bug */
c &= 0x7f;
#endif /* defined(sun) */
if (cursesdata) {
Dump('>', &c, 1);
}
if (!TTYROOM()) {
(void) DataToTerminal(&c, 1);
} else {
TTYADD(c);
}
}
#endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
void
SetIn3270()
{
if (Sent3270TerminalType && my_want_state_is_will(TELOPT_BINARY)
&& my_want_state_is_do(TELOPT_BINARY) && !donebinarytoggle) {
if (!In3270) {
In3270 = 1;
Init3270(); /* Initialize 3270 functions */
/* initialize terminal key mapping */
InitTerminal(); /* Start terminal going */
setconnmode(0);
}
} else {
if (In3270) {
StopScreen(1);
In3270 = 0;
Stop3270(); /* Tell 3270 we aren't here anymore */
setconnmode(0);
}
}
}
/*
* tn3270_ttype()
*
* Send a response to a terminal type negotiation.
*
* Return '0' if no more responses to send; '1' if a response sent.
*/
int
tn3270_ttype()
{
/*
* Try to send a 3270 type terminal name. Decide which one based
* on the format of our screen, and (in the future) color
* capaiblities.
*/
InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
if ((MaxNumberLines >= 24) && (MaxNumberColumns >= 80)) {
Sent3270TerminalType = 1;
if ((MaxNumberLines >= 27) && (MaxNumberColumns >= 132)) {
MaxNumberLines = 27;
MaxNumberColumns = 132;
sb_terminal[SBTERMMODEL] = '5';
} else if (MaxNumberLines >= 43) {
MaxNumberLines = 43;
MaxNumberColumns = 80;
sb_terminal[SBTERMMODEL] = '4';
} else if (MaxNumberLines >= 32) {
MaxNumberLines = 32;
MaxNumberColumns = 80;
sb_terminal[SBTERMMODEL] = '3';
} else {
MaxNumberLines = 24;
MaxNumberColumns = 80;
sb_terminal[SBTERMMODEL] = '2';
}
NumberLines = 24; /* before we start out... */
NumberColumns = 80;
ScreenSize = NumberLines*NumberColumns;
if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
ExitString("Programming error: MAXSCREENSIZE too small.\n",
1);
/*NOTREACHED*/
}
printsub('>', sb_terminal+2, sizeof sb_terminal-2);
ring_supply_data(&netoring, sb_terminal, sizeof sb_terminal);
return 1;
} else {
return 0;
}
}
#if defined(unix)
int
settranscom(argc, argv)
int argc;
char *argv[];
{
int i;
if (argc == 1 && transcom) {
transcom = 0;
}
if (argc == 1) {
return 1;
}
transcom = tline;
(void) strcpy(transcom, argv[1]);
for (i = 2; i < argc; ++i) {
(void) strcat(transcom, " ");
(void) strcat(transcom, argv[i]);
}
return 1;
}
#endif /* defined(unix) */
#endif /* defined(TN3270) */

View File

@ -31,14 +31,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)utilities.c 8.3 (Berkeley) 5/30/95";
#else
static const char rcsid[] =
"$FreeBSD$";
#endif
#endif /* not lint */
#define TELOPTS
#define TELCMDS
@ -60,10 +59,10 @@ static const char rcsid[] =
#include "externs.h"
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -76,11 +75,10 @@ int prettydump;
* Upcase (in place) the argument.
*/
void
upcase(argument)
register char *argument;
void
upcase(char *argument)
{
register int c;
int c;
while ((c = *argument) != 0) {
if (islower(c)) {
@ -96,21 +94,11 @@ upcase(argument)
* Compensate for differences in 4.2 and 4.3 systems.
*/
int
SetSockOpt(fd, level, option, yesno)
int fd, level, option, yesno;
int
SetSockOpt(int fd, int level, int option, int yesno)
{
#ifndef NOT43
return setsockopt(fd, level, option,
(char *)&yesno, sizeof yesno);
#else /* NOT43 */
if (yesno == 0) { /* Can't do that in 4.2! */
fprintf(stderr, "Error: attempt to turn off an option 0x%x.\n",
option);
return -1;
}
return setsockopt(fd, level, option, 0, 0);
#endif /* NOT43 */
}
/*
@ -119,9 +107,8 @@ SetSockOpt(fd, level, option, yesno)
unsigned char NetTraceFile[256] = "(standard output)";
void
SetNetTrace(file)
register char *file;
void
SetNetTrace(char *file)
{
if (NetTrace && NetTrace != stdout)
fclose(NetTrace);
@ -137,11 +124,8 @@ SetNetTrace(file)
strcpy((char *)NetTraceFile, "(standard output)");
}
void
Dump(direction, buffer, length)
char direction;
unsigned char *buffer;
int length;
void
Dump(char direction, unsigned char *buffer, int length)
{
# define BYTES_PER_LINE 32
# define min(x,y) ((x<y)? x:y)
@ -188,10 +172,8 @@ Dump(direction, buffer, length)
}
void
printoption(direction, cmd, option)
char *direction;
int cmd, option;
void
printoption(const char *direction, int cmd, int option)
{
if (!showoptions)
return;
@ -201,7 +183,7 @@ printoption(direction, cmd, option)
else
fprintf(NetTrace, "%s IAC %d", direction, option);
} else {
register char *fmt;
const char *fmt;
fmt = (cmd == WILL) ? "WILL" : (cmd == WONT) ? "WONT" :
(cmd == DO) ? "DO" : (cmd == DONT) ? "DONT" : 0;
if (fmt) {
@ -224,10 +206,10 @@ printoption(direction, cmd, option)
return;
}
void
optionstatus()
void
optionstatus(void)
{
register int i;
int i;
extern char will_wont_resp[], do_dont_resp[];
for (i = 0; i < 256; i++) {
@ -301,14 +283,13 @@ optionstatus()
}
void
printsub(direction, pointer, length)
char direction; /* '<' or '>' */
unsigned char *pointer; /* where suboption data sits */
int length; /* length of suboption data */
void
printsub(char direction, unsigned char *pointer, int length)
{
register int i;
int i;
#ifdef AUTHENTICATION
char buf[512];
#endif
extern int want_status_response;
if (showoptions || direction == 0 ||
@ -317,7 +298,7 @@ printsub(direction, pointer, length)
fprintf(NetTrace, "%s IAC SB ",
(direction == '<')? "RCVD":"SENT");
if (length >= 3) {
register int j;
int j;
i = pointer[length-2];
j = pointer[length-1];
@ -431,7 +412,7 @@ printsub(direction, pointer, length)
fprintf(NetTrace, " ?%d?", pointer[i]);
break;
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
case TELOPT_AUTHENTICATION:
fprintf(NetTrace, "AUTHENTICATION");
if (length < 2) {
@ -668,8 +649,8 @@ printsub(direction, pointer, length)
break;
case TELOPT_STATUS: {
register char *cp;
register int j, k;
const char *cp;
int j, k;
fprintf(NetTrace, "STATUS");
@ -782,7 +763,7 @@ printsub(direction, pointer, length)
fprintf(NetTrace, "INFO ");
env_common:
{
register int noquote = 2;
int noquote = 2;
#if defined(ENV_HACK) && defined(OLD_ENVIRON)
extern int old_env_var, old_env_value;
#endif
@ -877,72 +858,52 @@ printsub(direction, pointer, length)
* way to the kernel (thus the select).
*/
void
EmptyTerminal()
static void
EmptyTerminal(void)
{
#if defined(unix)
fd_set o;
FD_ZERO(&o);
#endif /* defined(unix) */
if (TTYBYTES() == 0) {
#if defined(unix)
FD_SET(tout, &o);
(void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
(struct timeval *) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
} else {
while (TTYBYTES()) {
(void) ttyflush(0);
#if defined(unix)
FD_SET(tout, &o);
(void) select(tout+1, (fd_set *) 0, &o, (fd_set *) 0,
(struct timeval *) 0); /* wait for TTLOWAT */
#endif /* defined(unix) */
}
}
}
void
SetForExit()
static void
SetForExit(void)
{
setconnmode(0);
#if defined(TN3270)
if (In3270) {
Finish3270();
}
#else /* defined(TN3270) */
do {
(void)telrcv(); /* Process any incoming data */
EmptyTerminal();
} while (ring_full_count(&netiring)); /* While there is any */
#endif /* defined(TN3270) */
setcommandmode();
fflush(stdout);
fflush(stderr);
#if defined(TN3270)
if (In3270) {
StopScreen(1);
}
#endif /* defined(TN3270) */
setconnmode(0);
EmptyTerminal(); /* Flush the path to the tty */
setcommandmode();
}
void
Exit(returnCode)
int returnCode;
void
Exit(int returnCode)
{
SetForExit();
exit(returnCode);
}
void
ExitString(string, returnCode)
char *string;
int returnCode;
void
ExitString(const char *string, int returnCode)
{
SetForExit();
fwrite(string, 1, strlen(string), stderr);

View File

@ -31,22 +31,23 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
/* Above "#ifdef"s actually "or"'ed together. XXX MarkM
*/
#include "telnetd.h"
#include <libtelnet/misc.h>
int
net_write(str, len)
unsigned char *str;
int len;
int
net_write(unsigned char *str, int len)
{
if (nfrontp + len < netobuf + BUFSIZ) {
output_datalen(str, len);
@ -55,8 +56,8 @@ net_write(str, len)
return(0);
}
void
net_encrypt()
void
net_encrypt(void)
{
#ifdef ENCRYPTION
char *s = (nclearto > nbackp) ? nclearto : nbackp;
@ -67,27 +68,23 @@ net_encrypt()
#endif /* ENCRYPTION */
}
int
telnet_spin()
int
telnet_spin(void)
{
ttloop();
return(0);
}
char *
telnet_getenv(val)
char *val;
char *
telnet_getenv(char *val)
{
return(getenv(val));
}
char *
telnet_gets(prompt, result, length, echo)
char *prompt;
char *result;
int length;
int echo;
char *
telnet_gets(const char *prompt __unused, char *result __unused, int length __unused, int echo __unused)
{
return((char *)0);
return(NULL);
}
#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
#endif /* ENCRYPTION */
#endif /* AUTHENTICATION */

View File

@ -56,10 +56,7 @@ extern int diagnostic; /* telnet diagnostic capabilities */
#ifdef BFTPDAEMON
extern int bftpd; /* behave as bftp daemon */
#endif /* BFTPDAEMON */
#if defined(SecurID)
extern int require_SecurID;
#endif
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
extern int auth_level;
#endif
@ -93,12 +90,12 @@ extern int SYNCHing; /* we are in TELNET SYNCH mode */
extern void
_termstat P((void)),
add_slc P((int, int, int)),
add_slc P((char, char, cc_t)),
check_slc P((void)),
change_slc P((int, int, int)),
change_slc P((char, char, cc_t)),
cleanup P((int)),
clientstat P((int, int, int)),
copy_termbuf P((char *, int)),
copy_termbuf P((char *, size_t)),
deferslc P((void)),
defer_terminit P((void)),
do_opt_slc P((unsigned char *, int)),
@ -106,8 +103,8 @@ extern void
dooption P((int)),
dontoption P((int)),
edithost P((char *, char *)),
fatal P((int, char *)),
fatalperror P((int, char *)),
fatal P((int, const char *)),
fatalperror P((int, const char *)),
get_slc_defaults P((void)),
init_env P((void)),
init_termbuf P((void)),
@ -117,10 +114,11 @@ extern void
netclear P((void)),
netflush P((void)),
#ifdef DIAGNOSTICS
printoption P((char *, int)),
printdata P((char *, char *, int)),
printsub P((int, unsigned char *, int)),
printoption P((const char *, int)),
printdata P((const char *, char *, int)),
printsub P((char, unsigned char *, int)),
#endif
process_slc P((unsigned char, unsigned char, cc_t)),
ptyflush P((void)),
putchr P((int)),
putf P((char *, char *)),
@ -136,7 +134,7 @@ extern void
set_termbuf P((void)),
start_login P((char *, int, char *)),
start_slc P((int)),
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
start_slave P((char *)),
#else
start_slave P((char *, int, char *)),
@ -186,6 +184,7 @@ extern void
int output_data __P((const char *, ...)) __printflike(1, 2);
void output_datalen __P((const char *, int));
void startslave __P((char *, int, char *));
#ifdef ENCRYPTION
extern void (*encrypt_output) P((unsigned char *, int));

View File

@ -31,13 +31,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include "telnetd.h"
@ -56,10 +56,10 @@ static unsigned char slcbuf[NSLC*6]; /* buffer for slc negotiation */
*
* Write out the current special characters to the client.
*/
void
send_slc()
void
send_slc(void)
{
register int i;
int i;
/*
* Send out list of triplets of special characters
@ -80,10 +80,10 @@ send_slc()
*
* Set pty special characters to all the defaults.
*/
void
default_slc()
static void
default_slc(void)
{
register int i;
int i;
for (i = 1; i <= NSLC; i++) {
slctab[i].current.val = slctab[i].defset.val;
@ -105,10 +105,10 @@ default_slc()
*
* Initialize the slc mapping table.
*/
void
get_slc_defaults()
void
get_slc_defaults(void)
{
register int i;
int i;
init_termbuf();
@ -127,10 +127,8 @@ get_slc_defaults()
*
* Add an slc triplet to the slc buffer.
*/
void
add_slc(func, flag, val)
register char func, flag;
register cc_t val;
void
add_slc(char func, char flag, cc_t val)
{
if ((*slcptr++ = (unsigned char)func) == 0xff)
@ -152,9 +150,8 @@ add_slc(func, flag, val)
* The parameter getit is non-zero if it is necessary to grab a copy
* of the terminal control structures.
*/
void
start_slc(getit)
register int getit;
void
start_slc(int getit)
{
slcchange = 0;
@ -171,11 +168,10 @@ start_slc(getit)
*
* Finish up the slc negotiation. If something to send, then send it.
*/
int
end_slc(bufp)
register unsigned char **bufp;
int
end_slc(unsigned char **bufp)
{
register int len;
int len;
/*
* If a change has occured, store the new terminal control
@ -217,12 +213,10 @@ end_slc(bufp)
*
* Figure out what to do about the client's slc
*/
void
process_slc(func, flag, val)
register unsigned char func, flag;
register cc_t val;
void
process_slc(unsigned char func, unsigned char flag, cc_t val)
{
register int hislevel, mylevel, ack;
int hislevel, mylevel, ack;
/*
* Ensure that we know something about this function
@ -283,12 +277,10 @@ process_slc(func, flag, val)
* Process a request to change one of our special characters.
* Compare client's request with what we are capable of supporting.
*/
void
change_slc(func, flag, val)
register char func, flag;
register cc_t val;
void
change_slc(char func, char flag, cc_t val)
{
register int hislevel, mylevel;
int hislevel, mylevel;
hislevel = flag & SLC_LEVELBITS;
mylevel = slctab[(int)func].defset.flag & SLC_LEVELBITS;
@ -393,10 +385,10 @@ cc_t oldeofc = '\004';
* likely to have changed. If a local change occurs, kick the support level
* and flags up to the defaults.
*/
void
check_slc()
void
check_slc(void)
{
register int i;
int i;
for (i = 1; i <= NSLC; i++) {
#if defined(USE_TERMIO) && (VEOF == VMIN)
@ -436,14 +428,12 @@ check_slc()
*
* ptr points to the beginning of the buffer, len is the length.
*/
void
do_opt_slc(ptr, len)
register unsigned char *ptr;
register int len;
void
do_opt_slc(unsigned char *ptr, int len)
{
register unsigned char func, flag;
unsigned char func, flag;
cc_t val;
register unsigned char *end = ptr + len;
unsigned char *end = ptr + len;
if (terminit()) { /* go ahead */
while (ptr < end) {
@ -477,8 +467,8 @@ do_opt_slc(ptr, len)
*
* Do slc stuff that was deferred.
*/
void
deferslc()
void
deferslc(void)
{
if (def_slcbuf) {
start_slc(1);

View File

@ -31,20 +31,20 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <stdarg.h>
#include "telnetd.h"
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -89,10 +89,12 @@ unsigned char *subsave;
#define TS_DO 7 /* do " */
#define TS_DONT 8 /* dont " */
void
telrcv()
static void doclientstat(void);
void
telrcv(void)
{
register int c;
int c;
static int state = TS_DATA;
while (ncc > 0) {
@ -422,9 +424,8 @@ gotiac: switch (c) {
* is complete.
*
*/
void
send_do(option, init)
int option, init;
void
send_do(int option, int init)
{
if (init) {
if ((do_dont_resp[option] == 0 && his_state_is_will(option)) ||
@ -446,22 +447,11 @@ send_do(option, init)
DIAG(TD_OPTIONS, printoption("td: send do", option));
}
#ifdef AUTHENTICATION
extern void auth_request();
#endif
#ifdef LINEMODE
extern void doclientstat();
#endif
#ifdef ENCRYPTION
extern void encrypt_send_support();
#endif /* ENCRYPTION */
void
willoption(option)
int option;
void
willoption(int option)
{
int changeok = 0;
void (*func)() = 0;
void (*func)(void) = 0;
/*
* process input from peer.
@ -649,9 +639,8 @@ willoption(option)
(*func)();
} /* end of willoption */
void
send_dont(option, init)
int option, init;
void
send_dont(int option, int init)
{
if (init) {
if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) ||
@ -665,9 +654,8 @@ send_dont(option, init)
DIAG(TD_OPTIONS, printoption("td: send dont", option));
}
void
wontoption(option)
int option;
void
wontoption(int option)
{
/*
* Process client input.
@ -731,7 +719,7 @@ wontoption(option)
slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE;
break;
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
case TELOPT_AUTHENTICATION:
auth_finished(0, AUTH_REJECT);
break;
@ -784,7 +772,7 @@ wontoption(option)
#endif /* defined(LINEMODE) && defined(KLUDGELINEMODE) */
break;
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
case TELOPT_AUTHENTICATION:
auth_finished(0, AUTH_REJECT);
break;
@ -798,9 +786,8 @@ wontoption(option)
} /* end of wontoption */
void
send_will(option, init)
int option, init;
void
send_will(int option, int init)
{
if (init) {
if ((will_wont_resp[option] == 0 && my_state_is_will(option))||
@ -825,9 +812,8 @@ send_will(option, init)
int turn_on_sga = 0;
#endif
void
dooption(option)
int option;
void
dooption(int option)
{
int changeok = 0;
@ -956,9 +942,8 @@ dooption(option)
} /* end of dooption */
void
send_wont(option, init)
int option, init;
void
send_wont(int option, int init)
{
if (init) {
if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) ||
@ -972,9 +957,8 @@ send_wont(option, init)
DIAG(TD_OPTIONS, printoption("td: send wont", option));
}
void
dontoption(option)
int option;
void
dontoption(int option)
{
/*
* Process client input.
@ -1078,17 +1062,17 @@ int env_ovalue = -1;
* Window size
* Terminal speed
*/
void
suboption()
void
suboption(void)
{
register int subchar;
int subchar;
DIAG(TD_OPTIONS, {netflush(); printsub('<', subpointer, SB_LEN()+2);});
subchar = SB_GET();
switch (subchar) {
case TELOPT_TSPEED: {
register int xspeed, rspeed;
int xspeed, rspeed;
if (his_state_is_wont(TELOPT_TSPEED)) /* Ignore if option disabled */
break;
@ -1126,7 +1110,7 @@ suboption()
while ((terminaltype < (terminalname + sizeof terminalname-1)) &&
!SB_EOF()) {
register int c;
int c;
c = SB_GET();
if (isupper(c)) {
@ -1140,7 +1124,7 @@ suboption()
} /* end of case TELOPT_TTYPE */
case TELOPT_NAWS: {
register int xwinsize, ywinsize;
int xwinsize, ywinsize;
if (his_state_is_wont(TELOPT_NAWS)) /* Ignore if option disabled */
break;
@ -1165,7 +1149,7 @@ suboption()
#ifdef LINEMODE
case TELOPT_LINEMODE: {
register int request;
int request;
if (his_state_is_wont(TELOPT_LINEMODE)) /* Ignore if option disabled */
break;
@ -1245,8 +1229,8 @@ suboption()
case TELOPT_NEW_ENVIRON:
#endif
case TELOPT_OLD_ENVIRON: {
register int c;
register char *cp, *varp, *valp;
int c;
char *cp, *varp, *valp;
if (SB_EOF())
return;
@ -1277,7 +1261,7 @@ suboption()
* reversed.
*/
if (env_ovar < 0) {
register int last = -1; /* invalid value */
int last = -1; /* invalid value */
int empty = 0;
int got_var = 0, got_value = 0, got_uservar = 0;
@ -1427,7 +1411,7 @@ suboption()
unsetenv(varp);
break;
} /* end of case TELOPT_NEW_ENVIRON */
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
case TELOPT_AUTHENTICATION:
if (SB_EOF())
break;
@ -1498,20 +1482,20 @@ suboption()
} /* end of suboption */
void
doclientstat()
static void
doclientstat(void)
{
clientstat(TELOPT_LINEMODE, WILL, 0);
}
#define ADD(c) *ncp++ = c
#define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; }
void
send_status()
void
send_status(void)
{
unsigned char statusbuf[256];
register unsigned char *ncp;
register unsigned char i;
unsigned char *ncp;
unsigned char i;
ncp = statusbuf;

File diff suppressed because it is too large Load Diff

View File

@ -243,26 +243,6 @@ have been idle for some period of time to determine
if the client is still there, so that idle connections
from machines that have crashed or can no longer
be reached may be cleaned up.
.It Fl s
This option is only enabled if
.Nm
is compiled with support for
.Tn SecurID
cards.
It causes the
.Fl s
option to be passed on to
.Xr login 1 ,
and thus is only useful if
.Xr login 1
supports the
.Fl s
flag to indicate that only
.Tn SecurID
validated logins are allowed, and is
usually useful for controlling remote logins
from outside of a firewall.
.It Fl S Ar tos
.It Fl u Ar len
This option is used to specify the size of the field
in the

View File

@ -31,67 +31,39 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include "telnetd.h"
#include "pathnames.h"
#include <err.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <err.h>
#include <libutil.h>
#include <paths.h>
#include <termcap.h>
#include <utmp.h>
#if defined(AUTHENTICATION)
#include <arpa/inet.h>
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
int auth_level = 0;
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
#include <libtelnet/misc.h>
#if defined(SecurID)
int require_SecurID = 0;
#endif
char remote_hostname[MAXHOSTNAMELEN];
int utmp_len = sizeof(remote_hostname) - 1;
size_t utmp_len = sizeof(remote_hostname) - 1;
int registerd_host_only = 0;
#ifdef STREAMSPTY
# include <stropts.h>
# include <termio.h>
/* make sure we don't get the bsd version */
# include "/usr/include/sys/tty.h"
# include <sys/ptyvar.h>
/*
* Because of the way ptyibuf is used with streams messages, we need
* ptyibuf+1 to be on a full-word boundary. The following weirdness
* is simply to make that happen.
*/
long ptyibufbuf[BUFSIZ/sizeof(long)+1];
char *ptyibuf = ((char *)&ptyibufbuf[1])-1;
char *ptyip = ((char *)&ptyibufbuf[1])-1;
char ptyibuf2[BUFSIZ];
unsigned char ctlbuf[BUFSIZ];
struct strbuf strbufc, strbufd;
#else /* ! STREAMPTY */
/*
* I/O data buffers,
@ -100,25 +72,21 @@ struct strbuf strbufc, strbufd;
char ptyibuf[BUFSIZ], *ptyip = ptyibuf;
char ptyibuf2[BUFSIZ];
# include <termcap.h>
int readstream(int p, char *ibuf, int bufsize);
void doit(struct sockaddr *who);
int terminaltypeok(char *s);
void startslave(char *host, int autologin, char *autoname);
#endif /* ! STREAMPTY */
int readstream(int, char *, int);
void doit(struct sockaddr *);
int terminaltypeok(char *);
int hostinfo = 1; /* do we print login banner? */
int debug = 0;
int keepalive = 1;
char *altlogin;
const char *altlogin;
void doit __P((struct sockaddr *));
int terminaltypeok __P((char *));
void startslave __P((char *, int, char *));
extern void usage P((void));
static void _gettermname __P((void));
/*
* The string to pass to getopt(). We do it this way so
@ -142,22 +110,30 @@ char valid_opts[] = {
#endif
#ifdef LINEMODE
'l',
#endif
#ifdef SecurID
's',
#endif
'\0'
};
int family = AF_INET;
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif /* MAXHOSTNAMELEN */
char *hostname;
char host_name[MAXHOSTNAMELEN];
extern void telnet P((int, int, char *));
int level;
char user_name[256];
int
main(argc, argv)
char *argv[];
main(int argc, char *argv[])
{
struct sockaddr_storage from;
int on = 1, fromlen;
register int ch;
int ch;
#if defined(IPPROTO_IP) && defined(IP_TOS)
int tos = -1;
#endif
@ -290,12 +266,6 @@ main(argc, argv)
altlogin = optarg;
break;
#ifdef SecurID
case 's':
/* SecurID required */
require_SecurID = 1;
break;
#endif /* SecurID */
case 'S':
#ifdef HAS_GETTOS
if ((tos = parsetos(optarg, "tcp")) < 0)
@ -308,9 +278,7 @@ main(argc, argv)
break;
case 'u':
utmp_len = atoi(optarg);
if (utmp_len < 0)
utmp_len = -utmp_len;
utmp_len = (size_t)atoi(optarg);
if (utmp_len >= sizeof(remote_hostname))
utmp_len = sizeof(remote_hostname) - 1;
break;
@ -352,7 +320,7 @@ main(argc, argv)
if (debug) {
int s, ns, foo, error;
char *service = "telnet";
const char *service = "telnet";
struct addrinfo hints, *res;
if (argc > 1) {
@ -460,9 +428,6 @@ usage()
#endif
fprintf(stderr, " [-n]");
fprintf(stderr, "\n\t");
#ifdef SecurID
fprintf(stderr, " [-s]");
#endif
#ifdef HAS_GETTOS
fprintf(stderr, " [-S tos]");
#endif
@ -484,15 +449,20 @@ static unsigned char ttytype_sbbuf[] = {
IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE
};
int
getterminaltype(name)
char *name;
#ifndef AUTHENTICATION
#define undef2 __unused
#else
#define undef2
#endif
static int
getterminaltype(char *name undef2)
{
int retval = -1;
void _gettermname();
settimer(baseline);
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
/*
* Handle the Authentication option before we do anything else.
*/
@ -630,8 +600,8 @@ getterminaltype(name)
return(retval);
} /* end of getterminaltype */
void
_gettermname()
static void
_gettermname(void)
{
/*
* If the client turned off the option,
@ -648,9 +618,8 @@ _gettermname()
ttloop();
}
int
terminaltypeok(s)
char *s;
int
terminaltypeok(char *s)
{
char buf[1024];
@ -669,25 +638,13 @@ terminaltypeok(s)
return(1);
}
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif /* MAXHOSTNAMELEN */
char *hostname;
char host_name[MAXHOSTNAMELEN];
extern void telnet P((int, int, char *));
int level;
char user_name[256];
/*
* Get a pty, scan input lines.
*/
void
doit(who)
struct sockaddr *who;
void
doit(struct sockaddr *who)
{
int err;
int err_; /* XXX */
int ptynum;
/*
@ -721,17 +678,23 @@ doit(who)
trimdomain(remote_hostname, UT_HOSTSIZE);
if (!isdigit(remote_hostname[0]) && strlen(remote_hostname) > utmp_len)
err = getnameinfo(who, who->sa_len, remote_hostname,
err_ = getnameinfo(who, who->sa_len, remote_hostname,
sizeof(remote_hostname), NULL, 0,
NI_NUMERICHOST|NI_WITHSCOPEID);
/* XXX: do 'err' check */
/* XXX: do 'err_' check */
(void) gethostname(host_name, sizeof(host_name) - 1);
host_name[sizeof(host_name) - 1] = '\0';
hostname = host_name;
#if defined(AUTHENTICATION) || defined(ENCRYPTION)
#ifdef AUTHENTICATION
#ifdef ENCRYPTION
/* The above #ifdefs should actually be "or"'ed, not "and"'ed.
* This is a byproduct of needing "#ifdef" and not "#if defined()"
* for unifdef. XXX MarkM
*/
auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1);
#endif
#endif
init_env();
@ -751,10 +714,8 @@ doit(who)
* Main loop. Select from pty and network, and
* hand data to telnet receiver finite state machine.
*/
void
telnet(f, p, host)
int f, p;
char *host;
void
telnet(int f, int p, char *host)
{
int on = 1;
#define TABBUFSIZ 512
@ -861,12 +822,10 @@ telnet(f, p, host)
if (my_state_is_wont(TELOPT_ECHO))
send_will(TELOPT_ECHO, 1);
#ifndef STREAMSPTY
/*
* Turn on packet mode
*/
(void) ioctl(p, TIOCPKT, (char *)&on);
#endif
#if defined(LINEMODE) && defined(KLUDGELINEMODE)
/*
@ -908,7 +867,7 @@ telnet(f, p, host)
#ifdef TIOCNOTTY
{
register int t;
int t;
t = open(_PATH_TTY, O_RDWR);
if (t >= 0) {
(void) ioctl(t, TIOCNOTTY, (char *)0);
@ -926,7 +885,6 @@ telnet(f, p, host)
*/
if (getent(defent, "default") == 1) {
char *Getstr();
char *cp=defstrs;
HE = Getstr("he", &cp);
@ -935,9 +893,9 @@ telnet(f, p, host)
if (HN && *HN)
(void) strlcpy(host_name, HN, sizeof(host_name));
if (IM == 0)
IM = "";
IM = strdup("");
} else {
IM = DEFAULT_IM;
IM = strdup(DEFAULT_IM);
HE = 0;
}
edithost(HE, host_name);
@ -968,7 +926,7 @@ telnet(f, p, host)
nfd = ((f > p) ? f : p) + 1;
for (;;) {
fd_set ibits, obits, xbits;
register int c;
int c;
if (ncc < 0 && pcc < 0)
break;
@ -1089,11 +1047,7 @@ telnet(f, p, host)
* Something to read from the pty...
*/
if (FD_ISSET(p, &ibits)) {
#ifndef STREAMSPTY
pcc = read(p, ptyibuf, BUFSIZ);
#else
pcc = readstream(p, ptyibuf, BUFSIZ);
#endif
/*
* On some systems, if we try to read something
* off the master side before the slave side is
@ -1188,114 +1142,16 @@ telnet(f, p, host)
# endif
#endif
#ifdef STREAMSPTY
int flowison = -1; /* current state of flow: -1 is unknown */
int readstream(p, ibuf, bufsize)
int p;
char *ibuf;
int bufsize;
{
int flags = 0;
int ret = 0;
struct termios *tsp;
struct termio *tp;
struct iocblk *ip;
char vstop, vstart;
int ixon;
int newflow;
strbufc.maxlen = BUFSIZ;
strbufc.buf = (char *)ctlbuf;
strbufd.maxlen = bufsize-1;
strbufd.len = 0;
strbufd.buf = ibuf+1;
ibuf[0] = 0;
ret = getmsg(p, &strbufc, &strbufd, &flags);
if (ret < 0) /* error of some sort -- probably EAGAIN */
return(-1);
if (strbufc.len <= 0 || ctlbuf[0] == M_DATA) {
/* data message */
if (strbufd.len > 0) { /* real data */
return(strbufd.len + 1); /* count header char */
} else {
/* nothing there */
errno = EAGAIN;
return(-1);
}
}
/*
* It's a control message. Return 1, to look at the flag we set
*/
switch (ctlbuf[0]) {
case M_FLUSH:
if (ibuf[1] & FLUSHW)
ibuf[0] = TIOCPKT_FLUSHWRITE;
return(1);
case M_IOCTL:
ip = (struct iocblk *) (ibuf+1);
switch (ip->ioc_cmd) {
case TCSETS:
case TCSETSW:
case TCSETSF:
tsp = (struct termios *)
(ibuf+1 + sizeof(struct iocblk));
vstop = tsp->c_cc[VSTOP];
vstart = tsp->c_cc[VSTART];
ixon = tsp->c_iflag & IXON;
break;
case TCSETA:
case TCSETAW:
case TCSETAF:
tp = (struct termio *) (ibuf+1 + sizeof(struct iocblk));
vstop = tp->c_cc[VSTOP];
vstart = tp->c_cc[VSTART];
ixon = tp->c_iflag & IXON;
break;
default:
errno = EAGAIN;
return(-1);
}
newflow = (ixon && (vstart == 021) && (vstop == 023)) ? 1 : 0;
if (newflow != flowison) { /* it's a change */
flowison = newflow;
ibuf[0] = newflow ? TIOCPKT_DOSTOP : TIOCPKT_NOSTOP;
return(1);
}
}
/* nothing worth doing anything about */
errno = EAGAIN;
return(-1);
}
#endif /* STREAMSPTY */
/*
* Send interrupt to process on other side of pty.
* If it is in raw mode, just write NULL;
* otherwise, write intr char.
*/
void
interrupt()
void
interrupt(void)
{
ptyflush(); /* half-hearted */
#if defined(STREAMSPTY) && defined(TIOCSIGNAL)
/* Streams PTY style ioctl to post a signal */
{
int sig = SIGINT;
(void) ioctl(pty, TIOCSIGNAL, &sig);
(void) ioctl(pty, I_FLUSH, FLUSHR);
}
#else
#ifdef TCSIG
(void) ioctl(pty, TCSIG, (char *)SIGINT);
#else /* TCSIG */
@ -1303,7 +1159,6 @@ interrupt()
*pfrontp++ = slctab[SLC_IP].sptr ?
(unsigned char)*slctab[SLC_IP].sptr : '\177';
#endif /* TCSIG */
#endif
}
/*
@ -1311,8 +1166,8 @@ interrupt()
* If it is in raw mode, just write NULL;
* otherwise, write quit char.
*/
void
sendbrk()
void
sendbrk(void)
{
ptyflush(); /* half-hearted */
#ifdef TCSIG
@ -1324,8 +1179,8 @@ sendbrk()
#endif /* TCSIG */
}
void
sendsusp()
void
sendsusp(void)
{
#ifdef SIGTSTP
ptyflush(); /* half-hearted */
@ -1342,8 +1197,8 @@ sendsusp()
* When we get an AYT, if ^T is enabled, use that. Otherwise,
* just send back "[Yes]".
*/
void
recv_ayt()
void
recv_ayt(void)
{
#if defined(SIGINFO) && defined(TCSIG)
if (slctab[SLC_AYT].sptr && *slctab[SLC_AYT].sptr != _POSIX_VDISABLE) {
@ -1354,8 +1209,8 @@ recv_ayt()
output_data("\r\n[Yes]\r\n");
}
void
doeof()
void
doeof(void)
{
init_termbuf();

View File

@ -31,6 +31,7 @@
* SUCH DAMAGE.
*
* @(#)telnetd.h 8.1 (Berkeley) 6/4/93
* $FreeBSD$
*/
@ -45,5 +46,4 @@
/* other external variables */
extern char **environ;
extern int errno;
extern const char *altlogin;

View File

@ -31,17 +31,17 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef lint
#if 0
static const char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include "telnetd.h"
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -133,8 +133,8 @@ static int _terminit = 0;
* then linemode is off, if server won't SGA, then linemode
* is on.
*/
void
localstat()
void
localstat(void)
{
int need_will_echo = 0;
@ -357,8 +357,8 @@ done:
*
* Check for changes to flow control
*/
void
flowstat()
void
flowstat(void)
{
if (his_state_is_will(TELOPT_LFLOW)) {
if (tty_flowmode() != flowmode) {
@ -387,9 +387,8 @@ flowstat()
* at a time, and if using kludge linemode, then only linemode may be
* affected.
*/
void
clientstat(code, parm1, parm2)
register int code, parm1, parm2;
void
clientstat(int code, int parm1, int parm2)
{
/*
@ -464,7 +463,7 @@ clientstat(code, parm1, parm2)
case LM_MODE:
{
register int ack, changed;
int ack, changed;
/*
* Client has sent along a mode mask. If it agrees with
@ -589,8 +588,8 @@ clientstat(code, parm1, parm2)
* function is called when the pty state has been processed for the first time.
* It calls other functions that do things that were deferred in each module.
*/
void
defer_terminit()
void
defer_terminit(void)
{
/*
@ -624,8 +623,8 @@ defer_terminit()
*
* Returns true if the pty state has been processed yet.
*/
int
terminit()
int
terminit(void)
{
return(_terminit);

View File

@ -47,10 +47,10 @@ static const char rcsid[] =
#define PRINTOPTIONS
#include "telnetd.h"
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
#include <libtelnet/auth.h>
#endif
#if defined(ENCRYPTION)
#ifdef ENCRYPTION
#include <libtelnet/encrypt.h>
#endif
@ -95,11 +95,10 @@ ttloop()
/*
* Check a descriptor to see if out of band data exists on it.
*/
int
stilloob(s)
int s; /* socket number */
int
stilloob(int s)
{
static struct timeval timeout = { 0 };
static struct timeval timeout = { 0, 0 };
fd_set excepts;
int value;
@ -120,8 +119,8 @@ stilloob(s)
}
}
void
ptyflush()
void
ptyflush(void)
{
int n;
@ -151,9 +150,8 @@ ptyflush()
* if the current address is a TELNET IAC ("I Am a Command")
* character.
*/
char *
nextitem(current)
char *current;
static char *
nextitem(char *current)
{
if ((*current&0xff) != IAC) {
return current+1;
@ -166,7 +164,7 @@ nextitem(current)
return current+3;
case SB: /* loop forever looking for the SE */
{
register char *look = current+2;
char *look = current+2;
for (;;) {
if ((*look++&0xff) == IAC) {
@ -181,7 +179,6 @@ nextitem(current)
}
} /* end of nextitem */
/*
* netclear()
*
@ -198,10 +195,10 @@ nextitem(current)
* caller should be setting the urgent data pointer AFTER calling
* us in any case.
*/
void
netclear()
void
netclear(void)
{
register char *thisitem, *next;
char *thisitem, *next;
char *good;
#define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
@ -251,8 +248,8 @@ netclear()
* Send as much data as possible to the network,
* handling requests for urgent data.
*/
void
netflush()
void
netflush(void)
{
int n;
extern int not42;
@ -326,10 +323,8 @@ netflush()
*/
void
fatal(f, msg)
int f;
char *msg;
void
fatal(int f, const char *msg)
{
char buf[BUFSIZ];
@ -349,12 +344,10 @@ fatal(f, msg)
exit(1);
}
void
fatalperror(f, msg)
int f;
char *msg;
void
fatalperror(int f, const char *msg)
{
char buf[BUFSIZ], *strerror();
char buf[BUFSIZ];
(void) snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(errno));
fatal(f, buf);
@ -362,15 +355,13 @@ fatalperror(f, msg)
char editedhost[32];
void
edithost(pat, host)
register char *pat;
register char *host;
void
edithost(char *pat, char *host)
{
register char *res = editedhost;
char *res = editedhost;
if (!pat)
pat = "";
pat = strdup("");
while (*pat) {
switch (*pat) {
@ -404,18 +395,16 @@ edithost(pat, host)
static char *putlocation;
void
putstr(s)
register char *s;
static void
putstr(const char *s)
{
while (*s)
putchr(*s++);
}
void
putchr(cc)
int cc;
void
putchr(int cc)
{
*putlocation++ = cc;
}
@ -423,18 +412,11 @@ putchr(cc)
#ifdef __FreeBSD__
static char fmtstr[] = { "%+" };
#else
/*
* This is split on two lines so that SCCS will not see the M
* between two % signs and expand it...
*/
static char fmtstr[] = { "%l:%M\
%P on %A, %d %B %Y" };
static char fmtstr[] = { "%l:%M%P on %A, %d %B %Y" };
#endif
void
putf(cp, where)
register char *cp;
char *where;
void
putf(char *cp, char *where)
{
char *slash;
time_t t;
@ -515,10 +497,8 @@ putf(cp, where)
/*
* Print telnet options and commands in plain text, if possible.
*/
void
printoption(fmt, option)
register char *fmt;
register int option;
void
printoption(const char *fmt, int option)
{
if (TELOPT_OK(option))
output_data("%s %s\r\n", fmt, TELOPT(option));
@ -529,13 +509,10 @@ printoption(fmt, option)
return;
}
void
printsub(direction, pointer, length)
char direction; /* '<' or '>' */
unsigned char *pointer; /* where suboption data sits */
int length; /* length of suboption data */
void
printsub(char direction, unsigned char *pointer, int length)
{
register int i = 0;
int i = 0;
if (!(diagnostic & TD_OPTIONS))
return;
@ -544,7 +521,7 @@ printsub(direction, pointer, length)
output_data("td: %s suboption ",
direction == '<' ? "recv" : "send");
if (length >= 3) {
register int j;
int j;
i = pointer[length-2];
j = pointer[length-1];
@ -764,8 +741,8 @@ printsub(direction, pointer, length)
break;
case TELOPT_STATUS: {
register char *cp;
register int j, k;
const char *cp;
int j, k;
output_data("STATUS");
@ -866,7 +843,7 @@ printsub(direction, pointer, length)
output_data("INFO ");
env_common:
{
register int noquote = 2;
int noquote = 2;
for (i = 2; i < length; i++ ) {
switch (pointer[i]) {
case NEW_ENV_VAR:
@ -911,7 +888,7 @@ printsub(direction, pointer, length)
}
break;
#if defined(AUTHENTICATION)
#ifdef AUTHENTICATION
case TELOPT_AUTHENTICATION:
output_data("AUTHENTICATION");
@ -1070,13 +1047,10 @@ printsub(direction, pointer, length)
/*
* Dump a data buffer in hex and ascii to the output data stream.
*/
void
printdata(tag, ptr, cnt)
register char *tag;
register char *ptr;
register int cnt;
void
printdata(const char *tag, char *ptr, int cnt)
{
register int i;
int i;
char xbuf[30];
while (cnt) {