157416Smarkm/*
257416Smarkm * Copyright (c) 1989, 1993
357416Smarkm *	The Regents of the University of California.  All rights reserved.
457416Smarkm *
557416Smarkm * Redistribution and use in source and binary forms, with or without
657416Smarkm * modification, are permitted provided that the following conditions
757416Smarkm * are met:
857416Smarkm * 1. Redistributions of source code must retain the above copyright
957416Smarkm *    notice, this list of conditions and the following disclaimer.
1057416Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1157416Smarkm *    notice, this list of conditions and the following disclaimer in the
1257416Smarkm *    documentation and/or other materials provided with the distribution.
1357416Smarkm * 3. All advertising materials mentioning features or use of this software
1457416Smarkm *    must display the following acknowledgement:
1557416Smarkm *	This product includes software developed by the University of
1657416Smarkm *	California, Berkeley and its contributors.
1757416Smarkm * 4. Neither the name of the University nor the names of its contributors
1857416Smarkm *    may be used to endorse or promote products derived from this software
1957416Smarkm *    without specific prior written permission.
2057416Smarkm *
2157416Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2257416Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2357416Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2457416Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2557416Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2657416Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2757416Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2857416Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2957416Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3057416Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3157416Smarkm * SUCH DAMAGE.
3257416Smarkm */
3357416Smarkm
3457416Smarkm/* a *lot* of ugly global definitions that really should be removed...
3557416Smarkm */
3657416Smarkm
3757416Smarkm#include "telnetd.h"
3857416Smarkm
39178825SdfrRCSID("$Id: global.c 14939 2005-04-24 20:59:35Z lha $");
4057416Smarkm
4157416Smarkm/*
4257416Smarkm * Telnet server variable declarations
4357416Smarkm */
4457416Smarkmchar	options[256];
4557416Smarkmchar	do_dont_resp[256];
4657416Smarkmchar	will_wont_resp[256];
4757416Smarkmint	linemode;	/* linemode on/off */
4857416Smarkmint	flowmode;	/* current flow control state */
4957416Smarkmint	restartany;	/* restart output on any character state */
5057416Smarkm#ifdef DIAGNOSTICS
5157416Smarkmint	diagnostic;	/* telnet diagnostic capabilities */
5257416Smarkm#endif /* DIAGNOSTICS */
5357416Smarkmint	require_otp;
5457416Smarkm
5557416Smarkmslcfun	slctab[NSLC + 1];	/* slc mapping table */
5657416Smarkm
57178825Sdfrchar	terminaltype[41];
5857416Smarkm
5957416Smarkm/*
6057416Smarkm * I/O data buffers, pointers, and counters.
6157416Smarkm */
6257416Smarkmchar	ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp;
6357416Smarkm
6457416Smarkmchar	netibuf[BUFSIZ], *netip;
6557416Smarkm
6657416Smarkmchar	netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp;
6757416Smarkmchar	*neturg;		/* one past last bye of urgent data */
6857416Smarkm
6957416Smarkmint	pcc, ncc;
7057416Smarkm
7157416Smarkmint	ourpty, net;
7257416Smarkmint	SYNCHing;		/* we are in TELNET SYNCH mode */
7357416Smarkm
7457416Smarkm/*
7557416Smarkm * The following are some clocks used to decide how to interpret
7657416Smarkm * the relationship between various variables.
7757416Smarkm */
7857416Smarkm
7957416Smarkmstruct clocks_t clocks;
8057416Smarkm
8157416Smarkm
8257416Smarkm/* whether to log unauthenticated login attempts */
8357416Smarkmint log_unauth;
8457416Smarkm
8557416Smarkm/* do not print warning if connection is not encrypted */
8657416Smarkmint no_warn;
8757416Smarkm
8857416Smarkm/*
8957416Smarkm * This function appends data to nfrontp and advances nfrontp.
9057416Smarkm */
9157416Smarkm
9257416Smarkmint
9357416Smarkmoutput_data (const char *format, ...)
9457416Smarkm{
9557416Smarkm  va_list args;
9690926Snectar  int remaining, ret;
9757416Smarkm
9857416Smarkm  va_start(args, format);
9957416Smarkm  remaining = BUFSIZ - (nfrontp - netobuf);
10057416Smarkm  ret = vsnprintf (nfrontp,
10157416Smarkm		   remaining,
10257416Smarkm		   format,
10357416Smarkm		   args);
10490926Snectar  nfrontp += min(ret, remaining-1);
10557416Smarkm  va_end(args);
10657416Smarkm  return ret;
10757416Smarkm}
108