/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2000, 2002, 2003, 2007, 2008 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* 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.
*
*/
/*
* Copyright 1993 by OpenVision Technologies, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and
* that both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of OpenVision not be used
* in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. OpenVision makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copyright (C) 1998 by the FundsXpress, INC.
*
* All rights reserved.
*
* 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 FundsXpress. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. FundsXpress makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* Copyright (c) 2006-2008, Novell, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* * The copyright holder's name is not used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
*/
/*
*/
/* Solaris Kerberos */
#include <libintl.h>
#include <locale.h>
#include <ctype.h>
#include "k5-int.h"
#include "gssapiP_krb5.h"
#include "mglueP.h" /* Solaris Kerberos */
#ifdef HAVE_MEMORY_H
#include <memory.h>
#endif
#include <stdlib.h>
#include <assert.h>
/* Solaris Kerberos start */
/* Solaris Kerberos end */
/*
* $Id: init_sec_context.c 23706 2010-02-08 20:55:36Z tlyu $
*/
/* XXX This is for debugging only!!! Should become a real bitfield
at some point */
int krb5_gss_dbg_client_expcreds = 0;
/*
* Common code which fetches the correct krb5 credentials from the
* ccache.
*/
{
goto cleanup;
/*
* Do constrained delegation if we have proxy credentials and
* we're not trying to get a ticket to ourselves (in which case
* we can just use the S4U2Self or evidence ticket directly).
*/
if (cred->proxy_cred &&
&mcreds,
if (code)
goto cleanup;
} else {
}
/*
* cred->name is immutable, so there is no need to acquire
* cred->name->lock.
*/
if (code != 0)
goto cleanup;
}
if (code)
goto cleanup;
if (flags & KRB5_GC_CONSTRAINED_DELEGATION) {
/* server did not support constrained delegation */
goto cleanup;
}
}
/*
* Enforce a stricter limit (without timeskew forgiveness at the
* boundaries) because accept_sec_context code is also similarly
* non-forgiving.
*/
goto cleanup;
}
return code;
}
struct gss_checksum_data {
};
#ifdef CFX_EXERCISE
#include "../../krb5/krb/auth_con.h"
#endif
static krb5_error_code KRB5_CALLCONV
{
unsigned char *ptr;
unsigned int junk;
/* build the checksum field */
/* first get KRB_CRED message, so we know its length */
/* clear the time check flag that was set in krb5_auth_con_init() */
&credmsg);
/* turn KRB5_AUTH_CONTEXT_DO_TIME back on */
if (code) {
request */
} else {
return(KRB5KRB_ERR_FIELD_TOOLONG);
}
}
} else {
}
#ifdef CFX_EXERCISE
/* Our ftp client code stupidly assumes a base64-encoded
version of the token will fit in 10K, so don't make this
too big. */
} else
junk = 0;
#else
junk = 0;
#endif
/* now allocate a buffer to hold the checksum data and
(maybe) KRB_CRED msg */
return(ENOMEM);
}
/* done with this, free it */
/* free credmsg data */
}
if (junk)
return 0;
}
static krb5_error_code
{
unsigned char *ptr;
unsigned char *t;
unsigned int tlen;
/* compute the hash of the channel bindings */
return(code);
case ENCTYPE_DES_CBC_CRC:
case ENCTYPE_DES_CBC_MD4:
case ENCTYPE_DES_CBC_MD5:
case ENCTYPE_DES3_CBC_SHA1:
if (code)
goto cleanup;
break;
default:
break;
}
/* call mk_req. subkey and ap_req need to be used or destroyed */
if (code)
goto cleanup;
/* store the interesting stuff from creds and authent */
/* build up the token */
/*
* For DCE RPC, do not encapsulate the AP-REQ in the
* typical GSS wrapping.
*/
} else {
/* allocate space for the token */
goto cleanup;
}
/* fill in the buffer */
ptr = t;
&ptr, KG_TOK_CTX_AP_REQ);
/* pass it back */
}
code = 0;
return (code);
}
/*
* new_connection
*
* Do the grunt work of setting up a new context.
*/
int default_mech)
{
/* make sure the cred is usable for init */
*minor_status = 0;
return(GSS_S_NO_CRED);
}
/* complain if the input token is non-null */
*minor_status = 0;
return(GSS_S_DEFECTIVE_TOKEN);
}
/* create the ctx */
== NULL) {
*minor_status = ENOMEM;
return(GSS_S_FAILURE);
}
/* fill in the ctx */
goto fail;
/* limit the encryption types negotiated (if requested) */
if (cred->req_enctypes) {
cred->req_enctypes))) {
goto fail;
}
}
if (req_flags & GSS_C_DCE_STYLE)
goto fail;
} else {
}
goto fail;
goto fail;
if (code)
goto fail;
/*
* GSS_C_DELEG_POLICY_FLAG means to delegate only if the
* ok-as-delegate ticket flag is set.
*/
if ((req_flags & GSS_C_DELEG_POLICY_FLAG)
if (default_mech) {
}
!= GSS_S_COMPLETE) {
code = *minor_status;
goto fail;
}
/*
* Now try to make it static if at all possible....
*/
{
/* gsskrb5 v1 */
(code == KG_EMPTY_CCACHE))
if (code == KRB5KRB_AP_ERR_TKT_EXPIRED)
goto fail;
}
&keyblock);
if (code != 0)
goto fail;
if (code != 0)
goto fail;
}
ctx->have_acceptor_subkey = 0;
if (code != 0)
goto fail;
/* at this point, the context is constructed and valid,
hence, releaseable */
/* intern the context handle */
goto fail;
}
ctx_free = 0;
/* compute time_rec */
if (time_rec) {
goto fail;
}
/* set the other returns */
*output_token = token;
if (ret_flags)
if (actual_mech_type)
/* return successfully */
*minor_status = 0;
ctx->established = 0;
return(GSS_S_CONTINUE_NEEDED);
} else {
return(GSS_S_COMPLETE);
}
fail:
if (ctx_free) {
if (ctx_free->auth_context)
} else
*minor_status = code;
return (major_status);
}
/*
* mutual_auth
*
* Handle the reply from the acceptor, if we're doing mutual auth.
*/
static OM_uint32
{
unsigned char *ptr;
char *sptr;
if (code)
goto fail;
/* validate the context handle */
/*SUPPRESS 29*/
if (! kg_validate_ctx_id(*context_handle)) {
return(GSS_S_NO_CONTEXT);
}
/* make sure the context is non-established, and that certain
arguments are unchanged */
if ((ctx->established) ||
goto fail;
}
/* Solaris Kerberos: spruce-up the err msg */
"Target name principal '%s' does "
"not match '%s'"),
}
if (s_name)
if (s_princ)
code = 0;
goto fail;
}
/* verify the token and leave the AP_REP message in ap_rep */
if (input_token == GSS_C_NO_BUFFER) {
code = 0;
goto fail;
}
/* Raw AP-REP */
/* Handle a KRB_ERROR message from the server */
if (code)
goto fail;
else
code = 0;
goto fail;
} else {
*minor_status = 0;
return(GSS_S_DEFECTIVE_TOKEN);
}
}
/* decode the ap_rep */
&ap_rep_data))) {
/*
* XXX A hack for backwards compatiblity.
* To be removed in 1999 -- proven
*/
&ap_rep_data)))
goto fail;
}
/* store away the sequence number */
/* Keep acceptor's subkey. */
&ctx->acceptor_subkey);
if (code) {
goto fail;
}
if (code) {
goto fail;
}
}
/* free the ap_rep_data */
if (code)
goto fail;
}
/* set established */
/* set returns */
if (time_rec) {
goto fail;
}
if (ret_flags)
if (actual_mech_type)
/* success */
*minor_status = 0;
return GSS_S_COMPLETE;
fail:
*minor_status = code;
return (major_status);
}
{
int err;
int default_mech = 0;
if (*context_handle == GSS_C_NO_CONTEXT) {
if (kerr) {
*minor_status = kerr;
return GSS_S_FAILURE;
}
return GSS_S_FAILURE;
}
} else {
}
/* set up return values so they can be "freed" successfully */
output_token->length = 0;
if (actual_mech_type)
*actual_mech_type = NULL;
/* verify that the target_name is valid and usable */
if (! kg_validate_name(target_name)) {
/* Solaris Kerberos: spruce-up the err msg */
if (kret == 0) {
"Target name principal '%s' is invalid"),
s_name);
}
if (*context_handle == GSS_C_NO_CONTEXT)
return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
}
/* verify the credential, or use the default */
/*SUPPRESS 29*/
if (claimant_cred_handle == GSS_C_NO_CREDENTIAL) {
/*
* Solaris Kerberos: here we are using the Solaris specific
* function get_default_cred() to handle the special case of a
* root principal
*/
(gss_cred_id_t *)&cred);
if (*context_handle == GSS_C_NO_CONTEXT)
return(major_status);
}
} else {
if (GSS_ERROR(major_status)) {
if (*context_handle == GSS_C_NO_CONTEXT)
return(major_status);
}
}
if (kerr) {
*minor_status = kerr;
return GSS_S_FAILURE;
}
/* verify the mech_type */
err = 0;
if (mech_type == GSS_C_NULL_OID) {
default_mech = 1;
} else if (cred->prerfc_mech) {
} else {
err = 1;
}
err = 1;
if (!cred->prerfc_mech)
err = 1;
err = 1;
} else {
err = 1;
}
if (err) {
*minor_status = 0;
if (*context_handle == GSS_C_NO_CONTEXT)
return(GSS_S_BAD_MECH);
}
/* is this a new connection or not? */
/*SUPPRESS 29*/
if (*context_handle == GSS_C_NO_CONTEXT) {
if (*context_handle == GSS_C_NO_CONTEXT) {
} else
} else {
/* mutual_auth doesn't care about the credentials */
context);
/* If context_handle is now NO_CONTEXT, mutual_auth called
delete_sec_context, which would've zapped the krb5 context
too. */
}
return(major_status);
}
#ifndef _WIN32
static int kdc_flag = 0;
#endif
{
#ifndef _WIN32
int is_kdc;
#endif
if (err)
return err;
#ifndef _WIN32
if (err)
return err;
if (is_kdc)
return krb5int_init_context_kdc(ctxp);
#endif
return krb5_init_context(ctxp);
}
#ifndef _WIN32
const gss_OID desired_mech,
const gss_OID desired_object,
{
*minor_status = 0;
if (err)
return err;
if (*minor_status) {
return GSS_S_FAILURE;
}
kdc_flag = 1;
return GSS_S_COMPLETE;
}
#endif
/* Solaris Kerberos specific routines start */
#define ROOT_UID 0
extern int
/* Solaris Kerberos */
static OM_uint32
const char *name,
{
0,
};
if (!name)
return (GSS_S_FAILURE);
*minor_status = code;
return (GSS_S_FAILURE);
}
*minor_status = code;
return (GSS_S_FAILURE);
} else if (kt_is_file && kt_size == 0) {
return (GSS_S_FAILURE);
}
if (type == KRB5_NT_SRV_HST)
else
if (code == 0) {
} else {
/* Try to set a useful error message */
"Failed to find realm for %s in keytab"),
if (princ)
}
}
if (code) {
*minor_status = code;
return (GSS_S_FAILURE);
}
0))) {
*minor_status = code;
return (GSS_S_FAILURE);
}
* when request
* gets to KDC
*/
*minor_status = code;
return (GSS_S_FAILURE);
}
if (code != 0) {
*minor_status = code;
return (GSS_S_FAILURE);
}
/*
* Evidently (sigh), on success, krb5_get_init_creds_keytab
* changes the my_creds princ ptrs so we need to free those
* princs (me&server) as well as freeing all of my_creds contents.
*/
}
if (code) {
*minor_status = code;
return (GSS_S_FAILURE);
}
&ccache);
if (code != 0) {
*minor_status = code;
return (GSS_S_FAILURE);
}
if (code != 0) {
*minor_status = code;
return (GSS_S_FAILURE);
}
&my_creds);
if (code) {
*minor_status = code;
return (GSS_S_FAILURE);
}
return (GSS_S_COMPLETE);
}
static OM_uint32
{
int options = 0;
0,
};
*minor_status = code;
return (GSS_S_FAILURE);
}
*minor_status = code;
return (GSS_S_FAILURE);
}
0))) {
*minor_status = code;
return (GSS_S_FAILURE);
}
return (KDC_ERR_BADOPTION);
}
creds.ticket_flags = 0;
if (code) {
*minor_status = code;
return (GSS_S_FAILURE);
}
if (ccache_name == NULL) {
return (GSS_S_FAILURE);
}
if (code == -1) {
*minor_status = code;
return (GSS_S_FAILURE);
}
}
return (GSS_S_COMPLETE);
}
/* Solaris Kerberos */
{
return (EINVAL);
return (errno);
*p = '\0';
for (p = localname; *p; p++)
*p = toupper(*p);
return (ENOMEM);
return (0);
}
/*
* Solaris Kerberos:
* We enforce a minimum refresh time on the root cred. This avoids problems for
* the higher level communication protocol for having valid creds and
* setting up a valid context, only to have it expire before or while
* it is being used. For non root users we don't care since we do not refresh
* there creds, they get what they can get.
*/
/* get_default_cred() must be called with the krb5_mutex lock held */
static OM_uint32
{
/*
* Solaris Kerberos
* Use krb5_getuid() to select the mechanism to obtain the uid.
*/
/* Get the default cred for user */
/* If we're not root we're done */
return (major);
/*
* Try and get root's cred in the cache using keytab.
*
* First try "root", then try "host", and finally try the Security
* Account Manager (SAM) for MS AD interop.
*/
if (major != GSS_S_COMPLETE)
context, "host",
if (major != GSS_S_COMPLETE) {
char *name;
if (code == 0) {
}
}
if (major != GSS_S_COMPLETE)
return (major);
/* We should have valid tgt now in the cache, so get it. */
return (major);
}
/* We've got a gss cred handle that is a kerberos cred handle. */
/* If we can't get the time, assume the worst. */
return (GSS_S_CREDENTIALS_EXPIRED);
}
/*
* Try and get root's cred in the cache using keytab.
*
* First try "root", then try "host", and finally try the Security
* Account Manager (SAM) for MS AD interop.
*/
/* If root's cred has expired re-get it */
if (major != GSS_S_COMPLETE)
context, "host",
if (major != GSS_S_COMPLETE) {
char *name;
if (code == 0) {
}
}
if (major != GSS_S_COMPLETE)
return (major);
if (major != GSS_S_COMPLETE)
return (major);
/* Any body else is SOL unless we can renew their credential cache */
if ((major != GSS_S_COMPLETE) &&
(major != KDC_ERR_BADOPTION))
return (major);
if (major != GSS_S_COMPLETE)
return (major);
}
/* Otherwise we got non expired creds */
return (GSS_S_COMPLETE);
}
/* Solaris Kerberos specific routines end */