/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* based on @(#)kerberos5.c 8.1 (Berkeley) 6/4/93 */
/*
* Copyright (C) 1990 by the Massachusetts Institute of Technology
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
#include <stdio.h>
#include <ctype.h>
#include <syslog.h>
#include <stdlib.h>
/* the following are from the kerberos tree */
#include <k5-int.h>
#include <com_err.h>
#include <netdb.h>
#include <profile/prof_int.h>
#include "externs.h"
extern char *RemoteHostName;
extern boolean_t auth_debug_mode;
extern int net;
#define ACCEPTED_ENCTYPE(a) \
(a == ENCTYPE_DES_CBC_CRC || a == ENCTYPE_DES_CBC_MD5)
/* for comapatibility with non-Solaris KDC's, this has to be big enough */
static void kerberos5_forward(Authenticator *);
/* telnet matches the AP_REQ and AP_REP with this */
/*
* Change the kerberos realm
*/
void
{
"no realm provided.\n"));
return;
}
if (telnet_krb5_realm)
if (telnet_krb5_realm == NULL)
"Could not set Kerberos realm, malloc failed\n"));
}
static int
{
/* the first 3 bytes are control chars */
unsigned char *p = str_data + 4;
unsigned char *cd = (unsigned char *)d;
/* spaceleft is incremented whenever p is decremented */
if (c == -1)
if (auth_debug_mode) {
(void) printf("%s:%d: [%d] (%d)",
printd(d, c);
(void) printf("\r\n");
}
if (spaceleft < 3)
*p++ = type;
spaceleft -= 3;
while (c-- > 0) {
if (spaceleft < 2)
*p++ = IAC;
spaceleft -= 2;
}
}
if (spaceleft < 2)
*p++ = IAC;
*p++ = SE;
}
/* ARGSUSED */
int
{
if (krb5auth_flag && (telnet_context == 0)) {
if (retval)
return (0);
}
return (1);
}
int
{
int ap_opts;
int i;
if (!UserNameRequested) {
if (auth_debug_mode)
"no user name supplied\r\n"));
return (0);
}
if (auth_debug_mode)
"could not get default ccache\r\n"));
return (0);
}
if (auth_debug_mode)
printf("telnet: calling krb5_sname_to_principal\n");
if (auth_debug_mode)
"while constructing service name: %s\r\n"),
return (0);
}
if (auth_debug_mode)
printf("telnet: done calling krb5_sname_to_principal\n");
if (telnet_krb5_realm != NULL) {
return (0);
}
if (auth_debug_mode)
"telnet: Kerberos V5: set kerberos realm to %s\r\n"),
}
if (auth_debug_mode) {
"telnet: Kerberos V5: failure on principal "
}
return (0);
}
/*
* Check to to confirm that at least one of the supported
* encryption types (des-cbc-md5, des-cbc-crc is available. If
* one is available then use it to obtain credentials.
*/
&ktypes))) {
if (auth_debug_mode) {
"telnet: Kerberos V5: could not determine "
"TGS encryption types "
"(see default_tgs_enctypes in krb5.conf) "
}
return (0);
}
for (i = 0; ktypes[i]; i++) {
if (ACCEPTED_ENCTYPE(ktypes[i]))
break;
}
if (ktypes[i] == 0) {
if (auth_debug_mode) {
"telnet: Kerberos V5: "
"failure on encryption types. "
"Cannot find des-cbc-md5 or des-cbc-crc "
"in list of TGS encryption types "
"(see default_tgs_enctypes in krb5.conf)\n"));
}
return (0);
}
if (auth_debug_mode) {
"telnet: Kerberos V5: failure on credentials "
}
return (0);
}
if (auth_context) {
auth_context = 0;
}
if (auth_debug_mode) {
"Kerberos V5: failed to init auth_context "
}
return (0);
}
if (session_key) {
session_key = 0;
}
if (newkey) {
/*
* keep the key in our private storage, but don't use it
* yet---see kerberos5_reply() below
*/
/* use the session key in credentials instead */
} else
newkey, &session_key);
}
if (retval) {
if (auth_debug_mode)
"telnet: Kerberos V5: mk_req failed (%s)\r\n"),
return (0);
}
if (auth_debug_mode)
"telnet: Not enough room for user name\r\n"));
return (0);
}
if (auth_debug_mode && retval) {
"telnet: Sent Kerberos V5 credentials to server\r\n"));
} else if (auth_debug_mode) {
"telnet: Not enough room for authentication data\r\n"));
return (0);
}
return (1);
}
void
{
if (cnt-- < 1)
return;
switch (*data++) {
case KRB_REJECT:
if (cnt > 0)
"[ Kerberos V5 refuses authentication because "
else
"[ Kerberos V5 refuses authentication ]\r\n"));
return;
case KRB_ACCEPT:
if (!mutual_complete) {
"[ Kerberos V5 accepted you, but didn't "
"provide mutual authentication! ]\r\n"));
return;
}
if (session_key) {
}
}
if (cnt)
"[ Kerberos V5 accepts you as ``%.*s'' ]\r\n"),
else
"[ Kerberos V5 accepts you ]\r\n"));
if (forward_flags & OPTS_FORWARD_CREDS)
break;
case KRB_RESPONSE:
/* the rest of the reply should contain a krb_ap_rep */
if (retval) {
"[ Mutual authentication failed: "
return;
}
if (session_key) {
}
}
return;
case KRB_FORWARD_ACCEPT:
"[ Kerberos V5 accepted forwarded credentials ]\r\n"));
return;
case KRB_FORWARD_REJECT:
"[ Kerberos V5 refuses forwarded credentials because "
return;
default:
if (auth_debug_mode)
return;
}
}
/* ARGSUSED */
int
{
return (level);
return (AUTH_VALID);
} else
return (AUTH_USER);
}
/*
* Used with the set opt command to print suboptions
*/
void
{
register int i;
buflen -= 1;
switch (data[3]) {
case KRB_REJECT: /* Rejected (reason might follow) */
goto common;
case KRB_ACCEPT: /* Accepted (name might follow) */
if (cnt <= 4)
break;
for (i = 4; i < cnt; i++)
break;
case KRB_AUTH: /* Authentication data follows */
goto common2;
case KRB_RESPONSE:
goto common2;
case KRB_FORWARD: /* Forwarded credentials follow */
goto common2;
case KRB_FORWARD_ACCEPT: /* Forwarded credentials accepted */
goto common2;
case KRB_FORWARD_REJECT: /* Forwarded credentials rejected */
/* (reason might follow) */
goto common2;
default:
gettext(" %d (unknown)"),
data[3]);
for (i = 4; i < cnt; i++) {
}
break;
}
}
void
{
if (!telnet_context) {
if (err) {
"Error initializing Kerberos 5 library: %s\n"),
error_message(err));
return;
}
}
if (err) {
"Error getting Kerberos 5 realms for: %s (%s)\n"),
return;
}
}
}
static void
{
forw_creds.data = 0;
if (auth_debug_mode)
"Kerberos V5: could not get default ccache - %s\r\n"),
return;
}
if (retval) {
if (auth_debug_mode)
"Kerberos V5: could not get default "
goto cleanup;
}
if (retval) {
if (auth_debug_mode)
"Kerberos V5: could not make server "
goto cleanup;
}
if (retval) {
if (auth_debug_mode)
"Kerberos V5: could not gen local full "
goto cleanup;
}
&forw_creds);
if (retval) {
if (auth_debug_mode)
"Kerberos V5: error getting forwarded "
goto cleanup;
}
/* Send forwarded credentials */
forw_creds.length)) {
if (auth_debug_mode)
"Not enough room for authentication data\r\n"));
} else if (auth_debug_mode)
"Forwarded local Kerberos V5 credentials to server\r\n"));
if (client)
if (server)
if (forw_creds.data)
/* LINTED */
}