1219820Sjeff/*
2219820Sjeff * Copyright (c) 1989, 1993
3219820Sjeff *	The Regents of the University of California.  All rights reserved.
4219820Sjeff *
5219820Sjeff * Redistribution and use in source and binary forms, with or without
6219820Sjeff * modification, are permitted provided that the following conditions
7219820Sjeff * are met:
8219820Sjeff * 1. Redistributions of source code must retain the above copyright
9219820Sjeff *    notice, this list of conditions and the following disclaimer.
10219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright
11219820Sjeff *    notice, this list of conditions and the following disclaimer in the
12219820Sjeff *    documentation and/or other materials provided with the distribution.
13219820Sjeff * 3. All advertising materials mentioning features or use of this software
14219820Sjeff *    must display the following acknowledgement:
15219820Sjeff *	This product includes software developed by the University of
16219820Sjeff *	California, Berkeley and its contributors.
17219820Sjeff * 4. Neither the name of the University nor the names of its contributors
18219820Sjeff *    may be used to endorse or promote products derived from this software
19219820Sjeff *    without specific prior written permission.
20219820Sjeff *
21219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22219820Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23219820Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24219820Sjeff * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25219820Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26219820Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27219820Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28219820Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29219820Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30219820Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31219820Sjeff * SUCH DAMAGE.
32219820Sjeff */
33219820Sjeff
34219820Sjeff/* a *lot* of ugly global definitions that really should be removed...
35219820Sjeff */
36219820Sjeff
37219820Sjeff#include "telnetd.h"
38219820Sjeff
39219820SjeffRCSID("$Id$");
40219820Sjeff
41219820Sjeff/*
42219820Sjeff * Telnet server variable declarations
43219820Sjeff */
44219820Sjeffchar	options[256];
45219820Sjeffchar	do_dont_resp[256];
46219820Sjeffchar	will_wont_resp[256];
47219820Sjeffint	linemode;	/* linemode on/off */
48219820Sjeffint	flowmode;	/* current flow control state */
49219820Sjeffint	restartany;	/* restart output on any character state */
50219820Sjeff#ifdef DIAGNOSTICS
51219820Sjeffint	diagnostic;	/* telnet diagnostic capabilities */
52219820Sjeff#endif /* DIAGNOSTICS */
53219820Sjeffint	require_otp;
54219820Sjeff
55219820Sjeffslcfun	slctab[NSLC + 1];	/* slc mapping table */
56219820Sjeff
57219820Sjeffchar	terminaltype[41];
58219820Sjeff
59219820Sjeff/*
60219820Sjeff * I/O data buffers, pointers, and counters.
61219820Sjeff */
62219820Sjeffchar	ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
63219820Sjeff
64219820Sjeffchar	netibuf[BUFSIZ], *netip;
65219820Sjeff
66219820Sjeffchar	netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
67219820Sjeffchar	*neturg;		/* one past last bye of urgent data */
68219820Sjeff
69219820Sjeffint	pcc, ncc;
70219820Sjeff
71219820Sjeffint	ourpty, net;
72219820Sjeffint	SYNCHing;		/* we are in TELNET SYNCH mode */
73219820Sjeff
74219820Sjeff/*
75219820Sjeff * The following are some clocks used to decide how to interpret
76219820Sjeff * the relationship between various variables.
77219820Sjeff */
78219820Sjeff
79219820Sjeffstruct clocks_t clocks;
80219820Sjeff
81219820Sjeff
82219820Sjeff/* whether to log unauthenticated login attempts */
83219820Sjeffint log_unauth;
84219820Sjeff
85219820Sjeff/* do not print warning if connection is not encrypted */
86219820Sjeffint no_warn;
87219820Sjeff
88219820Sjeff/*
89219820Sjeff * This function appends data to nfrontp and advances nfrontp.
90219820Sjeff */
91219820Sjeff
92219820Sjeffint
93219820Sjeffoutput_data (const char *format, ...)
94219820Sjeff{
95219820Sjeff  va_list args;
96219820Sjeff  int remaining, ret;
97219820Sjeff
98219820Sjeff  va_start(args, format);
99219820Sjeff  remaining = BUFSIZ - (nfrontp - netobuf);
100219820Sjeff  ret = vsnprintf (nfrontp,
101219820Sjeff		   remaining,
102219820Sjeff		   format,
103219820Sjeff		   args);
104219820Sjeff  nfrontp += min(ret, remaining-1);
105219820Sjeff  va_end(args);
106219820Sjeff  return ret;
107219820Sjeff}
108219820Sjeff