1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11
12 #if defined(AUTHENTICATION) || defined(ENCRYPTION)
13 #include <sys/types.h>
14 #include <arpa/telnet.h>
15 #include <libtelnet/encrypt.h>
16 #include <libtelnet/misc.h>
17
18 #include "general.h"
19 #include "ring.h"
20 #include "externs.h"
21 #include "defines.h"
22 #include "types.h"
23
24 int
net_write(str,len)25 net_write(str, len)
26 unsigned char *str;
27 int len;
28 {
29 if (NETROOM() > len) {
30 ring_supply_data(&netoring, str, len);
31 if (str[0] == IAC && str[1] == SE)
32 printsub('>', &str[2], len-2);
33 return(len);
34 }
35 return(0);
36 }
37
38 void
net_encrypt()39 net_encrypt()
40 {
41 #ifdef ENCRYPTION
42 if (encrypt_output)
43 ring_encrypt(&netoring, encrypt_output);
44 else
45 ring_clearto(&netoring);
46 #endif /* ENCRYPTION */
47 }
48
49 int
telnet_spin()50 telnet_spin()
51 {
52 return(-1);
53 }
54
55 char *
telnet_getenv(val)56 telnet_getenv(val)
57 char *val;
58 {
59 return((char *)env_getvalue((unsigned char *)val));
60 }
61
62 char *
telnet_gets(prompt,result,length,echo)63 telnet_gets(prompt, result, length, echo)
64 char *prompt;
65 char *result;
66 int length;
67 int echo;
68 {
69 extern char *getpass();
70 extern int globalmode;
71 int om = globalmode;
72 char *res;
73
74 TerminalNewMode(-1);
75 if (echo) {
76 printf("%s", prompt);
77 res = fgets(result, length, stdin);
78 } else if (res = getpass(prompt)) {
79 strncpy(result, res, length);
80 res = result;
81 }
82 TerminalNewMode(om);
83 return(res);
84 }
85 #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */
86