Debian Codegraph @

telnet/authenc.c

raw
1 /*
2 Copyright (C) 1995-2026 Free Software Foundation, Inc.
3
4 This file is part of GNU Inetutils.
5
6 GNU Inetutils is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Inetutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see `http://www.gnu.org/licenses/'. */
18
19 /*
20 * Copyright (c) 1991, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. Neither the name of the University nor the names of its contributors
32 * may be used to endorse or promote products derived from this software
33 * without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 */
47
48 #include <config.h>
49
50 #if defined AUTHENTICATION || defined ENCRYPTION
51 # include <unistd.h>
52 # include <sys/types.h>
53 # include <arpa/telnet.h>
54 # include <libtelnet/encrypt.h>
55 # include <libtelnet/misc.h>
56
57 # include "general.h"
58 # include "ring.h"
59 # include "externs.h"
60 # include "defines.h"
61 # include "types.h"
62
63 int
64 net_write (unsigned char *str, int len)
65 {
66 if (NETROOM () > len)
67 {
68 ring_supply_data (&netoring, str, len);
69 if (str[0] == IAC && str[1] == SE)
70 printsub ('>', &str[2], len - 2);
71 return (len);
72 }
73 return (0);
74 }
75
76 void
77 net_encrypt (void)
78 {
79 # ifdef ENCRYPTION
80 if (encrypt_output)
81 ring_encrypt (&netoring, encrypt_output);
82 else
83 ring_clearto (&netoring);
84 # endif/* ENCRYPTION */
85 }
86
87 int
88 telnet_spin (void)
89 {
90 return (-1);
91 }
92
93 char *
94 telnet_getenv (char *val)
95 {
96 return (char *) env_getvalue (val, false);
97 }
98
99 char *
100 telnet_gets (char *prompt, char *result, int length, int echo)
101 {
102 extern int globalmode;
103 int om = globalmode;
104 char *res;
105
106 TerminalNewMode (-1);
107 if (echo)
108 {
109 printf ("%s", prompt);
110 res = fgets (result, length, stdin);
111 }
112 else
113 {
114 res = getpass (prompt);
115 if (res)
116 {
117 strncpy (result, res, length);
118 memset (res, 0, strlen (res));
119 res = result;
120 }
121 }
122 TerminalNewMode (om);
123 return (res);
124 }
125 #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */