dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / telnet / authenc.c
blob0e6671a0320b438365b8d98f5230ab480f3bfa68
1 /*
2 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * Miscellaneous routines needed by the telnet client for authentication
8 * and / or encryption.
9 */
12 * Copyright (c) 1991, 1993
13 * The Regents of the University of California. All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the University of
26 * California, Berkeley and its contributors.
27 * 4. Neither the name of the University nor the names of its contributors
28 * may be used to endorse or promote products derived from this software
29 * without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * SUCH DAMAGE.
44 static char sccsid[] = "@(#)authenc.c 8.1 (Berkeley) 6/6/93";
46 #include <sys/types.h>
47 #include <arpa/telnet.h>
49 #include "general.h"
50 #include "ring.h"
51 #include "externs.h"
52 #include "defines.h"
53 #include "types.h"
55 char *RemoteHostName = NULL;
56 char *UserNameRequested = NULL;
58 #define MAXNETDATA 16
61 * Get ready to do authentication and encryption by calling their
62 * init routines, and clearing the user name variable
64 /* ARGSUSED */
65 void
66 auth_encrypt_init(char *local, char *remote, char *name)
68 RemoteHostName = remote;
70 auth_init(name);
72 encrypt_init(name);
74 if (UserNameRequested) {
75 free(UserNameRequested);
76 UserNameRequested = NULL;
81 * Set the user name variable. This is the user name used from now
82 * on for authentication and encryption
84 void
85 auth_encrypt_user(char *name)
87 free(UserNameRequested);
88 UserNameRequested = name ? strdup(name) : NULL;
91 int
92 net_write(unsigned char *str, int len)
94 if (NETROOM() > len) {
95 ring_supply_data(&netoring, str, len);
96 if (str[0] == IAC && str[1] == SE)
97 printsub('>', &str[2], len - 2);
98 return (len);
100 return (0);
103 void
104 net_encrypt(void)
106 if (encrypt_output)
107 ring_encrypt(&netoring, encrypt_output);
108 else
109 ring_clearto(&netoring);
113 * Spin to wait for authentication to complete
114 * This allows for a timeout
116 void
117 telnet_spin(void)
119 extern boolean_t scheduler_lockout_tty;
121 scheduler_lockout_tty = B_TRUE;
122 (void) Scheduler(0);
123 scheduler_lockout_tty = B_FALSE;
128 * Used to print out unsigned chars as decimals for debugging options
130 void
131 printd(unsigned char *data, int cnt)
133 cnt = (cnt < MAXNETDATA) ? cnt:MAXNETDATA;
134 while (cnt-- > 0)
135 (void) printf(" %02x", *data++);