xref: /freebsd/contrib/telnet/libtelnet/misc.c (revision 257e70f1d5ee61037c8c59b116538d3b6b1427a2)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef lint
31 #if 0
32 static const char sccsid[] = "@(#)misc.c	8.1 (Berkeley) 6/4/93";
33 #endif
34 #endif /* not lint */
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 #include "misc.h"
41 #ifdef	AUTHENTICATION
42 #include "auth.h"
43 #endif
44 #ifdef	ENCRYPTION
45 #include "encrypt.h"
46 #endif	/* ENCRYPTION */
47 
48 char *RemoteHostName;
49 char *LocalHostName;
50 char *UserNameRequested = 0;
51 int ConnectedCount = 0;
52 
53 #ifndef AUTHENTICATION
54 #define undef1 __unused
55 #else
56 #define undef1
57 #endif
58 
59 void
60 auth_encrypt_init(char *local, char *remote, const char *name undef1, int server undef1)
61 {
62 	RemoteHostName = remote;
63 	LocalHostName = local;
64 #ifdef	AUTHENTICATION
65 	auth_init(name, server);
66 #endif
67 #ifdef	ENCRYPTION
68 	encrypt_init(name, server);
69 #endif	/* ENCRYPTION */
70 	if (UserNameRequested) {
71 		free(UserNameRequested);
72 		UserNameRequested = 0;
73 	}
74 }
75 
76 #ifdef	ENCRYPTION
77 void
78 auth_encrypt_user(char *name)
79 {
80 	if (UserNameRequested)
81 		free(UserNameRequested);
82 	UserNameRequested = name ? strdup(name) : 0;
83 }
84 
85 /* ARGSUSED */
86 void
87 auth_encrypt_connect(int cnt __unused)
88 {
89 }
90 #endif	/* ENCRYPTION */
91 
92 void
93 printd(const unsigned char *data, int cnt)
94 {
95 	if (cnt > 16)
96 		cnt = 16;
97 	while (cnt-- > 0) {
98 		printf(" %02x", *data);
99 		++data;
100 	}
101 }
102