157416Smarkm/*-
257416Smarkm * Copyright (c) 1991, 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#include "telnet_locl.h"
3557416Smarkm
36233294SstasRCSID("$Id$");
3757416Smarkm
3857416Smarkm#if	defined(AUTHENTICATION) || defined(ENCRYPTION)
3957416Smarkmint
4057416Smarkmtelnet_net_write(unsigned char *str, int len)
4157416Smarkm{
4257416Smarkm	if (NETROOM() > len) {
4357416Smarkm		ring_supply_data(&netoring, str, len);
4457416Smarkm		if (str[0] == IAC && str[1] == SE)
4557416Smarkm			printsub('>', &str[2], len-2);
4657416Smarkm		return(len);
4757416Smarkm	}
4857416Smarkm	return(0);
4957416Smarkm}
5057416Smarkm
5157416Smarkmvoid
5257416Smarkmnet_encrypt(void)
5357416Smarkm{
5457416Smarkm#if	defined(ENCRYPTION)
5557416Smarkm	if (encrypt_output)
5657416Smarkm		ring_encrypt(&netoring, encrypt_output);
5757416Smarkm	else
5857416Smarkm		ring_clearto(&netoring);
5957416Smarkm#endif
6057416Smarkm}
6157416Smarkm
6257416Smarkmint
6357416Smarkmtelnet_spin(void)
6457416Smarkm{
65178825Sdfr    int ret = 0;
6690926Snectar
6790926Snectar    scheduler_lockout_tty = 1;
68178825Sdfr    if (Scheduler(0) == -1)
69178825Sdfr	ret = 1;
7090926Snectar    scheduler_lockout_tty = 0;
71233294Sstas
72178825Sdfr    return ret;
7390926Snectar
7457416Smarkm}
7557416Smarkm
7657416Smarkmchar *
7772445Sassartelnet_getenv(const char *val)
7857416Smarkm{
7957416Smarkm	return((char *)env_getvalue((unsigned char *)val));
8057416Smarkm}
8157416Smarkm
8257416Smarkmchar *
8357416Smarkmtelnet_gets(char *prompt, char *result, int length, int echo)
8457416Smarkm{
8557416Smarkm	int om = globalmode;
8657416Smarkm	char *res;
8757416Smarkm
8857416Smarkm	TerminalNewMode(-1);
8957416Smarkm	if (echo) {
9057416Smarkm		printf("%s", prompt);
9157416Smarkm		res = fgets(result, length, stdin);
9257416Smarkm	} else if ((res = getpass(prompt))) {
9357416Smarkm		strlcpy(result, res, length);
9457416Smarkm		res = result;
9557416Smarkm	}
9657416Smarkm	TerminalNewMode(om);
9757416Smarkm	return(res);
9857416Smarkm}
9957416Smarkm#endif
100