acquire_cred.c revision 178826
1113094Sphk/*
2135482Sphk * Copyright (c) 1997 - 2004 Kungliga Tekniska H�gskolan
3113094Sphk * (Royal Institute of Technology, Stockholm, Sweden).
4113094Sphk * All rights reserved.
5113094Sphk *
6113094Sphk * Redistribution and use in source and binary forms, with or without
7113094Sphk * modification, are permitted provided that the following conditions
8113094Sphk * are met:
9113094Sphk *
10113094Sphk * 1. Redistributions of source code must retain the above copyright
11113094Sphk *    notice, this list of conditions and the following disclaimer.
12113094Sphk *
13113094Sphk * 2. Redistributions in binary form must reproduce the above copyright
14113094Sphk *    notice, this list of conditions and the following disclaimer in the
15113094Sphk *    documentation and/or other materials provided with the distribution.
16113094Sphk *
17113094Sphk * 3. Neither the name of the Institute nor the names of its contributors
18113094Sphk *    may be used to endorse or promote products derived from this software
19113094Sphk *    without specific prior written permission.
20113094Sphk *
21113094Sphk * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22113094Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23113094Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24113094Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25113094Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26113094Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27113094Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28135482Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29135482Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30135482Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31135482Sphk * SUCH DAMAGE.
32135482Sphk */
33135482Sphk
34135482Sphk#include "ntlm/ntlm.h"
35135482Sphk
36135482SphkRCSID("$Id: acquire_cred.c 22380 2007-12-29 18:42:56Z lha $");
37135482Sphk
38135482SphkOM_uint32 _gss_ntlm_acquire_cred
39135482Sphk           (OM_uint32 * min_stat,
40135482Sphk            const gss_name_t desired_name,
41135482Sphk            OM_uint32 time_req,
42113094Sphk            const gss_OID_set desired_mechs,
43113094Sphk            gss_cred_usage_t cred_usage,
44135482Sphk            gss_cred_id_t * output_cred_handle,
45119418Sobrien            gss_OID_set * actual_mechs,
46119418Sobrien            OM_uint32 * time_rec
47119418Sobrien           )
48113094Sphk{
49113094Sphk    ntlm_name name = (ntlm_name) desired_name;
50113094Sphk    OM_uint32 maj_stat;
51113094Sphk    ntlm_ctx ctx;
52130026Sphk
53113270Sphk    *min_stat = 0;
54113094Sphk    if (output_cred_handle)
55113094Sphk	*output_cred_handle = GSS_C_NO_CREDENTIAL;
56113094Sphk    if (actual_mechs)
57113094Sphk	*actual_mechs = GSS_C_NO_OID_SET;
58113094Sphk    if (time_rec)
59119274Simp	*time_rec = GSS_C_INDEFINITE;
60119274Simp
61113094Sphk    if (desired_name == NULL)
62113094Sphk	return GSS_S_NO_CRED;
63113094Sphk
64113094Sphk    if (cred_usage == GSS_C_BOTH || cred_usage == GSS_C_ACCEPT) {
65113270Sphk
66113270Sphk	maj_stat = _gss_ntlm_allocate_ctx(min_stat, &ctx);
67113270Sphk	if (maj_stat != GSS_S_COMPLETE)
68113270Sphk	    return maj_stat;
69135482Sphk
70135482Sphk	maj_stat = (*ctx->server->nsi_probe)(min_stat, ctx->ictx,
71135482Sphk					     name->domain);
72135482Sphk
73135482Sphk	if (maj_stat)
74135482Sphk	    return maj_stat;
75113270Sphk
76135482Sphk	{
77135482Sphk	    gss_ctx_id_t context = (gss_ctx_id_t)ctx;
78135482Sphk	    _gss_ntlm_delete_sec_context(min_stat, &context, NULL);
79135482Sphk	    *min_stat = 0;
80135482Sphk	}
81135482Sphk    }
82135482Sphk    if (cred_usage == GSS_C_BOTH || cred_usage == GSS_C_INITIATE) {
83135482Sphk	ntlm_cred cred;
84143844Sphk
85135482Sphk	*min_stat = _gss_ntlm_get_user_cred(name, &cred);
86135482Sphk	if (*min_stat)
87135482Sphk	    return GSS_S_FAILURE;
88135482Sphk	cred->usage = cred_usage;
89113270Sphk
90113270Sphk	*output_cred_handle = (gss_cred_id_t)cred;
91143844Sphk    }
92113270Sphk
93113270Sphk    return (GSS_S_COMPLETE);
94113270Sphk}
95135482Sphk